Skip to content

Commit

Permalink
modules: tfm: Update Zephyr and TF-M to support UART pinctrl config
Browse files Browse the repository at this point in the history
Update TF-M to support UART pin config from pinctrl.
Change out-of-tree support to use the device tree information and
pass it to the TF-M UART driver.

Update TF-M tests to define hw-flow-control, and alternate pin setup
in devicetree instead of kconfig

Update Zephyr to include:
- nRF5340 DK flow control pins.
- Revert noup commits to take upstream commits for generic NS board
support
- Include nrf9160 flash layout fixes and BL2 logging fixes.

Signed-off-by: Joakim Andersson <[email protected]>
  • Loading branch information
joerchan authored and carlescufi committed Oct 31, 2023
1 parent 147d941 commit e684409
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 173 deletions.
49 changes: 25 additions & 24 deletions modules/tfm/tfm/boards/board/RTE_Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,45 @@
#define __RTE_DEVICE_H

#include <autoconf.h>
/* ARRAY_SIZE causes a conflict as it is defined both by TF-M and indirectly by devicetree.h */
#undef ARRAY_SIZE
#include <zephyr/devicetree.h>
#include <nrf-pinctrl.h>

#define UART_PIN_INIT(node_id, prop, idx) \
DT_PROP_BY_IDX(node_id, prop, idx),

/* Configuration settings for Driver_USART0. */
#if defined(CONFIG_TFM_SECURE_UART0) || DOMAIN_NS == 1U

#define RTE_USART0 1
/* Pin Selection (0xFFFFFFFF means Disconnected) */
#define RTE_USART0_TXD_PIN CONFIG_TFM_UART0_TXD_PIN
#define RTE_USART0_RXD_PIN CONFIG_TFM_UART0_RXD_PIN
#define RTE_USART0_RTS_PIN CONFIG_TFM_UART0_RTS_PIN
#define RTE_USART0_CTS_PIN CONFIG_TFM_UART0_CTS_PIN
#define RTE_USART0 1

#if defined(CONFIG_TFM_UART0_HWFC_ENABLED)
#define RTE_USART0_HWFC NRF_UARTE_HWFC_ENABLED
#else
#define RTE_USART0_HWFC NRF_UARTE_HWFC_DISABLED
#endif
#define RTE_USART0_PINS \
{ \
DT_FOREACH_CHILD_VARGS( \
DT_PINCTRL_BY_NAME(DT_NODELABEL(uart0), default, 0), \
DT_FOREACH_PROP_ELEM, psels, UART_PIN_INIT \
) \
}

#endif /* defined(CONFIG_TFM_SECURE_UART0) || DOMAIN_NS == 1U */

/* Configuration settings for Driver_USART1. */
#if defined(CONFIG_TFM_SECURE_UART1)
#if defined(CONFIG_TFM_SECURE_UART1) && DOMAIN_NS != 1U

#define RTE_USART1 1
/* Pin Selection (0xFFFFFFFF means Disconnected) */
#define RTE_USART1_TXD_PIN CONFIG_TFM_UART1_TXD_PIN
#define RTE_USART1_RXD_PIN CONFIG_TFM_UART1_RXD_PIN
#define RTE_USART1_RTS_PIN CONFIG_TFM_UART1_RTS_PIN
#define RTE_USART1_CTS_PIN CONFIG_TFM_UART1_CTS_PIN
#define RTE_USART1 1

#if defined(CONFIG_TFM_UART1_HWFC_ENABLED)
#define RTE_USART1_HWFC NRF_UARTE_HWFC_ENABLED
#else
#define RTE_USART1_HWFC NRF_UARTE_HWFC_DISABLED
#endif
#define RTE_USART1_PINS \
{ \
DT_FOREACH_CHILD_VARGS( \
DT_PINCTRL_BY_NAME(DT_NODELABEL(uart1), default, 0), \
DT_FOREACH_PROP_ELEM, psels, UART_PIN_INIT \
) \
}

#endif /* defined(CONFIG_TFM_SECURE_UART1) */

/* Configuration settings for Driver_FLASH0. */
#define RTE_FLASH0 1
#define RTE_FLASH0 1

#endif /* __RTE_DEVICE_H */
24 changes: 10 additions & 14 deletions modules/tfm/tfm/boards/board/device_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,23 @@
#ifndef DEVICE_CFG_H__
#define DEVICE_CFG_H__

/**
* \file device_cfg.h
* \brief
* This is the default device configuration file with all peripherals
* defined and configured to be use via the secure and/or non-secure base
* address.
*/
#include <autoconf.h>

/* ARRAY_SIZE causes a conflict as it is defined both by TF-M and indirectly by devicetree.h */
#undef ARRAY_SIZE
#include <autoconf.h>
#include <zephyr/devicetree.h>

