Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RP2350 support #4459

Draft
wants to merge 19 commits into
base: dev
Choose a base branch
from
Draft

Add RP2350 support #4459

wants to merge 19 commits into from

Conversation

soypat
Copy link
Contributor

@soypat soypat commented Sep 8, 2024

Seeks to solve #4452.

Notes:

  • gen-device-svd.go Changed to support multiline Metadata descriptions such as the one found for the RP2350.
  • rp2350.ld takes rust version as reference. Ideally I'd like a minimal version, I've left it all in so people with more experience can note of what is required and what is "extra"
  • There's two packages, QFN-60 with 30 GPIOs and QFN80 with 48 GPIOs. I imagine we could expose all 48 GPIOs for the rp2350 and avoid making the distinction at the package level. Board would expose GP* pins.
  • Pico-sdk's second stage bootloader is spagghetified from what I can tell. Not sure which is the assembly we should be running... that said:
  • Likely candidate is boot2_generic_03h which is apparently what Rust uses. I've tried adding it as best as I could

Copy link

github-actions bot commented Sep 8, 2024

Size difference with the dev branch:

Binary size difference
 flash                          ram
 before   after   diff          before   after   diff
  16716   16716      0   0.00%    4172    4172      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/adafruit4650
  61472   61472      0   0.00%    6180    6180      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adt7410/main.go
   9568    9568      0   0.00%    4748    4748      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adxl345/main.go
  13568   13568      0   0.00%    6788    6788      0   0.00% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/amg88xx
   8680    8680      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/main.go
  11884   11884      0   0.00%    6580    6580      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/apds9960/proximity/main.go
   9760    9760      0   0.00%    4752    4752      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/itsybitsy-m0/main.go
   8368    8368      0   0.00%    2320    2320      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/at24cx/main.go
   8124    8124      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bh1750/main.go
   7432    7432      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/blinkm/main.go
  70632   70632      0   0.00%    3660    3660      0   0.00% tinygo build -size short -o ./build/test.hex -target=pinetime     ./examples/bma42x/main.go
  64012   64012      0   0.00%    6196    6196      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmi160/main.go
  27412   27412      0   0.00%    4780    4780      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp180/main.go
  64072   64072      0   0.00%    6228    6228      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp280/main.go
  12200   12200      0   0.00%    4812    4812      0   0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bmp388/main.go
   8176    8176      0   0.00%    3344    3344      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/sram/main.go
  22216   22216      0   0.00%    3540    3540      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/time/main.go
  69768   69768      0   0.00%    6368    6368      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/ds3231/main.go
   4620    4620      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/easystepper/main.go
  69304   69304      0   0.00%    6968    6968      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/flash/console/spi
  65644   65644      0   0.00%    9004    9004      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/flash/console/qspi
   7212    7212      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/gc9a01/main.go
  67628   67628      0   0.00%    6360    6360      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/i2c/main.go
  68164   68164      0   0.00%    6504    6504      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/uart/main.go
   7872    7872      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/hcsr04/main.go
   5832    5832      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hd44780/customchar/main.go
   5784    5784      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hd44780/text/main.go
  10528   10528      0   0.00%    4748    4748      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/hd44780i2c/main.go
  14808   14808      0   0.00%    6580    6580      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/hts221/main.go
  16148   16148      0   0.00%    2360    2360      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hub75/main.go
  10152   10152      0   0.00%    6916    6916      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/basic
  10644   10644      0   0.00%    4868    4868      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/ili9341/basic
  29508   29508      0   0.00%   38076   38076      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/pyportal_boing
  10172   10172      0   0.00%    6916    6916      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/scroll
  10732   10732      0   0.00%    4868    4868      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/ili9341/scroll
 263712  263712      0   0.00%   46748   46748      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/slideshow
  11732   11732      0   0.00%    4780    4780      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis3dh/main.go
  14152   14152      0   0.00%    6580    6580      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/lps22hb/main.go
  26132   26132      0   0.00%    2328    2328      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/lsm303agr/main.go
  12448   12448      0   0.00%    4788    4788      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/lsm6ds3/main.go
  10744   10744      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mag3110/main.go
   9920    9920      0   0.00%    4780    4780      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp23017/main.go
  10372   10372      0   0.00%    4788    4788      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp23017-multiple/main.go
   9780    9780      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp3008/main.go
  68656   68656      0   0.00%    6188    6188      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp2515/main.go
  27224   27224      0   0.00%    3632    3632      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/microbitmatrix/main.go
  26944   26944      0   0.00%    5680    5680      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit-v2 ./examples/microbitmatrix/main.go
   8240    8240      0   0.00%    4748    4748      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mma8653/main.go
   8148    8148      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mpu6050/main.go
  75640   75640      0   0.00%    7448    7448      0   0.00% tinygo build -size short -o ./build/test.hex -target=p1am-100 ./examples/p1am/main.go
   6228    6228      0   0.00%    3288    3288      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setbuffer/main.go
   5260    5260      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setpixel/main.go
  10540   10540      0   0.00%    3328    3328      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/seesaw
   2825    2825      0   0.00%     558     558      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino ./examples/servo
  13772   13772      0   0.00%    3400    3400      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico     ./examples/sgp30
   8080    8080      0   0.00%    6788    6788      0   0.00% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/shifter/main.go
  57476   57476      0   0.00%    3684    3684      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht3x/main.go
  57532   57532      0   0.00%    3692    3692      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht4x/main.go
  57448   57448      0   0.00%    3684    3684      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/shtc3/main.go
   6688    6688      0   0.00%    2288    2288      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1306/i2c_128x32/main.go
   6140    6140      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1306/spi_128x64/main.go
   5844    5844      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1331/main.go
   6788    6788      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7735/main.go
   6700    6700      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7789/main.go
  16964   16964      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/thermistor/main.go
  10604   10604      0   0.00%    4540    4540      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-bluefruit ./examples/tone
  10064   10064      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/tm1637/main.go
  10872   10872      0   0.00%    3340    3340      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/touch/capacitive
   9524    9524      0   0.00%    6780    6780      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/touch/resistive/fourwire/main.go
  12596   12596      0   0.00%    6976    6976      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/touch/resistive/pyportal_touchpaint/main.go
  14980   14980      0   0.00%    4748    4748      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl53l1x/main.go
  13460   13460      0   0.00%    4748    4748      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl6180x/main.go
  24616   24616      0   0.00%   13720   13720      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840-sense ./examples/waveshare-epd/epd1in54/main.go
   6488    6488      0   0.00%    2320    2320      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13/main.go
   6176    6176      0   0.00%    2312    2312      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13x/main.go
   6400    6400      0   0.00%    2320    2320      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd4in2/main.go
  26140   26140      0   0.00%   16412   16412      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/waveshare-epd/epd2in66b/main.go
   6848    6848      0   0.00%    4780    4780      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/ws2812
   5764    5764      0   0.00%    9522    9522      0   0.00% tinygo build -size short -o ./build/test.bin -target=m5stamp-c3          ./examples/ws2812
  62532   62532      0   0.00%    5952    5952      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/is31fl3731/main.go
   1581    1581      0   0.00%     598     598      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino   ./examples/ws2812
   1056    1056      0   0.00%     180     180      0   0.00% tinygo build -size short -o ./build/test.hex -target=digispark ./examples/ws2812
  31856   31856      0   0.00%    4780    4780      0   0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bme280/main.go
  16436   16436      0   0.00%    4724    4724      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/microphone/main.go
  11080   11080      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/buzzer/main.go
  12788   12788      0   0.00%    4780    4780      0   0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/veml6070/main.go
   6752    6752      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l293x/simple/main.go
   8664    8664      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l293x/speed/main.go
   6720    6720      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l9110x/simple/main.go
   9276    9276      0   0.00%    4748    4748      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l9110x/speed/main.go
   7336    7336      0   0.00%    3316    3316      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-f103rb ./examples/shiftregister/main.go
   7012    7012      0   0.00%    2268    2268      0   0.00% tinygo build -size short -o ./build/test.hex -target=hifive1b ./examples/ssd1351/main.go
  13004   13004      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis2mdl/main.go
   8876    8876      0   0.00%    4756    4756      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/max72xx/main.go
  77348   77348      0   0.00%    6336    6336      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/dht/main.go
  36584   36584      0   0.00%    3988    3988      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/pcf8523/
  71368   71368      0   0.00%    6336    6336      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/alarm/
   7276    7276      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/clkout/
  70904   70904      0   0.00%    6332    6332      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/time/
  71328   71328      0   0.00%    6344    6344      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/timer/
  12188   12188      0   0.00%    3304    3304      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/qmi8658c/main.go
  10812   10812      0   0.00%    3288    3288      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/pcf8591/
   8744    8744      0   0.00%    4748    4748      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/ina260/main.go
  13196   13196      0   0.00%    4780    4780      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/ina219/main.go
   9308    9308      0   0.00%    5240    5240      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-l432kc ./examples/aht20/main.go
  72756   72756      0   0.00%   10748   10748      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/sdcard/console/
  61608   61608      0   0.00%    8232    8232      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/i2csoft/adt7410/
  10296   10296      0   0.00%    6788    6788      0   0.00% tinygo build -size short -o ./build/test.elf -target=wioterminal ./examples/axp192/m5stack-core2-blinky/
   9032    9032      0   0.00%    3276    3276      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/xpt2046/main.go
  13308   13308      0   0.00%    4928    4928      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/sx126x/lora_rxtx/
  31312   31312      0   0.00%    4540    4540      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/ssd1289/main.go
  11260   11260      0   0.00%    4252    4252      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/irremote/main.go
  12000   12000      0   0.00%    3324    3324      0   0.00% tinygo build -size short -o ./build/test.hex -target=badger2040 ./examples/uc8151/main.go
  10440   10440      0   0.00%    3356    3356      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/scd4x/main.go
   8552    8552      0   0.00%    4748    4748      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=circuitplay-express ./examples/makeybutton/main.go
   9664    9664      0   0.00%    4764    4764      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ds18b20/main.go
  82764   82764      0   0.00%    6576    6576      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/lora/lorawan/atcmd/
  15920   15920      0   0.00%    4868    4868      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/as560x/main.go
   9892    9892      0   0.00%    3296    3296      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mpu6886/main.go
   7808    7808      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ttp229/main.go
  66928   66928      0   0.00%    4816    4816      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/ndir/main_ndir.go
  62364   62364      0   0.00%    3780    3780      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ndir/main_ndir.go
  65348   65348      0   0.00%    6252    6252      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ndir/main_ndir.go
   9320    9320      0   0.00%    3288    3288      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mpu9150/main.go
  11400   11400      0   0.00%    3324    3324      0   0.00% tinygo build -size short -o ./build/test.hex -target=macropad-rp2040 ./examples/sh1106/macropad_spi
   8460    8460      0   0.00%    3760    3760      0   0.00% tinygo build -size short -o ./build/test.hex -target=macropad-rp2040 ./examples/encoders/quadrature-interrupt
  65888   65888      0   0.00%    4784    4784      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mcp9808/main.go
  85988   85988      0   0.00%    5140    5140      0   0.00% tinygo build -size short -o ./build/test.hex -target=challenger-rp2040 ./examples/net/ntpclient/
 296180  296180      0   0.00%   13776   13776      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal -stack-size 8kb ./examples/net/http-get/
 118864  118864      0   0.00%    7832    7832      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 -stack-size 8kb ./examples/net/tcpclient/
 244988  244988      0   0.00%   10476   10476      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb ./examples/net/websocket/dial/
 102760  102760      0   0.00%    9808    9808      0   0.00% tinygo build -size short -o ./build/test.hex -target=metro-m4-airlift -stack-size 8kb ./examples/net/socket/
 338132  338132      0   0.00%   15352   15352      0   0.00% tinygo build -size short -o ./build/test.hex -target=matrixportal-m4 -stack-size 8kb ./examples/net/webstatic/
 111092  111092      0   0.00%    7764    7764      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-mkrwifi1010 -stack-size 8kb ./examples/net/tlsclient/
 153720  153720      0   0.00%    6540    6540      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb ./examples/net/mqttclient/natiu/
 116688  116688      0   0.00%   13124   13124      0   0.00% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/webclient/
 285876  285876      0   0.00%   17804   17804      0   0.00% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/webserver/
 286756  286756      0   0.00%   18192   18192      0   0.00% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/mqttclient/paho/
  12256   12260      4   0.03%    3352    3352      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/pca9685/main.go
