Skip to content

Commit 5eb976a

Browse files
committed
Fix _sbrk() implementation for Cortex-M parts.
A recent commit, 43acaa4, to get _sbrk() to build successfully for LPC2368 broke the Cortex-M implementation. __get_MSP() isn't ever defined as a macro, it is an inline function. This means that the code would always be compiled to use SP instead of MSP on Cortex-M parts. I switched the code to instead use the TARGET_ARM7 define to choose which stack pointer to utilize. I tested this fix by making sure that the LPC2368 version of the mbed SDK would still build successfully with the Python scripts and that the NET1 test still built and ran successfully on my mbed-LPC1768 device.
1 parent 96ea3db commit 5eb976a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libraries/mbed/common/retarget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,10 @@ extern "C" caddr_t _sbrk(int incr) {
448448
unsigned char* prev_heap = heap;
449449
unsigned char* new_heap = heap + incr;
450450

451-
#ifdef __get_MSP
452-
if (new_heap >= (unsigned char*)__get_MSP()) {
453-
#else
451+
#if defined(TARGET_ARM7)
454452
if (new_heap >= stack_ptr) {
453+
#else
454+
if (new_heap >= (unsigned char*)__get_MSP()) {
455455
#endif
456456
errno = ENOMEM;
457457
return (caddr_t)-1;

0 commit comments

Comments
 (0)