CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Loading code from sd, possible?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
uN_Eof



Joined: 17 May 2010
Posts: 29
Location: I live in Spain, with the toros, paella and tortilla

View user's profile Send private message

Loading code from sd, possible?
PostPosted: Sun Aug 15, 2010 12:39 pm     Reply with quote

Hey all, I want to load some code from a SD card, is this even possible?

Thanks in advance.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Aug 15, 2010 2:23 pm     Reply with quote

Except for few special devices with external memory interface, e.g. PIC18F852x and similar, 8- and 16-Bit PICs can only execute from internal (flash) program memory. Code from SD card must be programmed to flash before it can be executed. Due to limited flash durability, it's only usable for occasional code update.

PIC18F852x in contrast would allow code execution from external RAM.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun Aug 15, 2010 3:26 pm     Reply with quote

You could though build a bootloader, which looked for a specific filename on an SD card, and loads this. However, it will be quite builky (FAT file system, SPI drivers, etc. etc....).
Or of course, write yourself an interpreter, which runs 'script' operations from an SD card in your own language.

Best Wishes
uN_Eof



Joined: 17 May 2010
Posts: 29
Location: I live in Spain, with the toros, paella and tortilla

View user's profile Send private message

PostPosted: Sun Aug 15, 2010 3:59 pm     Reply with quote

I think writing my own language its (or at least looks like) difficult.
Can you please explain a little bit the "sd bootloader"?

Thanks in advance again
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Aug 15, 2010 4:10 pm     Reply with quote

See an example of a ready-made SD bootloader:
http://www.brushelectronics.com/
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

RE:
PostPosted: Sun Aug 15, 2010 11:05 pm     Reply with quote

The script language is easy enough to make, something similar to BASIC should be good enough for most applications.
uN_Eof



Joined: 17 May 2010
Posts: 29
Location: I live in Spain, with the toros, paella and tortilla

View user's profile Send private message

PostPosted: Mon Aug 16, 2010 3:55 am     Reply with quote

@FvM what that does is reprogramming the internal flash of the pic and thats what i domt want.
What i want is to directly load the code from sd.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Mon Aug 16, 2010 4:08 am     Reply with quote

Fvm, has already told you - you can't.
Code directly 'run' by the PIC processor can come from:
1) The internal ROM.
2) In a very few cases externally connected _parallel acces_ ROM.
3) Something like an ICD.
SD, is none of the above...
You either have to copy the SD into the ROM (which is what the bootloader does), or have an interpreter running in the PIC, that uses the SD card contents as it's 'program'...

It is worth realising, that even on the PC, you can't 'run' code on an SD card. On the PC, because it has a 'flat' memory architecture (only one memory space for RAM, and ROM), when you 'run' code on an SD card, it is copied into the local RAM, and run from here. It is slightly harder on the PIC, with separate RAM, andf ROM spaces, but if you selected one of the chips which will run code from an external memory, you could attach a static RAM, with 'dual port' access, then write the code from the SD into the write port of the RAM, and then run this. However it is still going to have been copied into the PIC's memory space, not 'run from the card'.

Best Wishes
collink



Joined: 08 Jan 2010
Posts: 137
Location: Michigan

View user's profile Send private message Visit poster's website

PostPosted: Mon Aug 16, 2010 5:48 am     Reply with quote

The interpreter idea is basically the only thing that would work across all chips. It could likely be made to fit in 4-5k of program ROM and less than 1K of RAM if FAT support is not there (thus requiring a RAW file system or something else less complicated than FAT.) The higher level the interpreted language is the faster things will likely run. At the low end the scripting language could be straight PIC assembly but that would be very slow as the interpreter would have to individually parse and run each asm instruction. It's thus faster to have each scripting item be a larger, higher level construct that runs many instructions per script action.

Ideally such a language would be like BASIC (as it's fairly simple to create a BASIC interpreter) but also have a large number of built-in functions that the script can call. For instance, if the scripted program does a lot of menus then have menuing functions built-in. If it does a lot of serial I/O then have those built-in, etc. Obviously every built-in function adds to the overhead of the interpreter.

In the end this sort of scheme could be somewhat tricky to do but would effectively create unlimited program space. Some of the potential snags:

1. Have to support demand loading of SDCard pages. I believe that SDCards tend to be read in 512byte chunks so the script would have to be loaded 512 bytes at a time. If FAT isn't used then something else has
to track how the script is stored and which piece to grab.
2. What if the script has functions and there are two functions, one calls the other, and they end up in different 512 byte chunks? Say hello to thrashing! This can be eased by loading more than one chunk (say, by saving the last loaded chunk so that the two more recently used chunks are resident.)
3. Interpreters are slow. Doubly/triply/majorly so if you have no idea what you are doing.

All that having been said... This has got me thinking about it anyway. I've got an application where I can't change the hardware but I've got an SDCard and I'm really tight for code space. This sort of scheme might be viable.... Sounds like a lot of work though.

Is anyone aware of a good open source interpreter for PIC that supports sdcard loading? That seems like a tall order. ;-)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group