platformio / platform-atmelsam

Atmel SAM: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelsam
Apache License 2.0
84 stars 111 forks source link

Programming ATSAME51J19A #209

Open lillikelley opened 1 year ago

lillikelley commented 1 year ago

Hello all,

I am trying to use the Black Magic Probe to load firmware (.hex w/ bootloader) onto an ATSAME51J19A using a SWD header on a separate PCB. I have updated my BMP firmware as well as the PIO core (I am using the VSCode extension). I have my board set to the Adafruit feather w/ can since they have the same MCU, even though they're not the same board, but let me know if that's the root of my problems here. I have edited my C:\Users\.platformio\platforms\atmelsam\boards\adafruit_feather_m4_can.json file and added "blackmagic" into the protocols array to no avail.

Here is my platformio.ini file:

[env:adafruit_feather_m4_can] platform = GitHub - platformio/platform-atmelsam: Atmel SAM: development platform for PlatformIO 1 board = adafruit_feather_m4_can framework = arduino debug_tool = blackmagic debug_port = COM4 upload_port = COM4 upload_protocol = blackmagic

valeros commented 1 year ago

Hi @lillikelley, what's the error message exactly? Anyway, the adafruit_feather_m4_can board seems to have a bootloader, so it cannot be used with a generic ATSAME51J19A board.

lillikelley commented 1 year ago

Hi, thank you for answering! Would it be easy to make a custom .json for the SAME51 chip using some of the information from the feather w/ can board? Here is my original error message:

