Update freedomKL05 from upstream master

pull/11/head
0xc0170 2013-07-02 19:43:43 +02:00
commit 9ff042699b
32 changed files with 352 additions and 230 deletions

View File

@ -52,9 +52,9 @@ int I2C::write(int address, const char* data, int length, bool repeated) {
aquire(); aquire();
int stop = (repeated) ? 0 : 1; int stop = (repeated) ? 0 : 1;
int retval = i2c_write(&_i2c, address, data, length, stop); int written = i2c_write(&_i2c, address, data, length, stop);
return retval; return length != written;
} }
int I2C::write(int data) { int I2C::write(int data) {
@ -66,9 +66,9 @@ int I2C::read(int address, char* data, int length, bool repeated) {
aquire(); aquire();
int stop = (repeated) ? 0 : 1; int stop = (repeated) ? 0 : 1;
int retval = i2c_read(&_i2c, address, data, length, stop); int read = i2c_read(&_i2c, address, data, length, stop);
return retval; return length != read;
} }
int I2C::read(int ack) { int I2C::read(int ack) {

View File

@ -39,7 +39,7 @@ int I2CSlave::receive(void) {
} }
int I2CSlave::read(char *data, int length) { int I2CSlave::read(char *data, int length) {
return i2c_slave_read(&_i2c, data, length); return i2c_slave_read(&_i2c, data, length) != length;
} }
int I2CSlave::read(void) { int I2CSlave::read(void) {
@ -47,7 +47,7 @@ int I2CSlave::read(void) {
} }
int I2CSlave::write(const char *data, int length) { int I2CSlave::write(const char *data, int length) {
return i2c_slave_write(&_i2c, data, length); return i2c_slave_write(&_i2c, data, length) != length;
} }
int I2CSlave::write(int data) { int I2CSlave::write(int data) {

View File

@ -22,9 +22,7 @@ void pinmap_pinout(PinName pin, const PinMap *map) {
while (map->pin != NC) { while (map->pin != NC) {
if (map->pin == pin) { if (map->pin == pin) {
pin_function(pin, map->function); pin_function(pin, map->function);
#if defined(TARGET_STM32F407)
pin_alternate_function(pin, map->alternate_function);
#endif
pin_mode(pin, PullNone); pin_mode(pin, PullNone);
return; return;
} }

View File

@ -29,9 +29,13 @@ extern "C" {
uint32_t gpio_set(PinName pin); uint32_t gpio_set(PinName pin);
/* GPIO object */ /* GPIO object */
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction); void gpio_init (gpio_t *obj, PinName pin, PinDirection direction);
void gpio_mode(gpio_t *obj, PinMode mode);
void gpio_dir (gpio_t *obj, PinDirection direction); void gpio_mode (gpio_t *obj, PinMode mode);
void gpio_dir (gpio_t *obj, PinDirection direction);
void gpio_write(gpio_t *obj, int value);
int gpio_read (gpio_t *obj);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -26,10 +26,15 @@ extern "C" {
typedef struct i2c_s i2c_t; typedef struct i2c_s i2c_t;
enum {
I2C_ERROR_NO_SLAVE = -1,
I2C_ERROR_BUS_BUSY = -2
};
void i2c_init (i2c_t *obj, PinName sda, PinName scl); void i2c_init (i2c_t *obj, PinName sda, PinName scl);
void i2c_frequency (i2c_t *obj, int hz); void i2c_frequency (i2c_t *obj, int hz);
int i2c_start (i2c_t *obj); int i2c_start (i2c_t *obj);
void i2c_stop (i2c_t *obj); int i2c_stop (i2c_t *obj);
int i2c_read (i2c_t *obj, int address, char *data, int length, int stop); 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 i2c_write (i2c_t *obj, int address, const char *data, int length, int stop);
void i2c_reset (i2c_t *obj); void i2c_reset (i2c_t *obj);

View File

@ -26,15 +26,9 @@ typedef struct {
PinName pin; PinName pin;
int peripheral; int peripheral;
int function; int function;
#if defined(TARGET_STM32F407)
int alternate_function;
#endif
} PinMap; } PinMap;
void pin_function(PinName pin, int function); void pin_function(PinName pin, int function);
# if defined(TARGET_STM32F407)
void pin_alternate_function(PinName pin, int alternate_function);
#endif
void pin_mode (PinName pin, PinMode mode); void pin_mode (PinName pin, PinMode mode);
uint32_t pinmap_peripheral(PinName pin, const PinMap* map); uint32_t pinmap_peripheral(PinName pin, const PinMap* map);

View File

@ -96,7 +96,7 @@ int i2c_start(i2c_t *obj) {
return 0; return 0;
} }
void i2c_stop(i2c_t *obj) { int i2c_stop(i2c_t *obj) {
volatile uint32_t n = 0; volatile uint32_t n = 0;
obj->i2c->C1 &= ~I2C_C1_MST_MASK; obj->i2c->C1 &= ~I2C_C1_MST_MASK;
obj->i2c->C1 &= ~I2C_C1_TX_MASK; obj->i2c->C1 &= ~I2C_C1_TX_MASK;
@ -107,6 +107,7 @@ void i2c_stop(i2c_t *obj) {
// code provided with the freedom board // code provided with the freedom board
for (n = 0; n < 100; n++) __NOP(); for (n = 0; n < 100; n++) __NOP();
first_read = 1; first_read = 1;
return 0;
} }
static int timeout_status_poll(i2c_t *obj, uint32_t mask) { static int timeout_status_poll(i2c_t *obj, uint32_t mask) {
@ -221,12 +222,12 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
if (i2c_start(obj)) { if (i2c_start(obj)) {
i2c_stop(obj); i2c_stop(obj);
return 1; return I2C_ERROR_BUS_BUSY;
} }
if (i2c_do_write(obj, (address | 0x01))) { if (i2c_do_write(obj, (address | 0x01))) {
i2c_stop(obj); i2c_stop(obj);
return 1; return I2C_ERROR_NO_SLAVE;
} }
// set rx mode // set rx mode
@ -238,7 +239,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
uint8_t stop_ = (count == (length - 1)) ? 1 : 0; uint8_t stop_ = (count == (length - 1)) ? 1 : 0;
if (i2c_do_read(obj, ptr, stop_)) { if (i2c_do_read(obj, ptr, stop_)) {
i2c_stop(obj); i2c_stop(obj);
return 1; return count;
} }
} }
@ -250,25 +251,25 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
// last read // last read
data[count-1] = obj->i2c->D; data[count-1] = obj->i2c->D;
return 0; return length;
} }
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
int i; int i;
if (i2c_start(obj)) { if (i2c_start(obj)) {
i2c_stop(obj); i2c_stop(obj);
return 1; return I2C_ERROR_BUS_BUSY;
} }
if (i2c_do_write(obj, (address & 0xFE))) { if (i2c_do_write(obj, (address & 0xFE))) {
i2c_stop(obj); i2c_stop(obj);
return 1; return I2C_ERROR_NO_SLAVE;
} }
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if(i2c_do_write(obj, data[i])) { if(i2c_do_write(obj, data[i])) {
i2c_stop(obj); i2c_stop(obj);
return 1; return i;
} }
} }
@ -276,7 +277,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
i2c_stop(obj); i2c_stop(obj);
} }
return 0; return length;
} }
void i2c_reset(i2c_t *obj) { void i2c_reset(i2c_t *obj) {
@ -363,7 +364,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) {
for (count = 0; count < (length - 1); count++) { for (count = 0; count < (length - 1); count++) {
data[count] = obj->i2c->D; data[count] = obj->i2c->D;
if(i2c_wait_end_rx_transfer(obj)) { if(i2c_wait_end_rx_transfer(obj)) {
return 0; return count;
} }
} }
@ -382,7 +383,7 @@ int i2c_slave_write(i2c_t *obj, const char *data, int length) {
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if(i2c_do_write(obj, data[count++]) == 2) { if(i2c_do_write(obj, data[count++]) == 2) {
return 0; return i;
} }
} }
@ -393,7 +394,7 @@ int i2c_slave_write(i2c_t *obj, const char *data, int length) {
// otherwise the master cannot generate a stop bit // otherwise the master cannot generate a stop bit
obj->i2c->D; obj->i2c->D;
if(i2c_wait_end_rx_transfer(obj) == 2) { if(i2c_wait_end_rx_transfer(obj) == 2) {
return 0; return count;
} }
return count; return count;

View File

@ -124,13 +124,20 @@ inline int i2c_start(i2c_t *obj) {
return status; return status;
} }
inline void i2c_stop(i2c_t *obj) { inline int i2c_stop(i2c_t *obj) {
int timeout = 0;
// write the stop bit // write the stop bit
i2c_conset(obj, 0, 1, 0, 0); i2c_conset(obj, 0, 1, 0, 0);
i2c_clear_SI(obj); i2c_clear_SI(obj);
// wait for STO bit to reset // wait for STO bit to reset
while(I2C_CONSET(obj) & (1 << 4)); while(I2C_CONSET(obj) & (1 << 4)) {
timeout ++;
if (timeout > 100000) return 1;
}
return 0;
} }
@ -196,13 +203,13 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
if ((status != 0x10) && (status != 0x08)) { if ((status != 0x10) && (status != 0x08)) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_BUS_BUSY;
} }
status = i2c_do_write(obj, (address | 0x01), 1); status = i2c_do_write(obj, (address | 0x01), 1);
if (status != 0x40) { if (status != 0x40) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_NO_SLAVE;
} }
// Read in all except last byte // Read in all except last byte
@ -211,7 +218,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
status = i2c_status(obj); status = i2c_status(obj);
if (status != 0x50) { if (status != 0x50) {
i2c_stop(obj); i2c_stop(obj);
return status; return count;
} }
data[count] = (char) value; data[count] = (char) value;
} }
@ -221,7 +228,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
status = i2c_status(obj); status = i2c_status(obj);
if (status != 0x58) { if (status != 0x58) {
i2c_stop(obj); i2c_stop(obj);
return status; return length - 1;
} }
data[count] = (char) value; data[count] = (char) value;
@ -231,7 +238,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
i2c_stop(obj); i2c_stop(obj);
} }
return 0; return length;
} }
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
@ -241,20 +248,20 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
if ((status != 0x10) && (status != 0x08)) { if ((status != 0x10) && (status != 0x08)) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_BUS_BUSY;
} }
status = i2c_do_write(obj, (address & 0xFE), 1); status = i2c_do_write(obj, (address & 0xFE), 1);
if (status != 0x18) { if (status != 0x18) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_NO_SLAVE;
} }
for (i=0; i<length; i++) { for (i=0; i<length; i++) {
status = i2c_do_write(obj, data[i], 0); status = i2c_do_write(obj, data[i], 0);
if(status != 0x28) { if(status != 0x28) {
i2c_stop(obj); i2c_stop(obj);
return status; return i;
} }
} }
@ -265,7 +272,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
i2c_stop(obj); i2c_stop(obj);
} }
return 0; return length;
} }
void i2c_reset(i2c_t *obj) { void i2c_reset(i2c_t *obj) {
@ -343,7 +350,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) {
i2c_clear_SI(obj); i2c_clear_SI(obj);
return (count - 1); return count;
} }
int i2c_slave_write(i2c_t *obj, const char *data, int length) { int i2c_slave_write(i2c_t *obj, const char *data, int length) {

View File

@ -133,13 +133,20 @@ inline int i2c_start(i2c_t *obj) {
return status; return status;
} }
inline void i2c_stop(i2c_t *obj) { inline int i2c_stop(i2c_t *obj) {
int timeout = 0;
// write the stop bit // write the stop bit
i2c_conset(obj, 0, 1, 0, 0); i2c_conset(obj, 0, 1, 0, 0);
i2c_clear_SI(obj); i2c_clear_SI(obj);
// wait for STO bit to reset // wait for STO bit to reset
while(I2C_CONSET(obj) & (1 << 4)); while(I2C_CONSET(obj) & (1 << 4)) {
timeout ++;
if (timeout > 100000) return 1;
}
return 0;
} }
static inline int i2c_do_write(i2c_t *obj, int value, uint8_t addr) { static inline int i2c_do_write(i2c_t *obj, int value, uint8_t addr) {
@ -204,13 +211,13 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
if ((status != 0x10) && (status != 0x08)) { if ((status != 0x10) && (status != 0x08)) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_BUS_BUSY;
} }
status = i2c_do_write(obj, (address | 0x01), 1); status = i2c_do_write(obj, (address | 0x01), 1);
if (status != 0x40) { if (status != 0x40) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_NO_SLAVE;
} }
// Read in all except last byte // Read in all except last byte
@ -219,7 +226,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
status = i2c_status(obj); status = i2c_status(obj);
if (status != 0x50) { if (status != 0x50) {
i2c_stop(obj); i2c_stop(obj);
return status; return count;
} }
data[count] = (char) value; data[count] = (char) value;
} }
@ -229,7 +236,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
status = i2c_status(obj); status = i2c_status(obj);
if (status != 0x58) { if (status != 0x58) {
i2c_stop(obj); i2c_stop(obj);
return status; return length - 1;
} }
data[count] = (char) value; data[count] = (char) value;
@ -239,7 +246,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
i2c_stop(obj); i2c_stop(obj);
} }
return 0; return length;
} }
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
@ -249,20 +256,20 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
if ((status != 0x10) && (status != 0x08)) { if ((status != 0x10) && (status != 0x08)) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_BUS_BUSY;
} }
status = i2c_do_write(obj, (address & 0xFE), 1); status = i2c_do_write(obj, (address & 0xFE), 1);
if (status != 0x18) { if (status != 0x18) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_NO_SLAVE;
} }
for (i=0; i<length; i++) { for (i=0; i<length; i++) {
status = i2c_do_write(obj, data[i], 0); status = i2c_do_write(obj, data[i], 0);
if(status != 0x28) { if(status != 0x28) {
i2c_stop(obj); i2c_stop(obj);
return status; return i;
} }
} }
@ -273,7 +280,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
i2c_stop(obj); i2c_stop(obj);
} }
return 0; return length;
} }
void i2c_reset(i2c_t *obj) { void i2c_reset(i2c_t *obj) {
@ -351,7 +358,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) {
i2c_clear_SI(obj); i2c_clear_SI(obj);
return (count - 1); return count;
} }
int i2c_slave_write(i2c_t *obj, const char *data, int length) { int i2c_slave_write(i2c_t *obj, const char *data, int length) {

View File

@ -133,13 +133,20 @@ inline int i2c_start(i2c_t *obj) {
return status; return status;
} }
inline void i2c_stop(i2c_t *obj) { inline int i2c_stop(i2c_t *obj) {
int timeout = 0;
// write the stop bit // write the stop bit
i2c_conset(obj, 0, 1, 0, 0); i2c_conset(obj, 0, 1, 0, 0);
i2c_clear_SI(obj); i2c_clear_SI(obj);
// wait for STO bit to reset // wait for STO bit to reset
while (I2C_CONSET(obj) & (1 << 4)); while (I2C_CONSET(obj) & (1 << 4)) {
timeout ++;
if (timeout > 100000) return 1;
}
return 0;
} }
static inline int i2c_do_write(i2c_t *obj, int value, uint8_t addr) { static inline int i2c_do_write(i2c_t *obj, int value, uint8_t addr) {
@ -203,13 +210,13 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
if ((status != 0x10) && (status != 0x08)) { if ((status != 0x10) && (status != 0x08)) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_BUS_BUSY;
} }
status = i2c_do_write(obj, (address | 0x01), 1); status = i2c_do_write(obj, (address | 0x01), 1);
if (status != 0x40) { if (status != 0x40) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_NO_SLAVE;
} }
// Read in all except last byte // Read in all except last byte
@ -218,7 +225,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
status = i2c_status(obj); status = i2c_status(obj);
if (status != 0x50) { if (status != 0x50) {
i2c_stop(obj); i2c_stop(obj);
return status; return count;
} }
data[count] = (char) value; data[count] = (char) value;
} }
@ -228,7 +235,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
status = i2c_status(obj); status = i2c_status(obj);
if (status != 0x58) { if (status != 0x58) {
i2c_stop(obj); i2c_stop(obj);
return status; return length - 1;
} }
data[count] = (char) value; data[count] = (char) value;
@ -238,7 +245,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
i2c_stop(obj); i2c_stop(obj);
} }
return 0; return length;
} }
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
@ -248,20 +255,20 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
if ((status != 0x10) && (status != 0x08)) { if ((status != 0x10) && (status != 0x08)) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_BUS_BUSY;
} }
status = i2c_do_write(obj, (address & 0xFE), 1); status = i2c_do_write(obj, (address & 0xFE), 1);
if (status != 0x18) { if (status != 0x18) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_NO_SLAVE;
} }
for (i=0; i<length; i++) { for (i=0; i<length; i++) {
status = i2c_do_write(obj, data[i], 0); status = i2c_do_write(obj, data[i], 0);
if (status != 0x28) { if (status != 0x28) {
i2c_stop(obj); i2c_stop(obj);
return status; return i;
} }
} }
@ -272,7 +279,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
i2c_stop(obj); i2c_stop(obj);
} }
return 0; return length;
} }
void i2c_reset(i2c_t *obj) { void i2c_reset(i2c_t *obj) {
@ -353,7 +360,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) {
i2c_clear_SI(obj); i2c_clear_SI(obj);
return (count - 1); return count;
} }
int i2c_slave_write(i2c_t *obj, const char *data, int length) { int i2c_slave_write(i2c_t *obj, const char *data, int length) {

View File

@ -144,13 +144,20 @@ inline int i2c_start(i2c_t *obj) {
return status; return status;
} }
inline void i2c_stop(i2c_t *obj) { inline int i2c_stop(i2c_t *obj) {
int timeout = 0;
// write the stop bit // write the stop bit
i2c_conset(obj, 0, 1, 0, 0); i2c_conset(obj, 0, 1, 0, 0);
i2c_clear_SI(obj); i2c_clear_SI(obj);
// wait for STO bit to reset // wait for STO bit to reset
while(I2C_CONSET(obj) & (1 << 4)); while(I2C_CONSET(obj) & (1 << 4)) {
timeout ++;
if (timeout > 100000) return 1;
}
return 0;
} }
@ -213,13 +220,13 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
if ((status != 0x10) && (status != 0x08)) { if ((status != 0x10) && (status != 0x08)) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_BUS_BUSY;
} }
status = i2c_do_write(obj, (address | 0x01), 1); status = i2c_do_write(obj, (address | 0x01), 1);
if (status != 0x40) { if (status != 0x40) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_NO_SLAVE;
} }
// Read in all except last byte // Read in all except last byte
@ -228,7 +235,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
status = i2c_status(obj); status = i2c_status(obj);
if (status != 0x50) { if (status != 0x50) {
i2c_stop(obj); i2c_stop(obj);
return status; return count;
} }
data[count] = (char) value; data[count] = (char) value;
} }
@ -238,7 +245,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
status = i2c_status(obj); status = i2c_status(obj);
if (status != 0x58) { if (status != 0x58) {
i2c_stop(obj); i2c_stop(obj);
return status; return length - 1;
} }
data[count] = (char) value; data[count] = (char) value;
@ -248,7 +255,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
i2c_stop(obj); i2c_stop(obj);
} }
return 0; return length;
} }
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
@ -258,20 +265,20 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
if ((status != 0x10) && (status != 0x08)) { if ((status != 0x10) && (status != 0x08)) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_BUS_BUSY;
} }
status = i2c_do_write(obj, (address & 0xFE), 1); status = i2c_do_write(obj, (address & 0xFE), 1);
if (status != 0x18) { if (status != 0x18) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_NO_SLAVE;
} }
for (i=0; i<length; i++) { for (i=0; i<length; i++) {
status = i2c_do_write(obj, data[i], 0); status = i2c_do_write(obj, data[i], 0);
if (status != 0x28) { if (status != 0x28) {
i2c_stop(obj); i2c_stop(obj);
return status; return i;
} }
} }
@ -282,7 +289,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
i2c_stop(obj); i2c_stop(obj);
} }
return 0; return length;
} }
void i2c_reset(i2c_t *obj) { void i2c_reset(i2c_t *obj) {
@ -363,7 +370,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) {
i2c_clear_SI(obj); i2c_clear_SI(obj);
return (count - 1); return count;
} }
int i2c_slave_write(i2c_t *obj, const char *data, int length) { int i2c_slave_write(i2c_t *obj, const char *data, int length) {

View File

@ -87,9 +87,16 @@ inline int i2c_start(i2c_t *obj) {
return status; return status;
} }
inline void i2c_stop(i2c_t *obj) { inline int i2c_stop(i2c_t *obj) {
int timeout = 0;
obj->i2c->MSTCTL = (1 << 2) | (1 << 0); obj->i2c->MSTCTL = (1 << 2) | (1 << 0);
while ((obj->i2c->STAT & ((1 << 0) | (7 << 1))) != ((1 << 0) | (0 << 1))); while ((obj->i2c->STAT & ((1 << 0) | (7 << 1))) != ((1 << 0) | (0 << 1))) {
timeout ++;
if (timeout > 100000) return 1;
}
return 0;
} }
@ -147,7 +154,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
status = i2c_do_write(obj, (address | 0x01), 1); status = i2c_do_write(obj, (address | 0x01), 1);
if (status != 0x01) { if (status != 0x01) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_NO_SLAVE;
} }
// Read in all except last byte // Read in all except last byte
@ -156,7 +163,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
status = i2c_status(obj); status = i2c_status(obj);
if (status != 0x00) { if (status != 0x00) {
i2c_stop(obj); i2c_stop(obj);
return status; return count;
} }
data[count] = (char) value; data[count] = (char) value;
} }
@ -166,7 +173,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
status = i2c_status(obj); status = i2c_status(obj);
if (status != 0x01) { if (status != 0x01) {
i2c_stop(obj); i2c_stop(obj);
return status; return length - 1;
} }
data[count] = (char) value; data[count] = (char) value;
@ -178,7 +185,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
repeated_start = 1; repeated_start = 1;
} }
return 0; return length;
} }
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
@ -189,14 +196,14 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
status = i2c_do_write(obj, (address & 0xFE), 1); status = i2c_do_write(obj, (address & 0xFE), 1);
if (status != 0x02) { if (status != 0x02) {
i2c_stop(obj); i2c_stop(obj);
return status; return I2C_ERROR_NO_SLAVE;
} }
for (i=0; i<length; i++) { for (i=0; i<length; i++) {
status = i2c_do_write(obj, data[i], 0); status = i2c_do_write(obj, data[i], 0);
if (status != 0x02) { if (status != 0x02) {
i2c_stop(obj); i2c_stop(obj);
return status; return i;
} }
} }
@ -207,7 +214,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
repeated_start = 1; repeated_start = 1;
} }
return 0; return length;
} }
void i2c_reset(i2c_t *obj) { void i2c_reset(i2c_t *obj) {

View File

@ -22,6 +22,10 @@
extern "C" { extern "C" {
#endif #endif
#define STM_PIN_DATA(MODE, FUNC) (((MODE) << 8) | (FUNC))
#define STM_PIN_MODE(X) ((X) >> 8)
#define STM_PIN_FUNC(X) ((X) & 0xFF)
typedef enum { typedef enum {
PIN_INPUT, PIN_INPUT,
PIN_OUTPUT PIN_OUTPUT

View File

@ -25,23 +25,23 @@
#define ADC_12BIT_RANGE 0xFFF #define ADC_12BIT_RANGE 0xFFF
static const PinMap PinMap_ADC[] = { static const PinMap PinMap_ADC[] = {
{PA_0, ADC0_0, 3, 0}, {PA_0, ADC0_0, STM_PIN_DATA(3, 0)},
{PA_1, ADC0_1, 3, 0}, {PA_1, ADC0_1, STM_PIN_DATA(3, 0)},
{PA_2, ADC0_2, 3, 0}, {PA_2, ADC0_2, STM_PIN_DATA(3, 0)},
{PA_3, ADC0_3, 3, 0}, {PA_3, ADC0_3, STM_PIN_DATA(3, 0)},
{PA_4, ADC0_4, 3, 0}, {PA_4, ADC0_4, STM_PIN_DATA(3, 0)},
{PA_5, ADC0_5, 3, 0}, {PA_5, ADC0_5, STM_PIN_DATA(3, 0)},
{PA_6, ADC0_6, 3, 0}, {PA_6, ADC0_6, STM_PIN_DATA(3, 0)},
{PA_7, ADC0_7, 3, 0}, {PA_7, ADC0_7, STM_PIN_DATA(3, 0)},
{PB_0, ADC0_8, 3, 0}, {PB_0, ADC0_8, STM_PIN_DATA(3, 0)},
{PB_1, ADC0_9, 3, 0}, {PB_1, ADC0_9, STM_PIN_DATA(3, 0)},
{PC_0, ADC0_10, 3, 0}, {PC_0, ADC0_10, STM_PIN_DATA(3, 0)},
{PC_1, ADC0_11, 3, 0}, {PC_1, ADC0_11, STM_PIN_DATA(3, 0)},
{PC_2, ADC0_12, 3, 0}, {PC_2, ADC0_12, STM_PIN_DATA(3, 0)},
{PC_3, ADC0_13, 3, 0}, {PC_3, ADC0_13, STM_PIN_DATA(3, 0)},
{PC_4, ADC0_14, 3, 0}, {PC_4, ADC0_14, STM_PIN_DATA(3, 0)},
{PC_5, ADC0_15, 3, 0}, {PC_5, ADC0_15, STM_PIN_DATA(3, 0)},
{NC, NC, 0, 0} {NC, NC, 0}
}; };
# define ADC_RANGE ADC_12BIT_RANGE # define ADC_RANGE ADC_12BIT_RANGE

View File

@ -22,7 +22,7 @@ uint32_t gpio_set(PinName pin) {
// Enable GPIO peripheral clock // Enable GPIO peripheral clock
RCC->AHB1ENR |= 1 << port_index; RCC->AHB1ENR |= 1 << port_index;
pin_function(pin, 0); pin_function(pin, STM_PIN_DATA(0, 0));
return 1 << ((uint32_t) pin & 0xF); return 1 << ((uint32_t) pin & 0xF);
} }
@ -55,7 +55,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
void gpio_dir(gpio_t *obj, PinDirection direction) { void gpio_dir(gpio_t *obj, PinDirection direction) {
switch (direction) { switch (direction) {
case PIN_INPUT : pin_function(obj->pin, 0); break; case PIN_INPUT : pin_function(obj->pin, STM_PIN_DATA(0, 0)); break;
case PIN_OUTPUT: pin_function(obj->pin, 1); break; case PIN_OUTPUT: pin_function(obj->pin, STM_PIN_DATA(1, 0)); break;
} }
} }

View File

@ -22,25 +22,25 @@
#include "error.h" #include "error.h"
static const PinMap PinMap_I2C_SDA[] = { static const PinMap PinMap_I2C_SDA[] = {
{PB_7, I2C_1, 2, 4}, {PB_7, I2C_1, STM_PIN_DATA(2, 4)},
{PB_9, I2C_1, 2, 4}, {PB_9, I2C_1, STM_PIN_DATA(2, 4)},
{PB_11, I2C_2, 2, 4}, {PB_11, I2C_2, STM_PIN_DATA(2, 4)},
{PC_9, I2C_3, 2, 4}, {PC_9, I2C_3, STM_PIN_DATA(2, 4)},
{PF_0, I2C_2, 2, 4}, {PF_0, I2C_2, STM_PIN_DATA(2, 4)},
{PH_5, I2C_2, 2, 4}, {PH_5, I2C_2, STM_PIN_DATA(2, 4)},
{PH_8, I2C_3, 2, 4}, {PH_8, I2C_3, STM_PIN_DATA(2, 4)},
{NC , NC , 0, 0} {NC, NC, 0}
}; };
static const PinMap PinMap_I2C_SCL[] = { static const PinMap PinMap_I2C_SCL[] = {
{PA_8, I2C_3, 2, 4}, {PA_8, I2C_3, STM_PIN_DATA(2, 4)},
{PB_6, I2C_1, 2, 4}, {PB_6, I2C_1, STM_PIN_DATA(2, 4)},
{PB_8, I2C_1, 2, 4}, {PB_8, I2C_1, STM_PIN_DATA(2, 4)},
{PB_10, I2C_2, 2, 4}, {PB_10, I2C_2, STM_PIN_DATA(2, 4)},
{PF_1, I2C_2, 2, 4}, {PF_1, I2C_2, STM_PIN_DATA(2, 4)},
{PH_4, I2C_2, 2, 4}, {PH_4, I2C_2, STM_PIN_DATA(2, 4)},
{PH_7, I2C_3, 2, 4}, {PH_7, I2C_3, STM_PIN_DATA(2, 4)},
{NC , NC, 0, 0} {NC, NC, 0}
}; };
static const uint32_t I2C_addr_offset[2][4] = { static const uint32_t I2C_addr_offset[2][4] = {
@ -163,9 +163,10 @@ inline int i2c_start(i2c_t *obj) {
return 0; return 0;
} }
inline void i2c_stop(i2c_t *obj) { inline int i2c_stop(i2c_t *obj) {
// Generate the stop condition // Generate the stop condition
obj->i2c->CR1 |= I2C_CR1_STOP; obj->i2c->CR1 |= I2C_CR1_STOP;
return 0;
} }
@ -251,7 +252,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
i2c_stop(obj); i2c_stop(obj);
} }
return 0; return length;
} }
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
@ -273,7 +274,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
i2c_stop(obj); i2c_stop(obj);
} }
return 0; return length;
} }
void i2c_reset(i2c_t *obj) { void i2c_reset(i2c_t *obj) {

View File

@ -19,43 +19,38 @@
/** /**
* Set the pin into input, output, alternate function or analog mode * Set the pin into input, output, alternate function or analog mode
*/ */
void pin_function(PinName pin, int function) { void pin_function(PinName pin, int data) {
if (pin == (uint32_t)NC) return; if (pin == (uint32_t)NC) return;
int mode = STM_PIN_MODE(data);
int func = STM_PIN_FUNC(data);
uint32_t pin_number = (uint32_t)pin; uint32_t pin_number = (uint32_t)pin;
int port_index = pin_number >> 4; int port_index = pin_number >> 4;
int pin_index = (pin_number & 0xF); int pin_index = (pin_number & 0xF);
int offset = pin_index << 1;
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) (GPIOA_BASE + (port_index << 10))); GPIO_TypeDef * gpio = ((GPIO_TypeDef *) (GPIOA_BASE + (port_index << 10)));
// MODE
int offset = pin_index << 1;
gpio->MODER &= ~(0x3 << offset); gpio->MODER &= ~(0x3 << offset);
gpio->MODER |= function << offset; gpio->MODER |= mode << offset;
// Set high-speed mode // Set high-speed mode
gpio->OSPEEDR &= ~(0x3 << offset); gpio->OSPEEDR &= ~(0x3 << offset);
gpio->OSPEEDR |= (0x2 << offset); gpio->OSPEEDR |= (0x2 << offset);
}
// FUNCTION
void pin_alternate_function(PinName pin, int function) {
if (pin == (uint32_t)NC) return;
uint32_t pin_number = (uint32_t)pin;
int port_index = pin_number >> 4;
int pin_index = (pin_number & 0xF);
int offset = (pin_index & 0x7) << 2;
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) (GPIOA_BASE + (port_index << 10)));
// Bottom seven pins are in AFR[0], top seven in AFR[1] // Bottom seven pins are in AFR[0], top seven in AFR[1]
offset = (pin_index & 0x7) << 2;
if (pin_index <= 0x7) { if (pin_index <= 0x7) {
gpio->AFR[0] &= ~(0xF << offset); gpio->AFR[0] &= ~(0xF << offset);
gpio->AFR[0] |= function << offset; gpio->AFR[0] |= func << offset;
} }
else { else {
gpio->AFR[1] &= ~(0xF << offset); gpio->AFR[1] &= ~(0xF << offset);
gpio->AFR[1] |= function << offset; gpio->AFR[1] |= func << offset;
} }
} }
void pin_mode(PinName pin, PinMode mode) { void pin_mode(PinName pin, PinMode mode) {
if (pin == (uint32_t)NC) { return; } if (pin == (uint32_t)NC) { return; }

View File

@ -23,43 +23,43 @@
#include "error.h" #include "error.h"
static const PinMap PinMap_SPI_SCLK[] = { static const PinMap PinMap_SPI_SCLK[] = {
{PA_5, SPI_1, 2, 5}, {PA_5, SPI_1, STM_PIN_DATA(2, 5)},
{PB_3, SPI_1, 2, 5}, {PB_3, SPI_1, STM_PIN_DATA(2, 5)},
{PB_3, SPI_3, 2, 6}, {PB_3, SPI_3, STM_PIN_DATA(2, 6)},
{PB_10, SPI_2, 2, 5}, {PB_10, SPI_2, STM_PIN_DATA(2, 5)},
{PB_13, SPI_2, 2, 5}, {PB_13, SPI_2, STM_PIN_DATA(2, 5)},
{PC_10, SPI_3, 2, 6}, {PC_10, SPI_3, STM_PIN_DATA(2, 6)},
{NC , NC , 0, 0} {NC, NC, 0}
}; };
static const PinMap PinMap_SPI_MOSI[] = { static const PinMap PinMap_SPI_MOSI[] = {
{PA_7, SPI_1, 2, 5}, {PA_7, SPI_1, STM_PIN_DATA(2, 5)},
{PB_5, SPI_1, 2, 5}, {PB_5, SPI_1, STM_PIN_DATA(2, 5)},
{PB_5, SPI_3, 2, 6}, {PB_5, SPI_3, STM_PIN_DATA(2, 6)},
{PB_15, SPI_2, 2, 5}, {PB_15, SPI_2, STM_PIN_DATA(2, 5)},
{PC_3, SPI_2, 2, 5}, {PC_3, SPI_2, STM_PIN_DATA(2, 5)},
{PC_12, SPI_3, 2, 6}, {PC_12, SPI_3, STM_PIN_DATA(2, 6)},
{NC , NC , 0, 0} {NC, NC, 0}
}; };
static const PinMap PinMap_SPI_MISO[] = { static const PinMap PinMap_SPI_MISO[] = {
{PA_6, SPI_1, 2, 5}, {PA_6, SPI_1, STM_PIN_DATA(2, 5)},
{PB_4, SPI_1, 2, 5}, {PB_4, SPI_1, STM_PIN_DATA(2, 5)},
{PB_4, SPI_3, 2, 6}, {PB_4, SPI_3, STM_PIN_DATA(2, 6)},
{PB_14, SPI_2, 2, 5}, {PB_14, SPI_2, STM_PIN_DATA(2, 5)},
{PC_2, SPI_2, 2, 5}, {PC_2, SPI_2, STM_PIN_DATA(2, 5)},
{PC_11, SPI_3, 2, 6}, {PC_11, SPI_3, STM_PIN_DATA(2, 6)},
{NC , NC , 0, 0} {NC, NC, 0}
}; };
static const PinMap PinMap_SPI_SSEL[] = { static const PinMap PinMap_SPI_SSEL[] = {
{PA_4, SPI_1, 2, 5}, {PA_4, SPI_1, STM_PIN_DATA(2, 5)},
{PA_4, SPI_3, 2, 6}, {PA_4, SPI_3, STM_PIN_DATA(2, 6)},
{PA_15, SPI_1, 2, 5}, {PA_15, SPI_1, STM_PIN_DATA(2, 5)},
{PA_15, SPI_3, 2, 6}, {PA_15, SPI_3, STM_PIN_DATA(2, 6)},
{PB_9, SPI_2, 2, 5}, {PB_9, SPI_2, STM_PIN_DATA(2, 5)},
{PB_12, SPI_2, 2, 5}, {PB_12, SPI_2, STM_PIN_DATA(2, 5)},
{NC , NC , 0, 0} {NC, NC, 0}
}; };

View File

@ -55,19 +55,13 @@ public:
void queue(T k) void queue(T k)
{ {
mtx.lock(); mtx.lock();
while (((write + 1) % size) == read) //if (isFull())
{
/*while((((write + 1) % size) == read))
{*/
mtx.unlock();
Thread::wait(10);
mtx.lock();
/*}*/
//read++;
//read %= size;
}
buf[write++] = k; buf[write++] = k;
write %= size; write %= size;
if (isFull())
{
read++;
read %= size;
}
mtx.unlock(); mtx.unlock();
} }

View File

@ -0,0 +1,60 @@
#include "mbed.h"
#include "test_env.h"
#include <stdio.h>
#define ADDR (0xA0)
#define FREQ 100000
// ********************************************************
// This tests data transfer between two I2C interfaces on
// the same chip, one configured as master, the other as
// slave. Works on the LPC1768 mbed.
//
// Wiring:
// p28 <-> p9
// p27 <-> p10
// pull-up resistors on both lines
// ********************************************************
I2CSlave slave(p9, p10);
I2C master(p28, p27);
int main()
{
char sent = 'T', received;
master.frequency(FREQ);
slave.frequency(FREQ);
slave.address(ADDR);
// First transfer: master to slave
master.start();
master.write(ADDR);
master.write(sent);
if(slave.receive() != I2CSlave::WriteAddressed)
{
notify_completion(false);
return 1;
}
slave.read(&received, 1);
if(sent != received)
{
notify_completion(false);
return 1;
}
master.stop();
// Second transfer: slave to master
master.start();
master.write(ADDR | 1);
if(slave.receive() != I2CSlave::ReadAddressed)
{
notify_completion(false);
return 1;
}
slave.write(received);
received = master.read(0);
slave.stop();
notify_completion(received == sent);
}

View File

@ -85,9 +85,11 @@ if __name__ == '__main__':
id = "%s::%s" % (toolchain, target) id = "%s::%s" % (toolchain, target)
try: try:
mcu = TARGET_MAP[target] mcu = TARGET_MAP[target]
build_mbed_libs(mcu, toolchain, verbose=options.verbose) build_mbed_libs(mcu, toolchain, options=options.options,
verbose=options.verbose)
for lib_id in libraries: for lib_id in libraries:
build_lib(lib_id, mcu, toolchain, verbose=options.verbose) build_lib(lib_id, mcu, toolchain, options=options.options,
verbose=options.verbose)
successes.append(id) successes.append(id)
except Exception, e: except Exception, e:
if options.verbose: if options.verbose:

View File

@ -9,10 +9,10 @@ from workspace_tools.libraries import Library
def build_project(src_path, build_path, target, toolchain_name, def build_project(src_path, build_path, target, toolchain_name,
libraries_paths=None, linker_script=None, libraries_paths=None, options=None, linker_script=None,
clean=False, notify=None, verbose=False, name=None): clean=False, notify=None, verbose=False, name=None):
# Toolchain instance # Toolchain instance
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, notify) toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify)
toolchain.VERBOSE = verbose toolchain.VERBOSE = verbose
toolchain.build_all = clean toolchain.build_all = clean
@ -50,7 +50,8 @@ notify: Notify function for logs
verbose: Write the actual tools command lines if True verbose: Write the actual tools command lines if True
""" """
def build_library(src_paths, build_path, target, toolchain_name, def build_library(src_paths, build_path, target, toolchain_name,
dependencies_paths=None, name=None, clean=False, notify=None, verbose=False): dependencies_paths=None, options=None, name=None, clean=False,
notify=None, verbose=False):
if type(src_paths) != ListType: src_paths = [src_paths] if type(src_paths) != ListType: src_paths = [src_paths]
for src_path in src_paths: for src_path in src_paths:
@ -58,7 +59,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
raise Exception("The library source folder does not exist: %s", src_path) raise Exception("The library source folder does not exist: %s", src_path)
# Toolchain instance # Toolchain instance
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, notify) toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify)
toolchain.VERBOSE = verbose toolchain.VERBOSE = verbose
toolchain.build_all = clean toolchain.build_all = clean
@ -95,23 +96,23 @@ def build_library(src_paths, build_path, target, toolchain_name,
toolchain.build_library(objects, bin_path, name) toolchain.build_library(objects, bin_path, name)
def build_lib(lib_id, target, toolchain, verbose=False): def build_lib(lib_id, target, toolchain, options=None, verbose=False):
lib = Library(lib_id) lib = Library(lib_id)
if lib.is_supported(target, toolchain): if lib.is_supported(target, toolchain):
build_library(lib.source_dir, lib.build_dir, target, toolchain, lib.dependencies, verbose=verbose) build_library(lib.source_dir, lib.build_dir, target, toolchain, lib.dependencies, options, verbose=verbose)
else: else:
print '\n\nLibrary "%s" is not yet supported on target %s with toolchain %s' % (lib_id, target.name, toolchain) print '\n\nLibrary "%s" is not yet supported on target %s with toolchain %s' % (lib_id, target.name, toolchain)
# We do have unique legacy conventions about how we build and package the mbed library # We do have unique legacy conventions about how we build and package the mbed library
def build_mbed_libs(target, toolchain_name, verbose=False): def build_mbed_libs(target, toolchain_name, options=None, verbose=False):
# Check toolchain support # Check toolchain support
if toolchain_name not in target.supported_toolchains: if toolchain_name not in target.supported_toolchains:
print '\n%s target is not yet supported by toolchain %s' % (target.name, toolchain_name) print '\n%s target is not yet supported by toolchain %s' % (target.name, toolchain_name)
return return
# Toolchain # Toolchain
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target) toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options)
toolchain.VERBOSE = verbose toolchain.VERBOSE = verbose
# Source and Build Paths # Source and Build Paths

