Skip to content

Commit

Permalink
Merge pull request #337 from aabadie/trustzone_non_secure_support
Browse files Browse the repository at this point in the history
bsp: add support for non secure peripherals on application core
  • Loading branch information
aabadie authored Nov 14, 2024
2 parents ac7716d + 5c3a51b commit 1e19318
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 55 deletions.
6 changes: 3 additions & 3 deletions bsp/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
*/

#if defined(NRF5340_XXAA)
#if defined(NRF_APPLICATION)
#define NRF_CLOCK NRF_CLOCK_S
#else
#if defined(NRF_NETWORK) || defined(NRF_TRUSTZONE_NONSECURE)
#define NRF_CLOCK NRF_CLOCK_NS
#else
#define NRF_CLOCK NRF_CLOCK_S
#endif
#endif

Expand Down
18 changes: 13 additions & 5 deletions bsp/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,24 @@

//=========================== defines ==========================================

#if defined(NRF5340_XXAA) && defined(NRF_APPLICATION)
#if defined(NRF5340_XXAA)
#if defined(NRF_NETWORK)
#define NRF_P0 NRF_P0_NS
#define NRF_P1 NRF_P1_NS
#define NRF_GPIOTE NRF_GPIOTE_NS
#elif defined(NRF_APPLICATION) && defined(NRF_TRUSTZONE_NONSECURE)
#define NRF_P0 NRF_P0_NS
#define NRF_P1 NRF_P1_NS
#define NRF_GPIOTE NRF_GPIOTE1_NS
#define GPIOTE_IRQn GPIOTE1_IRQn
#define GPIOTE_IRQHandler GPIOTE1_IRQHandler
#elif defined(NRF_APPLICATION)
#define NRF_P0 NRF_P0_S
#define NRF_P1 NRF_P1_S
#define NRF_GPIOTE NRF_GPIOTE0_S
#define GPIOTE_IRQn GPIOTE0_IRQn
#define GPIOTE_IRQHandler GPIOTE0_IRQHandler
#elif defined(NRF5340_XXAA) && defined(NRF_NETWORK)
#define NRF_P0 NRF_P0_NS
#define NRF_P1 NRF_P1_NS
#define NRF_GPIOTE NRF_GPIOTE_NS
#endif
#endif

