cancel
Showing results for 
Search instead for 
Did you mean: 

stm32F2 FMSC->LCD hang during write when compiling with -O2

PSarr.1
Associate II

Hi,

we are using a STM32F2 to control an LCD driver using FSMC. The LCD can be configure and display the content correctly.

The project is working correctly for a long time in debug mode, but when we compile it in release (-O2) it seems that the code is hanging during a FSMC write.

The FSMC engine is configured on BANK1 using the FSMC mode A with 16 bits data.

Our project is using FreeRTOS with STEMWin. I reduced the project to 2 tasks. One task is the main task and the other one is for the LCD. We are using the interrupts to get the data for some of our inputs (rotation switch buttons). The LCD task is currently only clearing the display and showing an iteration counter.

If I let the projet run by itself in release, it can run for a long time and there doesn't seems to have any problem. If I turn our rotation swith which generate interrupts, the problem happens quickly. The main task is still running, but the LCD task is stuck in the write data on the FSMC bus. I don't have any hardfault or any other indication that something is wrong apart from the display to stop refreshing.

If we are in debug, if I generate interrupts I cannot reproduce the problem.

In the errata (https://www.st.com/resource/en/errata_sheet/dm00027213-stm32f205207xx-and-stm32f215217xx-device-limitations-stmicroelectronics.pdf) there seems to have a mention in section 2.9.3 about a possible hang in write mode, but doesn't seems to apply to me since I am in asynchronous mode.

I also made sure that all the call to write and read for the FSMC should not be optimise by the compiler (using volatile) as suggested here: http://www.programmersought.com/article/2535598703/

void LCD_WR_DATA(volatile uint16_t data)

{

data=data; //Time delay to insert when using -O2 optimization

LCD->LCD_RAM=data; //writing to FSMC

}

//Read LCD data

uint16_t LCD_RD_DATA(void)

{

volatile uint16_t ram; // prevent being optimized

ram=LCD->LCD_RAM; //reading the FSMC

return ram;

}

Any ideas of what could be wrong?

  • Registers to check for AHB error?
  • HAL FSMC initialisation parameter that could cause issue?
  • Optimisation in the compiler to remove
  • Could it be a cache problem? Need to enable MPU?

Let me know if you need more information

Thanks for all your help and support

2 REPLIES 2

> the LCD task is stuck in the write data on the FSMC bus

What does this exactly mean?

Can you try to single-step in disasm, and then tell us of your observations?

JW

PSarr.1
Associate II

Hi, thank for your reply. I continued to remove function from the project until I had the simplest projet. With that simplest project the problem happened in debug and I was able to isolate the problem to a memory corruption.

Since the correction, I was not able to reproduce the problem that happened quickly before.

Thanks for your help