Build flag introduces bug in previously working code

Hey everyone, Happy New Year to you all. I hope 2020 is full of rewarding projects.

I’m playing around with some Google TensorFlow code on the NXP FRDM-K66F platform and noticed some strange behaviour when I use the PIO_FRAMEWORK_MBED_RTOS_PRESENT build flag.

Google seems to have borrowed bits of driver code from the NXP SDK, so it doesn’t use any of the Mbed RTOS. When it is built without using the PIO_FRAMEWORK_MBED_RTOS_PRESENT build flag it works great. However once I use -D PIO_FRAMEWORK_MBED_RTOS_PRESENT, it compiles and runs for about 45 seconds before the audio cuts out. I’m not sure whether it’s the SAI interface that dies or something to do with buffer handling - I need to dig more.

But I’m wondering if anyone could provide some information on what the PIO_FRAMEWORK_MBED_RTOS_PRESENT build flag actually does to the executable.

Thanks for any thoughts.

See the file C:\Users\<user>\.platformio\packages\framework-mbed\platformio\platformio-build.py script. It enables the compilation of certain components,in particular the RTOS.

MBED_RTOS = "PIO_FRAMEWORK_MBED_RTOS_PRESENT" in env.Flatten(
    env.get("CPPDEFINES", []))

if MBED_RTOS:
    src_paths.extend([
        join(FRAMEWORK_DIR, "cmsis"),
        join(FRAMEWORK_DIR, "components"),
        join(FRAMEWORK_DIR, "features"),
        join(FRAMEWORK_DIR, "rtos")
    ])

And see Mbed OS — PlatformIO latest documentation.

I also can’t say directly why it doesn’t work, there might be multiple reasons. Out-of-memory due to increased memory needs and a memory leak somewhere, etc

Max, thanks for the input and pointer to the script. I will take a deeper dive.

However, I now believe this is more of an Mbed issue, rather than platformio. And just to be clear, the application does not crash after executing for a set period of time, it simply appears to cease processing audio samples. We are reusing a lot of NXP supplied driver code, which works under the bare metal Mbed profile, but not under the RTOS profile. There is some conflict occurring, potentially around DMA, or interrupts perhaps, as no doubt the Mbed RTOS would most likely install it’s own hooks/handlers/dispatchers which may be interfering with the NXP code (which was built to run on FreeRTOS).

Thanks again for your insight and suggestions.
Scott

1 Like