cancel
Showing results for 
Search instead for 
Did you mean: 

Misleading MCU flash and led blink error

Vilius
Associate II

Hi,

I am doing my absolute baby steps in the STM32 environment. My MCU model is STM32F756VGH6. After days of debugging I finally managed to connect my STLINK V3 to the MCU but not run the led blinky :(

This TFBGA100 package on a custom breakout board might not be the best for learning. However, the STLINK can read the core ID and connect to the MCU, so I suspect my wiring is right, I have enough decoupling capacitors, USB, BOOT, NRST and other crucial pins are at their needs as well..

 

#include "main.h"

void SystemClock_Config(void);
static void MPU_Config(void);
static void MX_GPIO_Init(void);

int main(void)
{
  MPU_Config();

  HAL_Init();

  SystemClock_Config();

  MX_GPIO_Init();

  while (1)
  {

	  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, 1);
	  HAL_Delay(1000);
	  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, 0);
	  HAL_Delay(1000);

  }

}

//---------------------------------------------------------------------------------------------------------------------------------------

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  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_HSI;
  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_GPIOC_CLK_ENABLE();


  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);

  GPIO_InitStruct.Pin = GPIO_PIN_13;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

}



void MPU_Config(void)
{
  MPU_Region_InitTypeDef MPU_InitStruct = {0};

  HAL_MPU_Disable();

  MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  MPU_InitStruct.BaseAddress = 0x0;
  MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
  MPU_InitStruct.SubRegionDisable = 0x87;
  MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
  MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
  MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
  MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
  MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;

  HAL_MPU_ConfigRegion(&MPU_InitStruct);

  HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);

}

void Error_Handler(void)
{

  __disable_irq();
  while (1)
  {
  }

}

#ifdef  USE_FULL_ASSERT

void assert_failed(uint8_t *file, uint32_t line)
{

}
#endif

 

This simple program was generated by the STM32CubeIDE to flash an led on pin PC14. As I mentioned, I do not get any voltage toggling on the pin... And there is one very strange circumstance: accidentally I noticed, that I was able to flash the MCU with NRST pin unconnected  to the STLINK (NRST was floating). I tried to flash both directly from the STM32CUBEIDE and from STM32Cube Programmer, here are the logs:

STM32Cube Programmer:

