cancel
Showing results for 
Search instead for 
Did you mean: 

Help in writing a bare metal code for implementing a UART RX interrupt routine in SMT32F767ZI ?

SSRIN.1
Associate III

I started writing embedded code 7 months back for a robotics project. Till now , I was able to handle most of the stuff with HAL libraries. I hit a snag when trying to interface with a AHRS(Microstrain CX5-25) unit. There were time when only first few bytes will be received and the device won't receive any more bytes, even thought the IMU status shows streaming. Suspecting something is wrong with the IMU, I tried reading it from PC using Pyserial and it worked. I suspect something is wrong with HAL Receive IT Function call.

Either way,After inputs from previous posts regarding handling of frames with different sizes. I decided to shift to bare metal register based programming at least for interfacing this device.

Currently I have the following hardware setup.

STM324767ZI Nucleo Uart 5 port is connected to pc via USB-TTL device. I will be using pyserial from PC side to send some arbitrary data. This will help me check the Uart receive isr routine written in STM32 micro controller.

Initial peripheral initialisation code is set using cubemx pre-generated code.

In main.c

I call

__HAL_UART_ENABLE_IT(&huart5,UART_IT_RXNE);

__HAL_UART_ENABLE_IT(&huart5,UART_IT_ERR);

to enable interrupts

Then I write a customisr routine which is called from 

void UART5_IRQHandler(void)

custom_isr(UART_HandleTypeDef * huart)

{

uint32_t isrflags = huart->Instance->ISR;

uint32_t crlits = huart->Instance->CR1;

if (((isrflags & USART_ISR_RXNE) != RESET) )//&& ((crlits & USART_CR1_RXNEIE) != RESET))

{unsigned char a = huart->Instance->RDR;

store_ring (a , rbuf);

}

}

I could verify that when ever, I send a byte from pc. The interrupt is triggered, But RDR register is empty.

When I checked the ISR register following bits were set : IDLE,TC complete,Transmit Data,End of Block,Busy flag,character match flag.

Strangely I have enabled interrupt only for error and rx not empty. However after interrupt trigger, when I check the ISR flag, rx not empty flag is not set.

I think, I am making a mistake in the sequence of how its done. Can any one advice on what I am missing ?

Thank you

Yours Sincerely,

S.Shyam

11 REPLIES 11

I wasn't considering it... Ok so if the L4xx HAL (I'm using L433) has DMA HT/TC and UART Idle line callbacks, I can manage more safely UART reception.

Before trying this out I think I'll write a custom handler mimicking HAL but without this interrupt activation/deactivation. If it gets out of hand, I'll start porting the github code. Thanks!

Sorry one more question:

As I'm not using CubeMX for code generation and I manually copied the last version of L4xx HAL in my Classes folder, would commenting the Interrupt deactivation work?

The more I write, the more I think I'll go with the DMA solution, but I already use that HAL_RECEIVE_IT(1) in a couple projects so I'd like to keep it.