Hello everybody,
I want to start a conversion on SDADC1 on an external trigger from TIM1_CH1 and use DMA2_CH3 to store the samples on SRAM.
fs = 1 kHz
buffer size = 2000
I want to toggle a led when the half transfer interrupt and the complete trasfer interrupt, from the DMA, are sets, but the led isn't blinking.
I did the debug and apparently the code write correctly on the registers. Could someone help me?
main
#include "stm32f3xx_hal.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
SDADC_HandleTypeDef hsdadc1;
DMA_HandleTypeDef hdma_sdadc1;
TIM_HandleTypeDef htim3;
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
static uint32_t aDST_Buffer[2000];
GPIO_InitTypeDef GPIO_InitStruct;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
//static void MX_TIM3_Init(void);
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
static void SDADC1_Init(void);
static void GPIO_Init(void);
static void DMA_Init(void);
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
/* USER CODE BEGIN 2 */
GPIO_Init();
DMA_Init();
SDADC1_Init();
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_15, GPIO_PIN_SET);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/** System Clock Configuration
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SDADC;
PeriphClkInit.SdadcClockSelection = RCC_SDADCSYSCLK_DIV12;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
HAL_PWREx_EnableSDADCAnalog(PWR_SDADC_ANALOG1);
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
HAL_RCC_MCOConfig(RCC_MCO, RCC_MCOSOURCE_SYSCLK, RCC_MCO_NODIV);
}
/* USER CODE BEGIN 4 */
/** Configure pins as **********************************************************
* Analog
* Input
* Output
* EVENT_OUT
* EXTI
*/
void GPIO_Init(void)
{
/* GPIO Ports Clock Enable */
__GPIOA_CLK_ENABLE();
__GPIOE_CLK_ENABLE();
GPIO_InitStruct.Pin = (GPIO_PIN_9 | GPIO_PIN_15);
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
}
/*******************************************************************************
* Enable DMA controller clock
*/
void DMA_Init(void)
{
/* DMA controller clock enable */
__DMA2_CLK_ENABLE();
/* Set Interrupt Group Priority */
HAL_NVIC_SetPriority(DMA2_Channel3_IRQn, 0, 0);
/* Enable the DMA global Interrupt */
HAL_NVIC_EnableIRQ(DMA2_Channel3_IRQn);
}
/* SDADC1 init function ***************************************************/
void SDADC1_Init(void)
{
SDADC_ConfParamTypeDef ConfParamStruct;
/**Configure the SDADC low power mode, fast conversion mode,
slow clock mode and SDADC1 reference voltage
*/
hsdadc1.Instance = SDADC1;
hsdadc1.Init.IdleLowPowerMode = SDADC_LOWPOWER_NONE;
hsdadc1.Init.FastConversionMode = SDADC_FAST_CONV_DISABLE;
hsdadc1.Init.SlowClockMode = SDADC_SLOW_CLOCK_DISABLE;
hsdadc1.Init.ReferenceVoltage = SDADC_VREF_EXT;
HAL_SDADC_Init(&hsdadc1);
/**Set parameters for SDADC configuration 0 Register
*/
ConfParamStruct.InputMode = SDADC_INPUT_MODE_SE_ZERO_REFERENCE;
ConfParamStruct.Gain = SDADC_GAIN_1;
ConfParamStruct.CommonMode = SDADC_COMMON_MODE_VSSA;
ConfParamStruct.Offset = 0;
HAL_SDADC_PrepareChannelConfig(&hsdadc1, SDADC_CONF_INDEX_0, &ConfParamStruct);
/**Set parameters for SDADC configuration 1 Register
*/
//HAL_SDADC_PrepareChannelConfig(&hsdadc1, SDADC_CONF_INDEX_1, &ConfParamStruct);
/**Set parameters for SDADC configuration 2 Register
*/
//HAL_SDADC_PrepareChannelConfig(&hsdadc1, SDADC_CONF_INDEX_2, &ConfParamStruct);
// associate channel 0 to the configuration 0
HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_0, SDADC_CONF_INDEX_0);
// channel 0 for injected conversion and not for continuous mode
HAL_SDADC_InjectedConfigChannel(&hsdadc1, SDADC_CHANNEL_0, SDADC_CONTINUOUS_CONV_OFF);
// select external trigger for injected conversion
HAL_SDADC_SelectInjectedTrigger(&hsdadc1, SDADC_EXTERNAL_TRIGGER);
// select timer 3 channel 1 as external trigger and falling edge
HAL_SDADC_SelectInjectedExtTrigger(&hsdadc1, SDADC_EXT_TRIG_TIM13_CC1, SDADC_EXT_TRIG_FALLING_EDGE);
// Start calibration in polling mode
HAL_SDADC_CalibrationStart(&hsdadc1, SDADC_CALIBRATION_SEQ_1);
// pool for end of calibration
HAL_SDADC_PollForCalibEvent(&hsdadc1, HAL_MAX_DELAY);
// start injected conversion in DMA mode
HAL_SDADC_InjectedStart_DMA(&hsdadc1, aDST_Buffer, 2000);
// start the timer'2 channel
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
}
// Gestione dell'interrupt di Half transfer del DMA ****************************
void HalfTransfer(DMA_HandleTypeDef *hsadc1)
{
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_15, GPIO_PIN_RESET);
}
// gestione dell'interrupt di trasferimento completo del DMA
void TransferComplete(DMA_HandleTypeDef *hsadc1)
{
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_15, GPIO_PIN_SET);
}
// gestione dell'interrupt di error del DMA
void TransferError(DMA_HandleTypeDef *hsadc1)
{
HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_9);
}
/* USER CODE END 4 */
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif
/**
* @}
*/
/**
* @}
*/
stm32f3xx_hal_msp
#include "stm32f3xx_hal.h"
extern DMA_HandleTypeDef hdma_sdadc1;
extern TIM_HandleTypeDef htim3;
/* USER CODE BEGIN 0 */
void HalfTransfer(DMA_HandleTypeDef *hsadc1);
void TransferComplete(DMA_HandleTypeDef *hsadc1);
void TransferError(DMA_HandleTypeDef *hsadc1);
/* USER CODE END 0 */
/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
__SYSCFG_CLK_ENABLE();
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
/* System interrupt init*/
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
void HAL_SDADC_MspInit(SDADC_HandleTypeDef* hsdadc)
{
GPIO_InitTypeDef GPIO_InitStruct;
if(hsdadc->Instance==SDADC1)
{
/* USER CODE BEGIN SDADC1_MspInit 0 */
//HAL_PWREx_EnableSDADCAnalog(PWR_SDADC_ANALOG1);
/* USER CODE END SDADC1_MspInit 0 */
/* Peripheral clock enable */
__SDADC1_CLK_ENABLE();
/**SDADC1 GPIO Configuration
PE12 ------> SDADC1_AIN0P
*/
GPIO_InitStruct.Pin = GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/* USER CODE BEGIN SDADC1_MspInit 1 */
/* Peripheral DMA init*/
hdma_sdadc1.Instance = DMA2_Channel3;
hdma_sdadc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_sdadc1.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_sdadc1.Init.MemInc = DMA_MINC_ENABLE;
hdma_sdadc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_sdadc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_sdadc1.Init.Mode = DMA_CIRCULAR;
hdma_sdadc1.Init.Priority = DMA_PRIORITY_HIGH;
/* Select Callbacks functions called after Half complete, Transfer complete and Transfer error */
hdma_sdadc1.XferCpltCallback = TransferComplete;
hdma_sdadc1.XferErrorCallback = TransferError;
hdma_sdadc1.XferHalfCpltCallback = HalfTransfer;
HAL_DMA_Init(&hdma_sdadc1);
__HAL_LINKDMA(hsdadc,hdma,hdma_sdadc1);
// HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
/**TIM3_CH1 GPIO Configuration
PA6
*/
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// peripheral TIM3 init
TIM_ClockConfigTypeDef sClockSourceConfig;
TIM_MasterConfigTypeDef sMasterConfig;
TIM_OC_InitTypeDef sConfigOC;
htim3.Instance = TIM3;
htim3.Init.Prescaler = 11;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 5999;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_Base_Init(&htim3);
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig);
HAL_TIM_PWM_Init(&htim3);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig);
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 3000;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1);
/* USER CODE END SDADC1_MspInit 1 */
}
}
void HAL_SDADC_MspDeInit(SDADC_HandleTypeDef* hsdadc)
{
if(hsdadc->Instance==SDADC1)
{
/* USER CODE BEGIN SDADC1_MspDeInit 0 */
/* USER CODE END SDADC1_MspDeInit 0 */
/* Peripheral clock disable */
__SDADC1_CLK_DISABLE();
/**SDADC1 GPIO Configuration
PE12 ------> SDADC1_AIN0P
*/
HAL_GPIO_DeInit(GPIOE, GPIO_PIN_12);
/* Peripheral DMA DeInit*/
HAL_DMA_DeInit(hsdadc->hdma);
}
/* USER CODE BEGIN SDADC1_MspDeInit 1 */
// TIM3 deInit
HAL_TIM_PWM_DeInit(&htim3);
/* USER CODE END SDADC1_MspDeInit 1 */
}
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
{
GPIO_InitTypeDef GPIO_InitStruct;
if(htim_base->Instance==TIM3)
{
/* USER CODE BEGIN TIM3_MspInit 0 */
/* USER CODE END TIM3_MspInit 0 */
/* Peripheral clock enable */
__TIM3_CLK_ENABLE();
/**TIM3 GPIO Configuration
PA6 ------> TIM3_CH1
*/
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USER CODE BEGIN TIM3_MspInit 1 */
/* USER CODE END TIM3_MspInit 1 */
}
}
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
{
if(htim_base->Instance==TIM3)
{
/* USER CODE BEGIN TIM3_MspDeInit 0 */
/* USER CODE END TIM3_MspDeInit 0 */
/* Peripheral clock disable */
__TIM3_CLK_DISABLE();
/**TIM3 GPIO Configuration
PA6 ------> TIM3_CH1
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6);
}
/* USER CODE BEGIN TIM3_MspDeInit 1 */
/* USER CODE END TIM3_MspDeInit 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/**
* @}
*/
/**
* @}
*/
stm32f3xx_it.c
#include "stm32f3xx_hal.h"
#include "stm32f3xx.h"
#include "stm32f3xx_it.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
extern DMA_HandleTypeDef hdma_sdadc1;
/******************************************************************************/
/* Cortex-M4 Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
HAL_SYSTICK_IRQHandler();
/* USER CODE BEGIN SysTick_IRQn 1 */
/* USER CODE END SysTick_IRQn 1 */
}
/******************************************************************************/
/* STM32F3xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32f3xx.s). */
/******************************************************************************/
/**
* @brief This function handles DMA2 channel3 global interrupt.
*/
void DMA2_Channel3_IRQHandler(void)
{
/* USER CODE BEGIN DMA2_Channel3_IRQn 0 */
/* USER CODE END DMA2_Channel3_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_sdadc1);
/* USER CODE BEGIN DMA2_Channel3_IRQn 1 */
/* USER CODE END DMA2_Channel3_IRQn 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
I known...it's a lot of code, but I need some input
Regards,