2026-04-22 1:01 AM - last edited on 2026-04-22 1:19 AM by Gyessine
Hello,
I configured a timer in STM32CubeMX2 to use 2 channels (HAL_TIM_CHANNEL_1 and HAL_TIM_CHANNEL_3). After the mx_system_init() I use the following code:
hal_tim_handle_t *htim5 = mx_tim5_gethandle();
if (HAL_TIM_OC_StartChannel(htim5, HAL_TIM_CHANNEL_1) != HAL_OK) {
return (-1);
}
if (HAL_TIM_OC_StartChannel(htim5, HAL_TIM_CHANNEL_3) != HAL_OK) {
return (-1);
}
if (HAL_TIM_Start(htim5) != HAL_OK) {
return (-1);
}
The first channel starts as expected, but when I attempt to start the second channel the code causes an assert in HAL_TIM_OC_StartChannel:
/* Check and update the channel state */
ASSERT_DBG_STATE(htim->channel_states[channel],
HAL_TIM_OC_CHANNEL_STATE_IDLE);
Do I need to do anything different?
Regards,
-Gil
Solved! Go to Solution.
2026-04-23 3:32 AM
Hello @gil_dobjanschi,
After testing, I realized I was mistaken: all the debug options in the screenshot above need to be enabled to generate the necessary functions for the application to work. I tested it with a logic analyzer and confirmed that it works. Attached, you will find the project.
Best regards,
2026-04-22 3:26 AM
Hello @gil_dobjanschi,
Let me check this out and get back to you ASAP.
Best regards,
2026-04-22 3:48 AM
Hello @gil_dobjanschi
Please, can you share the .ioc file or your example? I have tested it, and I noted that this line does not have any issue.
2026-04-22 3:52 AM
Hi @T_Hamdi ,
I attached the ioc2 file. Since I wrote the message I also enabled channel 4.
Thank you,
Gil
2026-04-22 4:08 AM
After inspecting the IOC, I believe you forgot to enable output channel CH3, just as you did with CH1. I suggest that you inspect the pwm_output HAL2 example in the software package.
2026-04-22 6:33 AM
Hi @STackPointer64 ,
In STM32CubeMx2 I enabled both channel 3 and channel 4. I attached the screenshots for the channel 3 and 4 configurations and I reattached the ioc2 just to make sure the mx2 configuration I'm looking at corresponds to the ioc2 file.
Thanks,
Gil
2026-04-22 7:15 AM
To resolve the issue, you need to enable Use default assert state function and
To resolve the issue, you need to enable Use default assert state function and Generate default assert parameter handler in the HAL System Init configuration. These options are required for the program to build and run successfully when the parameter assert option is enabled. Doing so adds the template implementations of the assert_dbg_param_failed and assert_dbg_state_failed functions in the mx_system.c source file.
2026-04-22 7:29 AM
Hi @STackPointer64 ,
Yes, I provided my own implementation of the assert functions which print the file name and line number where the assert occurs. This is how I learned where the assert occurs. My code builds without problems. When I run it and try to start channel 3 the problem occurs.
Regards.
-Gil
2026-04-22 8:07 AM
I commented out the asserts and I verified on the oscilloscope that channel 3 and 4 are working and outputting the expected waveform.
2026-04-23 3:32 AM
Hello @gil_dobjanschi,
After testing, I realized I was mistaken: all the debug options in the screenshot above need to be enabled to generate the necessary functions for the application to work. I tested it with a logic analyzer and confirmed that it works. Attached, you will find the project.
Best regards,