|
| 1 | +//go:build stm32u031 |
| 2 | + |
| 3 | +package machine |
| 4 | + |
| 5 | +import ( |
| 6 | + "device/stm32" |
| 7 | + "runtime/interrupt" |
| 8 | + "runtime/volatile" |
| 9 | + "unsafe" |
| 10 | +) |
| 11 | + |
| 12 | +var deviceIDAddr = []uintptr{0x1FFF3E50, 0x1FFF3E54, 0x1FFF3E58} |
| 13 | + |
| 14 | +// Pin constants for all stm32u0 package sizes |
| 15 | +const ( |
| 16 | + PA0 = portA + 0 |
| 17 | + PA1 = portA + 1 |
| 18 | + PA2 = portA + 2 |
| 19 | + PA3 = portA + 3 |
| 20 | + PA4 = portA + 4 |
| 21 | + PA5 = portA + 5 |
| 22 | + PA6 = portA + 6 |
| 23 | + PA7 = portA + 7 |
| 24 | + PA8 = portA + 8 |
| 25 | + PA9 = portA + 9 |
| 26 | + PA10 = portA + 10 |
| 27 | + PA11 = portA + 11 |
| 28 | + PA12 = portA + 12 |
| 29 | + PA13 = portA + 13 |
| 30 | + PA14 = portA + 14 |
| 31 | + PA15 = portA + 15 |
| 32 | + |
| 33 | + PB0 = portB + 0 |
| 34 | + PB1 = portB + 1 |
| 35 | + PB2 = portB + 2 |
| 36 | + PB3 = portB + 3 |
| 37 | + PB4 = portB + 4 |
| 38 | + PB5 = portB + 5 |
| 39 | + PB6 = portB + 6 |
| 40 | + PB7 = portB + 7 |
| 41 | + PB8 = portB + 8 |
| 42 | + PB9 = portB + 9 |
| 43 | + PB10 = portB + 10 |
| 44 | + PB11 = portB + 11 |
| 45 | + PB12 = portB + 12 |
| 46 | + PB13 = portB + 13 |
| 47 | + PB14 = portB + 14 |
| 48 | + PB15 = portB + 15 |
| 49 | + |
| 50 | + PC0 = portC + 0 |
| 51 | + PC1 = portC + 1 |
| 52 | + PC2 = portC + 2 |
| 53 | + PC3 = portC + 3 |
| 54 | + PC4 = portC + 4 |
| 55 | + PC5 = portC + 5 |
| 56 | + PC6 = portC + 6 |
| 57 | + PC7 = portC + 7 |
| 58 | + PC8 = portC + 8 |
| 59 | + PC9 = portC + 9 |
| 60 | + PC10 = portC + 10 |
| 61 | + PC11 = portC + 11 |
| 62 | + PC12 = portC + 12 |
| 63 | + PC13 = portC + 13 |
| 64 | + PC14 = portC + 14 |
| 65 | + PC15 = portC + 15 |
| 66 | + |
| 67 | + PD0 = portD + 0 |
| 68 | + PD1 = portD + 1 |
| 69 | + PD2 = portD + 2 |
| 70 | + PD3 = portD + 3 |
| 71 | + PD4 = portD + 4 |
| 72 | + PD5 = portD + 5 |
| 73 | + PD6 = portD + 6 |
| 74 | + PD7 = portD + 7 |
| 75 | + PD8 = portD + 8 |
| 76 | + PD9 = portD + 9 |
| 77 | + PD10 = portD + 10 |
| 78 | + PD11 = portD + 11 |
| 79 | + PD12 = portD + 12 |
| 80 | + PD13 = portD + 13 |
| 81 | + PD14 = portD + 14 |
| 82 | + PD15 = portD + 15 |
| 83 | + |
| 84 | + PE0 = portE + 0 |
| 85 | + PE1 = portE + 1 |
| 86 | + PE2 = portE + 2 |
| 87 | + PE3 = portE + 3 |
| 88 | + PE4 = portE + 4 |
| 89 | + PE5 = portE + 5 |
| 90 | + PE6 = portE + 6 |
| 91 | + PE7 = portE + 7 |
| 92 | + PE8 = portE + 8 |
| 93 | + PE9 = portE + 9 |
| 94 | + PE10 = portE + 10 |
| 95 | + PE11 = portE + 11 |
| 96 | + PE12 = portE + 12 |
| 97 | + PE13 = portE + 13 |
| 98 | + PE14 = portE + 14 |
| 99 | + PE15 = portE + 15 |
| 100 | + |
| 101 | + PF0 = portF + 0 |
| 102 | + PF1 = portF + 1 |
| 103 | + PF2 = portF + 2 |
| 104 | + PF3 = portF + 3 |
| 105 | + PF4 = portF + 4 |
| 106 | + PF5 = portF + 5 |
| 107 | + PF6 = portF + 6 |
| 108 | + PF7 = portF + 7 |
| 109 | + PF8 = portF + 8 |
| 110 | + PF9 = portF + 9 |
| 111 | + PF10 = portF + 10 |
| 112 | + PF11 = portF + 11 |
| 113 | + PF12 = portF + 12 |
| 114 | + PF13 = portF + 13 |
| 115 | + PF14 = portF + 14 |
| 116 | + PF15 = portF + 15 |
| 117 | +) |
| 118 | + |
| 119 | +func (p Pin) getPort() *stm32.GPIO_Type { |
| 120 | + switch p / 16 { |
| 121 | + case 0: |
| 122 | + return stm32.GPIOA |
| 123 | + case 1: |
| 124 | + return stm32.GPIOB |
| 125 | + case 2: |
| 126 | + return stm32.GPIOC |
| 127 | + case 3: |
| 128 | + return stm32.GPIOD |
| 129 | + case 4: |
| 130 | + return stm32.GPIOE |
| 131 | + case 5: |
| 132 | + return stm32.GPIOF |
| 133 | + default: |
| 134 | + panic("machine: unknown port") |
| 135 | + } |
| 136 | +} |
| 137 | + |
| 138 | +// enableClock enables the clock for this desired GPIO port. |
| 139 | +func (p Pin) enableClock() { |
| 140 | + switch p / 16 { |
| 141 | + case 0: |
| 142 | + stm32.RCC.IOPENR.SetBits(stm32.RCC_IOPENR_GPIOAEN) |
| 143 | + case 1: |
| 144 | + stm32.RCC.IOPENR.SetBits(stm32.RCC_IOPENR_GPIOBEN) |
| 145 | + case 2: |
| 146 | + stm32.RCC.IOPENR.SetBits(stm32.RCC_IOPENR_GPIOCEN) |
| 147 | + case 3: |
| 148 | + stm32.RCC.IOPENR.SetBits(stm32.RCC_IOPENR_GPIODEN) |
| 149 | + case 4: |
| 150 | + stm32.RCC.IOPENR.SetBits(stm32.RCC_IOPENR_GPIOEEN) |
| 151 | + case 5: |
| 152 | + stm32.RCC.IOPENR.SetBits(stm32.RCC_IOPENR_GPIOFEN) |
| 153 | + default: |
| 154 | + panic("machine: unknown port") |
| 155 | + } |
| 156 | +} |
| 157 | + |
| 158 | +func enableAltFuncClock(bus unsafe.Pointer) { |
| 159 | + switch bus { |
| 160 | + case unsafe.Pointer(stm32.I2C1): |
| 161 | + stm32.RCC.APBENR1.SetBits(stm32.RCC_APBENR1_I2C1EN) |
| 162 | + case unsafe.Pointer(stm32.I2C2): |
| 163 | + stm32.RCC.APBENR1.SetBits(stm32.RCC_APBENR1_I2C2EN) |
| 164 | + case unsafe.Pointer(stm32.I2C3): |
| 165 | + stm32.RCC.APBENR1.SetBits(stm32.RCC_APBENR1_I2C3EN) |
| 166 | + case unsafe.Pointer(stm32.USART1): |
| 167 | + stm32.RCC.APBENR2.SetBits(stm32.RCC_APBENR2_USART1EN) |
| 168 | + case unsafe.Pointer(stm32.USART2): |
| 169 | + stm32.RCC.APBENR1.SetBits(stm32.RCC_APBENR1_USART2EN) |
| 170 | + case unsafe.Pointer(stm32.USART3): |
| 171 | + stm32.RCC.APBENR1.SetBits(stm32.RCC_APBENR1_USART3EN) |
| 172 | + case unsafe.Pointer(stm32.USART4): |
| 173 | + stm32.RCC.APBENR1.SetBits(stm32.RCC_APBENR1_USART4EN) |
| 174 | + } |
| 175 | +} |
| 176 | + |
| 177 | +func (t *TIM) registerUPInterrupt() interrupt.Interrupt { |
| 178 | + panic("unimplemented: timer") |
| 179 | + |
| 180 | + return interrupt.Interrupt{} |
| 181 | +} |
| 182 | + |
| 183 | +func (t *TIM) registerOCInterrupt() interrupt.Interrupt { |
| 184 | + panic("unimplemented: timer") |
| 185 | + |
| 186 | + return interrupt.Interrupt{} |
| 187 | +} |
| 188 | + |
| 189 | +func (t *TIM) enableMainOutput() { |
| 190 | + panic("unimplemented: timer") |
| 191 | +} |
| 192 | + |
| 193 | +type arrtype = uint16 |
| 194 | +type psctype = uint16 |
| 195 | +type arrRegType = volatile.Register16 |
| 196 | + |
| 197 | +const ( |
| 198 | + ARR_MAX = 0x10000 |
| 199 | + PSC_MAX = 0x10000 |
| 200 | +) |
| 201 | + |
| 202 | +const ( |
| 203 | + UART_TX_PIN = NoPin |
| 204 | + UART_RX_PIN = NoPin |
| 205 | +) |
| 206 | + |
| 207 | +func (uart *UART) configurePins(config UARTConfig) { |
| 208 | + panic("unimplemented: UART") |
| 209 | +} |
| 210 | + |
| 211 | +func (uart *UART) getBaudRateDivisor(baudRate uint32) uint32 { |
| 212 | + panic("unimplemented: UART") |
| 213 | +} |
| 214 | + |
| 215 | +func (uart *UART) setRegisters() uint32 { |
| 216 | + panic("unimplemented: UART") |
| 217 | +} |
| 218 | + |
| 219 | +const ( |
| 220 | + I2C0_SCL_PIN = NoPin |
| 221 | + I2C0_SDA_PIN = NoPin |
| 222 | +) |
| 223 | + |
| 224 | +func (i2c I2C) getFreqRange(br uint32) uint32 { |
| 225 | + panic("unimplemented: I2C") |
| 226 | +} |
0 commit comments