Go Down

Topic: Run code off SD card? (Read 2290 times) previous topic - next topic

Chicken325

Look.  I know this has been asked a MILLION times but I'm still confused as to the answer.  Is it AT ALL possible to run Arduino-language code off an SD card?  I assume you'd have to mess with the bootloader but how do you do that?  Thanks!

Aeturnalus

No.

"Arduino language" code gets compiled to CPU instructions, which are loaded by the CPU from its internal flash.  Adding an SD card via the bootloader doesn't help, since the code STILL needs to be loaded onto the ATmega at some point. 

Of course, you could write your own interpreter for C/C++ and load a text file off an SD card, but it'd probably be a huge undertaking for very little gain.

If you're actually using more than 32 kilobytes of compiled code (that's something near 10000 lines, extrapolating from my existing code) in an Arduino, its past time for you to either a) optimize or b) use a bigger/better/faster controller.

dcb

As Aeturnalus points out you cannot run arduino compiled code straight from a sd card.  The code must be in flash memory.

There are some options but they are a long shot.

You can put "logic" on the sd card that drives some pre-arranged functionality, but it is well outside the lines of arduino to do so.  It would be like defining your own virtual machine language interpreter and putting the bytecode on the sd card.  It needent be quite that formal however, it could just be a handful of functions and some virtual registers to tie the functions together with the order of operations stored on the sd.  Probably a performance hit, but could save space.

Also not in scope would be to store executable code on the sd card and load it into flash as needed.  This would be ok for a rarely called function, but you will be testing the limits of your flash to rewrite it frequently, and you have to write a page at a time and play with fuses.


PaulS

Quote
Look.  I know this has been asked a MILLION times but I'm still confused as to the answer.

How many times do you have to read NO, without ever reading YES, to stop being confused?

dcb

#5
Jun 06, 2011, 01:35 pm Last Edit: Jun 06, 2011, 01:41 pm by dcb Reason: 1
I don't think he has seen a clear "No".  The other thread has a couple long-winded Yes's in it.  I'm not saying No, because you can run code off an SD card, just not directly.  bitlash is a prime example, it runs arduino "looking" code from a sd card (though I have no clue what the motivation for writing it was).

AWOL

I certainly wouldn't say "no", but as usual, if you have to ask the question...
"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.

Grumpy_Mike

Quote
because you can run code off an SD card, just not directly.

If it is not directly it is not running code off an SD card.
You can't run code off an SD card.

Maybe you want to ask the question,
Can I store code on an SD card and use that to load it into the arduino to run.
The answer to that is "not without considerable difficulty"

mowcius

#8
Jun 06, 2011, 06:47 pm Last Edit: Jun 06, 2011, 06:50 pm by mowcius Reason: 1
Quote
Maybe you want to ask the question,
Can I store code on an SD card and use that to load it into the arduino to run.
The answer to that is "not without considerable difficulty"

Well the uMMC bootloader does that with reasonable ease (mind you it does have another processor sorting a lot of the stuff out and a modified bootloader).

Quote
If it is not directly it is not running code off an SD card.
You can't run code off an SD card.

I'd say bitlash is code and you can run bitlash using an arduino off of an SD card. Why's that not direct?

Grumpy_Mike

Quote
I'd say bitlash is code

And I would say it is not.

mowcius

Quote
And I would say it is not.

I suppose that depends upon your definition of code. I presume you're talking specifically source code.

Wikipedia says:
Quote
In computer science, source code (commonly just source or code) is any collection of statements or declarations written in some human-readable computer programming language. Source code is the mechanism most often used by programmers to specify the actions to be performed by a computer.

With that definition, I'd say bitlash is code.

Or is your definition more like:
Quote
A text listing of commands to be compiled or assembled into an executable computer program

(Also specifically 'source code')
I suppose bitlash isn't really assembled - they're more instructions or commands but then I'd say that html is also instructions/commands and not really assembled/compiled.

dcb

"Hey, where did that code you are running come from"

"It came off the SD card"

not much point in arguing semantics.

dcb

bitlash is code.  It isn't binary machine language, but it absolutely is code and can make the CPU do stuff.

Code you run in flash that was loaded off SD card is also a reasonable interpretation.

But nobody has really explained WHY this is even necessary.  I can think of a few hypotheticals but I'm not going there.  I want to hear what problem the OP is really trying to solve.

mowcius

I have thought of a few reasons for wanting to be able to do something similar (but not quite what has been posted).

Grumpy_Mike

Quote
bitlash is code.

No it is not. It is text that gets interpreted.

You might as well call sensory data code as it is read by a program and the program changes its behavior depending on the sensory input.

Go Up