Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 5 months ago.
Access low level hardware functionality
Hey,
I just started using the online compiler (on a F401RE) and was wondering if there is a way to access low level hardware functionality for specificly timed pwm.
Something like the good old TIM_OCInitStructure:
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = (5 * f) / 1000000; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OC1Init(TIM5, &TIM_OCInitStructure);
Becuase the simple PwmOut class with it's few functions is giving me a hard time...
Thanks in advance Mikis
3 Answers
6 years, 5 months ago.
Hi Mikis,
To access low hardware functionality, you are able to change the code inside the HAL(Hardware Abstract Library) inside mbed-os folder mbed-os/targets/TARGET_STM/TARGET_STM32F4. Inside this folder you will have access to all the peripheral code, which you can then implement your own hardware specific design.
Please let me know if you have any questions!
- Peter, team Mbed
If this solved your question, please make sure to click the "Thanks" link below!
6 years, 5 months ago.
Hello Mikis,
You are free to access any low lvel hardware functionality. In case of STM boards it's very conveniet to use the STM32CubeMx tool. In board selector, select your Nucleo64 mbed board and you'll see what has already been used by mbed. Proceed to configure it while trying to keep mbed stuff. Once finished, let the STM32CubeMx generate the code, which you can then merge into your mbed project as I did for example in this case.
Thank you very much so far, so I simply activated TIM3 to do some PWM action on PB1 and generated some code, just as a test. The resulting files must then be imported into a project in the online IDE? So as I did this, I got an error message about "_Error_Handler(FILE, LINE);" not being defined, which is actually part of the generated code in the main.c file... any ideas on how to properly import it? Or will I have to tune that manually by deleting unnecessary parts of the code that conflict with external libraries that are used for code generation in STM32CubeMX? Or is this method just supposed to be manually setup?
posted by 23 Jul 2018(Sorry for some reason I can't edit my previous comment) This is a repo of the generated code: https://os.mbed.com/users/Airdevelopments/code/Nucleo_PWM_TEST/
posted by 23 Jul 20186 years, 5 months ago.
There are several enhanced PWM libs out there already. I would look at this one (https://os.mbed.com/users/Sissors/code/FastPWM/) and possibly add some features to it.