5329118 5329122      4   0.00%  810370  810370      0   0.00%

@deadprogram
Copy link
Member

This is great @soypat thank you for getting going on it!

Please see tinygo-org/cmsis-svd-data#1 for some related supporting work.

@soypat
Copy link
Contributor Author

soypat commented Sep 8, 2024

Yes! I've looked at it and generated the device definitions. I just added a new commit with stubs for machine and runtime and am getting the following error during linking:

$ tinygo build -target=rp2350 -serial=none  examples/blinky1 
ld.lld: error: unable to insert .start_block after .vector_table
ld.lld: error: no memory region specified for section '.ARM.exidx'
ld.lld: error: no memory region specified for section '.text'

@deadprogram
Copy link
Member

I'm not too sure that the ld file you added will actually work with TinyGo. You probably need to have mostly the same symbols in same order as other platforms.

@soypat
Copy link
Contributor Author

soypat commented Sep 8, 2024

OK, blinky1 now compiles. I am afraid of flashing the resulting .uf2 😅

@soypat
Copy link
Contributor Author

soypat commented Sep 8, 2024

I've noticed the bootloader is not included in the build pipeline. I can write invalid assembly in it and everything still compiles...

Copy link

@rminnich rminnich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my main concerns:
absolutely, make sure serial out is functional
make sure panic works
empty functions should panic
make sure all that stuff in ldscript is right
#if should have no defaults, there should always be a value, and the default should be "something was not set that is expected to be set"

