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
+12 -1
View File
@@ -70,4 +70,15 @@ package tmp
} UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt)func init() {) DefaultUART = UART1 } RxAltFuncSelector: AF7_USART1_2_3, TxAltFuncSelector: AF7_USART1_2_3, Bus: stm32.USART2, Buffer: NewRingBuffer(), _UART1 = UART{ UART1 = &_UART1 // debugger to be exposed as virtual COM port over USB. // USART2 is the hardware serial port connected to the onboard ST-LINKvar () UART_RX_PIN = PA3 UART_TX_PIN = PA2 // PA2 and PA3 are connected to the ST-Link Virtual Com Port (VCP) // UART pinsconst () BUTTON = PC13const () LED_GREEN = PA5 LED_BUILTIN = LED_GREEN LED = LED_BUILTINconst () D15 = PB8 D14 = PB9 D13 = PA5 D12 = PA6 D11 = PA7 D10 = PB0 D9 = PC7 D8 = PA9 D7 = PA8 D6 = PB10 D5 = PB4 D4 = PB5 D3 = PB3 D2 = PA10 D1 = PB6 D0 = PB7 A5 = PB12 A4 = PB11 A3 = PB1 A2 = PA4 A1 = PA1 A0 = PA0 // Arduino Pinsconst () "runtime/interrupt" "device/stm32"import (package machine// Arduino UNO Q board with STM32U585 processor.
} UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt)func init() {) I2C0 = I2C1 } AltFuncSelector: AF4_I2C1_2_3_4, Bus: stm32.I2C1, I2C1 = &I2C{ // I2C1 is documented, alias to I2C0 as well DefaultUART = UART1 } RxAltFuncSelector: AF7_USART1_2_3, TxAltFuncSelector: AF7_USART1_2_3, Bus: stm32.USART2, Buffer: NewRingBuffer(), _UART1 = UART{ UART1 = &_UART1 // debugger to be exposed as virtual COM port over USB. // USART2 is the hardware serial port connected to the onboard ST-LINKvar () I2C0_SDA_PIN = PB9 I2C0_SCL_PIN = PB8 // I2C pins UART_RX_PIN = PA3 UART_TX_PIN = PA2 // PA2 and PA3 are connected to the ST-Link Virtual Com Port (VCP) // UART pinsconst () BUTTON = PC13const () LED_GREEN = PA5 LED_BUILTIN = LED_GREEN LED = LED_BUILTINconst () D15 = PB8 D14 = PB9 D13 = PA5 D12 = PA6 D11 = PA7 D10 = PB0 D9 = PC7 D8 = PA9 D7 = PA8 D6 = PB10 D5 = PB4 D4 = PB5 D3 = PB3 D2 = PA10 D1 = PB6 D0 = PB7 A5 = PB12 A4 = PB11 A3 = PB1 A2 = PA4 A1 = PA1 A0 = PA0 // Arduino Pinsconst () "runtime/interrupt" "device/stm32"import (package machine// Arduino UNO Q board with STM32U585 processor.
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build stm32l5 || stm32f7 || stm32l4 || stm32l0 || stm32wlx || stm32g0
//go:build stm32l5 || stm32f7 || stm32l4 || stm32l0 || stm32wlx || stm32g0 || stm32u5
package machine
+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