Skip to content

Commit c220e22

Browse files
authored
Merge pull request #3761 from supperthomas/supperthomas
[bsp/nrf5x] add the config of softdevice
2 parents 1a42ca9 + 2446ee8 commit c220e22

File tree

8 files changed

+162
-52
lines changed

8 files changed

+162
-52
lines changed

bsp/nrf5x/libraries/drivers/SConscript

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ if GetDepend(['BSP_USING_QSPI_FLASH']):
1919

2020
if GetDepend(['BSP_USING_SPI']):
2121
src += ['drv_spi.c']
22+
if GetDepend(['BSP_USING_GPIO']):
23+
src += ['drv_gpio.c']
2224

2325
path = [cwd]
2426

bsp/nrf5x/libraries/drivers/drv_gpio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,5 +371,5 @@ int rt_hw_pin_init(void)
371371
}
372372

373373
}
374-
374+
INIT_BOARD_EXPORT(rt_hw_pin_init);
375375
#endif /* RT_USING_PIN */

bsp/nrf5x/nrf52840/.config

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ CONFIG_RT_SERIAL_RB_BUFSZ=64
122122
# CONFIG_RT_USING_I2C is not set
123123
CONFIG_RT_USING_PIN=y
124124
# CONFIG_RT_USING_ADC is not set
125+
# CONFIG_RT_USING_DAC is not set
125126
# CONFIG_RT_USING_PWM is not set
126127
# CONFIG_RT_USING_MTD_NOR is not set
127128
# CONFIG_RT_USING_MTD_NAND is not set
@@ -194,7 +195,9 @@ CONFIG_RT_USING_LIBC=y
194195
#
195196
# IoT - internet of things
196197
#
198+
# CONFIG_PKG_USING_LORAWAN_DRIVER is not set
197199
# CONFIG_PKG_USING_PAHOMQTT is not set
200+
# CONFIG_PKG_USING_UMQTT is not set
198201
# CONFIG_PKG_USING_WEBCLIENT is not set
199202
# CONFIG_PKG_USING_WEBNET is not set
200203
# CONFIG_PKG_USING_MONGOOSE is not set
@@ -240,7 +243,7 @@ CONFIG_RT_USING_LIBC=y
240243
# CONFIG_PKG_USING_GAGENT_CLOUD is not set
241244
# CONFIG_PKG_USING_ALI_IOTKIT is not set
242245
# CONFIG_PKG_USING_AZURE is not set
243-
# CONFIG_PKG_USING_TENCENT_IOTHUB is not set
246+
# CONFIG_PKG_USING_TENCENT_IOT_EXPLORER is not set
244247
# CONFIG_PKG_USING_JIOT-C-SDK is not set
245248
# CONFIG_PKG_USING_UCLOUD_IOT_SDK is not set
246249
# CONFIG_PKG_USING_JOYLINK is not set
@@ -270,6 +273,7 @@ CONFIG_RT_USING_LIBC=y
270273
# CONFIG_PKG_USING_libsodium is not set
271274
# CONFIG_PKG_USING_TINYCRYPT is not set
272275
# CONFIG_PKG_USING_TFM is not set
276+
# CONFIG_PKG_USING_YD_CRYPTO is not set
273277

274278
#
275279
# language packages
@@ -315,12 +319,7 @@ CONFIG_RT_USING_LIBC=y
315319
# CONFIG_PKG_USING_LWEXT4 is not set
316320
# CONFIG_PKG_USING_PARTITION is not set
317321
# CONFIG_PKG_USING_FAL is not set
318-
# CONFIG_PKG_USING_FAL_V00500 is not set
319-
# CONFIG_PKG_USING_FAL_V00400 is not set
320-
# CONFIG_PKG_USING_FAL_V00300 is not set
321-
# CONFIG_PKG_USING_FAL_V00200 is not set
322-
# CONFIG_PKG_USING_FAL_V00100 is not set
323-
# CONFIG_PKG_USING_FAL_LATEST_VERSION is not set
322+
# CONFIG_PKG_USING_FLASHDB is not set
324323
# CONFIG_PKG_USING_SQLITE is not set
325324
# CONFIG_PKG_USING_RTI is not set
326325
# CONFIG_PKG_USING_LITTLEVGL2RTT is not set
@@ -333,6 +332,8 @@ CONFIG_RT_USING_LIBC=y
333332
# CONFIG_PKG_USING_SYSWATCH is not set
334333
# CONFIG_PKG_USING_SYS_LOAD_MONITOR is not set
335334
# CONFIG_PKG_USING_PLCCORE is not set
335+
# CONFIG_PKG_USING_RAMDISK is not set
336+
# CONFIG_PKG_USING_MININI is not set
336337