src/machine/machine_rp2350.go Outdated Show resolved Hide resolved
src/machine/machine_rp2350.go Outdated Show resolved Hide resolved
src/runtime/runtime_rp2350.go Show resolved Hide resolved
src/runtime/runtime_rp2350.go Show resolved Hide resolved
targets/rp2350.ld Show resolved Hide resolved
sw a0, QMI_M0_RCMD_OFFSET(a3)
li a0, INIT_M0_RFMT
sw a0, QMI_M0_RFMT_OFFSET(a3)
#else
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make the #else have an actual value, #elseif arm and have the fallthrough #else do a #error. Maybe that's too picky, but I've been burned by default behavior.

@soypat
Copy link
Contributor Author

soypat commented Sep 10, 2024

@rminnich I'll leave all functions so far in panic("unimplemented") state. We should focus on getting the bootloader working and setting the LED pin high/low.

@soypat
Copy link
Contributor Author

soypat commented Sep 11, 2024

@deadprogram @aykevl I'm melding the RP2040 and RP2350 APIs... it's got some design decisions that some may consider questionable. I've managed to reuse a lot of logic between them at the cost of some magic constant weirdness. There are a few cases where code reuse was just not worth it though such as with the peripheral reset. Love to hear your input on how it is coming along.

@soypat
Copy link
Contributor Author

