Threads not working on a STM32F4

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

Moderators: barthess, RoccoMarco

FlorianB
Posts: 2
Joined: Sat Apr 05, 2014 7:23 pm

Threads not working on a STM32F4

Postby FlorianB » Sat Apr 05, 2014 7:37 pm

Hi everyone!

I hope I am in the right board, not sure if its a generic or a STM32 problem. I try to run ChibiOS on a STM32F4-Board from Waveshare. Nothing special connected, just the basics at the moment. I try to run the following code (removed the includes and such):

Code: Select all

#define TEST_WA_SIZE    THD_WA_SIZE(256)
static WORKING_AREA(waThread, 256);

static msg_t TestThread(void *arg) {
    while (TRUE) {
        palTogglePad(GPIOI, 10);
//        chThdSleepMicroseconds(1);
    }
    return 0;
}

int main(void) {
    uint8_t i=0;

    halInit();
    chSysInit();

    palSetPadMode(GPIOH,  2, PAL_MODE_OUTPUT_PUSHPULL);
    palSetPadMode(GPIOI, 10, PAL_MODE_OUTPUT_PUSHPULL);

    for (i=0;i<10;i++) {
        palTogglePad(GPIOH, 2);
    }
    for (i=0;i<10;i++) {
        palClearPad(GPIOH, 2);
    }

    (void)chThdCreateStatic(waThread, sizeof(waThread), NORMALPRIO, TestThread, NULL);

    for (i=0;i<10;i++) {
        palTogglePad(GPIOH, 2);
    }
    for (i=0;i<10;i++) {
        palClearPad(GPIOH, 2);
    }

    while (TRUE) {
        palTogglePad(GPIOH, 2);
//        chThdSleepMicroseconds(1);
    }
    return 0;
}


The Thread isnt working at all, the Pin is not toggling. Running the same command in main works, so I guess its not the hardware.
Uncommeting one of the sleeps: The system stops at that point. But even when commented out, it stops after exactly 20ms.

At the moment I haven't even an idea where to look for the error. Can someone please push me into the right direction? Thanks!

jscott
Posts: 129
Joined: Tue Jul 03, 2012 3:50 pm
Location: Middle Georgia, USA
Contact:

Re: Threads not working on a STM32F4

Postby jscott » Sat Apr 05, 2014 7:58 pm

Is this the STM32F4-discovery board?

Which demo program are you trying to use?

What tool chain are you using?

Anything else you can tell us about your setup?

Thanks
-John Scott

User avatar
Giovanni
Site Admin
Posts: 13012
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 745 times
Been thanked: 621 times
Contact:

Re: Threads not working on a STM32F4

Postby Giovanni » Sat Apr 05, 2014 9:16 pm

It is because both threads don't release the CPU, they are scheduled using round-robin and the interval is 20mS.

Note that you cannot sleep 1uS, the system resolution is limited by the system tick.

Giovanni

FlorianB
Posts: 2
Joined: Sat Apr 05, 2014 7:23 pm

Re: Threads not working on a STM32F4

Postby FlorianB » Sun Apr 06, 2014 11:02 am

I finally found the problem, as always it was rather simple. I had an error in the Makefile, so CORTEX_USE_FPU=TRUE was not set. That messed everything up... Thanks for the quick answers, the 1us sleep would have been my next problem I guess :-)

MuratUrsavas
Posts: 8
Joined: Mon May 12, 2014 11:29 am

Re: Threads not working on a STM32F4

Postby MuratUrsavas » Mon May 12, 2014 11:41 am

While trying to learn ChibiOS/RT I've faced with the same issue. As I'm not using a makefile based setup I'm setting some of the required parameters by myself in the toolchain settings. It turned out that if I not define the "CORTEX_USE_FPU" parameter, the compilation goes just fine but the MCU is trapped in an unhandled exception at the register store phase exactly at here:

Code: Select all

#if CORTEX_USE_FPU
  asm volatile ("vpush   {s16-s31}" : : : "memory");
#endif


My style is to create a compilation error for all the "required but not set" parameters. As this situation creates a silent runtime issue, maybe requesting this parameter from the developer could be a good idea.

This could be done maybe somewhere else and I could be missing it as I'm a ChibiOS/RT newbie. But this was what I've experienced in the first place.

FYI: I'm trying to find a way to integrate ChibiOS/RT with EMBlocks and running it successfully right now. At least blinking a LED :)

User avatar
Giovanni
Site Admin
Posts: 13012
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 745 times
Been thanked: 621 times
Contact:

Re: Threads not working on a STM32F4

Postby Giovanni » Mon May 12, 2014 1:09 pm

Hi,

Probably you are not using the provided startup files and .ld file, there a lot of FPU-related initialization details to be considered.

Giovanni

MuratUrsavas
Posts: 8
Joined: Mon May 12, 2014 11:29 am

Re: Threads not working on a STM32F4

Postby MuratUrsavas » Thu May 15, 2014 5:16 am

Hi Giovanni,

Yes, as I said I'm not using the provided makefiles but started based on master makefile, which is the STM32F429-DISCO example (using the provided linker script). I might miss the required definitions there. It was just a suggestion to have a smoother newbie experience.

User avatar
Giovanni
Site Admin
Posts: 13012
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 745 times
Been thanked: 621 times
Contact:

Re: Threads not working on a STM32F4

Postby Giovanni » Thu May 15, 2014 8:44 am

Hi,

It is set-up for a smooth newbie experience... you use what is included and it just works. If you start modifying the environment then you are moving out of the newbie zone :)

Are you using the ChibiOS startup file (crt0.c), there are important initializations inside.

Giovanni

MuratUrsavas
Posts: 8
Joined: Mon May 12, 2014 11:29 am

Re: Threads not working on a STM32F4

Postby MuratUrsavas » Sun May 18, 2014 11:29 am

You are right. I confess, it was out of the newbie zone :)

Regarding to "crt0.c", yes, I tried to include everything ChibiOS offers. To do that I took the makefile of the STM32F429I-DISCO example. At first I tried to build with another linker script but seen that it's not possible without some modfications. As I said before, the toolchain I'm using is not makefile based, this is why I can not use the provided makefiles.

Anyway, right now I'm in a good position and have a working setup. Now I'll try to do something tickless, which is necessary for the things in my mind.

User avatar
Giovanni
Site Admin
Posts: 13012
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 745 times
Been thanked: 621 times
Contact:

Re: Threads not working on a STM32F4

Postby Giovanni » Sun May 18, 2014 11:33 am

Creating non-Makefile projects is possible, for example there are projects for IAR and Keil which are not based on Makefiles.

Just make sure to use the startups and scatter files provided with ChibiOS initially.

Giovanni


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 9 guests