mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 21:13:39 +00:00
7d51044892
This fixes several issues in the STM32 UART implementation: - `writeByte` now waits for the transmit register to be empty before writing, preventing data loss by avoiding overwriting the shift register. - `flush` now correctly waits for the Transmission Complete (TC) flag. - The interrupt handler now clears all error flags (ORE, NE, FE, PE) to prevent interrupt storms, rather than just ORE. - Extracted `SetBaudRate` so it can be cleanly overridden by specific MCU families. It also introduces specific fixes for the STM32U5 family: - Enforces a minimum BRR divisor of 16 in `getBaudRateDivisor` to prevent undefined hardware behavior and CPU starvation. - Overrides `SetBaudRate` for STM32U585 to momentarily disable the USART (UE=0) before updating the BRR register, which is read-only when enabled. - Adds a readback after enabling the USART1 clock to ensure the clock is active before register access. Signed-off-by: deadprogram <ron@hybridgroup.com>
14 lines
418 B
Go
14 lines
418 B
Go
//go:build stm32 && !stm32u585
|
|
|
|
package machine
|
|
|
|
// SetBaudRate sets the communication speed for the UART. Defers to
|
|
// chip-specific getBaudRateDivisor for the divisor calculation.
|
|
//
|
|
// On STM32U585 this function is overridden in machine_stm32u585.go because
|
|
// the U5 family requires UE=0 to write BRR.
|
|
func (uart *UART) SetBaudRate(br uint32) {
|
|
divider := uart.getBaudRateDivisor(br)
|
|
uart.Bus.BRR.Set(divider)
|
|
}
|