337338
#
338339
# peripheral libraries and drivers
@@ -352,6 +353,8 @@ CONFIG_RT_USING_LIBC=y
352353
# CONFIG_PKG_USING_LITTLED is not set
353354
# CONFIG_PKG_USING_LKDGUI is not set
354355
# CONFIG_PKG_USING_NRF5X_SDK is not set
356+
# CONFIG_PKG_USING_NRF5X_SDK_V1300 is not set
357+
# CONFIG_PKG_USING_NRF5X_SDK_LATEST_VERSION is not set
355358
CONFIG_PKG_USING_NRFX=y
356359
CONFIG_PKG_NRFX_PATH="/packages/peripherals/nrfx"
357360
CONFIG_PKG_USING_NRFX_V210=y
@@ -381,6 +384,10 @@ CONFIG_PKG_NRFX_VER="v2.1.0"
381384
# CONFIG_PKG_USING_BEEP is not set
382385
# CONFIG_PKG_USING_EASYBLINK is not set
383386
# CONFIG_PKG_USING_PMS_SERIES is not set
387+
# CONFIG_PKG_USING_CAN_YMODEM is not set
388+
# CONFIG_PKG_USING_LORA_RADIO_DRIVER is not set
389+
# CONFIG_PKG_USING_QLED is not set
390+
# CONFIG_PKG_USING_PAJ7620 is not set
384391

385392
#
386393
# miscellaneous packages
@@ -427,12 +434,26 @@ CONFIG_SOC_NRF52840=y
427434
# Onboard Peripheral Drivers
428435
#
429436
# CONFIG_BSP_USING_JLINK_TO_USART is not set
437+
# CONFIG_BSP_USING_QSPI_FLASH is not set
430438

431439
#
432440
# On-chip Peripheral Drivers
433441
#
434-
# CONFIG_BSP_USING_GPIO is not set
435-
# CONFIG_BSP_USING_ON_CHIP_FLASH is not set
442+
CONFIG_BSP_USING_GPIO=y
443+
# CONFIG_BSP_USING_SOFTDEVICE is not set
436444
CONFIG_BSP_USING_UART=y
437445
CONFIG_BSP_USING_UART0=y
446+
CONFIG_BSP_UART0_RX_PIN=8
447+
CONFIG_BSP_UART0_TX_PIN=6
438448
# CONFIG_BSP_USING_UART1 is not set
449+
# CONFIG_BSP_USING_SPI is not set
450+
# CONFIG_BSP_USING_ON_CHIP_FLASH is not set
451+
452+
#
453+
# On-chip flash config
454+
#
455+
CONFIG_MCU_FLASH_START_ADDRESS=0x00000000
456+
CONFIG_MCU_FLASH_SIZE_KB=1024
457+
CONFIG_MCU_SRAM_START_ADDRESS=0x20000000
458+
CONFIG_MCU_SRAM_SIZE_KB=256
459+
CONFIG_MCU_FLASH_PAGE_SIZE=0x1000
Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
11
/*
2-
* File : application.c
3-
* This file is part of RT-Thread RTOS
4-
* COPYRIGHT (C) 2015, RT-Thread Development Team
2+
* Copyright (c) 2006-2020, RT-Thread Development Team
53
*
6-
* The license and distribution terms for this file may be
7-
* found in the file LICENSE in this distribution or at
8-
* http://www.rt-thread.org/license/LICENSE
4+
* SPDX-License-Identifier: Apache-2.0
95
*
106
* Change Logs:
117
* Date Author Notes
12-
* 2015-03-01 Yangfs the first version
13-
* 2015-03-27 Bernard code cleanup.
14-
*/
15-
16-
/**
17-
* @addtogroup NRF52832
8+
* 2020-04-29 supperthomas first version
9+
*
1810
*/
19-
/*@{*/
2011

2112
#include <rtthread.h>
22-
23-
#ifdef RT_USING_FINSH
24-
#include <finsh.h>
25-
#include <shell.h>
26-
#endif
27-
28-
#include <drv_gpio.h>
13+
#include <rtdevice.h>
2914
#define DK_BOARD_LED_1 13
15+
#define DK_BOARD_LED_2 14
3016