View File

@ -167,7 +167,7 @@ class CortexM(Target):
while True: while True:
r = self.transport.readDP(DP_REG['CTRL_STAT']) r = self.transport.readDP(DP_REG['CTRL_STAT'])
if (r & (CDBGPWRUPACK | CSYSPWRUPACK)) != (CSYSPWRUPREQ | CDBGPWRUPREQ): if (r & (CDBGPWRUPACK | CSYSPWRUPACK)) != (CDBGPWRUPACK | CSYSPWRUPACK):
break break
self.transport.writeDP(DP_REG['CTRL_STAT'], CSYSPWRUPREQ | CDBGPWRUPREQ | TRNNORMAL | MASKLANE) self.transport.writeDP(DP_REG['CTRL_STAT'], CSYSPWRUPREQ | CDBGPWRUPREQ | TRNNORMAL | MASKLANE)

View File

@ -23,7 +23,7 @@ setup(
description="CMSIS-DAP debugger for python", description="CMSIS-DAP debugger for python",
author="samux", author="samux",
author_email="samuel.mokrani@gmail.com", author_email="samuel.mokrani@gmail.com",
license="MIT", license="Apache 2.0",
classifiers = [ classifiers = [
"Development Status :: 4 - Beta", "Development Status :: 4 - Beta",
"License :: Apache 2.0", "License :: Apache 2.0",

View File

@ -91,7 +91,8 @@ if __name__ == '__main__':
target = TARGET_MAP[mcu] target = TARGET_MAP[mcu]
try: try:
bin = build_project(test.source_dir, build_dir, target, toolchain, bin = build_project(test.source_dir, build_dir, target, toolchain,
test.dependencies, linker_script=options.linker_script, test.dependencies, options.options,
linker_script=options.linker_script,
clean=options.clean, verbose=options.verbose) clean=options.clean, verbose=options.verbose)
print 'Image: %s' % bin print 'Image: %s' % bin

View File

@ -7,16 +7,18 @@ from workspace_tools.targets import TARGET_NAMES
def get_default_options_parser(): def get_default_options_parser():
parser = OptionParser() parser = OptionParser()
parser.add_option("-m", "--mcu", dest="mcu", parser.add_option("-m", "--mcu",
help="build for the given MCU (%s)" % ', '.join(TARGET_NAMES), help="build for the given MCU (%s)" % ', '.join(TARGET_NAMES),
metavar="MCU") metavar="MCU")
parser.add_option("-t", "--tool", dest="tool", parser.add_option("-t", "--tool",
help="build using the given TOOLCHAIN (%s)" % ', '.join(TOOLCHAINS), help="build using the given TOOLCHAIN (%s)" % ', '.join(TOOLCHAINS),
metavar="TOOLCHAIN") metavar="TOOLCHAIN")
parser.add_option("-c", "--clean", parser.add_option("-c", "--clean", action="store_true", default=False,
action="store_true", dest="clean", default=False,
help="clean the build directory") help="clean the build directory")
parser.add_option("-o", "--options", action="append",
help='Add a build option ("save-asm": save the asm generated by the compiler)')
return parser return parser

View File

@ -71,6 +71,8 @@ IAR_PATH = "C:/Program Files (x86)/IAR Systems/Embedded Workbench 6.0/arm"
CW_GCC_PATH = "C:/Freescale/CW MCU v10.3/Cross_Tools/arm-none-eabi-gcc-4_6_2/bin" CW_GCC_PATH = "C:/Freescale/CW MCU v10.3/Cross_Tools/arm-none-eabi-gcc-4_6_2/bin"
CW_EWL_PATH = "C:/Freescale/CW MCU v10.3/MCU/ARM_GCC_Support/ewl/lib" CW_EWL_PATH = "C:/Freescale/CW MCU v10.3/MCU/ARM_GCC_Support/ewl/lib"
BUILD_OPTIONS = []
try: try:
# Allow to overwrite the default settings without the need to edit the # Allow to overwrite the default settings without the need to edit the
# settings file stored in the repository # settings file stored in the repository

View File

@ -332,7 +332,14 @@ TESTS = [
"automated": True, "automated": True,
"peripherals": ["ADXL345"] "peripherals": ["ADXL345"]
}, },
{
"id": "MBED_29", "description": "I2C master/slave test",
"source_dir": join(TEST_DIR, "mbed", "i2c_master_slave"),
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB,],
"automated": True,
"mcu": ["LPC1768"]
},
# CMSIS RTOS tests # CMSIS RTOS tests
{ {
"id": "CMSIS_RTOS_1", "description": "Basic", "id": "CMSIS_RTOS_1", "description": "Basic",

View File

@ -7,6 +7,7 @@ from inspect import getmro
from workspace_tools.utils import run_cmd, mkdir, rel_path, ToolException, split_path from workspace_tools.utils import run_cmd, mkdir, rel_path, ToolException, split_path
from workspace_tools.patch import patch from workspace_tools.patch import patch
from workspace_tools.settings import BUILD_OPTIONS
def print_notify(event): def print_notify(event):
@ -110,7 +111,7 @@ class mbedToolchain:
"Cortex-M4" : ["__CORTEX_M4", "ARM_MATH_CM4", "__FPU_PRESENT=1"], "Cortex-M4" : ["__CORTEX_M4", "ARM_MATH_CM4", "__FPU_PRESENT=1"],
} }
def __init__(self, target, notify=None): def __init__(self, target, options=None, notify=None):
self.target = target self.target = target
if notify is not None: if notify is not None:
@ -118,6 +119,14 @@ class mbedToolchain:
else: else:
self.notify = print_notify self.notify = print_notify
if options is None:
self.options = []
else:
self.options = options
self.options.extend(BUILD_OPTIONS)
if self.options:
self.info("Build Options: %s" % (', '.join(self.options)))
self.name = self.__class__.__name__ self.name = self.__class__.__name__
self.obj_path = join(target.name, self.name) self.obj_path = join(target.name, self.name)

View File

@ -13,8 +13,8 @@ class ARM(mbedToolchain):
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+): (?P<severity>Warning|Error): (?P<message>.+)') DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+): (?P<severity>Warning|Error): (?P<message>.+)')
DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n') DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
def __init__(self, target, notify): def __init__(self, target, options=None, notify=None):
mbedToolchain.__init__(self, target, notify) mbedToolchain.__init__(self, target, options, notify)
if target.core == "Cortex-M0+": if target.core == "Cortex-M0+":
cpu = "Cortex-M0" cpu = "Cortex-M0"
@ -27,7 +27,11 @@ class ARM(mbedToolchain):
"--cpu=%s" % cpu, "--gnu", "--cpu=%s" % cpu, "--gnu",
"-Ospace", "--split_sections", "--apcs=interwork", "-Ospace", "--split_sections", "--apcs=interwork",
"--brief_diagnostics", "--restrict" "--brief_diagnostics", "--restrict"
] # "--asm" "--interleave" ]
if "save-asm" in self.options:
common.extend(["--asm", "--interleave"])
common_c = [ common_c = [
"--md", "--no_depend_system_headers", "--md", "--no_depend_system_headers",
'-I%s' % ARM_INC '-I%s' % ARM_INC
@ -85,15 +89,15 @@ class ARM(mbedToolchain):
class ARM_STD(ARM): class ARM_STD(ARM):
def __init__(self, target, notify=None): def __init__(self, target, options=None, notify=None):
ARM.__init__(self, target, notify) ARM.__init__(self, target, options, notify)
self.ld.append("--libpath=%s" % ARM_LIB) self.ld.append("--libpath=%s" % ARM_LIB)
class ARM_MICRO(ARM): class ARM_MICRO(ARM):
PATCHED_LIBRARY = True PATCHED_LIBRARY = True
def __init__(self, target, notify=None): def __init__(self, target, options=None, notify=None):
ARM.__init__(self, target, notify) ARM.__init__(self, target, notify)
# Compiler # Compiler

View File

@ -13,8 +13,8 @@ class GCC(mbedToolchain):
CIRCULAR_DEPENDENCIES = True CIRCULAR_DEPENDENCIES = True
DIAGNOSTIC_PATTERN = re.compile('((?P<line>\d+):)(\d+:)? (?P<severity>warning|error): (?P<message>.+)') DIAGNOSTIC_PATTERN = re.compile('((?P<line>\d+):)(\d+:)? (?P<severity>warning|error): (?P<message>.+)')
def __init__(self, target, notify, tool_path): def __init__(self, target, options=None, notify=None, tool_path=""):
mbedToolchain.__init__(self, target, notify) mbedToolchain.__init__(self, target, options, notify)
if target.core == "Cortex-M0+": if target.core == "Cortex-M0+":
cpu = "cortex-m0" cpu = "cortex-m0"
@ -34,9 +34,12 @@ class GCC(mbedToolchain):
common_flags = ["-c", "-O2", "-Wall", common_flags = ["-c", "-O2", "-Wall",
"-fmessage-length=0", "-fno-exceptions", "-fno-builtin", "-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
"-ffunction-sections", "-fdata-sections", "-ffunction-sections", "-fdata-sections",
"-MMD", "-save-temps" "-MMD"
] + self.cpu ] + self.cpu
if "save-asm" in self.options:
common_flags.append("-save-temps")
self.asm = [join(tool_path, "arm-none-eabi-as")] + self.cpu self.asm = [join(tool_path, "arm-none-eabi-as")] + self.cpu
self.cc = [join(tool_path, "arm-none-eabi-gcc"), "-std=gnu99"] + common_flags self.cc = [join(tool_path, "arm-none-eabi-gcc"), "-std=gnu99"] + common_flags
@ -112,8 +115,8 @@ class GCC(mbedToolchain):
class GCC_ARM(GCC): class GCC_ARM(GCC):
def __init__(self, target, notify=None): def __init__(self, target, options=None, notify=None):
GCC.__init__(self, target, notify, GCC_ARM_PATH) GCC.__init__(self, target, options, notify, GCC_ARM_PATH)
# Use latest gcc nanolib # Use latest gcc nanolib
self.ld.append("--specs=nano.specs") self.ld.append("--specs=nano.specs")
@ -124,8 +127,8 @@ class GCC_ARM(GCC):
class GCC_CR(GCC): class GCC_CR(GCC):
def __init__(self, target, notify=None): def __init__(self, target, options=None, notify=None):
GCC.__init__(self, target, notify, GCC_CR_PATH) GCC.__init__(self, target, options, notify, GCC_CR_PATH)
additional_compiler_flags = [ additional_compiler_flags = [
"-D__NEWLIB__", "-D__CODE_RED", "-D__USE_CMSIS", "-DCPP_USE_HEAP", "-D__NEWLIB__", "-D__CODE_RED", "-D__USE_CMSIS", "-DCPP_USE_HEAP",
@ -137,8 +140,8 @@ class GCC_CR(GCC):
class GCC_CS(GCC): class GCC_CS(GCC):
def __init__(self, target, notify=None): def __init__(self, target, options=None, notify=None):
GCC.__init__(self, target, notify, GCC_CS_PATH) GCC.__init__(self, target, options, notify, GCC_CS_PATH)
class GCC_CW(GCC): class GCC_CW(GCC):
@ -146,13 +149,13 @@ class GCC_CW(GCC):
"Cortex-M0+": "armv6-m", "Cortex-M0+": "armv6-m",
} }
def __init__(self, target, notify=None): def __init__(self, target, options=None, notify=None):
GCC.__init__(self, target, notify, CW_GCC_PATH) GCC.__init__(self, target, options, notify, CW_GCC_PATH)
class GCC_CW_EWL(GCC_CW): class GCC_CW_EWL(GCC_CW):
def __init__(self, target, notify=None): def __init__(self, target, options=None, notify=None):
GCC_CW.__init__(self, target, notify) GCC_CW.__init__(self, target, options, notify)
# Compiler # Compiler
common = [ common = [
@ -170,7 +173,7 @@ class GCC_CW_EWL(GCC_CW):
# Linker # Linker
self.sys_libs = [] self.sys_libs = []
self.CIRCULAR_DEPENDENCIES = False self.CIRCULAR_DEPENDENCIES = False
self.ld = [join(GCC_CW_PATH, "arm-none-eabi-g++"), self.ld = [join(CW_GCC_PATH, "arm-none-eabi-g++"),
"-Xlinker", "--gc-sections", "-Xlinker", "--gc-sections",
"-L%s" % join(CW_EWL_PATH, "lib", GCC_CW.ARCH_LIB[target.core]), "-L%s" % join(CW_EWL_PATH, "lib", GCC_CW.ARCH_LIB[target.core]),
"-n", "-specs=ewl_c++.specs", "-mfloat-abi=soft", "-n", "-specs=ewl_c++.specs", "-mfloat-abi=soft",
@ -180,5 +183,5 @@ class GCC_CW_EWL(GCC_CW):
class GCC_CW_NEWLIB(GCC_CW): class GCC_CW_NEWLIB(GCC_CW):
def __init__(self, target, notify=None): def __init__(self, target, options=None, notify=None):
GCC_CW.__init__(self, target, notify) GCC_CW.__init__(self, target, options, notify)

View File

@ -13,8 +13,8 @@ class IAR(mbedToolchain):
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)') DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)')
def __init__(self, target, notify=None): def __init__(self, target, options=None, notify=None):
mbedToolchain.__init__(self, target, notify) mbedToolchain.__init__(self, target, options, notify)
c_flags = [ c_flags = [
"-Oh", "-Oh",