SPI clock frequency (with ST7735 lib) on MBED os v5

So, the question is no longer about how to change SPI clock frequency. It is now how to reduce overhead.

Maybe mbed OS5 SPI interface has more overhead than OS2. You can look at the source and open an issue at the GitHub if necessary.

I think you can improve the performance by rewriting your code too. Looks like you draw pixel by pixel and assert de-assert chip select each time. That increases overhead. I would try to find a way to transfer a block of data for a line or something.

Blockquote Maybe mbed OS5 SPI interface has more overhead than OS2.

It’s the same code, same OS but different editors.
I’m using framework-mbed 6.51401.200402 (5.14.1) which the latest on VSCode and I already tried downgrading the Mbed version to the same of Vscode, with same results.

The problem is not the libs, they are the same. Something is delaying SPI !

What about the compiler? The same? What about the optimization setting?

Sorry,
This is actually my second time trying to do something with Mbed I don’t know much of it.
Is there a “Dump” command on Mbed where I can extract all configuration at once?

Disabling RTOS really helped a bit but it’s slow compared to VSCode.

setFrequency(16000000) delay between instructions:

VSCode with RTOS → 12µS

VSCode without RTOS → 5.5µs (fastest one)

Mbed Studio with RTOS → 18µS

Mbed Studio without RTOS → 9µs

Config I used to disable RTOS and other features on MBed Studio:

.mbedignore

rtos/*

features/cellular/

features/frameworks/*

features/net/*

features/netsocket/*

features/nvstore/*

features/storage/*

drivers/source/usb/*

features/lorawan*

features/lwipstack*

features/nanostack*

all .mbedignore files on VSCode:

find ./ -iname “.mbedignore” -type f -print -exec cat {} ;

.//components/TARGET_PSA/services/attestation/qcbor/.mbedignore
test/*

.//events/source/.mbedignore
tests/*

.//features/FEATURE_BLE/.mbedignore
tests/.//features/frameworks/mbed-client-randlib/.mbedignore
linux/

test/*

.//features/frameworks/mbed-coap/.mbedignore
test/*
unittest/*

.//features/frameworks/mbed-trace/.mbedignore
build/*
yotta_modules/*
yotta_targets/*
test/*
example/*

.//features/frameworks/nanostack-libservice/.mbedignore

test/*

.//features/lwipstack/.mbedignore

lwip/doc/*
lwip/test/*
lwip/src/apps/*
lwip/src/netif/lwip_slipif.c
lwip/src/include/lwip/apps/*
lwip/src/include/compat/stdc/*
lwip-eth/*

.//features/nanostack/coap-service/.mbedignore
test/*

.//features/nanostack/mbed-mesh-api/.mbedignore
test/*

.//features/nanostack/nanostack-hal-mbed-cmsis-rtos/.mbedignore
cs_nvm/test/*

.//features/nanostack/sal-stack-nanostack/.mbedignore
test/*
unittest/*
release/*
source/Service_Libs/CCM_lib/mbedOS/aes_mbedtls.c
output/*

.//features/storage/filesystem/littlefs/.mbedignore
littlefs/emubd/
littlefs/tests/
TESTS/util

.//features/storage/filesystem/littlefs/littlefs/emubd/.mbedignore
lfs_emubd.*
.//features/unsupported/.mbedignore

.//targets/TARGET_Silicon_Labs/TARGET_EFM32/TESTS/.mbedignore

*.//tools/.mbedignore

*.//UNITTESTS/.mbedignore

*%

I cannot say anything specific about Mbed Studio or VSCode. (I don’t use them.) But, with CLI, we use mbed build profiles to set optimization levels (and others). I guess you can do that on Studio too.

The same code doesn’t mean it always performs the same. You have to compile your code to run it on your target. The actual performance (and code size) depends on the compiler and optimization level.

Here is my little experiment for you. The same code, the same OS (5.15.1), the same microcontroller (LPC1768), and the same compiler (GCC). But, different optimization settings. You can see how they are different.

The code:

#include "mbed.h"

SPI spi(p5, p6, p7);
DigitalOut cs(p8);

int main() {

    spi.format(8, 3);
    spi.frequency(1000000);

	cs = 1;

    while (1) {
        cs = 0;
        spi.write('H');
        spi.write('e');
        spi.write('l');
        spi.write('l');
        spi.write('o');
        cs = 1;
	}
}

Optimization option -O0: 16.55us

Optimization option -O1: 8.35us

Optimization option -O2: 7.75us

Optimization option -O3: 7.3us

So, I suggest your playing around with the optimization settings before you conclude that this is a bug in Mbed Studio.
I would also see if Studio and VSCode use the same compiler.

OK, first let me thank you for your help.
I finally did it!
I installed the bare metal example without rtos and set optimization to -O3 (tools/profiles/Release.json)
I achieved ~4µs, very Good!

@skydarc since you are using rtos and if you want to optimize try change the optimization flag. If you want to use bare metal Bare metal example - Reference | Mbed OS 5 Documentation

Glad to hear that.

Discoveries from this thread :slightly_smiling_face::

  • When we work on embedded systems, we are blind without an oscilloscope.
  • We need to compile our code to run. And how we compile it matters.
1 Like

Bugs forces us to learn how things work. Some say, programming is 1% writing code, 99% debugging. :laughing:

1 Like