jaredwolff Jared thank you so much for your help. I was able to get the UART_RX_RDY to fire once by setting my receive buffer to a small value, but now I can not get this interrupt to fire no matter what.
The data that I am reading is a stale junk (not updated by the UART).
The UART_RX_BUF_REQUEST event that fires does not update the//read_ptr , because every time I re-load, and this event is generated, this pointer keeps giving me the same memory content (junk)., even if I invoke an offset on it and read it with an offset. printk(“BUF Req LENGTH =%d\n”, read_len); is 0 at all the times. So it did not read anything on that event.
case UART_RX_RDY : does not fire at all, even I know that my UART receives the data. If this event UART_RX_RDY does not fire, then the data in the buffer is not updated by the UART, so read_ptr gives me the same junk with no change (even if I apply the offset). g_rx_buf is currently 255. I was able to get this event to fire by setting up this buffer to only 2 characters , but even now this trick does not work (not sure why). Should be able to do that like you suggested - just set it to a small value and get the buffer to be full, and trigger this event, but no luck. Not sure what I am doing different, but something is different.
____________________ Read Characters _____________________
I set up a semaphore k_sem_give(&rx_rdy); and the program sits and waits for the semaphore to be taken (indefinitely), causing a blocking wait:
//----------------------------
void read_a_char_print_on_screen (const struct device *dev)
{
int ret;
int err = uart_rx_enable(dev, g_rx_buf, G_BUF_SIZE, 10); // SYS_FOREVER_US
if (err) {
LOG_INF("Can not do UART_RX_Enable from Print on Screen, ERR = %d", err);
}
k_sleep(K_MSEC(500));
while (k_sem_take(&rx_rdy, K_MSEC(100)) !=0)
{
printk("wait for semaphore.."); <---- I am seeing this message no matter what
}
print_buffer(chained_read_buf1, G_BUF_SIZE); <-------- this buffer is the secondary, and it also has no data
// k_sleep(K_MSEC(1000));
print_buffer(read_ptr, G_BUF_SIZE); <------------ to read this pointer, I have to disable the semaphore above
uart_rx_disable (dev);
____________________ Handler _____________________________________
static void uart_callback(const struct device *dev, struct uart_event *evt, void * buf)
{
ARG_UNUSED(dev);
ARG_UNUSED(buf);
switch (evt->type) {
case UART_RX_BUF_RELEASED :
LOG_ERR(" UART_RX_BUF_RELEASED: %d", evt->type);
k_sem_give(&rx_buf_released);
break;
case UART_RX_RDY :
LOG_ERR(" UART_RX_RDY: %d", evt->type);
read_ptr = evt->data.rx.buf+ evt->data.rx.offset;
read_len = evt->data.rx.len;
printk("BUF READY LENGTH =%d\n", read_len);
memcpy(g_rx_buf, read_ptr,read_len);
UART_RX_RDY_SET = true;
print_buffer(read_ptr, read_len);
k_sem_give(&rx_rdy);
break;
case UART_RX_BUF_REQUEST:
LOG_ERR(" UART_RX_BUF_REQUEST: %d", evt->type);
printk("BUF Req LENGTH =%d\n", read_len);
uart_rx_buf_rsp(dev, chained_read_buf1, G_BUF_SIZE);
__ASSERT(err == 0, "Failed to provide new buffer");
k_sem_give(&rx_disabled);
break;
case UART_RX_DISABLED:
LOG_ERR(" UART_RX_DISABLED: %d", evt->type);
k_sem_give(&rx_disabled);
break;
case UART_TX_DONE:
LOG_ERR(" UART_TX_DONE: %d", evt->type);
k_sem_give(&tx_done);
break;
case UART_TX_ABORTED:
LOG_ERR(" UART_TX_ABORTED: %d", evt->type);
break;
case UART_RX_STOPPED:
LOG_WRN(" UART_RX_STOPPED: %d", evt->type);
break;
default:
LOG_ERR("Unexpected event: %d", evt->type);
__ASSERT_NO_MSG(false);
break;
}
} //uart_callback
Thank you!