cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 does not reset using Internal Flash memory and TIM1

de Haro Carbonell
Associate III
Posted on November 29, 2017 at 12:04

Hello,

I am using a STM32F429ZIT Discovery board and It is working properly when I using some timers (TIM1, TIM2, TIM3, TIM5 and TIM5) with its interruptions, also using SPI - DMA and ADC functionality.

I have added the code to erase and program in the internal Flash Memory (just the example that you can find in the cubeMX library) and when I download the new program using System Workbench for STM32 and pressing 'RUN' button, the program works as expected, but when I press reset button,the uC doesn't do anything!!! the reset button was working well just before adding the FLASH code part, so obviously it is related to this.

I try to find out were is the problem and what I see it is that when I comment out ONLY the initialization of TIM1:

  

   // MX_TIM1_Init();      // When it is commented , the reset button restart the uC properly, otherwise uC stopped....

    HAL_TIM_Base_Start_IT(&htim1);

    HAL_NVIC_SetPriority(TIM1_UP_TIM10_IRQn, 0, 0);

    HAL_NVIC_ClearPendingIRQ(TIM1_UP_TIM10_IRQn);

    HAL_NVIC_EnableIRQ(TIM1_UP_TIM10_IRQn);

The uC is reseted properly and flash memory and rest of things are working as expected (just TIM1 is not activated).

Other interesting thing is that this initialization is AFTER the flash memory is erased and written, but as soon as the uC is reseted then it doesn't do anything ( I have added a led pin toggle to see if at least the uC start working and it is locked when it initialize something, but just after release the reset button it doesn't do anything ). ONLY WORKS when I press 'RUN'  or 'DEBUG' button in the System Workbench...

Does anyone know why this is happening? because I am completely lost ....

Here you can see the MX_TIM1_Init() inicialization:

void MX_TIM1_Init(void)//---------------------------------------------MX_TIM1_Init__PWM-----------------------------------

{

  TIM_MasterConfigTypeDef sMasterConfig;

  TIM_OC_InitTypeDef sConfigOC;

  TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;

  htim1.Instance = TIM1;

  htim1.Init.Prescaler = 0;

  htim1.Init.CounterMode = TIM_COUNTERMODE_CENTERALIGNED1;

  htim1.Init.Period = 5624;                                            // 180MHz / 16kHz = 11250 => 0 - 11249  to get 16khz PWM WHEN IS TIM_COUNTERMODE_UP (BIPOLAR mode)

  htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;                    // 180MHz / 32kHz = 5625 => 0 - 5624  to get 16khz PWM WHEN IS TIM_COUNTERMODE_CENTERALIGNED1 (UNIPOLAR mode)

  htim1.Init.RepetitionCounter = 0;

  if (HAL_TIM_OC_Init(&htim1) != HAL_OK)

  {

    Error_Handler();

  }

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

  if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)

  {

    Error_Handler();

  }

  sConfigOC.OCMode = TIM_OCMODE_PWM1;

  sConfigOC.Pulse = 2812;                                                               // 11250 / 2 = 5625 => 0 - 5624

  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

  sConfigOC.OCNPolarity = TIM_OCPOLARITY_HIGH;

  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

  sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;

  sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;                                       //  PWM PIN OUT         TIMER CHANNEL

  if (HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)           //  PE8            ->    TIM1_CH1N

  {                                                                                       //  PE9             ->    TIM1_CH1

    Error_Handler();                                                                   //  PE10         ->     TIM1_CH2N

  }                                                                                       //  PE11         ->     TIM1_CH2

  sConfigOC.Pulse = 2812;                                                               //  Channels TIM1_CH1 = TIM1_CH2, and  TIM1_CH1N = TIM1_CH2N

  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;                                           //  Channels TIM1_CHx and TIM1_CHxN are opposite and with Dead Time programmable

  sConfigOC.OCNPolarity = TIM_OCPOLARITY_HIGH;

  if (HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)

  {

    Error_Handler();

  }

  sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;

  sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;

  sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_1;

  sBreakDeadTimeConfig.DeadTime = IGBT_Dead_Time;

  sBreakDeadTimeConfig.BreakState = TIM_BREAK_ENABLE;

  sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;

  sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_ENABLE;

  if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)

  {

    Error_Handler();

  }

  HAL_TIM_MspPostInit(&htim1);

}

#stm32f #flash #reset
2 REPLIES 2
Posted on November 29, 2017 at 16:46

Probably does reset, instrument better in Reset Handler to confirm entry there, and then checkpoint deeper to see how far it goes. On custom designs driving NRST high will prevent a reset occurring, but you have a DISCO board.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 30, 2017 at 11:08

Thanks Clive for quick reply.

Yes, the uC resets but it gets completly blocked or stopped just after reset or disconnect and connect again to supply voltage.

Before implementing Flash acces code the uC was resetting propely, but now it gets blocked (not when i press 'RUN' button in the IDE).

Best regards.