STM32F405xx thread not waking up

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

Moderator: RoccoMarco

Post Reply
mitchy_g
Posts: 2
Joined: Wed Oct 28, 2015 12:16 am

STM32F405xx thread not waking up

Post by mitchy_g »

Hi All,

I am going through the noble quest of trying to run Chibios RT (3.0.2) without including HAL. I am also increasing the challenge by using Crossworks (GCC) as my compiler/debugger.

I have RT building and starting up (using Chibios startup and linker) on an STM32F405 dev board.

My code is currently the basic threaded LED blinker.

Code: Select all

#include "ch.h"

static THD_WORKING_AREA(waThread1, 128);
static THD_FUNCTION(Thread1, arg) {

  (void)arg;
  while (true)
  {
    GPIOC->ODR |= (1 << 12);
    chThdSleepMilliseconds()(500);
    GPIOC->ODR |= (0 << 12);
    chThdSleepMilliseconds(500);
  }
}

void
main(void)
{
    chSysInit();

   //
   // SNIP (GPIO initialisation code)
   //

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

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



My chconf.h is setup to _not_ use tickless mode.

Code: Select all

#define CH_CFG_ST_RESOLUTION                32
#define CH_CFG_ST_FREQUENCY                 10000
#define CH_CFG_ST_TIMEDELTA                 0
#define CH_CFG_TIME_QUANTUM                 0
#define CH_CFG_MEMCORE_SIZE                 0
#define CH_CFG_NO_IDLE_THREAD               FALSE


Basically I can never get the chThdSleepMilliseconds functions to return and continue processing. The code just loops through the "_idle_thread(void *p)" function.

I went through the HAL clock initialization code yesterday and played around with some different clock modes but nothing would help me progress.

My current thoughts are:
- Am I missing some sort of SysTick interrupt activation code? Because the idle thread is sitting there just doing the "port_wait_for_interrupt();" loop.

- I saw a few threads on the forum where people we sleeping in the main thread and this caused problems?

- Am I having some sort of stack issue? I have defined the following linker options:
--defsym=__main_stack_size__=0x1000
--defsym=__process_stack_size__=0x400

- I tried to look for how the OS attached to the SysTick timer but haven't found it yet.

Am I on the right track?

Any help would be much appreciated.

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

Re: STM32F405xx thread not waking up

Post by Giovanni »

Hi,

It is definitely a missing systick interrupt. Have you seen the HAL-less demos in 3.0.x? Under \demos\various

Giovanni
mitchy_g
Posts: 2
Joined: Wed Oct 28, 2015 12:16 am

Re: STM32F405xx thread not waking up

Post by mitchy_g »

Thanks Giovanni,

The HAL-less example is exactly what I needed to get it running.

Had to play around a bit with CH_CFG_ST_FREQUENCY to stop instability (10000 it seems, was too high)

I also noticed a potential issue with the generic HAL-less example code for Cortex M0 & M4 examples;

main.c line 67

Code: Select all

SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk |
                  SysTick_CTRL_ENABLE_Msk;


The SysTick_CTRL_ENABLE_Msk mask is duplicated. However I am unsure if this mask contains the TICKINT (enable systick interrupt) enable bit as well as the ENABLE (enable systick timer) bit?

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

Re: STM32F405xx thread not waking up

Post by Giovanni »

10000 is too high or not too high depending on a variety of factors, in general 1000 is used in ticked mode.

Instability can be caused by a lot of things, especially using startup files and ld files not designed for the RTOS. Generic startups in general don't do the required initializations.

Giovanni
Post Reply