mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-31 09:49:03 +00:00
b420a8be17
* pinout yamls removed * machine: implement default UART pin configuration for Embedfire boards * flash command moved to chip level so VS Code plugin can select bare chip * machine: add support for alternate pin mode configuration * add build targets for embedfire on py32 * add support for embedfire target in GNUmakefile for py32 * lib/py32-svd: remove duplicate DBGMCU.IDCODE CODE field Update submodule to fix duplicate SetIDCODE/GetIDCODE method declarations in the generated py32f002bxx.go device file. * update subproject commit reference in py32-svd * refactor: update CPU frequency handling in machine and runtime packages * refactor: replace ConfigureUARTPin function with direct pin configuration in UART setup * SetAltFunc documentation for GPIO pin alternate functions * refactor: improve UART write and flush error handling with timeout * machine/py32: generalize UART driver to any USART Add a per-instance setup func to the UART type so the driver is no longer hardwired to USART1. DefaultUART stays USART1; add UART2 (USART2) in a separately build-tagged file since py32f002x parts lack USART2. RX IRQ handlers reference runtime-assigned vars to break the init cycle, and setup is assigned in the var initializer so it runs before InitSerial. Add the py32f003_32k_4k target (32K flash / 4K RAM). * Add canonical PY32F002, F003, and F030 density targets Use CMSIS/pyocd device names for target files and build tags. Add all F003 and F030 densities plus F002A/B, correct F002B to 24K flash and its own startup file, fix the F030x8 pyocd target, and update Embedfire inheritance. * Add targets for all PY32 CMSIS devices * Support all PY32 register layout variants * machine/py32: use generated register definitions * machine/py32: fix alternate-function documentation * machine/py32: report the configured CPU frequency * machine/py32: use unsafe.Add for GPIO ports * machine/py32: bound and yield UART polling * machine/py32: configure UART pins from UARTConfig * build: use the current PY32 SVD repository URL * test: cover PY32 UART register layouts * machine/py32: restore dynamic CPU frequency tracking * machine/py32: share the USART TX-ready bit * targets/py32: scale system stacks with RAM * machine/py32: keep clock state internal * targets/py32: normalize generated metadata * machine/py32: normalize GPIO configuration * machine/py32: fix T020 UART setup * machine/py32: reduce clock variant files * machine/py32: clean up UART variants * machine/py32: decouple UART clock capability * lib/py32-svd: use organization repository * runtime/py32: name 24MHz HSI encodings * machine/py32: derive startup clock from capability * machine/py32: use generated USART clock mask * machine/py32: name T020 8-bit UART mode * ci: include PY32 in sharded smoke tests * runtime: remove PY32 HSI frequency workaround
198 lines
4.7 KiB
Go
198 lines
4.7 KiB
Go
package compileopts
|
|
|
|
import (
|
|
"encoding/csv"
|
|
"errors"
|
|
"io/fs"
|
|
"os"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadTarget(t *testing.T) {
|
|
_, err := LoadTarget(&Options{Target: "arduino"})
|
|
if err != nil {
|
|
t.Error("LoadTarget test failed:", err)
|
|
}
|
|
|
|
_, err = LoadTarget(&Options{Target: "notexist"})
|
|
if err == nil {
|
|
t.Error("LoadTarget should have failed with non existing target")
|
|
}
|
|
|
|
if !errors.Is(err, fs.ErrNotExist) {
|
|
t.Error("LoadTarget failed for wrong reason:", err)
|
|
}
|
|
}
|
|
|
|
func TestGetTargetSpecs_InheritableOnlyTargetsExcluded(t *testing.T) {
|
|
specs, err := GetTargetSpecs()
|
|
if err != nil {
|
|
t.Fatal("GetTargetSpecs failed:", err)
|
|
}
|
|
|
|
// Inheritable-only processor-level targets should not appear in the listing.
|
|
inheritableOnlyTargets := []string{"esp32", "esp32c3", "esp32s3", "esp8266", "rp2040", "rp2350", "rp2350b"}
|
|
for _, name := range inheritableOnlyTargets {
|
|
if _, ok := specs[name]; ok {
|
|
t.Errorf("inheritable-only target %q should not appear in GetTargetSpecs", name)
|
|
}
|
|
}
|
|
|
|
// Board targets that inherit from inheritable-only targets should still appear.
|
|
boardTargets := []string{"esp32-coreboard-v2", "pico"}
|
|
for _, name := range boardTargets {
|
|
if _, ok := specs[name]; !ok {
|
|
t.Errorf("board target %q should appear in GetTargetSpecs", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestLoadTarget_InheritableOnlyTargetStillLoadable(t *testing.T) {
|
|
// Inheritable-only targets should still be loadable directly (for building).
|
|
_, err := LoadTarget(&Options{Target: "esp32"})
|
|
if err != nil {
|
|
t.Errorf("LoadTarget should still load inheritable-only target esp32: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestLoadPY32ConcreteTargets(t *testing.T) {
|
|
file, err := os.Open("../tools/gen-py32-targets/devices.csv")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer file.Close()
|
|
|
|
records, err := csv.NewReader(file).ReadAll()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, record := range records[1:] {
|
|
part, core := record[0], record[2]
|
|
t.Run(part, func(t *testing.T) {
|
|
spec, err := LoadTarget(&Options{Target: part})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if spec.LinkerScript == "" {
|
|
t.Error("concrete target has no linker script")
|
|
}
|
|
wantCPU := "cortex-m0plus"
|
|
if core == "m4" {
|
|
wantCPU = "cortex-m4"
|
|
}
|
|
if spec.CPU != wantCPU {
|
|
t.Errorf("CPU is %q, want %q", spec.CPU, wantCPU)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestOverrideProperties(t *testing.T) {
|
|
baseAutoStackSize := true
|
|
base := &TargetSpec{
|
|
GOOS: "baseGoos",
|
|
CPU: "baseCpu",
|
|
CFlags: []string{"-base-foo", "-base-bar"},
|
|
BuildTags: []string{"bt1", "bt2"},
|
|
DefaultStackSize: 42,
|
|
AutoStackSize: &baseAutoStackSize,
|
|
}
|
|
childAutoStackSize := false
|
|
child := &TargetSpec{
|
|
GOOS: "",
|
|
CPU: "chlidCpu",
|
|
CFlags: []string{"-child-foo", "-child-bar"},
|
|
AutoStackSize: &childAutoStackSize,
|
|
DefaultStackSize: 64,
|
|
}
|
|
|
|
base.overrideProperties(child)
|
|
|
|
if base.GOOS != "baseGoos" {
|
|
t.Errorf("Overriding failed : got %v", base.GOOS)
|
|
}
|
|
if base.CPU != "chlidCpu" {
|
|
t.Errorf("Overriding failed : got %v", base.CPU)
|
|
}
|
|
if !reflect.DeepEqual(base.CFlags, []string{"-base-foo", "-base-bar", "-child-foo", "-child-bar"}) {
|
|
t.Errorf("Overriding failed : got %v", base.CFlags)
|
|
}
|
|
if !reflect.DeepEqual(base.BuildTags, []string{"bt1", "bt2"}) {
|
|
t.Errorf("Overriding failed : got %v", base.BuildTags)
|
|
}
|
|
if *base.AutoStackSize != false {
|
|
t.Errorf("Overriding failed : got %v", base.AutoStackSize)
|
|
}
|
|
if base.DefaultStackSize != 64 {
|
|
t.Errorf("Overriding failed : got %v", base.DefaultStackSize)
|
|
}
|
|
|
|
baseAutoStackSize = true
|
|
base = &TargetSpec{
|
|
AutoStackSize: &baseAutoStackSize,
|
|
DefaultStackSize: 42,
|
|
}
|
|
child = &TargetSpec{
|
|
AutoStackSize: nil,
|
|
DefaultStackSize: 0,
|
|
}
|
|
base.overrideProperties(child)
|
|
if *base.AutoStackSize != true {
|
|
t.Errorf("Overriding failed : got %v", base.AutoStackSize)
|
|
}
|
|
if base.DefaultStackSize != 42 {
|
|
t.Errorf("Overriding failed : got %v", base.DefaultStackSize)
|
|
}
|
|
|
|
}
|
|
|
|
func TestConfigLinkerFlavor(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
target *TargetSpec
|
|
goos string
|
|
want string
|
|
}{
|
|
{
|
|
name: "default gnu",
|
|
target: &TargetSpec{},
|
|
goos: "linux",
|
|
want: "gnu",
|
|
},
|
|
{
|
|
name: "default coff",
|
|
target: &TargetSpec{},
|
|
goos: "windows",
|
|
want: "coff",
|
|
},
|
|
{
|
|
name: "default darwin",
|
|
target: &TargetSpec{},
|
|
goos: "darwin",
|
|
want: "darwin",
|
|
},
|
|
{
|
|
name: "target override",
|
|
target: &TargetSpec{
|
|
LinkerFlavor: "coff",
|
|
},
|
|
goos: "linux",
|
|
want: "coff",
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
tc.target.GOOS = tc.goos
|
|
config := &Config{
|
|
Options: &Options{},
|
|
Target: tc.target,
|
|
}
|
|
if got := config.LinkerFlavor(); got != tc.want {
|
|
t.Fatalf("LinkerFlavor() = %q, want %q", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|