cancel
Showing results for 
Search instead for 
Did you mean: 

ST-LINK error (DEV_TARGET_NOT_HALTED)

Doc McStuffins
Associate

I am currently working on a bootloader using the NUCLEO-F446RE development board, which consists of a program that erases sectors 3-7 of the MCU's flash memory to create space for a program. When run my bootloader's erase function and then attempt to re-program the board using the "debug" button in the STM32CubeIDE, I get the following error on the console, and the board refuses to be reprogrammed:

STMicroelectronics ST-LINK GDB server. Version 5.2.3
Copyright (c) 2019, 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
 
Waiting for debugger connection...
Debugger connected
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.1.0                  
      -------------------------------------------------------------------
 
 
 
Log output file:   C:\Users\johnm\AppData\Local\Temp\STM32CubeProgrammer_a10620.log
ST-LINK SN  : 066DFF485151717867194350
ST-LINK FW  : V2J34M25
Voltage     : 3.25V
Error: ST-LINK error (DEV_TARGET_NOT_HALTED)
Encountered Error when opening C:\ST\STM32CubeIDE_1.0.1\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_1.0.0.201904021149\tools\bin\STM32_Programmer_CLI.exe
Error in STM32CubeProgrammer

This issue is only present when I use HAL drivers to erase a portion of the flash memory of the chip, as shown in the below code snippet. I do not believe that I am erasing any of my code, as the flash erase starts in sector 3, and the build size of my program is ~42Kbytes, which should only take up sectors 0-2.

HAL_StatusTypeDef status = HAL_FLASH_Unlock();
	if (status != HAL_OK) {
		DPRINT("unable to unlock flash before erasing, status 0x%x\n", status);
	}
 
	FLASH_EraseInitTypeDef erase_init;
	erase_init.TypeErase = FLASH_TYPEERASE_SECTORS;
	erase_init.Banks = FLASH_BANK_1;
	erase_init.Sector = FLASH_SECTOR_3;
	erase_init.NbSectors = 5; // erase sectors 3-7
	erase_init.VoltageRange = FLASH_VOLTAGE_RANGE_3;
	uint32_t sector_error;
 
	status = HAL_FLASHEx_Erase(&erase_init, &sector_error);
	if (status != HAL_OK) {
		DPRINT("error erasing firmware sector 0x%lx, status 0x%x\n", sector_error, status);
	} else {
		DPRINT("erased all firmware sectors\n");
	}
 
	status = HAL_FLASH_Lock();
	if (status != HAL_OK) {
		DPRINT("unable to lock flash before erasing, status 0x%x\n", status);
	}

Currently, the workaround to this issue that I have found is to connect to the board with the STM32 ST-Link Utility and perform a full chip erase before reconnecting and programming successfully with STM32CubeIDE. However, this workflow is slow and rather cumbersome. I have done my best to find any information about the DEV_TARGET_NOT_HALTED error but have so far found nothing. Is this a bug with STM32CubeIDE, or with my code? Some tips or assistance would be greatly appreciated!

11 REPLIES 11

This worked for me...

  • The same error, when using ST STD PERIPH library specifically to erase flash sector 4 on NUCLEO-F446RE dev.
  • One more observation is the issue doesn't happen when all the sectors in the range 4-7 are erased.
  • rk8266882_0-1715275419686.png