Setup HAL UART Interrupts in a Trustzone environment without CubeMX
Hi ST,
I’ve run into a whole lot of issues adding interrupt-based UART to your OEMiRoT w/ Trustzone example on a NUCLEO-U385RG-Q.
As you may know this example is not compatible with CubeMX, and it’s not clear which steps are needed to manually incorporate UART4 so that it activates an interrupt on receipt of input when running in the Non-Secure region of code. The idea is to only access the Secure region when needing to utilise certain sensitive variables, called from within a Non-Secure function.
Let’s take this opportunity to establish a step-by-step guide for someone who isn’t (yet) an embedded professional, please excuse my ignorance if this already exists, I’d be just as happy to be directed there. My settings so far are:
1. Secure/Inc/partition_stm32u385xx.h: Initialise UART4_IRQn as Non-Secure
#define NVIC_INIT_ITNS2 1
#define NVIC_INIT_ITNS2_VAL 0x00000001
2. Secure/Src/main.c: Define UART4 pins (CN7 1 & 2, or PC10 & 11) as NonSecure
HAL_GPIO_ConfigPinAttributes(GPIOC, GPIO_PIN_10|GPIO_PIN_11, GPIO_PIN_NSEC);
3. NonSecure/Src/stm32u3xx_it.c: Define interrupt handler (+ function definition in the related header file)
void UART4_IRQHandler(void) {
HAL_UART_IRQHandler(&huart4);
}
4. NonSecure/Src/main.c: Add Interrupt enable and priority inside MX_UART4_Init
HAL_NVIC_SetPriority(UART4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(UART4_IRQn);
5. NonSecure/Src/main.c: Add UART RX Interrupt callback
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
HAL_UART_Receive_IT(&huart4, &uart_rx_byte, 1);
}
Is there anything here I don’t need to do? And the more obvious question - what am I missing?
For future reference - how is a ‘successful’ user currently accessing this kind of information without needing your forum? I have 4 seperate user manuals consisting of the nucleo user manual (MB1841), the STM32U3 user manual (RM0487), the programmers manual (PM0264) and the TrustZone application note (AN5347) and neither of them contain a clear guide to implementing this basic(?) functionality.
Thanks for your help!
