Author Topic: My STM32F031 Refuses to Run  (Read 886 times)

0 Members and 1 Guest are viewing this topic.

Offline Ground_LoopTopic starter

  • Frequent Contributor
  • **
  • Posts: 645
  • Country: us
My STM32F031 Refuses to Run
« on: October 28, 2023, 10:33:16 pm »
I'm trying to expand my base a bit by getting into STM micros.  I have a few STM32F031 micros that I have been trying to blink an LED on.  I'm using STM IDE, STM PRG and ST Link V2 on Apple M1 silicon.  PRG will connect to the mico only if all the ST Link lines are connected.  I can download the hex file and confirm by reading it back out through PRG.  IDE will only see the device if I first connect to it in PRG then disconnect and then it connects maybe once every dozen attempts.  On the rare occasion that IDE does see the device it will download the file.

The micro setup is to use the internal oscillator with clock output on pin 29.  I have also tried an external crystal.  Download is SWD.The code is a simple HAL toggle and HAL delay to flash the LED.  It's a dirt simple program taken from an internet example.  The device was setup through IOC. 

Once the file is downloaded the LED does not flash and the clock output pin is dead.  I try a restart, reset pin low and high, Boot 0 high and low.  I go to the CPU screen in PRG and can step through the program and see the PC register increment.  If I select Run, I lose the connection. I've tried multiple MCUs with the same result;  IT WILL NOT RUN.  I'm sure it's some simple bone head mistake, but so far it eludes me.

main.c below

Code: [Select]
/* USER CODE BEGIN Header */

#include "main.h"


/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);

int main(void)
{

  HAL_Init();

  SystemClock_Config();

  MX_GPIO_Init();

  while (1)
  {

    HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
    HAL_Delay(500);

  }

}


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

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL8;
  RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  {
    Error_Handler();
  }
  HAL_RCC_MCOConfig(RCC_MCO, RCC_MCO1SOURCE_SYSCLK, RCC_MCODIV_1);
}

static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};


  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOF_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LED_1_GPIO_Port, LED_1_Pin, GPIO_PIN_SET);

  /*Configure GPIO pin : LED_1_Pin */
  GPIO_InitStruct.Pin = LED_1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(LED_1_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : PA8 */
  GPIO_InitStruct.Pin = GPIO_PIN_8;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

}

void Error_Handler(void)
{

  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
« Last Edit: October 28, 2023, 11:11:27 pm by Ground_Loop »
There's no point getting old if you don't have stories.
 

Offline wek

  • Frequent Contributor
  • **
  • Posts: 495
  • Country: sk
Re: My STM32F031 Refuses to Run
« Reply #1 on: October 29, 2023, 07:29:42 am »
What hardware, a "known-good" board like Nucleo or Disco, or your own? What is the power arrangement, decoupling? Are *all* gound and power pins connected (including VDDA/VSSA if present on given package)?

JW
 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: My STM32F031 Refuses to Run
« Reply #2 on: October 29, 2023, 08:57:20 am »
Post the ioc file!
Likely a bad connection somewhere, post pictures of your setup.
As Wek said, which board?

Ensure SWD (Serial Wire Debug) and systick are enabled in System Core / SYS tab.
Without SWD you will always need nRST to access the mcu (This need adjusting in Launch configuration / Reset behaviour / Type=Hardware reset) , while HAL_Delay depends on Systick.
With SWD enabled it will be a lot easier, just make sure SWD pins (PA13/PA14) aren't used by anything else!
« Last Edit: October 29, 2023, 09:14:13 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline Ground_LoopTopic starter

  • Frequent Contributor
  • **
  • Posts: 645
  • Country: us
Re: My STM32F031 Refuses to Run
« Reply #3 on: October 29, 2023, 11:39:32 am »
Pics below with IOC file.  I have verified all signals and power to the chip pin.  As I said earlier, I can read back the code after download, so its at least getting there.

Code: [Select]
#MicroXplorer Configuration settings - do not modify
CAD.formats=
CAD.pinconfig=
CAD.provider=
File.Version=6
GPIO.groupedBy=Group By Peripherals
KeepUserPlacement=false
Mcu.CPN=STM32F031C4T6
Mcu.Family=STM32F0
Mcu.IP0=NVIC
Mcu.IP1=RCC
Mcu.IP2=SYS
Mcu.IPNb=3
Mcu.Name=STM32F031C(4-6)Tx
Mcu.Package=LQFP48
Mcu.Pin0=PC13
Mcu.Pin1=PA0
Mcu.Pin2=PA8
Mcu.Pin3=PA13
Mcu.Pin4=PA14
Mcu.Pin5=VP_SYS_VS_Systick
Mcu.PinsNb=6
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F031C4Tx
MxCube.Version=6.9.2
MxDb.Version=DB.6.0.92
NVIC.ForceEnableDMAVector=true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.SVC_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
NVIC.SysTick_IRQn=true\:3\:0\:false\:false\:true\:false\:true\:false
PA0.Mode=SYS_WakeUp0
PA0.Signal=SYS_WKUP1
PA13.Locked=true
PA13.Mode=Serial_Wire
PA13.Signal=SYS_SWDIO
PA14.Mode=Serial_Wire
PA14.Signal=SYS_SWCLK
PA8.Mode=Clock-out
PA8.Signal=RCC_MCO
PC13.GPIOParameters=GPIO_Speed,PinState,GPIO_Label,GPIO_ModeDefaultOutputPP
PC13.GPIO_Label=LED_1
PC13.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_PP
PC13.GPIO_Speed=GPIO_SPEED_FREQ_LOW
PC13.Locked=true
PC13.PinState=GPIO_PIN_SET
PC13.Signal=GPIO_Output
PinOutPanel.RotationAngle=0
ProjectManager.AskForMigrate=true
ProjectManager.BackupPrevious=false
ProjectManager.CompilerOptimize=6
ProjectManager.ComputerToolchain=false
ProjectManager.CoupleFile=false
ProjectManager.CustomerFirmwarePackage=
ProjectManager.DefaultFWLocation=true
ProjectManager.DeletePrevious=true
ProjectManager.DeviceId=STM32F031C4Tx
ProjectManager.FirmwarePackage=STM32Cube FW_F0 V1.11.4
ProjectManager.FreePins=false
ProjectManager.HalAssertFull=false
ProjectManager.HeapSize=0x200
ProjectManager.KeepUserCode=true
ProjectManager.LastFirmware=true
ProjectManager.LibraryCopy=1
ProjectManager.MainLocation=Core/Src
ProjectManager.NoMain=false
ProjectManager.PreviousToolchain=
ProjectManager.ProjectBuild=false
ProjectManager.ProjectFileName=STM32_Again.ioc
ProjectManager.ProjectName=STM32_Again
ProjectManager.ProjectStructure=
ProjectManager.RegisterCallBack=
ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=STM32CubeIDE
ProjectManager.ToolChainLocation=
ProjectManager.UAScriptAfterPath=
ProjectManager.UAScriptBeforePath=
ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true
RCC.AHBFreq_Value=32000000
RCC.APB1Freq_Value=32000000
RCC.APB1TimFreq_Value=32000000
RCC.FCLKCortexFreq_Value=32000000
RCC.FamilyName=M
RCC.HCLKFreq_Value=32000000
RCC.I2SFreq_Value=32000000
RCC.IPParameters=AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,I2SFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLDivider,PLLMCOFreq_Value,PLLMUL,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USART1Freq_Value,VCOOutput2Freq_Value
RCC.MCOFreq_Value=32000000
RCC.PLLCLKFreq_Value=32000000
RCC.PLLDivider=RCC_PREDIV_DIV2
RCC.PLLMCOFreq_Value=32000000
RCC.PLLMUL=RCC_PLL_MUL8
RCC.SYSCLKFreq_VALUE=32000000
RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
RCC.TimSysFreq_Value=32000000
RCC.USART1Freq_Value=32000000
RCC.VCOOutput2Freq_Value=4000000
VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
board=custom
isbadioc=false

1914330-0

1914342-1

[ Specified attachment is not available ]

1914348-3

Cube IDE was able to connect this morning.  Here's the output:

Code: [Select]
Log output file:   /tmp/STM32CubeProgrammer_mhHHxm.log
ST-LINK SN  : 38FF6E06304E4B3014171943
ST-LINK FW  : V2J42S7
Board       : --
Voltage     : 3.29V
SWD freq    : 4000 KHz
Connect mode: Under Reset
Reset mode  : Hardware reset
Device ID   : 0x444
Revision ID : Rev 1.0
Device name : STM32F03x
Flash size  : 16 KBytes
Device type : MCU
Device CPU  : Cortex-M0
BL Version  : 0x10



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


Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 4]
Download in Progress:


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



