chThdSleepMilliseconds crashes

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
A319
Posts: 48
Joined: Thu Feb 05, 2015 9:52 am
Has thanked: 2 times
Been thanked: 3 times

chThdSleepMilliseconds crashes

Post by A319 »

Good afternoon,

I'm currently writing a bootloader for the STM32F407 Discovery board. Im flashing by a serial connection writing the first bytes at position 0x0801 0000. The bootloader which I'm using is taken from a STM32F3-Bootloader. Now I wanna boot a demo program which looks like this:

Code: Select all

int main(void)
{
   halInit();

   uint32_t i;
   palSetPadMode(GPIOE, 8, PAL_MODE_OUTPUT_PUSHPULL);

   while (TRUE) {
      palSetPad(GPIOE, 8);

      for(i=0; i<0xFFFFFF; i++)
         palSetPad(GPIOE, 0); // NOP

      palClearPad(GPIOE, 8);

      for(i=0; i<0xFFFFFF; i++)
         palClearPad(GPIOE, 0); // NOP
   }
}


It does its job but as soon I'm going to replace the NOP parts by chThdSleepMilliseconds() the whole system freezes. I've tried to debug whats going on. The MCU is finally freezing at point:
0x08000cc0: b.n 0x8000cc0 <_unhandled_exception>

My idea is, that I probably forgot to disable a specific timer in the bootloader. Thats my bootloader code:

Code: Select all

#define FLASH_USER_BASE 0x08000000
#define FW_BASE 0x10000

static void jumpToApp(uint32_t address)
{
   //SysMemBootJump=(void (*)(void)) (*((u32 *) address));

   typedef void (*pFunction)(void);
   pFunction Jump_To_Application;
   /* variable that will be loaded with the start address of the application */
   vu32* JumpAddress;
   const vu32* ApplicationAddress = (vu32*)address;
   /* get jump address from application vector table */
   JumpAddress = (vu32*) ApplicationAddress[1];
   /* load this address into function pointer */
   Jump_To_Application = (pFunction) JumpAddress;

   /* reset all interrupts to default */
   chSysDisable();

   /* Clear pending interrupts just to be on the save side*/
   SCB_ICSR = ICSR_PENDSVCLR;

   /* Disable all interrupts */
   int i;
   for(i=0; i<8; i++)
      NVIC->ICER[i] = NVIC->IABR[i];

   __set_MSP((u32) (ApplicationAddress[0]));
   Jump_To_Application();
}

void main() {
   // Doing some flashing actions
   jumpToApp(FLASH_USER_BASE + FW_BASE);
}



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

Re: chThdSleepMilliseconds crashes

Post by Giovanni »

hi,

Do you perform a chSysInit() in your application? it is not shown in the code you posted. Also, make sure to enable the debug options in chconf.h during development, those can catch most common problems.

Giovanni
A319
Posts: 48
Joined: Thu Feb 05, 2015 9:52 am
Has thanked: 2 times
Been thanked: 3 times

Re: chThdSleepMilliseconds crashes

Post by A319 »

Hi Giovanni,

Thanks for you fast answer. Indeed I've forgot chSysInit(). I inserted it at the beginning. But now the LED doesn't even light up. It just remains dark.
I've activated the debug options. I hoped, I could find out by the PC, where it stopped by the memory map.
OpenOCD (debug) tells me, that it holds at position: 0x08010250

Code: Select all

Info : halted: PC: 0x0800740e
Info : halted: PC: 0x08007410
Info : halted: PC: 0x08007412
Info : halted: PC: 0x08007414
Info : halted: PC: 0x08007418
Info : halted: PC: 0x0800741a
Info : halted: PC: 0x08010250


Regarding to the memory map there's the ResetHandler

Code: Select all

 .text.ResetHandler
                0x0000000008010250       0xf0 buildf4/obj/crt0.o
                0x0000000008010250                ResetHandler
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chThdSleepMilliseconds crashes

Post by Giovanni »

Hi,

You need also to relocate the vectors table and initialize the VTOR register to point at it. See the CORTEX_VTOR_INIT setting in the port layer. In general, when using bootloaders, you have to make sure that the bootloader undoes any initialization it performed before jumping to the application. The OS code in general expects a post-reset system state.

Giovanni
A319
Posts: 48
Joined: Thu Feb 05, 2015 9:52 am
Has thanked: 2 times
Been thanked: 3 times

Re: chThdSleepMilliseconds crashes

Post by A319 »

Hi,

Yes lights up again. But only this.
Just to get sure, the code now looks like this:

Code: Select all

#define CORTEX_VTOR_INIT   0x08010000

#include "hal.h"

/*
 * Application entry point.
 */
int main(void)
{
   chSysInit();
   halInit();

   palSetPadMode(GPIOE, 8, PAL_MODE_OUTPUT_PUSHPULL);

   while (TRUE) {
      palSetPad(GPIOE, 8);

      chThdSleepMilliseconds(10);

      palClearPad(GPIOE, 8);

      chThdSleepMilliseconds(10);
   }
}


I assume it again freezes at the sleep function.
A319
Posts: 48
Joined: Thu Feb 05, 2015 9:52 am
Has thanked: 2 times
Been thanked: 3 times

Re: chThdSleepMilliseconds crashes

Post by A319 »

BTW: Just to get sure, I removed everything I have in my bootloader except the jumping code. Unfortunately the same error occurs.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chThdSleepMilliseconds crashes

Post by Giovanni »

The VTOR setting should go in chconf.h (bottom section), not in the main.

Giovanni
A319
Posts: 48
Joined: Thu Feb 05, 2015 9:52 am
Has thanked: 2 times
Been thanked: 3 times

Re: chThdSleepMilliseconds crashes

Post by A319 »

Hi Giovanni,

that was exactly the problem. It works now.

Thanks a lot.
Post Reply