RFGateway M4 setup under PlatformIO [with solution]

Started by wohali, July 27, 2023, 10:50:22 PM

wohali

Hi Felix,

I've been trying to get the RFGateway M4 board set up under PlatformIO. So far, I can get the code to compile, but upload is failing.

Here's my board.json file so far, based on the Moteino M0 file:

    https://gist.github.com/wohali/5b12f17cc389a7a4dc793898371f3381

And here's what I'm seeing when I try to upload a project that successfully compiles:

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   2.5% (used 4888 bytes from 196608 bytes)
Flash: [=         ]   8.0% (used 40556 bytes from 507904 bytes)
Building .pio/build/rfgateway/firmware.bin
Configuring upload protocol...
AVAILABLE: atmel-ice, blackmagic, cmsis-dap, jlink, sam-ba
CURRENT: upload_protocol = sam-ba
Looking for upload port...
Using manually specified: /dev/ttyACM0
Forcing reset using 1200bps open/close on port /dev/ttyACM0
Waiting for the new upload port...
Uploading .pio/build/rfgateway/firmware.bin
No device found on ttyACM0
*** [upload] Error 1


What I see in dmesg is that the device disconnects, then reconnects, presenting a drive (/dev/sda). I'm unable to mount that drive. Presumably this is a UF2 bootloader (also visible after a double-press of the reboot button), but bossac refuses to talk to it:

$ ./packages/tool-bossac/bossac --info --debug --port "ttyACM0" --write --verify --reset --erase -U true ~/Wakko/Projects/WeatherStation/BaseStation/.pio/build/rfgateway/firmware.bin
Set binary mode
readWord(addr=0)=0x2000d380
readWord(addr=0xe000ed00)=0x410fc241
Send auto-baud
Set binary mode
No device found on ttyACM0


What do I need to do?

wohali

Update: I found that by manually installing the latest bossa-cli (v1.9.1) and running the following from a shell, I was able to upload my code.

$ bossac -p /dev/ttyACM0 -e -w -v -R --offset=0x4000 ~/Wakko/Projects/WeatherStation/BaseStation/.pio/build/rfgateway/firmware.bin 
Erase flash

Done in 2.320 seconds
Write 27456 bytes to flash (54 pages)
[==============================] 100% (54/54 pages)
Done in 0.389 seconds
Verify 27456 bytes of flash
[==============================] 100% (54/54 pages)
Verify successful
Done in 0.440 seconds


I was also able to convince PlatformIO to do the right thing, with the following values in platformioini:

[env:rfgateway]
platform = atmelsam
board = rfgateway
framework = arduino
lib_deps = 
	mikem/RadioHead@^1.120
	ricaun/ArduinoUniqueID@^1.3.0
	lowpowerlab/SPIFlash@^101.1.3
platform_packages =
	platformio/tool-bossac@^1.10901.0
upload_protocol = custom
upload_flags =
	--info
	--debug
	--write
	--verify
	--reset
	--erase
	--usb-port=1
	--offset=0x4000
upload_command = bossac $UPLOAD_FLAGS $SOURCE


Your lib_deps will likely differ.

Felix