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?
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.
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.
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.
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.
ionito:
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.
ionito:
The problem is that I'm removing the bootloader when I make the final deployment of the solution.
John's suggestion isn't to use the Arduino bootloader. Instead it is to look at how it writes to PROGMEM. You'll need to write your own bootloader in this case.
ionito:
Any other form of coding without using the bootloader?
To write to PROGMEM? No. Only the bootloader sector can write to PROGMEM.