Skip to main content
TGrot.1
Associate
September 6, 2022
Solved

Generating peripheral initialization as a pair of '.c / .h ' files per peripheral.

  • September 6, 2022
  • 4 replies
  • 4697 views

I have a STM32F7508-DK board and I'm using the last version of the STM32CubeIDE and TouchGFX.

I create a project in TouchGFX (or open one of the examples that are there) -> generate code -> open project in STM32CubeIDE -> compile -> run -> works fine.

Now in STM32CubeIDE I want to generate separate c and h files for each of the periphery. I open Device Configuration Tool -> Project Manager tab -> Code Generator -> and select Generate peripheral initialization as a pair of '.c /' h ' files per peripheral -> generate code again -> compile -> run -> doesn't work, black screen on the board. I don't change anything in the code, I only select the option to generate separate files.

Could someone please help me where can be problem?

This topic has been closed for replies.
Best answer by Semer CHERNI

Hello @TGrot.1​ 

Actually this is a known issue and it's the subject of an internal ticket.

I'll keep you posted with the updates.

Internal ticket number: 125071 (This is an internal tracking number and is not accessible or usable by customers).

Kind regards,

Semer.

4 replies

Javier1
Principal
September 6, 2022

>Could someone please help me where can be problem?

Are there any warnings youre not paying attention to?

when i do this (separate .c and.h files) sometimes i need to declare structs as external or include the corresonding .h files in some unexpected places

hit me up in https://www.linkedin.com/in/javiermuñoz/
Semer CHERNI
Semer CHERNIBest answer
ST Employee
September 6, 2022

Hello @TGrot.1​ 

Actually this is a known issue and it's the subject of an internal ticket.

I'll keep you posted with the updates.

Internal ticket number: 125071 (This is an internal tracking number and is not accessible or usable by customers).

Kind regards,

Semer.

Andrei Chichak
Lead
November 2, 2022

I'd like to throw a "me too" into this conversation.

I switched over to pairs of files and my project wouldn't even compile anymore. It's especially useful in that the FreeRTOS stuff gets split out into its own file too, very useful for real projects, not just sample code. There's nothing worse for maintenance than a project that is all stored in one huge file.

TGrot.1
TGrot.1Author
Associate
October 11, 2023

After one year I want to share the solution :grinning_face:. Problem is in fmc.c file. There is missing section:

 

/* USER CODE BEGIN FMC_Init 2 */
BSP_SDRAM_DeInit();
if(BSP_SDRAM_Init() != SDRAM_OK)
{
 Error_Handler();
}
/* USER CODE END FMC_Init 2 */

 

Also is nessesery add include at the top.

 

#include "stm32f7508_discovery_sdram.h"

 

It may look different in other boards. Unfortunately, you have to compare the old main.c with the new generated files and look for differences.

PGrif.2
Associate III
April 15, 2024

Its April 2024 and this is still an issue in the latest version of CubeIDE.

 

When generating a project in TouchGFX default setting for "Generate peripheral initialization as a pair of '.c /' h ' files per peripheral" is unchecked/false. All initialization is packed into the main file. In some intialization functions TouchGFX generates also the /* USER CODE */ sections.

 

When checking peripheral initialization as a pair of '.c /' h ' files those /* USER CODE */ sections will not be transfered out of the main.c to the new peripherial.c file. So use a file compare tool and copy the  section form main.c to the peripherial.c. 

See details for STM32H735-DK in next post.

 

Feel free to check out my unresolved issues with STM32H7 and CANFD

H723 FDCAN1 and FDCAN2 - STMicroelectronics Community

Thank You!

PGrif.2
Associate III
April 22, 2024

In case of the STM32H735-DK code is missing, when switching to  "generate pair of .c and .h files", so here is a workaround.

in TouchGFX

  • create (and build) your new project
  • copy the main at Core\Src\main.c to a temporary folder as "copy_main.c" (you will need the untouched copy)

