cancel
Showing results for 
Search instead for 
Did you mean: 

Do Not Generate Function Call option for MX_TouchGFX_Init not working

franck23
Senior

Hi,

In CubeMx, Project Manager tab -> Advanced Settings, the "Do Not Generate Function Call" for MX_TouchGFX_Init is not working.

After selecting it and generating the code, the MX_TouchGFX_Init() is still present in the main.c and going back to the Advanced Settings, the previously selected check box got deselected.

This is a problem because when using the QuadSpi with TouchGFx, it needs to be mapped before TouchGFX initialization.

The mapping cannot be made in the MX_QUADSPI_Init because there is no USER CODE section at the end of this function (Hey ST, what about having a user code section at the end of EVERY HAL init function???).

Settings:

MCU: STM32H743

CubeMx: 6.1.1

CubeIDE: 1.5.1

Firmware Package: FW_H7 1.8.0

1 ACCEPTED SOLUTION

Accepted Solutions

So I did a bit more testing and this issue seems to happen for all functions from additional X-Cube packages (like X-Cube-TouchGFX, X-CubeBLE, X-CubeNFC4, ...).

I created an internal ticket to investigate and fix this, thank you for reporting this.

View solution in original post

12 REPLIES 12
Romain DIELEMAN
ST Employee

Hi,

Thank you for reporting this. I am surprised by it as well as I could replicate the issue on projects on a STM32H743 eval board and on a H7b3 dk board. It seems that only the MX_TouchGFX_Init is not working, we will investigate more on that (might be just me not aware of a step to do). Could you add the topic "CubeMX" in the Topic tags of this post ? That way this will have more visibility.

Are you working on a custom board ? Did you start your project from scratch from CubeMX ? I am asking this because from what I understand from your message, you have the MX_TouchGFX_Init called before the MX_QUADSPI_Init ? This is not the case in the application template for the H743 eval board available on TouchGFX Designer. I believe the issue might come in your case from the "rank order" of your functions: you can see that in the Project Manager tab -> Advanced Settings --> Generated Function Calls. You can change the ranks of the function by selecting a function and pressing the "up or low arrows" on the top right (see picture)

0693W000007C167QAC.png/Romain

franck23
Senior

Hi Romain,

Thanks for the answer.

(CubeMX is now added to the topic).

Yes, I am working on a custom board, starting from scratch with CubeMX.

The MX_TouchGFX_Init is indeed called after the MX_QUADSPI_Init.

However, the bit of code to map the QSPI must be after MX_QUADSPI_Init and before MX_TouchGFX_Init.

The best place to add this code would be at the end of the MX_QUADSPI_Init function, but this is not possible because there is no "user code" section there.

What I have done now (and is working) is that I selected the "Do Not Generate Function Call" for the QSPI instead and moved the call to a user code section earlier in the main ("USER CODE BEGIN SysInit"). Then I do the QSPI mapping.

So I did a bit more testing and this issue seems to happen for all functions from additional X-Cube packages (like X-Cube-TouchGFX, X-CubeBLE, X-CubeNFC4, ...).

I created an internal ticket to investigate and fix this, thank you for reporting this.

franck23
Senior

Thanks for checking on this issue and creating the ticket!

KPort
Associate II

You wrote: "This is a problem because when using the QuadSpi with TouchGFx, it needs to be mapped before TouchGFX initialization."

I tried to make a STM32CubeIDE project for STM32H743 and then enabled QSPI functionality in CubeMX.

At the end (last 2 lines) of MX_QUADSPI_Init() function I can now see the user code section:

/* USER CODE BEGIN QUADSPI_Init 2 */

 /* USER CODE END QUADSPI_Init 2 */

If you put your QSPI mapping code there it will be called before MX_TouchGFX_Init() is called.

If you don't have these 2 lines, maybe you had deleted them, or you use older fw library (I used STM32Cube_FW_H7_V1.8.0).

franck23
Senior

Hi KPort,

Can you tell me which version of CubeMx you are using?

I do not have any USER CODE BEGIN in the MX_QUADSPI_Init() function (I do have it in the HAL_QSPI_MspInit, but that's not the right place for the mapping code).

I did a test by writing some garbage in this function and refreshing the CubeMx project. It does rewrite the MX_QUADSPI_Init(), but still no user code section

/* QUADSPI init function */
void MX_QUADSPI_Init(void)
{
 
  hqspi.Instance = QUADSPI;
  hqspi.Init.ClockPrescaler = 1;
  hqspi.Init.FifoThreshold = 4;
  hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
  hqspi.Init.FlashSize = 23;
  hqspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_1_CYCLE;
  hqspi.Init.ClockMode = QSPI_CLOCK_MODE_0;
  hqspi.Init.FlashID = QSPI_FLASH_ID_1;
  hqspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
  if (HAL_QSPI_Init(&hqspi) != HAL_OK)
  {
    Error_Handler();
  }
 
}

franck23
Senior

BTW, my firmware package is FW_H7 V1.8.0.

franck23
Senior

OK, I found out why I don't have a user code section.

It depends if the peripheral initialization is done in the main.c or in separated files.

In CubeMx Project Manager->CodeGenerator->Generated files, if the "Generate peripheral initialization as pair '.c/.h' files per peripheral" is selected, the MX_QUADSPI_Init function does not include the user code sections!

KPort
Associate II

Hi franck23,

I'using the latest STM32CubeIDE 1.5.1 and CubeMX 6.1.1 and FW_H7 V1.8.0.

The problem seems to be that you have selected in CubeMX the option "Generate peripheral initialization as a pair of '.c/.h' files per peripheral".

With this option it generates separate .c/.h files for each peripheral AND you don't get all the user code sections.

Without this option selected the generated code for MX_QUADSPI_Init() has all needed user code sections (but the code is inside main.c).

You could do the following: define a macro in main.c just before the HAL initializations like this:

 /* USER CODE BEGIN SysInit */

#define MX_QUADSPI_Init() MX_QUADSPI_Init(); map_my_qspi()

 /* USER CODE END SysInit */

...where map_my_qspi() is your custom code, run right after MX_QUADSPI_Init() (also declare it in section /* USER CODE BEGIN PFP */).

If you generate the code without the "Generate peripheral initialization..." flag selected, then it all becomes so much easier...

This is what gets generated without the flag (look at... /* USER CODE BEGIN QUADSPI_Init 2 */):

static void MX_QUADSPI_Init(void)

{

 /* USER CODE BEGIN QUADSPI_Init 0 */

 /* USER CODE END QUADSPI_Init 0 */

 /* USER CODE BEGIN QUADSPI_Init 1 */

 /* USER CODE END QUADSPI_Init 1 */

 /* QUADSPI parameter configuration*/

 hqspi.Instance = QUADSPI;

 hqspi.Init.ClockPrescaler = 255;

 hqspi.Init.FifoThreshold = 1;

 hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_NONE;

 hqspi.Init.FlashSize = 1;

 hqspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_1_CYCLE;

 hqspi.Init.ClockMode = QSPI_CLOCK_MODE_0;

 hqspi.Init.FlashID = QSPI_FLASH_ID_1;

 hqspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;

 if (HAL_QSPI_Init(&hqspi) != HAL_OK)

 {

   Error_Handler();

 }

 /* USER CODE BEGIN QUADSPI_Init 2 */

 /* USER CODE END QUADSPI_Init 2 */

}