2024-08-13 10:04 AM - last edited on 2024-09-02 08:47 AM by Amel NASRI
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();
}
}
2024-08-13 10:21 AM
>>what could be the problem?
It does run and then dies somewhere, silently?
2024-08-13 10:24 AM
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
2024-08-13 10:50 AM
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.
2024-08-14 06:06 AM
I removed all the code from the main and left a test blink, but still the code does not run. In the function ‘Error_Handler(void)’ I entered a command, but it is never executed...
I skipped the ‘SystemClock_Config()’ function but it still does not work.
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
GPIOA ->ODR &= ~GPIO_PIN_7;
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
GPIOA ->ODR ^= GPIO_PIN_6;
HAL_Delay(500);
}
/* USER CODE END 3 */
}
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
GPIOB ->ODR &= ~GPIO_PIN_0;
}
/* USER CODE END Error_Handler_Debug */
}
2024-08-15 08:59 AM
2024-08-17 12:19 PM
Update:
if upload the code and press "software reset" and "run" in STM32CubeProgrammer the uC execute the code without problem.
have you ever had this problem? how can i solve it?