Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/nrf{53,9160}: add periph_rtt support #19804

Merged
merged 4 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boards/nrf5340dk-app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ config BOARD_NRF5340DK_APP
bool
default y
select CPU_MODEL_NRF5340_APP
select HAS_PERIPH_RTT
select HAS_PERIPH_TIMER
select HAS_PERIPH_UART
select HAS_PERIPH_UART_HW_FC
Expand Down
1 change: 1 addition & 0 deletions boards/nrf5340dk-app/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CPU_MODEL = nrf5340_app
CPU = nrf53

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_rtt
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += periph_uart_hw_fc
18 changes: 18 additions & 0 deletions boards/nrf5340dk-app/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ static const uart_conf_t uart_config[] = {
#define UART_NUMOF ARRAY_SIZE(uart_config) /**< UART configuration NUMOF */
/** @} */

/**
* @name Real time counter configuration
* @{
*/
#ifndef RTT_DEV
#define RTT_DEV (0) /**< NRF_RTC0_S */
#endif

#define RTT_MAX_VALUE (0x00ffffff) /**< 24bit */
#define RTT_MAX_FREQUENCY (32768U) /**< in Hz */
#define RTT_MIN_FREQUENCY (8U) /**< in Hz */
#define RTT_CLOCK_FREQUENCY (32768U) /**< in Hz, LFCLK*/

#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1024U) /**< in Hz */
#endif
/** @} */

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions boards/nrf9160dk/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ config BOARD_NRF9160DK
default y
select CPU_MODEL_NRF9160
select HAS_PERIPH_I2C
select HAS_PERIPH_RTT
select HAS_PERIPH_SPI
select HAS_PERIPH_TIMER
select HAS_PERIPH_UART
Expand Down
1 change: 1 addition & 0 deletions boards/nrf9160dk/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CPU = nrf9160

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_rtt
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart
Expand Down
18 changes: 18 additions & 0 deletions boards/nrf9160dk/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ static const uart_conf_t uart_config[] = {
#define UART_NUMOF ARRAY_SIZE(uart_config) /**< UART confgiguration NUMOF */
/** @} */

/**
* @name Real time counter configuration
* @{
*/
#ifndef RTT_DEV
#define RTT_DEV (0) /**< NRF_RTC0_S */
#endif

#define RTT_MAX_VALUE (0x00ffffff) /**< 24bit */
#define RTT_MAX_FREQUENCY (32768U) /**< in Hz */
#define RTT_MIN_FREQUENCY (8U) /**< in Hz */
#define RTT_CLOCK_FREQUENCY (32768U) /**< in Hz, LFCLK*/

#ifndef RTT_FREQUENCY
#define RTT_FREQUENCY (1024U) /**< in Hz */
#endif
/** @} */

#ifdef __cplusplus
}
#endif
Expand Down
7 changes: 7 additions & 0 deletions cpu/nrf53/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ static_assert((CLOCK_CORECLOCK == MHZ(128)) || CLOCK_CORECLOCK == MHZ(64));
/* For now, disable the unused network core */
NRF_RESET_S->NETWORK.FORCEOFF = 1;

#if defined(MODULE_PERIPH_RTT) && (CLOCK_LFCLK==CLOCK_LFCLKSRC_SRC_LFXO)
/* Enable P0.00 and P0.01 as XL1/XL2 if LXFO is selected */
NRF_P0_S->PIN_CNF[0] &= ~GPIO_PIN_CNF_MCUSEL_Msk;
NRF_P0_S->PIN_CNF[0] |= GPIO_PIN_CNF_MCUSEL_Peripheral << GPIO_PIN_CNF_MCUSEL_Pos;
NRF_P0_S->PIN_CNF[1] &= ~GPIO_PIN_CNF_MCUSEL_Msk;
NRF_P0_S->PIN_CNF[1] |= GPIO_PIN_CNF_MCUSEL_Peripheral << GPIO_PIN_CNF_MCUSEL_Pos;
#endif
/* call cortexm default initialization */
cortexm_init();

Expand Down
14 changes: 14 additions & 0 deletions cpu/nrf5x_common/periph/rtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@
#include "periph/rtt.h"

/* get the IRQ configuration */
#ifdef NRF_RTC0_S
#if (RTT_DEV == 0)
#define DEV NRF_RTC0_S
#define ISR isr_rtc0
#define IRQn RTC0_IRQn
#elif (RTT_DEV == 1)
#define DEV NRF_RTC1_S
#define ISR isr_rtc1
#define IRQn RTC1_IRQn
#else
#error "RTT configuration: invalid or no RTC device specified (RTT_DEV)"
#endif
#else
#if (RTT_DEV == 1)
#define DEV NRF_RTC1
#define ISR isr_rtc1
Expand All @@ -37,6 +50,7 @@
#else
#error "RTT configuration: invalid or no RTC device specified (RTT_DEV)"
#endif
#endif /* def NRF_RTC0_S */

/* allocate memory for callbacks and their args */
static rtt_cb_t alarm_cb;
Expand Down