AnsweredAssumed Answered

STM32F4 does not reset using Internal Flash memory and TIM1

Question asked by de Haro Carbonell on Nov 29, 2017
Latest reply on Nov 30, 2017 by de Haro Carbonell



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_NVIC_SetPriority(TIM1_UP_TIM10_IRQn, 0, 0);


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.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)
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 2812;                                                               // 11250 / 2 = 5625 => 0 - 5624
  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
  if (HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
  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)