BSP ADC with DMA Circular

This commit is contained in:
2024-05-21 00:43:27 +02:00
parent a58079c3c0
commit 92c8624fe4
12 changed files with 206 additions and 18 deletions

56
Application/BSP/BSP_ADC.c Normal file
View File

@@ -0,0 +1,56 @@
#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);
}

10
Application/BSP/BSP_ADC.h Normal file
View File

@@ -0,0 +1,10 @@
void BSP_ADC_Start();
float BSP_ADC_ReadDimmerValue();
float BSP_ADC_ReadBusValue();

View File

@@ -9,6 +9,7 @@
#include "sdmmc.h"
#include "cmsis_os2.h"
#include "BSP_GPIO.h"
#include "BSP_ADC.h"
#define LPTIM_CLK 500 // Hz
#define SLEEP_TICK_TIME 1 // seconds to wait
@@ -126,4 +127,14 @@ void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim) {
}
}
}
}
void BSP_POWER_FullPowerMode() {
BSP_GPIO_ClsOn();
BSP_GPIO_PeriperalsOn();
BSP_ADC_Start();
}

View File

@@ -10,4 +10,7 @@ void BSP_POWER_Init();
void BSP_POWER_WakeUp();
void BSP_POWER_EnterStandby();
void BSP_POWER_EnterStandby();
void BSP_POWER_FullPowerMode();

View File

@@ -4,6 +4,7 @@ BSP_EE24.c
BSP_INA.c
BSP_POWER.c
BSP_GPIO.c
BSP_ADC.c
)
target_include_directories(BSP PUBLIC ./)