I have an application that will use much more than 32Kbytes available in ATMega328. Since the application can be divided into few independent modules I am thinking about use an external W25Q32 4Mbytes flash SPI module, like this one: W25Q32 W25Q64 W25Q128 large capacity FLASH storage module SPI interface BV FV STM32 code|Integrated Circuits| - AliExpress to keep everything and load & execute modules according to user's demand. Does anybody did something like that ? Is there somewhere to find tips about how to implement an sketch to load and execute parts of software stored in external SPI memory ? Thanks a lot
Just buy a chip that has more flash, e.g. atmega2560
256Kbytes is also not enough... and I have some budget limitations too !!! Let´s thinking togheter: If you have a bootloader that read, store and execute a hex sketch, why would be impossible to do almost the same ?
Get a Teensy Board. It will have way more resource than an AVR and blow the doors off one performance-wise.
Read and store, YES, execute, NO - the bootload only alows the code to be uploaded, the AVR runs the code. If 256K is not enough, get a microcontroller witha lot more memory, or get a raspberry pi!
Its fairly common to want to expand the memory capability of an Arduino to allow for larger sketches.
If it were possible to simply add an extra FLASH memory, you might expect there to be plenty of tutorials arround showing how it were done.
Similarly you would expect to be able to buy a UNO+ with extra FLASH memory.
How about an ESP8266.. It has 4 Mega.
I know there are many other possibilities besides avr but my project including an enormous scketch is ready !!! I really need to try a SPI flash module solution before change everything... But thanks anyway for suggestion
Good luck! It's not possible, but if you want to waste your time, feel free to do so.
Actually bootloader read, store and jump to address where sketch begins. So what I need is something like that. Maybe creating a special kind of bootloader that reads specific portions of code from external flash, store it in internal avr memory and jumper to its begin... Seams to be easy but I do not have any idea about how to implement this...
Use a second MCU to read from the flash and program the Atmega328.
Check this for example - GitHub - MrBlinky/Arduboy-FX-mod-chip: Self updating bootloader for Arduboy FX
Where there's a will there's a way
Have you considered it may not be possible ?
Wow... great idea in GitHub - MrBlinky/Arduboy-FX-mod-chip: Self updating bootloader for Arduboy FX It is a very good start. The challenge will be eliminate that attyny45 and keep the special bootloader inside atmega328... Thanks for help, rainyshadow
I think is too early to declare a defeat...
Maybe seek the assitance of Dr Who to go back in time and redesign the Arduino.
The magic is not in the bootloader, but in using a second chip. The Atmega328 can't reprogram itself.
You can replace the Attiny with another Atmega328 or anything else capable of reading the flash and reprogramming the first Atmega328.
Also, If your modules use common variables to "talk" to each-other, you will need a way to preserve these values.
I don't know what your level of hardware knowledge is and if the dataflow below can help you.
In this basic 8-bit AVR family dataflow below you can see how the program is "handled".
See that the program is in the Flash Program Memory, which is addressed by the Program Counter.
How are you going to stop the program from running, load new values
in Flash and reset the program counter?
What you are trying to do with Atmega is the equivalent of a virtual memory, paging flash memory.
Is there a "sketch" or virtual memorial library for Arduino?
PS: Look if this help: GitHub - Virmak/ArduinoVM: Arduino Virtual Machine
Dear ruilviana, supose I have a small program in a protected memory location somewhere inside 32Kbytes of internal avr flash memory. This program would receive through serial port one byte, i.e, number 0 to 9 corresponding to one of 10 different sketchs (already compiled and stored in machine language, of course) in the external SPI flash memory. Then the resident small program should read the requested module, move it to internal avr flash memory and jump to its begin. At end of execution, the user sketch (or module) would send the control back to small resident program who will stay waiting for a number of the next desired sketch from external flash to be executed...
Am I dreaming or it is possible ?
I do know if I was clear enough. As you know my native language is portuguese, not english...
I think you've already been told the answer .... NO.
Give it up and move on to more capable hardware.