cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] STM32G031J6-DISCO Can no longer program the chip (“No device found on target�?)

afvincent
Associate II

Hi,

I am trying to use an STM32G031J6-DISCO board to get a grasp on the 8-pin STM32G031J6 MCU that I consider for building small IoT sensors (for teaching purposes). I am new to STM32 products (or ST MCUs in general).

I managed to write a few variations of programs (with STM32CubeIDE v1.10.1 on Fedora 35) for blinking the built-in onboard user LED and playing with the built-in push-button as well. However, after rebooting my computer, the user LED is not blinking anymore and I now face an error message when I try to upload my code (using STM32CubeIDE):

STMicroelectronics ST-LINK GDB server. Version 7.0.0
Copyright (c) 2022, 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
 
Target no device found
 
Error in initializing ST-LINK device.
Reason: No device found on target.

I tried several times to power-cycle the board by unplugging and plugging the USB cable again. Without any success so far.

I also tried to update of the ST-Link/V2-1 using STLinkUpgrade 3.4.0. Based on p. 4 of the RN0093 release note regarding firmware V2J40M27, I opted for the “STM32 Debug+VCP�? type of firmware. As far as I can tell, the update of ST-Link/V2-1 was successful.

Unfortunately, when I try to connect to the MCU on the board using STM32CubeProgrammer v2.12.0 in order to attempt performing a “Full chip erase�?, I get the following error message

“Error: Connection to target must be established before performing the erase command.�?

even though the connection to the ST-Link/V2-1 seems to be OK as far as I can tell based on the top right panel (the displayed firmware version number is V2J40M27, as expected, and the feedback about the target voltage is 3.23 V, which seems reasonable to me). I played a bit with the options that are available in STM32CubeProgrammer, like reducing the SWD communication frequency (e.g. 100 kHz instead of the default 4 MHz value), using the “Under reset�? mode and “Hardware reset�? for the reset mode, but still without any success. When I click on the top right “Connect�? button, I always end up facing the following error message:

Error: No STM32 target found!

I read on the web that such an issue might be related to a faulty boot sequence, which is usually solved with pulling up the BOOT0 pin when powering up the device. However, the behavior of the BOOT0 pin in the STM32G031J6 MCU seems to be slightly different from what is usually used in other STM32 products. At least, pulling up the physical pin #8 of the MCU (which should be connected to BOOT0 according to Figure 10 in the STM32G031J6 datasheet ) did not change anything to my issue.

So far, I have been unable to tell if my issue is something that can be solved or if the MCU is definitively bricked. And if the chip can still be salvaged, could it be done “easily?�? In particular, I currently have a very restricted set of electronic tools at my disposal (at least for a few days). Basically the onboard ST-Link/V2-1, a couple wire jumpers and that is it…

Would there be another procedure or another hypothesis to test that I would have missed regarding my issue and that could help assessing the situation or finding a solution?

Best regards,

Adrien

1 ACCEPTED SOLUTION

Accepted Solutions
MM..1
Chief II

SO8 package is very tricky and need care special.

Try Connect modes in programmer and disconnect connect Idd jumper same time.

View solution in original post

11 REPLIES 11

Probably bricked.​

Want to add a startup delay prior to reconfiguring / reassigning​ pins on 8-pin devices.

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

What is your last code?

PDF : 3. PF2-NRST default functionnality is NRST, if used in this mode on SO8 and WLCSP, take particular care to configuration of other IOs connected to this pin.

How your last OB (option bytes)?

Is jumpers on Disco in right positions ?

All jumpers, i.e., the GND ones (CN5-CN8) and the IDD one (JP1), are closed.

I use the GUI “Device Configuration Tool�? in STM32CubeIDE to generate templates of programs (in C) that take care of setting up and initializing things like the I/O pins, the system clock, etc.

The program below was the one running correctly. It uses the PA12 pin as a digital output to blink the built-in user LED and the PF2 pin as a digital input to react to pressing the built-in push-button.

/* For length sake, almost all the comments
 * automatically generated by the “Device
 * Configuration Tool�? have been removed.
 */
 
#include "main.h"
#include <stdint.h>
#include <stdbool.h>
 
uint16_t half_period_ms = 100;
 
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
 
int main(void)
{
 
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
 
  while (1)
  {
 
      if (HAL_GPIO_ReadPin(GPIOF, GPIO_PIN_2) == GPIO_PIN_RESET) {
        half_period_ms = 125;
      } else {
        half_period_ms = 500;
      }
 
      // LED ON
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET);
      HAL_Delay(half_period_ms);
      // LED OFF
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
      HAL_Delay(half_period_ms);
  }
 
}
 
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 
  /** Configure the main internal regulator output voltage
  */
  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
 
  /** 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.HSIDiv = RCC_HSI_DIV1;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  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_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = 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};
 
  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOF_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
 
  /*Configure GPIO pin : PF2 */
  GPIO_InitStruct.Pin = GPIO_PIN_2;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
 
  /*Configure GPIO pin : PA12 */
  GPIO_InitStruct.Pin = GPIO_PIN_12;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
}
 
