cancel
Showing results for 
Search instead for 
Did you mean: 

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

TGrot.1
Associate

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Semer CHERNI
ST Employee

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.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

6 REPLIES 6
Javier1
Principal

>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

we dont need to firmware by ourselves, lets talk
Semer CHERNI
ST Employee

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.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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
Associate

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.

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!

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!