cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 HAL UART DMA Tx doesnt call Interrupt-Functions

Max Baeuml
Associate II
Posted on October 01, 2017 at 13:00

Hi @all

I would like to write a simple uart transmission using dma.

I see the transmitted data with a logic analyzer. All looks good.

But, Interrupt functions USART6_IRQHandler, DMA2_Stream7_IRQHandler, HAL_UART_TxCpltCallback, HAL_UART_TxHalfCpltCallback, doesn�t call.

If i suspend, the program ends every time in an infinite loop in file startup_stm32f446xx.s

I use a Nucleo F446RE

Can everybody help me?

Many thanks

Serial:

0690X00000608S7QAI.png

Infinite Loop:

0690X00000608SHQAY.png

Code:

&sharpinclude ''stm32f4xx.h''

&sharpinclude ''stm32f4xx_nucleo.h''

&sharpdefine BAUDRATE 115200

&sharpdefine TXPIN GPIO_PIN_6

&sharpdefine DATAPORT_TX GPIOC

UART_HandleTypeDef        huart1;

DMA_HandleTypeDef         hdma_usart1_tx;

int main(void)

{

         if( HAL_Init() != HAL_OK){

               for(;;);

         }

         

         //init GPIO

         __GPIOC_CLK_ENABLE();

         GPIO_InitTypeDef GPIO_InitStruct;

         GPIO_InitStruct.Pin = TXPIN;

         GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

         GPIO_InitStruct.Pull = GPIO_NOPULL;

         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

         GPIO_InitStruct.Alternate = GPIO_AF8_USART6;

         HAL_GPIO_Init(DATAPORT_TX, &GPIO_InitStruct);

         //init UART

         __USART6_CLK_ENABLE();

         huart1.Instance = USART6;

         huart1.Init.BaudRate = BAUDRATE;

         huart1.Init.WordLength = UART_WORDLENGTH_8B;

         huart1.Init.StopBits = UART_STOPBITS_1;

         huart1.Init.Parity = UART_PARITY_NONE;

         huart1.Init.Mode = UART_MODE_TX_RX;

         huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;

         huart1.Init.OverSampling = UART_OVERSAMPLING_16;

         if(HAL_UART_Init(&huart1) != HAL_OK){

               for(;;);

         }

         HAL_NVIC_SetPriority(USART6_IRQn, 0, 0);

         HAL_NVIC_EnableIRQ(USART6_IRQn);

         //init DMA TX

         __DMA2_CLK_ENABLE();

         hdma_usart1_tx.Instance = DMA2_Stream7;

         hdma_usart1_tx.Init.Channel = DMA_CHANNEL_5;

         hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;

         hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE;

         hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE;

         hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;

         hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;

         hdma_usart1_tx.Init.Mode = DMA_NORMAL;

         hdma_usart1_tx.Init.Priority = DMA_PRIORITY_HIGH;

         hdma_usart1_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

         if(HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK){

               for(;;);

         }

         __HAL_LINKDMA(&huart1, hdmatx, hdma_usart1_tx);

         HAL_NVIC_SetPriority(DMA2_Stream7_IRQn, 0, 0);

         HAL_NVIC_EnableIRQ(DMA2_Stream7_IRQn);

         //sending....

         char buffer[7] = ''abcdef'';

         if(HAL_UART_Transmit_DMA(&huart1, (u_int8_t*)&buffer,sizeof(buffer)) != HAL_OK){

               for(;;);

         }

         for(;;);

}

void USART6_IRQHandler(void){

         HAL_UART_IRQHandler(&huart1);

}

void DMA2_Stream7_IRQHandler(void){

         HAL_DMA_IRQHandler(&hdma_usart1_tx);

}

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart){

         //test

         int test= 0, test1= 0;

         test = 1;

         test1 = test;

}

void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart){

         //test

         int test= 0, test1= 0;

         test = 1;

         test1 = test;

}

#interrupts #cube-hal #uart-dma
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on October 01, 2017 at 18:55

You're using a .CPP file, so you'll get name mangling on the functions and no linkage to the vector table.

extern 'C' void DMA2_Stream7_IRQHandler(void){

         HAL_DMA_IRQHandler(&hdma_usart1_tx);

}
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2
Posted on October 01, 2017 at 18:55

You're using a .CPP file, so you'll get name mangling on the functions and no linkage to the vector table.

extern 'C' void DMA2_Stream7_IRQHandler(void){

         HAL_DMA_IRQHandler(&hdma_usart1_tx);

}
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 01, 2017 at 22:59

perfekt! it works!

thanks