LPC1768 / Mbed OS5 - Writing to LocalFileSystem after SPI initialisation results in a crash


Some expert knowledge needed here. We are trying to extend small functionality in an old MBED LPC1768 (devboard) based Firmware of which the code was written on top of Mbed OS5 (v5.15.8).

We are trying to write a file to the onboard flash chip from a second thread. We noticed that our save() method works fine as long as we don’t initialise our display. Which is a ST7789 SPI based display:

lcd = new Adafruit_ST7789(p5, p6, p7, p21, p22, p24);

I noticed that in the init() method of the Adafruit_ST7789 there are wait_ms() commands. Whenever I comment those lines, then my display doesn’t work but the LocalFileSystem access works and the code doesn’t crash. What is the relation between these 2 functionalities? Does the MBED LPC1768’ onboard flash somehow use resources of that SPI bus?

Pseudo demo code:

#include "mbed.h"

Adafruit_ST7789 *lcd;
Thread eventThread;
EventQueue queue;

int main(){
	 /*  works */

     /* Initialize the SPI display */
     lcd = new Adafruit_ST7789(p5, p6, p7, p21, p22, p24);

     /* Doesn't work and result in a crash / hardfault as soon as it hits fopen() in the method */


void save(){
	printf("Saving to flash..");

	LocalFileSystem local("local");
	FILE *fp = fopen("/local/test.txt", "w");
	fprintf(fp, "Hello World!");

I think it has to do with this issue:

The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored.

  • Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
  • able to access the LocalFileSystem

How can we prevent it from going to sleep?

Kind regards,



also in this topic it was reported, but both were closed cuz no activity or low priority… that is sad.

BR, Jan

I wonder, what happens if you just comment out the line mentioned in the issue? (you will need to not use the online compiler in order to modify the Mbed code, if you’re currently using it).

If that doesn’t work, another option we could look into would be modifying the compile options to remove the DEVICE_SLEEP define, which would probably fix your issue, but would require messing around with custom targets.

Sorry for my late reply, Indeed i tried to comment that line and so far everything is working perfectly! Hope it helps somebody.