in CubeIDE

  • import the project
  • open the .ico file and set at ProjectManager-> Code Generator -> check "generate pair of .c and .h files"
  • save and generate code
  • open "Application/User/Core/octospi.c" and compare

 

void MX_OCTOSPI1_Init(void)
void MX_OCTOSPI2_Init(void)​

 

 with the "copy_main.c" functions of the same name

  • you will find the following code sections missing in the  octospi.c so copy and past them

 

​/* USER CODE BEGIN 0 */
// ---------------------------------------------------
// added for generate pair of .c and .h files
#include "stm32h735g_discovery_ospi.h"
// ---------------------------------------------------
/* USER CODE END 0 */
/* OCTOSPI1 init function */
void MX_OCTOSPI1_Init(void)
{
 /* USER CODE BEGIN OCTOSPI1_Init 0 */
 // ---------------------------------------------------
 // added for generate pair of .c and .h files
 BSP_OSPI_NOR_Init_t ospi_nor_int;
 // ---------------------------------------------------
 /* USER CODE END OCTOSPI1_Init 0 */
 /* USER CODE BEGIN OCTOSPI1_Init 2 */
 // ---------------------------------------------------
 // added for generate pair of .c and .h files
 HAL_OSPI_DeInit(&hospi1);
 ospi_nor_int.InterfaceMode = BSP_OSPI_NOR_OPI_MODE;
 ospi_nor_int.TransferRate = BSP_OSPI_NOR_DTR_TRANSFER;
 BSP_OSPI_NOR_DeInit(0);
 if(BSP_OSPI_NOR_Init(0, &ospi_nor_int) != BSP_ERROR_NONE)
 {
 Error_Handler();
 }
 if(BSP_OSPI_NOR_EnableMemoryMappedMode(0) != BSP_ERROR_NONE)
 {
 Error_Handler();
 }
 // ---------------------------------------------------
 /* USER CODE END OCTOSPI1_Init 2 */
/* OCTOSPI2 init function */
void MX_OCTOSPI2_Init(void)
{
 /* USER CODE BEGIN OCTOSPI2_Init 0 */
 // ---------------------------------------------------
 // added for generate pair of .c and .h files
 BSP_OSPI_RAM_Init_t ospi_ram_init;
 // ---------------------------------------------------
 /* USER CODE END OCTOSPI2_Init 0 */
 /* USER CODE BEGIN OCTOSPI2_Init 1 */
 // ---------------------------------------------------
 // added for generate pair of .c and .h files
 OSPI_HyperbusCmdTypeDef sCommand = {0};
 OSPI_MemoryMappedTypeDef sMemMappedCfg = {0};
 // ---------------------------------------------------
 /* USER CODE END OCTOSPI2_Init 1 */
 /* USER CODE BEGIN OCTOSPI2_Init 2 */
 // ---------------------------------------------------
 // added for generate pair of .c and .h files
 sCommand.AddressSpace = HAL_OSPI_MEMORY_ADDRESS_SPACE;
 sCommand.AddressSize = HAL_OSPI_ADDRESS_32_BITS;
 sCommand.DQSMode = HAL_OSPI_DQS_ENABLE;
 sCommand.Address = 0;
 sCommand.NbData = 1;

 if (HAL_OSPI_HyperbusCmd(&hospi2, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
 {
 Error_Handler();
 }
 sMemMappedCfg.TimeOutActivation = HAL_OSPI_TIMEOUT_COUNTER_DISABLE;

 if (HAL_OSPI_MemoryMapped(&hospi2, &sMemMappedCfg) != HAL_OK)
 {
 Error_Handler();
 } 
 // ---------------------------------------------------
 /* USER CODE END OCTOSPI2_Init 2 */

 

 

  • build in CubeIDE and in TouchGFX

 

Cheers!

 

Feel free to check out my unresolved issues with STM32H7 and CANFD

H723 FDCAN1 and FDCAN2 - STMicroelectronics Community

Thank You!