Skip to content

Commit 2446ee8

Browse files
committed
[bsp/nrf5x] add the softdevice config
1 parent ebba4e1 commit 2446ee8

File tree

6 files changed

+124
-42
lines changed

6 files changed

+124
-42
lines changed

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ CONFIG_RT_USING_LIBC=y
353353
# CONFIG_PKG_USING_LITTLED is not set
354354
# CONFIG_PKG_USING_LKDGUI is not set
355355
# 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
356358
CONFIG_PKG_USING_NRFX=y
357359
CONFIG_PKG_NRFX_PATH="/packages/peripherals/nrfx"
358360
CONFIG_PKG_USING_NRFX_V210=y
@@ -438,6 +440,7 @@ CONFIG_SOC_NRF52840=y
438440
# On-chip Peripheral Drivers
439441
#
440442
CONFIG_BSP_USING_GPIO=y
443+
# CONFIG_BSP_USING_SOFTDEVICE is not set
441444
CONFIG_BSP_USING_UART=y
442445
CONFIG_BSP_USING_UART0=y
443446
CONFIG_BSP_UART0_RX_PIN=8
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

0 commit comments

Comments
 (0)