Showing results for 
Search instead for 
Did you mean: 

REPOST: USART Example....

QUESTION - TouchGFX Community repost - Coskun Durukan - Sep 2016


Please can you make an USART example or tutorial with TouchGFX? I can not access the other hardware in any case...

Thanks already...

ANSWER - TouchGFX Community repost - Armine Derragui - Sep 2016


I'm working with Tgfx for 2 months ago and I'm plenty satisfied.

I made a pretty cool UI on the STM32f769I board and manage to use the board features (GPIO, PWM, ADC...) by simply implenting the needed code in the model.cpp and model.hpp files.

But, I'm trying to use USART driver and as usual, I firstly made some tests with keil in order to understand how the USART driver works. 

As everything went fine, I decided to implement the USART code in my UI. But, unlike the previous drivers, USART code is in several files : main.c, stm32f7xx_hal_msp.c and stm32f7xx_it.c.

I couldn't figure out in which file I could put the "msp" and "it" code in the Tgfx environement. Whatever, I put only the init code (main + msp) in the model files. When I compiled (gcc) I had this error : "undefined reference to `HAL_UART_Init'" and "undefined reference to `HAL_UART_RECEIVE_DMA'"

The compiler didn't seem to "know" about the usart driver. I checked the makefile and the and noticed the lack of the uart and usart driver file. I add them and the problem was solved.

At this point it seems to work the same way as with keil, in transmission and receiving mode.

But the code about the "Main Interrupt Service Routines" in the *it.c file is not implemented and if I have to, where I should put it ? Actually, I have to say that I still don't get the whole thing about the interruption routines...

Thx for reading, hope that can help someone.

ANSWER - TouchGFX Community repost - Soren Pingel Dalsgaard- Sep 2016

Thanks for the detailed description.

Regarding interrupts, I can understand the confusion. A brief generic Cortex-M explanation is that somewhere in your code there will be a table of function pointers, with one entry for each possible interrupt. Your linker script is configured to place this table at a certain address in flash (the beginning). When a certain interrupt occurs, the MCU will automatically call the corresponding function from the table (each interrupt type has a numeric value that defines the index in the table).

Now, for the system at hand, this table is defined in a file called isr.c which is located right next to your Makefile (appname/target/.../gcc/). If you open this file you will see some entries in the table like USART1_IRQHandler, UART4_IRQHandler etc. In the bottom of the file you will see empty implementations of all these functions. So out of the box, nothing happens on these interrupts.

What you need to do is hook up the interrupts in isr.c to the code you have from the example that needs to run when the interrupt occurs. You can do this in several ways: you can make the empty function in isr.c call the function you need (requires some includes), or you can rename the function you want to be called to have the same name as the table entry, and then remove the empty implementation from isr.c

Whatever you do, be extremely careful not to rearrange the entries of the table. The order must be exact, otherwise you will get the wrong functions called on interrupts which can lead to many problems.

ANSWER - TouchGFX Community repost - Armine Derragui - Sep 2016

Hi Soren,

Thank you very much for the explanations, that help a lot !

I ran more tests and (obviously) I got some issues, as I didn't implement the interrupts functions...

According your explanations and Gergeley's ( I manage to fix the problem :

I move the declaration of the DMA and USART handle structure from the model.hpp to the top of main.cpp and declared them with the extern keyword in the model and BoardConfiguration cpp files.

I choose your second solution by removing the definition in the isr.c and declaring them in the BoardConfiguration.cpp by surrounding them by an extern "C" directive.

Thx again, really appericate the help !