I am fairly new to PX4 and NuttX and I’m currently working on using PX4 with a custom FMU. In my FMU design, I’ve implemented USB High-Speed using an external ULPI interface with the STM32H7. Since the USB HS transceiver requires a constant 13 MHz frequency to function correctly, I’ve assigned one of the STM32 pins to generate this clock signal. I’ve already tested the hardware using STM32CubeIDE, which I’m quite familiar with, and it works as expected, I can see the CDC interface as intended.
Now, I want to transition to PX4. I’ve configured everything in qconfig, following guidance I found online and by examining the code. The issue arises when I try to generate a fixed-frequency timer output on a pin. Despite searching extensively, I haven’t found a clear solution on how to set this up in PX4. I’ve looked at other board designs, and none of them seem to configure a fixed timer frequency at initialization. It appears that most rely on QGroundControl to configure PWM outputs but to use QGroundControl, I need a functional USB interface, which I can’t get without that timer output.
Has anyone worked on a similar setup or faced this issue? Any guidance or advice would be greatly appreciated.
I have a few more question if that’s possible. The hrt_tim_init is setup as interrupt right? Therefor I need to modify the function such that it can output a Timer waveform. Does something like that exist or do I need to create it myself, inspired by the hrt function?
Additionally I call px4_arch_configgpio(GPIO_TIM16_CH1OUT);
#define GPIO_TIM16_CH1OUT GPIO_TIM16_CH1OUT_2
I think this could work but not 100% of the implementation or if I forgot something. I don’t know if you can take a look and would be very nice thank you in advance !
Hello,
I have dug into the code and have started understanding how each files actually interact with another. May be you could help me a bit further.
So I looked a bit further into io_timer.c, and I saw there is macro to set the timer register, and they are called by majority of the functions in the file. Now the one that I think interest me are:
io_timer_channel_init → Allocate the channel, set the mode so for me I have to putIOTimerChanMode_PWMOut, it will fetch the timer which I have definied in timer_config.cpp and then initialise them.
io_timer_set_pwm_rate → modify the rARR register. Now I have a question for this one. I have seen that in the code there is this code written:
/* If the timer clock source provided as clock_freq is the STM32_APBx_TIMx_CLKIN
* then configure the timer to free-run at 1MHz.
* Otherwise, other frequencies are attainable by adjusting .clock_freq accordingly.
* For instance .clock_freq = 1000000 would set the prescaler to 1.
* We also allow for overrides here but all timer register usage need to be
* taken into account
*/
#if !defined(BOARD_PWM_FREQ)
#define BOARD_PWM_FREQ 10000
#endif
Seens my timer is using STM32_APB2_TIM16_CLKIN does that mean that I can’t change the freq ? With this setup I can only reach I max frequency of 1MHz since the rPSC register will have a value of 239, but in theory i could set prescaler to 0 right ?
io_timer_set_enable → Finale function which start the timer.
No need to dig into the code, simply need an overview of am I looking for the right functions/strategy or am I complety off ? I have called all this function in the stm32_boardinitialize function in init.cpp I have no way to test my code since I can’t find the error handler to set up a LED to know when I am in. Have you any tips to test my program? Thank you in advance!