This is an automated email from the ASF dual-hosted git repository. jerzy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 1ccc0a2dfe17209cf9051d565279d8281f410533 Author: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl> AuthorDate: Tue Oct 11 09:35:16 2022 +0200 mcu/nrf5340: Include TFM module to allow MCU GPIO assignment It was possible to assign GPIO pins to network core. It was done in ipc driver or for unsecure code it in bootloader code from hal_system_start.c. Now pin assignment to net core is done in nrf5340_periph_create() which is called in hal_bsp_init(). With this change pin assigment can be done: - in bootloader (regardless if it is secure or not) - in application build with MCU_APP_SECURE - in non-secure application when tfm functionality is provided by bootloader or other secure code. In this case bootloader does not redirect pins during startup but allows change from non-secure application at runtime. Signed-off-by: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl> --- hw/mcu/nordic/nrf5340/pkg.yml | 1 + hw/mcu/nordic/nrf5340/src/hal_system_start.c | 9 --------- hw/mcu/nordic/nrf5340/src/nrf5340_periph.c | 20 ++++++++++++++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/hw/mcu/nordic/nrf5340/pkg.yml b/hw/mcu/nordic/nrf5340/pkg.yml index 9aa3d530a..a725de27f 100644 --- a/hw/mcu/nordic/nrf5340/pkg.yml +++ b/hw/mcu/nordic/nrf5340/pkg.yml @@ -29,6 +29,7 @@ pkg.deps: - "@apache-mynewt-core/hw/mcu/nordic" - "@apache-mynewt-core/hw/cmsis-core" - "@apache-mynewt-core/hw/hal" + - "@apache-mynewt-core/hw/mcu/nordic/nrf5340/tfm" pkg.deps.BUS_DRIVER_PRESENT: - "@apache-mynewt-core/hw/bus/drivers/spi_hal" diff --git a/hw/mcu/nordic/nrf5340/src/hal_system_start.c b/hw/mcu/nordic/nrf5340/src/hal_system_start.c index c744a5bc5..153f38796 100644 --- a/hw/mcu/nordic/nrf5340/src/hal_system_start.c +++ b/hw/mcu/nordic/nrf5340/src/hal_system_start.c @@ -61,9 +61,6 @@ static const struct periph_id_range ns_peripheral_ids[] = { #define STRIP_PARENS(X) X #define UNMANGLE_MYNEWT_VAL(X) STRIP_PARENS(_Args X) -#if MYNEWT_VAL(MCU_GPIO_NET) -static const unsigned int net_gpios[] = { UNMANGLE_MYNEWT_VAL(MYNEWT_VAL(MCU_GPIO_NET)) }; -#endif #if MYNEWT_VAL(MCU_GPIO_PERIPH) static const unsigned int periph_gpios[] = { UNMANGLE_MYNEWT_VAL(MYNEWT_VAL(MCU_GPIO_PERIPH)) }; #endif @@ -121,12 +118,6 @@ hal_system_start(void *img_start) NRF_SPU->GPIOPORT[0].PERM = 0; NRF_SPU->GPIOPORT[1].PERM = 0; -#if MYNEWT_VAL(MCU_GPIO_NET) - for (i = 0; i < ARRAY_SIZE(net_gpios); ++i) { - nrf_gpio_pin_mcu_select(net_gpios[i], GPIO_PIN_CNF_MCUSEL_NetworkMCU); - } -#endif - #if MYNEWT_VAL(MCU_GPIO_PERIPH) for (i = 0; i < ARRAY_SIZE(periph_gpios); ++i) { nrf_gpio_pin_mcu_select(periph_gpios[i], GPIO_PIN_CNF_MCUSEL_Peripheral); diff --git a/hw/mcu/nordic/nrf5340/src/nrf5340_periph.c b/hw/mcu/nordic/nrf5340/src/nrf5340_periph.c index d663bf0aa..0c3b20ca3 100644 --- a/hw/mcu/nordic/nrf5340/src/nrf5340_periph.c +++ b/hw/mcu/nordic/nrf5340/src/nrf5340_periph.c @@ -24,6 +24,7 @@ #include <bsp/bsp.h> #include <nrfx.h> #include "hal/hal_spi.h" +#include "tfm/tfm.h" #if MYNEWT_VAL(BUS_DRIVER_PRESENT) #include "bus/bus.h" @@ -418,9 +419,28 @@ nrf5340_periph_create_i2c(void) #endif } +#define _Args(...) __VA_ARGS__ +#define STRIP_PARENS(X) X +#define UNMANGLE_MYNEWT_VAL(X) STRIP_PARENS(_Args X) + +static void +nrf5340_net_core_pins(void) +{ +#ifdef MYNEWT_VAL_MCU_GPIO_NET + unsigned int gpios[] = { UNMANGLE_MYNEWT_VAL(MYNEWT_VAL(MCU_GPIO_NET)) }; + int i; + + /* Configure GPIOs for Networking Core */ + for (i = 0; i < ARRAY_SIZE(gpios); i++) { + tfm_gpio_pin_mcu_select(gpios[i], GPIO_PIN_CNF_MCUSEL_NetworkMCU); + } +#endif +} + void nrf5340_periph_create(void) { + nrf5340_net_core_pins(); nrf5340_periph_create_timers(); nrf5340_periph_create_adc(); nrf5340_periph_create_pwm();