cancel
Showing results for 
Search instead for 
Did you mean: 

TouchGFX: UART to UI WITHOUT RTOS!!!

Krautermann
Senior II

I am trying to display UART data received to UI WITHOUT RTOS but I am unsure how to code the model, I am getting error every time. I read the documentation and tried to reproduce the same thing but in vain. I watched a lot of videos on youtube but they all used RTOS. My project consists of not using RTOS.

I can confirm that my UART works and I can receive strings from a terminal. I used HAL UART function in the Main() while loop.

while (1)
  {
  MX_TouchGFX_Process();
  HAL_UARTEx_ReceiveToIdle_DMA(&huart3, RX_String, sizeof(RX_String));
  }

In my Screen1View.cpp file, I have inserted a function that should display the received UART string to a text box:

void Screen1View::uart_Data(char* RX_String)
{
	textArea2.setWideTextAction(touchgfx::WIDE_TEXT_WORDWRAP);
	Unicode::strncpy(textArea2Buffer, RX_String, TEXTAREA2_SIZE);
	textArea2.invalidate();
}

In the Screen1Present.cpp:

void Screen1Presenter::uart_Data(char* RX_String)
{
	view.uart_Data(RX_String);
}

I declared virtual void uart_Data(char* RX_String); in ModelListener.hpp

I am however having problem with Model.cpp:

void Model::tick()
{
#ifndef SIMULATOR
	modelListener->uart_Data(RX_String);
#endif
}

This is what I have so far and I feel something is missing. Can someone please give some guidance?

1 ACCEPTED SOLUTION

Accepted Solutions
JTP1
Lead

OK, as far as I see you should replace

virtual void uart_Data(char* RX_String);

with

virtual void uart_Data(char* RX_String){}

in ModelListener.hpp.

Attached is tested simple example files from model tick to view. Remember to set typography wildcard range for exmpale 0x00-0xff. You can also touchgfx_printf- functions in simulator to test execution (commented)

View solution in original post

8 REPLIES 8
Krautermann
Senior II

My Error is:

c:\st\stm32cubeide_1.11.2\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.200.202301161003\tools\arm-none-eabi\bin\ld.exe: ./Application/User/gui/Screen1Presenter.o: in function `ModelListener::ModelListener()':
C:/Users/o.sang/Documents/TouchGFX/LED_toggle_UART1/STM32CubeIDE/CM7/Debug/../../CM7/../../CM7/TouchGFX/gui/include/gui/model/ModelListener.hpp:9: undefined reference to `vtable for ModelListener'
c:\st\stm32cubeide_1.11.2\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.200.202301161003\tools\arm-none-eabi\bin\ld.exe: ./Application/User/gui/Screen1Presenter.o: in function `ModelListener::~ModelListener()':
C:/Users/o.sang/Documents/TouchGFX/LED_toggle_UART1/STM32CubeIDE/CM7/Debug/../../CM7/../../CM7/TouchGFX/gui/include/gui/model/ModelListener.hpp:11: undefined reference to `vtable for ModelListener'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:90: stm32h745i_disco_CM7.elf] Error 1
"make -j8 all" terminated with exit code 2. Build might be incomplete.

JTP1
Lead

Where you have define the RX_String which main.cpp uses and have you extern it to the model.cpp or how the model.cpp knows it ?

Do you mean main.c? Because I do not see any main.cpp file in my project folder. In main.c, RX_String is defined as:

uint8_t RX_String[257];

which is being used in the while loop by a HAL UART function.

For the extern to model.cpp, I wrote the following but I am not sure if that's correct:

#ifndef SIMULATOR
#include "main.h"
#endif
extern "C"
{
	extern char* RX_String[];
}

primary you can , but this isnt good on every tick update (check change)

secondary your extern is bad

use

extern uint8_t RX_String[];

 and screenpresenter.hpp need too add

virtual void uart_data...

 and in both send pointer to string declared global is waste of params.

JTP1
Lead

OK, as far as I see you should replace

virtual void uart_Data(char* RX_String);

with

virtual void uart_Data(char* RX_String){}

in ModelListener.hpp.

Attached is tested simple example files from model tick to view. Remember to set typography wildcard range for exmpale 0x00-0xff. You can also touchgfx_printf- functions in simulator to test execution (commented)

Krautermann
Senior II

Thank you for your answer!

After removing the semicolon ; and replacing it with {}, the error was gone and I was able to compile and it now displays string from UART!

I don't get however why replacing the semicolon with {} made it work...if someone or you could explain me, would be great!

JTP1
Lead

Good that you get forward:thumbs_up:

This line is not function prototype, but it defines (this case empty) virtual function to the modelListener- class. This virtual function is then overrided in presenter class, you can see the prototype in presenter.hpp and function presenter.cpp.

Maybe you have allready read this documentation:

https://support.touchgfx.com/docs/development/ui-development/touchgfx-engine-features/backend-communication

AWack
Associate III

Hi,

 

indeed, it helps to put {} after my own virtual function definition

Achim