Porting to mbed 5.0, rtos exception

Hi,

I’m trying to port my board to mbed 5.0, i’ve already ported it to mbed 3.0, so i think i will reuse the same the cmsis and hal layers, and copy them into mbed-os/hal/target/cmsis/VENDOR/TARGET_mytarget and mbed-os/hal/target/hal/VENDOR/TARGET_mytarget

i did a small test with a blinking led, and it works.

Now i wanted to try rtos, so I added of course my board configuration in the 2 following files : RTX_CM_lib.h and RTX_Conf_CM.c.

I’m getting a weird exception when i try to start a thread, actually it prints using the uart : Exception.
I did a step by step debug and, it seems that the Exception occurs just after this line ( 3 line) in the function : osStatus Thread::start(Callback<void()> task) :

#if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
    _thread_def.pthread = Thread::_thunk;
    if (_thread_def.stack_pointer == NULL) {
        _thread_def.stack_pointer = new uint32_t[_thread_def.stacksize/sizeof(uint32_t)];
        if (_thread_def.stack_pointer == NULL) {
            _mutex.unlock();
            return osErrorNoMemory;
        }
    }

Is line 3 the allocation? Is your heap correctly set up?

Thanks for your reply, i did find the problem, it wasn’t the heap, it was my stack, i didn’t put it in the right place in my linker which causes the exception, now it’s working fine.

After activating uVisor, i’m getting a bus fault after executing the same line : i tried to set up my heap and and my stack as shown in the porting tutorial of uvisor.

here is the the gdb output :

639,420 @"***********************************************************\n"
639,432 @"                    BUS FAULT\n"
639,445 @"***********************************************************\n"
639,458 @"\n"
639,491 @"* CFSR  : 0x00008200\n"
639,523 @"\r\n"
639,555 @"\r* BFAR  : 0xE000ED08\n"
639,587 @"\r\n"
639,620 @"\r* EXCEPTION STACK FRAME\n"
639,652 @"  Exception from unprivileged code\n"
639,665 @"    psp:     0x20005560\n"
639,698 @"\r    lr:      0xFFFFFFFD\n"
639,710 @"\r  Exception stack frame:\n"
639,743 @"    psp[07]: 0x41000000 | xPSR\n"
639,755 @"    psp[06]: 0x1000F2C2 | pc\n"
639,768 @"    psp[05]: 0x1000F293 | lr\n"
639,782 @"    psp[04]: 0x01010101 | r12\n"
639,815 @"    psp[03]: 0x00000000 | r3\n"
639,827 @"    psp[02]: 0x00000000 | r2\n"
639,860 @"    psp[01]: 0x7F7F8000 | r1\n"
639,872 @"    psp[00]: 0x00000001 | r0\n"
639,905 @"\n"
639,937 @"* MPU CONFIGURATION\n"
639,969 @"\r\n"
640,002 @"\r  Background region enabled\n"
640,014 @"\r  MPU bypassed @NMI, @HardFault\n"
640,027 @"\r  MPU enabled\n"
640,040 @"\r\n"
640,073 @"\r  Region Start      Size  XN AP  TEX S C B SRD      Valid\n"
640,106 @"\r  0      0x10000000 128KB 0  110 000 0 0 0 00000000 1\n"
640,118 @"\r  1      0x20000000 128KB 0  011 000 0 0 0 00000000 1\n"
640,151 @"\r  2      0x20000000 016KB 1  001 000 0 0 0 11100000 1\n"
640,183 @"\r  3      0x42100000 004KB 1  011 000 0 0 0 00000000 1\n"
640,215 @"\r  4      0x40000000 064B  1  011 000 0 0 0 00000000 1\n"
640,247 @"\r  5      0x40010000 032B  1  011 000 0 0 0 00000000 1\n"
640,260 @"\r  6      0x40008000 256B  1  011 000 0 0 0 00000000 1\n"
640,292 @"\r  7      0x40020000 064B  1  011 000 0 0 0 00000000 1\n"
640,305 @"\r\n"
640,317 @"\r***********************************************************\n"
640,330 @"\n"
640,363 @"HALT_ERROR(./core/system/src/mpu/vmpu_armv7m.c#277): Access to restricted resource denied\\

Solved, this time was a heap problem.