soypat commented Sep 14, 2024

OK I feel like I've gotten the hang of writing Cortex assembler and understand what is going on with the linker scripts. I cannot however get to the point of flashing the RP2350 correctly- after I flash it the RP2350 enters bootoader mode and appears as a mass storage device ready to get flashed again.

@soypat
Copy link
Contributor Author

soypat commented Sep 14, 2024

Aha, looks like things have changed since the RP2040. We now have to build a valid IMAGE_DEF, which is a binary blob with specific format.
image

@soypat
Copy link
Contributor Author

soypat commented Sep 15, 2024

Working on a a pico binary encoder/decoder https://github.com/soypat/picobin. Raspberry Pi's picotool is missing lots of features to inspect binaries, which makes sense- it's not designed to reverse engineer their stuff.

Also RP2350 documentation on pico binary layout is VERY lackluster compared to their hardware documentation so having code to describe the layout gives me confidence on what exactly is going on.

@soypat
Copy link
Contributor Author

soypat commented Sep 22, 2024

OK. I've run into a limitation of the debug/elf package. I need to patch the bootloader by extending its length. I'm thinking of adding a elf implementation that can get the job done to https://github.com/soypat/tinyboot.

Note: @aykevl This PR would add aforementioned tinyboot as a dependency of tinygo compiler. I'm in favor of third partying build tools so that others can use the package and find bugs in parallel to the TinyGo compiler.

