Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0736c01
WIP
burgrp Nov 18, 2025
f2bb62b
WIP
burgrp Nov 18, 2025
43bcc36
WIP
burgrp Nov 21, 2025
065b744
WIP
burgrp Nov 21, 2025
4fefecb
WIP
burgrp Nov 28, 2025
30a1db1
WIP
burgrp Nov 29, 2025
7c876ab
WIP
burgrp Nov 29, 2025
dca5920
WIP
burgrp Nov 29, 2025
93eb60d
WIP
burgrp Nov 29, 2025
8a87063
WIP
burgrp Nov 29, 2025
722e1a0
WIP
burgrp Nov 30, 2025
ea82d3c
WIP
burgrp Nov 30, 2025
eb9e9a4
WIP
burgrp Nov 30, 2025
cb5ecef
WIP
burgrp Nov 30, 2025
8ce087a
WIP
burgrp Nov 30, 2025
7e43acf
WIP
burgrp Dec 2, 2025
1c07804
PR comments fixed
burgrp Dec 15, 2025
71cd7ba
pinout yamls removed
burgrp Dec 16, 2025
7fa20c4
machine: implement default UART pin configuration for Embedfire boards
burgrp Jan 6, 2026
32e5948
flash command moved to chip level so VS Code plugin can select bare chip
burgrp Jan 27, 2026
e9a2fa3
machine: add support for alternate pin mode configuration
burgrp Jan 27, 2026
637ba3d
WIP
burgrp Jan 27, 2026
d5fa72d
WIP
burgrp Feb 13, 2026
a2f7595
WIP
burgrp Feb 13, 2026
fe054f4
update subproject commit reference in net module
burgrp Feb 20, 2026
b4aa171
add build targets for embedfire on py32
burgrp Feb 20, 2026
6da46ee
add support for embedfire target in GNUmakefile for py32
burgrp Feb 20, 2026
1900e16
lib/py32-svd: remove duplicate DBGMCU.IDCODE CODE field
burgrp Feb 21, 2026
5788b18
update subproject commit reference in py32-svd
burgrp Feb 21, 2026
7e211e1
PR fixes
burgrp Mar 3, 2026
ff3eff4
refactor: update CPU frequency handling in machine and runtime packages
burgrp Mar 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ src/device/renesas/*.go
src/device/renesas/*.s
src/device/rp/*.go
src/device/rp/*.s
src/device/py32/*.go
src/device/py32/*.s
./vendor
llvm-build
llvm-project
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@
[submodule "lib/bdwgc"]
path = lib/bdwgc
url = https://github.com/ivmai/bdwgc.git
[submodule "lib/py32-svd"]
path = lib/py32-svd
url = https://github.com/burgrp/py32-svd.git
16 changes: 15 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ fmt-check: ## Warn if any source needs reformatting
@unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo " $$fn"; done; exit 1


gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-kendryte gen-device-nxp gen-device-rp ## Generate microcontroller-specific sources
gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-kendryte gen-device-nxp gen-device-rp gen-device-py32 ## Generate microcontroller-specific sources
ifneq ($(RENESAS), 0)
gen-device: gen-device-renesas
endif
Expand Down Expand Up @@ -262,6 +262,10 @@ gen-device-renesas: build/gen-device-svd
./build/gen-device-svd -source=https://github.com/cmsis-svd/cmsis-svd-data/tree/master/data/Renesas lib/cmsis-svd/data/Renesas/ src/device/renesas/
GO111MODULE=off $(GO) fmt ./src/device/renesas

gen-device-py32: build/gen-device-svd
./build/gen-device-svd -source=https://github.com/tinygo-org/py32-svd lib/py32-svd/svd src/device/py32/
GO111MODULE=off $(GO) fmt ./src/device/py32

$(LLVM_PROJECTDIR)/llvm:
git clone -b tinygo_20.x --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR)
llvm-source: $(LLVM_PROJECTDIR)/llvm ## Get LLVM sources
Expand Down Expand Up @@ -946,6 +950,16 @@ endif
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=hw-651-s110v8 examples/machinetest
@$(MD5SUM) test.hex
ifneq ($(PY32), 0)
$(TINYGO) build -size short -o test.hex -target=embedfire-py32f030 examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=embedfire-py32f030 examples/echo
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=embedfire-py32f002b examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=embedfire-py32f002b examples/echo
@$(MD5SUM) test.hex
endif
ifneq ($(WASM), 0)
$(TINYGO) build -size short -o wasm.wasm -target=wasm examples/wasm/export
$(TINYGO) build -size short -o wasm.wasm -target=wasm examples/wasm/main
Expand Down
1 change: 1 addition & 0 deletions lib/py32-svd
Submodule py32-svd added at cf2046
24 changes: 24 additions & 0 deletions src/machine/board_embedfire_py32f002b.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build embedfire_py32f002b

// Pin mappings for the Embedfire PY32F002B board.

package machine

// LEDs
const (
LED1 = PA1
LED2 = PA5
LED3 = PA4
LED = LED2
)

// Buttons
const (
KEY1 = PA3
KEY2 = PA0
)

func configureDefaultUARTPins() {
ConfigureUARTPin(PA6, 1) // TX
ConfigureUARTPin(PA7, 3) // RX
}
24 changes: 24 additions & 0 deletions src/machine/board_embedfire_py32f030.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build embedfire_py32f030

// Pin mappings for the Embedfire PY32F030 board.

package machine

// LEDs
const (
LED1 = PA2
LED2 = PA3
LED3 = PA4
LED = LED2
)

// Buttons
const (
KEY1 = PA5
KEY2 = PA6
)

func configureDefaultUARTPins() {
ConfigureUARTPin(PA7, 8) // TX
ConfigureUARTPin(PA8, 8) // RX
}
13 changes: 13 additions & 0 deletions src/machine/machine_py32_clock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build py32

package machine

// This variable must be updated after any change to the system clock from user code.
// Don't forget to re-initialize peripherals that depend on the system clock, such as:
// - runtime.ConfigureSystemTimer() for the system timer
// - machine.DefaultUART.Configure() if UART is in use
var CPUFrequencyHz uint32 = 24_000_000

func CPUFrequency() uint32 {
return CPUFrequencyHz
}
227 changes: 227 additions & 0 deletions src/machine/machine_py32_pin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
//go:build py32

package machine

import (
"device/py32"
"unsafe"
)

const deviceName = py32.Device

// Peripheral port offsets.
// Keep the same spacing used on other MCUs so helpers like Pin.getPortNumber
// can keep using simple division by 16.
const (
portA Pin = iota * 16
portB
portC
portD
portE
portF
)

const (
PA0 Pin = portA + iota
PA1
PA2
PA3
PA4
PA5
PA6
PA7
PA8
PA9
PA10
PA11
PA12
PA13
PA14
PA15
)

const (
PB0 Pin = portB + iota
PB1
PB2
PB3
PB4
PB5
PB6
PB7
PB8
PB9
PB10
PB11
PB12
PB13
PB14
PB15
)

const (
PC0 Pin = portC + iota
PC1
PC2
PC3
PC4
PC5
PC6
PC7
PC8
PC9
PC10
PC11
PC12
PC13
PC14
PC15
)

const (
PD0 Pin = portD + iota
PD1
PD2
PD3
PD4
PD5
PD6
PD7
PD8
PD9
PD10
PD11
PD12
PD13
PD14
PD15
)

const (
PE0 Pin = portE + iota
PE1
PE2
PE3
PE4
PE5
PE6
PE7
PE8
PE9
PE10
PE11
PE12
PE13
PE14
PE15
)

const (
PF0 Pin = portF + iota
PF1
PF2
PF3
PF4
PF5
PF6
PF7
PF8
PF9
PF10
PF11
PF12
PF13
PF14
PF15
)

const (
PinOutput PinMode = iota
PinInputFloating
PinInputPulldown
PinInputPullup
PinInputAnalog
PinAlternate
)
const PinInput PinMode = PinInputFloating

const (
gpioModeInput = py32.GPIO_MODER_MODE0_Input
gpioModeOutput = py32.GPIO_MODER_MODE0_Output
gpioModeAlternate = py32.GPIO_MODER_MODE0_Alternate
gpioModeAnalog = py32.GPIO_MODER_MODE0_Analog
gpioModeMask = py32.GPIO_MODER_MODE0_Msk

gpioPullFloating = py32.GPIO_PUPDR_PUPD0_Floating
gpioPullUp = py32.GPIO_PUPDR_PUPD0_PullUp
gpioPullDown = py32.GPIO_PUPDR_PUPD0_PullDown
gpioPullMask = py32.GPIO_PUPDR_PUPD0_Msk

gpioOutputSpeedLow = py32.GPIO_OSPEEDR_OSPEED0_LowSpeed
gpioOutputSpeedMedium = py32.GPIO_OSPEEDR_OSPEED0_MediumSpeed
gpioOutputSpeedHigh = py32.GPIO_OSPEEDR_OSPEED0_HighSpeed
gpioOutputSpeedVeryHigh = py32.GPIO_OSPEEDR_OSPEED0_VeryHighSpeed
gpioOutputSpeedMask = py32.GPIO_OSPEEDR_OSPEED0_Msk
)

func (p Pin) getPortNumber() uint8 {
return uint8(p) >> 4
}

func (p Pin) getPinNumber() uint8 {
return uint8(p) & 0x0F
}

func (p Pin) getPort() (*py32.GPIO_Type, uint8) {
offset := uintptr(p.getPortNumber()) * (uintptr(unsafe.Pointer(py32.GPIOB)) - uintptr(unsafe.Pointer(py32.GPIOA)))
return (*py32.GPIO_Type)(unsafe.Pointer(uintptr(unsafe.Pointer(py32.GPIOA)) + offset)), p.getPinNumber()
}

func (p Pin) Set(high bool) {
port, pin := p.getPort()
if high {
port.BSRR.Set(1 << pin)
} else {
port.BSRR.Set(1 << (pin + 16))
}
}

func (p Pin) Get() bool {
port, pin := p.getPort()
val := port.IDR.Get() & (1 << pin)
return val > 0
}

func (p Pin) Configure(config PinConfig) {
p.enableClock()
port, pin := p.getPort()
pos := (pin % 16) * 2

switch config.Mode {

case PinInputFloating:
port.MODER.ReplaceBits(gpioModeInput, gpioModeMask, pos)
port.PUPDR.ReplaceBits(gpioPullFloating, gpioPullMask, pos)
case PinInputPulldown:
port.MODER.ReplaceBits(gpioModeInput, gpioModeMask, pos)
port.PUPDR.ReplaceBits(gpioPullDown, gpioPullMask, pos)
case PinInputPullup:
port.MODER.ReplaceBits(gpioModeInput, gpioModeMask, pos)
port.PUPDR.ReplaceBits(gpioPullUp, gpioPullMask, pos)
case PinOutput:
port.MODER.ReplaceBits(gpioModeOutput, gpioModeMask, pos)
port.OTYPER.ReplaceBits(py32.GPIO_OTYPER_OT0_PushPull, py32.GPIO_OTYPER_OT0_Msk, pos>>1)
port.OSPEEDR.ReplaceBits(gpioOutputSpeedHigh, gpioOutputSpeedMask, pos)
case PinInputAnalog:
port.MODER.ReplaceBits(gpioModeAnalog, gpioModeMask, pos)
port.PUPDR.ReplaceBits(gpioPullFloating, gpioPullMask, pos)
case PinAlternate:
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
port.OSPEEDR.ReplaceBits(gpioOutputSpeedHigh, gpioOutputSpeedMask, pos)
}
}

func (p Pin) enableClock() {
portNo := p.getPortNumber()
py32.RCC.IOPENR.SetBits(1 << portNo)
}
12 changes: 12 additions & 0 deletions src/machine/machine_py32_pin_afrh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build py32 && !no_gpio_afrh

package machine

func (p Pin) SetAltFunc(af uint8) {
port, pin := p.getPort()
if pin >= 8 {
port.AFRH.ReplaceBits(uint32(af), 0xF, (pin%8)*4)
} else {
port.AFRL.ReplaceBits(uint32(af), 0xF, (pin%8)*4)
}
}
8 changes: 8 additions & 0 deletions src/machine/machine_py32_pin_no_afrh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build py32 && no_gpio_afrh

package machine

func (p Pin) SetAltFunc(af uint8) {
port, pin := p.getPort()
port.AFRL.ReplaceBits(uint32(af), 0xF, (pin%8)*4)
}
Loading
Loading