void Error_Handler(void)
{
  __disable_irq();
  while (1)  { }
}
 
#ifdef  USE_FULL_ASSERT
void assert_failed(uint8_t *file, uint32_t line) { }
#endif

And the other program below is the last one that I managed to load onto the board but that I could not test before having to switch off my computer. That program does not use the PF2 pin (unlike the previous program). It uses the channel CH1 of the timer TIM1 (which seems to be related to PA8 pin according to the “Device Configuration Tool�?), and the PA13 pin as an ADC input. I also kept the PA12 pin as a digital output because I was planning to perform some kind of user feedback per means of the built-in user LED in the future.

/* For length sake, almost all the comments
 * automatically generated by the “Device
 * Configuration Tool�? have been removed.
 */
 
#include "main.h"
#include <stdint.h>
 
TIM_HandleTypeDef htim1;
 
static int16_t duty_cycle_step = 70;
 
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_TIM1_Init(void);
 
int main(void)
{
 
  int32_t CH1_duty_cycle = 0;
 
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_TIM1_Init();
 
  HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
 
  while (1)
  {
	while(CH1_duty_cycle < 65535)
	{
		TIM1->CCR1 = CH1_duty_cycle;
		CH1_duty_cycle += duty_cycle_step;
		HAL_Delay(1);
	}
	while(CH1_duty_cycle > 0)
	{
		TIM1->CCR1 = CH1_duty_cycle;
		CH1_duty_cycle -= duty_cycle_step;
		HAL_Delay(1);
	}
  }
  
}
 
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 
  /** Configure the main internal regulator output voltage
  */
  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
 
  /** 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.HSIDiv = RCC_HSI_DIV1;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  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_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
}
 
static void MX_TIM1_Init(void)
{
 
  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  TIM_MasterConfigTypeDef sMasterConfig = {0};
 
  htim1.Instance = TIM1;
  htim1.Init.Prescaler = 0;
  htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim1.Init.Period = 65535;
  htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim1.Init.RepetitionCounter = 0;
  htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
  if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
  {
    Error_Handler();
  }
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }
 
}
 
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
 
  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOA_CLK_ENABLE();
 
  /*Configure GPIO pin : PA12 */
  GPIO_InitStruct.Pin = GPIO_PIN_12;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
  /*Configure GPIO pin : PA13 */
  GPIO_InitStruct.Pin = GPIO_PIN_13;
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
}
 
void Error_Handler(void)
{
  __disable_irq();
  while (1) { }
}
 
#ifdef  USE_FULL_ASSERT
void assert_failed(uint8_t *file, uint32_t line) { }
#endif

Hopefully this helps.

Edit: fixed a typo in the code snippet.

I am not sure that I totally understand your comment about adding a startup delay.

Do you mean that I should have added some `HAL_Delay(…)` instruction in the program before calling `MX_GPIO_Init()`? If so, what is the purpose of such a delay?

Or do you simply mean that I should have been more careful before starting to play with the alternative functions of the pins available of such an 8-pin chip due to the “muti-bonded pin feature�? that is a bit of a double-edge sword (and which may indeed be a bit tricky for a first experience with STM32 products)?

MM..1
Chief II

SO8 package is very tricky and need care special.

Try Connect modes in programmer and disconnect connect Idd jumper same time.

afvincent
Associate II

@MM..1​  Thank you, it seems like your suggestion worked :grinning_face: .

I removed the IDD jumper and used a bare wire to be able to make contact quickly when trying to connect to the board with STM32CubeProgrammer. The option that seemed to do the trick in my case was the Mode “Power Down�?. Once I managed to established a connection with the chip, I performed a “Full erase chip�? operation. I was then able to successfully upload my blinking LED test program that seems to be working correctly as far as I can tell.

I still do not really understand what I did wrong in the first place. Am I supposed to alter something in the configuration of the BOOT0 bit in order to try preventing such things from happening again or was it just very likely bad luck on my side in the first place?

Pin PA14 is also used as SWCLK and has a weak internal pull-down. The reference manual has a note on that in 7.3.1 General-purpose I/O (GPIO):

"PA14 is shared with BOOT0 functionality. Caution is required as the debugging device can

manipulate BOOT0 pin value."

If it is okay for you that the chip boots from Flash (with or without SWD debug probe attached), you can program the option bytes accordingly.

hth

KnarfB

I mean put an assembler spin-loop in Reset_Handler() as the process of connecting the debugger is not instantaneous, and you need some time for it to get some purchase before ploughing into regular code that might set up conflicting conditions.

Some of these devices bond out multiple pads to the pins, so it no longer just relates to PA13/PA14, but anything else that's sharing the physical pin. You're trying to broaden the connectivity window.

Say put 1,000,000 in r0, and decrement it in a NOP loop

Another approach is to have a mode in your device operation where you put the pins into a state the debugger can access, or you erase the device so that subsequent starts will go into the system loader.

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

Thanks for the information.

For the targeted application, the chip will (always) simply be programmed using the ST-Link on the DISCO demo board before being physically put into a dedicated socket on the IoT sensor node. So booting from Flash should be OK.