Skip to main content
PPres
Associate
January 26, 2021
Question

Hardfault when call setTypedText

  • January 26, 2021
  • 11 replies
  • 6524 views

Hi,

I'm developing on a custom hardware, trying to run a simple touchgfx project.

Single screen with an image an a text over.

Following the example and the strusture of a STM32F746G-Disco demo board, I makemy hardware functioning, any image, even big goes on the 800x480 LCD.

But any time I try to put on the screen a text the system faut to Hrdfault handler.

it seem that the function trying to call a protected area ( 0x5xxxxxx) .

I get that problem every time I try to call "setTypedText" funcion.

I don't understand if some memory settings in my app is wrong. I did try to put the text into external or internal memory, using wildcards or not. It's impossible to show any text.

I use freertos, the project is created with CubeMX + Touchgfx Designer.

I did encrease the heap and the stack.

Nothing. several images at the same time pass the test, but no text even if I use a single font and try printing a single word.

Please point me in some direction to search.

Thanks.

Paolo

11 replies

Tesla DeLorean
Guru
January 26, 2021

Look at whats actually faulting.

Could you be loading an ASCII string content where it actually wants a pointer.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
PPres
PPresAuthor
Associate
January 26, 2021

Maybe,

I will check​.

The true problem is that all the touchgfx code was generated by touchgfx designer, and on the only screen I have there are a static image a​nd a single text word . So I can't imagine what can be wrong on that simple code.

I thought about stack or heap problem or external memory configuration, but I don't know exactly where to look.

Any idea?

Tesla DeLorean
Guru
January 26, 2021

Without the source, do a disassembly listing, walk back from the fault, reconstructing the call chain from the stack so you can be more sure of the failure path inbound.

>>0x5xxxxxx

Too non specific, show the register dump at the fault. Show the exact register content. Is the register resolvable to an ASCII stringlet you can pin down in your own code, or the resources generated by the tools?

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
PPres
PPresAuthor
Associate
January 27, 2021

0693W000007Cqv6QAC.jpgHi Tesla,

I did find that returning from the function

touchgfx::Unicode::UnicodeChar* touchgfx::Texts::getText(TypedTextId id)

inside Touchgfx/generated/texts/src/Texts.cpp

jump to an odd flash memory address, I don't know if that can be the cause, but before that call all the disassembly steps goes right into pair address.

after that call an instruction "bx lr" jump to an odd address due to the fact that inside the LR register there is an odd address.

The address range is correct and pointing to the right back function .

At the same time the debugger became instable and is more and more difficult to proceed stepping the code.

If left run, the code goes suddenly into an hardfault.

All the function used are from library and/or auto generated code, so it's very strange.

All the text pointer into the external memory seems corrects. I can see the offsett of every string I'm using.

I think to a wrong aligned code but how it can be verifyed ? since the code is precompiled?

thanks.

PPres
PPresAuthor
Associate
January 27, 2021

Finally I did find it.

Was flagged the "A4" flag in the Text Configuration menu of TouchGFX Designer.

The alignement of the strings was obviously wrong.

That stupid flag costs me 2 day of debugging....

Many thanks for your support .

Paolo

Alexandre RENOUX
Visitor II
January 28, 2021

Hello @PPres​ ,

I'm glad you found a fix to your problem. Sorry for the trouble.

So you are saying that the A4 flag being ticked created the issue ? I'm sorry for the bother but could you elaborate your setup to understand why A4 had an impact on your project ?

/Alexandre

PPres
PPresAuthor
Associate
January 28, 2021

Sorr​y​, ​I didn't update yesterday.

I was too happy ​because it seems all functioning.

But after some verifying the p​roblem didn't disappear. So I'm again checking and testing.

At this point I don't think that the A4 flag ​is part of the problem.

With all the fonts, images and resources inside the flash all goes well.

If I don't u​se any text (always generated by touchgfx designer) all goes well even if the images are inside or on the quadspi.

