tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

rp2040: fix errata RP2040-E5 issue

Open sago35 opened this issue 2 years ago • 2 comments

https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/rp2040_usb_device_enumeration.c

sago35 avatar Jul 14 '22 15:07 sago35

As noted in the comments below, the code in this PR is probably working correctly. However, I am still not sure.

https://github.com/tinygo-org/tinygo/issues/3012#issuecomment-1192745833

tinygo flash failed when USB-CDC exchange was executed from another microcontroller with the same USB-HUB.
To be clear, USB Enumeration has failed.

https://github.com/tinygo-org/tinygo/pull/2991 source will allow successful USB Enumeration.
Perhaps a workaround for errata is done.

sago35 avatar Jul 28 '22 00:07 sago35

RP2040-E5 fix ready for review. It is difficult to verify that this change has been implemented correctly. However, as mentioned above, there are cases where it is working well and should be added.

sago35 avatar Sep 17 '22 05:09 sago35

@sago35 just wondering if we should be checking the chip version for this fix, similar to https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/rp2040_usb_device_enumeration.c#L27

deadprogram avatar Dec 19 '22 15:12 deadprogram

@deadprogram version check added.

I checked machine.ChipVersion() with the following code. The ChipVersion is probably obtained correctly.

pico (B0 chip)

$ tinygo flash --target pico --size short --monitor ./_x/rp2040_version/
   code    data     bss |   flash     ram
  49128    1460    3184 |   50588    4644
Connected to COM48. Press Ctrl-C to exit.
machine.ChipVersion : 01

pico-w (B2 chip)

$ tinygo flash --target pico --size short --monitor ./_x/rp2040_version/
   code    data     bss |   flash     ram
  49128    1460    3184 |   50588    4644
Connected to COM48. Press Ctrl-C to exit.
machine.ChipVersion : 02

test code

package main

import (
	"fmt"
	"machine"
	"time"
)

func main() {
	for {
		fmt.Printf("machine.ChipVersion : %02X\n", machine.ChipVersion())
		time.Sleep(1 * time.Second)
	}
}

The const values were described below.

SYSINFO_BASE https://github.com/raspberrypi/pico-sdk/blob/2e6142b15b8a75c1227dd3edbe839193b2bf9041/src/rp2040/hardware_regs/include/hardware/regs/addressmap.h#L37

SYSINFO_CHIP_ID_OFFSET https://github.com/raspberrypi/pico-sdk/blob/2e6142b15b8a75c1227dd3edbe839193b2bf9041/src/rp2040/hardware_regs/include/hardware/regs/sysinfo.h#L17

SYSINFO_CHIP_ID_REVISION_BITS https://github.com/raspberrypi/pico-sdk/blob/2e6142b15b8a75c1227dd3edbe839193b2bf9041/src/rp2040/hardware_regs/include/hardware/regs/sysinfo.h#L24

SYSINFO_CHIP_ID_REVISION_LSB https://github.com/raspberrypi/pico-sdk/blob/2e6142b15b8a75c1227dd3edbe839193b2bf9041/src/rp2040/hardware_regs/include/hardware/regs/sysinfo.h#L26

sago35 avatar Dec 20 '22 00:12 sago35

Sometimes machine_rp2040_enter_bootloader.go fails. It may be due to CGO, but I am not sure. Any ideas? @aykevl

https://github.com/tinygo-org/tinygo/blob/rp2040-e5/src/machine/machine_rp2040_enter_bootloader.go

 D:/a/tinygo/tinygo/build/tinygo/bin/tinygo build -size short -o test.hex -target=badger2040          examples/blinky1
# machine
Error: build\tinygo\src\machine\machine_rp2040_enter_bootloader.go:27:1: error: stack nearly exhausted; compilation time may suffer, and crashes due to stack overflow are likely
mingw32-make: *** [makefile:615: smoketest] Error 1
Error: Process completed with exit code 2.

sago35 avatar Dec 20 '22 11:12 sago35

@sago35 that is one of the occasional errors that only occur in the Windows smoke tests. Something is not quite correct, but not sure it can be attributed to the place the error appears. However, not sure on that one.

deadprogram avatar Dec 20 '22 11:12 deadprogram

Thanks for making the requested changes @sago35 now merging.

deadprogram avatar Dec 20 '22 14:12 deadprogram