#define TFM_UART uart##NRF_SECURE_UART_INSTANCE
#if defined(CONFIG_TFM_SECURE_UART0) || DOMAIN_NS == 1U
#define TFM_UART uart0
#endif /* defined(CONFIG_TFM_SECURE_UART0) || DOMAIN_NS == 1U */

#if defined(CONFIG_TFM_SECURE_UART1) && DOMAIN_NS != 1U
#define TFM_UART uart1
#endif /* defined(CONFIG_TFM_SECURE_UART1) */

#define DEFAULT_UART_BAUDRATE DT_PROP_OR(DT_NODELABEL(TFM_UART), current_speed, 115200)

#if (defined(CONFIG_TFM_SECURE_UART0) || DOMAIN_NS == 1U) && \
defined(CONFIG_TFM_UART0_HWFC_ENABLED)
#define DEFAULT_UART_CONTROL ARM_USART_FLOW_CONTROL_RTS_CTS
#elif defined(CONFIG_TFM_SECURE_UART1) && \
defined(CONFIG_TFM_UART1_HWFC_ENABLED)
#if DT_PROP(DT_NODELABEL(TFM_UART), hw_flow_control)
#define DEFAULT_UART_CONTROL ARM_USART_FLOW_CONTROL_RTS_CTS
#else
#define DEFAULT_UART_CONTROL 0
Expand Down
130 changes: 10 additions & 120 deletions modules/trusted-firmware-m/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ config TFM_REGRESSION_NS
bool
select NRF_TIMER0_SECURE

config TFM_LOG_LEVEL_SILENCE
default n
depends on $(dt_nodelabel_has_prop,uart0,pinctrl-names) || \
$(dt_nodelabel_has_prop,uart1,pinctrl-names)
help
Overrule zephyr disable TF-M secure output if the uart1 node has not
assigned GPIO pins using pinctrl.

config TFM_SECURE_UART
bool "TF-M configure UART instance as secure peripheral"
default y if !TFM_LOG_LEVEL_SILENCE
Expand Down Expand Up @@ -54,138 +62,20 @@ choice TFM_SECURE_UART_INSTANCE

config TFM_SECURE_UART0
bool "TF-M logging will use UART0 instance"
depends on $(dt_nodelabel_has_prop,uart0,pinctrl-names)
select NRF_UARTE0_SECURE
select TFM_SECURE_UART_SHARE_INSTANCE if NRFX_UARTE0 || HAS_HW_NRF_UARTE0

config TFM_SECURE_UART1
bool "TF-M logging will use UART1 instance"
depends on $(dt_nodelabel_has_prop,uart1,pinctrl-names)
select NRF_UARTE1_SECURE
select TFM_SECURE_UART_SHARE_INSTANCE if NRFX_UARTE1 || HAS_HW_NRF_UARTE1

endchoice

endif # TFM_SECURE_UART

menu "TF-M UART pins"
visible if BUILD_WITH_TFM

config TFM_UART0_TXD_PIN
int "UART0 TXD pin"
default 29 if BOARD_NRF9160DK_NRF9160_NS
default 27 if BOARD_NRF9161DK_NRF9161_NS
default 20 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS
default 18 if BOARD_THINGY91_NRF9160_NS
default 4294967295 # 0xffffffff i.e. disconnected
help
The GPIO pin the TFM build system will use for UART0 TXD pin.
UART0 is used by TF-M as the log output for the non-secure image.

Note: The non-secure image is only ever used when running the
TF-M regression tests.

config TFM_UART0_RXD_PIN
int "UART0 RXD pin"
default 28 if BOARD_NRF9160DK_NRF9160_NS
default 26 if BOARD_NRF9161DK_NRF9161_NS
default 22 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS
default 19 if BOARD_THINGY91_NRF9160_NS
default 4294967295 # 0xffffffff i.e. disconnected
help
The GPIO pin the TFM build system will use for UART0 RXD pin.
UART0 is used by TF-M as the log output for the non-secure image.

Note: The non-secure image is only ever used when running the
TF-M regression tests.

config TFM_UART0_RTS_PIN
int "UART0 RTS pin"
default 27 if BOARD_NRF9160DK_NRF9160_NS
default 14 if BOARD_NRF9161DK_NRF9161_NS
default 19 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS
default 20 if BOARD_THINGY91_NRF9160_NS
default 4294967295 # 0xffffffff i.e. disconnected
help
The GPIO pin the TFM build system will use for UART0 RTS pin.
UART0 is used by TF-M as the log output for the non-secure image.

Note: The non-secure image is only ever used when running the
TF-M regression tests.

