Skip to content

Commit 4e23b72

Browse files
committed
Merge pull request #76 from arebert/lpc4088
[LPC4088] Merged bugfixes and improvments for LPC1768 target to LPC4088 target
2 parents f2f7b21 + bb35d16 commit 4e23b72

File tree

11 files changed

+79
-50
lines changed

11 files changed

+79
-50
lines changed

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC408X/LPC407x_8x_177x_8x.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
#ifndef __LPC407x_8x_177x_8x_H__
3535
#define __LPC407x_8x_177x_8x_H__
3636

37-
#define CORE_M4
37+
#if defined(__CORTEX_M4) && !defined(CORE_M4)
38+
#define CORE_M4
39+
#endif
3840

3941
// ##################
4042
// Code Red - excluded extern "C" as unrequired

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC408X/TOOLCHAIN_ARM_STD/TARGET_LPC4088_EA/LPC407X_8X.sct

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ LR_IROM1 0x00000000 0x00080000 { ; load region size_region
1111
RW_IRAM1 0x100000E8 0x0000FF18 { ; RW data
1212
.ANY (+RW +ZI)
1313
}
14-
RW_IRAM2 0x20000000 0x00008000 {
14+
RW_IRAM2 0x20000000 0x00004000 {
15+
.ANY (AHBSRAM0)
16+
}
17+
RW_IRAM3 0x20004000 0x00004000 {
1518
.ANY (AHBSRAM1)
1619
}
1720
}

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogin_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static const PinMap PinMap_ADC[] = {
4343

4444
void analogin_init(analogin_t *obj, PinName pin) {
4545
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
46-
if (obj->adc == (uint32_t)NC) {
46+
if (obj->adc == (ADCName)NC) {
4747
error("ADC pin mapping failed");
4848
}
4949

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/analogout_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static const PinMap PinMap_DAC[] = {
2525

2626
void analogout_init(dac_t *obj, PinName pin) {
2727
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
28-
if (obj->dac == (uint32_t)NC) {
28+
if (obj->dac == (DACName)NC) {
2929
error("DAC pin mapping failed");
3030
}
3131

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/can_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void can_irq_set(can_t *obj, CanIrqType type, uint32_t enable) {
164164
obj->dev->MOD &= ~(1);
165165

166166
// Enable NVIC if at least 1 interrupt is active
167-
if((LPC_CAN1->IER | LPC_CAN2->IER) != 0) {
167+
if(((LPC_SC->PCONP & (1 << 13)) && LPC_CAN1->IER) || ((LPC_SC->PCONP & (1 << 14)) && LPC_CAN2->IER)) {
168168
NVIC_SetVector(CAN_IRQn, (uint32_t) &can_irq_n);
169169
NVIC_EnableIRQ(CAN_IRQn);
170170
}

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/ethernet_api.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ int ethernet_receive() {
722722
if(receive_idx == -1) {
723723
receive_idx = LPC_EMAC->RxConsumeIndex;
724724
} else {
725-
while(!(rxstat[receive_idx].Info & RINFO_LAST_FLAG) && (receive_idx != LPC_EMAC->RxProduceIndex)) {
725+
while(!(rxstat[receive_idx].Info & RINFO_LAST_FLAG) && ((uint32_t)receive_idx != LPC_EMAC->RxProduceIndex)) {
726726
receive_idx = rinc(receive_idx, NUM_RX_FRAG);
727727
}
728728
unsigned int info = rxstat[receive_idx].Info;
@@ -738,7 +738,7 @@ int ethernet_receive() {
738738
LPC_EMAC->RxConsumeIndex = receive_idx;
739739
}
740740

741-
if(receive_idx == LPC_EMAC->RxProduceIndex) {
741+
if((uint32_t)receive_idx == LPC_EMAC->RxProduceIndex) {
742742
receive_idx = -1;
743743
return 0;
744744
}
@@ -787,7 +787,7 @@ int ethernet_read(char *data, int dlen) {
787787
void *pdst, *psrc;
788788
int doff = 0;
789789

790-
if(receive_idx == LPC_EMAC->RxProduceIndex || receive_idx == -1) {
790+
if((uint32_t)receive_idx == LPC_EMAC->RxProduceIndex || receive_idx == -1) {
791791
return 0;
792792
}
793793

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/gpio_irq_api.c

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,66 @@ static void handle_interrupt_in(void) {
3030
uint32_t fall0 = LPC_GPIOINT->IO0IntStatF;
3131
uint32_t rise2 = LPC_GPIOINT->IO2IntStatR;
3232
uint32_t fall2 = LPC_GPIOINT->IO2IntStatF;
33-
uint32_t mask0 = 0;
34-
uint32_t mask2 = 0;
35-
int i;
36-
37-
// P0.0-0.31
38-
for (i = 0; i < 32; i++) {
39-
uint32_t pmask = (1 << i);
40-
if (rise0 & pmask) {
41-
mask0 |= pmask;
42-
if (channel_ids[i] != 0)
43-
irq_handler(channel_ids[i], IRQ_RISE);
44-
}
45-
if (fall0 & pmask) {
46-
mask0 |= pmask;
47-
if (channel_ids[i] != 0)
48-
irq_handler(channel_ids[i], IRQ_FALL);
49-
}
33+
34+
uint8_t bitloc;
35+
36+
// Continue as long as there are interrupts pending
37+
while(rise0 > 0) {
38+
// CLZ returns number of leading zeros, 31 minus that is location of
39+
// first pending interrupt
40+
bitloc = 31 - __CLZ(rise0);
41+
if (channel_ids[bitloc] != 0)
42+
irq_handler(channel_ids[bitloc], IRQ_RISE); //Run that interrupt
43+
44+
// Both clear the interrupt with clear register, and remove it from
45+
// our local copy of the interrupt pending register
46+
LPC_GPIOINT->IO0IntClr = 1 << bitloc;
47+
rise0 -= 1<<bitloc;
5048
}
51-
52-
// P2.0-2.31
53-
for (i = 0; i < 32; i++) {
54-
uint32_t pmask = (1 << i);
55-
int channel_index = i + 32;
56-
if (rise2 & pmask) {
57-
mask2 |= pmask;
58-
if (channel_ids[channel_index] != 0)
59-
irq_handler(channel_ids[channel_index], IRQ_RISE);
60-
}
61-
if (fall2 & pmask) {
62-
mask2 |= pmask;
63-
if (channel_ids[channel_index] != 0)
64-
irq_handler(channel_ids[channel_index], IRQ_FALL);
65-
}
49+
50+
// Continue as long as there are interrupts pending
51+
while(fall0 > 0) {
52+
// CLZ returns number of leading zeros, 31 minus that is location of
53+
// first pending interrupt
54+
bitloc = 31 - __CLZ(fall0);
55+
if (channel_ids[bitloc] != 0)
56+
irq_handler(channel_ids[bitloc], IRQ_FALL); //Run that interrupt
57+
58+
// Both clear the interrupt with clear register, and remove it from
59+
// our local copy of the interrupt pending register
60+
LPC_GPIOINT->IO0IntClr = 1 << bitloc;
61+
fall0 -= 1<<bitloc;
62+
}
63+
64+
// Same for port 2
65+
66+
// Continue as long as there are interrupts pending
67+
while(rise2 > 0) {
68+
// CLZ returns number of leading zeros, 31 minus that is location of
69+
// first pending interrupt
70+
bitloc = 31 - __CLZ(rise2);
71+
if (channel_ids[bitloc+32] != 0)
72+
irq_handler(channel_ids[bitloc+32], IRQ_RISE); //Run that interrupt
73+
74+
// Both clear the interrupt with clear register, and remove it from
75+
// our local copy of the interrupt pending register
76+
LPC_GPIOINT->IO2IntClr = 1 << bitloc;
77+
rise2 -= 1<<bitloc;
78+
}
79+
80+
// Continue as long as there are interrupts pending
81+
while(fall2 > 0) {
82+
// CLZ returns number of leading zeros, 31 minus that is location of
83+
// first pending interrupt
84+
bitloc = 31 - __CLZ(fall2);
85+
if (channel_ids[bitloc+32] != 0)
86+
irq_handler(channel_ids[bitloc+32], IRQ_FALL); //Run that interrupt
87+
88+
// Both clear the interrupt with clear register, and remove it from
89+
// our local copy of the interrupt pending register
90+
LPC_GPIOINT->IO2IntClr = 1 << bitloc;
91+
fall2 -= 1<<bitloc;
6692
}
67-
68-
// Clear the interrupts we just handled
69-
LPC_GPIOINT->IO0IntClr = mask0;
70-
LPC_GPIOINT->IO2IntClr = mask2;
7193
}
7294

7395
int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) {

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/pinmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "error.h"
1818

1919
void pin_function(PinName pin, int function) {
20-
if (pin == (uint32_t)NC) return;
20+
if (pin == (PinName)NC) return;
2121

2222
__IO uint32_t *reg = (__IO uint32_t*) (LPC_IOCON_BASE + 4 * pin);
2323

@@ -26,7 +26,7 @@ void pin_function(PinName pin, int function) {
2626
}
2727

2828
void pin_mode(PinName pin, PinMode mode) {
29-
if (pin == (uint32_t)NC) { return; }
29+
if (pin == (PinName)NC) { return; }
3030

3131
uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2;
3232

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/pwmout_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static unsigned int pwm_clock_mhz;
6666
void pwmout_init(pwmout_t* obj, PinName pin) {
6767
// determine the channel
6868
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
69-
if (pwm == (uint32_t)NC)
69+
if (pwm == (PWMName)NC)
7070
error("PwmOut pin mapping failed");
7171

7272
obj->channel = pwm;

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/serial_api.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,10 @@ int serial_writable(serial_t *obj) {
287287
}
288288

289289
void serial_clear(serial_t *obj) {
290-
obj->uart->FCR = 1 << 1 // rx FIFO reset
291-
| 1 << 2 // tx FIFO reset
292-
| 0 << 6; // interrupt depth
290+
obj->uart->FCR = 1 << 0 // FIFO Enable - 0 = Disables, 1 = Enabled
291+
| 1 << 1 // rx FIFO reset
292+
| 1 << 2 // tx FIFO reset
293+
| 0 << 6; // interrupt depth
293294
}
294295

295296
void serial_pinout_tx(PinName tx) {

workspace_tools/export/uvision4_lpc4088.uvproj.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@
385385
{% for file in object_files %}
386386
{{file}}
387387
{% endfor %}
388+
--any_placement=first_fit
388389
</Misc>
389390
<LinkerInputFile></LinkerInputFile>
390391
<DisabledWarnings></DisabledWarnings>

0 commit comments

Comments
 (0)