From bb35d1652161f27d156a2a6d12b55c16cf00bdd5 Mon Sep 17 00:00:00 2001 From: Andreas Rebert Date: Mon, 23 Sep 2013 11:39:52 +0200 Subject: [PATCH] Merged bugfixes and improvments for LPC1768 target to LPC4088 target --- .../TARGET_LPC408X/LPC407x_8x_177x_8x.h | 4 +- .../TARGET_LPC4088_EA/LPC407X_8X.sct | 5 +- .../TARGET_NXP/TARGET_LPC408X/analogin_api.c | 2 +- .../TARGET_NXP/TARGET_LPC408X/analogout_api.c | 2 +- .../hal/TARGET_NXP/TARGET_LPC408X/can_api.c | 2 +- .../TARGET_NXP/TARGET_LPC408X/ethernet_api.c | 6 +- .../TARGET_NXP/TARGET_LPC408X/gpio_irq_api.c | 94 ++++++++++++------- .../hal/TARGET_NXP/TARGET_LPC408X/pinmap.c | 4 +- .../TARGET_NXP/TARGET_LPC408X/pwmout_api.c | 2 +- .../TARGET_NXP/TARGET_LPC408X/serial_api.c | 7 +- .../export/uvision4_lpc4088.uvproj.tmpl | 1 + 11 files changed, 79 insertions(+), 50 deletions(-) diff --git a/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC408X/LPC407x_8x_177x_8x.h b/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC408X/LPC407x_8x_177x_8x.h index 530344571b..2a2220b0d8 100644 --- a/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC408X/LPC407x_8x_177x_8x.h +++ b/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC408X/LPC407x_8x_177x_8x.h @@ -34,7 +34,9 @@ #ifndef __LPC407x_8x_177x_8x_H__ #define __LPC407x_8x_177x_8x_H__ -#define CORE_M4 +#if defined(__CORTEX_M4) && !defined(CORE_M4) + #define CORE_M4 +#endif // ################## // Code Red - excluded extern "C" as unrequired diff --git a/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC408X/TOOLCHAIN_ARM_STD/TARGET_LPC4088_EA/LPC407X_8X.sct b/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC408X/TOOLCHAIN_ARM_STD/TARGET_LPC4088_EA/LPC407X_8X.sct index 61319733bc..2357956790 100644 --- a/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC408X/TOOLCHAIN_ARM_STD/TARGET_LPC4088_EA/LPC407X_8X.sct +++ b/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC408X/TOOLCHAIN_ARM_STD/TARGET_LPC4088_EA/LPC407X_8X.sct @@ -11,7 +11,10 @@ LR_IROM1 0x00000000 0x00080000 { ; load region size_region RW_IRAM1 0x100000E8 0x0000FF18 { ; RW data .ANY (+RW +ZI) } - RW_IRAM2 0x20000000 0x00008000 { + RW_IRAM2 0x20000000 0x00004000 { + .ANY (AHBSRAM0) + } + RW_IRAM3 0x20004000 0x00004000 { .ANY (AHBSRAM1) } } diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogin_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogin_api.c index 5ef1ca3e36..04e28939c5 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogin_api.c @@ -43,7 +43,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_LPC408X/analogout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogout_api.c index b849cdc64e..e43cc25982 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogout_api.c @@ -25,7 +25,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_LPC408X/can_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/can_api.c index 2c13747817..8d09fad8b2 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/can_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/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_SC->PCONP & (1 << 13)) && LPC_CAN1->IER) || ((LPC_SC->PCONP & (1 << 14)) && LPC_CAN2->IER)) { NVIC_SetVector(CAN_IRQn, (uint32_t) &can_irq_n); NVIC_EnableIRQ(CAN_IRQn); } diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/ethernet_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/ethernet_api.c index b51ea72341..fe1d57542b 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/ethernet_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/ethernet_api.c @@ -722,7 +722,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; @@ -738,7 +738,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; } @@ -787,7 +787,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; } diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/gpio_irq_api.c index 47dcddb711..605f2d6d87 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/gpio_irq_api.c @@ -30,44 +30,66 @@ static void handle_interrupt_in(void) { uint32_t fall0 = LPC_GPIOINT->IO0IntStatF; uint32_t rise2 = LPC_GPIOINT->IO2IntStatR; uint32_t fall2 = LPC_GPIOINT->IO2IntStatF; - uint32_t mask0 = 0; - uint32_t mask2 = 0; - int i; - - // P0.0-0.31 - for (i = 0; i < 32; i++) { - uint32_t pmask = (1 << i); - if (rise0 & pmask) { - mask0 |= pmask; - if (channel_ids[i] != 0) - irq_handler(channel_ids[i], IRQ_RISE); - } - if (fall0 & pmask) { - mask0 |= pmask; - if (channel_ids[i] != 0) - irq_handler(channel_ids[i], IRQ_FALL); - } + + uint8_t bitloc; + + // Continue as long as there are interrupts pending + while(rise0 > 0) { + // CLZ returns number of leading zeros, 31 minus that is location of + // first pending interrupt + bitloc = 31 - __CLZ(rise0); + if (channel_ids[bitloc] != 0) + irq_handler(channel_ids[bitloc], IRQ_RISE); //Run that interrupt + + // Both clear the interrupt with clear register, and remove it from + // our local copy of the interrupt pending register + LPC_GPIOINT->IO0IntClr = 1 << bitloc; + rise0 -= 1< 0) { + // CLZ returns number of leading zeros, 31 minus that is location of + // first pending interrupt + bitloc = 31 - __CLZ(fall0); + if (channel_ids[bitloc] != 0) + irq_handler(channel_ids[bitloc], IRQ_FALL); //Run that interrupt + + // Both clear the interrupt with clear register, and remove it from + // our local copy of the interrupt pending register + LPC_GPIOINT->IO0IntClr = 1 << bitloc; + fall0 -= 1< 0) { + // CLZ returns number of leading zeros, 31 minus that is location of + // first pending interrupt + bitloc = 31 - __CLZ(rise2); + if (channel_ids[bitloc+32] != 0) + irq_handler(channel_ids[bitloc+32], IRQ_RISE); //Run that interrupt + + // Both clear the interrupt with clear register, and remove it from + // our local copy of the interrupt pending register + LPC_GPIOINT->IO2IntClr = 1 << bitloc; + rise2 -= 1< 0) { + // CLZ returns number of leading zeros, 31 minus that is location of + // first pending interrupt + bitloc = 31 - __CLZ(fall2); + if (channel_ids[bitloc+32] != 0) + irq_handler(channel_ids[bitloc+32], IRQ_FALL); //Run that interrupt + + // Both clear the interrupt with clear register, and remove it from + // our local copy of the interrupt pending register + LPC_GPIOINT->IO2IntClr = 1 << bitloc; + fall2 -= 1<IO0IntClr = mask0; - LPC_GPIOINT->IO2IntClr = mask2; } int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) { diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/pinmap.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/pinmap.c index f7f75e75b3..d2e277ba9e 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/pinmap.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/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; __IO uint32_t *reg = (__IO uint32_t*) (LPC_IOCON_BASE + 4 * pin); @@ -26,7 +26,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 drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/pwmout_api.c index b3e922703e..296eef80f6 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/pwmout_api.c @@ -66,7 +66,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->channel = pwm; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/serial_api.c index d65416a942..ff0efb3b79 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/serial_api.c @@ -287,9 +287,10 @@ int serial_writable(serial_t *obj) { } void serial_clear(serial_t *obj) { - obj->uart->FCR = 1 << 1 // rx FIFO reset - | 1 << 2 // tx FIFO reset - | 0 << 6; // interrupt depth + obj->uart->FCR = 1 << 0 // FIFO Enable - 0 = Disables, 1 = Enabled + | 1 << 1 // rx FIFO reset + | 1 << 2 // tx FIFO reset + | 0 << 6; // interrupt depth } void serial_pinout_tx(PinName tx) { diff --git a/workspace_tools/export/uvision4_lpc4088.uvproj.tmpl b/workspace_tools/export/uvision4_lpc4088.uvproj.tmpl index 7f27cb75ae..3d28824bb5 100644 --- a/workspace_tools/export/uvision4_lpc4088.uvproj.tmpl +++ b/workspace_tools/export/uvision4_lpc4088.uvproj.tmpl @@ -385,6 +385,7 @@ {% for file in object_files %} {{file}} {% endfor %} + --any_placement=first_fit