diff --git a/platform/stm32f2xx/debug.c b/platform/stm32f2xx/debug.c index 57bb9bd8..f4770106 100644 --- a/platform/stm32f2xx/debug.c +++ b/platform/stm32f2xx/debug.c @@ -29,8 +29,8 @@ #include #include #include -//#include -//#include +#include +#include #include void stm32_debug_early_init(void) diff --git a/platform/stm32f2xx/gpio.c b/platform/stm32f2xx/gpio.c index dd800d64..1b6c0736 100644 --- a/platform/stm32f2xx/gpio.c +++ b/platform/stm32f2xx/gpio.c @@ -39,20 +39,21 @@ static GPIO_TypeDef *port_to_pointer(unsigned int port) case GPIO_PORT_E: return GPIOE; case GPIO_PORT_F: return GPIOF; case GPIO_PORT_G: return GPIOG; + case GPIO_PORT_H: return GPIOH; + case GPIO_PORT_I: return GPIOI; } } static void enable_port(unsigned int port) { - DEBUG_ASSERT(port <= GPIO_PORT_G); + DEBUG_ASSERT(port <= GPIO_PORT_I); /* happens to be the RCC ids are sequential bits, so we can start from A and shift */ - RCC_APB2PeriphClockCmd(RCC_AHB1Periph_GPIOA << port, ENABLE); + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA << port, ENABLE); } void stm32_gpio_early_init(void) { - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE); } int gpio_config(unsigned nr, unsigned flags) @@ -72,11 +73,8 @@ int gpio_config(unsigned nr, unsigned flags) init.GPIO_Mode = GPIO_Mode_IN; } else if (flags & GPIO_OUTPUT) { init.GPIO_Mode = GPIO_Mode_OUT; - if (flags & GPIO_STM32_OD) { - init.GPIO_OType = GPIO_OType_OD; - } else { - init.GPIO_OType = GPIO_OType_PP; - } + } else if (flags & GPIO_STM32_AF) { + init.GPIO_Mode = GPIO_Mode_AF; } if (flags & GPIO_PULLUP) { @@ -85,27 +83,12 @@ int gpio_config(unsigned nr, unsigned flags) init.GPIO_PuPd = GPIO_PuPd_DOWN; } -#if 0 - if (flags & GPIO_STM32_AF) { - if (flags & GPIO_STM32_OD) - init.GPIO_Mode = GPIO_OType_OD; - else - init.GPIO_Mode = GPIO_Mode_AF_PP; - } else if (flags & GPIO_OUTPUT) { - if (flags & GPIO_STM32_OD) - init.GPIO_Mode = GPIO_OType_OD; - else - init.GPIO_Mode = GPIO_Mode_Out_PP; - } else { // GPIO_INPUT - if (flags & GPIO_PULLUP) { - init.GPIO_Mode = GPIO_Mode_IPU; - } else if (flags & GPIO_PULLDOWN) { - init.GPIO_Mode = GPIO_Mode_IPD; - } else { - init.GPIO_Mode = GPIO_Mode_IN_FLOATING; - } + if (flags & GPIO_STM32_OD) { + init.GPIO_OType = GPIO_OType_OD; + } else { + init.GPIO_OType = GPIO_OType_PP; } -#endif + GPIO_Init(port_to_pointer(port), &init); return 0; diff --git a/platform/stm32f2xx/include/platform/gpio.h b/platform/stm32f2xx/include/platform/gpio.h index 7cf69fd7..7a213338 100644 --- a/platform/stm32f2xx/include/platform/gpio.h +++ b/platform/stm32f2xx/include/platform/gpio.h @@ -20,6 +20,8 @@ #define GPIO_PORT_E 4 #define GPIO_PORT_F 5 #define GPIO_PORT_G 6 +#define GPIO_PORT_H 7 +#define GPIO_PORT_I 8 #endif diff --git a/platform/stm32f2xx/init.c b/platform/stm32f2xx/init.c index f636b631..42e27dc7 100644 --- a/platform/stm32f2xx/init.c +++ b/platform/stm32f2xx/init.c @@ -34,11 +34,9 @@ void platform_early_init(void) stm32_timer_early_init(); stm32_gpio_early_init(); - stm32_flash_nor_early_init(); } void platform_init(void) { stm32_timer_init(); - stm32_flash_nor_init(); } diff --git a/platform/stm32f2xx/rules.mk b/platform/stm32f2xx/rules.mk index 18ae20b3..4e3e6dbf 100644 --- a/platform/stm32f2xx/rules.mk +++ b/platform/stm32f2xx/rules.mk @@ -10,32 +10,6 @@ MEMBASE := 0x20000000 ARCH := arm ARM_CPU := cortex-m3 -#ifeq ($(STM32_CHIP),stm32f107) -#DEFINES += \ -# STM32F10X_CL=1 -#MEMSIZE ?= 65536 -#endif -#ifeq ($(STM32_CHIP),stm32f103_xl) -#DEFINES += \ -# STM32F10X_XL=1 -#MEMSIZE ?= 65536 -#endif -#ifeq ($(STM32_CHIP),stm32f103_hd) -#DEFINES += \ -# STM32F10X_HD=1 -#MEMSIZE ?= 65536 -#endif -#ifeq ($(STM32_CHIP),stm32f103_md) -#DEFINES += \ -# STM32F10X_MD=1 -#MEMSIZE ?= 20480 -#endif -#ifeq ($(STM32_CHIP),stm32f103_ld) -#DEFINES += \ -# STM32F10X_LD=1 -#MEMSIZE ?= 20480 -#endif - DEFINES += \ MEMSIZE=$(MEMSIZE) @@ -44,14 +18,13 @@ INCLUDES += \ MODULE_SRCS += \ $(LOCAL_DIR)/init.c \ - $(LOCAL_DIR)/debug.c \ - $(LOCAL_DIR)/uart.c \ - $(LOCAL_DIR)/timer.c \ $(LOCAL_DIR)/vectab.c \ $(LOCAL_DIR)/gpio.c \ - $(LOCAL_DIR)/flash_nor.c \ + $(LOCAL_DIR)/timer.c \ + $(LOCAL_DIR)/debug.c \ + $(LOCAL_DIR)/uart.c \ -# $(LOCAL_DIR)/debug.c \ +# $(LOCAL_DIR)/flash_nor.c \ $(LOCAL_DIR)/interrupts.c \ $(LOCAL_DIR)/platform_early.c \ $(LOCAL_DIR)/platform.c \ diff --git a/project/stm3220g-eval.mk b/project/stm3220g-eval.mk index fb3b02f3..1aff4050 100644 --- a/project/stm3220g-eval.mk +++ b/project/stm3220g-eval.mk @@ -1,3 +1,7 @@ LOCAL_DIR := $(GET_LOCAL_DIR) +MODULES += \ + lib/debugcommands \ + app/shell + TARGET := stm3220g diff --git a/target/stm3220g/include/target/gpioconfig.h b/target/stm3220g/include/target/gpioconfig.h index 29430a9a..3978295f 100644 --- a/target/stm3220g/include/target/gpioconfig.h +++ b/target/stm3220g/include/target/gpioconfig.h @@ -25,7 +25,14 @@ #include -#define GPIO_LED0 GPIO(GPIO_PORT_C, 6) -#define GPIO_LED1 GPIO(GPIO_PORT_C, 7) +#define GPIO_USART3_TX GPIO(GPIO_PORT_C, 10) +#define GPIO_USART3_RX GPIO(GPIO_PORT_C, 11) + +#define GPIO_LED0 GPIO(GPIO_PORT_G, 6) +#define GPIO_LED1 GPIO(GPIO_PORT_G, 8) +#define GPIO_LED2 GPIO(GPIO_PORT_I, 9) +#define GPIO_LED3 GPIO(GPIO_PORT_C, 7) + +void stm3220g_set_led_bits(unsigned int nr); #endif diff --git a/target/stm3220g/init.c b/target/stm3220g/init.c index e063eb96..2ecc8e02 100644 --- a/target/stm3220g/init.c +++ b/target/stm3220g/init.c @@ -25,9 +25,9 @@ #include #include #include -//#include -//#include -//#include +#include +#include +#include //#include //#include #include @@ -36,22 +36,22 @@ void target_early_init(void) { -#if 0 /* configure the usart3 pins */ - GPIO_PinRemapConfig(GPIO_FullRemap_USART3, ENABLE); - - gpio_config(GPIO(GPIO_PORT_D, 8), GPIO_STM32_AF); - gpio_config(GPIO(GPIO_PORT_D, 9), GPIO_INPUT); + gpio_config(GPIO_USART3_TX, GPIO_STM32_AF | GPIO_PULLUP); + gpio_config(GPIO_USART3_RX, GPIO_STM32_AF | GPIO_PULLUP); + + GPIO_PinAFConfig(GPIOC, 10, GPIO_AF_USART3); + GPIO_PinAFConfig(GPIOC, 11, GPIO_AF_USART3); stm32_debug_early_init(); /* configure some status leds */ - gpio_set(GPIO_LED0, 0); - gpio_set(GPIO_LED1, 0); - gpio_config(GPIO_LED0, GPIO_OUTPUT); gpio_config(GPIO_LED1, GPIO_OUTPUT); -#endif + gpio_config(GPIO_LED2, GPIO_OUTPUT); + gpio_config(GPIO_LED3, GPIO_OUTPUT); + + stm3220g_set_led_bits(1); } void target_init(void) @@ -65,7 +65,6 @@ void target_init(void) void target_set_debug_led(unsigned int led, bool on) { -#if 0 switch (led) { case 0: gpio_set(GPIO_LED0, on); @@ -73,7 +72,19 @@ void target_set_debug_led(unsigned int led, bool on) case 1: gpio_set(GPIO_LED1, on); break; + case 2: + gpio_set(GPIO_LED2, on); + break; + case 3: + gpio_set(GPIO_LED3, on); + break; } -#endif } +void stm3220g_set_led_bits(unsigned int nr) +{ + gpio_set(GPIO_LED0, nr & 1); + gpio_set(GPIO_LED1, nr & 2); + gpio_set(GPIO_LED2, nr & 4); + gpio_set(GPIO_LED3, nr & 8); +}