From 3be88a4a6e7b5c903390a6f622b364ac9da91a31 Mon Sep 17 00:00:00 2001 From: Adam Green Date: Fri, 9 Aug 2013 15:11:50 -0700 Subject: [PATCH 1/7] Add .DS_Store to .gitignore Instruct git to ignore these OS X files. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 1077dbcaa1..d7c764479d 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,6 @@ uVision Project/ *.bak debug.log + +# Ignore OS X Desktop Services Store files +.DS_Store \ No newline at end of file From 15f833bc1bc1cb1b896a1ed851d8472de964971e Mon Sep 17 00:00:00 2001 From: Adam Green Date: Sun, 11 Aug 2013 01:08:49 -0700 Subject: [PATCH 2/7] Cast to matching enumeration type instead of uint32_t These were done to silence GCC warnings and fix potential bugs where they would never be equal when the enumeration wasn't a 32-bit type. For example, common/pinmap_common.c used to contain this code: if (pin == (uint32_t)NC) I switched it to: if (pin == (PinName)NC) I wonder why this casting to uint32_t was done in the first place? Maybe another supported compiler requires it? --- libraries/mbed/common/pinmap_common.c | 2 +- .../mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogin_api.c | 2 +- .../targets/hal/TARGET_NXP/TARGET_LPC176X/analogout_api.c | 2 +- libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pinmap.c | 4 ++-- .../mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pwmout_api.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/mbed/common/pinmap_common.c b/libraries/mbed/common/pinmap_common.c index 3abc2855d0..66ccf963ce 100644 --- a/libraries/mbed/common/pinmap_common.c +++ b/libraries/mbed/common/pinmap_common.c @@ -45,7 +45,7 @@ uint32_t pinmap_merge(uint32_t a, uint32_t b) { } uint32_t pinmap_peripheral(PinName pin, const PinMap* map) { - if (pin == (uint32_t)NC) + if (pin == (PinName)NC) return (uint32_t)NC; while (map->pin != NC) { diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogin_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogin_api.c index 31f6c48cbf..982845b2c2 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogin_api.c @@ -44,7 +44,7 @@ static const PinMap PinMap_ADC[] = { void analogin_init(analogin_t *obj, PinName pin) { obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); - if (obj->adc == (uint32_t)NC) { + if (obj->adc == (ADCName)NC) { error("ADC pin mapping failed"); } diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogout_api.c index d2704f37e4..103b644f17 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/analogout_api.c @@ -26,7 +26,7 @@ static const PinMap PinMap_DAC[] = { void analogout_init(dac_t *obj, PinName pin) { obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); - if (obj->dac == (uint32_t)NC) { + if (obj->dac == (DACName)NC) { error("DAC pin mapping failed"); } diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pinmap.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pinmap.c index 64d01d3e1e..be017ce181 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pinmap.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pinmap.c @@ -17,7 +17,7 @@ #include "error.h" void pin_function(PinName pin, int function) { - if (pin == (uint32_t)NC) return; + if (pin == (PinName)NC) return; uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0; int index = pin_number >> 4; @@ -28,7 +28,7 @@ void pin_function(PinName pin, int function) { } void pin_mode(PinName pin, PinMode mode) { - if (pin == (uint32_t)NC) { return; } + if (pin == (PinName)NC) { return; } uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0; int index = pin_number >> 5; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pwmout_api.c index 93cf235201..b4e8bc6acf 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/pwmout_api.c @@ -57,7 +57,7 @@ static unsigned int pwm_clock_mhz; void pwmout_init(pwmout_t* obj, PinName pin) { // determine the channel PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); - if (pwm == (uint32_t)NC) + if (pwm == (PWMName)NC) error("PwmOut pin mapping failed"); obj->pwm = pwm; From c4118236563b5330db7f2ad1b7649526a4794f56 Mon Sep 17 00:00:00 2001 From: Adam Green Date: Sun, 11 Aug 2013 01:19:15 -0700 Subject: [PATCH 3/7] Fix operator precedence warning in can_api.c The original code was: if(LPC_CAN1->IER | LPC_CAN2->IER != 0) { This would actually be interpreted as: if(LPC_CAN1->IER | (LPC_CAN2->IER != 0)) { I simplified it to: if(LPC_CAN1->IER | LPC_CAN2->IER) { With the comparison removed, the GCC warning no longer fires since the user's intent is no longer unclear. However, the end result should be the same. --- libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c index ac316468dd..5afee7ed4d 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c @@ -164,7 +164,7 @@ void can_irq_set(can_t *obj, CanIrqType type, uint32_t enable) { obj->dev->MOD &= ~(1); // Enable NVIC if at least 1 interrupt is active - if(LPC_CAN1->IER | LPC_CAN2->IER != 0) { + if(LPC_CAN1->IER | LPC_CAN2->IER) { NVIC_SetVector(CAN_IRQn, (uint32_t) &can_irq_n); NVIC_EnableIRQ(CAN_IRQn); } From 8fe7276b9820dc852630cdfdeaec475d75c1370c Mon Sep 17 00:00:00 2001 From: Adam Green Date: Sun, 11 Aug 2013 01:31:39 -0700 Subject: [PATCH 4/7] Silence signed/unsigned comparison warnings in GCC. Why do the wait APIs take a signed integer if they are going to be compared to unsigned quantities? --- libraries/mbed/common/wait_api.c | 2 +- .../targets/hal/TARGET_NXP/TARGET_LPC176X/ethernet_api.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/mbed/common/wait_api.c b/libraries/mbed/common/wait_api.c index 5bf00aee2c..b276614ca0 100644 --- a/libraries/mbed/common/wait_api.c +++ b/libraries/mbed/common/wait_api.c @@ -26,5 +26,5 @@ void wait_ms(int ms) { void wait_us(int us) { uint32_t start = us_ticker_read(); - while ((us_ticker_read() - start) < us); + while ((us_ticker_read() - start) < (uint32_t)us); } diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/ethernet_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/ethernet_api.c index f5dcb8fdd6..97770bbd21 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/ethernet_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/ethernet_api.c @@ -697,7 +697,7 @@ int ethernet_receive() { if(receive_idx == -1) { receive_idx = LPC_EMAC->RxConsumeIndex; } else { - while(!(rxstat[receive_idx].Info & RINFO_LAST_FLAG) && (receive_idx != LPC_EMAC->RxProduceIndex)) { + while(!(rxstat[receive_idx].Info & RINFO_LAST_FLAG) && ((uint32_t)receive_idx != LPC_EMAC->RxProduceIndex)) { receive_idx = rinc(receive_idx, NUM_RX_FRAG); } unsigned int info = rxstat[receive_idx].Info; @@ -713,7 +713,7 @@ int ethernet_receive() { LPC_EMAC->RxConsumeIndex = receive_idx; } - if(receive_idx == LPC_EMAC->RxProduceIndex) { + if((uint32_t)receive_idx == LPC_EMAC->RxProduceIndex) { receive_idx = -1; return 0; } @@ -762,7 +762,7 @@ int ethernet_read(char *data, int dlen) { void *pdst, *psrc; int doff = 0; - if(receive_idx == LPC_EMAC->RxProduceIndex || receive_idx == -1) { + if((uint32_t)receive_idx == LPC_EMAC->RxProduceIndex || receive_idx == -1) { return 0; } From cc56997a70c3f80f92b69c14a2ba47ddcdde11c4 Mon Sep 17 00:00:00 2001 From: Adam Green Date: Mon, 12 Aug 2013 15:40:35 -0700 Subject: [PATCH 5/7] Cast to matching enumeration type instead of uint32_t This commit targets the LPC11U24 code, whereas a previous one targetted similar issues in the LPC1768 mbed HAL code. These changes were made to silence GCC warnings and fix potential bugs where they would never be equal when the enumeration wasn't a 32-bit type. For example, pinmap.c used to contain this code: if (pin == (uint32_t)NC) return; I switched it to: if (pin == (PinName)NC) return; I wonder why this casting to uint32_t was done in the first place? Maybe another supported compiler requires it? --- .../targets/hal/TARGET_NXP/TARGET_LPC11UXX/analogin_api.c | 2 +- .../mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pinmap.c | 4 ++-- .../mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pwmout_api.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/analogin_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/analogin_api.c index 43a7a237a8..9078d2c002 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/analogin_api.c @@ -46,7 +46,7 @@ static const PinMap PinMap_ADC[] = { void analogin_init(analogin_t *obj, PinName pin) { obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); - if (obj->adc == (uint32_t)NC) { + if (obj->adc == (ADCName)NC) { error("ADC pin mapping failed"); } diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pinmap.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pinmap.c index 4e2445c658..d7a157a1df 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pinmap.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pinmap.c @@ -20,7 +20,7 @@ #define LPC_IOCON1_BASE (LPC_IOCON_BASE + 0x60) void pin_function(PinName pin, int function) { - if (pin == (uint32_t)NC) return; + if (pin == (PinName)NC) return; uint32_t pin_number = (uint32_t)pin; @@ -33,7 +33,7 @@ void pin_function(PinName pin, int function) { } void pin_mode(PinName pin, PinMode mode) { - if (pin == (uint32_t)NC) { return; } + if (pin == (PinName)NC) { return; } uint32_t pin_number = (uint32_t)pin; uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pwmout_api.c index afd2eba76f..718d7339cc 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/pwmout_api.c @@ -71,7 +71,7 @@ static unsigned int pwm_clock_mhz; void pwmout_init(pwmout_t* obj, PinName pin) { // determine the channel PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); - if (pwm == (uint32_t)NC) + if (pwm == (PWMName)NC) error("PwmOut pin mapping failed"); obj->pwm = pwm; From 461a3dd0d21a5e9812bbe46dc28fa2c25ddfdb9e Mon Sep 17 00:00:00 2001 From: Adam Green Date: Mon, 12 Aug 2013 19:30:16 -0700 Subject: [PATCH 6/7] Cast to matching enumeration type instead of uint32_t This commit targets the KL25Z code, whereas previous ones targetted similar issues in the LPC1768 and LPC11U24 mbed HAL code. These changes were made to silence GCC warnings and fix potential bugs where they would never be equal when the enumeration wasn't a 32-bit type. For example, pinmap.c used to contain this code: if (pin == (uint32_t)NC) return; I switched it to: if (pin == (PinName)NC) return; I wonder why this casting to uint32_t was done in the first place? Maybe another supported compiler requires it? --- .../targets/hal/TARGET_Freescale/TARGET_KL25Z/analogin_api.c | 2 +- .../targets/hal/TARGET_Freescale/TARGET_KL25Z/analogout_api.c | 2 +- .../mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/pinmap.c | 4 ++-- .../targets/hal/TARGET_Freescale/TARGET_KL25Z/pwmout_api.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/analogin_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/analogin_api.c index 9dcf436e45..455fa835db 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/analogin_api.c @@ -41,7 +41,7 @@ static const PinMap PinMap_ADC[] = { void analogin_init(analogin_t *obj, PinName pin) { obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); - if (obj->adc == (uint32_t)NC) { + if (obj->adc == (ADCName)NC) { error("ADC pin mapping failed"); } diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/analogout_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/analogout_api.c index e1839c3fc5..9dfa174edb 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/analogout_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/analogout_api.c @@ -28,7 +28,7 @@ static const PinMap PinMap_DAC[] = { void analogout_init(dac_t *obj, PinName pin) { obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); - if (obj->dac == (uint32_t)NC) { + if (obj->dac == (DACName)NC) { error("DAC pin mapping failed"); } diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/pinmap.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/pinmap.c index 7b68e497c0..9bb5c3f220 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/pinmap.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/pinmap.c @@ -17,7 +17,7 @@ #include "error.h" void pin_function(PinName pin, int function) { - if (pin == (uint32_t)NC) return; + if (pin == (PinName)NC) return; uint32_t port_n = (uint32_t)pin >> PORT_SHIFT; uint32_t pin_n = (uint32_t)(pin & 0x7C) >> 2; @@ -30,7 +30,7 @@ void pin_function(PinName pin, int function) { } void pin_mode(PinName pin, PinMode mode) { - if (pin == (uint32_t)NC) { return; } + if (pin == (PinName)NC) { return; } __IO uint32_t* pin_pcr = (__IO uint32_t*)(PORTA_BASE + pin); diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/pwmout_api.c index 7353900683..b31b9e01ee 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/pwmout_api.c @@ -48,7 +48,7 @@ static const PinMap PinMap_PWM[] = { void pwmout_init(pwmout_t* obj, PinName pin) { // determine the channel PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); - if (pwm == (uint32_t)NC) + if (pwm == (PWMName)NC) error("PwmOut pin mapping failed"); unsigned int port = (unsigned int)pin >> PORT_SHIFT; From 692e666ced6ceb0037148d87fcbbbc18151c2115 Mon Sep 17 00:00:00 2001 From: Adam Green Date: Mon, 12 Aug 2013 19:32:49 -0700 Subject: [PATCH 7/7] Silence signed/unsigned comparison warnings in GCC. i2c_frequency() compares a uint32_t ref variable to the int hz function parameter passed in by the caller. I forced this to be an uint32_t comparison. i2c_slave_write() declared i and count variables to be of type uint32_t but used them as int type throughout the code (in comparisons and returns) so I switched them to be of signed int type. spi_frequency() contains a change similar to that made in i2c_frequency(). --- .../mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/i2c_api.c | 4 ++-- .../mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/spi_api.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/i2c_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/i2c_api.c index 602a8c725e..7cf3b2683c 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/i2c_api.c @@ -215,7 +215,7 @@ void i2c_frequency(i2c_t *obj, int hz) { for (i = 1; i < 5; i*=2) { for (j = 0; j < 0x40; j++) { ref = PCLK / (i*ICR[j]); - if (ref > hz) + if (ref > (uint32_t)hz) continue; error = hz - ref; if (error < p_error) { @@ -392,7 +392,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) { } int i2c_slave_write(i2c_t *obj, const char *data, int length) { - uint32_t i, count = 0; + int i, count = 0; // set tx mode obj->i2c->C1 |= I2C_C1_TX_MASK; diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/spi_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/spi_api.c index 2492c774ad..20a953aec7 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/spi_api.c @@ -153,7 +153,7 @@ void spi_frequency(spi_t *obj, int hz) { divisor = 2; for (spr = 0; spr <= 8; spr++, divisor *= 2) { ref = PCLK / (prescaler*divisor); - if (ref > hz) + if (ref > (uint32_t)hz) continue; error = hz - ref; if (error < p_error) {