Hello,
I recently bought a Teensy 4.0 and have been having a lot of fun with it. I've played with arduinos and other micro-controllers before but have mostly done basic things like using GPIO, PWMs and talking to SPI/I2C devices.
I've been trying to take a deeper dive and from reading the forums have so far learned how to use a makefile to compile outside of the arduino environment as well as calling a function from a simple assembly file into the blinky LED program.
A couple days ago I came across a thread that really piqued my interest: https://forum.pjrc.com/threads/26995-Teensy-3-1-Running-a-Program-off-a-SD-card
While the project in itself seemed pretty cool (running games off an SD card), a lot of the topics involved to get it working are something that I know very little about but would like to learn how to do.
From Paul's Comments:
I've read through a few other threads that seemed to ask similar things and it seems the moral of the story is: this very very difficult and I have a high chance of ending up with a bricked board.
https://forum.pjrc.com/threads/31673-native-application-loading
https://forum.pjrc.com/threads/38559-Possible-to-program-3-2-from-can
https://forum.pjrc.com/threads/29772-Uploading-sketch-from-SD-card
https://forum.pjrc.com/threads/30723-SD-Bootloader
https://forum.pjrc.com/threads/24302-How-to-execute-code-in-SRAM-(Teensy-3)
Since this topic seems to come up frequently I figured there might be someone that already ran through these hurdles and has code available that I could try to learn from but so far I have been unable to find it.
I have tried to get started by reading up on a lot of the vocabulary and googling the topics but I have been having a lot of trouble figuring out just how to implement it on the Teensy 4.0.
I understand that a lot of these topics are very complex but I figured I gotta start somewhere and I really like this project. What I'm looking for is any documentation, code examples or guidance that could help me get to the goal of running a simple game off removable memory (I was thinking tic tac toe to begin with). Thanks!
I recently bought a Teensy 4.0 and have been having a lot of fun with it. I've played with arduinos and other micro-controllers before but have mostly done basic things like using GPIO, PWMs and talking to SPI/I2C devices.
I've been trying to take a deeper dive and from reading the forums have so far learned how to use a makefile to compile outside of the arduino environment as well as calling a function from a simple assembly file into the blinky LED program.
A couple days ago I came across a thread that really piqued my interest: https://forum.pjrc.com/threads/26995-Teensy-3-1-Running-a-Program-off-a-SD-card
While the project in itself seemed pretty cool (running games off an SD card), a lot of the topics involved to get it working are something that I know very little about but would like to learn how to do.
From Paul's Comments:
- You'd need to edit the linker file, so the compiler creates the code for the RAM address, rather than flash.
- Your code will presumably need both static and stack based variables.
- You could create your linker script to just put your static variables right after your code, in the same block of RAM.
- You could even simplify the startup routines at the beginning of your code, since it wouldn't need to copy static initialization from flash to ram. Presumably, you'd use the already-established stack, set up by the code running from flash.
- You'll probably need to edit the normal linker script too, to make a big chunk of the RAM with a fixed starting address available.
- Then you could have the flash-based code simply copy the binary data from a file on the SD card to the big RAM buffer.
- Achieving any sort of integration between the RAM-based code and flash based code will make the arcane syntax of linker scripts and C function pointer type casting look like a walk in the park!
- Using interrupts from the RAM-based code will be the first huge challenge. Probably the simplest way would be to just create a new vector table in the RAM image and use it.
- But if you want to actually use any of the code in flash, you're going to have to figure out some way for your RAM-based program to know where the flash-based code allocated stuff in the _other_ RAM that's not dedicated to your program.
I've read through a few other threads that seemed to ask similar things and it seems the moral of the story is: this very very difficult and I have a high chance of ending up with a bricked board.
https://forum.pjrc.com/threads/31673-native-application-loading
https://forum.pjrc.com/threads/38559-Possible-to-program-3-2-from-can
https://forum.pjrc.com/threads/29772-Uploading-sketch-from-SD-card
https://forum.pjrc.com/threads/30723-SD-Bootloader
https://forum.pjrc.com/threads/24302-How-to-execute-code-in-SRAM-(Teensy-3)
Since this topic seems to come up frequently I figured there might be someone that already ran through these hurdles and has code available that I could try to learn from but so far I have been unable to find it.
I have tried to get started by reading up on a lot of the vocabulary and googling the topics but I have been having a lot of trouble figuring out just how to implement it on the Teensy 4.0.
I understand that a lot of these topics are very complex but I figured I gotta start somewhere and I really like this project. What I'm looking for is any documentation, code examples or guidance that could help me get to the goal of running a simple game off removable memory (I was thinking tic tac toe to begin with). Thanks!