2023-04-11 05:16 AM
Hi
I searched everywhere but I'm stuck with starting DMA after waking up STM32L053C6U6 from stop mode. Chip displays LCD content, goes to sleep, wakes up by external interrupt on pin, receives SPI data through DMA,sends few bytes at the same time, updates LCD and goes back to sleep. If I use DMA without going to sleep everything is fine, but not current draw obviously. Before I used normal transmit/receive blocking function it was all fine, but not transmission speed which I wanted to increase for shorter transmisisons periods. What I need is step by step what should be done in general. I know that I shell turn off DMA and restart it/initialize it again, but I tried everything, but like I said no clear guidlines anywhere. It's also unlcear what means turn off DMA and reinitialize it, because there are many things that can be turned off. Below callbacks I tried. Main loop is empty Any help will be appreciated
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
HAL_ResumeTick();
SystemClock_Config();
MX_DMA_Init();
HAL_SPI_DMAResume(&hspi1);
// __HAL_RCC_DMA1_CLK_ENABLE();
// __HAL_DMA_ENABLE(&hdma_spi1_rx);
// if (HAL_DMA_Init(&hdma_spi1_rx) != HAL_OK)
// {
// Error_Handler();
// }
//
// __HAL_LINKDMA(&hspi1, hdmarx, hdma_spi1_rx);
// __HAL_DMA_ENABLE(&hdma_spi1_rx);
////
// if (HAL_DMA_Init(&hdma_spi1_tx) != HAL_OK)
// {
// Error_Handler();
// }
//
// __HAL_LINKDMA(&hspi1, hdmatx, hdma_spi1_tx);
// __HAL_DMA_ENABLE(&hdma_spi1_tx);
HAL_SPI_TransmitReceive_DMA(&hspi1, SPI_version_buf, SPI_receive_buf, 9);
}
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
{
lcd_update();
HAL_SPI_DMAStop(hspi);
// HAL_DMA_DeInit(&hdma_spi1_rx);
// HAL_DMA_DeInit(&hdma_spi1_tx);
// __HAL_DMA_DISABLE(&hdma_spi1_rx);
// __HAL_DMA_DISABLE(&hdma_spi1_tx);
// __HAL_RCC_DMA1_CLK_DISABLE();
HAL_SuspendTick();
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); //clear flag after stop mode
//
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); //enter stop mode
}