Edit: progress here: https://github.com/soypat/tinyboot/tree/main/build/xelf

@cibomahto
Copy link

cibomahto commented Nov 17, 2024

Thanks for all you great work on this! I was able to bodge together enough fixes to build a working RP2350 GPIO out example here: Blinkinlabs@fbb5234

I cheated in several ways to get it to work so it isn't pullable as-is. The main changes were:

  • remove the second stage bootloader- the documentation suggests that it's no longer needed unless you have a weird spi flash chip, and elf files generated by the pico 2 sdk don't seem to include it. The functionality has been moved into the boot rom.
  • add a stub embedded block right after the isr vector table, so that the boot rom can identify the image. I borrowed this from the rp2350 datasheet. A more complete system like you are describing would include a second block at the end of the image. The elf files generated by the pico 2 sdk include this second block. I think the only function it serves is to verify that the entire image was written into flash, as the default block doesn't include an image checksum.

After disabling some other initialization bits which were causing the image to hang, I succeeded in running a very short that just turns the LED on and off repeatedly.

package main

import (
        "machine"
)

func main() {

    led := machine.LED
    led.Configure(machine.PinConfig{Mode: machine.PinOutput})

    for {
        led.Low()
        led.High()
    }
}

@cibomahto
Copy link

Here's also a very basic python tool for extracting IMAGE_BLOCKs from rp2350 ELF files: https://gist.github.com/cibomahto/790c1a34d6001a088de9bfba6e27ed23

@aykevl
Copy link
Member

aykevl commented Nov 18, 2024

I need to patch the bootloader by extending its length.

@soypat What do you mean by this? It's generally not possible to move stuff in the firmware file after linking.

@aykevl
Copy link
Member

aykevl commented Nov 18, 2024

Would it be possible to write binaries in a similar way that ESP8266/ESP32 binaries are created? So the ELF file is not modified, instead the ELF file is converted to a binary in a custom way that adds the special header.

@cibomahto
Copy link

@aykevl Looking at the esp builder:

I think not, because for the RP2350, the pico SDK generates a normal ELF image, just with some magic headers embedded in it.

For RP2350 ELF output, the pico SDK generates a normal ELF file directly, with one info block tucked between the isr table and the start of program image, and another in a second ELF section, at the end of the program image. The first one needs to include an offset to the second one (which needs to be calculated after the program image size is determined), but the second one points back to the memory address of the first one, which should be fixed. If this is done as a post-processing step, it does require rewriting the ELF file in order to make those two changes. Perhaps the builder could insert a dummy section for the second block, and then patch it with elfpatch? At a glance, this seems like it should also allow UF2 files to be generated from the patched ELF.

However, the datasheet also gives an example of a minimum implementation that doesn't need any post processing, just a simple header that needs to be placed in the first 4k of the image. I've chosen this approach to get a basic output working. The disadvantage of this is that it won't support any of the fancier validation options that the rp2350 boot rom offers, such as image signing or partition support.

@aykevl
Copy link
Member

aykevl commented Nov 18, 2024

However, the datasheet also gives an example of a minimum implementation that doesn't need any post processing, just a simple header that needs to be placed in the first 4k of the image.

That looks like a much simpler way to do it!
This doesn't require any patching or rewriting of the ELF file, right? Just a way to tell the linker to put that magic block at the right position (presumably after the interrupt table).

