From 7e1e85124be26cdc5aeb5dbd348f64d2b8cb4f12 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 31 May 2013 23:32:26 +0000 Subject: [PATCH] DMA interrupts interrupting git-svn-id: https://svn.code.sf.net/p/freetel/code@1301 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/stm32/Makefile | 10 +- codec2-dev/stm32/inc/{dac_ut.h => dac_it.h} | 52 +++--- codec2-dev/stm32/src/dac_it.c | 188 ++++++++++++++++++++ codec2-dev/stm32/src/dac_ut.c | 12 ++ 4 files changed, 228 insertions(+), 34 deletions(-) rename codec2-dev/stm32/inc/{dac_ut.h => dac_it.h} (69%) create mode 100644 codec2-dev/stm32/src/dac_it.c diff --git a/codec2-dev/stm32/Makefile b/codec2-dev/stm32/Makefile index cc431558..9befea45 100644 --- a/codec2-dev/stm32/Makefile +++ b/codec2-dev/stm32/Makefile @@ -14,7 +14,7 @@ SIZE=$(BINPATH)/arm-none-eabi-size ################################################### -CFLAGS = -std=gnu99 -g -O2 -Wall -Tstm32_flash.ld -DSTM32F4XX -DCORTEX_M4 +CFLAGS = -std=gnu99 -O2 -g -Wall -Tstm32_flash.ld -DSTM32F4XX -DCORTEX_M4 CFLAGS += -mlittle-endian -mthumb -mthumb-interwork -nostartfiles -mcpu=cortex-m4 ifeq ($(FLOAT_TYPE), hard) @@ -132,19 +132,15 @@ $(PROJ_NAME).elf: $(SRCS) fft_test.elf: $(FFT_TEST_SRCS) $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS) -DAC_TEST=$(PERIPHLIBDIR)/Project/STM32F4xx_StdPeriph_Examples/DAC/DAC_SignalsGeneration DAC_TEST_SRCS=\ src/dac_ut.c \ +src/dac_it.c \ src/system_stm32f4xx.c \ src/startup_stm32f4xx.s \ src/init.c -#$(DAC_TEST)/stm32f4xx_it.c \ -#$(DAC_TEST)/system_stm32f4xx.c \ -#(PERIPHLIBDIR)/Utilities/STM32_EVAL/STM3240_41_G_EVAL/stm324xg_eval.c \ - dac_ut.elf: $(DAC_TEST_SRCS) - $(CC) $(CFLAGS) -DUSE_STM324xG_EVAL -I$(PERIPHLIBDIR)/Utilities/STM32_EVAL/STM3240_41_G_EVAL -I$(PERIPHLIBDIR)/Utilities/STM32_EVAL/Common $^ -o $@ $(LIBPATHS) $(LIBS) + $(CC) $(CFLAGS) -O0 $^ -o $@ $(LIBPATHS) $(LIBS) clean: rm -f *.o diff --git a/codec2-dev/stm32/inc/dac_ut.h b/codec2-dev/stm32/inc/dac_it.h similarity index 69% rename from codec2-dev/stm32/inc/dac_ut.h rename to codec2-dev/stm32/inc/dac_it.h index b235e56c..e935feab 100644 --- a/codec2-dev/stm32/inc/dac_ut.h +++ b/codec2-dev/stm32/inc/dac_it.h @@ -1,10 +1,10 @@ /** ****************************************************************************** - * @file DAC/DAC_SignalsGeneration/main.h + * @file DMA/DMA_FLASHToRAM/stm32f4xx_it.h * @author MCD Application Team * @version V1.1.0 * @date 18-January-2013 - * @brief Header for main.c module + * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * @@ -24,40 +24,38 @@ * ****************************************************************************** */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __MAIN_H -#define __MAIN_H - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx.h" -#if defined (USE_STM324xG_EVAL) - #include "stm324xg_eval.h" +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F4xx_IT_H +#define __STM32F4xx_IT_H -#elif defined (USE_STM324x7I_EVAL) - #include "stm324x7i_eval.h" +#ifdef __cplusplus + extern "C" { +#endif -#else - #error "Please select first the Evaluation board used in your application (in Project Options)" -#endif +/* Includes ------------------------------------------------------------------*/ +#include "stm32f4xx_dma.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ -#if defined (USE_STM324xG_EVAL) - - #define DAC_DHR12R2_ADDRESS 0x40007414 - #define DAC_DHR8R1_ADDRESS 0x40007410 - -#else /* defined (USE_STM324x7I_EVAL)*/ - - #define DAC_DHR12R2_ADDRESS 0x40007414 - #define DAC_DHR8R1_ADDRESS 0x40007410 +/* Exported functions ------------------------------------------------------- */ +void NMI_Handler(void); +void HardFault_Handler(void); +void MemManage_Handler(void); +void BusFault_Handler(void); +void UsageFault_Handler(void); +void SVC_Handler(void); +void DebugMon_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void DMA_STREAM_IRQHANDLER(void); + +#ifdef __cplusplus +} #endif -/* Exported functions ------------------------------------------------------- */ -#endif /* __MAIN_H */ +#endif /* __STM32F4xx_IT_H */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/src/dac_it.c b/codec2-dev/stm32/src/dac_it.c new file mode 100644 index 00000000..3d671ca8 --- /dev/null +++ b/codec2-dev/stm32/src/dac_it.c @@ -0,0 +1,188 @@ +/** + ****************************************************************************** + * @file DMA/DMA_FLASHToRAM/stm32f4xx_it.c + * @author MCD Application Team + * @version V1.1.0 + * @date 18-January-2013 + * @brief Main Interrupt Service Routines. + * This file provides template for all exceptions handler and + * peripherals interrupt service routine. + ****************************************************************************** + * @attention + * + *

