@@ -117,6 +117,25 @@ const (
117117 PE15 = portE + 15
118118)
119119
120+ // IRQs are defined here as they vary in the SVDs, but do have consistent mapping
121+ // to Timer Interrupts.
122+ const (
123+ irq_TIM1_BRK_TIM15 = 24
124+ irq_TIM1_UP_TIM16 = 25
125+ irq_TIM1_TRG_COM_TIM17 = 26
126+ irq_TIM1_CC = 27
127+ irq_TIM2 = 28
128+ irq_TIM3 = 29
129+ irq_TIM4 = 30
130+ irq_TIM5 = 50
131+ irq_TIM6 = 54
132+ irq_TIM7 = 55
133+ irq_TIM8_BRK = 43
134+ irq_TIM8_UP = 44
135+ irq_TIM8_TRG_COM = 45
136+ irq_TIM8_CC = 46
137+ )
138+
120139func (p Pin ) getPort () * stm32.GPIO_Type {
121140 switch p / 16 {
122141 case 0 :
@@ -185,8 +204,6 @@ func enableAltFuncClock(bus unsafe.Pointer) {
185204 stm32 .RCC .APB1ENR1 .SetBits (stm32 .RCC_APB1ENR1_TIM2EN )
186205 case unsafe .Pointer (stm32 .LPTIM2 ): // LPTIM2 clock enable
187206 stm32 .RCC .APB1ENR2 .SetBits (stm32 .RCC_APB1ENR2_LPTIM2EN )
188- case unsafe .Pointer (stm32 .I2C4 ): // I2C4 clock enable
189- stm32 .RCC .APB1ENR2 .SetBits (stm32 .RCC_APB1ENR2_I2C4EN )
190207 case unsafe .Pointer (stm32 .LPUART1 ): // LPUART1 clock enable
191208 stm32 .RCC .APB1ENR2 .SetBits (stm32 .RCC_APB1ENR2_LPUART1EN )
192209 case unsafe .Pointer (stm32 .TIM16 ): // TIM16 clock enable
@@ -258,6 +275,29 @@ func (p Pin) registerInterrupt() interrupt.Interrupt {
258275 return interrupt.Interrupt {}
259276}
260277
278+ //---------- UART related code
279+
280+ // Configure the UART.
281+ func (uart * UART ) configurePins (config UARTConfig ) {
282+ // enable the alternate functions on the TX and RX pins
283+ config .TX .ConfigureAltFunc (PinConfig {Mode : PinModeUARTTX }, uart .TxAltFuncSelector )
284+ config .RX .ConfigureAltFunc (PinConfig {Mode : PinModeUARTRX }, uart .RxAltFuncSelector )
285+ }
286+
287+ // UART baudrate calc based on the bus and clockspeed
288+ // NOTE: keep this in sync with the runtime/runtime_stm32l5x2.go clock init code
289+ func (uart * UART ) getBaudRateDivisor (baudRate uint32 ) uint32 {
290+ return (CPUFrequency () / baudRate )
291+ }
292+
293+ // Register names vary by ST processor, these are for STM L5
294+ func (uart * UART ) setRegisters () {
295+ uart .rxReg = & uart .Bus .RDR
296+ uart .txReg = & uart .Bus .TDR
297+ uart .statusReg = & uart .Bus .ISR
298+ uart .txEmptyFlag = stm32 .USART_ISR_TXE
299+ }
300+
261301//---------- SPI related types and code
262302
263303// SPI on the STM32Fxxx using MODER / alternate function pins
@@ -445,19 +485,19 @@ var (
445485func (t * TIM ) registerUPInterrupt () interrupt.Interrupt {
446486 switch t {
447487 case & TIM1 :
448- return interrupt .New (stm32 . IRQ_TIM1_UP_TIM16 , TIM1 .handleUPInterrupt )
488+ return interrupt .New (irq_TIM1_UP_TIM16 , TIM1 .handleUPInterrupt )
449489 case & TIM2 :
450- return interrupt .New (stm32 . IRQ_TIM2 , TIM2 .handleUPInterrupt )
490+ return interrupt .New (irq_TIM2 , TIM2 .handleUPInterrupt )
451491 case & TIM3 :
452- return interrupt .New (stm32 . IRQ_TIM3 , TIM3 .handleUPInterrupt )
492+ return interrupt .New (irq_TIM3 , TIM3 .handleUPInterrupt )
453493 case & TIM6 :
454- return interrupt .New (stm32 . IRQ_TIM6_DACUNDER , TIM6 .handleUPInterrupt )
494+ return interrupt .New (irq_TIM6 , TIM6 .handleUPInterrupt )
455495 case & TIM7 :
456- return interrupt .New (stm32 . IRQ_TIM7 , TIM7 .handleUPInterrupt )
496+ return interrupt .New (irq_TIM7 , TIM7 .handleUPInterrupt )
457497 case & TIM15 :
458- return interrupt .New (stm32 . IRQ_TIM1_BRK_TIM15 , TIM15 .handleUPInterrupt )
498+ return interrupt .New (irq_TIM1_BRK_TIM15 , TIM15 .handleUPInterrupt )
459499 case & TIM16 :
460- return interrupt .New (stm32 . IRQ_TIM1_UP_TIM16 , TIM16 .handleUPInterrupt )
500+ return interrupt .New (irq_TIM1_UP_TIM16 , TIM16 .handleUPInterrupt )
461501 }
462502
463503 return interrupt.Interrupt {}
@@ -466,19 +506,19 @@ func (t *TIM) registerUPInterrupt() interrupt.Interrupt {
466506func (t * TIM ) registerOCInterrupt () interrupt.Interrupt {
467507 switch t {
468508 case & TIM1 :
469- return interrupt .New (stm32 . IRQ_TIM1_CC , TIM1 .handleUPInterrupt )
509+ return interrupt .New (irq_TIM1_CC , TIM1 .handleUPInterrupt )
470510 case & TIM2 :
471- return interrupt .New (stm32 . IRQ_TIM2 , TIM2 .handleOCInterrupt )
511+ return interrupt .New (irq_TIM2 , TIM2 .handleOCInterrupt )
472512 case & TIM3 :
473- return interrupt .New (stm32 . IRQ_TIM3 , TIM3 .handleOCInterrupt )
513+ return interrupt .New (irq_TIM3 , TIM3 .handleOCInterrupt )
474514 case & TIM6 :
475- return interrupt .New (stm32 . IRQ_TIM6_DACUNDER , TIM6 .handleOCInterrupt )
515+ return interrupt .New (irq_TIM6 , TIM6 .handleOCInterrupt )
476516 case & TIM7 :
477- return interrupt .New (stm32 . IRQ_TIM7 , TIM7 .handleOCInterrupt )
517+ return interrupt .New (irq_TIM7 , TIM7 .handleOCInterrupt )
478518 case & TIM15 :
479- return interrupt .New (stm32 . IRQ_TIM1_BRK_TIM15 , TIM15 .handleOCInterrupt )
519+ return interrupt .New (irq_TIM1_BRK_TIM15 , TIM15 .handleOCInterrupt )
480520 case & TIM16 :
481- return interrupt .New (stm32 . IRQ_TIM1_UP_TIM16 , TIM16 .handleOCInterrupt )
521+ return interrupt .New (irq_TIM1_UP_TIM16 , TIM16 .handleOCInterrupt )
482522 }
483523
484524 return interrupt.Interrupt {}
0 commit comments