18:02:56:184 : Memory Programming ...
18:02:56:184 : Opening and parsing file: Learning_project.elf
18:02:56:188 : File : Learning_project.elf
18:02:56:188 : Size : 6.12 KB
18:02:56:188 : Address : 0x08000000
18:02:56:189 : Erasing Segment <0> Address <0x08000000> Size <6268>Bytes
18:02:56:189 : Erasing memory corresponding to segment 0:
18:02:56:189 : Memory Erase via FlashLoader!
18:02:56:189 : Memory erase...
18:02:56:192 : halt ap 0
18:02:56:192 : w ap 0 reg 15 PC (0x20000000)
18:02:56:192 : w ap 0 reg 17 MSP (0x20000500)
18:02:56:193 : w ap 0 reg 16 xPSR (0x01000000)
18:02:56:195 : w ap 0 @0x20000D80 : 0x00000200 bytes, Data 0x00000000...
18:02:56:195 : w ap 0 @0x20000000 : 0x00000004 bytes, Data 0x0000BE00...
18:02:56:203 : w ap 0 @0x20000004 : 0x00000954 bytes, Data 0xF000B580...
18:02:56:203 : Erasing internal memory sector 0
18:02:56:203 : Init flashloader...
18:02:56:203 : halt ap 0
18:02:56:203 : w ap 0 reg 0 R0 0x00000001
18:02:56:204 : w ap 0 reg 1 R1 0x00000000
18:02:56:204 : w ap 0 reg 2 R2 0x00000000
18:02:56:204 : w ap 0 reg 3 R3 0x00000000
18:02:56:204 : w ap 0 reg 4 R4 0x00000000
18:02:56:204 : w ap 0 reg 5 R5 0x00000000
18:02:56:204 : w ap 0 reg 6 R6 0x00000000
18:02:56:204 : w ap 0 reg 7 R7 0x00000000
18:02:56:205 : w ap 0 reg 8 R8 0x00000000
18:02:56:205 : w ap 0 reg 9 R9 0x00000000
18:02:56:205 : w ap 0 reg 10 R10 0x00000000
18:02:56:205 : w ap 0 reg 11 R11 0x00000000
18:02:56:205 : w ap 0 reg 12 R12 0x00000000
18:02:56:206 : w ap 0 reg 13 SP 0x00000000
18:02:56:206 : w ap 0 reg 14 LR 0x20000001
18:02:56:207 : w ap 0 reg 15 PC 0x20000005
18:02:56:207 : w ap 0 reg 16 xPSR 0x01000000
18:02:56:207 : w ap 0 reg 17 MSP 0x20000D54
18:02:56:207 : w ap 0 reg 18 PSP 0x00000000
18:02:56:207 : run ap 0
18:02:56:210 : halt ap 0
18:02:56:211 : r ap 0 reg 0 R0 0x00000001
18:02:56:211 : Loader sector erase...
18:02:56:211 : w ap 0 reg 0 R0 0x08000000
18:02:56:212 : w ap 0 reg 1 R1 0x08000000
18:02:56:212 : w ap 0 reg 2 R2 0x00000002
18:02:56:213 : w ap 0 reg 3 R3 0x00000000
18:02:56:213 : w ap 0 reg 4 R4 0x00000000
18:02:56:213 : w ap 0 reg 5 R5 0x00000000
18:02:56:214 : w ap 0 reg 6 R6 0x00000000
18:02:56:214 : w ap 0 reg 7 R7 0x00000000
18:02:56:215 : w ap 0 reg 8 R8 0x00000000
18:02:56:215 : w ap 0 reg 9 R9 0x00000000
18:02:56:216 : w ap 0 reg 10 R10 0x00000000
18:02:56:219 : w ap 0 reg 11 R11 0x00000000
18:02:56:219 : w ap 0 reg 12 R12 0x00000000
18:02:56:220 : w ap 0 reg 13 SP 0x00000000
18:02:56:220 : w ap 0 reg 14 LR 0x20000001
18:02:56:221 : w ap 0 reg 15 PC 0x200002AD
18:02:56:221 : w ap 0 reg 16 xPSR 0x01000000
18:02:56:222 : w ap 0 reg 17 MSP 0x20000D54
18:02:56:222 : w ap 0 reg 18 PSP 0x00000000
18:02:56:222 : run ap 0
18:02:56:414 : halt ap 0
18:02:56:415 : r ap 0 reg 0 R0 0x00000001
18:02:56:415 : erase: 0226ms
18:02:56:416 : Download in Progress:
18:02:56:416 : Size : 6272 Bytes
18:02:56:416 : Address : 0x08000000
18:02:56:416 : Buffer program...
18:02:56:419 : halt ap 0
18:02:56:419 : w ap 0 reg 15 PC (0x20000000)
18:02:56:419 : w ap 0 reg 17 MSP (0x20000500)
18:02:56:419 : w ap 0 reg 16 xPSR (0x01000000)
18:02:56:432 : w ap 0 @0x20000D80 : 0x00000200 bytes, Data 0x00000000...
18:02:56:432 : w ap 0 @0x20000000 : 0x00000004 bytes, Data 0x0000BE00...
18:02:56:434 : w ap 0 @0x20000004 : 0x00000954 bytes, Data 0xF000B580...
18:02:56:434 : Loader write range...
18:02:56:434 : w ap 0 @0x20000D80 : 0x00000C40 bytes, Data 0x20050000...
18:02:56:434 : W B1 in RAM @0x20000D80 size 0x00000C40 : 0006ms
18:02:56:434 : Init flashloader...
18:02:56:434 : halt ap 0
18:02:56:435 : w ap 0 reg 0 R0 0x00000001
18:02:56:435 : w ap 0 reg 1 R1 0x00000000
18:02:56:436 : w ap 0 reg 2 R2 0x00000000
18:02:56:436 : w ap 0 reg 3 R3 0x00000000
18:02:56:436 : w ap 0 reg 4 R4 0x00000000
18:02:56:437 : w ap 0 reg 5 R5 0x00000000
18:02:56:437 : w ap 0 reg 6 R6 0x00000000
18:02:56:437 : w ap 0 reg 7 R7 0x00000000
18:02:56:437 : w ap 0 reg 8 R8 0x00000000
18:02:56:438 : w ap 0 reg 9 R9 0x00000000
18:02:56:439 : w ap 0 reg 10 R10 0x00000000
18:02:56:448 : w ap 0 reg 11 R11 0x00000000
18:02:56:449 : w ap 0 reg 12 R12 0x00000000
18:02:56:450 : w ap 0 reg 13 SP 0x00000000
18:02:56:450 : w ap 0 reg 14 LR 0x20000001
18:02:56:451 : w ap 0 reg 15 PC 0x20000005
18:02:56:451 : w ap 0 reg 16 xPSR 0x01000000
18:02:56:452 : w ap 0 reg 17 MSP 0x20000D54
18:02:56:452 : w ap 0 reg 18 PSP 0x00000000
18:02:56:453 : run ap 0
18:02:56:455 : halt ap 0
18:02:56:455 : r ap 0 reg 0 R0 0x00000001
18:02:56:455 : w ap 0 reg 0 R0 0x08000000
18:02:56:456 : w ap 0 reg 1 R1 0x00000C40
18:02:56:456 : w ap 0 reg 2 R2 0x20000D80
18:02:56:457 : w ap 0 reg 3 R3 0x00000002
18:02:56:457 : w ap 0 reg 4 R4 0x00000000
18:02:56:457 : w ap 0 reg 5 R5 0x00000000
18:02:56:457 : w ap 0 reg 6 R6 0x00000000
18:02:56:457 : w ap 0 reg 7 R7 0x00000000
18:02:56:457 : w ap 0 reg 8 R8 0x00000000
18:02:56:457 : w ap 0 reg 9 R9 0x00000000
18:02:56:458 : w ap 0 reg 10 R10 0x00000000
18:02:56:458 : w ap 0 reg 11 R11 0x00000000
18:02:56:458 : w ap 0 reg 12 R12 0x00000000
18:02:56:458 : w ap 0 reg 13 SP 0x00000000
18:02:56:458 : w ap 0 reg 14 LR 0x20000001
18:02:56:458 : w ap 0 reg 15 PC 0x2000004D
18:02:56:458 : w ap 0 reg 16 xPSR 0x01000000
18:02:56:458 : w ap 0 reg 17 MSP 0x20000D54
18:02:56:458 : w ap 0 reg 18 PSP 0x00000000
18:02:56:458 : run ap 0
18:02:56:468 : w ap 0 @0x200019C0 : 0x00000C40 bytes, Data 0x61BB4013...
18:02:56:468 : W B2 in RAM @0x20028580 size 0x00000C40: 0023ms
18:02:56:470 : r ap 0 reg 0 R0 0x00000001
18:02:56:470 : Wait W B1 in Flash @0x08000000 size 0x00000C40: 0003ms
18:02:56:471 : w ap 0 reg 0 R0 0x08000C40
18:02:56:471 : w ap 0 reg 1 R1 0x00000C40
18:02:56:472 : w ap 0 reg 2 R2 0x200019C0
18:02:56:473 : w ap 0 reg 3 R3 0x00000002
18:02:56:473 : w ap 0 reg 4 R4 0x00000000
18:02:56:474 : w ap 0 reg 5 R5 0x00000000
18:02:56:475 : w ap 0 reg 6 R6 0x00000000
18:02:56:476 : w ap 0 reg 7 R7 0x00000000
18:02:56:476 : w ap 0 reg 8 R8 0x00000000
18:02:56:476 : w ap 0 reg 9 R9 0x00000000
18:02:56:476 : w ap 0 reg 10 R10 0x00000000
18:02:56:477 : w ap 0 reg 11 R11 0x00000000
18:02:56:477 : w ap 0 reg 12 R12 0x00000000
18:02:56:477 : w ap 0 reg 13 SP 0x00000000
18:02:56:477 : w ap 0 reg 14 LR 0x20000001
18:02:56:477 : w ap 0 reg 15 PC 0x2000004D
18:02:56:477 : w ap 0 reg 16 xPSR 0x01000000
18:02:56:478 : w ap 0 reg 17 MSP 0x20000D54
18:02:56:478 : w ap 0 reg 18 PSP 0x00000000
18:02:56:478 : run ap 0
18:02:56:495 : r ap 0 reg 0 R0 0x00000001
18:02:56:496 : Write elapsed time: 0051ms
18:02:56:497 : Segment[0] downloaded successfully
18:02:56:497 : File download complete
18:02:56:514 : Time elapsed during download operation: 00:00:00.288
18:02:56:516 : Verifying ...
18:02:56:517 : Read progress:
18:02:56:518 : Reading data...
18:02:56:532 : r ap 0 @0x08000000 0x00001880 bytes Data 0x20050000
18:02:56:532 : Download verified successfully
18:02:56:562 : RUNNING Program ...
18:02:56:562 : Address: : 0x08000000
18:02:56:571 : w ap 0 reg 15 PC 0x08000791
18:02:56:572 : w ap 0 reg 17 MSP 0x20050000
18:02:56:572 : w ap 0 reg 16 xPSR 0x01000000
18:02:56:572 : Application is running, Please Hold on...
18:02:56:572 : Start operation achieved successfully