3117
int main(void)
3218
{
@@ -44,4 +30,3 @@ int main(void)
4430
return RT_EOK;
4531
}
4632

47-
/*@}*/

bsp/nrf5x/nrf52840/board/Kconfig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,37 @@ menu "On-chip Peripheral Drivers"
5555
bool "Enable GPIO"
5656
select RT_USING_PIN
5757
default y
58+
menuconfig BSP_USING_SOFTDEVICE
59+
bool "Enable NRF SOFTDEVICE"
60+
select PKG_USING_NRF5X_SDK
61+
default n
62+
if BSP_USING_SOFTDEVICE
63+
config NRFX_CLOCK_ENABLED
64+
int "NRFX_CLOCK_ENABLED"
65+
default 1
66+
config NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY
67+
int "NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY"
68+
default 7
69+
config NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY
70+
int "NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY"
71+
default 7
72+
config NRFX_RTC_ENABLED
73+
int "NRFX_RTC_ENABLED"
74+
default 1
75+
config NRF_CLOCK_ENABLED
76+
int "NRF_CLOCK_ENABLED"
77+
default 1
78+
config NRF_SDH_BLE_ENABLED
79+
int "NRF_SDH_BLE_ENABLED"
80+
default 1
81+
config NRF_SDH_ENABLED
82+
int "NRF_SDH_ENABLED"
83+
default 1
84+
config NRF_SDH_SOC_ENABLED
85+
int "NRF_SDH_SOC_ENABLED"
86+
default 1
87+
88+
endif
5889

5990
menuconfig BSP_USING_UART
6091
bool "Enable UART"

bsp/nrf5x/nrf52840/board/board.c

Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
1+
/*
2+
* Copyright (c) 2006-2020, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2020-04-29 supperthomas first version
9+
*
10+
*/
111
#include <rtthread.h>
212
#include <rthw.h>
313
#include <nrfx_systick.h>
414

515
#include "board.h"
6-
#include "drv_gpio.h"
716
#include "drv_uart.h"
17+
#ifdef BSP_USING_SOFTDEVICE
18+
#include <nrfx_rtc.h>
19+
#include <nrfx_clock.h>
20+
#include "app_error.h"
21+
#include "nrf_drv_clock.h"
22+
const nrfx_rtc_t rtc = NRFX_RTC_INSTANCE(1); /**< Declaring an instance of nrf_drv_rtc for RTC0. */
823

9-
void SysTick_Configuration(void)
24+
static void rtc_handler(nrfx_rtc_int_type_t int_type)
1025
{
11-
/* Set interrupt priority */
12-
NVIC_SetPriority(SysTick_IRQn, 0xf);
13-
14-
/* Configure SysTick to interrupt at the requested rate. */
15-
nrf_systick_load_set(SystemCoreClock / RT_TICK_PER_SECOND);
16-
nrf_systick_val_clear();
17-
nrf_systick_csr_set(NRF_SYSTICK_CSR_CLKSOURCE_CPU | NRF_SYSTICK_CSR_TICKINT_ENABLE
18-
| NRF_SYSTICK_CSR_ENABLE);
19-
}
26+
if (int_type == NRFX_RTC_INT_TICK)
27+
{
28+
rt_interrupt_enter();
2029

30+
rt_tick_increase();
31+
32+
rt_interrupt_leave();
33+
}
34+
}
35+
#else
2136
/**
2237
* This is the timer interrupt service routine.
2338
*
@@ -32,27 +47,61 @@ void SysTick_Handler(void)
3247
/* leave interrupt */
3348
rt_interrupt_leave();
3449
}
50+
#endif
51+
void SysTick_Configuration(void)
52+
{
53+
#ifdef BSP_USING_SOFTDEVICE
54+
nrf_drv_clock_init();
55+
nrf_drv_clock_lfclk_request(NULL);
56+
57+
uint32_t err_code;
58+
#define TICK_RATE_HZ RT_TICK_PER_SECOND
59+
#define SYSTICK_CLOCK_HZ ( 32768UL )
3560

61+
#define NRF_RTC_REG NRF_RTC1
62+
/* IRQn used by the selected RTC */
63+
#define NRF_RTC_IRQn RTC1_IRQn
64+
/* Constants required to manipulate the NVIC. */
65+
#define NRF_RTC_PRESCALER ( (uint32_t) (NRFX_ROUNDED_DIV(SYSTICK_CLOCK_HZ, TICK_RATE_HZ) - 1) )
66+
nrfx_rtc_config_t config = NRFX_RTC_DEFAULT_CONFIG;
67+
config.prescaler = NRF_RTC_PRESCALER;
68+
69+
err_code = nrfx_rtc_init(&rtc, &config, rtc_handler);
70+
// APP_ERROR_CHECK(err_code);
71+
nrfx_rtc_tick_enable(&rtc, true);
72+
#define COMPARE_COUNTERTIME (3UL) /**< Get Compare event COMPARE_TIME seconds after the counter starts from 0. */
73+
//Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds
74+
err_code = nrfx_rtc_cc_set(&rtc, 0, COMPARE_COUNTERTIME * 8, true);
75+
// APP_ERROR_CHECK(err_code);
76+
77+
//Power on RTC instance
78+
nrfx_rtc_enable(&rtc);
79+
#else
80+
/* Set interrupt priority */
81+
NVIC_SetPriority(SysTick_IRQn, 0xf);
82+
83+
/* Configure SysTick to interrupt at the requested rate. */
84+
nrf_systick_load_set(SystemCoreClock / RT_TICK_PER_SECOND);
85+
nrf_systick_val_clear();
86+
nrf_systick_csr_set(NRF_SYSTICK_CSR_CLKSOURCE_CPU | NRF_SYSTICK_CSR_TICKINT_ENABLE
87+
| NRF_SYSTICK_CSR_ENABLE);
88+
#endif
89+
}
3690

