6 years, 11 months ago.

Import mbed-dev to a stm32cube mx project

Hi, I am using Keil as an IDE and it work great for debugging mbed-os exported projects.

Currently I am working with a custom target, based on the NUCLEO-F446ZE, but with different clock settings. Since the custom board was clock-incompatible with the original target, and i needed usb-otg support, I was forced to start using stm32cubemx for generating startup code.

But most of my code for my application was developed during the prototyping stage using mbed-dev libraries and c++ classes, like Serial, InterruptIn, Ticker, and many others.

I tried many ways to import mbed-dev to a stm32cubemx generated project on Keil, but nothing works properly. I managed to compile the code with no errors, but after flashing, most of mbed objects don't work properly.

i suppose i should post code, or something that could help someone help me, but i am hopping that someone in here had this same problem and found a solution.

I have tried to approaches, but had no success. Approach 1:

  1. Generate a STM32cubemx project with all the peripherals and clock configs i need.
  2. Migrate the project form C to C++.
  3. Add USB suport as a CDC device. (Everything works till here)
  4. Import mbed-dev (minus the files that are already in the project).
  5. Add InterruprIn and wait_us calls to main()

After compiling and flashing, InterruptIn get stuck during initialization and wait_us() also get stuck.

Approach 2:

  1. Generate a mbed project (Blinky) and export it to mbed (works ok)
  2. Replace mbed-dev/targets/target_stm files with new ones.

Also interruptIn get stuck during initialization and wait_us() also get stuck.

It seems to me that something must be modified in the cube files to work with mbed-dev libraries. I have some ideas where to start looking, but I am hoping someone had this same problem in the past and knows how to deal with it.

Any help would be much appreciated.

As a side comment, mbed is a great tool for prototyping, but when moving forward to a custom-board as a final product, many issues arise. This is one of the many issued i had encountered when migrating from a development board to a custom-board. If i had the time to re-write the code that was written with mbed-dev and use raw HAL-CMSIS code, i would abandon mbed altogether.

Any comments or piece of advice on this would also be appreciated.

regards

1 Answer

6 years, 11 months ago.

Hello Guillermo,
You can add code snippets or files generated by the stm32cube mx to your mbed project. Have a look at the Internal_Temperature_F103RB demo and the CANnucleo library. You can also change the clock settings in your mbed application based on the code generated in frame of a stm32cube mx project. Have a look at the STM32F103C8T6_Hello demo and the mbed-STM32F103C8T6 library. But then, to avoid initialization issues, I recommend you to create your mbed objects in main after the system clock has already been set, as for instance in this STM32F103C8T6_ILI9341 demo.

Thanks Zoltan,

so far that approach is the one that has worked in most cases. But I still have to deal with outdated code in core include files in folder targets/target_stm/ that don't allow some snippets to work. Particularly I am trying to enable USB CDC, but on my board it only works with latest stm32cube libraries.

posted by Guillermo García 02 May 2017