Sysprogs forums › Forums › VisualGDB › STM32 UART Rx with DMA
Tagged: stm32 dma uart
- This topic has 1 reply, 2 voices, and was last updated 7 years, 3 months ago by
support.
-
AuthorPosts
-
February 9, 2018 at 15:09 #20017
bdahl
ParticipantHi,
i have a STM32L475VG and i want to rx uart data with dma.
My Problem is that my Callbacks where never called.
Can anybody help me?
Testfile:
#include <stm32l4xx_hal.h>
#include <stm32_hal_legacy.h>
#include <cstring>using namespace std;
#ifdef __cplusplus
extern “C”
#endif
void SysTick_Handler(void)
{
HAL_IncTick();
HAL_SYSTICK_IRQHandler();
}</div>
<div>static UART_HandleTypeDef s_UARTHandle = UART_HandleTypeDef();
static DMA_HandleTypeDef s_DMAHandle = DMA_HandleTypeDef();
static unsigned char s_Buffer[100];</div>
extern “C” void DMA1_Stream6_IRQHandler()
{
HAL_DMA_IRQHandler(s_UARTHandle.hdmarx);}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
unsigned char tempBuffer[100];
memcpy(tempBuffer, s_Buffer, 100);
printf(“RxCpltCallback”);
}
void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
{
unsigned char tempBuffer[100];
memcpy(tempBuffer,s_Buffer,100);
printf(“RxHalfCpltCallback”);
}
int main(void)
{
HAL_Init();
__USART2_CLK_ENABLE();
//__GPIOC_CLK_ENABLE();
__GPIOA_CLK_ENABLE();
__DMA1_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.Pin = GPIO_PIN_2;
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Alternate = GPIO_AF7_USART2;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);GPIO_InitStructure.Pin = GPIO_PIN_3;
GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
s_UARTHandle.Instance = USART2;
s_UARTHandle.Init.BaudRate = 9600;
s_UARTHandle.Init.WordLength = UART_WORDLENGTH_8B;
s_UARTHandle.Init.StopBits = UART_STOPBITS_1;
s_UARTHandle.Init.Parity = UART_PARITY_NONE;
s_UARTHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
s_UARTHandle.Init.Mode = UART_MODE_RX;if (HAL_UART_Init(&s_UARTHandle) != HAL_OK)
{}
__DMA1_CLK_ENABLE();
s_DMAHandle.Instance = DMA1_Channel6;
s_DMAHandle.Init.Direction = DMA_PERIPH_TO_MEMORY;
s_DMAHandle.Init.PeriphInc = DMA_PINC_DISABLE;
s_DMAHandle.Init.MemInc = DMA_MINC_ENABLE;
s_DMAHandle.Init.Mode = DMA_CIRCULAR;s_DMAHandle.Init.Priority = DMA_PRIORITY_VERY_HIGH;
s_DMAHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
s_DMAHandle.Init.MemDataAlignment = DMA_PDATAALIGN_BYTE;if (HAL_DMA_Init(&s_DMAHandle) != HAL_OK)
asm(“bkpt 255”);__HAL_LINKDMA(&s_UARTHandle, hdmarx, s_DMAHandle);
NVIC_EnableIRQ(DMA1_Channel6_IRQn);//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_10, GPIO_PIN_SET);
if(HAL_UART_Receive_DMA(&s_UARTHandle, (uint8_t *)s_Buffer, sizeof(s_Buffer)) != HAL_OK)
{
asm(“bkpt 255”);
}
for (;;)
{
printf(“Test”);
/* unsigned char buffer[100];
size_t len = sizeof(buffer);
HAL_UART_Receive(&s_UARTHandle, (uint8_t*) buffer, sizeof(buffer), HAL_MAX_DELAY);
printf(“%s”, buffer);*/}
}
Best regardsBrian
February 9, 2018 at 19:04 #20020support
KeymasterHi,
Most likely your program is missing some initialization code, or interrupt handlers. We would advise cloning a sample project for your board that demonstrates DMA, ensuring that it works, and then comparing the initialization code between the 2 projects.
-
AuthorPosts
- You must be logged in to reply to this topic.