When I p​ut some text on the project an hardfault is fired every time.

Doesn't matter if the texts are in flash or outside.

I d​on't knows where to look to solve the problem.

Now I take a look to the quadspi driver and loader because I use an already maded code and I have some doubt about.

I t​ry to write my own external loader and

I'll back ​soon with some update.

PPres
PPresAuthor
Associate
January 28, 2021

Ok, Today I did realized an external loader to speed up the debug and during this activity I learn more about the quadspi.

The problem related to the text was a false problem , because the lcd did shows the last correct image, so I thought that the images did run and the texts fails, but I was wrong.

The problem involve all the graphic rendering when I try to us ean external memory.

So I have:

  • a freeRTOS running with a single task ( the touchgfx task) priority normal, stack = 8192byte,
  • LCD initialization tested with a fixed static (in flash) image and with a fixed static in 0x90000000 (quadspi address)
  • Quadspi running ( after the MemoryMappedMode activation, on debug I can see all the data stored with my external loader)
  • FMC running ( after the SDRAM init I can see the all the data passing from 00000 to garbage )

I create a simple project with touchgfx designer and with all the data on internal flash all goes well, ( gif, text, animation and fade-in process etc..)

When I move something into quadspi memory nothing is showed on the screen, it call all the initialization function into the file ViewBase.cpp and then it became un-debuggable.

I try to change the priority of all the IRQ involved ( ) but nothing.

I tryed to check if the quadspi is readable putting a raw image on it and configuring the framebuffer to pointing to, and it works.

Can You help me to find a way ?

Thank you.

Alexandre RENOUX
Visitor II
January 29, 2021

Hello PPres,

What we are relatively sure about is that there's a problem around your QSPI Flash implementation since everything works in internal Flash.

Are you sure your external loader loads correctly data in external Flash ?

"Create a simple GUI" is not very precise. What widgets did you use ? "move something into quadspi memory" is not precise either. What do you move to external Flash ? Bitmaps ? fonts ?

/Alexandre

PPres
PPresAuthor
Associate
January 29, 2021

Hi Alexandre,

Yes I'm sure that all data in quadspi are correct. My external bootloader verify that and I did try to show on lcd some raw data from quadspy configuring the framebuffer to get data from 0x90000000 location memory.

After some test with

It seems something wrong on interrrupt priority or that the system load can't be managed correctly.

The simple project was not so simple because include a fade-in interaction on the start screen, so it was not so obvious if images and text was loaded or not.

Then I create a very simple project ( just one image on the screen), and it run even inside or outside into quadspi.

That is the good part. So I 'm sure to have all periferals correctly configured and running. ( quadspi, SDRAM, Rtos, touchgfx, timer, LCD) .

