github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/machine/board_feather-stm32f405.go (about) 1 //go:build feather_stm32f405 2 3 package machine 4 5 import ( 6 "device/stm32" 7 "runtime/interrupt" 8 ) 9 10 const ( 11 NUM_DIGITAL_IO_PINS = 39 12 NUM_ANALOG_IO_PINS = 7 13 ) 14 15 // Digital pins 16 const ( 17 // Arduino pin = MCU port pin // primary functions (alternate functions) 18 D0 = PB11 // USART3 RX, PWM TIM2_CH4 (I2C2 SDA) 19 D1 = PB10 // USART3 TX, PWM TIM2_CH3 (I2C2 SCL, I2S2 BCK) 20 D2 = PB3 // GPIO, SPI3 FLASH SCK 21 D3 = PB4 // GPIO, SPI3 FLASH MISO 22 D4 = PB5 // GPIO, SPI3 FLASH MOSI 23 D5 = PC7 // GPIO, PWM TIM3_CH2 (USART6 RX, I2S3 MCK) 24 D6 = PC6 // GPIO, PWM TIM3_CH1 (USART6 TX, I2S2 MCK) 25 D7 = PA15 // GPIO, SPI3 FLASH CS 26 D8 = PC0 // GPIO, Neopixel 27 D9 = PB8 // GPIO, PWM TIM4_CH3 (CAN1 RX, I2C1 SCL) 28 D10 = PB9 // GPIO, PWM TIM4_CH4 (CAN1 TX, I2C1 SDA, I2S2 WSL) 29 D11 = PC3 // GPIO (I2S2 SD, SPI2 MOSI) 30 D12 = PC2 // GPIO (I2S2ext SD, SPI2 MISO) 31 D13 = PC1 // GPIO, Builtin LED 32 D14 = PB7 // I2C1 SDA, PWM TIM4_CH2 (USART1 RX) 33 D15 = PB6 // I2C1 SCL, PWM TIM4_CH1 (USART1 TX, CAN2 TX) 34 D16 = PA4 // A0 (DAC OUT1) 35 D17 = PA5 // A1 (DAC OUT2, SPI1 SCK) 36 D18 = PA6 // A2, PWM TIM3_CH1 (SPI1 MISO) 37 D19 = PA7 // A3, PWM TIM3_CH2 (SPI1 MOSI) 38 D20 = PC4 // A4 39 D21 = PC5 // A5 40 D22 = PA3 // A6 41 D23 = PB13 // SPI2 SCK, PWM TIM1_CH1N (I2S2 BCK, CAN2 TX) 42 D24 = PB14 // SPI2 MISO, PWM TIM1_CH2N (I2S2ext SD) 43 D25 = PB15 // SPI2 MOSI, PWM TIM1_CH3N (I2S2 SD) 44 D26 = PC8 // SDIO 45 D27 = PC9 // SDIO 46 D28 = PC10 // SDIO 47 D29 = PC11 // SDIO 48 D30 = PC12 // SDIO 49 D31 = PD2 // SDIO 50 D32 = PB12 // SD Detect 51 D33 = PC14 // OSC32 52 D34 = PC15 // OSC32 53 D35 = PA11 // USB D+ 54 D36 = PA12 // USB D- 55 D37 = PA13 // SWDIO 56 D38 = PA14 // SWCLK 57 ) 58 59 // Analog pins 60 const ( 61 A0 = D16 // ADC12 IN4 62 A1 = D17 // ADC12 IN5 63 A2 = D18 // ADC12 IN6 64 A3 = D19 // ADC12 IN7 65 A4 = D20 // ADC12 IN14 66 A5 = D21 // ADC12 IN15 67 A6 = D22 // VBAT 68 ) 69 70 func init() { 71 initLED() 72 initUART() 73 initSPI() 74 initI2C() 75 } 76 77 // -- LEDs --------------------------------------------------------------------- 78 79 const ( 80 NUM_BOARD_LED = 1 81 NUM_BOARD_NEOPIXEL = 1 82 83 LED_RED = D13 84 LED_NEOPIXEL = D8 85 LED_BUILTIN = LED_RED 86 LED = LED_BUILTIN 87 WS2812 = D8 88 ) 89 90 func initLED() {} 91 92 // -- UART --------------------------------------------------------------------- 93 94 const ( 95 // #===========#==========#==============#============#=======#=======# 96 // | Interface | Hardware | Bus(Freq) | RX/TX Pins | AltFn | Alias | 97 // #===========#==========#==============#============#=======#=======# 98 // | UART1 | USART3 | APB1(42 MHz) | D0/D1 | 7 | ~ | 99 // | UART2 | USART6 | APB2(84 MHz) | D5/D6 | 8 | ~ | 100 // | UART3 | USART1 | APB2(84 MHz) | D14/D15 | 7 | ~ | 101 // | --------- | -------- | ------------ | ---------- | ----- | ----- | 102 // | UART0 | USART3 | APB1(42 MHz) | D0/D1 | 7 | UART1 | 103 // #===========#==========#==============#============#=======#=======# 104 NUM_UART_INTERFACES = 3 105 106 UART1_RX_PIN = D0 // UART1 = hardware: USART3 107 UART1_TX_PIN = D1 // 108 109 UART2_RX_PIN = D5 // UART2 = hardware: USART6 110 UART2_TX_PIN = D6 // 111 112 UART3_RX_PIN = D14 // UART3 = hardware: USART1 113 UART3_TX_PIN = D15 // 114 115 UART0_RX_PIN = UART1_RX_PIN // UART0 = alias: UART1 116 UART0_TX_PIN = UART1_TX_PIN // 117 118 UART_RX_PIN = UART0_RX_PIN // default/primary UART pins 119 UART_TX_PIN = UART0_TX_PIN // 120 ) 121 122 var ( 123 UART1 = &_UART1 124 _UART1 = UART{ 125 Buffer: NewRingBuffer(), 126 Bus: stm32.USART3, 127 TxAltFuncSelector: AF7_USART1_2_3, 128 RxAltFuncSelector: AF7_USART1_2_3, 129 } 130 UART2 = &_UART2 131 _UART2 = UART{ 132 Buffer: NewRingBuffer(), 133 Bus: stm32.USART6, 134 TxAltFuncSelector: AF8_USART4_5_6, 135 RxAltFuncSelector: AF8_USART4_5_6, 136 } 137 UART3 = &_UART3 138 _UART3 = UART{ 139 Buffer: NewRingBuffer(), 140 Bus: stm32.USART1, 141 TxAltFuncSelector: AF7_USART1_2_3, 142 RxAltFuncSelector: AF7_USART1_2_3, 143 } 144 DefaultUART = UART1 145 ) 146 147 func initUART() { 148 UART1.Interrupt = interrupt.New(stm32.IRQ_USART3, _UART1.handleInterrupt) 149 UART2.Interrupt = interrupt.New(stm32.IRQ_USART6, _UART2.handleInterrupt) 150 UART3.Interrupt = interrupt.New(stm32.IRQ_USART1, _UART3.handleInterrupt) 151 } 152 153 // -- SPI ---------------------------------------------------------------------- 154 155 const ( 156 // #===========#==========#==============#==================#=======#=======# 157 // | Interface | Hardware | Bus(Freq) | SCK/SDI/SDO Pins | AltFn | Alias | 158 // #===========#==========#==============#==================#=======#=======# 159 // | SPI1 | SPI2 | APB1(42 MHz) | D23/D24/D25 | 5 | ~ | 160 // | SPI2 | SPI3 | APB1(42 MHz) | D2/D3/D4 | 6 | ~ | 161 // | SPI3 | SPI1 | APB2(84 MHz) | D17/D18/D19 | 5 | ~ | 162 // | --------- | -------- | ------------ | ---------------- | ----- | ----- | 163 // | SPI0 | SPI2 | APB1(42 MHz) | D23/D24/D25 | 5 | SPI1 | 164 // #===========#==========#==============#==================#=======#=======# 165 NUM_SPI_INTERFACES = 3 166 167 SPI1_SCK_PIN = D23 // 168 SPI1_SDI_PIN = D24 // SPI1 = hardware: SPI2 169 SPI1_SDO_PIN = D25 // 170 171 SPI2_SCK_PIN = D2 // 172 SPI2_SDI_PIN = D3 // SPI2 = hardware: SPI3 173 SPI2_SDO_PIN = D4 // 174 175 SPI3_SCK_PIN = D17 // 176 SPI3_SDI_PIN = D18 // SPI3 = hardware: SPI1 177 SPI3_SDO_PIN = D19 // 178 179 SPI0_SCK_PIN = SPI1_SCK_PIN // 180 SPI0_SDI_PIN = SPI1_SDI_PIN // SPI0 = alias: SPI1 181 SPI0_SDO_PIN = SPI1_SDO_PIN // 182 183 SPI_SCK_PIN = SPI0_SCK_PIN // 184 SPI_SDI_PIN = SPI0_SDI_PIN // default/primary SPI pins 185 SPI_SDO_PIN = SPI0_SDO_PIN // 186 ) 187 188 var ( 189 SPI1 = SPI{ 190 Bus: stm32.SPI2, 191 AltFuncSelector: AF5_SPI1_SPI2, 192 } 193 SPI2 = SPI{ 194 Bus: stm32.SPI3, 195 AltFuncSelector: AF6_SPI3, 196 } 197 SPI3 = SPI{ 198 Bus: stm32.SPI1, 199 AltFuncSelector: AF5_SPI1_SPI2, 200 } 201 SPI0 = SPI1 202 ) 203 204 func initSPI() {} 205 206 // -- I2C ---------------------------------------------------------------------- 207 208 const ( 209 // #===========#==========#==============#==============#=======#=======# 210 // | Interface | Hardware | Bus(Freq) | SDA/SCL Pins | AltFn | Alias | 211 // #===========#==========#==============#==============#=======#=======# 212 // | I2C1 | I2C1 | APB1(42 MHz) | D14/D15 | 4 | ~ | 213 // | I2C2 | I2C2 | APB1(42 MHz) | D0/D1 | 4 | ~ | 214 // | I2C3 | I2C1 | APB1(42 MHz) | D9/D10 | 4 | ~ | 215 // | --------- | -------- | ------------ | ------------ | ----- | ----- | 216 // | I2C0 | I2C1 | APB1(42 MHz) | D14/D15 | 4 | I2C1 | 217 // #===========#==========#==============#==============#=======#=======# 218 NUM_I2C_INTERFACES = 3 219 220 I2C1_SDA_PIN = D14 // I2C1 = hardware: I2C1 221 I2C1_SCL_PIN = D15 // 222 223 I2C2_SDA_PIN = D0 // I2C2 = hardware: I2C2 224 I2C2_SCL_PIN = D1 // 225 226 I2C3_SDA_PIN = D9 // I2C3 = hardware: I2C1 227 I2C3_SCL_PIN = D10 // (interface duplicated on second pair of pins) 228 229 I2C0_SDA_PIN = I2C1_SDA_PIN // I2C0 = alias: I2C1 230 I2C0_SCL_PIN = I2C1_SCL_PIN // 231 232 I2C_SDA_PIN = I2C0_SDA_PIN // default/primary I2C pins 233 I2C_SCL_PIN = I2C0_SCL_PIN // 234 235 SDA_PIN = I2C0_SDA_PIN 236 SCL_PIN = I2C0_SCL_PIN 237 ) 238 239 var ( 240 I2C1 = &I2C{ 241 Bus: stm32.I2C1, 242 AltFuncSelector: AF4_I2C1_2_3, 243 } 244 I2C2 = &I2C{ 245 Bus: stm32.I2C2, 246 AltFuncSelector: AF4_I2C1_2_3, 247 } 248 I2C3 = &I2C{ 249 Bus: stm32.I2C1, 250 AltFuncSelector: AF4_I2C1_2_3, 251 } 252 I2C0 = I2C1 253 ) 254 255 func initI2C() {}