Skip to content

Commit 84756c5

Browse files
committed
machine: implement default UART pin configuration for Embedfire boards
1 parent 6b9edf3 commit 84756c5

File tree

6 files changed

+23
-25
lines changed

6 files changed

+23
-25
lines changed

src/machine/board_embedfire_py32f002b.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ const (
1818
KEY2 = PA0
1919
)
2020

21-
// UART
22-
const (
23-
DEFAULT_UART_TX_PIN = PA6
24-
DEFAULT_UART_RX_PIN = PA7
25-
DEFAULT_UART_TX_PIN_AF = 1
26-
DEFAULT_UART_RX_PIN_AF = 3
27-
)
21+
func configureDefaultUARTPins() {
22+
ConfigureUARTPin(PA6, 1) // TX
23+
ConfigureUARTPin(PA7, 3) // RX
24+
}

src/machine/board_embedfire_py32f030.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ const (
1818
KEY2 = PA6
1919
)
2020

21-
// UART
22-
const (
23-
DEFAULT_UART_TX_PIN = PA7
24-
DEFAULT_UART_RX_PIN = PA8
25-
DEFAULT_UART_TX_PIN_AF = 8
26-
DEFAULT_UART_RX_PIN_AF = 8
27-
)
21+
func configureDefaultUARTPins() {
22+
ConfigureUARTPin(PA7, 8) // TX
23+
ConfigureUARTPin(PA8, 8) // RX
24+
}

src/machine/machine_py32_uart.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,11 @@ var DefaultUART = &UART{Bus: py32.USART1, Buffer: NewRingBuffer()}
2323
// ConfigureWithClock initializes the UART using the provided peripheral clock
2424
// frequency (in Hz). This avoids assuming a fixed MCU clock.
2525
func (uart *UART) ConfigureWithClock(config UARTConfig, clockHz uint32) error {
26+
2627
if config.BaudRate == 0 {
2728
config.BaudRate = 115200
2829
}
2930

30-
// Configure default pins if they weren't provided.
31-
if config.TX == 0 {
32-
ConfigureUARTPin(DEFAULT_UART_TX_PIN, DEFAULT_UART_TX_PIN_AF)
33-
}
34-
35-
if config.RX == 0 {
36-
ConfigureUARTPin(DEFAULT_UART_RX_PIN, DEFAULT_UART_RX_PIN_AF)
37-
}
38-
3931
// Enable peripheral clock.
4032
py32.RCC.APBENR2.SetBits(py32.RCC_APBENR2_USART1EN)
4133

@@ -56,6 +48,8 @@ func (uart *UART) ConfigureWithClock(config UARTConfig, clockHz uint32) error {
5648
uart.irq.SetPriority(0xc0)
5749
uart.irq.Enable()
5850

51+
configureDefaultUARTPins()
52+
5953
return nil
6054
}
6155

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build py32 && !default_uart_pins
2+
3+
package machine
4+
5+
func configureDefaultUARTPins() {
6+
// There are no default UART pins for this board. Configure them in
7+
// application main() using ConfigureUARTPin().
8+
}

targets/embedfire-py32f002b.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
],
55
"flash-command": "pyocd load -t py32f002bx5 {bin}",
66
"build-tags": [
7-
"embedfire_py32f002b"
7+
"embedfire_py32f002b",
8+
"default_uart_pins"
89
]
910
}

targets/embedfire-py32f030.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
],
55
"flash-command": "pyocd load -t py32f003x8 {bin}",
66
"build-tags": [
7-
"embedfire_py32f030"
7+
"embedfire_py32f030",
8+
"default_uart_pins"
89
]
910
}

0 commit comments

Comments
 (0)