Skip to main content
Associate
November 10, 2025
Question

About STMCWB ADC issue

  • November 10, 2025
  • 3 replies
  • 194 views

I used MC_SDK_6.3.2 to generate a motor control program, but found that sometimes the motherboard crashes. Debugging found that the following code has problems. May I ask why this is? Is it a hardware bug?

//The problematic code is here, and the program will enter a dead loop: 

while (LL_ADC_IsActiveFlag_EOCS(RCM_handle_array[handle]->regADC) == 0u)
{
 /* Nothing to do */
}

The complete code is as follows:

uint16_t RCM_ExecRegularConv (RegConv_t *regConv)
{
 uint16_t retVal;
 uint8_t handle = regConv->convHandle;
 LL_ADC_REG_SetSequencerRanks(RCM_handle_array[handle]->regADC,
 LL_ADC_REG_RANK_1,
 __LL_ADC_DECIMAL_NB_TO_CHANNEL(RCM_handle_array[handle]->channel));

 (void)LL_ADC_REG_ReadConversionData12L(RCM_handle_array[handle]->regADC);
 /* Bit banding access equivalent to LL_ADC_REG_StartConversionSWStart */
 BB_REG_BIT_SET(&RCM_handle_array[handle]->regADC->CR2, ADC_CR2_SWSTART_Pos);
 /* Wait until end of regular conversion */
 while (LL_ADC_IsActiveFlag_EOCS(RCM_handle_array[handle]->regADC) == 0u)
 {
 /* Nothing to do */
 }
 retVal = LL_ADC_REG_ReadConversionData12L(RCM_handle_array[handle]->regADC);
 return (retVal);
}

3 replies

GMA
Technical Moderator
November 12, 2025

Hello @Longhua,

Can you add the references for the boards used?
Is it a generated firmware or a custom firmware?
What is the use case to reproduce the issue?

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

It's a board I designed myself, and the FOC driver looks normal, but sometimes it enters this dead loop(as shown below). I don't know the reason, because i just  adding a CAN interface in the automatically generated firmware. Does it look like an ADC conversion error? But I'm not sure why the conversion error occurred. This error occurred randomly, and I did not find any patterns in it.

 

 /* Wait until end of regular conversion */
 while (LL_ADC_IsActiveFlag_EOCS(RCM_handle_array[handle]->regADC) == 0u)
 {
 /* Nothing to do */
 }

 

Ozone
Principal
November 24, 2025

This is not a "dead loop", but a loop waiting for the EOS flag of the ADC set.
Depending on your ADC configuration, errors (like overruns) might stop it.

> I don't know the reason, because i just  adding a CAN interface in the automatically generated firmware.

I suspect your code wastes too much time in interrupt context, blocking other interrupts  and causing overflows.


Motor control runs on short control cycles.
It is almost mandatory to use DMA for ADCs in this context.
Just saying ...

LonghuaAuthor
Associate
November 24, 2025

"Motor control runs on short control cycles.It is almost mandatory to use DMA for ADCs in this context.“

But this code is automatically generated by STMCWB.

The attachment is the IOC file.

Ozone
Principal
November 24, 2025

You see ?
This is why it still needs software engineers.