Problem on a F407VG board

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: utzig, lbednarz, tfAteba, barthess, RoccoMarco

Posts: 3
Joined: Mon Nov 30, 2020 10:30 am
Been thanked: 1 time

Problem on a F407VG board

Postby guig73 » Mon Nov 30, 2020 12:16 pm

Hello everybody.

I already have been successful to use ChibiOS with the STM32F103 and STMF411 pills.

But I currently struggle a bit with this board :

My board version uses a STM32F407VGT6.
I’ve copied the RT-STMF4-discovery example project, which has the same MCU, and started to setup the board with the board configuration tool, as I did for my other projects.

I’ve simplified it as the simplest possible, just starting the OS and blink the LED.

The HAL and MCU config also the simplest, with only PAL activated.

The sleep in the main function is 1000ms, and the blinker is 500ms ON and 500ms OFF.
When I debug the program, I see the first sleep in the main is executed correctly, but when it comes to the first sleep of the blinker thread, the board reboots as I can see it executes again the init function where I set a breakpoint.
It seems to fail when the context switch happens as I can enter the context switch function.

Code: Select all

 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 See the License for the specific language governing permissions and
 limitations under the License.

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

 * This is a periodic thread that does absolutely nothing except flashing
 * a LED.
static THD_WORKING_AREA(waThread1, 128);
static THD_FUNCTION(Thread1, arg) {

  while (true) {
    palSetPad(GPIOA, GPIOA_ONBOARD_LED_D2); /* green. */
    palClearPad(GPIOA, GPIOA_ONBOARD_LED_D2); /* green.  */

 * Application entry point.
int main(void) {

   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.

   * Creates the example thread.
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO - 1, Thread1, NULL);

   * Normal main() thread activity, in this demo it does nothing except
   * sleeping in a loop and check the button state.
  while (true) {

If I set the sleep in the main function is 100ms and the blinker to both 50ms, the program runs fine.

According to the website above, the HSE osc is 16Mhz.
Whereas the F4 discovery has a 8Mhz osc.
It would be better if I read correctly the specs.... :roll:

Could it come from this difference ?
Could the PLL setup is totally to rethink in this case ?
I have just dumbly copied the mcuconf.h from the F4 disco.

Or would it have another reason ?

The option bytes show a HW or SW watchdog option.
I’ve modified it, but seems to have no effect here.

Any suggestion to debug it would be very welcome.

Thank you very much.

User avatar
Site Admin
Posts: 13527
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 861 times
Been thanked: 743 times

Re: Problem on a F407VG board

Postby Giovanni » Mon Nov 30, 2020 6:19 pm

If the external oscillator has the same frequecy then mcuconf.h should not change, if it has a different frequency you just need to adjust the PLL input divider "M" (if I remember well).

Other differences are all in board files, you need to create board files for that board.


Posts: 3
Joined: Mon Nov 30, 2020 10:30 am
Been thanked: 1 time

Re: Problem on a F407VG board

Postby guig73 » Mon Dec 07, 2020 1:31 pm

Thank you for your help Giovanni.

Code: Select all

 * HAL driver system settings.
#define STM32_NO_INIT                       FALSE
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0
#define STM32_BKPRAM_ENABLE                 FALSE
#define STM32_HSI_ENABLED                   FALSE
#define STM32_LSI_ENABLED                   FALSE
#define STM32_HSE_ENABLED                   TRUE
#define STM32_LSE_ENABLED                   TRUE
#define STM32_CLOCK48_REQUIRED              TRUE
#define STM32_SW                            STM32_SW_PLL
#define STM32_PLLSRC                        STM32_PLLSRC_HSE
 * Clock input for the PLL
 * => 1Mhz
#define STM32_PLLM_VALUE                    8
 * VCO clock
 * => 336Mhz
#define STM32_PLLN_VALUE                    336
 * The SYSCLK from the PLL
#define STM32_PLLP_VALUE                    2
 * The 48MHz clock
#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_LSE
#define STM32_RTCPRE_VALUE                  8
#define STM32_MCO1SEL                       STM32_MCO1SEL_HSE
#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

I've checked with the doc each values and enabled the setting for using the HSE clock (8MHz)

It does exactly the result.

It looks like there is a kind of watchdog that prevent longer sleep intevals...

Posts: 3
Joined: Mon Nov 30, 2020 10:30 am
Been thanked: 1 time

Re: Problem on a F407VG board

Postby guig73 » Mon Dec 07, 2020 1:44 pm

Ah ! Eureka !
I've found the problem !

It was indeed due to a WDT.
The WDT_SW switch in option bytes was not checked, probably due to the initial application inside the MCU.
Since I checked it, it runs fine !

If my trouble could help someone else...

Thank you for your help anyway.

Return to “General Support”

Who is online

Users browsing this forum: No registered users and 4 guests