Skip to main content
Zui
Senior
February 7, 2020
Question

Hardfault error (STM32F746G) when generating project with cubeMx

  • February 7, 2020
  • 28 replies
  • 6126 views

Hello

i'm using STM32F746G with touchGfx and keil for a project. i have a working empty project (a blank screen with a button). but when i regenerate the project with cubeMX checking the option :"generate peripheral initialization as a pair of '.c/.h/' files per peripheral" i get HardFault Handler. My keil caller stack say is caused by: touchgfx_init ->setLanguage ->hardFault_Handler

This topic has been closed for replies.

28 replies

ST Technical Moderator
February 11, 2020

Hello @Zui​ ,

Please provide your ioc file with more details about the STM32CubeMX and firmware package versions used.

This will help us to check and analyze your issue.

Best Regards,

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
Ozone
Principal
February 11, 2020

Toolchains are notoriously bad at determining stack sizes.

A quick test would be to try that first. With touchGFX involved, I would guess 1 or 2 kBytes.

Michael K
Senior III
February 11, 2020

Can you elaborate on how to find and change the stack size?

Embedded UI/UX Consulting: cadenza.design
Tesla DeLorean
Guru
February 11, 2020

The OP was using Keil, there the stack size is called out in startup_stm32f7xx.s

Seem to recall IAR having something in the .ICF file, whereas GNU/GCC just comingles the heap/stack and hopes they don't plough into each other.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Martin KJELDSEN
Principal III
February 17, 2020

Have you enabled CRC? The STM32 CRC check may be failing which results in an intentional hard fault.

Otherwise it could have something to do with QSPI initialization since texts and fonts are placed in external flash by default.

Zui
ZuiAuthor
Senior
February 17, 2020

@Martin KJELDSEN​  thanks for your reply.

Yes i have crc enabled. i've tryed disabling it, but nothing changed.

How can it be QSPI initialization since the same empry project generated with cubeMx with "generate peripheral initialization as a pair of '.c/.h/' files per peripheral" doesnt work, but without that option do work. the QSPI initialization is the same.

Tesla DeLorean
Guru
February 17, 2020

Need to look at faulting instructions and processor registers to determine the nature of the failure better. Published routines to dump salient details previously.

An access/probe of QSPI memory will fault if the memory is not properly initialized, same with SDRAM.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
February 17, 2020

Dear Zui! Have you enabled memory mapped mode for QSPI?

Try to add BSP_QSPI_EnableMemoryMappedMode(); after QSPI initialisation.

Michael K
Senior III
July 9, 2021

Hi, I'm going to necro-bump this topic because I somewhat randomly came across it again. I think this happens because for some reason when you check the peripheral pair box and regenerate, CubeMX removes code within User Code labels, including that which is responsible for setting up DSI, LTDC, QSPI and FMC in certain TouchGFX application templates, fyi @Martin KJELDSEN​ .

Here's my Git diff after checking the box, generating, and then unchecking the box then generating again. Red lines denote removals that occurred after the first generation, and persisted after the second. The whole list is about twice as long as shown in the screenshot. @Imen DAHMEN​ this is a fairly serious issue with CubeMX that should get another look. Using CubeIDE 1.6.0 with CubeMX plugin Version: 6.2.0-RC3.0693W00000BdJuFQAV.png

Embedded UI/UX Consulting: cadenza.design
Martin KJELDSEN
Principal III
July 12, 2021

That looks scary. I haven't come across this issue in Stand alone CubeMX. Have you tried CubeIDE 1.6.1 plugin? It probably uses CubeMX 6.2.1 (latest official).

Michael K
Senior III
July 12, 2021

Just tried it with standalone CubeMX 6.2.1 and it does the same thing.

Embedded UI/UX Consulting: cadenza.design
allard
Senior
July 13, 2021

I've got the same kind of problem using Keil. I've done the following:

  • Create a project using the old 4.16 version of TouchGFX
  • Decided the update to 4.17, the project upgraded without problems
  • Open project in cube (latest version 6.1.2), select Keil V5 instead of CubeIDE (initially with "Generate peripheral initialization as a pair of .c/.h files" enabled), regenerate project
  • Open in TouchGFX designer again, generate files
  • Open in Keil, compile, set ext memory configuration in debugger window, using STM32F746G DISCOVERY as board.
  • Debug -> hard fault in setLanguage

I also tried the same with "Generate peripheral initialization as a pair of .c/.h files" disabled, no change. Keil gave one warning that might be related:

.\STM32F746G_DISCO.sct(18): warning: L6314W: No section matches pattern *.o(ExtFlashSection).

I compared the scatter file with the one generated by earlier projects made with v4.16, no difference.

Edit: went back to v4.16 and after a reset of my st-link (with J-LINK firmware) the projects works again, it think the external memory didn't get programmed. Will make a new topic if get further problems and not capture this topic.

franck23
Associate III
July 13, 2021

Check that you are setting the QSPI in Memory-mapped mode in the USER CODE section right at the end of the MX_QUADSPI_Init().

It needs to be set immediately at the end of MX_QUADSPI_Init(), not earlier, and not later.

It was some issues before where "generate peripheral initialization as a pair of '.c/.h/' files per peripheral" would not generate the USER CODE section at the end of the MX_QUADSPI_Init(). But it seems that it is fixed in the last CubeMx version.

You should also check that MX_QUADSPI_Init() is called before MX_TouchGFX_Init();

Your QSPI setup should mostly look like this (config for N25QL128):

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 */
 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();
 }
 /* USER CODE BEGIN QUADSPI_Init 2 */
 QSPI_Map();
 /* USER CODE END QUADSPI_Init 2 */
}
 
bool QSPI_Map(void)
{
	// Map QSPI
	QSPI_CommandTypeDef s_command;
	QSPI_MemoryMappedTypeDef s_mem_mapped_cfg;
	// Configure the command for the read instruction
	s_command.InstructionMode = QSPI_INSTRUCTION_1_LINE;
	s_command.Instruction = QUAD_INOUT_FAST_READ_CMD;
	s_command.AddressMode = QSPI_ADDRESS_4_LINES;
	s_command.AddressSize = QSPI_ADDRESS_24_BITS;
	s_command.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
	s_command.DataMode = QSPI_DATA_4_LINES;
	s_command.DummyCycles = N25Q128A_DUMMY_CYCLES_READ_QUAD;
	s_command.DdrMode = QSPI_DDR_MODE_DISABLE;
	s_command.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
	s_command.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
	// Configure the memory mapped mode
	s_mem_mapped_cfg.TimeOutActivation = QSPI_TIMEOUT_COUNTER_DISABLE;
	return HAL_QSPI_MemoryMapped(&hqspi, &s_command, &s_mem_mapped_cfg) == HAL_OK;
}