2024-11-20 12:11 AM - last edited on 2024-11-20 12:41 AM by Andrew Neil
"In the STM32U5, the LPTimer is used to periodically wake up from Stop 2 mode to sample ADC data. After the ADC samples the data via DMA and generates an interrupt, the system re-enters Stop 2 mode. When using a debugger, the sampled data is normal. However, when the device is running, the sampled data is not correct.
2024-11-20 12:16 AM
ADC:
2024-11-20 12:45 AM
Please see the posting tips for how to properly post source code; also details needed - what board, etc:
@lsc wrote:When using a debugger, the sampled data is normal. However, when the device is running, the sampled data is not correct.
In what way, "not correct" ?
One key difference when running under debug is that the target probably doesn't actually enter the STOP mode...
2024-11-20 12:51 AM
Below is the ADC configuration. After being awakened from Stop 2 mode by the LPTimer, the ADC data sampling results are higher than expected
ADC:
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc1.Init.Resolution = ADC_RESOLUTION_14B;
hadc1.Init.GainCompensation = 0;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 2;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = ENABLE;
hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR;
hadc1.Init.OversamplingMode = ENABLE;
hadc1.Init.Oversampling.Ratio = 3;
hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_NONE;
hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
hadc1.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_9;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_20CYCLES;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_10;
sConfig.Rank = ADC_REGULAR_RANK_2;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
2024-11-20 01:05 AM
Still missing details - What chip, what board, etc:
Show the code where you handle going into & coming out of STOP.
2024-11-20 01:41 AM
Main function and LPTimer handling: After the ADC sampling is completed via DMA and generates an interrupt, the system enters Stop 2 mode
main()
{
if(g_SystemFRAM.EnterLpFlag.Lpm == ENTER_STOP2_MODE)
{
/* enter stop2 mode */
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
}
}
//ADC+DMA
void Interrupt_DmaTc(void)
{
/* Check whether DMA transfer complete caused the DMA interruption */
g_SystemFRAM.EnterLpFlag.Lpm = ENTER_STOP2_MODE;
}
//lptime
void Interrupt_LpTime(void)
{
g_SystemFRAM.ADData.Current[Wp] = g_SystemFRAM.ADData.ADCxConvertedValues[2];
g_SystemFRAM.ADData.Electric[Wp] = g_SystemFRAM.ADData.ADCxConvertedValues[1];
if((g_SystemFRAM.ADData.Current[Wp] == 0) ||
HAL_ADC_Start(&hadc1);
}