Go Down

Topic: Uploading Bin file (Read 4340 times) previous topic - next topic

DArduino86

Hi! I have to upload an exported bin file ( sketch from Arduino IDE ) and upload it to SAMD21 board with Atmel Ice through SWD connector.
How can I do it ?
Thank you!

AloyseTech

See here. Second section ("Feather M0 and others") shows you how to upload a compiled program on the chip using Atmel Studio and the Atmel ICE.

MartinL

Hi AloyseTech,

Thanks again, that's really useful.

MartinL

DArduino86

Hy AloyseTech!

Thank you!


d3str0y3rport

taken from Sulimarco. I tested and it works:



"if you are not worried to make a little modification to a ZERO board, I think you can try the following method to use a ZERO as an SWD programmer.


I didn't try it but I think it could work.


1- Remove the two resistors shown in the "Arduino_ZERO_pcb" and "ARDUINO_ZERO_schematics" attachments.

2- Make your board. A minimalist implementation is shown in the "SAMD21G18_minimalist_implementation" attachment.

3- Connect signals SWDIO, SWCLK, RESET plus GND and 3.3V between the ZERO and your board.

For  RESET  GND and 3.3V I recommend to use the normal Arduino's connector.
For SWDIO and SWCLK you can use the pads of the SWD connector or the left side pads of the removed resistors.

Keep the wires as short as possible.


4- Double check your connection.

5- Connect your PC to the ZERO's  "programming " usb connector (the one near the black power supply connector".

6- Open the Arduino IDE on your pc and select the ZERO board and the ZERO's programming port as a programmer.

7- Burn the ZERO's bootloader.

8- If everything go ok you can now write a sketch and download it to your board."

DArduino86

Hi all!

I've been able to upload a sketch from the Arduino IDE to SAMD21G18 via Atmel Ice and through SWD connector. It works but only from the sketch.
If I try to upload the exported bin file via Atmel Studio the file doesn't start.
Maybe because without the bootloader the sketch starts from a different address? how can I link it to the correct address?

Thank you!

AloyseTech

If you want to upload and execute a bin file without the bootloader, you have to compile using the correct linker script.

In fact, with the bootloader, your code is located at address 0x2000, and the bootloader take care of everything at launch.

But without bootloader, you have to upload the sketch at address 0x0000, because at start up this is the where the first instructions are expected to be. 
See this line in the linker script (with/without bootloader):

 FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00040000-0x2000 /* First 8KB used by bootloader */
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000

DArduino86

Hi AloyseTech!

Thank you, it works!


LucaTudor

Hello, I hate to bump such an old thread, but I don't want to start a new one with the same topic.
Forgive me for being such a noob but how do you select which linker script arduino ide uses?

I looked over the boards.txt file for the samd packages.
And this entry seems to describe the m0:


Code: [Select]

######################################################
#ARDUINO M0 (WITH) BOOTLOADER
mzero_bl.name=Arduino M0
mzero_bl.vid.0=0x2a03
mzero_bl.pid.0=0x004d
mzero_bl.vid.1=0x2a03
mzero_bl.pid.1=0x804d
mzero_bl.vid.2=0x2a03
mzero_bl.pid.2=0x004e
mzero_bl.vid.3=0x2a03
mzero_bl.pid.3=0x804e
mzero_bl.upload.tool=avrdude
mzero_bl.upload.protocol=stk500v2
mzero_bl.upload.maximum_size=262144
mzero_bl.upload.use_1200bps_touch=true
mzero_bl.upload.wait_for_upload_port=true
mzero_bl.upload.native_usb=true
mzero_bl.upload.speed=57600
mzero_bl.build.mcu=cortex-m0plus
mzero_bl.build.f_cpu=48000000L
mzero_bl.build.usb_product="Arduino M0"
mzero_bl.build.board=SAM_ZERO
mzero_bl.build.core=arduino
mzero_bl.build.extra_flags=-D__SAMD21G18A__ -mthumb {build.usb_flags}
mzero_bl.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
mzero_bl.build.variant=arduino_mzero
mzero_bl.build.variant_system_lib=
mzero_bl.build.vid=0x2a03
mzero_bl.build.pid=0x804e
mzero_bl.build.preferred_out_format=hex
mzero_bl.bootloader.size=0x4000
mzero_bl.build.emu.mcu=atmega2560
mzero_bl.bootloader.tool=avrdude
mzero_bl.bootloader.low_fuses=0xff


Do i modify
Code: [Select]
mzero_bl.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld, to point to
the linker script without bootloader. And what about the other entries.

MartinL

Hi LucaTudor,

Quote
Do i modify
Code: [Select]

mzero_bl.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld

, to point to
the linker script without bootloader. And what about the other entries.
Yes that's right, you just need to change the linker script file in the "boards.txt" file.

The only difference between the "flash_with_bootloader.ld" and "flash_without_bootloader.ld" linker scripts, are that the flash with bootloader script reserves the first 8K of flash memory and starts at address 0x2000 (8192 bytes or 8KB in decimal), whereas flash without bootloader starts at 0x0000.

The command lines used by the Arduino IDE for the compiler and linker can be found in the "platform.txt" file.

Go Up