Skip to content

Minor correction to the pio/rp2-pio/examples/blinky/main.go #25

@tinkerator

Description

@tinkerator

I'm exploring how to use PIO on a pico2-ice board with an R2350B chip. This chip runs at 150MHz, and not what this code hardcodes as 125MHz. I'm not sure what board runs at that speed, but recognize it is a target specific value.

Also, comparing the blinking rate of what I was attempting and what I was able to see with a logic analyzer, I saw the ability to generate the desired clock started to undershoot as I increased the target frequency.

Staring at the PIO code and the calculation, I realized that the code does not account for the 3 clock cycles per half of the square wave that the code executes. I find the following rewrite of this main.go function generates much more timing accurate frequencies:

func blinkPinForever(sm pio.StateMachine, offset uint8, pin machine.Pin, freq uint32) {
	blinkProgramInit(sm, offset, pin)
	clockFreq := machine.CPUFrequency()
	sm.SetEnabled(true)
	println("Blinking", int(pin), "at", freq, "Hz")
	sm.TxPut(uint32(clockFreq/(2*freq)) - 3)
}

PS I'd submit this in the form of a pull request, or patch, but am wondering how this is supposed to be built? My attempt to compile the two files in this directory main.go and blink_pio.go at the same time, with tinygo, generates a failure to compile:

$ ~/go/bin/tinygo flash -target=pico2-ice  blink_pio.go  main.go
/home/tinkerer/gits/tinygo/src/runtime/scheduler_cores.go:150: linker could not find symbol main.main
$ ~/go/bin/tinygo flash -target=pico2-ice  main.go blink_pio.go
# command-line-arguments
main.go:17:32: undefined: blinkInstructions
main.go:17:51: undefined: blinkOrigin
main.go:29:2: undefined: blinkProgramInit

The pico2-ice port is a pending pull request for tinygo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions