cancel
Showing results for 
Search instead for 
Did you mean: 

Starting the second channel of a timer causes assert failure

gil_dobjanschi
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions

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.

STackPointer64_0-1776940302365.png

Best regards,

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.

View solution in original post

11 REPLIES 11
STackPointer64
ST Employee

Hello @gil_dobjanschi,

Let me check this out and get back to you ASAP.

Best regards,

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.
T_Hamdi
ST Employee

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.

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Hamdi Teyeb

Hi @T_Hamdi ,

 

I attached the ioc2 file. Since I wrote the message I also enabled channel 4.

Thank you,

Gil

STackPointer64
ST Employee

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.

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.

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

 

 

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.

STackPointer64_0-1776867081998.png

 

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.
gil_dobjanschi
Associate III

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

I commented out the asserts and I verified on the oscilloscope that channel 3 and 4 are working and outputting the expected waveform.

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.

STackPointer64_0-1776940302365.png

Best regards,

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.