config TFM_UART0_CTS_PIN
int "UART0 CTS pin"
default 26 if BOARD_NRF9160DK_NRF9160_NS
default 15 if BOARD_NRF9161DK_NRF9161_NS
default 21 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS
default 21 if BOARD_THINGY91_NRF9160_NS
default 4294967295 # 0xffffffff i.e. disconnected
help
The GPIO pin the TFM build system will use for UART0 CTS pin.
UART0 is used by TF-M as the log output for the non-secure image.

Note: The non-secure image is only ever used when running the
TF-M regression tests.

config TFM_UART0_HWFC_ENABLED
bool "UART0 hardware flow control"
help
Enable hardware flow control on UART0 in the TFM build system.

config TFM_UART1_TXD_PIN
int "UART1 TXD pin"
depends on TFM_SECURE_UART1
default 1 if BOARD_NRF9160DK_NRF9160_NS
default 29 if BOARD_NRF9161DK_NRF9161_NS
default 25 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS
default 22 if BOARD_THINGY91_NRF9160_NS
default 4294967295 # 0xffffffff i.e. disconnected
help
The GPIO pin the TFM build system will use for UART1 TXD pin.
UART1 is used by TF-M as the log output for the secure image.

config TFM_UART1_RXD_PIN
int "UART1 RXD pin"
depends on TFM_SECURE_UART1
default 0 if BOARD_NRF9160DK_NRF9160_NS
default 28 if BOARD_NRF9161DK_NRF9161_NS
default 26 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS
default 23 if BOARD_THINGY91_NRF9160_NS
default 4294967295 # 0xffffffff i.e. disconnected
help
The GPIO pin the TFM build system will use for UART1 RXD pin.
UART1 is used by TF-M as the log output for the secure image.

config TFM_UART1_RTS_PIN
int "UART1 RTS pin"
depends on TFM_SECURE_UART1
default 14 if BOARD_NRF9160DK_NRF9160_NS
default 16 if BOARD_NRF9161DK_NRF9161_NS
default 5 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS
default 24 if BOARD_THINGY91_NRF9160_NS
default 4294967295 # 0xffffffff i.e. disconnected
help
The GPIO pin the TFM build system will use for UART1 RTS pin.
UART1 is used by TF-M as the log output for the secure image.

config TFM_UART1_CTS_PIN
int "UART1 CTS pin"
depends on TFM_SECURE_UART1
default 15 if BOARD_NRF9160DK_NRF9160_NS
default 17 if BOARD_NRF9161DK_NRF9161_NS
default 6 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS
default 25 if BOARD_THINGY91_NRF9160_NS
default 4294967295 # 0xffffffff i.e. disconnected
help
The GPIO pin the TFM build system will use for UART1 CTS pin.
UART1 is used by TF-M as the log output for the secure image.

config TFM_UART1_HWFC_ENABLED
bool "UART1 hardware flow control"
help
Enable hardware flow control on UART1 in the TFM build system.

endmenu


choice TFM_PROFILE_TYPE
default TFM_PROFILE_TYPE_MINIMAL

Expand Down
19 changes: 19 additions & 0 deletions tests/tfm/tfm_regression_test/app.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
&uart0 {
compatible = "nordic,nrf-uarte";
current-speed = <115200>;
status = "okay";
hw-flow-control;
};

&uart1 {
compatible = "nordic,nrf-uarte";
current-speed = <115200>;
/* Set to disabled in application, since TF-M will be using it. */
status = "disabled";
hw-flow-control;
};

This file was deleted.

4 changes: 0 additions & 4 deletions tests/tfm/tfm_regression_test/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ CONFIG_TFM_NRF_PROVISIONING=y
CONFIG_TFM_IPC=y
CONFIG_TFM_ISOLATION_LEVEL=2

# We need flow control for test output
CONFIG_TFM_UART0_HWFC_ENABLED=y
CONFIG_TFM_UART1_HWFC_ENABLED=y

# RNG
CONFIG_PSA_WANT_GENERATE_RANDOM=y

Expand Down
4 changes: 2 additions & 2 deletions west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ manifest:
# https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/modules.html
- name: zephyr
repo-path: sdk-zephyr
revision: f1ee732cab5ebaa83ddf94f0d4c6f734d2684ea7
revision: ff85910bf8ed1aac0571bca0e7f206782234efbb
import:
# In addition to the zephyr repository itself, NCS also
# imports the contents of zephyr/west.yml at the above
Expand Down Expand Up @@ -145,7 +145,7 @@ manifest:
- name: trusted-firmware-m
repo-path: sdk-trusted-firmware-m
path: modules/tee/tf-m/trusted-firmware-m
revision: 6854dd509f4252cb0f9724c4a181586abf31a12d
revision: 8f6d96538f2221ac3a5c7df2e8fdbe3bd147d2ce
- name: matter
repo-path: sdk-connectedhomeip
path: modules/lib/matter
Expand Down

0 comments on commit e684409

Please sign in to comment.