NRF9160 UART2

Hi nordic:

    NCS1.8.0 , I added UART2 to the NRF9160 LWM2M sample, but it cannot send and receive, but the same code is put into the NRF9160 UDP sample and it can work normally.
The sample log output on the 9160 LWM2M shows: 06 NRF_UARTE2 Secure SKIP;

Project files as attachments。

Please check where the configuration is wrong

thanks !!

jermi

  • //#if 0
    //JXB ADD START
    #define UART_RX_BUF_NUM 2
    #define UART_RX_LEN 256
    #define UART_RX_TIMEOUT_MS 10
    #define UART_ERROR_DELAY_MS 500
    #define UART_RX_MARGIN_MS 10
    # define UART_RX_TEMP_LEN 2000

    static const struct device *uart_dev2;
    static unsigned char uart_rx_buf2[UART_RX_BUF_NUM][UART_RX_LEN];

    static unsigned char uart_tx_buf2[UART_RX_LEN]={0,1,2,3},txlenth=0;


    static uint16_t uart_rx_num=0;
    unsigned char rxdata[UART_RX_TEMP_LEN];

    static unsigned char *next_buf1;
    static unsigned char *uart_tx_buf1;


    static int uart_data_send(void)
    {
    int ret;
    ret = uart_tx(uart_dev2, uart_tx_buf2, txlenth, SYS_FOREVER_MS);
    return ret;
    }

    extern int uarte_nrfx_tx(const struct device *dev, const uint8_t *buf,
    size_t len,
    int32_t timeout);

    void rxchar(uint8_t data)
    {
    rxdata[uart_rx_num]=data;
    uart_rx_num++;
    if(uart_rx_num>=UART_RX_TEMP_LEN)
    {
    uart_rx_num=0;

    // k_work_submit(&uart_data_send_work);
    }
    }
    uint32_t counterrx=0;
    uint8_t changebuf=0;
    static void uart_callback2(const struct device *dev, struct uart_event *evt, void *user_data)
    {
    int err,i;
    static uint16_t pos2;
    static bool enable_rx_retry;

    ARG_UNUSED(dev);
    ARG_UNUSED(user_data);

    switch (evt->type) {
    case UART_TX_DONE:
    k_free(uart_tx_buf1);
    // k_sem_give(&tx_done);
    break;
    case UART_TX_ABORTED:
    k_free(uart_tx_buf1);
    // k_sem_give(&tx_done);
    // LOG_INF("TX_ABORTED");
    break;
    case UART_RX_RDY:

    for (int i = pos2; i < (pos2 + evt->data.rx.len); i++)
    {

    rxchar(evt->data.rx.buf[i]);

    }

    uart_tx(uart_dev2,&( evt->data.rx.buf[pos2]), evt->data.rx.len, SYS_FOREVER_MS);

    pos2 += evt->data.rx.len;
    counterrx+=evt->data.rx.len;

    break;
    case UART_RX_BUF_REQUEST:
    pos2 = 0;
    err = uart_rx_buf_rsp(uart_dev2, next_buf1, sizeof(uart_rx_buf2[0]));

    break;
    case UART_RX_BUF_RELEASED:
    if(changebuf==0)
    {
    changebuf=1;
    next_buf1 = uart_rx_buf2[1];
    }
    else{
    changebuf=0;
    next_buf1 = uart_rx_buf2[0];

    }
    break;
    case UART_RX_STOPPED:
    //LOG_WRN("RX_STOPPED (%d)", evt->data.rx_stop.reason);
    /* Retry automatically in case of UART ERROR interrupt */
    if (evt->data.rx_stop.reason != 0) {
    enable_rx_retry = true;
    }
    break;
    case UART_RX_DISABLED:
    /*
    if (enable_rx_retry && !uart_recovery_pending) {
    k_work_schedule(&uart_recovery_work, K_MSEC(UART_ERROR_DELAY_MS));
    enable_rx_retry = false;
    uart_recovery_pending = true;
    }
    */
    break;
    default:
    break;
    }
    }


    void uartini(void)
    {
    uint32_t start_time,err;

    uart_dev2 = device_get_binding(DT_LABEL(DT_NODELABEL(uart2))); //JXB
    if (uart_dev2 == NULL) {
    return;
    }

    /* Wait for the UART line to become valid */
    start_time = k_uptime_get_32();
    do {
    err = uart_err_check(uart_dev2);
    if (err) {
    uint32_t now = k_uptime_get_32();

    if (now - start_time > UART_ERROR_DELAY_MS) {
    return -EIO;
    }
    k_sleep(K_MSEC(10));
    }
    } while (err);
    /* Register async handling callback */
    err = uart_callback_set(uart_dev2, uart_callback2, NULL);
    if (err) {
    return -EFAULT;
    }

    //uart_data_send();
    /* Power on UART module */
    //pm_device_action_run(uart_dev2, PM_DEVICE_ACTION_RESUME);
    pm_device_state_set(uart_dev2, PM_DEVICE_STATE_ACTIVE); //PM_DEVICE_STATE_ACTIVE PM_DEVICE_STATE_LOW_POWER


    int ret;
    uart_irq_rx_enable(uart_dev2);
    ret=uart_rx_enable(uart_dev2, uart_rx_buf2[0], sizeof(uart_rx_buf2[0]), UART_RX_TIMEOUT_MS);
    next_buf1 = uart_rx_buf2[1];

    // k_work_init(&uart_data_send_work, uart_data_send);
    // k_work_init(&raw_send_work, raw_send);
    // k_work_init(&cmd_send_work, cmd_send);
    // k_work_init(&datamode_quit_work, datamode_quit);
    // k_work_init_delayable(&uart_recovery_work, uart_recovery);
    // k_sem_give(&tx_done);
    // LOG_INF("at_host init done");
    // uart_data_send();

    }

  • Hello , can you please provide full project? I see that the UDP sample includes nrf\samples\nrf9160\udp\child_image\spm.conf
    Have you tried to add this to your project?

    Kind regards,
    Øyvind

Related