cancel
Showing results for 
Search instead for 
Did you mean: 

PWM TIM update IRQ Crashing after upgrading to 6.4.1 ADC fails to synchronize ? Race condition ?

Muthanna
Associate III

During Startup,

after 

MX_NVIC_Init();


when it jumps into 

/* USER CODE BEGIN 2 */


The code is interrupted by 

TIMx_UP_M1_IRQHandler()

 

in its routine, 

(void)R3_2_TIMx_UP_IRQHandler(&PWM_Handle_M1);



the code gets stuck at

 
/* We can not change OPAMP source if ADC acquisition is ongoing (Dual motor with internal opamp use case) */

while (0x0u != pHandle->pParams_str->ADCDataReg1[pHandle->_Super.Sector]->JSQR)

{

/* Nothing to do */

}

I'm not able to understand why this is happening. I have not initialized any custom ADC (RCM) yet.
Everything that has run, until that point is generated code only.

With some research I have understood that the TIM1 update routine is infinitely waiting for the ADC(Injected Conversion) to finish. 
Is this some kind of race condition ?

This doesn't happen always on every boot/startup. Only randomly, some times. 
If it does not crash at this point, I have not observed it to crash at a later point of time.

Am I supposed to something differently in this version of sdk ?

At least, how can I work around this temporarily ?

I upgraded to 6.4.1 from 6.2.1 , and I started facing this.
ST 'SPIN' package G4 - custom board 
Single Motor Drive , 3 shunt config.
@cedric H @Fabrice LOUBEYRE 

1 ACCEPTED SOLUTION

Accepted Solutions

@GMA ,
I did try what you suggested. I still saw random occurrences of these crashes.

I spent some time trying to find out what's up. 

I found a workaround for this,

 
 LL_TIM_DisableCounter(TIM1);

 LL_TIM_ClearFlag_UPDATE(TIM1);

 LL_TIM_ClearFlag_CC1(TIM1);

 LL_TIM_ClearFlag_CC2(TIM1);

 LL_TIM_ClearFlag_CC3(TIM1);

 LL_TIM_ClearFlag_CC4(TIM1);

 NVIC_ClearPendingIRQ(TIM1_UP_TIM16_IRQn);



//probes

 tim_running = TIM1->CR1 & TIM_CR1_CEN;

 tim_uif = TIM1->SR & TIM_SR_UIF;

 adc1_jsqr = ADC1->JSQR;

 adc2_jsqr = ADC2->JSQR;

 adc1_busy = LL_ADC_IsActiveFlag_JEOS(ADC1);

Since the motor isn't running,
I disabled the timer, cleared flags, irq before enabling TIM1 IRQ
Then started the timer right after that.

 
// NVIC BLOCK
HAL_NVIC_SetPriority(TIM1_UP_TIM16_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn);

//Start Timer
LL_TIM_EnableCounter(TIM1);

I was able to start the MCU over and over without it crashing in the while(ADC->JSQR){} .

I understand this is not a solution. But I can carry on.
It probably needs a fix in the Middleware.

Thanks for your support, Looking forward to a proper solution.

View solution in original post

4 REPLIES 4
GMA
ST Employee

Hello @Muthanna,

Do you have a single or a dual drive configuration?

If you agree with the answer, please accept it by clicking on 'Accept as solution'.
Best regards.
GMA

Hello @GMA 
Single Drive Configuration.
My Design is almost identical to EVSPIN32G4 (3 shunt) only with use of the additional MCU pins

I will update the same in my question.

Thanks for your prompt response, looking forward to solve this with your help.

Here's running part of my main()

int main(void)
{

	/* USER CODE BEGIN 1 */

	/* USER CODE END 1 */

	/* MCU Configuration--------------------------------------------------------*/

	/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
	HAL_Init();

	/* USER CODE BEGIN Init */

	/* USER CODE END Init */

	/* Configure the system clock */
	SystemClock_Config();

	/* USER CODE BEGIN SysInit */

	/* USER CODE END SysInit */

	/* Initialize all configured peripherals */
	MX_GPIO_Init();
	MX_ADC1_Init();
	MX_ADC2_Init();
	MX_COMP1_Init();
	MX_COMP2_Init();
	MX_COMP4_Init();
	MX_CORDIC_Init();
	MX_DAC3_Init();
	MX_I2C3_Init();
	MX_OPAMP1_Init();
	MX_OPAMP2_Init();
	MX_TIM1_Init();
	MX_TIM4_Init();
	MX_MotorControl_Init();
	MX_I2C1_Init();
	MX_RTC_Init();
	MX_TIM2_Init();
	MX_TIM3_Init();

	/* Initialize interrupts */
	MX_NVIC_Init();
	/* USER CODE BEGIN 2 */
	HAL_Delay(10);            // <------ CRASHES HERE 



Hello @Muthanna,

Did you try using a default MCSDK project without adding I2C1/RTC/TIM2/TIM3 Ips?  

If you agree with the answer, please accept it by clicking on 'Accept as solution'.
Best regards.
GMA

@GMA ,
I did try what you suggested. I still saw random occurrences of these crashes.

I spent some time trying to find out what's up. 

I found a workaround for this,

 
 LL_TIM_DisableCounter(TIM1);

 LL_TIM_ClearFlag_UPDATE(TIM1);

 LL_TIM_ClearFlag_CC1(TIM1);

 LL_TIM_ClearFlag_CC2(TIM1);

 LL_TIM_ClearFlag_CC3(TIM1);

 LL_TIM_ClearFlag_CC4(TIM1);

 NVIC_ClearPendingIRQ(TIM1_UP_TIM16_IRQn);



//probes

 tim_running = TIM1->CR1 & TIM_CR1_CEN;

 tim_uif = TIM1->SR & TIM_SR_UIF;

 adc1_jsqr = ADC1->JSQR;

 adc2_jsqr = ADC2->JSQR;

 adc1_busy = LL_ADC_IsActiveFlag_JEOS(ADC1);

Since the motor isn't running,
I disabled the timer, cleared flags, irq before enabling TIM1 IRQ
Then started the timer right after that.

 
// NVIC BLOCK
HAL_NVIC_SetPriority(TIM1_UP_TIM16_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn);

//Start Timer
LL_TIM_EnableCounter(TIM1);

I was able to start the MCU over and over without it crashing in the while(ADC->JSQR){} .

I understand this is not a solution. But I can carry on.
It probably needs a fix in the Middleware.

Thanks for your support, Looking forward to a proper solution.