# STM32F303RET's core is always halted after programming

I have an STM32F303RET MCU with Eclipse, Cross ARM GCC and HAL library environment. I am using an STM32F4Discovery board as SWD programmer. My problem is when I download the hex file to the MCU I got the following message:

Connected via SWD.
Target voltage = 2.9 V.
Connection mode : Normal.
Device ID:0x446
Device flash Size : 512 Kbytes
Device family :STM32F302xE/F303xE/F398xx

Flash Programming:
File : Line_Sensors2.hex
Memory programming...
0% ................................. 100%
Memory programmed in 1s and 358ms.
Programming Complete.

MCU Reset.

The core is halted!

My current configuration in STM32CUBEMX with an external 8MHz crystal is:

Soure files, generated by STM32CubeMX:

main.c

/* Includes ------------------------------------------------------------------*/
#include "stm32f3xx_hal.h"
#include "mxconstants.h"

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

int main(void)
{
/* MCU Configuration----------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* Configure the system clock */
SystemClock_Config();

/* Initialize all configured peripherals */
MX_GPIO_Init();

while (1)
{
HAL_GPIO_WritePin(GPIOB, D42_LED_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOB, D43_LED_Pin, GPIO_PIN_SET);
}
}

/** System Clock Configuration
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL2;
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
HAL_RCC_OscConfig(&RCC_OscInitStruct);

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);

HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

/** Configure pins as
* Analog
* Input
* Output
* EVENT_OUT
* EXTI
*/
void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;

/* GPIO Ports Clock Enable */
__GPIOF_CLK_ENABLE();
__GPIOA_CLK_ENABLE();
__GPIOB_CLK_ENABLE();

/*Configure GPIO pins : D42_LED_Pin D43_LED_Pin */
GPIO_InitStruct.Pin = D42_LED_Pin|D43_LED_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}


stm32f3xx_hal_msp.c:

/* Includes ------------------------------------------------------------------*/
#include "stm32f3xx.h"
#include "stm32f3xx_hal.h"
#include "stm32f3xx_hal_cortex.h"
/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
__SYSCFG_CLK_ENABLE();

HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);

/* System interrupt init*/
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}


stm32f3xx_it.c:

/* Includes ------------------------------------------------------------------*/
#include "stm32f3xx_hal.h"
#include "stm32f3xx.h"
#include "stm32f3xx_it.h"

/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
HAL_IncTick();
HAL_SYSTICK_IRQHandler();
}


I have tried with the internal oscillator (calibrated to 8MHz) as PLL source, and without PLL. Also tried with different PLLMUL and PLLDIV values. The results are all the same, core is halted after programming.

I do not have any breakpoints, I do not even use debug session, I just simply download the hex file to the controller. The voltage on the reset pin is 2.96V.

I am flashing the device with ST-LINK_CLI, arguments are the following:

-c SWD -p  \${project_name}.hex  -Rst -Run


The -Run always fails as the core is halted.

I am out of ideas, I do not know what can be the problem here. Something is missing from the HAL project, but I do not know what since CubeMX should generate all necessary initialization.

Update

I was able to successfully program the MCU using SPL library so the problem must be HAL library specific. The programmer/debugger should be OK.

• Missing compiler or linker parameters could also be a problem, please post them. Nov 14 '15 at 20:51
• I add them right away. Nov 14 '15 at 20:58
• @Turbo J, I have added some more details, let me know if there is something else. Nov 14 '15 at 21:18
• You need to figure out if this is a program problem or a debugger one. Best ways to do that are either flashing a known-good example, or else writing a very simple program to toggle an I/O or generate serial output, flashing it, and then power cycling the board without the debugger connected. Nov 14 '15 at 21:36
• The current code is consits of a clock configuration part and I am setting two IO to HIGH state, to lit up LEDs. I have tried to reset the MCU after disconnecting the programmer, no success. Debugger is unavailable as I did not find any usable config file with OpenOCD. @Chris , do you know any known-good example? Nov 14 '15 at 21:46

Have you seen this settings page? This is why my debugger halts before debugging:

• I don't, and going to check right away. But unfortunately the core is halted when I do not used debug just downloaded the hex file with external tool (St-Link Utility). But it is a useful answer, thanks for it. Nov 15 '15 at 17:07

I have managed to solve the problem. The problem itself was the whole Eclipse project. I have tried to put together a project for the F3 using HAL based on the F4 HAL Eclipse project template. I must say that some details (necessary files or configurations) lost, and all in all the code could not run on the MCU.

## To highlight one:

The file vectors_stm32f4xx.c (project/system/src/cmsis directory) should contain the startup code when MCU resets, and it is provided by the F4 Eclipse template. In my case I had to use an assembler file provided by ST, STM32CubeMX.

The file is startup_stm32f303xe.s. Now, since Eclipse is not able to manage files ending with .s, I should have changed the file extension to .S (capital 's'). I did not change the file extension so the MCU probably could not start up after reset. Maybe this was the biggest problem.

## The complete soultion:

I have found a detailed description about how to use Eclipse + STM32Cube + any STM32 controller. Unfortunately it is too long to include all of it on here, so I just provide a link and hope it will stay available. It worked fine for me.