Compiling Program to RAM On SAM V71 XPlained Pro Card

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

I am using a SAMV71 Xplained Ultra development card with Atmel Studio 7.0.1417. 

Up to now, I have been working by compiling my project so that the code is in the embedded flash memory. This works fine, however, I realize this memory has a finite number of write cycles.

During iterative debug, I would like to be able to compile my program to the on-chip RAM.

These are the options for that I currently have for the linker:

arm-none-eabi-gcc -mthumb -Wl,-Map="$(OutputFileName).map" -Wl,--start-group -lm  -Wl,--end-group -L"../src/ASF/thirdparty/CMSIS/Lib/GCC"  -Wl,--gc-sections -mcpu=cortex-m7 -Wl,--entry=Reset_Handler -Wl,--cref -mthumb -T../src/ASF/sam/utils/linker_scripts/samv71/samv71q21/gcc/flash.ld -Wl, -u,vfprintf 

I assume that I need to modify the linker script called 'flash.ld'. Do I need to use the "SAM-BA" utility to download my code to RAM? Or can this be done directly from Atmel Studio?

Any tips would be appreciated.

->Adrian

PS: I assume that there is no simulator/emulator for the samv71q21 device. Is this correct?

 

 

 

citizen_adrian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

citizen_adrian wrote:
I realize this memory has a finite number of write cycles.

That finite number is 10,000+ write cycles. If you programed your device 5.49 times a day for the next 5 years you would might start running into issues. I've heard that number is rated higher in some cases. I think you will be fine.

"When all else fails, read the directions"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks very much for the spec about the number of write cycles.

The reason I asked the question, is that I am now frequently seeing this error message when I start to debug. The specific addresses may change a bit. A week ago, I would see it once a day. Now I am seeing it almost every time.

Is this due to the flash wearing out? Or do you thinking it is something else?

Message which appears when downloaading

 

Thanks!

 

citizen_adrian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not worried about wearing out the flash, but I would like to run from RAM for faster turnaround during development. Running from RAM avoids the flash erase delay. ASF includes a corresponding ASF/sam/utils/linker_scripts/samv71/samv71q21/gcc/sram.ld linker command file which puts everything into sram but I haven't figured out the other tool settings necessary to run from ram. (using Atmel-ICE debugger)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To run a program compiled in ram needs to make some code to settle in flash. This code needs to identify if there is a program in sram and jump into sram code if there is one.

 

  uint32_t *pSrc, *pDest;

 if(*((uint32_t *) 0x20400004)==0x20400149){     //Check if there is program loaded in sram by matching start address

  __asm__ volatile(

  "MOV R0, PC \n\t"

  "LDR R1, =0X20400000 \n\t"                            // Same70 sram begin address

  "CMP R0, R1 \n\t"                                             // Compare current PC with sram begin address

  "BGT     label1 \n\t"                                           // IF current PC is greater than 0x20400000 means that program running in sram, no action required, jump out to label1

  "LDR r0, =0x20400000 \n\t"                              // Program is running in flash, loading stack pointer address

  "LDR SP, [R0] \n\t"                                            // Loading stack pointer

  "LDR  R0,=0x20400004 \n\t"                            // Loading sram program start address's address

  "LDR R0, [r0,#0] \n\t"                                       // Loading sram program start address

  "BX  R0 \n\t"                                                     // Go to sram Reset_handler code

  "label1: \n\t"

  :

  :

  :  "r0","r1"

  );

  }else{

   /* No sram program is loaded in sram area, initialize the relocate segment */

  pSrc = &_etext;

  pDest = &_srelocate;

  if (pSrc != pDest) {

   for (; pDest < &_erelocate;) {

    *pDest++ = *pSrc++;

   }

  }

 }

 

The following procedure works with SAM E70 Xplained Evaluation Board and Atmel Studio 7.0.1417. And only apply to atmel cortex M7 with 2M flash memory and 384K sram.

 

  1. Open Atmel Studio Example project “Common IOPORT Service Example1-SAME70-XPLD”

  2. Replace Reset_Handler() content with reset_handler.txt Reset_Handler content.

  3. Replace linker script “flash.ld” content with run_in_flash.txt content.

  4. Go to Tool screen, choose option Erase entire chip and boot from ROM to run the program. (Do not select Override Vector Table Offset Register)

  5. Close this project.

  6. Switch to the project that you want to run in sram.

  7. Replace Reset_Handler content with reset_handler.txt Reset_Handler content.

  8. Replace linker script “flash.ld” content with run_in_sram.txt content

  9. Go to Tool screen, choose option Incremental programming and boot from ROM to run the program. (Do not select Override Vector Table Offset Register)

  10. The program with start from flash and jump into sram program.

 

Note:

  • Step 9 is critical. If you choose Erase entire chip at step 8, the program will end up anywhere, and you might need to erase the chip by jumper on the Xplained board and need to go to menu Tools --- Device Programming to set boot option bit to boot from flash.

  • Step 4 and 9 was supposed to select boot from Flash. There might be some unknown issue in Atmel Studio 7.0.1417.  Old version was ok to select boot from Flash or Unchanged.

Attachment(s): 

Last Edited: Sun. Oct 22, 2017 - 03:01 PM