Author Topic: ATSAM3x8e and storing variables in program space equivalent  (Read 1534 times)

0 Members and 1 Guest are viewing this topic.

Offline MyElectronsFellOutTopic starter

  • Regular Contributor
  • *
  • Posts: 70
  • Country: gb
I have use AVR atmels in the past and have utilized the ability to store large arrays in program space using the PROGMEM keyword (learned through arduino).

What I want to know, is what is the equivalent in the ATSAM3x8e?
I have read that simply declaring something as const puts the variable in program space rather than RAM?
« Last Edit: July 06, 2016, 09:50:56 am by MyElectronsFellOut »
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: ATSAM3x8e and storing variables in program space equivalent
« Reply #1 on: July 06, 2016, 10:01:15 am »
I have read that simply declaring something as const puts the variable in program space rather than RAM?
Depends on the toolchain, but generally that's how it works. You can always check your map file to verify.

Offline MyElectronsFellOutTopic starter

  • Regular Contributor
  • *
  • Posts: 70
  • Country: gb
Re: ATSAM3x8e and storing variables in program space equivalent
« Reply #2 on: July 06, 2016, 10:11:55 am »
Im using atmel studio, how do I access the map file?
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: ATSAM3x8e and storing variables in program space equivalent
« Reply #3 on: July 06, 2016, 12:30:49 pm »
The map file is in the output directory of the linker. You may need an additional flag/tickbox to have a map file created.
Another method would be to start the debugger and lookup the value of &array.

Which toolchain are you using?
 

Offline MyElectronsFellOutTopic starter

  • Regular Contributor
  • *
  • Posts: 70
  • Country: gb
Re: ATSAM3x8e and storing variables in program space equivalent
« Reply #4 on: July 06, 2016, 02:30:04 pm »
Im using SAMBA to upload via USB. Don't have a debugger for ARM chips yet.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: ATSAM3x8e and storing variables in program space equivalent
« Reply #5 on: July 06, 2016, 05:18:05 pm »
I have read that simply declaring something as const puts the variable in program space rather than RAM?
Use "static const" and only local access. Otherwise compiler will enforce "const" part for a specific compilation unit, but may not be able to actually put it into read-only section for the whole program.
Alex
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: ATSAM3x8e and storing variables in program space equivalent
« Reply #6 on: July 06, 2016, 05:57:43 pm »
In no scope does static mean data is read only. Const is made for that.
When you tell the ARM compiler data is const, it won't be put in ram by _main*.

On an AVR (arduino), with harvard architecture, there are two distinct memory spaces: instruction and data.
By default, any object will be made and initialized in data. Which is sram. You have to explicetely tell the compiler to put an object in the instruction memory by using progmem.
The compiler needs to know this since other instructions are needed to access instruction memory, compared to normal data memory.
With ARM, and it's single 32 bit byte addressable address space, this is no longer needed.  :phew:

*the function called prior to main().

In C:
Static in global scope limits the scope of the variable to only the C file.
Static in local scope (code block) makes the variable "global", yet keeping the identifier local.

Quote from: ISO/IEC 9899 6.2.2
3) If the declaration of a file scope identifier for an object or a function contains the storageclass
specifier static, the identifier has internal linkage.
eg: toss an error on extern.
Quote from: ISO/IEC 9899 6.2.4
3) An object whose identifier is declared with external or internal linkage, or with the
storage-class specifier static has static storage duration. Its lifetime is the entire
execution of the program and its stored value is initialized only once, prior to program
startup.
eg: only one instance of the variable exists. No matter how many times the function is being recursed/threaded.

You've still not mentioned the toolchain. uVision? Atmel Studio? Bare GNU?
« Last Edit: July 06, 2016, 06:02:13 pm by Jeroen3 »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf