I'm trying to do a simple blinker thread example on a custom STM32F105 based board. The board has no external oscillator and is 100% functionnal (tested all peripherals in CubeMx).
So, I started from an existing ChibiOS project (ChibiOS/demos/STM32/RT-STM32F107-OLIMEX_P107-LWIP) and I tried to configure the clock so that it can use the internal clock.
Here is what I did in mcuconf.h:
Code: Select all
#define STM32F107_MCUCONF
/*
* HAL driver system settings.
*/
#define STM32_NO_INIT FALSE
#define STM32_HSI_ENABLED TRUE
#define STM32_LSI_ENABLED FALSE
#define STM32_HSE_ENABLED FALSE
#define STM32_LSE_ENABLED FALSE
#define STM32_SW STM32_SW_PLL
#define STM32_PLLSRC STM32_PLLSRC_HSI
//#define STM32_PREDIV1SRC STM32_PLLSRC_HSI
//#define STM32_PREDIV1_VALUE 2
//#define STM32_PLLMUL_VALUE 8
//#define STM32_PREDIV2_VALUE 1
//#define STM32_PLL2MUL_VALUE 8
//#define STM32_PLL3MUL_VALUE 8
//#define STM32_PPRE2 STM32_PPRE2_DIV1
//#define STM32_ADCPRE STM32_ADCPRE_DIV2
#define STM32_OTG_CLOCK_REQUIRED FALSE
#define STM32_OTGFSPRE STM32_OTGFSPRE_DIV3
#define STM32_I2S_CLOCK_REQUIRED FALSE
#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK
#define STM32_RTCSEL STM32_RTCSEL_NOCLOCK
#define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
And also what I have in board.h in order to avoid compilation error about
STM32_PLLxCLKIN outside acceptable range
Code: Select all
/*
* Board frequencies.
*/
#define STM32_LSECLK 0
#define STM32_HSECLK 25000000
The project is compiling fine without errors and warning but LED pin stay high and never blinks0.
I think LED pin is correctly configured:
Code: Select all
/*
* Port A setup.
* Everything input with pull-up except:
* PA8 - output push-pull (LED1).
* PA9 - output push-pull (LED2).
*/
#define VAL_GPIOACRL 0x88888888 /* PA7...PA0 */
#define VAL_GPIOACRH 0x88888833 /* PA15...PA8 */
#define VAL_GPIOAODR 0xFFFFFFFF
And for information, here is the main thread:
Code: Select all
#include "ch.h"
#include "hal.h"
/*
* Green LED blinker thread, times are in milliseconds.
*/
static THD_WORKING_AREA(waThread1, 128);
static THD_FUNCTION(Thread1, arg) {
(void)arg;
chRegSetThreadName("blinker");
while (TRUE) {
palClearPad(GPIOA, GPIOA_LED_1);
chThdSleepMilliseconds(500);
palSetPad(GPIOA, GPIOA_LED_1);
chThdSleepMilliseconds(500);
}
}
/*
* 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.
*/
halInit();
chSysInit();
/*
* Creates the blinker thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/*
* Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and check the button state.
*/
while (true) {
chThdSleepMilliseconds(500);
}
}
I wonder now what I'm doing wrong with the clock configuration and why LED is not blinking ?
I can provide the full project as a zip file if it is needed.
Thank you in advance,
Jeremy