Go Down

Topic: Run functions from an SD card? (without bootloader) (Read 380 times) previous topic - next topic

Aksolotl

Heya!
Recently I have been developing the idea of run functions from an sd card, the point or the final result is that the arduino only have a "pasive" code that is able to run external functions, I mean, it could give practically unlimited posibilities if it works.

I've been searching information and I only see stuff about "bootloaders" and constantly restart the arduino to load brand new codes, the problem I see is that the arduino will be broken very fast, if you put it in an automatic system working 24/7 in a few months the arduino will be maybe burned.

My question is the next; is it posible to run functions from an sd card without the need of constantly reset and boot the arduino?, I don't want to upload a whole sketch, I want to have some functions inside the sd, when i need to run an specific function the arduino would read it from the sd so you can change and add in an easy way new functions (of course if the card is empty or something the arduino will send an error message), because the code of the automatic system I want to do will be big enough to fill in completly the arduino memory (even creating separate functions).

It would be awesome if someone can help me, I will understand if there is no method to do it exactly as I want, some library or some specific sd command or whatever, because I'm not really interested to try with a bootloader, if someone help me I will be very glad and maybe I will publish the work for free use, I honestly say that this could change things of this world for better.

I wish you a nice day and any help is welcome!

Smajdalf

AFAIK there is no simple way. You may write your own interpreter of commands stored in the SD card but it would be complicated. It is much better to get some better MCU able to execute code from RAM.
ATMega used in Arduino Uno is powerful in its simplicity. One aspect of the simplicity is limited ability to update the code. It is better to get a MCU intended to run a code generated on the fly.
Banned forever by Coding Badly for "trolling". Good luck with such attitude.
Update: Timeout "Extended, yet again, for lying." From eternity to Apr 19, 2019. Interesting...

Juraj

it is possible. I know how to do it.
but why not only put all the functions into the sketch
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

Lucario448

it is possible. I know how to do it.
In an AVR? How?

Apart from implementing an interpreter or programming the flash memory on the fly, is not possible to execute code outside of the MCU, not even from it's internal RAM.
AVR's architecture seems to always "hard-wire" the instruction fetching only to flash memory; even the Program Counter only address this type memory.

Juraj

In an AVR? How?

Apart from implementing an interpreter or programming the flash memory on the fly, is not possible to execute code outside of the MCU, not even from it's internal RAM.
AVR's architecture seems to always "hard-wire" the instruction fetching only to flash memory; even the Program Counter only address this type memory.
Optiboot 8 has do_sdm service function. I use it here to store new version of the application in upper half of the flash memory (and later to copy it to flash beginning to run it after reset).

the call to do_spm self is an example of call to independent 'module' in flash
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

Smajdalf

Optiboot 8 has do_sdm service function. I use it here to store new version of the application in upper half of the flash memory (and later to copy it to flash beginning to run it after reset).

the call to do_spm self is an example of call to independent 'module' in flash
But this is only a "bootloader in a disguise". This will not help if OP wants to change the code so often a flash wear may cause problems.
Banned forever by Coding Badly for "trolling". Good luck with such attitude.
Update: Timeout "Extended, yet again, for lying." From eternity to Apr 19, 2019. Interesting...

Lucario448

Optiboot 8 has do_sdm service function. I use it here to store new version of the application in upper half of the flash memory (and later to copy it to flash beginning to run it after reset).
It's basically programming the flash memory on the fly, which I knew it's possible with that exact bootloader.

Soft-resetting is pretty straightfoward anyways: you just make the CPU jump to the reset vector, the equivalent of pressing the button but "in-code" (by the machine instruction "jump") and not physically (by an interrupt).



Nevertheless, this doesn't change the fact that code is still being executed from flash and not from RAM or external sources. Thus reprogramming the flash memory is the only option for that matter.

Fun fact: with the appropriate assembly code, you can make the Arduino execute code from any PROGMEM data array; a very cryptic way of coding but possible.

Juraj

Soft-resetting is pretty straightfoward anyways: you just make the CPU jump to the reset vector, the equivalent of pressing the button but "in-code" (by the machine instruction "jump") and not physically (by an interrupt).
jump to reset vector is not reset. the state of the MCU is not reset. only the program start from the beginning. only watchdog reset is a real 'soft' reset on AVR


Nevertheless, this doesn't change the fact that code is still being executed from flash and not from RAM or external sources. Thus reprogramming the flash memory is the only option for that matter.
that is true
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

Aksolotl

it is possible. I know how to do it.
but why not only put all the functions into the sketch
Well, the thing is that maybe the amount of code or functions will be bigger than the memory of the card, in my last project I used 85% of an UNO card and this will be bigger.
And the other thing is that i want to try a "modular programming" concept, it would change the world if we find a correct use for it

Juraj

Well, the thing is that maybe the amount of code or functions will be bigger than the memory of the card, in my last project I used 85% of an UNO card and this will be bigger.
And the other thing is that i want to try a "modular programming" concept, it would change the world if we find a correct use for it
use a Mega
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

Go Up