Go Down

Topic: array to progmem (Read 1 time) previous topic - next topic

tecmac

Hello All,

I'm working on a project that gets a data stream (sequence of bytes which I want to place in an array) and then does something with it. I would like to receive the stream and save it to the program memory because I would like to store 4096bytes and flash is not enough on my 328P.

The following section of my program is quite simple and works saving the elements to an array in flash memory:
Code: [Select]

...
unsigned char HelloMP3[1024] = { };
...
//******************SAVING ARRAY TO FLASH:
//DATA IS COMING IN FROM THE NETWORK
while (client2.connected()){           
            p = &HelloMP3[0];
            while (p <= &HelloMP3[sizeof(HelloMP3)-1]) {
              *p = client2.read();
              p++;
            }
}
//******************READING ARRAY
p = &HelloMP3[0]; // Point "p" to the beginning of array
while (p <= &HelloMP3[sizeof(HelloMP3)-1]) {
            variable = p*;
            p++;
}


now I would like to implement the exact same code but saving each element in progmem as they are made available or alternatively I can store the data on a 1024 array (I have this amount available in flash) and then transfer it to progmem and repeat this until I get to 4096bytes.

I hope I was clear enough! Any good ideas?

TIA,
Rui
--

AWOL

To write to PROGMEM, you'd have to rewrite the bootloader.
I don't think you're ready for that.
Have you thought about using SD for storage?
"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.

tecmac

thanks!

yeah, I actually did think about the SDcard storage, here's something I did sometime ago regarding that: http://supertechman.blogspot.com/2011/01/convert-old-ethernet-shield-to-sdcard.html

I was just thinking about other possibilities before I added more HW to the project. I think I'll go the SDcard way.

Cheers,
Rui
--

skyjumper

There is a PROGMEM library to make using PROGMEN for program varibales easy. Why would he have to rewrite the boot loader?

AWOL

@skyjumper:

I took this:
Quote
I would like to receive the stream and save it to the program memory

to mean "at run-time".
There are no write methods in the PROGMEM library.
"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.

skyjumper

Interesting...

I was looking at this:

http://www.arduino.cc/en/Reference/PROGMEM

It looked like you could set up variables and define them to go into program memory as opposed to ram. Are you saying that if I map an array or some long strings at compile time, I can only read these and not modify them? It seems I should be able to do that.

Graynomad

Quote
I can only read these and not modify them?

Correct, there are special methods (instructions) to write into flash, you can't just do it from your normal program.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

olikraus

Just to make things more clearly:

1.
You have a big constant array (perhaps larger than system RAM) which will never be altered during program execution. Such an array can be put into the flash ROM memory at compile time and accessed during run-time with the PROGMEM feature of the gnu compiler:
http://www.nongnu.org/avr-libc/user-manual/pgmspace.html
Note: Constant arrays are always placed in flash ROM area:
Without PROGMEM: Array is copied to RAM
With PROGMEM: Array is NOT copied to RAM

2.
You want to store a lot of data, but there is not enough RAM or EEPROM. You might consider a run-time self programming of the flash ROM memory:
http://www.atmel.com/dyn/resources/prod_documents/doc2575.pdf
Not sure if anybody has implemented procedures for the Arduino.


Oliver

skyjumper

I'm glad this thread was started, I was under the mistaken impression that the PROGMEM lib could be used to place program varibales into the flash program space, and used like normal varibales. Thanks for clarifying that.

For the OP, you could add a bit of flash to your Arduino pretty easily and cheaply. I did, check this out:

http://arduino.cc/forum/index.php/topic,51017.0.html

I added a big 4 MByte chip, but if you don't need that much you can buy much smaller chips for less money. When you're shopping, remember that chips like this are rated in mega BITS, so divide by 8 to get Mega BYTES. Six wires, (two of which are power and ground) and you're in business.




Go Up