Skip to content

Commit

Permalink
Commit initial configuration for safecast build target
Browse files Browse the repository at this point in the history
  • Loading branch information
bunnie committed Dec 27, 2011
1 parent f7e384a commit c1b23cf
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -31,8 +31,8 @@ PRODUCT_ID := 0003

# Try "make help" for more information on BOARD and MEMORY_TARGET;
# these default to a Maple Flash build.
BOARD ?= maple
MEMORY_TARGET ?= flash
BOARD ?= safecast
MEMORY_TARGET ?= jtag

# $(BOARD)- and $(MEMORY_TARGET)-specific configuration
include $(MAKEDIR)/target-config.mk
Expand Down
24 changes: 24 additions & 0 deletions libmaple/rcc.c
Expand Up @@ -112,6 +112,7 @@ void rcc_clk_init(rcc_sysclk_src sysclk_src,
uint32 cfgr = 0;
uint32 cr;

#if !defined(BOARD_safecast)
/* Assume that we're going to clock the chip off the PLL, fed by
* the HSE */
ASSERT(sysclk_src == RCC_CLKSRC_PLL &&
Expand All @@ -138,6 +139,29 @@ void rcc_clk_init(rcc_sysclk_src sysclk_src,
RCC_BASE->CFGR = cfgr;
while ((RCC_BASE->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL)
;
#else
RCC_BASE->CFGR = pll_src | pll_mul;

// safecast uses the HSI
cr = RCC_BASE->CR;
cr |= RCC_CR_HSION;
RCC_BASE->CR = cr;
while (!(RCC_BASE->CR & RCC_CR_HSIRDY))
;

/* Now the PLL */
cr |= RCC_CR_PLLON;
RCC_BASE->CR = cr;
while (!(RCC_BASE->CR & RCC_CR_PLLRDY))
;

/* Finally, let's switch over to the PLL */
cfgr &= ~RCC_CFGR_SW;
cfgr |= RCC_CFGR_SW_PLL;
RCC_BASE->CFGR = cfgr;
while ((RCC_BASE->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL)
;
#endif
}

/**
Expand Down
20 changes: 10 additions & 10 deletions libmaple/rules.mk
Expand Up @@ -3,8 +3,8 @@ sp := $(sp).x
dirstack_$(sp) := $(d)
d := $(dir)
BUILDDIRS += $(BUILD_PATH)/$(d)
BUILDDIRS += $(BUILD_PATH)/$(d)/usb
BUILDDIRS += $(BUILD_PATH)/$(d)/usb/usb_lib
#BUILDDIRS += $(BUILD_PATH)/$(d)/usb
#BUILDDIRS += $(BUILD_PATH)/$(d)/usb/usb_lib

LIBMAPLE_INCLUDES := -I$(LIBMAPLE_PATH) -I$(LIBMAPLE_PATH)/usb -I$(LIBMAPLE_PATH)/usb/usb_lib

Expand All @@ -30,14 +30,14 @@ cSRCS_$(d) := adc.c \
systick.c \
timer.c \
usart.c \
util.c \
usb/usb.c \
usb/usb_reg_map.c \
usb/usb_cdcacm.c \
usb/usb_lib/usb_core.c \
usb/usb_lib/usb_init.c \
usb/usb_lib/usb_mem.c \
usb/usb_lib/usb_regs.c
util.c
# usb/usb.c \ # bunnie TODO: make this swap-out based on BOARD identifier
# usb/usb_reg_map.c \
# usb/usb_cdcacm.c \
# usb/usb_lib/usb_core.c \
# usb/usb_lib/usb_init.c \
# usb/usb_lib/usb_mem.c \
# usb/usb_lib/usb_regs.c

sSRCS_$(d) := exc.S

Expand Down
37 changes: 37 additions & 0 deletions libmaple/stm32.h
Expand Up @@ -54,6 +54,9 @@

#endif

#if !defined(BOARD_safecast)
#error "not building for safecast"

#ifndef STM32_PCLK1
#define STM32_PCLK1 36000000U
#endif
Expand All @@ -74,6 +77,30 @@
#error "(Deprecated) PCLK2 differs from STM32_PCLK2"
#endif

#else

#ifndef STM32_PCLK1
#define STM32_PCLK1 36000000U // 8mhz / 2 * 9, i.e. HSI * 4.5
#endif
#ifndef PCLK1
#define PCLK1 STM32_PCLK1
#endif
#if PCLK1 != STM32_PCLK1
#error "(Deprecated) PCLK1 differs from STM32_PCLK1"
#endif

#ifndef STM32_PCLK2
#define STM32_PCLK2 36000000U
#endif
#ifndef PCLK2
#define PCLK2 STM32_PCLK2
#endif
#if PCLK2 != STM32_PCLK2
#error "(Deprecated) PCLK2 differs from STM32_PCLK2"
#endif

#endif

/*
* Density-specific configuration.
*/
Expand Down Expand Up @@ -181,6 +208,16 @@
#define NR_GPIO_PORTS STM32_NR_GPIO_PORTS
#define DELAY_US_MULT STM32_DELAY_US_MULT

#elif defined(MCU_STM32F101RE)
/* e.g., safecast */

#define STM32_NR_GPIO_PORTS 4
#define STM32_DELAY_US_MULT 6 // half of others as 101 clocks at half speed
#define STM32_SRAM_END ((void*)0x2000C000)

#define NR_GPIO_PORTS STM32_NR_GPIO_PORTS
#define DELAY_US_MULT STM32_DELAY_US_MULT

#else

#error "No MCU type specified. Add something like -DMCU_STM32F103RB " \
Expand Down
11 changes: 11 additions & 0 deletions support/make/target-config.mk
Expand Up @@ -50,6 +50,17 @@ ifeq ($(BOARD), olimex_stm32_h103)
SRAM_SIZE := 20480
endif

ifeq ($(BOARD), safecast)
MCU := STM32F101RE
PRODUCT_ID := 0003 # not relevant in our case
ERROR_LED_PORT := GPIOD
ERROR_LED_PIN := 2
DENSITY := STM32_HIGH_DENSITY
FLASH_SIZE := 524288
SRAM_SIZE := 49152
endif


# Memory target-specific configuration values

ifeq ($(MEMORY_TARGET), ram)
Expand Down
8 changes: 4 additions & 4 deletions wirish/boards.cpp
Expand Up @@ -41,7 +41,7 @@
#include "gpio.h"
#include "adc.h"
#include "timer.h"
#include "usb_cdcacm.h"
//#include "usb_cdcacm.h"

static void setupFlash(void);
static void setupClocks(void);
Expand All @@ -58,7 +58,7 @@ void init(void) {
afio_init();
setupADC();
setupTimers();
usb_cdcacm_enable(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
// usb_cdcacm_enable(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
boardInit();
}

Expand Down Expand Up @@ -87,9 +87,9 @@ static void setupFlash(void) {
* comment above.
*/
static void setupClocks() {
rcc_clk_init(RCC_CLKSRC_PLL, RCC_PLLSRC_HSE, RCC_PLLMUL_9);
rcc_clk_init(RCC_CLKSRC_PLL, RCC_PLLSRC_HSI_DIV_2, RCC_PLLMUL_9);
rcc_set_prescaler(RCC_PRESCALER_AHB, RCC_AHB_SYSCLK_DIV_1);
rcc_set_prescaler(RCC_PRESCALER_APB1, RCC_APB1_HCLK_DIV_2);
rcc_set_prescaler(RCC_PRESCALER_APB1, RCC_APB1_HCLK_DIV_1);
rcc_set_prescaler(RCC_PRESCALER_APB2, RCC_APB2_HCLK_DIV_1);
}

Expand Down
2 changes: 2 additions & 0 deletions wirish/boards.h
Expand Up @@ -134,6 +134,8 @@ bool boardUsesPin(uint8 pin);
#include "maple_RET6.h"
#elif defined(BOARD_olimex_stm32_h103)
#include "olimex_stm32_h103.h"
#elif defined(BOARD_safecast)
#include "safecast.h"
#else
/*
* TODO turn this into a warning so people can:
Expand Down
2 changes: 2 additions & 0 deletions wirish/comm/HardwareSPI.cpp
Expand Up @@ -62,12 +62,14 @@ static const spi_pins board_spi_pins[] __FLASH__ = {
BOARD_SPI2_SCK_PIN,
BOARD_SPI2_MISO_PIN,
BOARD_SPI2_MOSI_PIN},
#if !defined(BOARD_safecast)
#ifdef STM32_HIGH_DENSITY
{BOARD_SPI3_NSS_PIN,
BOARD_SPI3_SCK_PIN,
BOARD_SPI3_MISO_PIN,
BOARD_SPI3_MOSI_PIN},
#endif
#endif
};


Expand Down
2 changes: 2 additions & 0 deletions wirish/comm/HardwareSerial.cpp
Expand Up @@ -51,11 +51,13 @@

HardwareSerial Serial1(USART1, TX1, RX1, STM32_PCLK2);
HardwareSerial Serial2(USART2, TX2, RX2, STM32_PCLK1);
#if !defined(BOARD_safecast)
HardwareSerial Serial3(USART3, TX3, RX3, STM32_PCLK1);
#if defined(STM32_HIGH_DENSITY) && !defined(BOARD_maple_RET6)
HardwareSerial Serial4(UART4, TX4, RX4, STM32_PCLK1);
HardwareSerial Serial5(UART5, TX5, RX5, STM32_PCLK1);
#endif
#endif

HardwareSerial::HardwareSerial(usart_dev *usart_device,
uint8 tx_pin,
Expand Down
3 changes: 2 additions & 1 deletion wirish/rules.mk
Expand Up @@ -18,21 +18,22 @@ cppSRCS_$(d) := wirish_math.cpp \
Print.cpp \
boards.cpp \
boards/maple.cpp \
boards/safecast.cpp \
boards/maple_mini.cpp \
boards/maple_native.cpp \
boards/maple_RET6.cpp \
boards/olimex_stm32_h103.cpp \
comm/HardwareSerial.cpp \
comm/HardwareSPI.cpp \
HardwareTimer.cpp \
usb_serial.cpp \
cxxabi-compat.cpp \
wirish_shift.cpp \
wirish_analog.cpp \
wirish_time.cpp \
pwm.cpp \
ext_interrupts.cpp \
wirish_digital.cpp
# usb_serial.cpp \ # bunnie TODO: need to make this BOARD dependent

cFILES_$(d) := $(cSRCS_$(d):%=$(d)/%)
cppFILES_$(d) := $(cppSRCS_$(d):%=$(d)/%)
Expand Down

0 comments on commit c1b23cf

Please sign in to comment.