2025-11-09 7:09 PM
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);
}
2025-11-12 8:38 AM
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?
2025-11-24 2:52 AM
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 */
}
2025-11-24 3:12 AM
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 ...
2025-11-24 3:48 AM
2025-11-24 4:09 AM
You see ?
This is why it still needs software engineers.