Can't restart debugger without reloading code

Discuss how to use the features of Atollic TrueSTUDIO, including the editor, assembler, C/C++ compiler, linker, debugger, static code analysis and team collaboration tools.

Moderators: Markus Girdland, Mattias Norlander

dirkvermaak
Posts: 11
Joined: Mon Dec 11, 2017 11:22 am
Location: United Kingdom
Contact:

Re: Can't restart debugger without reloading code

Postby dirkvermaak » Fri May 18, 2018 5:27 pm

I have a theory (not yet proven). When you restart all it does is set the PC to the Main(). The underlying interrupts are still enabled and the timers are running. You then go in and fiddle with the clocks in HAL_Init() and they go nuts. It's because it's not performing a chip reset, just moving the PC about.

Of course this could cause other nasty problems.
Andibee Ltd.
Loughborough
Leicestershire
LE11 3SJ

dirkvermaak@andibee.co.uk

Designing with STM32 since 2007

dirkvermaak
Posts: 11
Joined: Mon Dec 11, 2017 11:22 am
Location: United Kingdom
Contact:

Re: Can't restart debugger without reloading code

Postby dirkvermaak » Sat May 19, 2018 4:38 pm

Ok so an update, the problem is caused by *NOT* using the SysTick timer for the HAL System tick. (Which is the case if you are running FreeRTOS). I have built the simplest project possible for a NUCLEO-F401RE board and when I use the SysTick timer it restarts properly using the button.

When I then swap the source to TIM11 it works just the same until I use the Restart button. Then , the code runs until it configures the timer, and the interrupt starts. Then it seems to flat chat in the interrupt handler but never increment the HAL Tick Counter.

So this is why a lot of people never see or complain about the problem. It doesn't affect them.

Next question is why it does this, which is my next investigation.
Andibee Ltd.
Loughborough
Leicestershire
LE11 3SJ

dirkvermaak@andibee.co.uk

Designing with STM32 since 2007

dirkvermaak
Posts: 11
Joined: Mon Dec 11, 2017 11:22 am
Location: United Kingdom
Contact:

Re: Can't restart debugger without reloading code

Postby dirkvermaak » Sat May 19, 2018 5:37 pm

EASY SOLUTION - but not very elegant as you have to modify the HAL auto generated code.

The problem lies in the stm32f4xx_hal_timebase_TIM.c file at Line 85.

Code: Select all

HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
  RCC_ClkInitTypeDef    clkconfig;
  uint32_t              uwTimclock = 0;
  uint32_t              uwPrescalerValue = 0;
  uint32_t              pFLatency;
 
  /*Configure the TIM5 IRQ priority */
  HAL_NVIC_SetPriority(TIM5_IRQn, TickPriority ,0);

 /* Enable the TIM5 global Interrupt */
  HAL_NVIC_EnableIRQ(TIM5_IRQn);

  /* Enable TIM5 clock */
  __HAL_RCC_TIM5_CLK_ENABLE();
 
  /* Get clock configuration */
  HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
 


On the run immediately after a restart, as soon as this interrupt is enabled you jump straight to the handler and flat chat around the interrupt.This doesn't happen the first time you run the code after you enter the debugger. If you comment out the two lines that configure the interrupt and then put them in at line 118 as shown below...

