Author Topic: Clear SRAM on AT91SAM3X8E (Arduino Due)  (Read 2750 times)

0 Members and 1 Guest are viewing this topic.

Offline tomshirvoTopic starter

  • Regular Contributor
  • *
  • Posts: 53
Clear SRAM on AT91SAM3X8E (Arduino Due)
« on: January 15, 2015, 06:37:41 am »
I have finished making my bootloader but I am not sure if when it starts the uploaded firmware that the SRAM is cleared of all the global variables used in the bootloader.

I pass the location on the flash that the firmware was uploaded too. everything works but I am just wondering if things like the serial buffer that is a global variable is still allocated in the SRAM. All the variables from the bootloader can be wiped when the loaded firmware is started.

Below is the code that is run that starts the uploaded firmware.

Thanks

Code: [Select]
/**
 * Jump to CM3 vector table
 */
void _binExec (void * l_code_addr)
{
    __asm__ ("mov   r1, r0        \n"
             "ldr   r0, [r1, #4]  \n"
             "ldr   sp, [r1]      \n"
             "blx   r0"
             );
}








/**
 * Name:      binary_exec
 * Purpose:   Execute the binary
 * Input:
 *  - Application starting address
 * Output:    If success, no return.
 *            1, address alignment error.
 *            2, address not executable.
 */
int binary_exec(void * vStart)
{
    int i;
    // -- Check parameters
    // Should be at least 32 words aligned
    if ((uint32_t)vStart & 0x7F)
        return 1;
    // Should in code or sram region
    if ((uint32_t)vStart > CM3_SRAM_END)
        return 2;
    // -- Disable interrupts
    // Disable IRQ
    __disable_irq();
    // Disable IRQs
    for (i = 0; i < 8; i ++) NVIC->ICER[i] = 0xFFFFFFFF;
    // Clear pending IRQs
    for (i = 0; i < 8; i ++) NVIC->ICPR[i] = 0xFFFFFFFF;
    // -- Modify vector table location
    // Barriars
    __DSB();
    __ISB();
    // Change the vector table
    SCB->VTOR = ((uint32_t)vStart & SCB_VTOR_TBLOFF_Msk);
    // Barriars
    __DSB();
    __ISB();
    // -- Enable interrupts
    __enable_irq();
    // -- Load Stack & PC
    _binExec(vStart);
    return 0;
}
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: Clear SRAM on AT91SAM3X8E (Arduino Due)
« Reply #1 on: January 16, 2015, 08:59:15 am »
Normally the C startup code for a chip will reinitialize memory structures in complete ignorance that anything else might have data there.  This includes only the memory space actually used by the new program (data and bss), not heap memory.  (however, if malloc() is used ITS data structures will be initialized, and malloc()ed memory is cleared.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf