2016-09-20 12:49 PM
Hi,
I've been struggling to get interrupt for DMA working. I got it working for USART interrupt. I'm configuring for USART1 and DMA1_Channel5. My problem is that I don't get an interrupt for the DMA. So is there something I miss during the configuration? Regards main.cvoid USART1_IRQHandler(void)
{ } void DMA1_Channel5_IRQHandler(void) { // do something } main(void) { NVIC_SetPriorityGrouping(PRIORITY_GROUP); NVIC_SetPriority(DMA1_Channel5_IRQn, NVIC_EncodePriority(PRIORITY_GROUP, 1, 1)); // DMA NVIC_SetPriority(USART1_IRQn, NVIC_EncodePriority(PRIORITY_GROUP, 2, 0)); // USART1 NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(PRIORITY_GROUP, 2, 2)); // SysTick bsp_init(); while (1) { // just loop 4 ever :) } }bsp.c
void GPIO_Usart_1_Configuaration(void) { GPIO_InitTypeDef GPIO_InitStructure; // enable USART clocks RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // setup port A GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | // USART1_TX GPIO_Pin_10; // USART1_RX GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_7); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_7); GPIO_Init(GPIOA, &GPIO_InitStructure); // setup USART1 USART_InitTypeDef USART_InitStructure; USART_ClockInitTypeDef USART_ClockInitStructure; // setu up USART1_ClockInitStruct member with its default value USART_ClockStructInit(&USART_ClockInitStructure); USART_ClockInit(USART1, &USART_ClockInitStructure); USART_InitStructure.USART_BaudRate = BAUDRATE_9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART1, &USART_InitStructure); // enable DMA interface for RX USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE); // USART_CR3, 0x4001 3808 // enable USART1 port USART_Cmd(USART1, ENABLE); // enable CM, RXNE interrupt USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // enable USART1 global interrupt NVIC_EnableIRQ(USART1_IRQn); } void GPIO_Dma_1_Configuaration(void) { DMA_InitTypeDef DMA_InitStructure; // enable DMA clocks RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); /* DMA2 channel5 configuration */ DMA_DeInit(DMA1_Channel5); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART1->RDR; // DMA_CPAR, 0x4002 0060 DMA_InitStructure.DMA_MemoryBaseAddr = 0x00000000; // DMA_CMAR, 0x4002 0064 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = RX_BUFFER_SIZE; // DMA_CNDTR, 0x4002 005C DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; // DMA_CCR, 0x4002 0058 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel5, &DMA_InitStructure); // enable DMA interrupt NVIC_EnableIRQ(DMA1_Channel5_IRQn); // enable transfer complete interrupt DMA_ITConfig(DMA1_Channel5, DMA_IT_TC, ENABLE); // enable DMA1 channel5 DMA_Cmd(DMA1_Channel5, ENABLE); } // initialize clocks and GPIO ports void bsp_init(void) { GPIO_Usart_1_Configuaration(); GPIO_Dma_1_Configuaration(); } #stm322016-09-20 03:35 PM
Zero isn't going to be a viable buffer address here.
You should provide enough code for this to compile and be testable, a bunch of definitions missing.2016-09-21 12:00 AM
About the code, yes I just cut out what I thought was the important stuff.
Nevertheless I changed my buffer address to:DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)rx_buffer;
I have a declaration further up in the code:char rx_buffer[2];
And now I can see that I get a DMA interrupt. At least one step ahead. Thank You Clive1.