2025-09-11 10:08 PM - last edited on 2025-09-12 12:08 AM by mƎALLEm
This is to document various uses of delays like HAL_Delay() in STM32 code.
I have found 2 decent uses
1. Put at the start of /* USER CODE BEGIN 2 */ to stop the code from executing when we are reprogramming the board.
2. Put at the start of /* USER CODE BEGIN 2 */ to give time to properly initialize DMA related functionality.
/* USER CODE BEGIN 2 */
HAL_Delay(2000);
HAL_UARTEx_ReceiveToIdle_DMA( &huart7,
gsm_response_buffer,
GSM_RESPONSE_BUFFER_SIZE);
__HAL_DMA_DISABLE_IT(&hdma_uart7_rx, DMA_IT_HT);
/* USER CODE END 2 */
without the delay the DMA reception was not working.
Please put any other / any modification anyone find / know here to make it as a central repository.
Edited by ST moderator to be inline with the community rules especially with the code sharing. In next time please use </> button to paste your code. Please read this post: How to insert source code
2025-09-12 12:01 AM
Right,
but no need to wait so long time;
i have/need it, because attached LCD/TFT etc. needs some time to be ready to work , so:
....
MX_I2C1_Init();
MX_ADC1_Init();
/* USER CODE BEGIN 2 */
// live variables decaration maybe - must - be here !!!!
// initialise_monitor_handles();
HAL_Delay(50); // wait for LCD etc. power up ********************************
....
50...100 ms usually good value here.