0
votes

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:

  1. Opening Cube IDE, New -> STM32 project

  2. Selecting STM32L011F4PX and clicking NEXT

  3. Name of project and settings

Name of project and settings

Next step: NEXT

...and "Finish.

  1. 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.

GPIO OUTPUT

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)

  1. Now opening main.c. Code generated automatically.

  2. 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:

BIN

And that's all.

  1. Now build all and I have my bin which is ready to upload. I use "ST-Link Utility.

  2. ST-Link Utility: Target->Program.

  3. 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)

stm32l011_it.c file

1
Just two lines in "while (1) {}" How? Can you copy your whole main() 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 the LED1_Pin in CubeMX?KamilCuk
Thank you for the answer! I added main function as an image in post. LED is connected between PA7 and GND (so LED should be drived by High potential on PA7 pin). LED has also 1k resistor to limit the current. LED1_Pin is configured graphically, as in picture GPIO OUTPUT.Karlsson
Please do not post images of text. Please post text as text. Well, from what you are showing I believe it should work. So there is something missing that you did not consider that is not working. I would recommend to debug the code, which will also be a great opportunity to learn to use a debugger, and also check with a meter the voltages on that pin (and also a IDE, like eclipse).KamilCuk
Ok, the code block is correct for now. Initially, I thought that here the error may be something related to the microcontroller clock setting - because I practically did not touch this part: c And that is why there is no blinking :cKarlsson
The voltage on LED is 1.82 V.Karlsson

1 Answers

0
votes

you need to add MX_GPIO_Init(); before your while(1) loop