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_mcu.h"
9#include "../stm32_adc_utils.h"
14#define _ADC_VOLTAGE_F4 3.3f
15#define _ADC_RESOLUTION_F4 4096.0f
17#ifdef SIMPLEFOC_STM32_ADC_INTERRUPT
18#define USE_ADC_INTERRUPT 1
20#define USE_ADC_INTERRUPT 0
24uint32_t adc_val[5][4]={0};
27Stm32AdcInterruptConfig adc_interrupt_config[5] = {
28 {0, 0, USE_ADC_INTERRUPT},
29 {0, 0, USE_ADC_INTERRUPT},
30 {0, 0, USE_ADC_INTERRUPT},
31 {0, 0, USE_ADC_INTERRUPT},
32 {0, 0, USE_ADC_INTERRUPT}
37 Stm32CurrentSenseParams*
cs_params=
new Stm32CurrentSenseParams {
39 .adc_voltage_conv = (_ADC_VOLTAGE_F4) / (_ADC_RESOLUTION_F4)
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 if (adc_interrupt_config[adc_index].use_adc_interrupt){
72 HAL_NVIC_SetPriority(ADC_IRQn, 0, 0);
73 HAL_NVIC_EnableIRQ(ADC_IRQn);
75 HAL_ADCEx_InjectedStart_IT(
cs_params->adc_handle);
77 HAL_ADCEx_InjectedStart(
cs_params->adc_handle);
81 stm32_resume(driver_params);
92 uint8_t adc_index = (uint8_t)_adcToIndex(((Stm32CurrentSenseParams*)
cs_params)->adc_handle);
93 return _readADCInjectedChannelVoltage(pin, (
void*)
cs_params, adc_interrupt_config[adc_index], adc_val[adc_index]);
97 void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *AdcHandle){
98 uint8_t adc_index = (uint8_t)_adcToIndex(AdcHandle);
99 _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