cancel
Showing results for 
Search instead for 
Did you mean: 

[Suggestion, Fix] Swap SystemClock_Config() & HAL_Init()

valentin
Senior
Posted on January 16, 2017 at 04:37

Edit:

Seems as if this wasn't a permanent fix. It still happens ... but why?

I then always have to step through the HAL_Init & sysclockcfg functions until the timer is started. Only then can I resume the program in free running mode.

--------------------

Hi,

I'm using FreeRTOS with TIM14 as clock source on an STM32F2 and I noticed that if I just click restart during a debugging session, it would fail.

After investigating a bit, it seems that the reason is that the tick interrupt register of TIM14 wasn't cleared and therefore the mcu hangs during interrupt enabling in HAL_Init().

To fix this, I swapped SystemClock_Config() and HAL_Init() at the beginning of the main function. Now it works.

Is there any downside to this practice? If not, I suggest using this procedure per default.

Any opinions?

int main(void) {
 /* USER CODE BEGIN 1 */
 NVIC->ICPR[1] = 0xffffffff; // clear all pending bits
 /* USER CODE END 1 */
 /* MCU Configuration----------------------------------------------------------*/
 /* Configure the system clock */
 SystemClock_Config();
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();
 /* Initialize all configured peripherals */
...
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Note: Line #4 was me trying to clear those bits. Didn't work. But doesn't harm the code either.

#debug #timbase #hang #restart #freertos
2 REPLIES 2
Adalgiso
Associate II
Posted on February 02, 2017 at 14:12

Hi,

I had the same kind of trouble. I modified the vector table offset like this

int main(void)

{

/* USER CODE BEGIN 1 */

/* Set the Vector Table base location at 0x08000000 */

//SCB->VTOR = FLASH_BASE | 0x00000; /* Vector Table Relocation in Internal FLASH */

/* USER CODE END 1 */

/* MCU Configuration----------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

/* Configure the system clock */

SystemClock_Config();

....

Otherwise make sure that in file system_stm32f2xx.c  VECT_TAB_SRAM is commented

************************* Miscellaneous Configuration ************************/

/*!< Uncomment the following line if you need to use external SRAM mounted

on STM322xG_EVAL board as data memory */

/* #define DATA_IN_ExtSRAM */

/*!< Uncomment the following line if you need to relocate your vector Table in

Internal SRAM. */

//#define VECT_TAB_SRAM

#define VECT_TAB_OFFSET 0x0000 /*!< Vector Table base offset field.

This value must be a multiple of 0x200. */

/******************************************************************************/
Posted on February 06, 2017 at 20:29

Hi

Castrignano.Adalgiso

‌,

thanks for your reply. It seems to work so far. I'll further test it.

Much appreciated!