CubeMX is missing some lines of code, so the FMC will not work with the generated code.
CubeMX Version: 4.22.1
First I configured the FMC for my TFT display with the standard libs and all worked fine.
Then I used CubeMX to generate the same code using HAL.
In general the code is correct, but two important things are missing in MX_FMC_Init():
1. at the beginning the FMC clock must be enabled: __HAL_RCC_FMC_CLK_ENABLE();
2. the GPIOs of the FMCs are not initialized as alternate function, so I added:
GPIO_Init_Structure.Mode = GPIO_MODE_AF_PP;
GPIO_Init_Structure.Pull = GPIO_NOPULL;
GPIO_Init_Structure.Speed = GPIO_SPEED_HIGH;
GPIO_Init_Structure.Alternate = GPIO_AF12_FMC;
GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 |
GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 |
GPIO_PIN_14 | GPIO_PIN_15;
GPIO_Init_Structure.Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 |
GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
with this additional code everything works perfectly.
Maybe one of the CubeMX programmers can look at this issue and add this code into the automatic program generator.