[stm32f2xx] Clean up gpios and get uart3 running

This commit is contained in:
Chris Anderson
2012-10-05 15:36:14 -07:00
parent f54f887e71
commit b614bcf281
8 changed files with 57 additions and 79 deletions

View File

@@ -29,8 +29,8 @@
#include <arch/ops.h>
#include <dev/uart.h>
#include <target/debugconfig.h>
//#include <stm32f2xx_rcc.h>
//#include <stm32f2xx_usart.h>
#include <stm32f2xx_rcc.h>
#include <stm32f2xx_usart.h>
#include <arch/arm/cm3.h>
void stm32_debug_early_init(void)

View File

@@ -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;

View File

@@ -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

View File

@@ -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();
}

View File

@@ -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 \

View File

@@ -1,3 +1,7 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
MODULES += \
lib/debugcommands \
app/shell
TARGET := stm3220g

View File

@@ -25,7 +25,14 @@
#include <platform/gpio.h>
#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

View File

@@ -25,9 +25,9 @@
#include <target.h>
#include <compiler.h>
#include <dev/gpio.h>
//#include <stm32f10x_usart.h>
//#include <stm32f10x_rcc.h>
//#include <stm32f10x_gpio.h>
#include <stm32f2xx_usart.h>
#include <stm32f2xx_rcc.h>
#include <stm32f2xx_gpio.h>
//#include <stm32f10x_flash.h>
//#include <stm32f10x_dbgmcu.h>
#include <platform/stm32.h>
@@ -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);
}