Now go to the bad part: If I introduce some transition ( fade in or out) the system load the first screen and stop ticking ( Model::tick() is no more called ), so the fade stops. If I try to move a big colored box ( so it's not an image but is generated on the fly by touchgfx) the same problem (tick freezing) happens.

If the transition or some movements involve a little colored box all goes well.

It seems that some heavy work freeze the process, but a light one not.

Those are the irq settings for my peripherals:

LCD irq 5

DMA2 irq 5

SDRAM irq 5

QSPI irq 4 ( I did try to rise the irq but it functions only with 4 or lower irq priority)

TIM( tick using TIM14) irq 0

RCC irq 5

no other peripherals are configured.

linker file:

_Min_Heap_Size = 0x1000 ;   

_Min_Stack_Size = 0x1000 ;   

FreeRTOSv2 task:

.stack_size = 1024 of touchgfxTask

ExtFlashSection + FontFlashSection + TextFlashSection all on Quadspi.

The display is 800x480 so not so small, but I tink that if some issue on performance happens I should see flickering the images( during the animations), but with all the touchgfxTask running .

I try to enable the overrun interrupt on LCD configuration but nothing happens.

Is it possible that with an heavy load touchgfx generate some overrun handler who stop anything?

How can I verify that?

Thanks

Associate III
October 30, 2022

What was your solution to this problem? I am having a similar issue where I can place images/icons in the external flash and everything works fine, but if I put text in the external flash, it causes the system to have a hard fault.

PPres
PPresAuthor
Associate
March 4, 2021

Finally I found what was the problem.

The fact was that into quadspi the data war all right as my reading procedure at the very beginning of main() demostrate, but the procedure I did use to read and write the memory was wrong.

After every command sent to the quadspi I did check the internal status flag register to be sure that the operation was finished, but the function ( copyed from other project) did tests a bit that on my MT25Q doesn't exists. So the result was unpredictable. That generates random errors also if the internal data was corrects.

Now I have a project with a lot of iumages, text and animations and all functioning very well.

Thanks for support.

March 15, 2023

Whilst my cause of Hardfault inside setTypedText was different from that of TS, I will write it here anyway. Hope it will help somebody.

In my project I was creating TextAreas in runtime, on the fly. All worked smoothly for several months. And suddenly transferring to that specific screen caused long time hanging and then hardfault. Now I know the reason - setTypedText has a side effect of calling resizeToCurrentText() which in turn calculates size if text, including contents of wildcards. It has happend that I was filling the wildcard buffer AFTER I called the setTypedText, so it calculated size of garbage text, reading memory starting from wildcard buffer till the first zero encountered. All these months before it was a kind of miracle that zeroes were not far away from wildcard buffers.

ferro
Lead
March 15, 2023

Hi @Community member​ ,

"I was creating TextAreas in runtime"

Could you share your technique of doing this please ?

Are allocating GFX widget on a Heap in e.g. in GFX::View constructor or GFX::View::setupScreen () and adding pointer to eg Container::add () ?

I am asking because I saw in few places that this is not recommended to do eg comment by @Yoann KLEIN​  here:

0693W00000aJ2jyQAC.pngI am not sure wherher to go new/delete path as implementation of GFX could change and cause application crash later in the project.

I work in Qt/emWin. Not being able to new/delete widgets is quite a change in a design paradigm/way of thinking - this is not a complaint, just a statement.

Thanks

March 20, 2023
class FastEditScreenView: public FastEditScreenViewBase {
 ...
 private:
 touchgfx::MoveAnimator<touchgfx::TextAreaWithOneWildcard> 
 letter_boxes[LETTER_COUNT];
 touchgfx::Unicode::UnicodeChar letter_buffers[LETTER_COUNT][LETTER_BUF_SIZE];
}
 
void FastEditScreenView::setupScreen() {
	FastEditScreenViewBase::setupScreen();
 
	int16_t temp_width, temp_height;
	temp_width = 20;
	temp_height = 20;
	for (uint8_t i = 0; i < LETTER_COUNT; i++) {
		letter_boxes[i].setXY(18 + i * 14, 88 + 3 * i);
		letter_boxes[i].setHeight(temp_height); // before setTypedText ! 
		letter_boxes[i].setWidth(temp_width);
		letter_boxes[i].setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
		letter_boxes[i].setLinespacing(0);
		Unicode::snprintf(letter_buffers[i], 2, "%s", "W"); // before setTypedText !
		letter_boxes[i].setWildcard(letter_buffers[i]);	 
 letter_boxes[i].setTypedText(touchgfx::TypedText( T_RESOURCELETTERWC));
		letter_boxes[i].resizeToCurrentText();
		add(letter_boxes[i]);
		letter_boxes[i].invalidate();
	}
}

It is really more comfortable to create controls in Designer and hide/show them as needed. But if you really-really eager such strange things, you can look in your ...ViewBase.cpp file and do more or less the same - new controls should be fields of your view. See also this discussion: https://community.st.com/s/question/0D53W00000ttGs7SAE/creating-textarea-programmatically-with-wildcard-and-buffer