Hello folks, I’m trying to put my mBuino to use by combining a few libraries and a bit of code. However, my experiments are not very successful yet. Even at only a few lines of code, I seem to hit the flashmemory limit of 32K.
In this particular case I tried to test my micro-SD adapter. For that I need the SDFileSystem library (imported via this handbook page) and for debugging the USBSerial class from the USBDevice library.
By building example programs using the separate libraries I found the following estimated sizes:
mbed + some code 10.0 kB
USBDevice 7.7 kB
SDFileSystem 15.2 kB
-------------+
Total 32.9 kB
Obviously this is too much for the mBuino flash-memory limits.
Decades ago when memory-constraints were always an issue, I would look for smaller sized libraries that were optimized for size by stripping debug information and unneeded code.
What methods are available on mbed to fit everything on mBuino?
(BTW. I’m using the online IDE)
FYI: this is the minimalized piece of test code I could fit on mBuino. As you can see I had to comment-out all my debug statements to fit it just under the 32K. Unfortunately even this code doesn’t work and gives me the 4-led-error-blink. Perhaps just under 32K is too much, or maybe mBuino doesn’t like my choice of pins.
Edit: the blinking seems size related. Using just the SDFileSystem or only the USBSerial gives me binaries without error-blinks.
#include "mbed.h"
#include "SDFileSystem.h" // see developer.mbed.org/handbook/SDFileSystem
#include "USBSerial.h" // see developer.mbed.org/users/mbed_official/code/USBDevice/
SDFileSystem sd(P0_21, P0_22, P1_15, P0_11, "sd"); // pinout used on mBuino (MOSI, MISO, SCLK, SSEL)
DigitalOut LED[] = {(LED1), (LED2), (LED3), (LED4), (LED5), (LED6), (LED7)};// the 7 LEDs of mBuino
void BlinkLed(uint8_t nLed, float flDelay=0.1)
{
LED[nLed] = 1; // turn on
wait(flDelay); // delay
LED[nLed] = 0; // turn on
wait(flDelay); // delay
}
// The USB virtual serial port is used for debugging. Note: driver required, see developer.mbed.org/handbook/USBSerial
USBSerial serialUSB; // Virtual serial port over USB
int main() {
//serialUSB.printf("Hello World!\n");
while(!serialUSB.readable()) {
serialUSB.printf(".");
BlinkLed(4);
}
//serialUSB.printf("Writing SD dir/file...\n");
serialUSB.printf("Write");
mkdir("/sd/mydir", 0777);
FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
if(fp == NULL) {
//serialUSB.printf("Could not open file for write\n");
serialUSB.printf("Err");
}
fprintf(fp, "Hello SD Card World!");
fclose(fp);
//serialUSB.printf("Goodbye World!\n");
}