board: Initial import of stm32f3discovery

This commit is contained in:
Hauke Petersen 2014-06-24 23:37:10 +02:00
parent c5c860f435
commit 94848cf57f
7 changed files with 458 additions and 0 deletions

View File

@ -0,0 +1,4 @@
# tell the Makefile.base which module to build
MODULE = $(BOARD)_base
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,47 @@
# define the cpu used by the stm32f3-discovery board
export CPU = stm32f3
export CPU_MODEL = stm32f303vc
#define the default port depending on the host OS
OS := $(shell uname)
ifeq ($(OS),Linux)
PORT ?= /dev/ttyUSB0
else ifeq ($(OS),Darwin)
PORT ?= $(shell ls -1 /dev/tty.SLAB_USBtoUART* | head -n 1)
else
$(info CAUTION: No flash tool for your host system found!)
# TODO: add support for windows as host platform
endif
export PORT
# define tools used for building the project
export PREFIX = arm-none-eabi-
export CC = $(PREFIX)gcc
export AR = $(PREFIX)ar
export AS = $(PREFIX)as
export LINK = $(PREFIX)gcc
export SIZE = $(PREFIX)size
export OBJCOPY = $(PREFIX)objcopy
export TERMPROG = $(RIOTBASE)/dist/tools/pyterm/pyterm.py
export FLASHER = st-flash
export DEBUGGER = $(RIOTBOARD)/$(BOARD)/dist/debug.sh
# define build specific options
CPU_USAGE = -mcpu=cortex-m4
FPU_USAGE = -mfloat-abi=hard -mfpu=fpv4-sp-d16
export CFLAGS += -ggdb -g3 -std=gnu99 -Os -Wall -Wstrict-prototypes $(CPU_USAGE) $(FPU_USAGE) -mlittle-endian -mthumb -mthumb-interwork -nostartfiles
export CFLAGS += -ffunction-sections -fdata-sections -fno-builtin
export ASFLAGS += -ggdb -g3 $(CPU_USAGE) $(FPU_USAGE) -mlittle-endian
export LINKFLAGS += -g3 -ggdb -std=gnu99 $(CPU_USAGE) $(FPU_USAGE) -mlittle-endian -static -lgcc -mthumb -mthumb-interwork -nostartfiles
export LINKFLAGS += -T$(LINKERSCRIPT)
export OFLAGS = -O binary
export FFLAGS = write bin/$(BOARD)/$(APPLICATION).hex 0x8000000
export DEBUGGER_FLAGS = $(RIOTBOARD)/$(BOARD)/dist/gdb.conf $(BINDIR)/$(APPLICATION).elf
# use newLib nano-specs if available
ifeq ($(shell $(LINK) -specs=nano.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0)
export LINKFLAGS += -specs=nano.specs -lc -lnosys
endif
# export board specific includes to the global includes-listing
export INCLUDES += -I$(RIOTBOARD)/$(BOARD)/include

View File

@ -0,0 +1,67 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @ingroup board_stm32f3discovery
* @{
*
* @file
* @brief Board specific implementations for the STM32F3Discovery evaluation board
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include "board.h"
static void leds_init(void);
void board_init(void)
{
/* initialize the boards LEDs */
leds_init();
/* initialize the CPU */
cpu_init();
}
/**
* @brief Initialize the boards on-board LEDs (LD3 to LD10)
*
* The LED initialization is hard-coded in this function. As the LEDs are soldered
* onto the board they are fixed to their CPU pins.
*
* The LEDs are connected to the following pins:
* - LD3: PE9
* - LD4: PE8
* - LD5: PE10
* - LD6: PE15
* - LD7: PE11
* - LD8: PE14
* - LD9: PE12
* - LD10: PE13
*/
static void leds_init(void)
{
/* enable clock for port GPIOE */
RCC->AHBENR |= RCC_AHBENR_GPIOEEN;
/* set output speed to 50MHz */
LED_PORT->OSPEEDR |= 0xffff0000;
/* set output type to push-pull */
LED_PORT->OTYPER &= ~(0x0000ff00);
/* configure pins as general outputs */
LED_PORT->MODER &= ~(0xffff0000);
LED_PORT->MODER |= 0x55550000;
/* disable pull resistors */
LED_PORT->PUPDR &= ~(0xffff0000);
/* turn all LEDs off */
LED_PORT->BRR = 0xff00;
}

4
boards/stm32f3discovery/dist/debug.sh vendored Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
echo "Debugging $1"
arm-none-eabi-gdb -tui -command=$1 $2

1
boards/stm32f3discovery/dist/gdb.conf vendored Normal file
View File

@ -0,0 +1 @@
tar extended-remote :4242

View File

@ -0,0 +1,103 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @defgroup board_stm32f3discovery STM32F3Discovery
* @ingroup boards
* @brief Board specific files for the STM32F3Discovery board
* @{
*
* @file
* @brief Board specific definitions for the STM32F3Discovery evaluation board
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*/
#ifndef __BOARD_H
#define __BOARD_H
#include "cpu.h"
/**
* Define the nominal CPU core clock in this board
*/
#define F_CPU (72000000UL)
/**
* @name Assign the hardware timer
*/
#define HW_TIMER TIMER_0
/**
* @name Define the UART used for stdio
* @{
*/
#define STDIO UART_0
#define STDIO_BAUDRATE (115200U)
#define STDIO_BUFSIZE (64U)
/** @} */
/**
* @name LED pin definitions
* @{
*/
#define LED_PORT GPIOE
#define LD3_PIN (1 << 9)
#define LD4_PIN (1 << 8)
#define LD5_PIN (1 << 10)
#define LD6_PIN (1 << 15)
#define LD7_PIN (1 << 11)
#define LD8_PIN (1 << 14)
#define LD9_PIN (1 << 12)
#define LD10_PIN (1 << 13)
/** @} */
/**
* @name Macros for controlling the on-board LEDs.
* @{
*/
#define LD3_ON (LED_PORT->BSRRL = LD3_PIN)
#define LD3_OFF (LED_PORT->BSRRH = LD3_PIN)
#define LD3_TOGGLE (LED_PORT->ODR ^= LD3_PIN)
#define LD4_ON (LED_PORT->BSRRL = LD4_PIN)
#define LD4_OFF (LED_PORT->BSRRH = LD4_PIN)
#define LD4_TOGGLE (LED_PORT->ODR ^= LD4_PIN)
#define LD5_ON (LED_PORT->BSRRL = LD5_PIN)
#define LD5_OFF (LED_PORT->BSRRH = LD5_PIN)
#define LD5_TOGGLE (LED_PORT->ODR ^= LD5_PIN)
#define LD6_ON (LED_PORT->BSRRL = LD6_PIN)
#define LD6_OFF (LED_PORT->BSRRH = LD6_PIN)
#define LD6_TOGGLE (LED_PORT->ODR ^= LD6_PIN)
#define LD7_ON (LED_PORT->BSRRL = LD7_PIN)
#define LD7_OFF (LED_PORT->BSRRH = LD7_PIN)
#define LD7_TOGGLE (LED_PORT->ODR ^= LD7_PIN)
#define LD8_ON (LED_PORT->BSRRL = LD8_PIN)
#define LD8_OFF (LED_PORT->BSRRH = LD8_PIN)
#define LD8_TOGGLE (LED_PORT->ODR ^= LD8_PIN)
#define LD9_ON (LED_PORT->BSRRL = LD9_PIN)
#define LD9_OFF (LED_PORT->BSRRH = LD9_PIN)
#define LD9_TOGGLE (LED_PORT->ODR ^= LD9_PIN)
#define LD10_ON (LED_PORT->BSRRL = LD10_PIN)
#define LD10_OFF (LED_PORT->BSRRH = LD10_PIN)
#define LD10_TOGGLE (LED_PORT->ODR ^= LD10_PIN)
/* for compatability to other boards */
#define LED_GREEN_ON LD4_ON
#define LED_GREEN_OFF LD4_OFF
#define LED_GREEN_TOGGLE LD4_TOGGLE
#define LED_RED_ON LD5_ON
#define LED_RED_OFF LD5_OFF
#define LED_RED_TOGGLE LD5_TOGGLE
/** @} */
/**
* @brief Initialize board specific hardware, including clock, LEDs and std-IO
*/
void board_init(void);
#endif /** __BOARD_H */
/** @} */

View File

@ -0,0 +1,232 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @ingroup board_stm32f3discovery
* @{
*
* @file
* @brief Peripheral MCU configuration for the STM32F3discovery board
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*/
#ifndef __PERIPH_CONF_H
#define __PERIPH_CONF_H
/**
* @name Clock system configuration
* @{
*/
#define CLOCK_HSE (8000000U) /* external oscillator */
#define CLOCK_CORECLOCK (72000000U) /* desired core clock frequency */
/* the actual PLL values are automatically generated */
#define CLOCK_PLL_MUL (CLOCK_CORECLOCK / CLOCK_HSE)
#define CLOCK_AHB_DIV RCC_CFGR_HPRE_DIV1
#define CLOCK_APB2_DIV RCC_CFGR_PPRE2_DIV1
#define CLOCK_APB1_DIV RCC_CFGR_PPRE1_DIV2
#define CLOCK_FLASH_LATENCY FLASH_ACR_LATENCY_1
/** @} */
/**
* @brief Timer configuration
* @{
*/
#define TIMER_NUMOF (1U)
#define TIMER_0_EN 1
#define TIMER_IRQ_PRIO 1
/* Timer 0 configuration */
#define TIMER_0_DEV TIM2
#define TIMER_0_CHANNELS 4
#define TIMER_0_PRESCALER (71U)
#define TIMER_0_MAX_VALUE (0xffffffff)
#define TIMER_0_CLKEN() (RCC->APB1ENR |= RCC_APB1ENR_TIM2EN)
#define TIMER_0_ISR isr_tim2
#define TIMER_0_IRQ_CHAN TIM2_IRQn
/** @} */
/**
* @brief UART configuration
* @{
*/
#define UART_NUMOF (3U)
#define UART_0_EN 1
#define UART_1_EN 1
#define UART_2_EN 1
#define UART_IRQ_PRIO 1
/* UART 0 device configuration */
#define UART_0_DEV USART1
#define UART_0_CLKEN() (RCC->APB2ENR |= RCC_APB2ENR_USART1EN)
#define UART_0_CLK (CLOCK_CORECLOCK / 1) /* UART clock runs with 72MHz (F_CPU / 1) */
#define UART_0_IRQ_CHAN USART1_IRQn
#define UART_0_ISR isr_usart1
/* UART 0 pin configuration */
#define UART_0_PORT_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOAEN)
#define UART_0_PORT GPIOA
#define UART_0_TX_PIN 9
#define UART_0_RX_PIN 10
#define UART_0_AF 7
/* UART 1 device configuration */
#define UART_1_DEV USART2
#define UART_1_CLKEN() (RCC->APB1ENR |= RCC_APB1ENR_USART2EN)
#define UART_1_CLK (CLOCK_CORECLOCK / 2) /* UART clock runs with 36MHz (F_CPU / 2) */
#define UART_1_IRQ_CHAN USART2_IRQn
#define UART_1_ISR isr_usart2
/* UART 1 pin configuration */
#define UART_1_PORT_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIODEN)
#define UART_1_PORT GPIOD
#define UART_1_TX_PIN 5
#define UART_1_RX_PIN 6
#define UART_1_AF 7
/* UART 1 device configuration */
#define UART_2_DEV USART3
#define UART_2_CLKEN() (RCC->APB1ENR |= RCC_APB1ENR_USART3EN)
#define UART_2_CLK (CLOCK_CORECLOCK / 2) /* UART clock runs with 36MHz (F_CPU / 2) */
#define UART_2_IRQ_CHAN USART3_IRQn
#define UART_2_ISR isr_usart3
/* UART 1 pin configuration */
#define UART_2_PORT_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIODEN)
#define UART_2_PORT GPIOD
#define UART_2_TX_PIN 8
#define UART_2_RX_PIN 9
#define UART_2_AF 7
/** @} */
/**
* @brief GPIO configuration
* @{
*/
#define GPIO_NUMOF 12
#define GPIO_0_EN 1
#define GPIO_1_EN 1
#define GPIO_2_EN 1
#define GPIO_3_EN 1
#define GPIO_4_EN 1
#define GPIO_5_EN 1
#define GPIO_6_EN 1
#define GPIO_7_EN 1
#define GPIO_8_EN 1
#define GPIO_9_EN 1
#define GPIO_10_EN 1
#define GPIO_11_EN 1
#define GPIO_IRQ_PRIO 1
/* IRQ config */
#define GPIO_IRQ_0 GPIO_11 /* alternatively GPIO_4 could be used here */
#define GPIO_IRQ_1 GPIO_5
#define GPIO_IRQ_2 GPIO_0
#define GPIO_IRQ_3 GPIO_3
#define GPIO_IRQ_4 GPIO_1
#define GPIO_IRQ_5 GPIO_2
#define GPIO_IRQ_6 (-1) /* not configured */
#define GPIO_IRQ_7 (-1) /* not configured */
#define GPIO_IRQ_8 (-1) /* not configured */
#define GPIO_IRQ_9 (-1) /* not configured */
#define GPIO_IRQ_10 (-1) /* not configured */
#define GPIO_IRQ_11 GPIO_6
#define GPIO_IRQ_12 GPIO_7
#define GPIO_IRQ_13 GPIO_8
#define GPIO_IRQ_14 GPIO_9
#define GPIO_IRQ_15 GPIO_10
/* GPIO channel 0 config */
#define GPIO_0_PORT GPIOE /* LSM303DLHC -> DRDY */
#define GPIO_0_PIN 2
#define GPIO_0_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOEEN)
#define GPIO_0_EXTI_CFG1() (SYSCFG->EXTICR[0] &= ~(SYSCFG_EXTICR1_EXTI2))
#define GPIO_0_EXTI_CFG2() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI2_PE)
#define GPIO_0_IRQ EXTI2_TSC_IRQn
/* GPIO channel 1 config */
#define GPIO_1_PORT GPIOE /* LSM303DLHC -> INT1 */
#define GPIO_1_PIN 4
#define GPIO_1_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOEEN)
#define GPIO_1_EXTI_CFG1() (SYSCFG->EXTICR[1] &= ~(SYSCFG_EXTICR2_EXTI4))
#define GPIO_1_EXTI_CFG2() (SYSCFG->EXTICR[1] |= SYSCFG_EXTICR2_EXTI4_PE)
#define GPIO_1_IRQ EXTI4_IRQn
/* GPIO channel 2 config */
#define GPIO_2_PORT GPIOE /* LSM303DLHC -> INT2 */
#define GPIO_2_PIN 5
#define GPIO_2_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOEEN)
#define GPIO_2_EXTI_CFG1() (SYSCFG->EXTICR[1] &= ~(SYSCFG_EXTICR2_EXTI5))
#define GPIO_2_EXTI_CFG2() (SYSCFG->EXTICR[1] |= SYSCFG_EXTICR2_EXTI5_PE)
#define GPIO_2_IRQ EXTI9_5_IRQn
/* GPIO channel 3 config */
#define GPIO_3_PORT GPIOE /* L2GD20 -> CS */
#define GPIO_3_PIN 3
#define GPIO_3_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOEEN)
#define GPIO_3_EXTI_CFG1() (SYSCFG->EXTICR[0] &= ~(SYSCFG_EXTICR1_EXTI3))
#define GPIO_3_EXTI_CFG2() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI3_PE)
#define GPIO_3_IRQ EXTI3_IRQn
/* GPIO channel 4 config */
#define GPIO_4_PORT GPIOE /* L2GD20 -> INT1 */
#define GPIO_4_PIN 0
#define GPIO_4_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOEEN)
#define GPIO_4_EXTI_CFG1() (SYSCFG->EXTICR[0] &= ~(SYSCFG_EXTICR1_EXTI0))
#define GPIO_4_EXTI_CFG2() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI0_PE)
#define GPIO_4_IRQ EXTI0_IRQn
/* GPIO channel 5 config */
#define GPIO_5_PORT GPIOE /* L2GD20 -> INT2/DRDY */
#define GPIO_5_PIN 1
#define GPIO_5_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOEEN)
#define GPIO_5_EXTI_CFG1() (SYSCFG->EXTICR[0] &= ~(SYSCFG_EXTICR1_EXTI1))
#define GPIO_5_EXTI_CFG2() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI1_PE)
#define GPIO_5_IRQ EXTI1_IRQn
/* GPIO channel 6 config */
#define GPIO_6_PORT GPIOB
#define GPIO_6_PIN 11
#define GPIO_6_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOBEN)
#define GPIO_6_EXTI_CFG1() (SYSCFG->EXTICR[2] &= ~(SYSCFG_EXTICR3_EXTI11))
#define GPIO_6_EXTI_CFG2() (SYSCFG->EXTICR[2] |= SYSCFG_EXTICR3_EXTI11_PB)
#define GPIO_6_IRQ EXTI15_10_IRQn
/* GPIO channel 7 config */
#define GPIO_7_PORT GPIOB
#define GPIO_7_PIN 12
#define GPIO_7_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOBEN)
#define GPIO_7_EXTI_CFG1() (SYSCFG->EXTICR[3] &= ~(SYSCFG_EXTICR4_EXTI12))
#define GPIO_7_EXTI_CFG2() (SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI12_PB)
#define GPIO_7_IRQ EXTI15_10_IRQn
/* GPIO channel 8 config */
#define GPIO_8_PORT GPIOB
#define GPIO_8_PIN 13
#define GPIO_8_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOBEN)
#define GPIO_8_EXTI_CFG1() (SYSCFG->EXTICR[3] &= ~(SYSCFG_EXTICR4_EXTI13))
#define GPIO_8_EXTI_CFG2() (SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI13_PB)
#define GPIO_8_IRQ EXTI15_10_IRQn
/* GPIO channel 9 config */
#define GPIO_9_PORT GPIOB
#define GPIO_9_PIN 14
#define GPIO_9_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOBEN)
#define GPIO_9_EXTI_CFG1() (SYSCFG->EXTICR[3] &= ~(SYSCFG_EXTICR4_EXTI14))
#define GPIO_9_EXTI_CFG2() (SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI14_PB)
#define GPIO_9_IRQ EXTI15_10_IRQn
/* GPIO channel 10 config */
#define GPIO_10_PORT GPIOB
#define GPIO_10_PIN 15
#define GPIO_10_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOBEN)
#define GPIO_10_EXTI_CFG1() (SYSCFG->EXTICR[3] &= ~(SYSCFG_EXTICR4_EXTI15))
#define GPIO_10_EXTI_CFG2() (SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI15_PB)
#define GPIO_10_IRQ EXTI15_10_IRQn
/* GPIO channel 11 config */
#define GPIO_11_PORT GPIOA /* User button 1 */
#define GPIO_11_PIN 0
#define GPIO_11_CLKEN() (RCC->AHBENR |= RCC_AHBENR_GPIOAEN)
#define GPIO_11_EXTI_CFG1() (SYSCFG->EXTICR[0] &= ~(SYSCFG_EXTICR1_EXTI0))
#define GPIO_11_EXTI_CFG2() (SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI0_PA)
#define GPIO_11_IRQ EXTI0_IRQn
/** @} */
#endif /* __PERIPH_CONF_H */