Go Down

Topic: PROGMEM: real FLASH memory address access (Read 1 time) previous topic - next topic

ionito

I have been using PROGMEM basically to store/read constant values at FLASH instead of RAM.

Now, I'd like to directly access the flash addresses to, at least, read or "dump" the flash memory content.

Using 4 unchar variables called N01_S1, N01_S2, N01_S3, and N01_S4, I defined different values for each one (0x51, 0x52, 0x53, 0x54).

Using a loop from 0 to 255, I printed the content of the Flash for the first 256 positions by using pgm_read_byte_near(i), where i varies from 0 to 255. I figured out that the positions 228-231 have the values 0x51 to 0x54. 

Is this kind of address allocation random or it is precisely defined at Arduino environment? If positive, where?

Thanks

Nick Gammon

Show your code?

The flash memory contents will be whatever is in the .hex file uploaded to the processor, if you want to see what it is.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

AWOL

Quote
. I figured out that the positions 228-231

How did you figure that?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

ionito

I am using a different computer to send this message. I'll try to upload the original code later.

But.. I just figured out (experimentally) that PROGMEM only works at compilation time. When we try to use the statement below anywhere in setup() or loop()

PROGMEM prog_uchar N01_S5[] = { 0x55 };

it does not work and you cannot access the content of N01_S5.

Therefore, PROGMEM seems to me designed to deal with constant values only. I expected to extend its use, but I believe it is not possible.

Any comments?



AWOL

Quote
Therefore, PROGMEM seems to me designed to deal with constant values only.

The only place you can write to PROGMEM is from code running in the boot area, which is why the bootloader works so well.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

ionito

I started 2 related topics today, but after feedbacks and some research, I realized that for one of my projects, the internal flash memory of ATmega1280 (128KB) is enough for me and the number of writes cycles will not be an issue for at least 5 years.

Some details:

* No Arduino bootloader. Actually, I never used it on my projects. I develop using Arduino IDE but only upload the object code without the bootloader. Therefore, I have the full 128KB available for my design (ATmega1280 case).

* No external flash device for this project.

* EEPROM is not an option: I am already fully using it for other purpose.
 
In short, I want to use the internal flash memory of Atmega without using PROGMEM. I do not care to access byte-by-byte instead of page mode, but I need to read and write in running time.

Thank you for any, any idea or suggestion :)

Nick Gammon

Program memory is intended to hold programs, hence its name. It doesn't have an indefinite life for writing.

Why do you need to write to it? Do you not have enough RAM? Some processors (like the 1284) have a lot more RAM (16 Kb). Or you can attach an SD card and write to that.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

johnwasser

Only the Boot Loader Section is allowed to write into the Application Program Section of FLASH at run time.  You will have to put some code in the BLS that you can then call to write data into the APS with the SPM (Store Program Memory) instruction.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

ionito

Thanks johnwasser, it seems to be the direction.

However, I never coded in such level...
Guys, any idea of how to get the steps/examples in this area?

CrossRoads

Or an SPI-accessed Ramtron FRAM, access it at serial SRAM speeds, holds data like an EEPROM, no battery backup needed.
Available at mouser.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

James C4S


Therefore, PROGMEM seems to me designed to deal with constant values only. I expected to extend its use, but I believe it is not possible.

Any comments?

Not "seems to be", but "is".

PROGMEM stands for Program Memory.  It cannot be modified during run-time, unless the code is run out of the boot part of PROGMEM.  This is why the bootloader can write to it, and you cannot.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

johnwasser


any idea of how to get the steps/examples in this area?


Well, the bootloader writes into Application Program Section.  The source code for the bootloaders are included in Arduino 1.0.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

ionito

The problem is that I'm removing the bootloader when I make the final deployment of the solution. I cannot include the bootloader due to other issues.

Any other form of coding without using the bootloader?

johnwasser

You wanted an example of how code in the BLS could write into the APS.  The bootloaders do that.  You can use the source code as an example.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

MarkT

Also you would have to write whole pages at once, as its Flash, not EEPROM, which is inconvient for general storage.
[ I won't respond to messages, use the forum please ]

Go Up