2023-08-03 01:52 AM
Using CubeIDE v1.13.0, installed this week.
On STM32F0Discovery (STM32F051):
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_UART_Transmit( &huart1, "Hello, UART1 world!\r\n", 21, 10000 );
HAL_GPIO_TogglePin( LD3_GPIO_Port, LD3_Pin );
HAL_Delay( 500 );
HAL_UART_Transmit( &huart2, "Hello, UART2 world!\r\n", 21, 10000 );
HAL_GPIO_TogglePin( LD4_GPIO_Port, LD4_Pin );
HAL_Delay( 500 );
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
The first HAL_UART_Transmit is to UART1, configured as full-duplex.
This works fine - the full string is transmitted each time:
The second HAL_UART_Transmit is to UART2, configured as Single Wire Half Duplex.
This does not quite work - only the 1st two characters are ever transmitted:
If I single-step the transmit loop in the HAL_UART_Transmit for UART2, it does transmit the entire string.
So what's going on here? Is there some gotcha! with Single Wire Half Duplex?
(Screenshots are from YAT; same results when using TeraTerm)
Solved! Go to Solution.
2023-08-04 02:31 AM - edited 2023-08-04 02:32 AM
"Datasheet says that happens in hardware"
Well, sort of ...
What the datasheet is talking about is just the input/output setting of the hardware pin.
The user code does have to manage the enabling & disabling of the UART peripheral's transmitter & receiver.
The problem is that the generated initialisation function leaves both the transmitter and the receiver enabled!
This is what causes HAL_UART_Transmit to fail.
Two options to fix:
2023-08-03 03:26 AM
I reconfigured the IOC to 'Async' instead of Single Wire Half Duplex & re-generated.
No other changes to code.
Now UART2 is also fine:
So there definitely is something wrong with HAL_UART_Transmit in Single Wire Half Duplex.
2023-08-03 03:40 AM
Then go through that function and find what's happening when the half-duplex select bit is set.
Anyway, you could still manage the half-duplex by yourself, always turn off the transmitter after each transmission.
2023-08-03 03:53 AM
... okay, in my H7 uart HAL functions there's not much about half-duplex management, mostly that it is an extra init function, not much else.
And nothing in the HAL_UART_Transmit function.
2023-08-03 04:18 AM
"Then go through that function and find what's happening when the half-duplex select bit is set"
Yes - doing that...
Not seen anything in Ref Manual yet that suggests the operation should be any different at all.
"you could still manage the half-duplex by yourself, always turn off the transmitter after each transmission"
Datasheet says that happens in hardware.
2023-08-04 02:31 AM - edited 2023-08-04 02:32 AM
"Datasheet says that happens in hardware"
Well, sort of ...
What the datasheet is talking about is just the input/output setting of the hardware pin.
The user code does have to manage the enabling & disabling of the UART peripheral's transmitter & receiver.
The problem is that the generated initialisation function leaves both the transmitter and the receiver enabled!
This is what causes HAL_UART_Transmit to fail.
Two options to fix:
2023-08-29 03:33 AM
Hello,
An internal ticket (ID 160120) is submitted in order to work on this issue.
(PS: ID 160120 is only for reference, not available outside of ST)
Imen