Allow Serial pin to be NC on Freescale/NXP devices

Nordic(?)/STM should also be done, but I don't know if they do their own
stuff.

Issue is that since the mbed-assert implementation, calling pin_mode
causes an assert when a pin is NC. Since defining a serial object with
only TX or RX is a valid use case, this should be handled.

pinmap_pinout does accept NC pins, so there no guards are needed (person
who adds asserts there may also fix it in all other code).
pull/530/head
Sissors 2014-10-04 22:47:25 +02:00
parent b5b42b5f4b
commit 86e71216fa
11 changed files with 44 additions and 22 deletions

View File

@ -98,8 +98,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
pinmap_pinout(rx, PinMap_UART_RX);
// set rx/tx pins in PullUp mode
pin_mode(tx, PullUp);
pin_mode(rx, PullUp);
if (tx != NC)
pin_mode(tx, PullUp);
if (rx != NC)
pin_mode(rx, PullUp);
obj->uart->C2 |= (UART_C2_RE_MASK | UART_C2_TE_MASK);

View File

@ -96,8 +96,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
pinmap_pinout(rx, PinMap_UART_RX);
// set rx/tx pins in PullUp mode
pin_mode(tx, PullUp);
pin_mode(rx, PullUp);
if (tx != NC)
pin_mode(tx, PullUp);
if (rx != NC)
pin_mode(rx, PullUp);
obj->uart->C2 |= (UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);

View File

@ -68,8 +68,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
pinmap_pinout(tx, PinMap_UART_TX);
pinmap_pinout(rx, PinMap_UART_RX);
pin_mode(tx, PullUp);
pin_mode(rx, PullUp);
if (tx != NC)
pin_mode(tx, PullUp);
if (rx != NC)
pin_mode(rx, PullUp);
if (obj->index == STDIO_UART) {
stdio_uart_inited = 1;

View File

@ -142,8 +142,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
pinmap_pinout(rx, PinMap_UART_RX);
// set rx/tx pins in PullUp mode
pin_mode(tx, PullUp);
pin_mode(rx, PullUp);
if (tx != NC)
pin_mode(tx, PullUp);
if (rx != NC)
pin_mode(rx, PullUp);
is_stdio_uart = (uart == STDIO_UART) ? (1) : (0);

View File

@ -73,8 +73,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
pinmap_pinout(rx, PinMap_UART_RX);
// set rx/tx pins in PullUp mode
pin_mode(tx, PullUp);
pin_mode(rx, PullUp);
if (tx != NC)
pin_mode(tx, PullUp);
if (rx != NC)
pin_mode(rx, PullUp);
switch (uart) {
case UART_0: obj->index = 0; break;

View File

@ -82,8 +82,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
pinmap_pinout(rx, PinMap_UART_RX);
// set rx/tx pins in PullUp mode
pin_mode(tx, PullUp);
pin_mode(rx, PullUp);
if (tx != NC)
pin_mode(tx, PullUp);
if (rx != NC)
pin_mode(rx, PullUp);
switch (uart) {
case UART_0: obj->index = 0; break;

View File

@ -85,8 +85,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
pinmap_pinout(rx, PinMap_UART_RX);
// set rx/tx pins in PullUp mode
pin_mode(tx, PullUp);
pin_mode(rx, PullUp);
if (tx != NC)
pin_mode(tx, PullUp);
if (rx != NC)
pin_mode(rx, PullUp);
switch (uart) {
case UART_0: obj->index = 0; break;

View File

@ -120,8 +120,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
pinmap_pinout(rx, PinMap_UART_RX);
// set rx/tx pins in PullUp mode
pin_mode(tx, PullUp);
pin_mode(rx, PullUp);
if (tx != NC)
pin_mode(tx, PullUp);
if (rx != NC)
pin_mode(rx, PullUp);
switch (uart) {
case UART_0: obj->index = 0; break;

View File

@ -96,8 +96,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
pinmap_pinout(rx, PinMap_UART_RX);
// set rx/tx pins in PullUp mode
pin_mode(tx, PullUp);
pin_mode(rx, PullUp);
if (tx != NC)
pin_mode(tx, PullUp);
if (rx != NC)
pin_mode(rx, PullUp);
switch (uart) {
case UART_0: obj->index = 0; break;

View File

@ -104,8 +104,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
pinmap_pinout(rx, PinMap_UART_RX);
// set rx/tx pins in PullUp mode
pin_mode(tx, PullUp);
pin_mode(rx, PullUp);
if (tx != NC)
pin_mode(tx, PullUp);
if (rx != NC)
pin_mode(rx, PullUp);
switch (uart) {
case UART_0: obj->index = 0; break;

View File

@ -139,8 +139,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
serial_format(obj, 8, ParityNone, 1);
// pinout the chosen uart
pinmap_pinout(tx, PinMap_UART_TX);
pinmap_pinout(rx, PinMap_UART_RX);
if (tx != NC)
pin_mode(tx, PullUp);
if (rx != NC)
pin_mode(rx, PullUp);
// set rx/tx pins in PullUp mode
pin_mode(tx, PullUp);