/**
Expand Down
12 changes: 8 additions & 4 deletions bsp/nrf/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@ void _wait_for_transfer(i2c_t i2c);
static const i2c_conf_t _devs[TWIM_COUNT] = {
#if defined(NRF5340_XXAA)
{
#if defined(NRF_APPLICATION)
.p = NRF_TWIM0_S,
#else
#if defined(NRF_NETWORK) || defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_TWIM0_NS,
#else
.p = NRF_TWIM0_S,
#endif
.irq = SERIAL0_IRQn,
},
#if defined(NRF_APPLICATION)
{
.p = NRF_TWIM1_S,
#if defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_TWIM1_NS,
#else
.p = NRF_TWIM1_S,
#endif
.irq = SERIAL1_IRQn,
},
#endif
Expand Down
12 changes: 9 additions & 3 deletions bsp/nrf/lh2_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@
#endif

#if defined(NRF5340_XXAA) && defined(NRF_APPLICATION)
#define NRF_SPIM NRF_SPIM4_S
#if defined(NRF_TRUSTZONE_NONSECURE)
#define NRF_SPIM NRF_SPIM4_NS
#define NRF_GPIOTE NRF_GPIOTE0_NS
#define NRF_PPI NRF_DPPIC_NS
#else
#define NRF_SPIM NRF_SPIM4_S
#define NRF_GPIOTE NRF_GPIOTE0_S
#define NRF_PPI NRF_DPPIC_S
#endif
#define SPIM_IRQ SPIM4_IRQn
#define SPIM_IRQ_HANDLER SPIM4_IRQHandler
#define NRF_GPIOTE NRF_GPIOTE0_S
#define NRF_PPI NRF_DPPIC_S
#else
#define NRF_SPIM NRF_SPIM3
#define SPIM_IRQ SPIM3_IRQn
Expand Down
8 changes: 5 additions & 3 deletions bsp/nrf/nvmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

//=========================== defines =========================================

#if defined(NRF5340_XXAA) && defined(NRF_APPLICATION)
#define NRF_NVMC NRF_NVMC_S
#elif defined(NRF5340_XXAA) && defined(NRF_NETWORK)
#if defined(NRF5340_XXAA)
#if defined(NRF_NETWORK) || defined(NRF_TRUSTZONE_NONSECURE)
#define NRF_NVMC NRF_NVMC_NS
#elif defined(NRF_APPLICATION)
#define NRF_NVMC NRF_NVMC_S
#endif
#endif

//=========================== public ==========================================
Expand Down
8 changes: 5 additions & 3 deletions bsp/nrf/partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@

//=========================== defines =========================================

#if defined(NRF5340_XXAA) && defined(NRF_APPLICATION)
#define NRF_NVMC NRF_NVMC_S
#elif defined(NRF5340_XXAA) && defined(NRF_NETWORK)
#if defined(NRF5340_XXAA)
#if defined(NRF_NETWORK) || defined(NRF_TRUSTZONE_NONSECURE)
#define NRF_NVMC NRF_NVMC_NS
#elif defined(NRF_APPLICATION)
#define NRF_NVMC NRF_NVMC_S
#endif
#endif

#define DB_PARTITIONS_TABLE_ADDRESS (0x00001000UL + DB_FLASH_OFFSET)
Expand Down
9 changes: 8 additions & 1 deletion bsp/nrf/pwm_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,18 @@ typedef struct {
//=========================== variables ========================================

static NRF_PWM_Type *_pwm_devs[PWM_COUNT] = {
#if defined(NRF5340_XXAA) && defined(NRF_APPLICATION)
#if defined(NRF5340_XXAA)
#if defined(NRF_TRUSTZONE_NONSECURE)
NRF_PWM0_NS,
NRF_PWM1_NS,
NRF_PWM2_NS,
NRF_PWM3_NS,
#else
NRF_PWM0_S,
NRF_PWM1_S,
NRF_PWM2_S,
NRF_PWM3_S,
#endif
#else
NRF_PWM0,
NRF_PWM1,
Expand Down
5 changes: 5 additions & 0 deletions bsp/nrf/qdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ typedef struct {

static qdec_vars_t _qdec_vars[QDEC_COUNT];
static NRF_QDEC_Type *_qdec_devs[QDEC_COUNT] = {
#if defined(NRF_TRUSTZONE_NONSECURE)
NRF_QDEC0_NS,
NRF_QDEC1_NS
#else
NRF_QDEC0_S,
NRF_QDEC1_S
#endif
};

//=========================== public ===========================================
Expand Down
6 changes: 3 additions & 3 deletions bsp/nrf/qspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
//=========================== defines ==========================================

#if defined(NRF5340_XXAA)
#if defined(NRF_APPLICATION)
#define DB_QSPI (NRF_QSPI_S) ///< QSPI peripheral used
#elif defined(NRF_NETWORK)
#if defined(NRF_TRUSTZONE_NONSECURE)
#define DB_QSPI (NRF_QSPI_NS) ///< QSPI peripheral used
#else
#define DB_QSPI (NRF_QSPI_S) ///< QSPI peripheral used
#endif
#else
#define DB_QSPI (NRF_QSPI) ///< QSPI peripheral
Expand Down
12 changes: 7 additions & 5 deletions bsp/nrf/rpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@

//=========================== defines ==========================================

#if defined(NRF5340_XXAA) && defined(NRF_APPLICATION)
#if defined(NRF5340_XXAA)
#if defined(NRF_NETWORK) || defined(NRF_TRUSTZONE_NONSECURE)
#define NRF_TIMER0 NRF_TIMER0_NS
#define NRF_TIMER1 NRF_TIMER1_NS
#define NRF_PPI NRF_DPPIC_NS
#elif defined(NRF_APPLICATION)
#define NRF_GPIOTE NRF_GPIOTE0_S
#define NRF_TIMER0 NRF_TIMER0_S
#define NRF_TIMER1 NRF_TIMER1_S
#define NRF_PPI NRF_DPPIC_S
#elif defined(NRF5340_XXAA) && defined(NRF_NETWORK)
#define NRF_TIMER0 NRF_TIMER0_NS
#define NRF_TIMER1 NRF_TIMER1_NS
#define NRF_PPI NRF_DPPIC_NS
#endif
#endif

#define RPM_LEFT_TIMER (NRF_TIMER0) ///< Timer peripheral used to count left cycles
Expand Down
6 changes: 3 additions & 3 deletions bsp/nrf/saadc.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
//=========================== defines ==========================================

#if defined(NRF5340_XXAA)
#if defined(NRF_APPLICATION)
#define NRF_SAADC NRF_SAADC_S
#else
#if defined(NRF_TRUSTZONE_NONSECURE)
#define NRF_SAADC NRF_SAADC_NS
#else
#define NRF_SAADC NRF_SAADC_S
#endif
#endif

Expand Down
30 changes: 23 additions & 7 deletions bsp/nrf/spim.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,44 @@ typedef struct {
static const spim_conf_t _devs[SPIM_COUNT] = {
#if defined(NRF5340_XXAA)
{
#if defined(NRF_APPLICATION)
.p = NRF_SPIM0_S,
#else
#if defined(NRF_NETWORK) || defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_SPIM0_NS,
#else
.p = NRF_SPIM0_S,
#endif
.irq = SERIAL0_IRQn,
},
#if defined(NRF_APPLICATION)
{
.p = NRF_SPIM1_S,
#if defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_SPIM1_NS,
#else
.p = NRF_SPIM1_S,
#endif
.irq = SERIAL1_IRQn,
},
{
.p = NRF_SPIM2_S,
#if defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_SPIM2_NS,
#else
.p = NRF_SPIM2_S,
#endif
.irq = SERIAL2_IRQn,
},
{
.p = NRF_SPIM3_S,
#if defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_SPIM3_NS,
#else
.p = NRF_SPIM3_S,
#endif
.irq = SERIAL3_IRQn,
},
{
.p = NRF_SPIM4_S,
#if defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_SPIM4_NS,
#else
.p = NRF_SPIM4_S,
#endif
.irq = SPIM4_IRQn,
},
#endif
Expand Down
14 changes: 8 additions & 6 deletions bsp/nrf/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ static uint32_t _ms_to_ticks(uint32_t ms);
static const timer_conf_t _devs[RTC_COUNT] = {
#if defined(NRF5340_XXAA)
{
#if defined(NRF_APPLICATION)
.p = NRF_RTC0_S,
#else
#if defined(NRF_NETWORK) || defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_RTC0_NS,
#else
.p = NRF_RTC0_S,
#endif
.irq = RTC0_IRQn,
.cc_num = RTC0_CC_NUM - 1,
},
{
#if defined(NRF_APPLICATION)
.p = NRF_RTC1_S,
#else
#if defined(NRF_NETWORK) || defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_RTC1_NS,
#else
.p = NRF_RTC1_S,
#endif
.irq = RTC1_IRQn,
.cc_num = RTC1_CC_NUM - 1,
Expand Down Expand Up @@ -90,8 +90,10 @@ void db_timer_init(timer_t timer) {
// No delay is running after initialization
_timer_vars[timer].running = false;

#if !defined(USE_SWARMIT)
// Configure and start Low Frequency clock
db_lfclk_init();
#endif

// Configure the RTC
_devs[timer].p->TASKS_STOP = 1;
Expand Down
8 changes: 5 additions & 3 deletions bsp/nrf/timer_hf.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef struct {
static const timer_hf_conf_t _devs[TIMER_COUNT] = {
#if defined(NRF5340_XXAA)
{
#if defined(NRF_NETWORK)
#if defined(NRF_NETWORK) || defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_TIMER0_NS,
#else
.p = NRF_TIMER0_S,
Expand All @@ -51,7 +51,7 @@ static const timer_hf_conf_t _devs[TIMER_COUNT] = {
.cc_num = TIMER0_CC_NUM - 1,
},
{
#if defined(NRF_NETWORK)
#if defined(NRF_NETWORK) || defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_TIMER1_NS,
#else
.p = NRF_TIMER1_S,
Expand All @@ -60,7 +60,7 @@ static const timer_hf_conf_t _devs[TIMER_COUNT] = {
.cc_num = TIMER1_CC_NUM - 1,
},
{
#if defined(NRF_NETWORK)
#if defined(NRF_NETWORK) || defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_TIMER2_NS,
#else
.p = NRF_TIMER2_S,
Expand Down Expand Up @@ -105,8 +105,10 @@ void db_timer_hf_init(timer_hf_t timer) {
// No delay is running after initialization
_timer_hf_vars[timer].running = false;

#if !defined(USE_SWARMIT)
// Configure and start High Frequency clock
db_hfclk_init();
#endif

// Configure the timer
_devs[timer].p->TASKS_CLEAR = 1;
Expand Down
24 changes: 20 additions & 4 deletions bsp/nrf/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,35 @@ typedef struct {
static const uart_conf_t _devs[UARTE_COUNT] = {
#if defined(NRF5340_XXAA) && defined(NRF_APPLICATION)
{
.p = NRF_UARTE0_S,
#if defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_UARTE0_NS,
#else
.p = NRF_UARTE0_S,
#endif
.irq = SERIAL0_IRQn,
},
{
.p = NRF_UARTE1_S,
#if defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_UARTE1_NS,
#else
.p = NRF_UARTE1_S,
#endif
.irq = SERIAL1_IRQn,
},
{
.p = NRF_UARTE2_S,
#if defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_UARTE2_NS,
#else
.p = NRF_UARTE2_S,
#endif
.irq = SERIAL2_IRQn,
},
{
.p = NRF_UARTE3_S,
#if defined(NRF_TRUSTZONE_NONSECURE)
.p = NRF_UARTE3_NS,
#else
.p = NRF_UARTE3_S,
#endif
.irq = SERIAL3_IRQn,
},
#elif defined(NRF5340_XXAA) && defined(NRF_NETWORK)
Expand Down
6 changes: 5 additions & 1 deletion bsp/nrf/wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

#if defined(NRF5340_XXAA)
#if defined(NRF_APPLICATION)
#define NRF_WDT NRF_WDT0_S
#if defined(NRF_TRUSTZONE_NONSECURE)
#define NRF_WDT NRF_WDT0_NS
#else
#define NRF_WDT NRF_WDT0_S
#endif
#define WDT_IRQn WDT0_IRQn
#define WDT_IRQHandler WDT0_IRQHandler
#elif defined(NRF_NETWORK)
Expand Down
2 changes: 1 addition & 1 deletion nRF/System/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void reset_handler(void) {
func++();
}

#ifndef __NO_SYSTEM_INIT
#if !defined(__NO_SYSTEM_INIT) && !defined(NRF_TRUSTZONE_NONSECURE)
system_init();
#endif

Expand Down

0 comments on commit 1e19318

Please sign in to comment.