Customized module

“Write once and use everywhere” is the goal of component-based development. In my opinion, mbed OS utilizes modules to head towards that goal. However, sometimes I need to customize existing module(s) to meet my needs, but I could not find a feasible way to achieve that.

For example, the retarget.cpp of mbed-drivers implements the the low-level _write function to re-direct the debug messages to the serial port, but its speed is slow. On the contrary, Segger RTT could output debugging messages with very high performance. To use Segger RTT, I also need to re-implement the low level _write function. The end result is that I need a customized version of mbed-dirvers to disable the _write function in order to utilize Segger RTT.

To use the customized mbed-dirvers for my executable, I could use yotta link command to link to it. But how do I share the source of the executable to others to successfully build that executable? If they build the executable without using yotta link, yotta will pull mbed-drivers from the yotta registry.

How does mbed OS to solve this kind of problem?

Total mbed OS noob here.

I started to write a blurb about C++ templating, but I see _write is a extern “C” function, so scratch that.

Glancing at _write source code, it seems you could rig up your own version of a FileHandle class and override the write(buffer, length) to serve your own evil high speed deeds. The trick to that seems to be ensuring you’re utilizing a filehandle# over 3. Presumably 0-3 represents stuff like stdin, stdout, stderr - but I am only guessing.