I am new to Chibios and need some support getting started to configure my custom board.
Here is what I did so far but now I am a little lost...
I'd like to make the LED blink and communicate via USART.
I configured in mcuconf.h:
Code: Select all
#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 //STM32_PLLSRC_HSE
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
#define STM32_PLLMUL_VALUE 9
#define STM32_HPRE STM32_HPRE_DIV1
#define STM32_PPRE1 STM32_PPRE1_DIV2
#define STM32_PPRE2 STM32_PPRE2_DIV2
#define STM32_ADCPRE STM32_ADCPRE_DIV4
#define STM32_USB_CLOCK_REQUIRED TRUE
#define STM32_USBPRE STM32_USBPRE_DIV1P5
#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK
#define STM32_RTCSEL STM32_RTCSEL_NOCLOCK //STM32_RTCSEL_LSI //STM32_RTCSEL_HSEDIV
#define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
....
#define STM32_UART_USE_USART1 TRUE
...
and in halconf.h
Code: Select all
#define HAL_USE_PAL TRUE
The LEDs are at PB4 & 5. So I configured in my board.h ...
Code: Select all
#if !defined(STM32_LSECLK)
#define STM32_LSECLK 0
#endif
#define STM32_LSEDRV (3 << 3)
#if !defined(STM32_HSECLK)
#define STM32_HSECLK 0
#endif
#define STM32_HSE_BYPASS
#define STM32F10X_MD
....
//#define VAL_GPIOBCRL 0x4B668888 /* PB7...PB0 */
//#define VAL_GPIOBCRH 0xAAA88888 /* PB15...PB8 */
#define VAL_GPIOBCRL 0x4B338888 /* PB7...PB0 */
#define VAL_GPIOBCRH 0xAAA88888 /* PB15...PB8 */
#define VAL_GPIOBODR 0xFFFFFFFF
Now I tried to blink the LEDs
Code: Select all
palTogglePad(GPIOB, 4);
palTogglePad(GPIOB, 5);Which makes the LED at PB5 blink but NOT the LED at PB4!
What may be wrong there?
To verify that the board is ok, this code (using libopencm3) makes both LEDs blink as they should:
Code: Select all
/*
* This file is part of the libopencm3 project.
*/
#include <libopencm3/stm32/f1/rcc.h>
#include <libopencm3/stm32/f1/gpio.h>
static void clock_setup(void)
{
/* Set STM32 to 64 MHz. */
rcc_clock_setup_in_hsi_out_64mhz();
/* Enable alternate function peripheral clock. */
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
/* Enable GPIOB clock. */
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
}
static void gpio_setup(void)
{
/* Configure PB4 as GPIO. */
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST;
/* Set GPIO4 and 5 (in GPIO port B) to 'output push-pull'. */
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO4 | GPIO5);
}
int main(void)
{
int i;
clock_setup();
gpio_setup();
/* Blink the LEDs on the board. */
while (1) {
gpio_toggle(GPIOB, GPIO4); /* LED on/off */
for (i = 0; i < 8000000; i++) /* Wait a bit. */
__asm__("nop");
gpio_toggle(GPIOB, GPIO5); /* LED on/off */
for (i = 0; i < 8000000; i++) /* Wait a bit. */
__asm__("nop");
}
return 0;
}
Additionally the USART configuration seems not to work...
The full code is at:
https://github.com/joewa/bldc-strip
You can see the schematics at:
https://github.com/joewa/open-bldc-hardware/tree/master/strip/v0.2
Cheers,
Jörg