STM32CubeIDE:


STMicroelectronics ST-LINK GDB server. Version 7.3.0
Copyright (c) 2023, STMicroelectronics. All rights reserved.

Starting server with the following options:
Persistent Mode : Disabled
Logging Level : 1
Listen Port Number : 61234
Status Refresh Delay : 15s
Verbose Mode : Disabled
SWD Debug : Enabled
InitWhile : Enabled

Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
-------------------------------------------------------------------
STM32CubeProgrammer v2.13.0
-------------------------------------------------------------------

 

Log output file: C:\Users\Vilius\AppData\Local\Temp\STM32CubeProgrammer_a16920.log
ST-LINK SN : 002800363331511134333834
ST-LINK FW : V3J12M3B5S1
Board : STLINK-V3SET
Voltage : 3.20V
SWD freq : 8000 KHz
Connect mode: Under Reset
Reset mode : Hardware reset
Device ID : 0x449
Revision ID : Rev Z
Device name : STM32F74x/STM32F75x
Flash size : 1 MBytes
Device type : MCU
Device CPU : Cortex-M7
BL Version : 0x90
Debug in Low Power mode enabled

 

Memory Programming ...
Opening and parsing file: ST-LINK_GDB_server_a16920.srec
File : ST-LINK_GDB_server_a16920.srec
Size : 6.12 KB
Address : 0x08000000