The first one needs to include an offset to the second one (which needs to be calculated after the program image size is determined),

This can probably also be done by the linker, with some special assembler magic.

@cibomahto
Copy link

cibomahto commented Nov 18, 2024

However, the datasheet also gives an example of a minimum implementation that doesn't need any post processing, just a simple header that needs to be placed in the first 4k of the image.

That looks like a much simpler way to do it! This doesn't require any patching or rewriting of the ELF file, right? Just a way to tell the linker to put that magic block at the right position (presumably after the interrupt table).

Correct. These 'blocks' each contain a pointer to the next block, in the form of an offset. The rp2350 bootrom uses the offsets to walk through the block chain, and to verify that they form a closed loop back to the first block. The trick is that if you only have one block, you can point it back to itself by specifying a zero offset, so no calculation needs to be done.

For the proof of concept, I gave it an explicit position by modifying the arm linker file: Blinkinlabs@fbb5234#diff-2048f2f7e5dcd7f7efd321f90018d841b002168ec4aa103d33363f4f4f316171R12 .

This is very straightforward, but seems a little invasive to add that for all ARM targets. Another straightforward option is to include a modified version of arm.ld just for the rp2350, but I don't see any other examples that do that and it's probably more difficult to maintain. Maybe there's an assembler directive to put something at the beginning of .text?

@aykevl
Copy link
Member

aykevl commented Nov 18, 2024

For the proof of concept, I gave it an explicit position by modifying the arm linker file: Blinkinlabs@fbb5234#diff-2048f2f7e5dcd7f7efd321f90018d841b002168ec4aa103d33363f4f4f316171R12 .

Actually in my opinion it's fine, if the name is slightly different. Something more generic/descriptive. What about KEEP(*(.after_isr_vector))? Maybe with a short note like /* for the RP2350 */.

@soypat
Copy link
Contributor Author

soypat commented Nov 21, 2024

What do you mean by this? It's generally not possible to move stuff in the firmware file after linking.

Not without great effort, which I was motivated to do at one point but no longer- Seeing @cibomahto PR that works looks like a good starting point. Let me know what I can do to get this merged ASAP.

@cibomahto
Copy link

cibomahto commented Nov 22, 2024

I sent a pull request for the changes that I knew how to add properly. I know of at least these issues that are remaining:

@cibomahto
Copy link

cibomahto commented Dec 2, 2024

In my 'experimental' branch, I've succeeded in getting the resets, clocks, timer, UART, and USB running, for at least enough functionality to use time.Sleep(), set a correct UART baud rate, and enable the USB CDC function for a virtual serial terminal.

For testing, I commented out the code that changed between the RP2040 and RP2350, but it needs to be integrated more cleanly.

For instance, in machine_rp2_clocks, the init code is mostly the same, but the registers are laid out differently:
src/machine/machine_rp2_clocks.go

Does anyone have a suggestion or reference for how these should be set up correctly? I think these peripherals are still close enough that it makes sense to have a common '_clocks' file for them.

Reset is here:
Blinkinlabs@96bb225
Blinkinlabs@0ddbe7d

System clocks (and tick source) are here:
Blinkinlabs@96df708
Blinkinlabs@f2327dc

and USB is here (the only difference from rp2040 are the CMSIS register names, and one pad disconnect):
Blinkinlabs@361bd1e

@deadprogram
Copy link
Member

The CI builds show an error failed to calculate ELF ROM addresses: no ELF ROM sections found...

@cibomahto
Copy link

The CI builds show an error failed to calculate ELF ROM addresses: no ELF ROM sections found...

It looks like this started failing at f56a0c7 . @soypat Do you know if those changes are necessary if we don't need to patch the ELF file?

Note: I bisected the history using this pattern:

git checkout f56a0c74
git submodule update
go install
make gen-device
make llvm-source
tinygo build -size short -o test.hex -target=pca10040            examples/blinky1

@soypat
Copy link
Contributor Author

soypat commented Dec 7, 2024

