chThdSleep strange behaviour

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

Moderator: RoccoMarco

am3syl
Posts: 11
Joined: Wed Jan 13, 2016 12:37 pm

chThdSleep strange behaviour

Post by am3syl »

Hello guys,

First of all, thanks for this tremendous work. ChibiOS is great !

I have some trouble with a custom board using a STM32F427IIT6. It is probably a configuration problem because I have reduced the code to :

Code: Select all

int main(void) {

halInit();
chSysInit();

chThdSleepMicroseconds(250);

while (TRUE) {
chThdSleepMicroseconds(250);
}
}


I use ChibiOS 16.1.
In debug mode the chThdSleepMicroseconds function never end ( debugger is lost at line 338 of chschd.c )

My chconf.h have all the values at the default values.
Nothing is activated in halconf.h

My mcuconf.h:

Code: Select all

#define STM32F4xx_MCUCONF

/*
 * HAL driver system settings.
 */
#define STM32_NO_INIT                       FALSE
#define STM32_HSI_ENABLED                   TRUE
#define STM32_LSI_ENABLED                   TRUE
#define STM32_HSE_ENABLED                   TRUE
#define STM32_LSE_ENABLED                   FALSE
#define STM32_CLOCK48_REQUIRED              TRUE
#define STM32_SW                            STM32_SW_PLL
#define STM32_PLLSRC                        STM32_PLLSRC_HSE
#define STM32_PLLM_VALUE                    24
#define STM32_PLLN_VALUE                    336
#define STM32_PLLP_VALUE                    2
#define STM32_PLLQ_VALUE                    7
#define STM32_HPRE                          STM32_HPRE_DIV1
#define STM32_PPRE1                         STM32_PPRE1_DIV4
#define STM32_PPRE2                         STM32_PPRE2_DIV2
#define STM32_RTCSEL                        STM32_RTCSEL_LSI
#define STM32_RTCPRE_VALUE                  8
#define STM32_MCO1SEL                       STM32_MCO1SEL_HSI
#define STM32_MCO1PRE                       STM32_MCO1PRE_DIV1
#define STM32_MCO2SEL                       STM32_MCO2SEL_SYSCLK
#define STM32_MCO2PRE                       STM32_MCO2PRE_DIV5
#define STM32_I2SSRC                        STM32_I2SSRC_CKIN
#define STM32_PLLI2SN_VALUE                 192
#define STM32_PLLI2SR_VALUE                 5
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0
#define STM32_BKPRAM_ENABLE                 FALSE


Code works on other platforms ( stm32f7discovery with the demo config files )

Any idea of what happens?

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

Re: chThdSleep strange behaviour

Post by Giovanni »

Hi,

You need to stop the target and see where it hangs, enabling usual debug options in chconf.h is also a good idea.

Being a custom board it could be a problem with the oscillator. Try booting using HSI.

Giovanni
am3syl
Posts: 11
Joined: Wed Jan 13, 2016 12:37 pm

Re: chThdSleep strange behaviour

Post by am3syl »

The program is in the infinite loop of the idle_thread, waiting for a timer interrupt which never came ( port_wait_for_interrupt ).

As you said it's probably the oscillator but I tried to change to HSI with:

Code: Select all

#define STM32F4xx_MCUCONF

/*
 * HAL driver system settings.
 */
#define STM32_NO_INIT                       FALSE
#define STM32_HSI_ENABLED                   TRUE
#define STM32_LSI_ENABLED                   TRUE
#define STM32_HSE_ENABLED                   FALSE
#define STM32_LSE_ENABLED                   FALSE
#define STM32_CLOCK48_REQUIRED              TRUE
#define STM32_SW                            STM32_SW_HSI
#define STM32_PLLSRC                        STM32_PLLSRC_HSI
#define STM32_PLLM_VALUE                    16
#define STM32_PLLN_VALUE                    336
#define STM32_PLLP_VALUE                    2
#define STM32_PLLQ_VALUE                    7
#define STM32_HPRE                          STM32_HPRE_DIV1
#define STM32_PPRE1                         STM32_PPRE1_DIV4
#define STM32_PPRE2                         STM32_PPRE2_DIV2
#define STM32_RTCSEL                        STM32_RTCSEL_LSI
#define STM32_RTCPRE_VALUE                  8
#define STM32_MCO1SEL                       STM32_MCO1SEL_HSI
#define STM32_MCO1PRE                       STM32_MCO1PRE_DIV1
#define STM32_MCO2SEL                       STM32_MCO2SEL_SYSCLK
#define STM32_MCO2PRE                       STM32_MCO2PRE_DIV5
#define STM32_I2SSRC                        STM32_I2SSRC_CKIN
#define STM32_PLLI2SN_VALUE                 192
#define STM32_PLLI2SR_VALUE                 5
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0
#define STM32_BKPRAM_ENABLE                 FALSE


The problem remains, I will check the oscillator path entirely with MCO pin.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chThdSleep strange behaviour

Post by Giovanni »

Hi,

It is normal to break it in the idle loop, are you sure it does not exit chthdSleep()? try compiling using -O0 and place breakpoints, optimizations make those unreliable.

Giovanni
am3syl
Posts: 11
Joined: Wed Jan 13, 2016 12:37 pm

Re: chThdSleep strange behaviour

Post by am3syl »

Yes I'm sure, the timer associate to system tick doesn't count even with HSI clock. I replace the stm32f427 by another but same thing happens.

I'm already in O0 optimisation.

It's look like a bad configuration or hardware malfunction. I will start over from scratch.
am3syl
Posts: 11
Joined: Wed Jan 13, 2016 12:37 pm

Re: chThdSleep strange behaviour

Post by am3syl »

Errata the timer count but very slowly, probably prescaler settings
am3syl
Posts: 11
Joined: Wed Jan 13, 2016 12:37 pm

Re: chThdSleep strange behaviour

Post by am3syl »

Forget the posts above, I'm sure of nothing :(

How I can ensure the chthdSleep is not exited? There is a interrupt to watch or something?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chThdSleep strange behaviour

Post by Giovanni »

Hi,

Look at the "st" (systick) driver, file name is /os/hap/ports/STM32/TIMv1/st_lld.c, timer ISRs are there, you could put a breakpoint there.

This is used for all the demos so it is unlikely a problem there. You most likely have a settings problem.

Giovanni
am3syl
Posts: 11
Joined: Wed Jan 13, 2016 12:37 pm

Re: chThdSleep strange behaviour

Post by am3syl »

Some details:

Its seems I never go in the systick ISR.

TIM2 is higher than the CCR1 value, the compare/capture flag is set but no interrupt happens.

I will check the interrupt register and vectors things.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chThdSleep strange behaviour

Post by Giovanni »

Are you using startups, vectors and ld files provided with ChibiOS?

Giovanni
Post Reply