From 0b01040f4769bd3176849eb5769872a7a05a1715 Mon Sep 17 00:00:00 2001 From: Joe Turner Date: Wed, 24 Apr 2013 11:48:27 +0100 Subject: [PATCH] Lots of small changes which get us compiling. --- libraries/mbed/capi/pinmap.h | 2 +- .../STM/capi/STM32F407/PeripheralNames.h | 6 ++-- .../mbed/vendor/STM/capi/STM32F407/device.h | 18 +++++------ .../mbed/vendor/STM/capi/STM32F407/objects.h | 6 ++-- libraries/mbed/vendor/STM/capi/gpio_api.c | 15 +++++---- libraries/mbed/vendor/STM/capi/i2c_api.c | 32 +++++++++---------- libraries/mbed/vendor/STM/capi/pinmap.c | 6 ++-- libraries/mbed/vendor/STM/capi/port_api.c | 9 +++--- 8 files changed, 50 insertions(+), 44 deletions(-) diff --git a/libraries/mbed/capi/pinmap.h b/libraries/mbed/capi/pinmap.h index 8aca5dd372..07ca2e30ee 100644 --- a/libraries/mbed/capi/pinmap.h +++ b/libraries/mbed/capi/pinmap.h @@ -26,7 +26,7 @@ typedef struct { PinName pin; int peripheral; int function; -#ifdef defined(TARGET_STM32F407) +#if defined(TARGET_STM32F407) int alternate_function; #endif } PinMap; diff --git a/libraries/mbed/vendor/STM/capi/STM32F407/PeripheralNames.h b/libraries/mbed/vendor/STM/capi/STM32F407/PeripheralNames.h index caa98afa81..1b73a1af3a 100644 --- a/libraries/mbed/vendor/STM/capi/STM32F407/PeripheralNames.h +++ b/libraries/mbed/vendor/STM/capi/STM32F407/PeripheralNames.h @@ -62,9 +62,9 @@ typedef enum { } SPIName; typedef enum { - I2C_0 = (int)I2C1_BASE, - I2C_1 = (int)I2C2_BASE, - I2C_2 = (int)I2C3_BASE + I2C_1 = (int)I2C1_BASE, + I2C_2 = (int)I2C2_BASE, + I2C_3 = (int)I2C3_BASE } I2CName; typedef enum { diff --git a/libraries/mbed/vendor/STM/capi/STM32F407/device.h b/libraries/mbed/vendor/STM/capi/STM32F407/device.h index 883cd77329..75c52c04b3 100644 --- a/libraries/mbed/vendor/STM/capi/STM32F407/device.h +++ b/libraries/mbed/vendor/STM/capi/STM32F407/device.h @@ -20,28 +20,28 @@ #define DEVICE_PORTOUT 1 #define DEVICE_PORTINOUT 1 -#define DEVICE_INTERRUPTIN 1 +#define DEVICE_INTERRUPTIN 0 #define DEVICE_ANALOGIN 1 -#define DEVICE_ANALOGOUT 1 +#define DEVICE_ANALOGOUT 0 -#define DEVICE_SERIAL 1 +#define DEVICE_SERIAL 0 #define DEVICE_I2C 1 -#define DEVICE_I2CSLAVE 1 +#define DEVICE_I2CSLAVE 0 #define DEVICE_SPI 1 #define DEVICE_SPISLAVE 1 -#define DEVICE_CAN 1 +#define DEVICE_CAN 0 -#define DEVICE_RTC 1 +#define DEVICE_RTC 0 -#define DEVICE_ETHERNET 1 +#define DEVICE_ETHERNET 0 -#define DEVICE_PWMOUT 1 +#define DEVICE_PWMOUT 0 -#define DEVICE_SLEEP 1 +#define DEVICE_SLEEP 0 #include "objects.h" diff --git a/libraries/mbed/vendor/STM/capi/STM32F407/objects.h b/libraries/mbed/vendor/STM/capi/STM32F407/objects.h index 54fdc1e2c1..80caf21974 100644 --- a/libraries/mbed/vendor/STM/capi/STM32F407/objects.h +++ b/libraries/mbed/vendor/STM/capi/STM32F407/objects.h @@ -32,9 +32,11 @@ struct gpio_irq_s { }; struct port_s { - __IO uint32_t *reg_dir; + __IO uint32_t *reg_mode; + __IO uint32_t *reg_in; __IO uint32_t *reg_out; - __I uint32_t *reg_in; + __IO uint16_t *reg_set; + __IO uint16_t *reg_clr; PortName port; uint32_t mask; }; diff --git a/libraries/mbed/vendor/STM/capi/gpio_api.c b/libraries/mbed/vendor/STM/capi/gpio_api.c index 4f28aa791e..d6875fae15 100644 --- a/libraries/mbed/vendor/STM/capi/gpio_api.c +++ b/libraries/mbed/vendor/STM/capi/gpio_api.c @@ -20,7 +20,7 @@ uint32_t gpio_set(PinName pin) { uint32_t port_index = (uint32_t) pin >> 4; // Enable GPIO peripheral clock - RCC_APB1ENR |= 1 << port_index; + RCC->APB1ENR |= 1 << port_index; pin_function(pin, 0); return 1 << ((uint32_t) pin & 0xF); @@ -32,11 +32,14 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) { obj->pin = pin; obj->mask = gpio_set(pin); - GPIO_TypeDef *port = (GPIO_TypeDef *) (GPIOA_BASE + port_index << 6); + uint32_t port_index = (uint32_t) pin >> 4; + + GPIO_TypeDef *port_reg = (GPIO_TypeDef *) (GPIOA_BASE + (port_index << 6)); obj->reg_mode = &port_reg->MODER; - obj->reg_set = &port_reg->BSSRH; - obj->reg_clr = &port_reg->BSSRL; + obj->reg_set = &port_reg->BSRRH; + obj->reg_clr = &port_reg->BSRRL; obj->reg_in = &port_reg->IDR; + obj->reg_in = &port_reg->ODR; gpio_dir(obj, direction); @@ -53,7 +56,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) { void gpio_dir(gpio_t *obj, PinDirection direction) { switch (direction) { - case PIN_INPUT : pin_function(pin, 0); break; - case PIN_OUTPUT: pin_function(pin, 1); break; + case PIN_INPUT : pin_function(obj->pin, 0); break; + case PIN_OUTPUT: pin_function(obj->pin, 1); break; } } diff --git a/libraries/mbed/vendor/STM/capi/i2c_api.c b/libraries/mbed/vendor/STM/capi/i2c_api.c index d7be525d64..1bcb162a0b 100644 --- a/libraries/mbed/vendor/STM/capi/i2c_api.c +++ b/libraries/mbed/vendor/STM/capi/i2c_api.c @@ -29,7 +29,7 @@ static const PinMap PinMap_I2C_SDA[] = { {PF_0, I2C_2, 2, 4}, {PH_5, I2C_2, 2, 4}, {PH_8, I2C_3, 2, 4}, - {NC , NC , 0} + {NC , NC , 0, 0} }; static const PinMap PinMap_I2C_SCL[] = { @@ -40,7 +40,7 @@ static const PinMap PinMap_I2C_SCL[] = { {PF_1, I2C_2, 2, 4}, {PH_4, I2C_2, 2, 4}, {PH_7, I2C_3, 2, 4}, - {NC , NC, 0} + {NC , NC, 0, 0} }; static const uint32_t I2C_addr_offset[2][4] = { @@ -60,16 +60,16 @@ static inline void i2c_interface_disable(i2c_t *obj) { static inline void i2c_power_enable(i2c_t *obj) { switch ((int)obj->i2c) { - case I2C_1: RCC_APB1ENR |= RCC_APB1ENR_I2C1EN; break; - case I2C_2: RCC_APB1ENR |= RCC_APB1ENR_I2C2EN; break; - case I2C_3: RCC_APB1ENR |= RCC_APB1ENR_I2C3EN; break; + case I2C_1: RCC->APB1ENR |= RCC_APB1ENR_I2C1EN; break; + case I2C_2: RCC->APB1ENR |= RCC_APB1ENR_I2C2EN; break; + case I2C_3: RCC->APB1ENR |= RCC_APB1ENR_I2C3EN; break; } } static inline void i2c_wait_status(i2c_t *obj, uint32_t sr1_mask, uint32_t sr2_mask) { - while (!((obj->i2c->SR1 & sr1_mask >= sr1_mask) && - (obj->i2c->SR2 & sr2_mask == sr2_mask))); + while (!(((obj->i2c->SR1 & sr1_mask) >= sr1_mask) && + ((obj->i2c->SR2 & sr2_mask) == sr2_mask))); } // Wait until the slave address has been acknowledged @@ -150,7 +150,7 @@ static inline int i2c_do_write(i2c_t *obj, int value, uint8_t addr) { return 0; } -static inline void i2c_do_read(i2c_t *obj, int last) { +static inline int i2c_do_read(i2c_t *obj, int last) { if(last) { // Don't acknowledge the byte obj->i2c->CR1 &= ~(I2C_CR1_ACK); @@ -167,7 +167,7 @@ static inline void i2c_do_read(i2c_t *obj, int last) { } void i2c_frequency(i2c_t *obj, int hz) { - i2c_interface_disable(); + i2c_interface_disable(obj); obj->i2c->CCR &= ~I2C_CCR_CCR; if (hz > 100000) { // Fast Mode @@ -183,7 +183,7 @@ void i2c_frequency(i2c_t *obj, int hz) { result = result < 0x4 ? 0x4 : result; obj->i2c->CCR |= result & I2C_CCR_CCR; } - i2c_interface_enable(); + i2c_interface_enable(obj); } // The I2C does a read or a write as a whole operation @@ -201,7 +201,7 @@ void i2c_frequency(i2c_t *obj, int hz) { // check for that int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) { - int count, status; + int count; i2c_start(obj); @@ -230,7 +230,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) { } int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { - int i, status; + int i; i2c_start(obj); @@ -239,8 +239,8 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { i2c_wait_addr(obj); for (i=0; iMODER &= ~(0x3 << offset); gpio->MODER |= function << offset; } @@ -40,7 +40,7 @@ void pin_alternate_function(PinName pin, int function) { int pin_index = (pin_number & 0xF); int offset = (pin_index & 0x7) << 2; - GPIO_TypeDef * gpio = ((GPIO_TypeDef *) GPIOA_BASE + port_index << 6); + GPIO_TypeDef * gpio = ((GPIO_TypeDef *) GPIOA_BASE + (port_index << 6)); // Bottom seven pins are in AFR[0], top seven in AFR[1] if (pin_index <= 0x7) { @@ -61,7 +61,7 @@ void pin_mode(PinName pin, PinMode mode) { int pin_index = (pin_number & 0xF); int offset = pin_index << 1; - GPIO_TypeDef * gpio = ((GPIO_TypeDef *) GPIOA_BASE + port_index << 6); + GPIO_TypeDef * gpio = ((GPIO_TypeDef *) GPIOA_BASE + (port_index << 6)); if (mode == OpenDrain) { gpio->OTYPER |= 1 << pin_index; } diff --git a/libraries/mbed/vendor/STM/capi/port_api.c b/libraries/mbed/vendor/STM/capi/port_api.c index c797e4cdbe..ad515c124d 100644 --- a/libraries/mbed/vendor/STM/capi/port_api.c +++ b/libraries/mbed/vendor/STM/capi/port_api.c @@ -27,14 +27,15 @@ void port_init(port_t *obj, PortName port, int mask, PinDirection dir) { obj->port = port; obj->mask = mask; - int port_index = (uint32_t) pin >> 4; + uint32_t port_index = (uint32_t) port; - GPIO_TypeDef *port_reg = (GPIO_TypeDef *)(GPIOA_BASE + port_index << 6); + GPIO_TypeDef *port_reg = (GPIO_TypeDef *)(GPIOA_BASE + (port_index << 6)); obj->reg_mode = &port_reg->MODER; - obj->reg_set = &port_reg->BSSRH; - obj->reg_clr = &port_reg->BSSRL; + obj->reg_set = &port_reg->BSRRH; + obj->reg_clr = &port_reg->BSRRL; obj->reg_in = &port_reg->IDR; + obj->reg_in = &port_reg->ODR; port_dir(obj, dir); }