Skip to content

STM32F411RET6 hangs before boot #4653

Closed
@waymond91

Description

@waymond91

Description

  • Type: Bug

  • Priority: Blocker

  • Related issues:

I have seen this issue in a number of places online. The first place I encountered was here: https://developer.mbed.org/forum/bugs-suggestions/topic/5600/
But from what I have seen, this solution seems to have been rolled out a long time ago.

After rooting around online even more, it seemed issue #4532 captured a description of my problem.

But it seems like a lot of these similar problems were recently solved by pr #4543

I also found this post from over a year ago that seems very similar, the fact that no solution was found makes me feel like my current hardware design is dead in the water:
https://developer.mbed.org/questions/61589/Program-hangs-at-SetSysClock-on-a-custom/

Any ideas of what I should do? I felt like this must have been a hardware issue when I first started. But now I see that I can run & debug code if I use the system default clock, so I should be able to configure the HSI to run at a reasonabe speed, preferably with the Mbed environment!


Bug

Target
NUCLEO_F411RE

Toolchain:
GCC_ARM

Toolchain version:
6.3.1

mbed-cli version:
1.0.0

Expected Behavior
Platform should boot to the beginning of the main() function.

Actual Behavior
Application times out/crash before reaching the main application while configuring the MCU clocks.

Hey Guys,
After playing around with a Nucleo-F411 board for a while I decided I wanted to deploy this MCU to a custom PCB for my application.
I am using an external 8 Mhz crystal, and I believe I have selected the right capacitors for the oscillator.
Regardless, my system hangs and does not make it to the main() function of my code when building via mbed-cli.
I have tried removing the external crystal and configuring the HSI. However, when using the mbed compiler does not work because the program doesn't reach my main function.
If I comment out this line of system_stm32f4xx.c
237 SetSysClock();
the program will make it to my application, but of course everything runs at the default 16Mhz, while the rest of the application expects 96Mhz.

So from here I should be able to configure the HSI to run similarly to the HSE:

SYSCLK = 96 Mhz
AHBCLK = 96 Mhz
APB1CLK = 48 Mhz
APB2CLK = 96 Mhz

But I don't really know how much of this configuration Mbed is performing in the background.
Using CoIde + ARM_GCC, I have tried to configure the clocks in a variety of ways, shown below.
But the program often crashes after HAL_RCC_OscConfig(&RCC_OscInitStruct) although sometimes it runs if I step the processor through the entire stm32f4xx_hal_rcc.c file manually?

#include "stm32f4xx.h"
#include "stm32f4xx_hal_gpio.h"
#include "stm32f4xx_hal_rcc.h"

GPIO_InitTypeDef GPIO_InitStructure;

void Error_Handler(void);

int main(void)
{
	HAL_Init();

	RCC_OscInitTypeDef RCC_OscInitStruct;
	RCC_ClkInitTypeDef RCC_ClkInitStruct;

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

	__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

	//Configure Internal Oscillator
	RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
	RCC_OscInitStruct.HSIState = RCC_HSI_ON;
	RCC_OscInitStruct.HSICalibrationValue = 16;
	RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

	RCC_OscInitStruct.PLL.PLLM = 16;
	RCC_OscInitStruct.PLL.PLLN = 192;
	RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
	//RCC_OscInitStruct.PLL.PLLQ = 2;


	//Configure External Oscillator
	/*
	RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
	RCC_OscInitStruct.HSEState = RCC_HSE_ON;
	RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
	RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

	RCC_OscInitStruct.PLL.PLLM = 8;
	RCC_OscInitStruct.PLL.PLLN = 192;
	RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
	RCC_OscInitStruct.PLL.PLLQ = 2;
	*/
	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_PLLCLK;
	RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
	RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
	RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

	if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
	{
	Error_Handler();
	}

	/**Configure the Systick interrupt time
	*/
	HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

	/**Configure the Systick
	*/
	HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

	/* SysTick_IRQn interrupt configuration */
	HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

	__GPIOC_CLK_ENABLE();
	GPIO_InitStructure.Pin   = GPIO_PIN_8;
	GPIO_InitStructure.Mode  = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStructure.Pull  = GPIO_PULLUP;
	GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
	HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);

	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_SET);

	//printf("Yeah Right\n\n");

	while(1)
	{
		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET);
	}
}

void Error_Handler(void){}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions