Skip to content

Commit 3c0775f

Browse files
committed
More pin mux options for KL25Z
- as reported in mbed bug section, add all available mux options
1 parent e993e94 commit 3c0775f

File tree

4 files changed

+92
-61
lines changed

4 files changed

+92
-61
lines changed

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/analogin_api.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
static const PinMap PinMap_ADC[] = {
2323
{PTE20, ADC0_SE0, 0},
24+
{PTE21, ADC0_SE4a, 0},
2425
{PTE22, ADC0_SE3, 0},
26+
{PTE23, ADC0_SE7a, 0},
2527
{PTE29, ADC0_SE4b, 0},
2628
{PTE30, ADC0_SE23, 0},
2729
{PTB0, ADC0_SE8, 0},

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/i2c_api.c

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ static const PinMap PinMap_I2C_SDA[] = {
2525
{PTE0, I2C_1, 6},
2626
{PTB1, I2C_0, 2},
2727
{PTB3, I2C_0, 2},
28+
{PTC11, I2C_1, 2},
29+
{PTC2, I2C_1, 2},
30+
{PTA4, I2C_1, 2},
2831
{NC , NC , 0}
2932
};
3033

@@ -34,6 +37,8 @@ static const PinMap PinMap_I2C_SCL[] = {
3437
{PTE1, I2C_1, 6},
3538
{PTB0, I2C_0, 2},
3639
{PTB2, I2C_0, 2},
40+
{PTC10, I2C_1, 2},
41+
{PTC1, I2C_1, 2},
3742
{NC , NC, 0}
3843
};
3944

@@ -79,7 +84,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
7984

8085
pinmap_pinout(sda, PinMap_I2C_SDA);
8186
pinmap_pinout(scl, PinMap_I2C_SCL);
82-
87+
8388
first_read = 1;
8489
}
8590

