Skip to content

Commit cfd74c2

Browse files
authored
Add stm32g0b1 support (#5150)
* Add STM32G0B1 target support Introduce support for STM32G0B1 microcontrollers, including target-specific JSON files, linker scripts, and runtime initialization. This update adds hardware support for GPIO, UART, SPI, I2C, timers, and additional board-specific configurations like Nucleo-G0B1RE. * Update STM32G0 clock initialization to 64MHz and adjust related configurations Reconfigure STM32G0 to use a 64MHz system clock via PLL with HSI16 as the source. Update flash latency, prescaler settings, and I2C timing values to reflect the new frequency. * Cleanup * Cleanup * Add STM32G0-specific UART implementation Introduce a new UART implementation for the STM32G0 series with chip-specific setup and configuration methods. Update the generic STM32 UART code to exclude STM32G0. * Refactor STM32G0 runtime and machine code to utilize chip-specific register access functions Simplify and standardize register operations with dedicated setter methods in the STM32G0 runtime and machine code and cleanup redundant syntax. * Remove redundant commented-out APBENR1 register operations in STM32G0 machine code * Introduce FDCAN support for STM32G0B1 series Add FDCAN peripheral implementation targeting STM32G0B1, including support for standard, extended identifiers, and bit rate configuration. Update board files to include FDCAN pins, instances, and clock configuration for Nucleo-G0B1RE and Amken Trio boards.
1 parent 9bcca97 commit cfd74c2

23 files changed

+2021
-9
lines changed

src/machine/board_amken_trio.go

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
//go:build amken_trio
2+
3+
// RabbitPNP Toolhead Board
4+
// MCU: STM32G0B1CBTx (LQFP48, 128KB Flash, 144KB RAM)
5+
6+
package machine
7+
8+
import (
9+
"device/stm32"
10+
"runtime/interrupt"
11+
)
12+
13+
// Vacuum sensors (PWM input via TIM2)
14+
const (
15+
VAC1 = PA0 // TIM2_CH1
16+
VAC2 = PA1 // TIM2_CH2
17+
)
18+
19+
// Motor 1 pins (stepper driver)
20+
const (
21+
M1_CS = PC7
22+
M1_DIR = PB13 // REFL
23+
M1_STEP = PB14 // REFR
24+
M1_ENN = PA10 // Enable (active low)
25+
)
26+
27+
// Motor 2 pins (stepper driver)
28+
const (
29+
M2_CS = PA9
30+
M2_DIR = PB12 // REFL
31+
M2_STEP = PB11 // REFR
32+
M2_ENN = PC6 // Enable (active low)
33+
)
34+
35+
// Motor 3 pins (stepper driver)
36+
const (
37+
M3_CS = PB15
38+
M3_DIR = PB2 // REFL
39+
M3_STEP = PB1 // REFR
40+
M3_ENN = PA8 // Enable (active low)
41+
)
42+
43+
// LED
44+
const (
45+
LED = LED1
46+
LED_BUILTIN = LED1
47+
LED1 = PB7
48+
)
49+
50+
// Solenoid and Neopixel (PWM via TIM4)
51+
const (
52+
SOLENOID = PB8 // TIM4_CH3
53+
NEOPIXEL = PB9 // TIM4_CH4
54+
)
55+
56+
// Endstops
57+
const (
58+
ENDSTOP_IN1 = PC13
59+
ENDSTOP_IN2 = PC14
60+
)
61+
62+
// Magnetic sensor
63+
const (
64+
MAG1 = PB3
65+
)
66+
67+
// Accelerometer chip select (LIS2D on SPI2)
68+
const (
69+
LIS2D_CS = PB5
70+
)
71+
72+
// SPI1 pins (motor drivers)
73+
const (
74+
SPI1_SCK_PIN = PA5
75+
SPI1_SDO_PIN = PA2 // MOSI
76+
SPI1_SDI_PIN = PA6 // MISO
77+
SPI0_SCK_PIN = SPI1_SCK_PIN
78+
SPI0_SDO_PIN = SPI1_SDO_PIN
79+
SPI0_SDI_PIN = SPI1_SDI_PIN
80+
)
81+
82+
// SPI2 pins (accelerometer)
83+
const (
84+
SPI2_SCK_PIN = PB10
85+
SPI2_SDO_PIN = PA4 // MOSI
86+
SPI2_SDI_PIN = PA3 // MISO
87+
)
88+
89+
// I2C2 pins
90+
const (
91+
I2C2_SCL_PIN = PA7
92+
I2C2_SDA_PIN = PB4
93+
I2C0_SCL_PIN = I2C2_SCL_PIN
94+
I2C0_SDA_PIN = I2C2_SDA_PIN
95+
)
96+
97+
// FDCAN1 pins
98+
const (
99+
CAN_RX = PD0
100+
CAN_TX = PD1
101+
)
102+
103+
// USB pins
104+
const (
105+
USB_DM = PA11
106+
USB_DP = PA12
107+
)
108+
109+
// UART pins (not directly connected but required by machine package)
110+
const (
111+
UART_TX_PIN = NoPin
112+
UART_RX_PIN = NoPin
113+
)
114+
115+
var (
116+
// SPI1 for motor drivers
117+
SPI1 = &SPI{
118+
Bus: stm32.SPI1,
119+
AltFuncSelector: AF0_SYSTEM,
120+
}
121+
SPI0 = SPI1
122+
123+
// SPI2 for accelerometer
124+
SPI2 = &SPI{
125+
Bus: stm32.SPI2,
126+
AltFuncSelector: AF1_TIM1_TIM2_TIM3_LPTIM1,
127+
}
128+
129+
// I2C2
130+
I2C2 = &I2C{
131+
Bus: stm32.I2C2,
132+
AltFuncSelector: AF6_SPI2_USART3_USART4_I2C1,
133+
}
134+
I2C0 = I2C2
135+
136+
// FDCAN1 on PD0 (RX) / PD1 (TX) with onboard transceiver
137+
CAN1 = &_CAN1
138+
_CAN1 = FDCAN{
139+
Bus: stm32.FDCAN1,
140+
TxAltFuncSelect: AF3_FDCAN1_FDCAN2,
141+
RxAltFuncSelect: AF3_FDCAN1_FDCAN2,
142+
instance: 0,
143+
}
144+
// Alias for convenience
145+
CAN0 = CAN1
146+
)
147+
148+
// Suppress unused import warning for interrupt package
149+
var _ = interrupt.New
150+
151+
func init() {
152+
// No UART configured on this board - uses USB or CAN for communication
153+
}

src/machine/board_nucleog0b1re.go

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
}

