Feature request / bugfix: make _sbrk() weak (for malloc() from external memory)

01 Dec 2017

Request

In the file mbed-os/platform/mbed_retarget.cpp, please add the attribute MBED_WEAK (or equivalent) to the function definition _sbrk(), to allow the user to override it.

extern "C" MBED_WEAK caddr_t _sbrk(int incr) {
   // [snip...]
}

Details / Motivation

An approach sometimes used to access external memory in embedded systems is to have all stack memory use internal RAM, and all dynamic memory (e.g. malloc()) allocate memory from external RAM. This is especially useful during development, to at least temporarily skip over the often difficult task of editing linker files.

Embedded Artists' EALib takes this approach to enable access to an external SDRAM chip. In sdram.cpp, it defines/overrides the _sbrk() function, which is used by malloc(), (etc.), to manage the heap.

This worked in older versions of mbed (at least through rev 120), but I cannot build it in the latest mbed-os, due to _sbrk() already being defined in mbed_retarget.cpp. Please make the mbed-os _sbrk() weak, to allow EALib to use the SDRAM as intended.

01 Dec 2017

Hey Brendan,

If you feel comfortable, could please submit an issue against mbed OS for this feature request? Here is the link - https://github.com/ARMmbed/mbed-os/issues

This document will detail the accounts needed to submit GitHub issues - https://os.mbed.com/contributing/. Don't worry about signing the CLA unless you want to submit the fix yourself. Here is the most relevant link captured there - https://guides.github.com/features/issues/

If you're not comfortable, I can walk you through the process.

01 Dec 2017

I submitted an issue on GitHub. Thanks.

https://github.com/ARMmbed/mbed-os/issues/5638