Deadlock on STM32H7S7L with FreeRTOS and TouchGFX
I’m using a custom board based 99% on the STM32H7S78-DK (except for the display, which is a 7”).
I’m having a serious deadlock issue (the entire microcontroller freezes, and I can’t connect to the debugger).
My firmware is composed:
- The bootloader that just checks if an SD card is attached (if so, it mounts, reads it, and, in case, updates the external flash with the firmware).
- If no SD card is detected, it loads the application.
The bootloader uses I and D caches and sets up the external memory via XSPI (PSRAM and FLASH)
The PSRAM is used for the TouchGFX framebuffer; the FLASH for the TouchGFX assets.
The .icd defines (among other things)
define symbol __ICFEDIT_intvec_start__ = 0x70000000;
define region EXTRAM_region = mem:[from 0x90000000 to 0x91FFFFFF];
define region ROM_region = mem:[from 0x70000000to 0x701FFFFF];
define region EXTROM_region = mem:[from 0x70200000to 0x77FFFFFF];
place in ROM_region { readonly };
place in RAM_region { readwrite };
place in EXTRAM_region { first section TouchGFX_Framebuffer
, section Video_RGB_Buffer
, section Nemagfx_Stencil_Buffer };
place in EXTROM_region { section TextFlashSection
, section FontFlashSection
, section FontSearchFlashSection
, section ExtFlashSection };The application uses only the I cache, and it has just 3 RTOS tasks:
- TouchGFX
- COM (for UART communication over MODBUS protocol)
- EEPROM read/write (to read and write EEPROM data via I2C)
What I’ve tried so far to avoid this deadlock:
- increased stack size of every task (8192 for TouchGFX, 4096 for COM and 4096 for EEPROM)
- increased heap size to 65536 in configTOTAL_HEAP_SIZE in FreeRTOSConfig.h
- increased configMINIMAL_STACK_SIZE to 256
- set configTIMER_TASK_PRIORITY to configMAX_PRIORITIES - 1
- set INCLUDE_vTaskCleanUpResources to 1
- disabled all tasks and kept just the TouchGFX one
- removed all the code in Model::tick to avoid overloading the task
- reduced frequency of XSPI (especially PSRAM) setting PsramObject.psram_public.FreqMax = 100 * 1000000u; even if max ferquency is 200MHz
- increased prescaler to hxspi1.Init.ClockPrescaler = 2;
- enabled hxspi1.Init.DelayHoldQuarterCycle = HAL_XSPI_DHQC_ENABLE;
- added hxspi1.Init.SampleShifting = HAL_XSPI_SAMPLE_SHIFT_HALFCYCLE; instead of None
- Increased in the .icf file CSTACK = 0x6000; and HEAP = 0x4000;
- applied fix for errata 2.2.17
- checked errata 2.4.2, but I’m not multiplexing XSPI
- followed this fix https://forums.freertos.org/t/tmr-svc-appears-to-stop-working-and-threads-waiting-for-event-bits-become-non-responsive-how-should-i-debug-this/16324/2 setting configMAX_PRIORITIES 56 and configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1) and #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
The issue happens after a couple of minutes from startup. After it happens, if I instantly power up the board, it happens after 2-3 seconds (the application always boots from the bootloader). If I wait to power cycle (like 2-3 minutes), the application keeps working for a little more before it crashes.
I’ve no idea how to debug it, as soon as the microcontroller freezes, the debugger basically disconnects, and I can’t find the latest code executed. Any idea, or I’m missing something?
I’m using IAR 9.60 and the J-Link Base