@@ -112,12 +117,12 @@ int i2c_stop(i2c_t *obj) {
112117

113118
static int timeout_status_poll(i2c_t *obj, uint32_t mask) {
114119
uint32_t i, timeout = 1000;
115-
120+
116121
for (i = 0; i < timeout; i++) {
117122
if (obj->i2c->S & mask)
118123
return 0;
119124
}
120-
125+
121126
return 1;
122127
}
123128

@@ -126,14 +131,14 @@ static int timeout_status_poll(i2c_t *obj, uint32_t mask) {
126131
// 1: OK ack not received
127132
// 2: failure
128133
static int i2c_wait_end_tx_transfer(i2c_t *obj) {
129-
134+
130135
// wait for the interrupt flag
131136
if (timeout_status_poll(obj, I2C_S_IICIF_MASK)) {
132137
return 2;
133138
}
134-
139+
135140
obj->i2c->S |= I2C_S_IICIF_MASK;
136-
141+
137142
// wait transfer complete
138143
if (timeout_status_poll(obj, I2C_S_TCF_MASK)) {
139144
return 2;
@@ -151,9 +156,9 @@ static int i2c_wait_end_rx_transfer(i2c_t *obj) {
151156
if (timeout_status_poll(obj, I2C_S_IICIF_MASK)) {
152157
return 1;
153158
}
154-
159+
155160
obj->i2c->S |= I2C_S_IICIF_MASK;
156-
161+
157162
return 0;
158163
}
159164

@@ -288,33 +293,33 @@ void i2c_reset(i2c_t *obj) {
288293

289294
int i2c_byte_read(i2c_t *obj, int last) {
290295
char data;
291-
296+
292297
// set rx mode
293298
obj->i2c->C1 &= ~I2C_C1_TX_MASK;
294-
299+
295300
if(first_read) {
296301
// first dummy read
297302
i2c_do_read(obj, &data, 0);
298303
first_read = 0;
299304
}
300-
305+
301306
if (last) {
302307
// set tx mode
303308
obj->i2c->C1 |= I2C_C1_TX_MASK;
304309
return obj->i2c->D;
305310
}
306-
311+
307312
i2c_do_read(obj, &data, last);
308-
313+
309314
return data;
310315
}
311316

312317
int i2c_byte_write(i2c_t *obj, int data) {
313318
first_read = 1;
314-
319+
315320
// set tx mode
316321
obj->i2c->C1 |= I2C_C1_TX_MASK;
317-
322+
318323
return !i2c_do_write(obj, (data & 0xFF));
319324
}
320325

@@ -335,33 +340,33 @@ int i2c_slave_receive(i2c_t *obj) {
335340
switch(obj->i2c->S) {
336341
// read addressed
337342
case 0xE6: return 1;
338-
343+
339344
// write addressed
340345
case 0xE2: return 3;
341-
346+
342347
default: return 0;
343348
}
344349
}
345350

346351
int i2c_slave_read(i2c_t *obj, char *data, int length) {
347352
uint8_t dummy_read, count;
348353
uint8_t * ptr;
349-
354+
350355
// set rx mode
351356
obj->i2c->C1 &= ~I2C_C1_TX_MASK;
352-
357+
353358
// first dummy read
354359
dummy_read = obj->i2c->D;
355360
if(i2c_wait_end_rx_transfer(obj)) {
356361
return 0;
357362
}
358-
363+
359364
// read address
360365
dummy_read = obj->i2c->D;
361366
if(i2c_wait_end_rx_transfer(obj)) {
362367
return 0;
363368
}
364-
369+
365370
// read (length - 1) bytes
366371
for (count = 0; count < (length - 1); count++) {
367372
data[count] = obj->i2c->D;
@@ -373,32 +378,32 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) {
373378
// read last byte
374379
ptr = (length == 0) ? &dummy_read : (uint8_t *)&data[count];
375380
*ptr = obj->i2c->D;
376-
381+
377382
return (length) ? (count + 1) : 0;
378383
}
379384

380385
int i2c_slave_write(i2c_t *obj, const char *data, int length) {
381386
uint32_t i, count = 0;
382-
387+
383388
// set tx mode
384389
obj->i2c->C1 |= I2C_C1_TX_MASK;
385-
390+
386391
for (i = 0; i < length; i++) {
387392
if(i2c_do_write(obj, data[count++]) == 2) {
388393
return i;
389394
}
390395
}
391-
396+
392397
// set rx mode
393398
obj->i2c->C1 &= ~I2C_C1_TX_MASK;
394-
399+
395400
// dummy rx transfer needed
396401
// otherwise the master cannot generate a stop bit
397402
obj->i2c->D;
398403
if(i2c_wait_end_rx_transfer(obj) == 2) {
399404
return count;
400405
}
401-
406+
402407
return count;
403408
}
404409

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/serial_api.c

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,27 @@
2828
* INITIALIZATION
2929
******************************************************************************/
3030
static const PinMap PinMap_UART_TX[] = {
31-
{PTC4, UART_1, 3},
32-
{PTA2, UART_0, 2},
33-
{PTD5, UART_2, 3},
34-
{PTD3, UART_2, 3},
35-
{NC , NC , 0}
31+
{PTC4, UART_1, 3},
32+
{PTA2, UART_0, 2},
33+
{PTD5, UART_2, 3},
34+
{PTD3, UART_2, 3},
35+
{PTD7, UART_0, 3},
36+
{PTE20, UART_0, 4},
37+
{PTE22, UART_2, 4},
38+
{PTE0, UART_1, 3},
39+
{NC , NC , 0}
3640
};
3741

3842
static const PinMap PinMap_UART_RX[] = {
39-
{PTC3, UART_1, 3},
40-
{PTA1, UART_0, 2},
41-
{PTD4, UART_2, 3},
42-
{PTD2, UART_2, 3},
43-
{NC , NC , 0}
43+
{PTC3, UART_1, 3},
44+
{PTA1, UART_0, 2},
45+
{PTD4, UART_2, 3},
46+
{PTD2, UART_2, 3},
47+
{PTD6, UART_0, 3},
48+
{PTE23, UART_2, 4},
49+
{PTE21, UART_0, 4},
50+
{PTE1, UART_1, 3},
51+
{NC , NC , 0}
4452
};
4553

4654
#define UART_NUM 3
@@ -69,7 +77,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
6977
}
7078
// Disable UART before changing registers
7179
obj->uart->C2 &= ~(UART_C2_RE_MASK | UART_C2_TE_MASK);
72-
80+
7381
switch (uart) {
7482
case UART_0: obj->index = 0; break;
7583
case UART_1: obj->index = 1; break;
@@ -114,13 +122,13 @@ void serial_free(serial_t *obj) {
114122
// DivAddVal < MulVal
115123
//
116124
void serial_baud(serial_t *obj, int baudrate) {
117-
125+
118126
// save C2 state
119127
uint8_t c2_state = (obj->uart->C2 & (UART_C2_RE_MASK | UART_C2_TE_MASK));
120-
128+
121129
// Disable UART before changing registers
122130
obj->uart->C2 &= ~(UART_C2_RE_MASK | UART_C2_TE_MASK);
123-
131+
124132
// [TODO] not hardcode this value
125133
uint32_t PCLK = (obj->uart == UART0) ? 48000000u : 24000000u;
126134

@@ -135,20 +143,20 @@ void serial_baud(serial_t *obj, int baudrate) {
135143
// set BDH and BDL
136144
obj->uart->BDH = (obj->uart->BDH & ~(0x1f)) | ((DL >> 8) & 0x1f);
137145
obj->uart->BDL = (obj->uart->BDL & ~(0xff)) | ((DL >> 0) & 0xff);
138-
146+
139147
// restore C2 state
140148
obj->uart->C2 |= c2_state;
141149
}
142150

143151
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
144152
uint8_t m10 = 0;
145-
153+
146154
// save C2 state
147155
uint8_t c2_state = (obj->uart->C2 & (UART_C2_RE_MASK | UART_C2_TE_MASK));
148-
156+
149157
// Disable UART before changing registers
150158
obj->uart->C2 &= ~(UART_C2_RE_MASK | UART_C2_TE_MASK);
151-
159+
152160
// 8 data bits = 0 ... 9 data bits = 1
153161
if ((data_bits < 8) || (data_bits > 9)) {
154162
error("Invalid number of bits (%d) in serial format, should be 8..9\r\n", data_bits);
@@ -170,7 +178,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
170178
error("Invalid stop bits specified\r\n");
171179
}
172180
stop_bits -= 1;
173-
181+
174182
// 9 data bits + parity
175183
if (data_bits == 2) {
176184
// only uart0 supports 10 bit communication
@@ -185,17 +193,17 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
185193
obj->uart->C1 = ((data_bits << 4)
186194
| (parity_enable << 1)
187195
| (parity_select << 0));
188-
196+
189197
// enable 10bit mode if needed
190198
if (obj->index == 0) {
191199
obj->uart->C4 &= ~UARTLP_C4_M10_MASK;
192200
obj->uart->C4 |= (m10 << UARTLP_C4_M10_SHIFT);
193201
}
194-
202+
195203
// stop bits
196204
obj->uart->BDH &= ~UART_BDH_SBNS_MASK;
197205
obj->uart->BDH |= (stop_bits << UART_BDH_SBNS_SHIFT);
198-
206+
199207
// restore C2 state
200208
obj->uart->C2 |= c2_state;
201209
}
@@ -296,7 +304,7 @@ void serial_pinout_tx(PinName tx) {
296304
}
297305

298306
void serial_break_set(serial_t *obj) {
299-
obj->uart->C2 |= UART_C2_SBK_MASK;
307+
obj->uart->C2 |= UART_C2_SBK_MASK;
300308
}
301309

302310
void serial_break_clear(serial_t *obj) {

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/spi_api.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,47 @@
2222
#include "error.h"
2323

2424
static const PinMap PinMap_SPI_SCLK[] = {
25-
{PTE2, SPI_1, 2},
26-
{PTC5, SPI_0, 2},
27-
{PTD1, SPI_0, 2},
28-
{NC , NC , 0}
25+
{PTE2, SPI_1, 2},
26+
{PTC5, SPI_0, 2},
27+
{PTD1, SPI_0, 2},
28+
{PTB11, SPI_1, 2},
29+
{PTD5, SPI_1, 2},
30+
{NC , NC , 0}
2931
};
3032

3133
static const PinMap PinMap_SPI_MOSI[] = {
3234
{PTE1, SPI_1, 2},
3335
{PTC6, SPI_0, 2},
3436
{PTD2, SPI_0, 2},
37+
{PTE3, SPI_1, 2},
38+
{PTD7, SPI_1, 5},
39+
{PTC7, SPI_0, 5},
40+
{PTD3, SPI_0, 5},
41+
{PTD6, SPI_1, 2},
3542
{NC , NC , 0}
3643
};
3744

3845
static const PinMap PinMap_SPI_MISO[] = {
39-
{PTE3, SPI_1, 2},
40-
{PTC7, SPI_0, 2},
41-
{PTD3, SPI_0, 2},
46+
{PTE3, SPI_1, 2},
47+
{PTC7, SPI_0, 2},
48+
{PTD3, SPI_0, 2},
49+
{PTE1, SPI_1, 5},
50+
{PTA16, SPI_0, 5},
51+
{PTA17, SPI_0, 5},
52+
{PTC5, SPI_0, 5},
53+
{PTD2, SPI_0, 5},
54+
{PTD6, SPI_1, 5},
55+
{PTD7, SPI_1, 2},
4256
{NC , NC , 0}
4357
};
4458

4559
static const PinMap PinMap_SPI_SSEL[] = {
46-
{PTE4, SPI_1, 2},
47-
{PTC4, SPI_0, 2},
48-
{PTD0, SPI_0, 2},
49-
{NC , NC , 0}
60+
{PTE4, SPI_1, 2},
61+
{PTC4, SPI_0, 2},
62+
{PTD0, SPI_0, 2},
63+
{PTB10, SPI_1, 2},
64+
{PTD4, SPI_1, 2},
65+
{NC , NC , 0}
5066
};
5167

5268
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) {

0 commit comments

Comments
 (0)