Erasing memory corresponding to segment 0:
Erasing internal memory sector 0
Download in Progress:


File download complete
Time elapsed during download operation: 00:00:00.310

 

Verifying ...

 


Download verified successfully


Shutting down...
Exit.

In both cases logs seem to be indicating successful flash event, but result is the same, no voltage level toggling on on PC14 pin (I checked all 100 of the MCU pins, just to be sure that I did not mess up the numbering, no voltage toggling was detected on any of those...)

As this is my very first program, please excuse and mention even the most obvious things that are usually done working with STM32s. Maybe there is some hidden project option, maybe there is some specific reset procedure etc. Basically, anything that could prevent the MCU from working, as the code is so simple, thats its unlikely to be causing the fault. Thank you in advance




1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

> GPIO_InitStruct.Pin = GPIO_PIN_13;

>    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, 1);

You're initializing PC13 but you're toggling PC14.

 

The posted code should be toggling PC13. Debug and step through the program and watch bit 14 in the GPIOC->IDR and GPIOC->ODR registers after the HAL_GPIO_Write statements. Both should be toggling. If they're toggling in the cpu but not on your board, the pin isn't hooked up to whatever you're monitoring. If only ODR is toggling, the pin is likely shorted to something holding it low or high.

You can view registers in the SRFs window (Window -> Show View -> SFRs)

You can program the chip without NRST connected--no surprise there, although it's helpful to connect NRST to allow the programmer to do a hardware reset, or connect under reset.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3

Perhaps run in the debugger, see what's happening? Step the code.

PC14 is not designed for much current, it's in the low power domain.

Have Error_Handler also blink LED, or output to another, or via a UART so it doesn't just die in silence.

void Error_Handler(void)
{
  while(1) // Fast-Blink with IRQ's enabled to signal fault
  {
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, 1);
    HAL_Delay(200);
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, 0);
    HAL_Delay(200);
  }
}

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TDK
Guru

> GPIO_InitStruct.Pin = GPIO_PIN_13;

>    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, 1);

You're initializing PC13 but you're toggling PC14.

 

The posted code should be toggling PC13. Debug and step through the program and watch bit 14 in the GPIOC->IDR and GPIOC->ODR registers after the HAL_GPIO_Write statements. Both should be toggling. If they're toggling in the cpu but not on your board, the pin isn't hooked up to whatever you're monitoring. If only ODR is toggling, the pin is likely shorted to something holding it low or high.

You can view registers in the SRFs window (Window -> Show View -> SFRs)

You can program the chip without NRST connected--no surprise there, although it's helpful to connect NRST to allow the programmer to do a hardware reset, or connect under reset.

If you feel a post has answered your question, please click "Accept as Solution".
Vilius
Associate II

Thank you very much, that was a true beginners mistake of mine