src/machine/machine_stm32_exti_syscfg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build stm32 && !stm32f1 && !stm32l5 && !stm32wlx
1+
//go:build stm32 && !stm32f1 && !stm32l5 && !stm32wlx && !stm32g0
22

33
package machine
44

src/machine/machine_stm32_gpio_reva.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build stm32 && !stm32l4 && !stm32l5 && !stm32wlx
1+
//go:build stm32 && !stm32l4 && !stm32l5 && !stm32wlx && !stm32g0
22

33
package machine
44

src/machine/machine_stm32_i2c_revb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build stm32l5 || stm32f7 || stm32l4 || stm32l0 || stm32wlx
1+
//go:build stm32l5 || stm32f7 || stm32l4 || stm32l0 || stm32wlx || stm32g0
22

33
package machine
44

src/machine/machine_stm32_rng.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build stm32 && !(stm32f103 || stm32l0x1)
1+
//go:build stm32 && !(stm32f103 || stm32l0x1 || stm32g0)
22

33
package machine
44

src/machine/machine_stm32_spi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build stm32 && !stm32f7x2 && !stm32l5x2
1+
//go:build stm32 && !stm32f7x2 && !stm32l5x2 && !stm32g0
22

33
package machine
44

src/machine/machine_stm32_uart.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//go:build stm32
1+
//go:build stm32 && !stm32g0
22

33
package machine
44

5-
// Peripheral abstraction layer for UARTs on the stm32 family.
5+
// Peripheral abstraction layer for UARTs on the stm32 family (except stm32g0).
66

77
import (
88
"device/stm32"

0 commit comments

Comments
 (0)