#include "main.h" #include "BSP_ADC.h" #include "adc.h" #include "stdbool.h" #define ADC_CONVERTED_DATA_BUFFER_SIZE ((uint32_t) 16) /* Size of array aADCxConvertedData[] */ ALIGN_32BYTES (static uint16_t aADCxConvertedData[ADC_CONVERTED_DATA_BUFFER_SIZE]); static bool adcIsInitialized = false; //start the ADC conversion void BSP_ADC_Start() { if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED) != HAL_OK) { Error_Handler(); } if (HAL_ADC_Start_DMA(&hadc1, (uint32_t *)aADCxConvertedData, ADC_CONVERTED_DATA_BUFFER_SIZE ) != HAL_OK) { Error_Handler(); } adcIsInitialized = true; } /** * @brief Conversion complete callback in non-blocking mode * @param hadc: ADC handle * @retval None */ void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc) { /* Invalidate Data Cache to get the updated content of the SRAM on the first half of the ADC converted data buffer: 32 bytes */ SCB_InvalidateDCache_by_Addr((uint32_t *) &aADCxConvertedData[0], ADC_CONVERTED_DATA_BUFFER_SIZE); } /** * @brief Conversion DMA half-transfer callback in non-blocking mode * @param hadc: ADC handle * @retval None */ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) { /* Invalidate Data Cache to get the updated content of the SRAM on the second half of the ADC converted data buffer: 32 bytes */ SCB_InvalidateDCache_by_Addr((uint32_t *) &aADCxConvertedData[ADC_CONVERTED_DATA_BUFFER_SIZE/2], ADC_CONVERTED_DATA_BUFFER_SIZE); }