AnsweredAssumed Answered

STM32F7 HAL_Uart_receive_IT revisited

Question asked by Christopher Pappas on Jul 12, 2017
Latest reply on Jul 14, 2017 by Christopher Pappas

STM32F7 HAL_Uart_receive_IT trying to receive and process one byte at a time, and like many others in the forum, I get one byte ok, then the HAL Receive Callback routine will not run again. Here are the basic code pieces that I am using now..

 

FROM MAIN.H
----------------------------------------------------------
/* Definition for USARTx clock resources */
#define USARTx USART3
#define USARTx_CLK_ENABLE() __HAL_RCC_USART3_CLK_ENABLE();
#define USARTx_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define USARTx_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()

#define USARTx_FORCE_RESET() __HAL_RCC_USART3_FORCE_RESET()
#define USARTx_RELEASE_RESET() __HAL_RCC_USART3_RELEASE_RESET()

/* Definition for USARTx Pins */
#define USARTx_TX_PIN GPIO_PIN_8
#define USARTx_TX_GPIO_PORT GPIOD
#define USARTx_TX_AF GPIO_AF7_USART3
#define USARTx_RX_PIN GPIO_PIN_9
#define USARTx_RX_GPIO_PORT GPIOD
#define USARTx_RX_AF GPIO_AF7_USART3

#define USARTx_IRQn USART3_IRQn
#define USARTx_IRQHandler USART3_IRQHandler

 

FROM MAIN.C
----------------------------------------------------------
UART_HandleTypeDef UartHandle;

/* Buffer used for reception */
uint8_t aRxBuffer[1];

int main(void)
{
/* Enable the CPU Cache */
CPU_CACHE_Enable();

/* STM32F7xx HAL library initialization */
HAL_Init();

/* Configure the system clock to 216 MHz */
SystemClock_Config();

/* Initialize all configured peripherals */
MX_UART_Init();

HAL_UART_Receive_IT(&UartHandle, (uint8_t *)aRxBuffer, 1);

while (1)
{
}
}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
BSP_LED_Toggle(LED2);
}

/* UART init function */
void MX_UART_Init(void)
{
UartHandle.Instance = USARTx;
UartHandle.Init.BaudRate = 921600;
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_NONE;
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle.Init.Mode = UART_MODE_TX_RX;
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&UartHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
}

 

FROM IT.C
-----------------------------------------------------------------
extern UART_HandleTypeDef UartHandle;

void USARTx_IRQHandler(void)
{
HAL_UART_IRQHandler(& UartHandle);
}

 

FROM MSP.C
-----------------------------------------------------------------
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{
GPIO_InitTypeDef GPIO_InitStruct;

RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit;

/* Enable GPIO TX/RX clock */
USARTx_TX_GPIO_CLK_ENABLE();
USARTx_RX_GPIO_CLK_ENABLE();

/* Select SysClk as source of USART1 clocks */
RCC_PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
RCC_PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_SYSCLK;
HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInit);

/* Enable USARTx clock */
USARTx_CLK_ENABLE();

 

Does anybody have any ideas of suggestions to make this very simple standard HAL code work properly?

 

Thanks all!

 

Chris

Outcomes