Teensy 3.1: use flash mem

Status
Not open for further replies.

mete

New member
Hi,

I'm pretty new to all that. I'm actually just a programmer. I was wondering, if I could write from my program to the rest of the flash mem in Teensy 3.1? My program uses 12-20kb only and then rest of the 256kb is unused. I would like to store stuff there instead of using a MicroSD card. Is that even possible? When browsing the source code I just found read functions for the flash mem.

Thanks and greetings,
Mete
 
Will the data you have fit into the non-volatile memory area that emulates the EEPROM as in Atmel AVR?
Of course, an SD card is gigabytes in size. The default non-volatile area size is 2048 bytes.
It is possible for your program to write data into fixed size blocks of flash memory, but it is rarely done.
 
Thank you! The data would not fit into 2048 bytes. It will be up to ~230'000 bytes. How would I write data into fixed size blocks of flash memory?
 
I don't think there are Teensyduino library calls to do that. It may be that you can write low level code to call the flash block read/write, but it may also be that the Teensy memory scheme is to lock the flash after downloading.

230KB would be about half of the Teensy 3.1's flash. If I recall, this K20 CPU does flash erase in 1KB blocks. But if the bootloader locks the entire flash, you have a no-go as is.

It would be better/easier to use either an SD card or an added EEPROM chip on the I2C bus.
 
Last edited:
if I could write from my program to the rest of the flash mem in Teensy 3.1? My program uses 12-20kb only and then rest of the 256kb is unused. I would like to store stuff there instead of using a MicroSD card. Is that even possible?

I believe this may be possible, but with some serious caveats. So far, nobody has done it.

First, this is risky. You might overwrite part of your program. Second, it's tricky to do correctly. The code has to run from RAM and interrupts must be disabled until the flash operation completes, since the flash won't be available to execute your program. If done incorrectly, the ARM processor will get a bus fault, and then a hard lockup if it can't fetch the fault handler. I'd highly recommend a 10+ second delay before writing while you develop the code, to give yourself time to hopefully do another upload after power cycling.

The code in eeprom.c is probably the best starting point. There you'll find the chuck of RAM-based code, and the complex C syntax to call it.
 
Thanks for your hints! I looked at the eeprom.c and also mk20dx128.h, but then decided to go with a normal MicroSD card. I was hoping that I missed some already existing API.

Greetings,
Mete
 
Status
Not open for further replies.
Back
Top