3791

3892
void rt_hw_board_init(void)
3993
{
94+
rt_hw_interrupt_enable(0);
4095
// sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
4196
/* Activate deep sleep mode */
4297
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
4398

44-
4599
SysTick_Configuration();
46-
100+
47101
#if defined(RT_USING_HEAP)
48102
rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
49103
#endif
50-
51-
/* Pin driver initialization is open by default */
52-
#ifdef RT_USING_PIN
53-
rt_hw_pin_init();
54-
#endif
55-
104+
56105
#ifdef RT_USING_SERIAL
57106
rt_hw_uart_init();
58107
#endif
@@ -65,5 +114,19 @@ void rt_hw_board_init(void)
65114
rt_components_board_init();
66115
#endif
67116

117+
#ifdef BSP_USING_SOFTDEVICE
118+
extern uint32_t Image$$RW_IRAM1$$Base;
119+
uint32_t const *const m_ram_start = &Image$$RW_IRAM1$$Base;
120+
if ((uint32_t)m_ram_start == 0x20000000)
121+
{
122+
rt_kprintf("\r\n using softdevice the RAM couldn't be %p,please use the templete from package\r\n", m_ram_start);
123+
while (1);
124+
}
125+
else
126+
{
127+
rt_kprintf("\r\n using softdevice the RAM at %p\r\n", m_ram_start);
128+
}
129+
#endif
130+
68131
}
69132

bsp/nrf5x/nrf52840/board/sdk_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#endif
4949
// <h> nRF_BLE
5050

51+
#include <rtconfig.h>
5152
//==========================================================
5253
// <q> BLE_ADVERTISING_ENABLED - ble_advertising - Advertising module
5354

@@ -11694,7 +11695,6 @@
1169411695
#endif
1169511696
// </e>
1169611697

11697-
// </h>
1169811698
//==========================================================
1169911699
#ifndef NRFX_SYSTICK_ENABLED
1170011700
#define NRFX_SYSTICK_ENABLED 1

bsp/nrf5x/nrf52840/rtconfig.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,21 @@
155155

156156
/* Onboard Peripheral Drivers */
157157

158-
#define BSP_USING_JLINK_TO_USART
159158

160159
/* On-chip Peripheral Drivers */
161160

161+
#define BSP_USING_GPIO
162162
#define BSP_USING_UART
163163
#define BSP_USING_UART0
164164
#define BSP_UART0_RX_PIN 8
165165
#define BSP_UART0_TX_PIN 6
166166

167+
/* On-chip flash config */
168+
169+
#define MCU_FLASH_START_ADDRESS 0x00000000
170+
#define MCU_FLASH_SIZE_KB 1024
171+
#define MCU_SRAM_START_ADDRESS 0x20000000
172+
#define MCU_SRAM_SIZE_KB 256
173+
#define MCU_FLASH_PAGE_SIZE 0x1000
174+
167175
#endif

0 commit comments

Comments
 (0)