Skip to content

Commit

Permalink
Multiple stability improvements, unused file and config cleanups (#38)
Browse files Browse the repository at this point in the history
* app remove buttonless dfu entry and cleanups

* app uart driver switch

* app cmake improvements

* nrfutil setup move to script to speed up build, minor adjust flash script

* power event reporting issue fix

* app wdt behavior change

* pmu irq reg fetch delay extend to 20ms

---------

Signed-off-by: Adam BZH <[email protected]>
  • Loading branch information
424778940z authored Jun 2, 2024
1 parent 79aab2a commit 8693cd9
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 119 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
build
_build
artifacts*
ble-firmware/external/micro-ecc/nrf52hf_armgcc/armgcc/micro_ecc_lib_nrf52.a
# secrets
temp.pk
build_local_signed.sh
# garbages
utils/nrfutil_repo
*.bak
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ set(CMAKE_INCLUDE_CURRENT_DIR OFF)

# populate vars
set(DIR_UTILS "${PROJECT_SOURCE_DIR}/utils")
# set(DIR_NRFUTIL_REPO "${PROJECT_BINARY_DIR}/nrfutil_repo")
set(DIR_NRFUTIL_REPO "${DIR_UTILS}/nrfutil_repo")
set(FILE_KEY "${PROJECT_BINARY_DIR}/temp.pk")
set(FILE_INPUT_BL_CONFIG "bl_config.hex")
set(FILE_INPUT_MBR_UICR "${PROJECT_SOURCE_DIR}/artifacts/OnekeyProBTFW_MBR_UICR.hex")
Expand Down Expand Up @@ -49,7 +51,7 @@ add_custom_target(
# nrf tools
add_custom_target(
${CMAKE_PROJECT_NAME}_UTIL
COMMAND ${DIR_UTILS}/nrfutil install nrf5sdk-tools
COMMAND ${DIR_UTILS}/nrfutil_prepare.sh "${DIR_NRFUTIL_REPO}"
)

# python env (poetry)
Expand Down Expand Up @@ -162,7 +164,7 @@ add_custom_target(
# flash
add_custom_target(
${CMAKE_PROJECT_NAME}_FLASH_FACTORY
COMMAND JLINK_SN=$ENV{JLINK_SN} ${PROJECT_SOURCE_DIR}/flash_factory.sh
COMMAND JLINK_SN=$ENV{JLINK_SN} ${DIR_UTILS}/jlink_flash.sh ${FILE_OUTPUT_FACTORY_HEX}
DEPENDS ${CMAKE_PROJECT_NAME}_FACTORY_HEX
)

Expand Down
107 changes: 57 additions & 50 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set(
${NRF_SDK_ROOT}/components/ble/ble_services/ble_bas_c
${NRF_SDK_ROOT}/components/ble/ble_services/ble_cscs
${NRF_SDK_ROOT}/components/ble/ble_services/ble_cts_c
${NRF_SDK_ROOT}/components/ble/ble_services/ble_dfu
# ${NRF_SDK_ROOT}/components/ble/ble_services/ble_dfu
${NRF_SDK_ROOT}/components/ble/ble_services/ble_dis
${NRF_SDK_ROOT}/components/ble/ble_services/ble_gls
${NRF_SDK_ROOT}/components/ble/ble_services/ble_hids
Expand All @@ -51,17 +51,17 @@ set(
${NRF_SDK_ROOT}/components/ble/nrf_ble_gq
${NRF_SDK_ROOT}/components/ble/nrf_ble_qwr
${NRF_SDK_ROOT}/components/ble/peer_manager
${NRF_SDK_ROOT}/components/boards
# ${NRF_SDK_ROOT}/components/boards
${NRF_SDK_ROOT}/components/libraries/atomic
${NRF_SDK_ROOT}/components/libraries/atomic_fifo
${NRF_SDK_ROOT}/components/libraries/atomic_flags
${NRF_SDK_ROOT}/components/libraries/balloc
${NRF_SDK_ROOT}/components/libraries/bootloader
${NRF_SDK_ROOT}/components/libraries/bootloader/ble_dfu
# ${NRF_SDK_ROOT}/components/libraries/bootloader/ble_dfu
${NRF_SDK_ROOT}/components/libraries/bootloader/dfu
${NRF_SDK_ROOT}/components/libraries/bsp
${NRF_SDK_ROOT}/components/libraries/button
${NRF_SDK_ROOT}/components/libraries/cli
# ${NRF_SDK_ROOT}/components/libraries/bsp
# ${NRF_SDK_ROOT}/components/libraries/button
# ${NRF_SDK_ROOT}/components/libraries/cli
${NRF_SDK_ROOT}/components/libraries/crc16
${NRF_SDK_ROOT}/components/libraries/crc32
${NRF_SDK_ROOT}/components/libraries/crypto
Expand All @@ -74,23 +74,23 @@ set(
${NRF_SDK_ROOT}/components/libraries/crypto/backend/nrf_sw
${NRF_SDK_ROOT}/components/libraries/crypto/backend/oberon
${NRF_SDK_ROOT}/components/libraries/crypto/backend/optiga
${NRF_SDK_ROOT}/components/libraries/csense
${NRF_SDK_ROOT}/components/libraries/csense_drv
# ${NRF_SDK_ROOT}/components/libraries/csense
# ${NRF_SDK_ROOT}/components/libraries/csense_drv
${NRF_SDK_ROOT}/components/libraries/delay
${NRF_SDK_ROOT}/components/libraries/ecc
${NRF_SDK_ROOT}/components/libraries/experimental_section_vars
${NRF_SDK_ROOT}/components/libraries/experimental_task_manager
# ${NRF_SDK_ROOT}/components/libraries/experimental_task_manager
${NRF_SDK_ROOT}/components/libraries/fds
${NRF_SDK_ROOT}/components/libraries/fifo
${NRF_SDK_ROOT}/components/libraries/fstorage
${NRF_SDK_ROOT}/components/libraries/gfx
# ${NRF_SDK_ROOT}/components/libraries/gfx
${NRF_SDK_ROOT}/components/libraries/gpiote
${NRF_SDK_ROOT}/components/libraries/hardfault
${NRF_SDK_ROOT}/components/libraries/hci
${NRF_SDK_ROOT}/components/libraries/led_softblink
# ${NRF_SDK_ROOT}/components/libraries/led_softblink
${NRF_SDK_ROOT}/components/libraries/log
${NRF_SDK_ROOT}/components/libraries/log/src
${NRF_SDK_ROOT}/components/libraries/low_power_pwm
# ${NRF_SDK_ROOT}/components/libraries/low_power_pwm
${NRF_SDK_ROOT}/components/libraries/mem_manager
${NRF_SDK_ROOT}/components/libraries/memobj
${NRF_SDK_ROOT}/components/libraries/mpu
Expand All @@ -100,8 +100,8 @@ set(
${NRF_SDK_ROOT}/components/libraries/queue
${NRF_SDK_ROOT}/components/libraries/ringbuf
${NRF_SDK_ROOT}/components/libraries/scheduler
${NRF_SDK_ROOT}/components/libraries/sdcard
${NRF_SDK_ROOT}/components/libraries/sensorsim
# ${NRF_SDK_ROOT}/components/libraries/sdcard
# ${NRF_SDK_ROOT}/components/libraries/sensorsim
${NRF_SDK_ROOT}/components/libraries/slip
${NRF_SDK_ROOT}/components/libraries/sortlist
${NRF_SDK_ROOT}/components/libraries/spi_mngr
Expand All @@ -111,17 +111,17 @@ set(
${NRF_SDK_ROOT}/components/libraries/svc
${NRF_SDK_ROOT}/components/libraries/timer
${NRF_SDK_ROOT}/components/libraries/twi_mngr
${NRF_SDK_ROOT}/components/libraries/twi_sensor
# ${NRF_SDK_ROOT}/components/libraries/twi_sensor
${NRF_SDK_ROOT}/components/libraries/uart
${NRF_SDK_ROOT}/components/libraries/usbd
${NRF_SDK_ROOT}/components/libraries/usbd/class/audio
${NRF_SDK_ROOT}/components/libraries/usbd/class/cdc
${NRF_SDK_ROOT}/components/libraries/usbd/class/cdc/acm
${NRF_SDK_ROOT}/components/libraries/usbd/class/hid
${NRF_SDK_ROOT}/components/libraries/usbd/class/hid/generic
${NRF_SDK_ROOT}/components/libraries/usbd/class/hid/kbd
${NRF_SDK_ROOT}/components/libraries/usbd/class/hid/mouse
${NRF_SDK_ROOT}/components/libraries/usbd/class/msc
# ${NRF_SDK_ROOT}/components/libraries/usbd
# ${NRF_SDK_ROOT}/components/libraries/usbd/class/audio
# ${NRF_SDK_ROOT}/components/libraries/usbd/class/cdc
# ${NRF_SDK_ROOT}/components/libraries/usbd/class/cdc/acm
# ${NRF_SDK_ROOT}/components/libraries/usbd/class/hid
# ${NRF_SDK_ROOT}/components/libraries/usbd/class/hid/generic
# ${NRF_SDK_ROOT}/components/libraries/usbd/class/hid/kbd
# ${NRF_SDK_ROOT}/components/libraries/usbd/class/hid/mouse
# ${NRF_SDK_ROOT}/components/libraries/usbd/class/msc
${NRF_SDK_ROOT}/components/libraries/util
${NRF_SDK_ROOT}/components/softdevice/common
${NRF_SDK_ROOT}/components/softdevice/s132/headers
Expand All @@ -130,7 +130,7 @@ set(
${NRF_SDK_ROOT}/external/fprintf
${NRF_SDK_ROOT}/external/mbedtls/include
${NRF_SDK_ROOT}/external/micro-ecc/micro-ecc
${NRF_SDK_ROOT}/external/nrf_cc310/include
# ${NRF_SDK_ROOT}/external/nrf_cc310/include
${NRF_SDK_ROOT}/external/nrf_oberon
${NRF_SDK_ROOT}/external/nrf_oberon/include
${NRF_SDK_ROOT}/external/nrf_tls/mbedtls/nrf_crypto/config
Expand All @@ -150,9 +150,9 @@ set(
${NRF_SDK_ROOT}/components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c
${NRF_SDK_ROOT}/components/ble/ble_racp/ble_racp.c
${NRF_SDK_ROOT}/components/ble/ble_services/ble_bas/ble_bas.c
${NRF_SDK_ROOT}/components/ble/ble_services/ble_dfu/ble_dfu.c
${NRF_SDK_ROOT}/components/ble/ble_services/ble_dfu/ble_dfu_bonded.c
${NRF_SDK_ROOT}/components/ble/ble_services/ble_dfu/ble_dfu_unbonded.c
# ${NRF_SDK_ROOT}/components/ble/ble_services/ble_dfu/ble_dfu.c
# ${NRF_SDK_ROOT}/components/ble/ble_services/ble_dfu/ble_dfu_bonded.c
# ${NRF_SDK_ROOT}/components/ble/ble_services/ble_dfu/ble_dfu_unbonded.c
${NRF_SDK_ROOT}/components/ble/ble_services/ble_dis/ble_dis.c
${NRF_SDK_ROOT}/components/ble/ble_services/ble_lbs/ble_lbs.c
${NRF_SDK_ROOT}/components/ble/ble_services/ble_nus/ble_nus.c
Expand Down Expand Up @@ -250,6 +250,7 @@ set(
${NRF_SDK_ROOT}/external/segger_rtt/SEGGER_RTT_printf.c
${NRF_SDK_ROOT}/external/utf_converter/utf.c
${NRF_SDK_ROOT}/integration/nrfx/legacy/nrf_drv_rng.c
${NRF_SDK_ROOT}/integration/nrfx/legacy/nrf_drv_uart.c
${NRF_SDK_ROOT}/modules/nrfx/drivers/src/nrfx_clock.c
${NRF_SDK_ROOT}/modules/nrfx/drivers/src/nrfx_gpiote.c
${NRF_SDK_ROOT}/modules/nrfx/drivers/src/nrfx_rng.c
Expand Down Expand Up @@ -367,48 +368,54 @@ execute_process(
)
add_definitions('-DBUILD_ID=\"${GIT_VERSION}\"')

target_compile_definitions(
${CMAKE_PROJECT_NAME} PRIVATE
# debug handling
$<$<CONFIG:Debug>:
DEBUG
>
# project flags
APP_TIMER_V2
APP_TIMER_V2_RTC1_ENABLED
CONFIG_GPIO_AS_PINRESET
FLOAT_ABI_HARD
NRF52
NRF52832_XXAA
NRF_SD_BLE_API_VERSION=7
S132
SOFTDEVICE_PRESENT
# BUTTONLESS_ENABLED
BOND_ENABLE
# NRF_DFU_TRANSPORT_BLE
MBEDTLS_CONFIG_FILE="nrf_crypto_mbedtls_config.h"
NRF_APP_VERSION=0x00000001
NRF_APP_VERSION_ADDR=0x1D000
NRF_CRYPTO_MAX_INSTANCE_COUNT=1
# heap and stack
__HEAP_SIZE=8192
__STACK_SIZE=8192
)

target_compile_options(
${CMAKE_PROJECT_NAME} PRIVATE

# Build type handling
$<$<CONFIG:Debug>:
-Og -ggdb
-DDEBUG
>
$<$<CONFIG:Release>:
-Os -g0
>

# Uncomment the line below to enable link time optimization
# -flto=auto
# C flags common to all targets
-DAPP_TIMER_V2
-DAPP_TIMER_V2_RTC1_ENABLED
-DCONFIG_GPIO_AS_PINRESET
-DFLOAT_ABI_HARD
-DNRF52
-DNRF52832_XXAA
-DNRF_SD_BLE_API_VERSION=7
-DS132
-DSOFTDEVICE_PRESENT
# project flags
-DBUTTONLESS_ENABLED
-DBOND_ENABLE
-DNRF_DFU_TRANSPORT_BLE
-DMBEDTLS_CONFIG_FILE="nrf_crypto_mbedtls_config.h"
-DNRF_APP_VERSION=0x00000001
-DNRF_APP_VERSION_ADDR=0x1D000
-DNRF_CRYPTO_MAX_INSTANCE_COUNT=1
# -Wall -Werror
-Wall -Wno-comment -Wno-array-bounds
-mcpu=cortex-m4
-mthumb -mabi=aapcs
-mfloat-abi=hard -mfpu=fpv4-sp-d16
# keep every function in a separate section, this allows linker to discard unused ones
-ffunction-sections -fdata-sections -fno-strict-aliasing -fno-builtin -fshort-enums
# heap and stack
-D__HEAP_SIZE=8192
-D__STACK_SIZE=8192
)

target_link_options(
Expand Down
17 changes: 1 addition & 16 deletions app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
#include "peer_manager_handler.h"
#include "sdk_macros.h"
#include "app_scheduler.h"
#include "ble_dfu.h"
// #include "ble_dfu.h"
#include "nrf_bootloader_info.h"
#include "nrf_crypto.h"
#include "nrf_crypto_init.h"
Expand Down Expand Up @@ -949,21 +949,6 @@ static void nrf_qwr_error_handler(uint32_t nrf_error)
APP_ERROR_HANDLER(nrf_error);
}

static void disconnect(uint16_t conn_handle, void* p_context)
{
UNUSED_PARAMETER(p_context);

ret_code_t err_code = sd_ble_gap_disconnect(conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
if ( err_code != NRF_SUCCESS )
{
NRF_LOG_WARNING("Failed to disconnect connection. Connection handle: %d Error: %d", conn_handle, err_code);
}
else
{
NRF_LOG_DEBUG("Disconnected connection handle %d", conn_handle);
}
}

#ifdef BUTTONLESS_ENABLED
static void advertising_config_get(ble_adv_modes_config_t* p_config)
{
Expand Down
2 changes: 2 additions & 0 deletions app/power_manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ static void pmu_if_irq(const uint64_t irq)
if ( irq == 0 )
return;

nrf_delay_ms(20); // wait regs update

pmu_p->PullStatus();

if ( 0 != (irq & (1 << PWR_IRQ_PWR_CONNECTED)) )
Expand Down
89 changes: 88 additions & 1 deletion app/sdk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4223,7 +4223,7 @@
// <0=> Pause in SLEEP and HALT

#ifndef NRFX_WDT_CONFIG_BEHAVIOUR
#define NRFX_WDT_CONFIG_BEHAVIOUR 0
#define NRFX_WDT_CONFIG_BEHAVIOUR 1
#endif

// <o> NRFX_WDT_CONFIG_RELOAD_VALUE - Reload value <15-4294967295>
Expand Down Expand Up @@ -4390,6 +4390,93 @@
// </e>


// <e> UART_ENABLED - nrf_drv_uart - UART/UARTE peripheral driver - legacy layer
//==========================================================
#ifndef UART_ENABLED
#define UART_ENABLED 1
#endif
// <o> UART_DEFAULT_CONFIG_HWFC - Hardware Flow Control

// <0=> Disabled
// <1=> Enabled

#ifndef UART_DEFAULT_CONFIG_HWFC
#define UART_DEFAULT_CONFIG_HWFC 0
#endif

// <o> UART_DEFAULT_CONFIG_PARITY - Parity

// <0=> Excluded
// <14=> Included

#ifndef UART_DEFAULT_CONFIG_PARITY
#define UART_DEFAULT_CONFIG_PARITY 0
#endif

// <o> UART_DEFAULT_CONFIG_BAUDRATE - Default Baudrate

// <323584=> 1200 baud
// <643072=> 2400 baud
// <1290240=> 4800 baud
// <2576384=> 9600 baud
// <3862528=> 14400 baud
// <5152768=> 19200 baud
// <7716864=> 28800 baud
// <10289152=> 38400 baud
// <15400960=> 57600 baud
// <20615168=> 76800 baud
// <30801920=> 115200 baud
// <61865984=> 230400 baud
// <67108864=> 250000 baud
// <121634816=> 460800 baud
// <251658240=> 921600 baud
// <268435456=> 1000000 baud

#ifndef UART_DEFAULT_CONFIG_BAUDRATE
#define UART_DEFAULT_CONFIG_BAUDRATE 30801920
#endif

// <o> UART_DEFAULT_CONFIG_IRQ_PRIORITY - Interrupt priority


// <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
// <0=> 0 (highest)
// <1=> 1
// <2=> 2
// <3=> 3
// <4=> 4
// <5=> 5
// <6=> 6
// <7=> 7

#ifndef UART_DEFAULT_CONFIG_IRQ_PRIORITY
#define UART_DEFAULT_CONFIG_IRQ_PRIORITY 6
#endif

// <q> UART_EASY_DMA_SUPPORT - Driver supporting EasyDMA


#ifndef UART_EASY_DMA_SUPPORT
#define UART_EASY_DMA_SUPPORT 1
#endif

// <q> UART_LEGACY_SUPPORT - Driver supporting Legacy mode


#ifndef UART_LEGACY_SUPPORT
#define UART_LEGACY_SUPPORT 0
#endif

// <e> UART0_ENABLED - Enable UART0 instance
//==========================================================
#ifndef UART0_ENABLED
#define UART0_ENABLED 1
#endif

// </e>

// </e>

// <h> nrfx_qspi - QSPI peripheral driver

//==========================================================
Expand Down
Loading

0 comments on commit 8693cd9

Please sign in to comment.