Verbose mode can be enabled via -v, --verbose option DebugInvalidOptionsError: Unknown debug tool blackmagic. Please use one of atmel-ice, jlink or custom: File "C:\Users\lkelley.platformio\penv\Lib\site-packages\platformio\builder\main.py", line 174: env.SConscript("$BUILD_SCRIPT") File "C:\Users\lkelley.platformio\packages\tool-scons\scons-local-4.5.2\SCons\Script\SConscript.py", line 598: return _SConscript(self.fs, *files, subst_kw) File "C:\Users\lkelley.platformio\packages\tool-scons\scons-local-4.5.2\SCons\Script\SConscript.py", line 285: exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals) File "C:\Users\lkelley.platformio\platforms\atmelsam@src-3902fa010271b7fd4b3fe129967364bc\builder\main.py", line 127: target_elf = env.BuildProgram() File "C:\Users\lkelley.platformio\packages\tool-scons\scons-local-4.5.2\SCons\Util\envs.py", line 242: return self.method(*nargs, *kwargs) File "C:\Users\lkelley.platformio\penv\Lib\site-packages\platformio\builder\tools\piobuild.py", line 60: env.ProcessProgramDeps() File "C:\Users\lkelley.platformio\packages\tool-scons\scons-local-4.5.2\SCons\Util\envs.py", line 242: return self.method(nargs, kwargs) File "C:\Users\lkelley.platformio\penv\Lib\site-packages\platformio\builder\tools\piobuild.py", line 110: env.PrintConfiguration() File "C:\Users\lkelley.platformio\packages\tool-scons\scons-local-4.5.2\SCons\Util\envs.py", line 242: return self.method(*nargs, **kwargs) File "C:\Users\lkelley.platformio\penv\Lib\site-packages\platformio\builder\tools\pioplatform.py", line 233: _get_debug_data(), File "C:\Users\lkelley.platformio\penv\Lib\site-packages\platformio\builder\tools\pioplatform.py", line 197: % board_config.get_debug_tool_name(env.GetProjectOption("debug_tool")), File "C:\Users\lkelley.platformio\penv\Lib\site-packages\platformio\platform\board.py", line 127: raise DebugInvalidOptionsError( ========================== [FAILED] Took 1.01 seconds ==========================

valeros commented 1 year ago

Here is my original error message:

You probably have two installations of the same platform here C:\Users<user>.platformio\platforms\platforms\atmelsam@src-3902fa010271b7fd4b3fe129967364bc and here C:\Users<user>.platformio\platforms\atmelsam. So when you're editing adafruit_feather_m4_can.json it has not effect on your project. Delete all folders C:\Users<user>.platformio\platforms\atmelsam* and reinstall the platform from scratch.

Would it be easy to make a custom .json for the SAME51 chip using some of the information from the feather w/ can board?

I guess you can use the adafruit_feather_m4_can.json manifest as a blueprint, but you will need to adjust the ldscript field to flash_without_bootloader.ld and also remove the "offset_address": "0x4000" line. Keep in mind that pinout for your board may be different.

lillikelley commented 1 year ago

Alright, so this is as far as I got after making those changes. The project built successfully, and I have the .hex file to be programmed in .pio/build/adafruit_feather_m4_can/. The flash and ram origin and lengths specified in .platformio\packages\framework-arduino-samd-adafruit\variants\feather_m4_can\linker_scripts\gcc\flash_without_bootloader.ld already match those specified in the datasheet for the SAME51J19A board, so I'm not sure how to proceed with my next move. This is my new error message:

Processing adafruit_feather_m4_can (platform: https://github.com/platformio/platform-atmelsam; board: adafruit_feather_m4_can; framework: arduino) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via -v, --verbose option CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/adafruit_feather_m4_can.html PLATFORM: Atmel SAM (8.1.0+sha.61f7971) > Adafruit Feather M4 CAN HARDWARE: SAME51J19A 120MHz, 192KB RAM, 496KB Flash DEBUG: Current (blackmagic) External (atmel-ice, blackmagic, jlink) PACKAGES:

[Inferior 1 (Remote target) killed] ================================================================================================ [SUCCESS] Took 3.39 seconds ================================================================================================

pauljeffress commented 1 year ago

Hi @lillikelley While I don’t know much about this sort of thing, I just happened to notice this line in your output

1 Microchip SAME51N20A (rev D) M4

Is that an indicator of the issue? It’s not the ATSAME51J19A part?

lillikelley commented 1 year ago

Hi @valeros, I ran the "Project Inspect" feature and found that there is an invalid board option 'upload.offset_address'. My firmware includes the bootloader, so I modified flash_with_bootloader's bootloader size to match mine. Here is my error output after inspecting memory and checking code on my debug environment:

PIO Core Call Error: "Processing feather_can_debug (platform: https://github.com/platformio/platform-atmelsam; board: adafruit_feather_m4_can; framework: arduino)

Verbose mode can be enabled via -v, --verbose option CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/adafruit_feather_m4_can.html PLATFORM: Atmel SAM (8.1.0+sha.61f7971) > Adafruit Feather M4 CAN HARDWARE: SAME51J19A 120MHz, 192KB RAM, 496KB Flash DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink) PACKAGES:

KeyError: "Invalid board option 'upload.offset_address'": File "C:\Users\lkelley.platformio\penv\Lib\site-packages\platformio\builder\main.py", line 175: env.SConscript("$BUILD_SCRIPT") File "C:\Users\lkelley.platformio\packages\tool-scons\scons-local-4.5.2\SCons\Script\SConscript.py", line 598: return _SConscript(self.fs, *files, **subst_kw) File "C:\Users\lkelley.platformio\packages\tool-scons\scons-local-4.5.2\SCons\Script\SConscript.py", line 285: exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals) File "C:\Users\lkelley.platformio\platforms\atmelsam\builder\main.py", line 224: "-U", "--offset", board.get("upload.offset_address")]) File "C:\Users\lkelley.platformio\penv\Lib\site-packages\platformio\platform\board.py", line 47: raise KeyError("Invalid board option '%s'" % path) ========================== [FAILED] Took 0.95 seconds ========================== Environment Status Duration


feather_can_debug FAILED 00:00:00.953 ==================== 1 failed, 0 succeeded in 00:00:00.953 ===================="

valeros commented 1 year ago

Here is my error output after inspecting memory and checking code on my debug environment:

You're probably using an incorrect option name, it should be board_upload.offset_address not upload.offset_address.