Page 1 of 3

stm32f103vct6 freeze after chThdSleepMilliseconds() - IAR

Posted: Fri Apr 13, 2012 9:48 am
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

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Posted: Fri Apr 13, 2012 10:00 am
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.

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Posted: Fri Apr 13, 2012 10:01 am
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

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Posted: Fri Apr 13, 2012 10:04 am
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

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Posted: Fri Apr 13, 2012 10:19 am
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);
  }
}

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Posted: Fri Apr 13, 2012 11:05 am
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

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Posted: Fri Apr 13, 2012 11:19 am
by Giovanni
Giovanni wrote:Please activate the debug options, the stack checking should work in that case and confirm this.


Did you try this?

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Posted: Fri Apr 13, 2012 11:42 am
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...

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Posted: Fri Apr 13, 2012 11:44 am
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

Re: stm32f103vct6 freeze after chThdSleepMilliseconds() - IA

Posted: Fri Apr 13, 2012 11:48 am
by DeusExMachina
oh, thank you... :oops: