machine/stm32: add STM32U5 I2C support

Add I2C timing values for STM32U585 at 160MHz PCLK1 (10/100/400/500 KHz).
Add I2C1 peripheral and pin definitions to arduino-uno-q board.
Update i2c_revb build tag to include stm32u5.
This commit is contained in:
deadprogram
2026-03-15 15:45:38 +01:00
parent 38a3ccee52
commit 0ac7bf8c8b
3 changed files with 35 additions and 3 deletions
+22 -1
View File
@@ -44,4 +44,25 @@ package tmp
} uart.txEmptyFlag = stm32.USART_ISR_TXE uart.statusReg = &uart.Bus.ISR uart.txReg = &uart.Bus.TDR uart.rxReg = &uart.Bus.RDRfunc (uart *UART) setRegisters() {// Register names vary by ST processor, these are for STM U5} return CPUFrequency() / baudRatefunc (uart *UART) getBaudRateDivisor(baudRate uint32) uint32 {// NOTE: keep this in sync with the runtime/runtime_stm32u5.go clock init code// UART baudrate calc based on the bus and clockspeed} config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.RxAltFuncSelector) config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.TxAltFuncSelector) // enable the alternate functions on the TX and RX pins } stm32.PWR.SetSVMCR_IO2SV(1) // Enable VDDIO2 power supply for PGx pins if config.RX.getPort() == stm32.GPIOG || config.TX.getPort() == stm32.GPIOG {func (uart *UART) configurePins(config UARTConfig) {// Configure the UART.//---------- UART related codeconst APB2_TIM_FREQ = 160e6 // 160MHzconst APB1_TIM_FREQ = 160e6 // 160MHz// and clock frequencies// in sync with any changes to runtime package which configures the oscillators// Internal use: configured speed of the APB1 and APB2 timers, this should be kept} return 160000000func CPUFrequency() uint32 {) "device/stm32"import (package machine
} } return 0 default: return 0x00802172 case 500 * KHz: return 0x10802D9B case 400 * KHz: return 0x30A0A7FB case 100 * KHz: return 0xF010F3FE case 10 * KHz: switch br { // TODO: Do calculations based on PCLK1 // for 160MHz PCLK1. // These are 'magic' values calculated by STM32CubeMXfunc (i2c *I2C) getFreqRange(br uint32) uint32 {// Gets the value for TIMINGR register//---------- I2C related code} uart.txEmptyFlag = stm32.USART_ISR_TXE uart.statusReg = &uart.Bus.ISR uart.txReg = &uart.Bus.TDR uart.rxReg = &uart.Bus.RDRfunc (uart *UART) setRegisters() {// Register names vary by ST processor, these are for STM U5} return CPUFrequency() / baudRatefunc (uart *UART) getBaudRateDivisor(baudRate uint32) uint32 {// NOTE: keep this in sync with the runtime/runtime_stm32u5.go clock init code// UART baudrate calc based on the bus and clockspeed} config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.RxAltFuncSelector) config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.TxAltFuncSelector) // enable the alternate functions on the TX and RX pins } stm32.PWR.SetSVMCR_IO2SV(1) // Enable VDDIO2 power supply for PGx pins if config.RX.getPort() == stm32.GPIOG || config.TX.getPort() == stm32.GPIOG {func (uart *UART) configurePins(config UARTConfig) {// Configure the UART.//---------- UART related codeconst APB2_TIM_FREQ = 160e6 // 160MHzconst APB1_TIM_FREQ = 160e6 // 160MHz// and clock frequencies// in sync with any changes to runtime package which configures the oscillators// Internal use: configured speed of the APB1 and APB2 timers, this should be kept} return 160000000func CPUFrequency() uint32 {) "device/stm32"import (package machine