bossac.exe crashes when uploading minimal asm program to Arduino Due

Hello

I am learning low level details of sam3x8e MCU with Arduino Due board. I think it is kind of "stand alone microcontrollers related to sam3x8e" question so I decided to post it in this discussion. But please advise better place to ask if you think that question is inappropriate here.

I wrote a very simple asm program (probably minimal possible for cortex-m3 architecture)

.syntax unified
.thumb
.cpu cortex-m3
.section .vectors                     /* Put everything in a section called "vectors" from now on... */
  .align 2                            /* Make sure the output goes on an address divisible by 4 (that's 1 << 2) */
                                                                    /* Address:   Exception Vector Description: */
  .long  _sstack                      /* 0x00000000 The initial stack pointer (defined by the linker-script) */
  .long  Reset_Handler + 1            /* 0x00000004 The startup-code, I also tried without "+ 1" */ 

.text
Reset_Handler:
  B Reset_Handler       /*Infinite loop*/

  .END

And try to generate binary file with following linker script:

OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)

/* Memory Spaces Definitions */
MEMORY
{
 rom (rx)    : ORIGIN = 0x00080000, LENGTH = 0x00080000 /* Flash, 512K */
 sram0 (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000 /* sram0, 64K */
 sram1 (rwx) : ORIGIN = 0x20080000, LENGTH = 0x00008000 /* sram1, 32K */
 ram (rwx)   : ORIGIN = 0x20070000, LENGTH = 0x00018000 /* sram, 96K */
}

STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : 0x2000 ;

/* Section Definitions */
SECTIONS
{
    .text :
    {
        . = ALIGN(4);
        _sfixed = .;
        KEEP(*(.vectors .vectors.*))
        *(.text .text.*)
    } > rom

    /* stack section */
    .stack (NOLOAD):
    {
        . = ALIGN(8);
        _sstack = .;
        . = . + STACK_SIZE;
        . = ALIGN(8);
        _estack = .;
    } > ram
}

I run following sequence of commands:

arm-none-eabi-as.exe  -mcpu=cortex-m3 ./min.s -o ./min.o
arm-none-eabi-ld.exe  -T ./min.ld ./min.o -o ./min.elf
arm-none-eabi-objcopy.exe -O binary ./min.elf ./min.bin

Everything goes very smooth without any errors or warnings. Resulting bin file has size 12 bytes ant it's content is a kind of what I expect:

0000000000: 00 00 07 20 09 00 08 00 │ FF F7 FE BF

Then I try to flash it to Arduino Due board with bossac.exe

bossac -i -d --port=COM5 -U false -e -w -v -b min.bin -R

And it crashes with message:

-------------Error messagebox---------------
bossac.EXE has stopped working

A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.

If I click "Debug" button on this error box Visual Studio starts and says that exception is "Division by zero".

At the same time bossac.exe flash binaries generated by Arduino IDE perfectly well. I also can flash IDE-generated binaries from command line without any problems.

I am completely stuck at this point. Any ideas, comments or links are very appreciated

Thank you

1 Like

Have you found an answer yet? I'm having the same problem.

Since you have direct access in C/C++ to all registers, there is (usually) no need for ARM assembler. The general rule is to let the compiler do the optimization for you with the appropriate #pragma GCC optimize ("OX").

However, if you think some parts of your code would be more efficiently coded in assembler, the best option is inline assembler, or insert functions coded in pure assembler in a .S file inside a sketch folder, with an extern "C" in the .ino file.

If you want to see the minimal assembler code needed for a Sam3x8e, run Atmel studio, select new project, select Sam3x8e, compile the minimal code with an int main (void) function, then edit the GccApplicationxy.lss file.

1 Like