2025-09-25 1:03 PM - last edited on 2025-09-25 1:26 PM by mƎALLEm
Post edited by a ST moderator. Please use </> button to paste your code.
Hi,
I’m working with an STM32H7 (dual-core) and I want both CM4 and CM7 to be able to transmit on the same UART. On CM7, I initialize the UART normally MX_USART1_UART_Init(). On CM4, I try to send data via HAL and I’ve protected access with a hardware semaphore.
Problem is that CM4 doesn’t see the properly initialized huart1 from CM7 and nothing is transmitted.
What exactly do I need to do so that CM4 can use the same huart1, i tried the
__attribute__((section(".RAM_D2"))) UART Handle TypeDef huart1;
but it doesn't work ither. . Also why both cores declares huart1on their own??
Thanks in advance for any help!
code:
int __io_putchar(int ch)
{
// Take semaphore
HAL_HSEM_FastTake(UART_HSEM_ID);
if (ch == '\n') {
uint8_t cr = '\r';
HAL_UART_Transmit(&huart1, &cr, 1, HAL_MAX_DELAY);
}
HAL_UART_Transmit(&huart1, (uint8_t*)&ch, 1, HAL_MAX_DELAY);
// Release semaphore
HAL_HSEM_Release(UART_HSEM_ID, 0);
return ch;
}
2025-09-25 1:48 PM
You need to trick the system by modifying huart1 on the CM4 to reflect the initialized state of the peripheral. Typically this is just the State parameter, but I think on UART there's a gState and something else. See what they are after CM7 initialization and explicitly set them to that on the CM4 side once you can guarantee the peripheral is actually initialized.
2025-09-25 2:43 PM - edited 2025-09-25 2:47 PM
So basically, on the CM4 side I just keep my own declaration:
and then just add stuff like:
huart1.gState = HAL_UART_STATE_READY;
huart1.RxState = HAL_UART_STATE_READY;
2025-09-25 3:05 PM
Yep, that's the way I would do it.
You'll need to ensure only one core talks to the peripheral at once, so gated behind an HSEM or something like that. Only pass off the HSEM when both states are READY.
Note that HAL_HSEM_FastTake can fail if the HSEM is already taken. Your code just silently ignores this.
2025-09-25 3:27 PM
You've indicate that for the CM7 you initialize the UART normally MX_USART1_UART_Init(). But you didn't say that was that done on the CM4 as well?
In the IOC, did you select both CM4 and CM7? If the CM7 was the initializer, then MX_USART1_UART_Init() is not called in the CM4, so huart1 is not initialized. You have to call that function manually to initialize huart1 on the CM4.