© COPYRIGHT 2013 STMicroelectronics

+ * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ +int interrupts; + + +/* Includes ------------------------------------------------------------------*/ +#include "dac_it.h" + +/** @addtogroup STM32F4xx_StdPeriph_Examples + * @{ + */ + +/** @addtogroup DMA_FLASHToRAM + * @{ + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/******************************************************************************/ +/* Cortex-M4 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + * @param None + * @retval None + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + * @param None + * @retval None + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles Memory Manage exception. + * @param None + * @retval None + */ +void MemManage_Handler(void) +{ + /* Go to infinite loop when Memory Manage exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles Bus Fault exception. + * @param None + * @retval None + */ +void BusFault_Handler(void) +{ + /* Go to infinite loop when Bus Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles Usage Fault exception. + * @param None + * @retval None + */ +void UsageFault_Handler(void) +{ + /* Go to infinite loop when Usage Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + * @param None + * @retval None + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles Debug Monitor exception. + * @param None + * @retval None + */ +void DebugMon_Handler(void) +{ +} + +/** + * @brief This function handles PendSVC exception. + * @param None + * @retval None + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + * @param None + * @retval None + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* STM32F4xx Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_stm32f40xx.s/startup_stm32f427x.s). */ +/******************************************************************************/ + +/** + * @brief This function handles DMA Stream interrupt request. + * @param None + * @retval None + */ +void DMA1_Stream6_IRQHandler(void) +{ + /* Test on DMA Stream Transfer Complete interrupt */ + if(DMA_GetITStatus(DMA1_Stream6, DMA_IT_HTIF6)) + { + /* Clear DMA Stream Transfer Complete interrupt pending bit */ + DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_HTIF6); + interrupts++; + } + if(DMA_GetITStatus(DMA1_Stream6, DMA_IT_TCIF6)) + { + /* Clear DMA Stream Transfer Complete interrupt pending bit */ + DMA_ClearITPendingBit(DMA1_Stream6, DMA_IT_TCIF6); + interrupts++; + } +} + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/codec2-dev/stm32/src/dac_ut.c b/codec2-dev/stm32/src/dac_ut.c index 72849177..c0d0f7c5 100644 --- a/codec2-dev/stm32/src/dac_ut.c +++ b/codec2-dev/stm32/src/dac_ut.c @@ -156,6 +156,7 @@ static void TIM6_Config(void) static void DAC_Ch2_SineWaveConfig(void) { DMA_InitTypeDef DMA_InitStructure; + NVIC_InitTypeDef NVIC_InitStructure; /* DAC channel2 Configuration */ DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO; @@ -182,6 +183,17 @@ static void DAC_Ch2_SineWaveConfig(void) DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(DMA1_Stream6, &DMA_InitStructure); + /* Enable DMA Half 7 Complete interrupts */ + DMA_ITConfig(DMA1_Stream6, DMA_IT_TC | DMA_IT_HT, ENABLE); + + /* Enable the DMA Stream IRQ Channel */ + + NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream6_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + /* Enable DMA1_Stream6 */ DMA_Cmd(DMA1_Stream6, ENABLE); -- 2.25.1