@cibomahto The use of tinyboot is no longer needed. Reverting use of tinyboot- didn't think we'd solve this one so quickly :)

@deadprogram
Copy link
Member

All unit tests now pass, including the TinyHCI hardware test on a RP2040 Pico.

Is this PR ready to be squashed and merged? @soypat @cibomahto @aykevl ?

switch patch {
case "rp2040":
err = patchRP2040BootCRC(executable)
// case "rp2350":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be commented out here?

@cibomahto
Copy link

@deadprogram These changes still need to be merged in a way that's compatible with rp2040: #4459 (comment) . I made a first pass at it last night, will try to get it submitted tomorrow.

@deadprogram
Copy link
Member

Sounds good @cibomahto please let me know anything I can do to help out!

@cibomahto
Copy link

@deadprogram Here is the pull request: #4655

I ran into an issue using a USB console and fmt that I'm not sure how to debug. Given a basic program that is compiled with -serial=usb:

package main

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

var (
    usbcdc = machine.USBCDC
)

func main() {
    led := machine.LED
    led.Configure(machine.PinConfig{Mode: machine.PinOutput})

    count := 0
    for {
        led.Low()
        fmt.Println("Hello world!", count)
//        usbcdc.WriteByte('a')

        time.Sleep(500*time.Millisecond)

        led.High()
        fmt.Println("xxx")
//        usbcdc.WriteByte('b')
        time.Sleep(500*time.Millisecond)

        count++
    }
}

If I use fmt(), it panics at the start of go/src/fmt/print.go:303 . The underlying USB seems to work because if I call usbcdc directly, then I can transfer data to and from a PC.

I think this should probably be debugged before merging.

@deadprogram
Copy link
Member

If I use fmt(), it panics at the start of go/src/fmt/print.go:303 . The underlying USB seems to work because if I call usbcdc directly, then I can transfer data to and from a PC.

Seems odd, I will take a peek.

@deadprogram
Copy link
Member

that I'm not sure how to debug

@cibomahto do we have GDB support for rp2350 yet? seems like backtrace might show something.

I can confirm the crash behavior you describe, and that usbcdc.WriteByte() and usbcdc.Write() both work.

Interestingly, when the modified version is running, I did notice something else: when trying to reflash, the pico2 seems to stop running (LED stops blinking) but never actually seems to start running the bootloader to receive the new code as no MSD device appears until a hard restart of the board.

@cibomahto
Copy link

cibomahto commented Dec 13, 2024

that I'm not sure how to debug

@cibomahto do we have GDB support for rp2350 yet? seems like backtrace might show something.

@deadprogram I'm using openocd/gdb directly (with a pico debug probe): https://github.com/Blinkinlabs/rp2350_tinygo_dev/blob/main/docker/Makefile

I wasn't able to figure out any more from the backtrace, except to confirm that it happened from the very first call to fmt(). My initial suspicion was that the buffer pool that the print library uses was not being initialized.

I can confirm the crash behavior you describe, and that usbcdc.WriteByte() and usbcdc.Write() both work.

Interestingly, when the modified version is running, I did notice something else: when trying to reflash, the pico2 seems to stop running (LED stops blinking) but never actually seems to start running the bootloader to receive the new code as no MSD device appears until a hard restart of the board.

That's probably because of this:
https://github.com/Blinkinlabs/tinygo/blob/adecf5383066d8af59fc35d3b6ea9b53a874d122/src/machine/machine_rp2_2350.go#L208

I've been using a pico debug probe to do this development, loading the code using openocd instead of the bootloader. It shouldn't be too tough to implement this, I can take a stab at it.

@deadprogram
Copy link
Member

That's probably because of this:
https://github.com/Blinkinlabs/tinygo/blob/adecf5383066d8af59fc35d3b6ea9b53a874d122/src/machine/machine_rp2_2350.go#L208

That would certainly explain it! 😸

@deadprogram
Copy link
Member

OK I found the USB on rp2350 problem, see https://github.com/tinygo-org/tinygo/pull/4655/files#r1884304340

@deadprogram
Copy link
Member

Rebased against latest dev branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants