Skip to main content
Visitor II
August 13, 2024
Question

STM32L031G Custom Board - Program don't run after upload

  • August 13, 2024
  • 1 reply
  • 1578 views

Hello,

I have a problem with a STM32L031G in a custom board.

The program don't run after the program.

BOOT0 is connected to gnd via 10K resistor.

Attached you can find a circuit diagram and clock configuration.

what could be the problem?

Thanks 

Michele

 

 

 

 

void SystemClock_Config(void)
{
 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

 /** Configure the main internal regulator output voltage
 */
 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

 /** Initializes the RCC Oscillators according to the specified parameters
 * in the RCC_OscInitTypeDef structure.
 */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
 RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_4;
 RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler();
 }

 /** Initializes the CPU, AHB and APB buses clocks
 */
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV64;
 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();
 }
 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
 PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;
 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
 {
 Error_Handler();
 }
}

 

 

 

 

SchematicSchematicClock ConfigurationClock Configuration

    This topic has been closed for replies.

    1 reply

    Graduate II
    August 13, 2024

    >>what could be the problem?

    It does run and then dies somewhere, silently?

    Visitor II
    August 13, 2024

    It loads the code, but does not execute it. the first thing it has to do is light a led, but it does not do this

    Graduate II
    August 13, 2024

    It does this in Reset_Handler() immediately at startup? Or somewhere much later in main() after SystemInit(), HAL_Init() and SystemClock_Config() ? Review ALL the code between Reset_Handler entry point, and the point where you've initialized the GPIO and illuminated the LED.

    Skip SystemClock_Config() entirely, let the system continue to run at the clock it started on, and not the snail paced 500 KHz. Watch the 1KHz SysTick doesn't saturate.

    Get something in Error_Handler() and HardFault_Handler() so the while(1) aren't silent.

    BOOT0 is Low, so perhaps double check the validity of the Initial SP and PC in the Vector Table. Check Option Bytes if using those.

    Use the debugger, stop the MCU, confirm where it's stuck. In your own code, or in the ROM.