1#include "../../../hardware_api.h"
4#include "../../../../common/foc_utils.h"
5#include "../../../../drivers/hardware_api.h"
6#include "../../../../drivers/hardware_specific/stm32/stm32_mcu.h"
7#include "../../../hardware_api.h"
8#include "../stm32_adc_utils.h"
9#include "../stm32_mcu.h"
13#define _ADC_VOLTAGE_F1 3.3f
14#define _ADC_RESOLUTION_F1 4096.0f
17uint32_t adc_val[5][4]={0};
19#ifdef SIMPLEFOC_STM32_ADC_INTERRUPT
20#define USE_ADC_INTERRUPT 1
22#define USE_ADC_INTERRUPT 0
26Stm32AdcInterruptConfig adc_interrupt_config[5] = {
27 {0, 0, USE_ADC_INTERRUPT},
28 {0, 0, USE_ADC_INTERRUPT},
29 {0, 0, USE_ADC_INTERRUPT},
30 {0, 0, USE_ADC_INTERRUPT},
31 {0, 0, USE_ADC_INTERRUPT}
37 Stm32CurrentSenseParams*
cs_params=
new Stm32CurrentSenseParams {
39 .adc_voltage_conv = (_ADC_VOLTAGE_F1) / (_ADC_RESOLUTION_F1)
48 STM32DriverParams* driver_params = (STM32DriverParams*)_driver_params;
49 Stm32CurrentSenseParams*
cs_params = (Stm32CurrentSenseParams*)_cs_params;
55 stm32_pause(driver_params);
58 int adc_index = _adcToIndex(
cs_params->adc_handle);
60 bool tim_interrupt = _initTimerInterruptDownsampling(
cs_params, driver_params, adc_interrupt_config[adc_index]);
63 SIMPLEFOC_DEBUG(
"STM32-CS: timer has no repetition counter, ADC interrupt has to be used");
67 LL_TIM_SetTriggerOutput(
cs_params->timer_handle->Instance, LL_TIM_TRGO_UPDATE);
70 HAL_ADCEx_Calibration_Start(
cs_params->adc_handle);
73 if(adc_interrupt_config[adc_index].use_adc_interrupt){
74 HAL_NVIC_SetPriority(ADC1_2_IRQn, 0, 0);
75 HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
77 HAL_ADCEx_InjectedStart_IT(
cs_params->adc_handle);
79 HAL_ADCEx_InjectedStart(
cs_params->adc_handle);
84 stm32_resume(driver_params);
95 uint8_t adc_index = (uint8_t)_adcToIndex(((Stm32CurrentSenseParams*)
cs_params)->adc_handle);
96 return _readADCInjectedChannelVoltage(pin, (
void*)
cs_params, adc_interrupt_config[adc_index], adc_val[adc_index]);
100 void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *AdcHandle){
101 uint8_t adc_index = (uint8_t)_adcToIndex(AdcHandle);
102 _handleInjectedConvCpltCallback(AdcHandle, adc_interrupt_config[adc_index], adc_val[adc_index]);
#define SIMPLEFOC_DEBUG(msg,...)
void * _driverSyncLowSide(void *driver_params, void *cs_params)
#define SIMPLEFOC_CURRENT_SENSE_INIT_FAILED
void * _configureADCLowSide(const void *driver_params, const int pinA, const int pinB, const int pinC=NOT_SET)
float _readADCVoltageLowSide(const int pinA, const void *cs_params)
const int const int const int pinC