cancel
Showing results for 
Search instead for 
Did you mean: 

DMA Interrupt

arastolga8
Associate II
Posted on April 26, 2016 at 13:13

Hi

I have a problem with the DMA Interrupt on a nucleo stm32f4 Everytime the Nucleo goes into an Infinite_Loop

1.
.section .text.Default_Handler,
''ax''
,%progbits
2.
Default_Handler:
3.
Infinite_Loop:
4.
b Infinite_Loop
5.
.size Default_Handler, .-Default_Handler

my main.cpp is this one:


#include ''mbed.h''

#include ''globals.h''

UART_HandleTypeDef huart2;

DMA_HandleTypeDef hdma_usart2_tx;

void DMA1_Stream6_IRQHandler(void);


void
SystemClock_Config(
void
);

static
void
MX_GPIO_Init(
void
);

static
void
MX_DMA_Init(
void
);


void
test(DMA_HandleTypeDef* dma){

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5,GPIO_PIN_RESET);

char
buffer[] =
''12345678901234567890123456789000000''
;

HAL_DMA_Start_IT(&hdma_usart2_tx, (uint32_t) &buffer, (uint32_t)&(USART2->DR),
sizeof
(buffer));

USART2->CR3 |= USART_CR3_DMAT;

}


void
HAL_UART_MspInit(UART_HandleTypeDef* huart)

{


GPIO_InitTypeDef GPIO_InitStruct;

if
(huart->Instance==USART2)

{

/* USER CODE BEGIN USART2_MspInit 0 */


/* USER CODE END USART2_MspInit 0 */

/* Peripheral clock enable */

__USART2_CLK_ENABLE();


/**USART2 GPIO Configuration

PA2 ------> USART2_TX

PA3 ------> USART2_RX

*/

GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_PULLUP;

GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

GPIO_InitStruct.Alternate = GPIO_AF7_USART2;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);


/* Peripheral DMA init*/

hdma_usart2_tx.Instance = DMA1_Stream6;

hdma_usart2_tx.Init.Channel = DMA_CHANNEL_4;

hdma_usart2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;

hdma_usart2_tx.Init.PeriphInc = DMA_PINC_DISABLE;

hdma_usart2_tx.Init.MemInc = DMA_MINC_ENABLE;

hdma_usart2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;

hdma_usart2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;

hdma_usart2_tx.Init.Mode = DMA_NORMAL;

hdma_usart2_tx.Init.Priority = DMA_PRIORITY_LOW;

hdma_usart2_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;

hdma_usart2_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;

hdma_usart2_tx.Init.MemBurst = DMA_MBURST_SINGLE;

hdma_usart2_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;

hdma_usart2_tx.XferCpltCallback = test;

HAL_DMA_Init(&hdma_usart2_tx);


__HAL_LINKDMA(huart,hdmatx,hdma_usart2_tx);


/* USER CODE BEGIN USART2_MspInit 1 */


/* USER CODE END USART2_MspInit 1 */

}


}


void
MX_USART2_UART_Init(
void
)

{


huart2.Instance = USART2;

huart2.Init.BaudRate = 115200;

huart2.Init.WordLength = UART_WORDLENGTH_8B;

huart2.Init.StopBits = UART_STOPBITS_1;

huart2.Init.Parity = UART_PARITY_NONE;

huart2.Init.Mode = UART_MODE_TX_RX;

huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;

huart2.Init.OverSampling = UART_OVERSAMPLING_16;

HAL_UART_Init(&huart2);

}



int
main() {

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();


/* Initialize all configured peripherals */

MX_GPIO_Init();

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5, GPIO_PIN_SET);

MX_DMA_Init();

MX_USART2_UART_Init();

char
buffer[] =
''12345678901234567890123456789000000''
;

HAL_DMA_Start_IT(&hdma_usart2_tx, (uint32_t) &buffer, (uint32_t) &(USART2->DR),
sizeof
(buffer));

USART2->CR3 |= USART_CR3_DMAT;


while
(1){}

}
void DMA1_Stream6_IRQHandler(void)
{
 /* USER CODE BEGIN DMA1_Stream6_IRQn 0 */
 HAL_NVIC_ClearPendingIRQ(DMA1_Stream6_IRQn);
 /* USER CODE END DMA1_Stream6_IRQn 0 */
 HAL_DMA_IRQHandler(&hdma_usart2_tx);
 /* USER CODE BEGIN DMA1_Stream6_IRQn 1 */

 /* USER CODE END DMA1_Stream6_IRQn 1 */
}

#stm32 #dma #interrupt #handler
1 REPLY 1
torsten2
Associate II
Posted on April 26, 2016 at 13:29

As you named your file main.cpp, your compiler will most likely interpret the source code as C++ code and not as C code. When the linker put together the interrupt vector table, it looks for functions with specific names, but most C++ compilers emit different function names (to implement function overloading) and even might have different ABIs.

To make a long story short. Use a C compiler, or force that functions that have to have C binding to have C binding by declaring them as `extern ''C''`:

  extern ''C'' 

void DMA1_Stream6_IRQHandler(void)

cheers,

Torsten