Skip to main content
Lars Beiderbecke
Senior III
April 18, 2020
Question

Request: CubeMX: Generate user code section between peripherals and interrupt initialization

  • April 18, 2020
  • 4 replies
  • 1027 views

I'm using "interupt unmasking ordering" in CubeMX, which basically generates code like this:

 MX_GPIO_Init();
 MX_DMA_Init();
 MX_FMC_Init();
 MX_DAC_Init();
 ... <--- add user code section
 MX_NVIC_Init();

My request is to add another use code section between the end of the peripheral initialization and the enabling of the interrupts.

The reason is that I need to configure additional entities, e.g., the SDRAM by calling SDRAM_Init(), which I now cannot do before enabling interrupts. This is required for my application, though.

This topic has been closed for replies.

4 replies

Nesrine.JLASSI
Visitor II
May 11, 2020

Hello @Lars Beiderbecke​ 

I don't think we'll be able to add this in the generated code since it's a specific case contrary to STM32CubeMX which gives something more general.

So, I the solution is to write your code again. 

Best regards,

Nesrine

Lars Beiderbecke
Senior III
May 11, 2020

Well, I did say "I", but I actually think this is a general case of needing further initialization before enabling interrupts. One such example would be the SDRAM (not FMC) initialization, in case an interrupt handler needs to access SDRAM.

KnarfB
Super User
February 2, 2021

?workaround?: call __disable_irq(); before the init block and __enable_irq(); when everything is prepared?

MSmit.4
Visitor II
February 2, 2021

I have spent a of time creating clever, and not so clever, but always awkward and hard to understand, ways to add code or comments where CubeMX does not let you put them without the risk of having it vanish.

One simple, general solution would be to let the user put user code protection wherever they need or want it, such as:

 /* USER CODE BEGIN Added by user 0 */

// This comment will not be removed by CubeMX.

 /* USER CODE END Added by user 0 */

Thanks