Page 1 of 1

STM32F0 Discovery problem

Posted: Fri Nov 09, 2012 7:23 pm
by steved
New to ChibiOS and STM chips, so may be a simple solution.

I'm using ChibiStudio with OpenOCD 0.6.1 to compile and run a simple program on an STM32F0 Discovery board.
Debug enabled - specifically:
#define CH_DBG_SYSTEM_STATE_CHECK TRUE

In the call from chSysInit(), the program crashes with error SV#3 - 'misplaced chSysEnable()'.
(If debug is disabled, the program crashes with 'Unhandled exception')

If I simply load the program into flash, and run without the JTAG debugger, it runs as expected.

Program is as follows (essentially the standard LED flashing program):

Code: Select all

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

/*
 * Blue LED blinker thread, times are in milliseconds.
 */
static WORKING_AREA(waThread1, 128);
__attribute__((noreturn)) static msg_t Thread1(void *arg)
{
  (void)arg;
  chRegSetThreadName("blinker1");
  while (TRUE)
  {
    palClearPad(GPIOC, GPIOC_LED4);
    chThdSleepMilliseconds(500);
    palSetPad(GPIOC, GPIOC_LED4);
    chThdSleepMilliseconds(500);
  }
}


int main(void)
{
  halInit();
  chSysInit();

  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  while (TRUE) {
    chThdSleepMilliseconds(500);
  }
}

Any suggestions as to the problem, or how to debug it?

Re: STM32F0 Discovery problem

Posted: Fri Nov 09, 2012 7:38 pm
by Giovanni
Hi,

Does the standard demo behave in the same way?

Giovanni

Re: STM32F0 Discovery problem

Posted: Mon Nov 12, 2012 2:41 pm
by steved
Giovanni wrote:Does the standard demo behave in the same way?
Giovanni

On a quick test, yes (in fact, it was probably the starting point for my program, which I have stripped down).

I'll try and dig deeper later.

Re: STM32F0 Discovery problem

Posted: Wed Nov 14, 2012 9:16 am
by steved
I should perhaps have mentioned that I am using the latest SVN - 2.5.x version.

I think some, at least, of my problems are due to a lack of appreciation of how to set up debugging with the Discovery. After some research I've basically got things configured as per the setup on http://www.chibios.org/dokuwiki/doku.php?id=chibios:guides:eclipse2 - although not working yet (I can't even run or step the program ATM, where I could before).

Re: STM32F0 Discovery problem

Posted: Wed Nov 14, 2012 9:46 am
by Giovanni
Hi,

I tested the demo using the default ChibiStudio and it works regardless the CH_DBG_SYSTEM_STATE_CHECK setting. Are you specifying the correct .cfg file to openocd? there is one specific for the F0-discovery under ./scripts/board

Giovanni

Re: STM32F0 Discovery problem

Posted: Fri Nov 23, 2012 2:59 pm
by steved
Mostly sorted now - does still crash sometimes (usually after loading changed code).
Not 100% certain, but partly I wasn't starting OpenOCD in the project directory. I also modified the startup 'script' in the debug configuration, which appeared to help. Plus the usual bit of trying to find the way round a different programming environment, and missing things for the first to fifth times!