Skip to main content
Graduate
December 23, 2023
Solved

Problem with STM32411 Chip

  • December 23, 2023
  • 5 replies
  • 5366 views

HI there,  I have rewitten this simple piece of code from scratch multiple times with no success. I am just attempting to turn on a set of LEDs.  First in the While Loop. Second in the interupt handler for TIM2.  The chip is a STM32F411CCU in a homespun board.  

Stack is 

0x0

<Signal Handler Called>() at 0xfffffff9

0x7db68e2

<Signal Handler Called>() at 0xfffffff9

HAL_TIM_Base_Start_IT() Line 479

Main()   Line 93

 

Any assistance I can get would be greatly appreciated.

 

 

Full files are attached.

#include "main.h"
 
TIM_HandleTypeDef htim2;
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_TIM2_Init(void);
 
int main(void)
{
 
  HAL_Init();
 
  SystemClock_Config();
 
  MX_GPIO_Init();
  MX_TIM2_Init();
 
  HAL_TIM_Base_Start_IT(&htim2);
 
  while (1)
  {
  HAL_GPIO_TogglePin(GPIOA,LED2_Pin);
  HAL_Delay(1000);
 
  }
}
 
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
 
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
 
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
}
 
static void MX_TIM2_Init(void)
{
  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  TIM_MasterConfigTypeDef sMasterConfig = {0};
 
  htim2.Instance = TIM2;
  htim2.Init.Prescaler = 0;
  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim2.Init.Period = 4294967295;
  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
  {
    Error_Handler();
  }
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }
 
}
 
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
 
  __HAL_RCC_GPIOA_CLK_ENABLE();
 
  HAL_GPIO_WritePin(GPIOA, LED1_Pin|LED2_Pin, GPIO_PIN_RESET);
 
  GPIO_InitStruct.Pin = LED1_Pin|LED2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
}
 
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  /* Prevent unused argument(s) compilation warning */
  if (htim == &htim2){
  HAL_GPIO_TogglePin(GPIOA,LED1_Pin);
  }
 
}
 
void Error_Handler(void)
{
  __disable_irq();
  while (1)
  {
  }
}
 
#ifdef  USE_FULL_ASSERT
void assert_failed(uint8_t *file, uint32_t line)
{
}
#endif /* USE_FULL_ASSERT */
    This topic has been closed for replies.
    Best answer by TDK

    > If I debug it (F6), it will die at  HAL_TIM_Base_Start_IT

    What does die mean?

    Sounds like it may be swamped with interrupts. Hit pause, see where execution is at. Lower timer interrupt speed, etc.

    5 replies

    Super User
    December 23, 2023

    Hi,

    >STM32F411CCU in a homespun board

    Is this your first test with this board? (ever working before?)

    + How you connect: st-link ? working?

    +You have other boards with STM , maybe nucleo board ?

    Graduate II
    December 23, 2023

    Provide schematic for what you actually built

    Make sure BOOT0 is pulled low.

    That VCAP pins have correct capacitors and measure 1.25 V there.

    That Analogue supply pins are connected.

    SpeedyPLHAuthor
    Graduate
    December 23, 2023

    HI TEsla, Ascha,

     

    Here is the relevant part of the Schematic.  It is basically the STM32 chip, an FT201 on i2c, and a couple of test sensors on i2c.  I dont have any i2c elements enabled at the moment as I am trying to narrow the problem down.   

    I am using an STLink/V2 to connect.

    I have had it working on a number of occasions.  But it has been very unreliable.

    It successfully programmes it.  If I debug it (F6), it will die at  HAL_TIM_Base_Start_IT. If I Step into that function (F5), it will complete succesfully, but then dies on the next instruction HAL_GPIO_TogglePin.  I cant work it out.

    I am wondering if it has enough power...Pressure Sensor.png

    Graduate
    December 23, 2023

    Here are the three most common sources of error on your PCB.

    1. bad decoupling

    2. poorly soldered connections

    3. power supply with high noise or unstable under load

    And, I think NRST pin should have a capacitor to GND. Usualy 100nF.

    Visitor II
    December 23, 2023

    Since you've said it's a homespun PCB, I recommend testing the PCB. YOu can test it with a multimeter or make a PCB tester like this

    Super User
    December 23, 2023

    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)

    Try to increase number of flash wait states. FLASH_LATENCY_0 -> FLASH_LATENCY_8

    TDKAnswer
    Super User
    December 24, 2023

    > If I debug it (F6), it will die at  HAL_TIM_Base_Start_IT

    What does die mean?

    Sounds like it may be swamped with interrupts. Hit pause, see where execution is at. Lower timer interrupt speed, etc.