I have a trouble because I am trying to run simple code with blinking LED (with Cube IDE and ST Link v.2 mini). It is STM32L011F4P6 - without devboard - just simple mC with some resistors and capacitors, and without external oscillator.
Here's how I do it so far:
Opening Cube IDE, New -> STM32 project
Selecting STM32L011F4PX and clicking NEXT
Name of project and settings
Next step: NEXT
...and "Finish.
Now, the hardest thing (and I think this is the area where my faults can be visible:
a) Set PA7 as a GPIO output and rename to "LED1" (PA7 has been connected to the anode of LED and cathode of LED to the ground.
b) Debug serial wire - selected as below: Debug serial wire
And no other options selected in that window (maybe that's the problem?)
c) ALT+K (generate code)
Now opening main.c. Code generated automatically.
I added only two lines:
HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin); HAL_Delay(1000);
Just two lines in "while (1) {}". Now I have to set bin and hex options:
And that's all.
Now build all and I have my bin which is ready to upload. I use "ST-Link Utility.
ST-Link Utility: Target->Program.
What I see? I see that PA7 LED is switched on... But not blinking:C Why?:c
CODE:
#include "main.h"
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
while (1)
{
HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
HAL_Delay(1000);
}
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = 0;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_5;
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_MSI;
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_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_GPIOA_CLK_ENABLE();
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = LED1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED1_GPIO_Port, &GPIO_InitStruct);
}
void Error_Handler(void)
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t *file, uint32_t line)
{
}
#endif
UPDATE: I noticed that only main.h from stm32l0xx_it.c was included in code. Maybe here is the problem? (picture below)
Just two lines in "while (1) {}"
How? Can you copy your wholemain()
function as-is as text into the question?just simple mC with some resistors
Well, then how is the led connected? How did you configured theLED1_Pin
in CubeMX? – KamilCuk