If you read my replies above, you'll see the reply to your question... which, is the same that Joseph had.
Idiot guide to using SD card on Olimexino - STM32 Maple clone
(26 posts) (11 voices)-
Posted 3 years ago #
-
@everyone I think the problem for new users is that there is no warning anywhere to tell them that all the examples that come with the sd library do not work on the Maple and will never work because they use Arduino specific code (IIRC pointers and PROGMEM). Obviously they work with a bit of tweaking to the Maple. It's not a big problem, just time consuming for the number of examples. The only one that works is filesys.
I think a simple, but obvious, readme which states this problem would be a simple fix. The first thing most new users are going to do are run the examples, rather than look at the docs and write their own code. Or just put an
#error These files won't compile on Maple without modifications
on each example file.I know I went through about 4 or 5 of the examples changing them for the Maple (Olimexino), but it wasn't a pretty fix.
BTW The Olimexino uses pin 25 for chip select on port 2, not 31. Will there be an easy way to change this? I've noticed that the new Arduino spi library allows you to specify the nss pin i.e. spi.begin(25).
A quick fix is just to run a wire from pin 25 to pin 31. Not ideal.
While I'm here @feurig, the FileSys example as supplied doesn't work, there are two spi.begin() in it? Why? Surely just the one begin should work. If you need someone to test your new libraries I can do this. Also I have a SdMapleRTC.h that uses the maples real time clock for timestamps if needed.
Posted 3 years ago # -
So, playing around with the newer maplesdfat, I've made a very quick hack which will enable some (maybe all?) of the arduino examples to work on the maple with only 1 or 2 modifications.
@everyone who codes pro or semi-pro or teaches : you are not going to like this hack, but it's better than staring at a page of nonsensical errors.
First, add a file called MapleHack.h to the sdfat library (you've installed it so you should know where it is) and paste in the following 'code' :-
// BEGIN MASSIVE ARDUINO to MAPLE HACK #include <string.h> // needed for strcpy #define Serial SerialUSB #define SPI_HALF_SPEED &spi // Replace line "init.card(SPI_HALF_SPEED)" with line "init.card(&spi)" #define PSTR (const char*) #define strcpy_P (strcpy) #define PgmPrint(x) SerialPrint_P(PSTR(x)) #define PgmPrintln(x) SerialPrintln_P(PSTR(x)) #define NOINLINE __attribute__((noinline)) #include <HardwareSPI.h> HardwareSPI spi( 1 ); // Change this to 2 if your SD card is on SPI2 #include <WProgram.h> static NOINLINE void SerialPrint_P(const char *str) { SerialUSB.print(str); } static NOINLINE void SerialPrintln_P(const char *str) { SerialUSB.println(str); } static int FreeRam(void) { return (20); // NOPE! }
Save it and forget all about it. PLEASE Don't use it in your own code!
For each arduino examples your interested in playing around with (and ONLY for these examples) replace
#include <fatutils.h>
with#include <MapleHack.h>
Then replace
serial.begin(9600)
which isn't needed on the Maple with
spi.begin(SPI_4_5MHZ, MSBFIRST, 0); // Start the SPI at the given speed
It's confirmed to work with sdfatls, sdfatinfo, sdfatappend, sdfatcopy though you might have to remove a
serial.flush()
from the code as Maple doesn't do that.If your using a Olimexino with built in sdcard, change the spi in the code above to 2 and either change the maple.h file found in the depths of the maple core and change the line
#define BOARD_SPI2_NSS_PIN
25 // oli is 25, maple is 31
OR if your feeling lazy, wire pins 25 and pin 31 together.Note also that in all these examples, the setup() waits for a character from serialusb before proceeding, so don't forget to type any key and hit 'send'.
Hopefully this'll be useful for someone who wants to use the Maple to 'make stuff' without getting too bogged down in details of sd card programming.
Posted 3 years ago # -
Hi there,
i got a code working on the STM32 Olimexino using sd card functionality on an example way. (file open, write....)
I also made changes in .h according to some older posts that were really hard to find the propper settings revealing too much confusing stuff also. eventually i got it working just by hardcoding the 31 to 25 issue.
I could then write to the SD card..
The really hard thing i encouterred with this script, and that´s what i wanted to talk about here, is that i have severe SRAM problems. (error message like: '...region ram overflowed by...' '...reported above...')
the script is very small; I know that i could have flash used for the .text based files (whatever part that might be) but i do not understand why the size is that big and do not want to exegerate or exhaust the timley constricted falsh ram.
could anybode explain why the compiled file is too big and how to maybe shrink it.
thank you; go61t
here is the code:
#include <SdFat.h> #include <HardwareSPI.h> #include <stdint.h> HardwareSPI spi(2); Sd2Card card; SdVolume volume; SdFile root; SdFile file; void setup() { SerialUSB.begin(); spi.begin(SPI_281_250KHZ, MSBFIRST, 0); SerialUSB.println("type any char to start"); while (!SerialUSB.available()); SerialUSB.println(); if (!card.init(&spi)) SerialUSB.println("card.init failed"); else SerialUSB.println("card.init passed"); // spi.end(); // spi.begin(SPI_1_125MHZ, MSBFIRST, 0); delay(100); // initialize a FAT volume if (!volume.init(&card)) SerialUSB.println("volume.init failed"); else SerialUSB.println("volume.init passed"); // open the root directory if (!root.openRoot(&volume)) SerialUSB.println("openRoot failed"); else SerialUSB.println("openRoot passed"); /*file.createContiguous(&root, "TEXTFILE.TXT", 100); */file.ls(LS_SIZE, 1); /* // open a file if (file.open(&root, "output2.csv", O_READ)) { SerialUSB.println("Opened PRINT00.TXT"); } else if (file.open(&root, "WRITE00.TXT", O_READ)) { SerialUSB.println("Opened WRITE00.TXT"); } else { SerialUSB.println("file.open failed"); }*/ SerialUSB.println(); /* int16_t n; uint8_t buf[7];// nothing special about 7, just a lucky number. while ((n = file.read(buf, sizeof(buf))) > 0) { for (uint8_t i = 0; i < n; i++) SerialUSB.print(buf[i]); }*/ /* easier way int16_t c; while ((c = file.read()) > 0) Serial.print((char)c); */ SerialUSB.println("\nDone"); spi.end(); } void loop() { }
Posted 3 years ago # -
go61t - this may be a silly question, but are compiling and loading the program into Flash or RAM?
Posted 3 years ago # -
hi gbulmer - as posted I tried both and had problems in case i use the RAM solely. (20kb)
The thing is that I want to know why so much storage is used in case of the above script covering the SD card fuctionality.
If I add realtime functionaliy I truely get more problems, that might fast exceed the flash as well. (128kB)I could not imagine that others have less code involved in their projects...
Thank you
Posted 3 years ago # -
Hello,
I copied and pasted the script into the maple IDE and it compiled. :\ Mind you though that I don't have the last SDFat library, or the DMA enabled version either.
Have you tried different versions of the library?I got this back from the compiler:
Compiling the sketch...
Linking...
Computing sketch size.../var/folders/b2/b2Qxxb0JHpulgWmJOPT3vU+++TI/-Tmp-/build8926750940236191491.tmp/sketch_nov29a.cpp.bin :
section size addr
.data 22376 0
Total 22376Posted 3 years ago # -
looks good on your side. i guess you have the flash enabled for your compiled code as target.
otherwise there should be the message (storage... reported above...) as the 20kb of the SRAM is exhausted also as in my case.>>Total 22376<<
the question remains. why is the script that big!
Posted 3 years ago # -
i did not find a way to shrink the amount of compiled code when using the SD card functionallity; what is your experience with the size. the sd file object has a size of 4kb but the behaviour is strange. while instancing another object the size is not increasing, even if the rest of the code is reduced to almost zero! when using the rest of the code it goes up to 30kb; only 7kb are free in SRAM as the boot environment already takes round 12kb
Does anybody know a way to extend ram as a solution?
Posted 3 years ago # -
go61t - I asked "this may be a silly question, but are compiling and loading the program into Flash or RAM?"
you replied "hi gbulmer - as posted I tried both ..."
Where did you say that? I've reread your post, and can't find an explanation about which you tried.You went on to say "... and had problems in case i use the RAM solely. (20kb)"
So when you compile and load the program and all of its data into RAM, it exceeds RAM?Then compile and load the program into Flash.
An Arduino runs the original SdFat library in 32kB Flash and 2kB of RAM. If you try to load the entire thing into 20kB RAM, along with the Maples USB libraries and buffers, plus the RAM used by the Maple bootloader, it might overflow RAM. No surprises, that's not unreasonable.
"the question remains. why is the script that big!
BECAUSE YOU ARE LOADING BOTH THE PROGRAM AND DATA INTO RAM?The boot environment only uses a couple of kB of RAM, so there should be plenty if you compile and load the code into Flash.
Posted 3 years ago # -
Thanks vor Your post!
RAM / flash
I did mentioned in the opening Post saying. (I could have flash used... )
What implies that i know the behaviour of flash it. It's working.
Sorry for Not making me clear, but i intended to ask for the size.
If You think it's Not Too big i proceed. I just thought that two
objects and two Lines couldn't make the difference. Cheers
I' ll Swap to maple native maybe.Posted 3 years ago #
Reply
You must log in to post.