Verifying ...




Download verified successfully


Shutting down...
Exit.

Still won't run.  When I go back and connect with PRG and look at CPU page the core state reports Halted.  Someting strange though.  Voltage on reset pin 7 is .7 V.  I attached a 56K pullup and no change to voltage.

« Last Edit: October 29, 2023, 01:04:51 pm by Ground_Loop »
There's no point getting old if you don't have stories.
 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: My STM32F031 Refuses to Run
« Reply #4 on: October 29, 2023, 12:48:57 pm »
Add a 100nF cap between nRST-GND for noise stability, no need for pullup.
BOOT0 should be always low to run from the flash.
You forgot VDDA/VSSA pins. VDDA is not only for the ADC, but also for the PLL!
Also follow the reference power decoupling, it seems you're using only 2x 100nF?
At least, put 1uF+100nF to every VDD(A) pin.

« Last Edit: October 29, 2023, 01:03:58 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: Ground_Loop

Offline Ground_LoopTopic starter

  • Frequent Contributor
  • **
  • Posts: 645
  • Country: us
Re: My STM32F031 Refuses to Run
« Reply #5 on: October 29, 2023, 01:38:54 pm »
As I suspected, bone head mistake.  VSSA and VDDA were the problem.  Thanks David.

Add a 100nF cap between nRST-GND for noise stability, no need for pullup.
BOOT0 should be always low to run from the flash.
You forgot VDDA/VSSA pins. VDDA is not only for the ADC, but also for the PLL!
Also follow the reference power decoupling, it seems you're using only 2x 100nF?
At least, put 1uF+100nF to every VDD(A) pin.

(Attachment Link)
There's no point getting old if you don't have stories.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14481
  • Country: fr
Re: My STM32F031 Refuses to Run
« Reply #6 on: October 30, 2023, 12:27:07 am »
As I suspected, bone head mistake.  VSSA and VDDA were the problem.  Thanks David.

This mistake is more common than you'd think. Many people tend to assume that the "analog" power supply pins of MCUs can be left open if no analog peripheral is used, and this is rarely the case in practice.
Same for Microchip MCUs. Here you can suspect that the PLL was just not running as DavidAlfa pointed out. In some datasheets, while they usually recommend a powering scheme in which VDDA pins are connected, they do not always explain why, and I've already seen engineers do the same mistake as you did here.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf