6 years, 1 month ago.

Advanced timers and manual peripheral configuration

Hi all,

I want to be able to access the advanced peripheral features such as timer PWM & ADC synchronization.

MBED appears similar to Arduino, so being used to direct port manipulation, to manually configure peripherals by writing to registers, I'm wondering whenever MBED also supports this functionality.

As I understand, much of the code can directly be generated by STM32Cube. Are there any examples in how to import it to MBED, instead of using HAL drivers or libraries?

Thanks!

1 Answer

6 years, 1 month ago.

I am slightly confused by your question as STM32Cube MX uses HAL libraries it just helps preconfigure them for you. Mbed os uses similar HAL libraries to control peripherals on ST targets (I have not checked if they are identical but they are definitely similar). You can use any of the low level HAL functions directly yourself to make full use of the hardware regardless whether mbed-os has put a pretty C++ wrapper over it. Import the mbed-os source files into your project rather than using the precompiled mbed library and you can dig down and see all the various HAL modules for your target. And you can see how the C++ api wrappers make calls into the HAL layers. I've used the mbed included HAL libraries to implement a Watchdog timer and a complicated 2 phase pwm and I've added filtering to the CAN module because mbed hadn't implemented it. All the peripheral functionality is already there.

As far as CubeMX, my approach would be to generate some code in that program and then go in and inspect it. Then go to mbed and implement something similar using the HAL files provided by mbed. As always you will need to crack open the datasheet for whichever peripheral you're working on to fully understand exactly how you want to use the hardware registers. This can be sort of tedious, but unfortunately is a part of embedded development.

And yes you can write directly to registers if you want to manipulate peripherals that way as well though I can't say I would generally recommend it.