From 5cc9f45a3e74f3337a54c0b93d667a462c9a129f Mon Sep 17 00:00:00 2001 From: supperthomas <78900636@qq.com> Date: Sat, 12 Sep 2020 17:20:22 +0800 Subject: [PATCH 1/4] [bsp/nrf5x]:add nimble and fix kconfig --- bsp/nrf5x/nrf52840/board/Kconfig | 128 +++++++------------------------ bsp/nrf5x/nrf52840/board/board.c | 53 ++----------- 2 files changed, 36 insertions(+), 145 deletions(-) diff --git a/bsp/nrf5x/nrf52840/board/Kconfig b/bsp/nrf5x/nrf52840/board/Kconfig index 09ec92dff4..7cdd0b4a7f 100644 --- a/bsp/nrf5x/nrf52840/board/Kconfig +++ b/bsp/nrf5x/nrf52840/board/Kconfig @@ -6,6 +6,12 @@ config SOC_NRF52840 select RT_USING_COMPONENTS_INIT select RT_USING_USER_MAIN default y + config NRFX_CLOCK_ENABLED + int + default 1 + config NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY + int + default 7 config SOC_NORDIC bool @@ -177,106 +183,7 @@ menu "On-chip Peripheral Drivers" default 16 endif endif - menuconfig BSP_USING_SOFTDEVICE - bool "Enable NRF SOFTDEVICE" - select PKG_USING_NRF5X_SDK - select NRFX_CLOCK_ENABLED - default n -if BSP_USING_SOFTDEVICE - config NRFX_CLOCK_ENABLED - int - default 1 - config NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY - int - default 7 - config NRFX_RTC_ENABLED - int - default 1 - config NRFX_RTC1_ENABLED - int - default 1 - config NRF_CLOCK_ENABLED - int - default 1 - config NRF_SDH_BLE_ENABLED - int - default 1 - config NRF_SDH_ENABLED - int - default 1 - config NRF_SDH_SOC_ENABLED - int - default 1 - config NRF_SDH_BLE_PERIPHERAL_LINK_COUNT - int - default 1 - config BLE_ADVERTISING_ENABLED - int - default 1 - config NRF_BLE_QWR_ENABLED - int - default 1 - config NRF_SDH_BLE_VS_UUID_COUNT - int - default 1 - config NRF_BLE_CONN_PARAMS_ENABLED - int - default 1 - config NRF_BLE_CONN_PARAMS_MAX_SLAVE_LATENCY_DEVIATION - int - default 499 - config NRF_BLE_CONN_PARAMS_MAX_SUPERVISION_TIMEOUT_DEVIATION - int - default 65535 - config NRF_BLE_GATT_ENABLED - int - default 1 - choice - prompt "sample(softdevice)" - default SD_BLE_APP_BEACON - - config SD_BLE_APP_BEACON - bool "ble_app_beacon" - default n - - config SD_BLE_APP_BLINKY - bool "ble_app_blinky" - default n - if SD_BLE_APP_BLINKY - config BLE_LBS_ENABLED - int - default 1 - endif - - config SD_BLE_APP_UART - bool "ble_app_uart" - default n - if SD_BLE_APP_UART - config BLE_NUS_ENABLED - int - default 1 - config NRF_SDH_BLE_GATT_MAX_MTU_SIZE - int - default 247 - endif - - config SD_BLE_APP_HRS - bool "ble_app_hrs" - default n - if SD_BLE_APP_HRS - config BLE_HRS_ENABLED - int - default 1 - config NRF_SDH_BLE_GATT_MAX_MTU_SIZE - int - default 247 - endif - config SD_BLE_APP_HIDS_MOUSE - bool "ble_app_hids_mouse" - default n - endchoice -endif menuconfig BSP_USING_UART bool "Enable UART" @@ -422,4 +329,27 @@ endif endif endmenu + +choice +prompt "BLE STACK" +default BLE_STACK_USING_NULL +help + Select the ble stack + +config BLE_STACK_USING_NULL + bool "not use the ble stack" + +config BSP_USING_SOFTDEVICE + select PKG_USING_NRF5X_SDK + bool "Nordic softdevice(perpheral)" + +config BSP_USING_NIMBLE + select PKG_USING_NIMBLE + select PKG_NIMBLE_BSP_NRF52840 + bool "use nimble stack(iot)" +endchoice + + endmenu + + diff --git a/bsp/nrf5x/nrf52840/board/board.c b/bsp/nrf5x/nrf52840/board/board.c index d1e55f4c49..2ba3214bfa 100644 --- a/bsp/nrf5x/nrf52840/board/board.c +++ b/bsp/nrf5x/nrf52840/board/board.c @@ -14,25 +14,8 @@ #include "board.h" #include "drv_uart.h" -#ifdef BSP_USING_SOFTDEVICE -#include #include -#include "app_error.h" -#include "nrf_drv_clock.h" -const nrfx_rtc_t rtc = NRFX_RTC_INSTANCE(1); /**< Declaring an instance of nrf_drv_rtc for RTC0. */ -static void rtc_handler(nrfx_rtc_int_type_t int_type) -{ - if (int_type == NRFX_RTC_INT_TICK) - { - rt_interrupt_enter(); - - rt_tick_increase(); - - rt_interrupt_leave(); - } -} -#else /** * This is the timer interrupt service routine. * @@ -47,36 +30,14 @@ void SysTick_Handler(void) /* leave interrupt */ rt_interrupt_leave(); } -#endif + +static void clk_event_handler(nrfx_clock_evt_type_t event){} + void SysTick_Configuration(void) { -#ifdef BSP_USING_SOFTDEVICE - nrf_drv_clock_init(); - nrf_drv_clock_lfclk_request(NULL); - - uint32_t err_code; -#define TICK_RATE_HZ RT_TICK_PER_SECOND -#define SYSTICK_CLOCK_HZ ( 32768UL ) - -#define NRF_RTC_REG NRF_RTC1 - /* IRQn used by the selected RTC */ -#define NRF_RTC_IRQn RTC1_IRQn - /* Constants required to manipulate the NVIC. */ -#define NRF_RTC_PRESCALER ( (uint32_t) (NRFX_ROUNDED_DIV(SYSTICK_CLOCK_HZ, TICK_RATE_HZ) - 1) ) - nrfx_rtc_config_t config = NRFX_RTC_DEFAULT_CONFIG; - config.prescaler = NRF_RTC_PRESCALER; - - err_code = nrfx_rtc_init(&rtc, &config, rtc_handler); - // APP_ERROR_CHECK(err_code); - nrfx_rtc_tick_enable(&rtc, true); -#define COMPARE_COUNTERTIME (3UL) /**< Get Compare event COMPARE_TIME seconds after the counter starts from 0. */ - //Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds - err_code = nrfx_rtc_cc_set(&rtc, 0, COMPARE_COUNTERTIME * 8, true); - // APP_ERROR_CHECK(err_code); - - //Power on RTC instance - nrfx_rtc_enable(&rtc); -#else + nrfx_clock_init(clk_event_handler); + nrfx_clock_enable(); + nrfx_clock_lfclk_start(); /* Set interrupt priority */ NVIC_SetPriority(SysTick_IRQn, 0xf); @@ -85,7 +46,7 @@ void SysTick_Configuration(void) nrf_systick_val_clear(); nrf_systick_csr_set(NRF_SYSTICK_CSR_CLKSOURCE_CPU | NRF_SYSTICK_CSR_TICKINT_ENABLE | NRF_SYSTICK_CSR_ENABLE); -#endif + } From e7351c6f49a8e61e874bc5be07d033f7d4695a26 Mon Sep 17 00:00:00 2001 From: supperthomas <78900636@qq.com> Date: Sat, 12 Sep 2020 21:00:28 +0800 Subject: [PATCH 2/4] [bsp/nrf5x] fix the template --- bsp/nrf5x/nrf52840/template.uvoptx | 2 +- bsp/nrf5x/nrf52840/template.uvprojx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bsp/nrf5x/nrf52840/template.uvoptx b/bsp/nrf5x/nrf52840/template.uvoptx index f567bf47e8..f948795a16 100644 --- a/bsp/nrf5x/nrf52840/template.uvoptx +++ b/bsp/nrf5x/nrf52840/template.uvoptx @@ -120,7 +120,7 @@ 0 JL2CM3 - -U683349164 -O78 -S2 -ZTIFSpeedSel5000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8004 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC4000 -FN2 -FF0nrf52xxx.flm -FS00 -FL0200000 -FP0($$Device:nRF52840_xxAA$Flash\nrf52xxx.flm) -FF1nrf52xxx_uicr.flm -FS110001000 -FL11000 -FP1($$Device:nRF52840_xxAA$Flash\nrf52xxx_uicr.flm) + -U683349164 -O78 -S2 -ZTIFSpeedSel5000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8004 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC4000 -FN2 -FF0nrf52xxx_uicr.flm -FS010001000 -FL01000 -FP0($$Device:nRF52840_xxAA$Flash\nrf52xxx_uicr.flm) -FF1nrf52xxx_sde -FS10 -FL1200000 -FP1($$Device:nRF52840_xxAA$Flash\nrf52xxx_sde.flm) 0 diff --git a/bsp/nrf5x/nrf52840/template.uvprojx b/bsp/nrf5x/nrf52840/template.uvprojx index 62c5997a13..10b169333d 100644 --- a/bsp/nrf5x/nrf52840/template.uvprojx +++ b/bsp/nrf5x/nrf52840/template.uvprojx @@ -16,7 +16,7 @@ nRF52840_xxAA Nordic Semiconductor - NordicSemiconductor.nRF_DeviceFamilyPack.8.32.1 + NordicSemiconductor.nRF_DeviceFamilyPack.8.27.1 http://developer.nordicsemi.com/nRF5_SDK/pieces/nRF_DeviceFamilyPack/ IRAM(0x20000000,0x40000) IROM(0x00000000,0x100000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE From 912d9cda3777129cc095452761f42f6139b72f00 Mon Sep 17 00:00:00 2001 From: supperthomas <78900636@qq.com> Date: Sat, 12 Sep 2020 22:09:23 +0800 Subject: [PATCH 3/4] [bsp/nrf5x] fix the kconfig --- bsp/nrf5x/nrf52840/board/Kconfig | 19 +++++++++++++++++++ bsp/nrf5x/nrf52840/board/sdk_config.h | 8 ++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/bsp/nrf5x/nrf52840/board/Kconfig b/bsp/nrf5x/nrf52840/board/Kconfig index 7cdd0b4a7f..1a3fd7d8ba 100644 --- a/bsp/nrf5x/nrf52840/board/Kconfig +++ b/bsp/nrf5x/nrf52840/board/Kconfig @@ -12,7 +12,11 @@ config SOC_NRF52840 config NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY int default 7 + config NRFX_CLOCK_CONFIG_LF_SRC + int + default 1 + config SOC_NORDIC bool config SOC_NORDIC @@ -69,6 +73,11 @@ menu "On-chip Peripheral Drivers" bool "Enable GPIO" select RT_USING_PIN default y + if BSP_USING_GPIO + config NRFX_GPIOTE_ENABLED + int + default 1 + endif config BSP_USING_SAADC bool "Enable SAADC" select RT_USING_ADC @@ -191,10 +200,17 @@ menu "On-chip Peripheral Drivers" select RT_USING_SERIAL if BSP_USING_UART + config NRFX_UART_ENABLED + int + default 1 + config BSP_USING_UART0 bool "Enable UART0" default y if BSP_USING_UART0 + config NRFX_UART0_ENABLED + int + default 1 config BSP_UART0_RX_PIN int "uart0 rx pin number" range 0 31 @@ -215,6 +231,9 @@ menu "On-chip Peripheral Drivers" default y if BSP_USING_SPI + config NRFX_SPI_ENABLED + int + default 1 config BSP_USING_SPI0 bool "Enable SPI0 bus" default y diff --git a/bsp/nrf5x/nrf52840/board/sdk_config.h b/bsp/nrf5x/nrf52840/board/sdk_config.h index 172e0ccc2c..bdc0abd4a9 100644 --- a/bsp/nrf5x/nrf52840/board/sdk_config.h +++ b/bsp/nrf5x/nrf52840/board/sdk_config.h @@ -1899,7 +1899,7 @@ // NRFX_GPIOTE_ENABLED - nrfx_gpiote - GPIOTE peripheral driver //========================================================== #ifndef NRFX_GPIOTE_ENABLED -#define NRFX_GPIOTE_ENABLED 1 +#define NRFX_GPIOTE_ENABLED 0 #endif // NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS - Number of lower power input pins #ifndef NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS @@ -2903,7 +2903,7 @@ // NRFX_QSPI_ENABLED - nrfx_qspi - QSPI peripheral driver //========================================================== #ifndef NRFX_QSPI_ENABLED -#define NRFX_QSPI_ENABLED 1 +#define NRFX_QSPI_ENABLED 0 #endif // NRFX_QSPI_CONFIG_SCK_DELAY - tSHSL, tWHSL and tSHWL in number of 16 MHz periods (62.5 ns). <0-255> @@ -4382,11 +4382,11 @@ // NRFX_UART_ENABLED - nrfx_uart - UART peripheral driver //========================================================== #ifndef NRFX_UART_ENABLED -#define NRFX_UART_ENABLED 1 +#define NRFX_UART_ENABLED 0 #endif // NRFX_UART0_ENABLED - Enable UART0 instance #ifndef NRFX_UART0_ENABLED -#define NRFX_UART0_ENABLED 1 +#define NRFX_UART0_ENABLED 0 #endif // NRFX_UART_DEFAULT_CONFIG_HWFC - Hardware Flow Control From c47d9f13f257983fcbb2909fe078cf7d472efe79 Mon Sep 17 00:00:00 2001 From: supperthomas <78900636@qq.com> Date: Wed, 16 Sep 2020 22:12:41 +0800 Subject: [PATCH 4/4] fix the template --- bsp/nrf5x/nrf52840/template.uvoptx | 2 +- bsp/nrf5x/nrf52840/template.uvprojx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bsp/nrf5x/nrf52840/template.uvoptx b/bsp/nrf5x/nrf52840/template.uvoptx index f948795a16..f567bf47e8 100644 --- a/bsp/nrf5x/nrf52840/template.uvoptx +++ b/bsp/nrf5x/nrf52840/template.uvoptx @@ -120,7 +120,7 @@ 0 JL2CM3 - -U683349164 -O78 -S2 -ZTIFSpeedSel5000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8004 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC4000 -FN2 -FF0nrf52xxx_uicr.flm -FS010001000 -FL01000 -FP0($$Device:nRF52840_xxAA$Flash\nrf52xxx_uicr.flm) -FF1nrf52xxx_sde -FS10 -FL1200000 -FP1($$Device:nRF52840_xxAA$Flash\nrf52xxx_sde.flm) + -U683349164 -O78 -S2 -ZTIFSpeedSel5000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8004 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC4000 -FN2 -FF0nrf52xxx.flm -FS00 -FL0200000 -FP0($$Device:nRF52840_xxAA$Flash\nrf52xxx.flm) -FF1nrf52xxx_uicr.flm -FS110001000 -FL11000 -FP1($$Device:nRF52840_xxAA$Flash\nrf52xxx_uicr.flm) 0 diff --git a/bsp/nrf5x/nrf52840/template.uvprojx b/bsp/nrf5x/nrf52840/template.uvprojx index 10b169333d..62c5997a13 100644 --- a/bsp/nrf5x/nrf52840/template.uvprojx +++ b/bsp/nrf5x/nrf52840/template.uvprojx @@ -16,7 +16,7 @@ nRF52840_xxAA Nordic Semiconductor - NordicSemiconductor.nRF_DeviceFamilyPack.8.27.1 + NordicSemiconductor.nRF_DeviceFamilyPack.8.32.1 http://developer.nordicsemi.com/nRF5_SDK/pieces/nRF_DeviceFamilyPack/ IRAM(0x20000000,0x40000) IROM(0x00000000,0x100000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE