Thread::wait does not work on my own target

19 Jan 2017

I am writing a target port for pixhawk stm32f427vit6 board and add it inside the mbed-os source. The main routine is as following

main.cpp

DigitalOut myled(LED1);
BufferedSerial pc(PA_0, PA_1);

int main() {
    pc.baud(115200);

    while(1) {
        myled = !myled;
        pc.printf("Hello World - buf\r\n");
        wait(1);
    }
}

In debug mode, it can go to wait > wait_us > Thread::wait > svcDelay > scvHandler > svcUser > defaultHandler. Can anyone tell me where the problem is and how to fix it?? If you can, can you explain how the svcHandler involves into the delay routine of os???

21 Jan 2017

i try a few things today.

  • first, if i use the wait without mbedos, the program can run okie but the duration 1 sec is wrong. i guess i config the clock wrongly
  • second, when i compare the startup script from stm32cube and mbed stm32f429, there is a difference. In the startup script from stm32cube, it calls "libc_init_array". on the other hand, the other one calls _start. do u know where is the definition of the link "_start"
21 Jan 2017

I continue to try on it today. At first, my best guess is that some initialization procedures of mbed are not called. For example, when in debug mode, the uC doesn't break at software_init_hook(). It makes me strongly believe that the startup script is the main mistake here.

After skimming through the startup scripts of different targets, to my surprise, some of them uncomment libc_init_array and call "bl _start" while the other boards call both libc_init_array and _start link. Thus, I made my script calling both libc_init_array and _start. As the result of that, it began to work correctly.

If you want to port a new target, i would like to summarize my experiment here:

  • use mbedcli to export the project to use and debug on the supported ide (i use coide in my experiment). By using mbedcli, the project contains the whole source code of mbed-os (if u use the online ide, the exported project only has the mbed-os lib file, not source)
  • the exported proj will require some modifications before it can compile successfully.
    • fix the deviceID in .coproj.
    • add the macro in mbed_config.h into coocox proj configuration (tab compile->defined symbols)
  • after it can be compiled and works correctly on the mbed board, u can start to port by adding the target driver of ur port and put inside the folder mbed-os/target/target-stm/target_stmf4/target_<boardName>
    • change PinNames.h and PeripheralPins.c, PortNames.h according to ur board.
    • change system_stm32f4xx.c
    • change startup script
    • there may be smt else need to change as well. However, the key is that only the target folder is one that s matter. So just make sure every line of code in that folder is changed correctly, the mbed code should work correctly as well.

==> by now, ur board should run the mbed program gracefully with blinking led, but still left the serial print

22 Jan 2017

the serial print still doesnt work.

okie, the detail is that if i use BufferedSerial library, it can print a few character every 1 sec which is the waiting time, but combine them together, all the characters can form the word "hello\r\n". Then i try to use Serial, the program hangs at libc_init_array. Until now, I dont understand what are the meanings of libc_init_array and _start in the startup script. If the routines doesnt have the source, i dont have any means to check what is executed inside. I get stucked....

Can anyone help me on the startup script???