|
| 1 | +//go:build nucleog0b1re |
| 2 | + |
| 3 | +// Schematic: https://www.st.com/resource/en/user_manual/um2324-stm32-nucleo64-boards-mb1360-stmicroelectronics.pdf |
| 4 | +// Datasheet: https://www.st.com/resource/en/datasheet/stm32g0b1re.pdf |
| 5 | + |
| 6 | +package machine |
| 7 | + |
| 8 | +import ( |
| 9 | + "device/stm32" |
| 10 | + "runtime/interrupt" |
| 11 | +) |
| 12 | + |
| 13 | +const ( |
| 14 | + // Arduino Pins |
| 15 | + A0 = PA0 |
| 16 | + A1 = PA1 |
| 17 | + A2 = PA4 |
| 18 | + A3 = PB1 |
| 19 | + A4 = PA11 |
| 20 | + A5 = PA12 |
| 21 | + |
| 22 | + D0 = PB7 |
| 23 | + D1 = PB6 |
| 24 | + D2 = PA10 |
| 25 | + D3 = PB3 |
| 26 | + D4 = PB5 |
| 27 | + D5 = PB4 |
| 28 | + D6 = PB10 |
| 29 | + D7 = PA8 |
| 30 | + D8 = PA9 |
| 31 | + D9 = PC7 |
| 32 | + D10 = PB0 |
| 33 | + D11 = PA7 |
| 34 | + D12 = PA6 |
| 35 | + D13 = PA5 |
| 36 | + D14 = PB9 |
| 37 | + D15 = PB8 |
| 38 | +) |
| 39 | + |
| 40 | +// User LD4: the green LED is a user LED connected to ARDUINO signal D13 corresponding |
| 41 | +// to STM32 I/O PA5. |
| 42 | +const ( |
| 43 | + LED = LED_BUILTIN |
| 44 | + LED_BUILTIN = LED_GREEN |
| 45 | + LED_GREEN = PA5 |
| 46 | +) |
| 47 | + |
| 48 | +// User B1: the user button is connected to PC13. |
| 49 | +const ( |
| 50 | + BUTTON = PC13 |
| 51 | +) |
| 52 | + |
| 53 | +const ( |
| 54 | + // UART pins |
| 55 | + // PA2 and PA3 are connected to the ST-Link Virtual Com Port (VCP) |
| 56 | + UART_TX_PIN = PA2 |
| 57 | + UART_RX_PIN = PA3 |
| 58 | + |
| 59 | + // I2C pins |
| 60 | + // PB8 is SCL (connected to Arduino connector D15) |
| 61 | + // PB9 is SDA (connected to Arduino connector D14) |
| 62 | + I2C0_SCL_PIN = PB8 |
| 63 | + I2C0_SDA_PIN = PB9 |
| 64 | + |
| 65 | + // SPI pins |
| 66 | + SPI1_SCK_PIN = PA5 |
| 67 | + SPI1_SDI_PIN = PA6 |
| 68 | + SPI1_SDO_PIN = PA7 |
| 69 | + SPI0_SCK_PIN = SPI1_SCK_PIN |
| 70 | + SPI0_SDI_PIN = SPI1_SDI_PIN |
| 71 | + SPI0_SDO_PIN = SPI1_SDO_PIN |
| 72 | + |
| 73 | + // CAN pins (directly accessible on Nucleo-G0B1RE board) |
| 74 | + // FDCAN1: PA11 (TX) / PA12 (RX) using AF9 |
| 75 | + // FDCAN2: PD12 (TX) / PD13 (RX) using AF3 |
| 76 | + CAN1_TX_PIN = PA11 |
| 77 | + CAN1_RX_PIN = PA12 |
| 78 | + CAN2_TX_PIN = PD12 |
| 79 | + CAN2_RX_PIN = PD13 |
| 80 | +) |
| 81 | + |
| 82 | +var ( |
| 83 | + // USART2 is the hardware serial port connected to the onboard ST-LINK |
| 84 | + // debugger to be exposed as virtual COM port over USB on Nucleo boards. |
| 85 | + UART1 = &_UART1 |
| 86 | + _UART1 = UART{ |
| 87 | + Buffer: NewRingBuffer(), |
| 88 | + Bus: stm32.USART2, |
| 89 | + TxAltFuncSelector: AF1_TIM1_TIM2_TIM3_LPTIM1, |
| 90 | + RxAltFuncSelector: AF1_TIM1_TIM2_TIM3_LPTIM1, |
| 91 | + } |
| 92 | + DefaultUART = UART1 |
| 93 | + |
| 94 | + // I2C1 is documented, alias to I2C0 as well |
| 95 | + I2C1 = &I2C{ |
| 96 | + Bus: stm32.I2C1, |
| 97 | + AltFuncSelector: AF6_SPI2_USART3_USART4_I2C1, |
| 98 | + } |
| 99 | + I2C0 = I2C1 |
| 100 | + |
| 101 | + // SPI1 is documented, alias to SPI0 as well |
| 102 | + SPI1 = &SPI{ |
| 103 | + Bus: stm32.SPI1, |
| 104 | + AltFuncSelector: AF0_SYSTEM, |
| 105 | + } |
| 106 | + SPI0 = SPI1 |
| 107 | + |
| 108 | + // FDCAN1 on PA11 (TX) / PA12 (RX) |
| 109 | + CAN1 = &_CAN1 |
| 110 | + _CAN1 = FDCAN{ |
| 111 | + Bus: stm32.FDCAN1, |
| 112 | + TxAltFuncSelect: AF9_FDCAN1_FDCAN2, |
| 113 | + RxAltFuncSelect: AF9_FDCAN1_FDCAN2, |
| 114 | + instance: 0, |
| 115 | + } |
| 116 | + |
| 117 | + // FDCAN2 on PD12 (TX) / PD13 (RX) |
| 118 | + CAN2 = &_CAN2 |
| 119 | + _CAN2 = FDCAN{ |
| 120 | + Bus: stm32.FDCAN2, |
| 121 | + TxAltFuncSelect: AF3_FDCAN1_FDCAN2, |
| 122 | + RxAltFuncSelect: AF3_FDCAN1_FDCAN2, |
| 123 | + instance: 1, |
| 124 | + } |
| 125 | +) |
| 126 | + |
| 127 | +func init() { |
| 128 | + UART1.Interrupt = interrupt.New(stm32.IRQ_USART2_LPUART2, _UART1.handleInterrupt) |
| 129 | + // Note: FDCAN interrupts share with USB (IRQ_UCPD1_UCPD2_USB = 8) |
| 130 | + // User should configure interrupts via SetInterrupt method if needed |
| 131 | +} |
0 commit comments