cancel
Showing results for 
Search instead for 
Did you mean: 

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

Lars Beiderbecke
Senior III

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.

4 REPLIES 4

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

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.

MSmit.4
Associate

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

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