Code: Select all

  htim5.Init.Period = (1000000 / 1000) - 1;
  htim5.Init.Prescaler = uwPrescalerValue;
  htim5.Init.ClockDivision = 0;
  htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
  if(HAL_TIM_Base_Init(&htim5) == HAL_OK)
  {
   /*Configure the TIM5 IRQ priority */
    HAL_NVIC_SetPriority(TIM5_IRQn, TickPriority ,0);

   /* Enable the TIM5 global Interrupt */
   HAL_NVIC_EnableIRQ(TIM5_IRQn);

    /* Start the TIM time Base generation in interrupt mode */
    return HAL_TIM_Base_Start_IT(&htim5);


It all seems to work. I've tried this on our basic projects and on our current FreeRTOS project and it seems to have no ill effect.

Of course a better solution would be to not have to mod the HAL code so I will try and find out why it behaves differently, it may be that we can add a line or two in the main.c to make it a bit easier.
Andibee Ltd.
Loughborough
Leicestershire
LE11 3SJ

dirkvermaak@andibee.co.uk

Designing with STM32 since 2007

dirkvermaak
Posts: 11
Joined: Mon Dec 11, 2017 11:22 am
Location: United Kingdom
Contact:

Re: Can't restart debugger without reloading code

Postby dirkvermaak » Mon May 21, 2018 7:05 am

Additional Information

In the end, the solution I posted above proved unreliable. We found that the DMA controllers suffered the same problem although it seemed more intermittent. Basically, the restart button doesn't Reset the peripherals properly and so you get unreliable behaviour. I guess for a lot of configurations it doesn't matter but if you get complicated it does.

Anyway I've found a solution that does work for us.

Code: Select all

int main(void)
{
  /* USER CODE BEGIN 1 */

  /* This check looks at the pre-scale register of the HAL TIC timer. If previously configured */
  /* then we have not had a 'proper' reset at restart (debugger) and so we should cause one */
  if (TIM5->PSC != 0)
  {
   HAL_NVIC_SystemReset();
  }   
  /* USER CODE END 1 */


So, as the first line of code, insert a test to see if something has previously been configured. In our case we use TIM5 as the HAL_SysTick() timer and using the Restart button leaves this with a value in it. So far this works perfectly, the debug continues and we get normal behaviour. You can always adapt the test to your particular peripherals.
Andibee Ltd.
Loughborough
Leicestershire
LE11 3SJ

dirkvermaak@andibee.co.uk

Designing with STM32 since 2007

aurelienr
Posts: 3
Joined: Thu Aug 09, 2018 4:42 pm

Re: Can't restart debugger without reloading code

Postby aurelienr » Thu Aug 09, 2018 4:48 pm

Hello,
I'm starting my first project on STM32 and FreeRTOS, and obviously I encountered the same issue :|
The work around given in the last post works well, thank you very much !
Just a question : why do you test the Timer state before reseting NVIC : I mean, why you don't reset NVIC systematically without testing timer config ? In what cases would my statement interefere with the system ?

Thanks
Aurelien

dirkvermaak
Posts: 11
Joined: Mon Dec 11, 2017 11:22 am
Location: United Kingdom
Contact:

Re: Can't restart debugger without reloading code

Postby dirkvermaak » Thu Aug 09, 2018 5:06 pm

Because you go into an infinite loop on the first run of the program. You would just always reset and never get started. Only reset if you've previously been configured .

Glad this helps. I have raised it with the ST guys at a conference and hope it will get properly fixed sometime.
Andibee Ltd.
Loughborough
Leicestershire
LE11 3SJ

dirkvermaak@andibee.co.uk

Designing with STM32 since 2007

aurelienr
Posts: 3
Joined: Thu Aug 09, 2018 4:42 pm

Re: Can't restart debugger without reloading code

Postby aurelienr » Thu Aug 09, 2018 5:15 pm

OK, next time I will check what the function really do...I was thinking it was only to reset interrupts, but since it's the whole system, my question is just stupid :)
Thanks anyway

Mattias Norlander
Posts: 273
Joined: Fri Apr 29, 2016 10:01 am

Re: Can't restart debugger without reloading code

Postby Mattias Norlander » Wed Aug 29, 2018 9:27 am

dirkvermaak wrote:Additional Information

Code: Select all

int main(void)
{
  /* USER CODE BEGIN 1 */

  /* This check looks at the pre-scale register of the HAL TIC timer. If previously configured */
  /* then we have not had a 'proper' reset at restart (debugger) and so we should cause one */
  if (TIM5->PSC != 0)
  {
   HAL_NVIC_SystemReset();
  }   
  /* USER CODE END 1 */



+1 for that solution ;-)

The Restart button in TS only resets the Program Counter. We are aware of it. We are trying some stuff to see if this can be easily solved across all supported cores. We believe that this is only an issue on the cortex-m4 cores.

If anyone has the same problem on core != m4 then please let us know!

aurelienr
Posts: 3
Joined: Thu Aug 09, 2018 4:42 pm

Re: Can't restart debugger without reloading code

Postby aurelienr » Wed Aug 29, 2018 3:16 pm

Mattias Norlander wrote:If anyone has the same problem on core != m4 then please let us know!

Hi,
I got the same problem on F207 device.

Aurelien

Mattias Norlander
Posts: 273
Joined: Fri Apr 29, 2016 10:01 am

Re: Can't restart debugger without reloading code

Postby Mattias Norlander » Fri Aug 31, 2018 9:42 am

aurelienr wrote:I got the same problem on F207 device.

OK - confirmed, the problem is on M3/M4/M7. We hope to have a fix in next release in some weeks.


Return to “Atollic TrueSTUDIO tool discussions”

Who is online

Users browsing this forum: No registered users and 1 guest