Run code off SD card?

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!

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.

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.

It was asked yesterday...

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?

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).

I certainly wouldn't say "no", but as usual, if you have to ask the question...

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"

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).

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?

I'd say bitlash is code

And I would say it is not.

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:

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:

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.

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

"It came off the SD card"

not much point in arguing semantics.

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.

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

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.

Grumpy_Mike - so what is your definition of code? (source code?)

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

Yes but so is all code - javascript is simply human readable text that gets interpreted...

(source code?)

No source code isn't code - it is the source of the code hence the name!
Code is machine instructions. Source code is the source, used by a compiler, to produce code.
Bitlash is just text that is interpreted by another program, it is not code.

Ahh but that's what most people refer to when talking about code - you're just being pedantic.

Bitlash is therefore source code yes?

C++ is then not code but still source code?

Are we happy now? :smiley:

Ahh but that's what most people refer to when talking about code

Doesn't stop them from being wrong does it, just because a lot of people are wrong.

Glad we agree now...

:smiley:

Living up to your name tonight - didn't want to let us down :wink: