cancel
Showing results for 
Search instead for 
Did you mean: 

STM32MP157D- DK1 :- User LED Blink Program

B_D_R
Associate III

Hello Friends,

 

I started learning programming on the STM32MP157D-DK1 evaluation board. I wrote code to blink the user LED LD6, which is connected to PA13, but the LED did not change its state (BSRR register). Can anyone please help me identify what might be wrong with the code?

 

 

Code:-

 

 

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

int main(void)

{

 

HAL_Init();

 

if(IS_ENGINEERING_BOOT_MODE())

{

/* Configure the system clock */

SystemClock_Config();

}

 

MX_GPIO_Init();

while(1)

{

GPIOA->BSRR |= (1<<13);

HAL_Delay(2000);

GPIOA->BSRR |= (1<<29);

HAL_Delay(1000);

}

}

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct = {0};

RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 

/** Configure LSE Drive Capability

*/

HAL_PWR_EnableBkUpAccess();

__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_MEDIUMHIGH);

 

/** Initializes the RCC Oscillators according to the specified parameters

* in the RCC_OscInitTypeDef structure.

*/

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE

|RCC_OSCILLATORTYPE_LSE;

RCC_OscInitStruct.HSEState = RCC_HSE_ON;

RCC_OscInitStruct.LSEState = RCC_LSE_ON;

RCC_OscInitStruct.HSIState = RCC_HSI_ON;

RCC_OscInitStruct.HSIDivValue = RCC_HSI_DIV1;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

RCC_OscInitStruct.PLL2.PLLState = RCC_PLL_NONE;

RCC_OscInitStruct.PLL3.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL3.PLLSource = RCC_PLL3SOURCE_HSE;

RCC_OscInitStruct.PLL3.PLLM = 2;

RCC_OscInitStruct.PLL3.PLLN = 35;

RCC_OscInitStruct.PLL3.PLLP = 3;

RCC_OscInitStruct.PLL3.PLLQ = 2;

RCC_OscInitStruct.PLL3.PLLR = 2;

RCC_OscInitStruct.PLL3.PLLRGE = RCC_PLL3IFRANGE_1;

RCC_OscInitStruct.PLL3.PLLFRACV = 0;

RCC_OscInitStruct.PLL3.PLLMODE = RCC_PLL_INTEGER;

RCC_OscInitStruct.PLL4.PLLState = RCC_PLL_NONE;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

{

Error_Handler();

}

 

/** RCC Clock Config

*/

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_ACLK

|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2

|RCC_CLOCKTYPE_PCLK3|RCC_CLOCKTYPE_PCLK4

|RCC_CLOCKTYPE_PCLK5;

RCC_ClkInitStruct.AXISSInit.AXI_Clock = RCC_AXISSOURCE_HSI;

RCC_ClkInitStruct.AXISSInit.AXI_Div = RCC_AXI_DIV1;

RCC_ClkInitStruct.MCUInit.MCU_Clock = RCC_MCUSSOURCE_PLL3;

RCC_ClkInitStruct.MCUInit.MCU_Div = RCC_MCU_DIV2;

RCC_ClkInitStruct.APB4_Div = RCC_APB4_DIV1;

RCC_ClkInitStruct.APB5_Div = RCC_APB5_DIV1;

RCC_ClkInitStruct.APB1_Div = RCC_APB1_DIV1;

RCC_ClkInitStruct.APB2_Div = RCC_APB2_DIV1;

RCC_ClkInitStruct.APB3_Div = RCC_APB3_DIV1;

 

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct) != HAL_OK)

{

Error_Handler();

}

 

/** Set the HSE division factor for RTC clock

*/

__HAL_RCC_RTC_HSEDIV(1);

}

 

/**

* @brief GPIO Initialization Function

* @param None

* @retval None

*/

static void MX_GPIO_Init(void)

{

GPIO_InitTypeDef GPIO_InitStruct = {0};

/* USER CODE BEGIN MX_GPIO_Init_1 */

/* USER CODE END MX_GPIO_Init_1 */

 

/* GPIO Ports Clock Enable */

__HAL_RCC_GPIOC_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();

__HAL_RCC_GPIOH_CLK_ENABLE();

 

/*Configure GPIO pin Output Level */

HAL_GPIO_WritePin(LED6_GPIO_Port, LED6_Pin, GPIO_PIN_RESET);

 

/*Configure GPIO pin : LED6_Pin */

GPIO_InitStruct.Pin = LED6_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

HAL_GPIO_Init(LED6_GPIO_Port, &GPIO_InitStruct);

 

/* USER CODE BEGIN MX_GPIO_Init_2 */

/* USER CODE END MX_GPIO_Init_2 */

}

1 ACCEPTED SOLUTION

Accepted Solutions
PatrickF
ST Employee

Hi @B_D_R 

PA13 is particular as in Development Boot (aka Engineering Boot), the BootROM code running on Cortex-A7 is toggling PA13 (in open-drain) at around 5 kHz (PA13 is used in very few cases to help user to know some low level state). So conflicting with what the Cortex-M4 is trying to do (overwriting what you wrote after few tens of us, so you barely notice anything changing).

Although your code should work fine when Linux is started.

Please try using PA14 instead (or another GPIO).

Regards.

 

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

View solution in original post

3 REPLIES 3
PatrickF
ST Employee

Hi @B_D_R 

PA13 is particular as in Development Boot (aka Engineering Boot), the BootROM code running on Cortex-A7 is toggling PA13 (in open-drain) at around 5 kHz (PA13 is used in very few cases to help user to know some low level state). So conflicting with what the Cortex-M4 is trying to do (overwriting what you wrote after few tens of us, so you barely notice anything changing).

Although your code should work fine when Linux is started.

Please try using PA14 instead (or another GPIO).

Regards.

 

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hello @PatrickF ,

Thanks for reply and suggestion. Its working at PA14. Can you please explain why its not working at PA13 if you know the reason.

Once again Thanks.

Regards.

Hi,

I already explained in my previous post. PA13 is used by the Cortex-A7 when you are in development boot (BOOT pins = 0b100), so you cannot use it from Cortex-M4.

But during normal use case, with Linux running, PA13 could be used by Cortex-M4 if not assigned to Linux peripheral or gpio.

Regards.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.