stm32f103vct6 freeze after chThdSleepMilliseconds() - IAR

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

stm32f103vct6 freeze after chThdSleepMilliseconds() - IAR

Post by DeusExMachina »

I use device with stm32f103vct6 and I tried to used Chibios example for Olimex board. So I changed CPU type in IAR project options to ST STM32F10xxC, changed STM32F10X_MD to STM32F10X_HD in board.h, and changed pins and hw declarations. Program compiles and debugs well, but when I use chThdSleepMilliseconds() program freezes. Debugging shows that error occurs it chSchGoSleepS(newstate); line in chSchGoSleepTimeoutS function in
chschd.c.
What it can be? thanks
IAR 6.3.10.2075
DrunkenDonkey
Posts: 124
Joined: Sun Aug 28, 2011 5:16 pm

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Post by DrunkenDonkey »

Got exactly the same days ago, was overflowing the stack in one of the threads, and yeah, program was working fine till it reaches the sleep.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Post by Giovanni »

You don't give me much info to work with but it looks like there is something wrong with stacks.

Does changing device change some other options too? compare your project with the original project carefully (all option tabs). You have to adjust the scatter file too, note that you have to use the one provided with the OS.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Post by Giovanni »

DD posted before me :-)

There is a reason about why it does happen when the sleep is invoked, during the chSchGoSleepS() the system pushes all registers in the stack so in most cases the overflow happens right in that moment.

Please activate the debug options, the stack checking should work in that case and confirm this.

Giovanni
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Post by DeusExMachina »

code is almost the same as in demo (comments stripped)
How can I encrease stacks size?

Code: Select all

#include "ch.h"
#include "hal.h"
#include "test.h"

static WORKING_AREA(waThread1, 128);
static msg_t Thread1(void *arg)
{

  (void)arg;
  chRegSetThreadName("blinker");
  while (TRUE)
  {
    palSetPad(GPIOD, 5);
    chThdSleepMilliseconds(500);
    palClearPad(GPIOD, 5);
  }
}

int main(void)
{
  AFIO->MAPR |= 3;
 
  halInit();

  chSysInit();

  sdStart(&SD2, NULL);
 
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  while (TRUE)
  {
   if (palReadPad(GPIOC, 5))
      TestThread(&SD2);
    chThdSleepMilliseconds(500);
  }
}
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Post by DeusExMachina »

when i press break button in iar during debugging (after freeze) in disassembler window i see this:

Code: Select all

IRQSTACK$$Base:
   0x20000000: 0x20008000     ANDCS     R8, R0, R0
   0x20000004: 0x20000125     ANDCS     R0, R0, R5, LSR #2 << execution cursor is there >>
   0x20000008: 0x5dc549dd     STCLPL    p9, C4, [R5, #0x374]
   0x2000000c: 0x9daf3ee1     STCLS     p14, C3, [PC, #0x384]!
   0x20000010: 0x88dfafc0     LDMHI     PC, {R6-R11, SP, PC}^   ; Exception return
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Post by Giovanni »

Giovanni wrote:Please activate the debug options, the stack checking should work in that case and confirm this.


Did you try this?
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Post by DeusExMachina »

I don't know how to do this in IAR... I only found Stack view window, but it shows only C-stack which seems to be static during all program execution...
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Post by Giovanni »

Debug options are activated in chconf.h, there are several of them, enable assertions, checks and stack overflow checks at least.

http://www.chibios.org/dokuwiki/doku.ph ... ebug_guide

Giovanni
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Post by DeusExMachina »

oh, thank you... :oops:
Post Reply