This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Zephyr UART on Fanstel BLG840F

I am using UART on the Fanstel BLG840F to communicate from the 9160 to the 52840.  So far I have successfully been able to communicate from the 52840 to the 9160 but have not been able to send UART messages back from the 9160 to the 52840.  I am using shared UART functions between the boards with a single function to handle sending:

int uart_send(struct uart_data_t *uart_data)
{
    int status = uart_tx(device_uart, uart_data->data, uart_data->length, SYS_FOREVER_MS);

    if (status != 0)
    {
        printk("uart_tx ( error: %d )\n", status);

        // Add to tx queue to try and process / send later ...
        k_fifo_put(&fifo_uart_tx_data, uart_data);
    }
    printk("data sent: %s \n", uart_data);

    return status;
}

and a registered event handler:

static void on_uart_event(const struct device *dev, struct uart_event *evt, void *user_data)
{
    struct uart_data_t *uart_data;
    static uint8_t *aborted_buf;
    static size_t aborted_len;

    switch (evt->type)
    {
    //put this in ifdef block
    
    case UART_RX_RDY:
    {
        printk("UART_RX_RDY\n");

        uart_data = CONTAINER_OF(evt->data.rx.buf, struct uart_data_t, data); // where does third parameter data come from?

        printk("uart_rx called with data: %s", uart_data->data);
       

        hive_uart_queue_rx_data_buffer(uart_data);

        uart_rx_disable(device_uart); 

        break;
    }
    
    case UART_RX_DISABLED:
    {
        printk("UART_RX_DISABLED\n");

        start_receiving();

        break;
    }
    case UART_RX_BUF_REQUEST:
    {
        printk("UART_RX_BUF_REQUEST\n");

        struct uart_data_t *uart_data = hive_uart_allocate_data_buffer();

        if (uart_data == NULL)
        {
            break;
        }

        uart_rx_buf_rsp(device_uart, uart_data->data, sizeof(uart_data->data));

        break;
    }
    case UART_RX_BUF_RELEASED:
    {
        printk("UART_RX_BUF_RELEASED\n");

        uart_data = CONTAINER_OF(evt->data.rx_buf.buf, struct uart_data_t, data);

        k_free(uart_data);

        break;
    }
    case UART_TX_DONE:
    {
        printk("UART_TX_DONE\n");

        if ((evt->data.tx.len == 0) || (!evt->data.tx.buf))
        {
            return;
        }

        if (aborted_buf)
        {
            uart_data = CONTAINER_OF(aborted_buf, struct uart_data_t, data);
            aborted_buf = NULL;
            aborted_len = 0;
        }
        else
        {
            uart_data = CONTAINER_OF(evt->data.tx.buf, struct uart_data_t, data);
        }

        k_free(uart_data);

        // See if there's anything waiting in the queue ...
        uart_data = k_fifo_get(&fifo_uart_tx_data, K_NO_WAIT);

        if (!uart_data)
        {
            return;
        }

        if (uart_tx(device_uart, uart_data->data, uart_data->length, SYS_FOREVER_MS))
        {
            printk("(UART_TX_DONE) Failed to send data over UART\n");

            // Add back to queue to try again ...
            k_fifo_put(&fifo_uart_tx_data, uart_data);
        }

        break;
    }
    case UART_TX_ABORTED:
    {
        if (!aborted_buf)
        {
            aborted_buf = (uint8_t *)evt->data.tx.buf;
        }

        aborted_len += evt->data.tx.len;

        uart_data = CONTAINER_OF(aborted_buf, struct uart_data_t, data);

        if (uart_tx(device_uart, &uart_data->data[aborted_len], uart_data->length - aborted_len, SYS_FOREVER_MS))
        {
            printk("(UART_TX_ABORTED) Failed to send data over UART\n");

            // Add to queue to try again later ...
            k_fifo_put(&fifo_uart_tx_data, uart_data);
        }

        break;
    }
    default:
    {
        printk("UART event received: %d\n", evt->type);
        break;
    }
    }
}

Calling the UART send function on the 52840 triggers the UART_RX_RDY case correctly on the 9160, but calling the UART send function on the 9160 does not trigger the UART_RX_RDY on the 52840.  Does each board need a separate event handler and separate UART function or can they be shared in this way and I have setup something on the 9160 side incorrectly?

Thanks

  • Hi Jake

    Wouldn't the BLG840X come with its own set of specifications detailing which pins from the nRF9160 are connected to which pins on the BT840?

    Best regards
    Torbjørn

  • They provide this block diagram which has App1-UART of the 9160 connected to nRF52-UART of the BT840F via the JS3 connector.  I looked through the 9160 datasheet and couldn't find any labeling of APP1 so I wasn't sure what that was referring to, and same with nRF52 in its datasheet.  It says that uart pins such as psel.rts can be mapped to pins, but psel.rxd, psel.rts etc. were all mapped to P0.31 so I didn't understand this.  Wouldn't these need to be separate pins physically?

  • Hi 

    I noticed the same diagram, but it is not very specific unfortunately. 

    I am not sure what they mean by App1-UART either, to my knowledge we don't have any references to this in our documentation. Possibly they reused the pins used by the respective board files of the nRF9160 and nRF52840 DK's, but this is just speculation. 

    In the BT840 schematic they mention UART_TX on pin 1.02 (C5) and UART_RX on pin 1.01 (D5), but whether or not this is the UART pins they use in the BLG840X is anyone's guess. 

    Could you try to contact Fanstel directly and ask if they have some more documentation that would provide these details?

    I guess it is possible to write some code for the two devices that toggle each and every pin one after the other in one device, and read all the GPIO's in the other device to see which one changes, but this is a pretty cumbersome way to figure out how they are connected. 

    Best regards
    Torbjørn

  • After a while I found the solution it was with the pins.  There was overlapping assignment with uart0 and spi1, so I disabled them in the overlay file by adding:

    &spi1 {
        status = "disabled";
    };

    &uart0 {
        status = "disabled";
    };
    which fixed the issue
Related