Topics

Example of how use UART to communicate with a LTE modem #stm32 #uart


Paul Sokolovsky
 

Hello,

On Thu, 29 Nov 2018 15:50:17 -0800
"Gustavo FN" <@gfnord> wrote:

[]

As far as I have seen, is no simple uart example in the sample
section. So it is difficult for me to figure out how to take the
initial steps. Please, has someone did it before and could share how
it was done?
Coming back to this original question of UART API in Zephyr, the
current situation is that we have a few such APIs, all either subideal
or not yet fully finished. In that regard, I'd like to draw attention
to an API I'm working on:
https://github.com/zephyrproject-rtos/zephyr/blob/master/include/tty.h .
This provides buffered UART access modeled after Unix/POSIX "tty" API.

And that's exactly my response to multitude of UART APIs in Zephyr:
instead of inventing own Zephyr APIs, we should stay close to known
best practices, like POSIX ("close" and "not exactly" because following
POSIX by word would lead to quite bloated solutions, though we're going
to provide that option too via Zephyr's POSIX subsystem).

Caveat is the same as with some other APIs in Zephyr: it's
experimental, work in progress, and subject to change (and will
change, as again, the idea is to make it better than legacy UART
APIs). The race here is to try to stabilize as much as possible of it
for the 1.14 LTS release.


All the best
[]

--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog


Gustavo FN
 

Thank you Rodrigo, I'll work on the code you shared with me and I'll let you know the results.


On Fri, Nov 30, 2018 at 3:29 PM Rodrigo Peixoto <rodrigopex@...> wrote:
The code is:

#include <device.h>
#include <misc/printk.h>
#include <uart.h>
#include <zephyr.h>
#define SYS_LOG_DOMAIN "UART_DRIVER"
#include <logging/sys_log.h>
static void (*__uart_callback)(u8_t) = 0;
void ay_uart_driver_set_callback(void (*callback)(u8_t))
{
__uart_callback = callback;
}
static void uart_fifo_callback(struct device *dev)
{
u8_t recvData;
/* Verify uart_irq_update() */
if (!uart_irq_update(dev)) {
SYS_LOG_ERR("retval should always be 1");
return;
}
/* Verify uart_irq_rx_ready() */
if (uart_irq_rx_ready(dev)) {
/* Verify uart_fifo_read() */
uart_fifo_read(dev, &recvData, 1);
if (__uart_callback) {
__uart_callback(recvData);
}
}
}
u8_t ay_uart_driver_open()
{
struct device *uart_dev = device_get_binding("UART_0");
if (!uart_dev) {
SYS_LOG_ERR("Problem to load uart device");
return 1;
}
/* Verify uart_irq_callback_set() */
uart_irq_callback_set(uart_dev, uart_fifo_callback);
/* Enable Tx/Rx interrupt before using fifo */
/* Verify uart_irq_rx_enable() */
uart_irq_rx_enable(uart_dev);
SYS_LOG_INF("UART device loaded...[OK]");
return 0;
}
void ay_uart_driver_write(u8_t data)
{
<you blocking write code >
}
On Fri, 30 Nov 2018 at 20:12 Rodrigo Peixoto <rodrigopex@...> wrote:
I am not at home. I’ll take a look if I can share that with you.

De nada.
Abraço,
Rodrigo  

On Fri, 30 Nov 2018 at 19:58 Gustavo F N <gustavofn@...> wrote:
No, I haven't. 

Can you share a piece of code of how to do this?

Obrigado Rodrigo!

On Fri, Nov 30, 2018 at 2:57 PM Rodrigo Peixoto <rodrigopex@...> wrote:
I am always using a blocking way to write and a non-blocking way to read. Have you tried?
On Fri, 30 Nov 2018 at 19:50 Gustavo F N <gustavofn@...> wrote:
Hi Rodrigo,

Yes the pins are okay. I can confirm the STM32 is sending a testing message (I connected the sending UART to my computer and read the input).

Looks like the code to read the response is not working, the following part:

while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
}
On Fri, Nov 30, 2018 at 2:45 PM Rodrigo Peixoto <rodrigopex@...> wrote:
Gustavo,

Are you sure the pins are setup ok? You can try to use a ftdi connector to be sure.

Do you have an dts overlay?

Best regards,
Rodrigo
On Fri, 30 Nov 2018 at 12:59 Gustavo FN <gustavofn@...> wrote:
Thank you Stefan, I'll take a look.

I'll share here the simple code I'm doing but so far it is not working. The pins PA9 and PA10 of my STM32 are connected to an adapter to serial port (TX->RX, RX->TX and same ground, also I powed the adapter at 3.3V STM32 pin), a serial port cable and then connected to the modem LTE serial port (I'll double check if the adapter is working well to).

#include <zephyr.h>
#include <device.h>
#include <gpio.h>
#include <uart.h>

static int myuart_send(struct device *uart, char * szStr) {
    size_t i;
    unsigned char temp;
    for (i = 0; i < strlen(szStr); i++) {
        temp = szStr[i];
        temp = uart_poll_out(uart, temp);
    }
}

#define myuart_UART "UART_1"

void main(void) {
    struct device * uart;

    // uart setup
    uart = device_get_binding(myuart_UART);
    if (!uart) {
        printk("Cannot find myuart uart(%s)!\n", myuart_UART);
        return;
    }

    printk("Sending AT to UART");
    myuart_send(uart,"AT\r");
    printk("Sleeping 500ms");
    k_sleep(500);
    printk("Infinite Loop to read the response from uart1");
    while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
    }
}

What I'm missing? This code should send the command "AT" to the modem and the loop should expect to print the "OK" back.

Thanks everyone,

On Fri, Nov 30, 2018 at 6:58 AM Paul Sokolovsky <paul.sokolovsky@...> wrote:
Hello Stefan,

On Fri, 30 Nov 2018 10:20:19 +0000
"Stefan Jaritz" <stefan@...> wrote:

[]

> Keep in mind when you are on the master branch that the API is
> changing from time to time. p.e. 2 days ago the uart_poll_out
> function changed and broke my demo project. :D

Can you elaborate on this? uart_poll_out() is one of the most stable
functions one can imagine, and we're making commitment to not touch it
with the upcoming refactors of UART APIs (which are required otherwise
to both make it more general and easier to use).

>
>
> Regards!
>
>
> Stefan

[]

--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog



--
Gustavo

--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Gustavo
--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Gustavo
--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.

--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Gustavo


Peter A. Bigot
 

Based on the documentation uart_poll_in returns zero to indicate a character arrived.  A negative value, which you're checking for in your code, would indicate the operation failed.  Chances are it's working, and you're discarding the received characters without displaying them.

Peter

On 11/30/18 9:59 AM, Gustavo FN wrote:
    printk("Infinite Loop to read the response from uart1");
    while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
    }
}

What I'm missing? This code should send the command "AT" to the modem and the loop should expect to print the "OK" back.


Rodrigo Peixoto <rodrigopex@...>
 

You have to enable uart interrupt at the conf files.

On Fri, 30 Nov 2018 at 20:29 Rodrigo Peixoto <rodrigopex@...> wrote:
The code is:

#include <device.h>
#include <misc/printk.h>
#include <uart.h>
#include <zephyr.h>
#define SYS_LOG_DOMAIN "UART_DRIVER"
#include <logging/sys_log.h>
static void (*__uart_callback)(u8_t) = 0;
void ay_uart_driver_set_callback(void (*callback)(u8_t))
{
__uart_callback = callback;
}
static void uart_fifo_callback(struct device *dev)
{
u8_t recvData;
/* Verify uart_irq_update() */
if (!uart_irq_update(dev)) {
SYS_LOG_ERR("retval should always be 1");
return;
}
/* Verify uart_irq_rx_ready() */
if (uart_irq_rx_ready(dev)) {
/* Verify uart_fifo_read() */
uart_fifo_read(dev, &recvData, 1);
if (__uart_callback) {
__uart_callback(recvData);
}
}
}
u8_t ay_uart_driver_open()
{
struct device *uart_dev = device_get_binding("UART_0");
if (!uart_dev) {
SYS_LOG_ERR("Problem to load uart device");
return 1;
}
/* Verify uart_irq_callback_set() */
uart_irq_callback_set(uart_dev, uart_fifo_callback);
/* Enable Tx/Rx interrupt before using fifo */
/* Verify uart_irq_rx_enable() */
uart_irq_rx_enable(uart_dev);
SYS_LOG_INF("UART device loaded...[OK]");
return 0;
}
void ay_uart_driver_write(u8_t data)
{
<you blocking write code >
}
On Fri, 30 Nov 2018 at 20:12 Rodrigo Peixoto <rodrigopex@...> wrote:
I am not at home. I’ll take a look if I can share that with you.

De nada.
Abraço,
Rodrigo  

On Fri, 30 Nov 2018 at 19:58 Gustavo F N <gustavofn@...> wrote:
No, I haven't. 

Can you share a piece of code of how to do this?

Obrigado Rodrigo!

On Fri, Nov 30, 2018 at 2:57 PM Rodrigo Peixoto <rodrigopex@...> wrote:
I am always using a blocking way to write and a non-blocking way to read. Have you tried?
On Fri, 30 Nov 2018 at 19:50 Gustavo F N <gustavofn@...> wrote:
Hi Rodrigo,

Yes the pins are okay. I can confirm the STM32 is sending a testing message (I connected the sending UART to my computer and read the input).

Looks like the code to read the response is not working, the following part:

while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
}
On Fri, Nov 30, 2018 at 2:45 PM Rodrigo Peixoto <rodrigopex@...> wrote:
Gustavo,

Are you sure the pins are setup ok? You can try to use a ftdi connector to be sure.

Do you have an dts overlay?

Best regards,
Rodrigo
On Fri, 30 Nov 2018 at 12:59 Gustavo FN <gustavofn@...> wrote:
Thank you Stefan, I'll take a look.

I'll share here the simple code I'm doing but so far it is not working. The pins PA9 and PA10 of my STM32 are connected to an adapter to serial port (TX->RX, RX->TX and same ground, also I powed the adapter at 3.3V STM32 pin), a serial port cable and then connected to the modem LTE serial port (I'll double check if the adapter is working well to).

#include <zephyr.h>
#include <device.h>
#include <gpio.h>
#include <uart.h>

static int myuart_send(struct device *uart, char * szStr) {
    size_t i;
    unsigned char temp;
    for (i = 0; i < strlen(szStr); i++) {
        temp = szStr[i];
        temp = uart_poll_out(uart, temp);
    }
}

#define myuart_UART "UART_1"

void main(void) {
    struct device * uart;

    // uart setup
    uart = device_get_binding(myuart_UART);
    if (!uart) {
        printk("Cannot find myuart uart(%s)!\n", myuart_UART);
        return;
    }

    printk("Sending AT to UART");
    myuart_send(uart,"AT\r");
    printk("Sleeping 500ms");
    k_sleep(500);
    printk("Infinite Loop to read the response from uart1");
    while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
    }
}

What I'm missing? This code should send the command "AT" to the modem and the loop should expect to print the "OK" back.

Thanks everyone,

On Fri, Nov 30, 2018 at 6:58 AM Paul Sokolovsky <paul.sokolovsky@...> wrote:
Hello Stefan,

On Fri, 30 Nov 2018 10:20:19 +0000
"Stefan Jaritz" <stefan@...> wrote:

[]

> Keep in mind when you are on the master branch that the API is
> changing from time to time. p.e. 2 days ago the uart_poll_out
> function changed and broke my demo project. :D

Can you elaborate on this? uart_poll_out() is one of the most stable
functions one can imagine, and we're making commitment to not touch it
with the upcoming refactors of UART APIs (which are required otherwise
to both make it more general and easier to use).

>
>
> Regards!
>
>
> Stefan

[]

--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog



--
Gustavo

--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Gustavo
--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Gustavo
--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.

--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.


Rodrigo Peixoto <rodrigopex@...>
 

The code is:

#include <device.h>
#include <misc/printk.h>
#include <uart.h>
#include <zephyr.h>
#define SYS_LOG_DOMAIN "UART_DRIVER"
#include <logging/sys_log.h>
static void (*__uart_callback)(u8_t) = 0;
void ay_uart_driver_set_callback(void (*callback)(u8_t))
{
__uart_callback = callback;
}
static void uart_fifo_callback(struct device *dev)
{
u8_t recvData;
/* Verify uart_irq_update() */
if (!uart_irq_update(dev)) {
SYS_LOG_ERR("retval should always be 1");
return;
}
/* Verify uart_irq_rx_ready() */
if (uart_irq_rx_ready(dev)) {
/* Verify uart_fifo_read() */
uart_fifo_read(dev, &recvData, 1);
if (__uart_callback) {
__uart_callback(recvData);
}
}
}
u8_t ay_uart_driver_open()
{
struct device *uart_dev = device_get_binding("UART_0");
if (!uart_dev) {
SYS_LOG_ERR("Problem to load uart device");
return 1;
}
/* Verify uart_irq_callback_set() */
uart_irq_callback_set(uart_dev, uart_fifo_callback);
/* Enable Tx/Rx interrupt before using fifo */
/* Verify uart_irq_rx_enable() */
uart_irq_rx_enable(uart_dev);
SYS_LOG_INF("UART device loaded...[OK]");
return 0;
}
void ay_uart_driver_write(u8_t data)
{
<you blocking write code >
}

On Fri, 30 Nov 2018 at 20:12 Rodrigo Peixoto <rodrigopex@...> wrote:
I am not at home. I’ll take a look if I can share that with you.

De nada.
Abraço,
Rodrigo  

On Fri, 30 Nov 2018 at 19:58 Gustavo F N <gustavofn@...> wrote:
No, I haven't. 

Can you share a piece of code of how to do this?

Obrigado Rodrigo!

On Fri, Nov 30, 2018 at 2:57 PM Rodrigo Peixoto <rodrigopex@...> wrote:
I am always using a blocking way to write and a non-blocking way to read. Have you tried?
On Fri, 30 Nov 2018 at 19:50 Gustavo F N <gustavofn@...> wrote:
Hi Rodrigo,

Yes the pins are okay. I can confirm the STM32 is sending a testing message (I connected the sending UART to my computer and read the input).

Looks like the code to read the response is not working, the following part:

while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
}
On Fri, Nov 30, 2018 at 2:45 PM Rodrigo Peixoto <rodrigopex@...> wrote:
Gustavo,

Are you sure the pins are setup ok? You can try to use a ftdi connector to be sure.

Do you have an dts overlay?

Best regards,
Rodrigo
On Fri, 30 Nov 2018 at 12:59 Gustavo FN <gustavofn@...> wrote:
Thank you Stefan, I'll take a look.

I'll share here the simple code I'm doing but so far it is not working. The pins PA9 and PA10 of my STM32 are connected to an adapter to serial port (TX->RX, RX->TX and same ground, also I powed the adapter at 3.3V STM32 pin), a serial port cable and then connected to the modem LTE serial port (I'll double check if the adapter is working well to).

#include <zephyr.h>
#include <device.h>
#include <gpio.h>
#include <uart.h>

static int myuart_send(struct device *uart, char * szStr) {
    size_t i;
    unsigned char temp;
    for (i = 0; i < strlen(szStr); i++) {
        temp = szStr[i];
        temp = uart_poll_out(uart, temp);
    }
}

#define myuart_UART "UART_1"

void main(void) {
    struct device * uart;

    // uart setup
    uart = device_get_binding(myuart_UART);
    if (!uart) {
        printk("Cannot find myuart uart(%s)!\n", myuart_UART);
        return;
    }

    printk("Sending AT to UART");
    myuart_send(uart,"AT\r");
    printk("Sleeping 500ms");
    k_sleep(500);
    printk("Infinite Loop to read the response from uart1");
    while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
    }
}

What I'm missing? This code should send the command "AT" to the modem and the loop should expect to print the "OK" back.

Thanks everyone,

On Fri, Nov 30, 2018 at 6:58 AM Paul Sokolovsky <paul.sokolovsky@...> wrote:
Hello Stefan,

On Fri, 30 Nov 2018 10:20:19 +0000
"Stefan Jaritz" <stefan@...> wrote:

[]

> Keep in mind when you are on the master branch that the API is
> changing from time to time. p.e. 2 days ago the uart_poll_out
> function changed and broke my demo project. :D

Can you elaborate on this? uart_poll_out() is one of the most stable
functions one can imagine, and we're making commitment to not touch it
with the upcoming refactors of UART APIs (which are required otherwise
to both make it more general and easier to use).

>
>
> Regards!
>
>
> Stefan

[]

--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog



--
Gustavo

--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Gustavo
--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Gustavo
--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.

--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.


Rodrigo Peixoto <rodrigopex@...>
 

I am not at home. I’ll take a look if I can share that with you.

De nada.
Abraço,
Rodrigo  

On Fri, 30 Nov 2018 at 19:58 Gustavo F N <gustavofn@...> wrote:
No, I haven't. 

Can you share a piece of code of how to do this?

Obrigado Rodrigo!

On Fri, Nov 30, 2018 at 2:57 PM Rodrigo Peixoto <rodrigopex@...> wrote:
I am always using a blocking way to write and a non-blocking way to read. Have you tried?
On Fri, 30 Nov 2018 at 19:50 Gustavo F N <gustavofn@...> wrote:
Hi Rodrigo,

Yes the pins are okay. I can confirm the STM32 is sending a testing message (I connected the sending UART to my computer and read the input).

Looks like the code to read the response is not working, the following part:

while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
}
On Fri, Nov 30, 2018 at 2:45 PM Rodrigo Peixoto <rodrigopex@...> wrote:
Gustavo,

Are you sure the pins are setup ok? You can try to use a ftdi connector to be sure.

Do you have an dts overlay?

Best regards,
Rodrigo
On Fri, 30 Nov 2018 at 12:59 Gustavo FN <gustavofn@...> wrote:
Thank you Stefan, I'll take a look.

I'll share here the simple code I'm doing but so far it is not working. The pins PA9 and PA10 of my STM32 are connected to an adapter to serial port (TX->RX, RX->TX and same ground, also I powed the adapter at 3.3V STM32 pin), a serial port cable and then connected to the modem LTE serial port (I'll double check if the adapter is working well to).

#include <zephyr.h>
#include <device.h>
#include <gpio.h>
#include <uart.h>

static int myuart_send(struct device *uart, char * szStr) {
    size_t i;
    unsigned char temp;
    for (i = 0; i < strlen(szStr); i++) {
        temp = szStr[i];
        temp = uart_poll_out(uart, temp);
    }
}

#define myuart_UART "UART_1"

void main(void) {
    struct device * uart;

    // uart setup
    uart = device_get_binding(myuart_UART);
    if (!uart) {
        printk("Cannot find myuart uart(%s)!\n", myuart_UART);
        return;
    }

    printk("Sending AT to UART");
    myuart_send(uart,"AT\r");
    printk("Sleeping 500ms");
    k_sleep(500);
    printk("Infinite Loop to read the response from uart1");
    while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
    }
}

What I'm missing? This code should send the command "AT" to the modem and the loop should expect to print the "OK" back.

Thanks everyone,

On Fri, Nov 30, 2018 at 6:58 AM Paul Sokolovsky <paul.sokolovsky@...> wrote:
Hello Stefan,

On Fri, 30 Nov 2018 10:20:19 +0000
"Stefan Jaritz" <stefan@...> wrote:

[]

> Keep in mind when you are on the master branch that the API is
> changing from time to time. p.e. 2 days ago the uart_poll_out
> function changed and broke my demo project. :D

Can you elaborate on this? uart_poll_out() is one of the most stable
functions one can imagine, and we're making commitment to not touch it
with the upcoming refactors of UART APIs (which are required otherwise
to both make it more general and easier to use).

>
>
> Regards!
>
>
> Stefan

[]

--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog



--
Gustavo

--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Gustavo
--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Gustavo
--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.


Gustavo FN
 

No, I haven't. 

Can you share a piece of code of how to do this?

Obrigado Rodrigo!

On Fri, Nov 30, 2018 at 2:57 PM Rodrigo Peixoto <rodrigopex@...> wrote:
I am always using a blocking way to write and a non-blocking way to read. Have you tried?
On Fri, 30 Nov 2018 at 19:50 Gustavo F N <gustavofn@...> wrote:
Hi Rodrigo,

Yes the pins are okay. I can confirm the STM32 is sending a testing message (I connected the sending UART to my computer and read the input).

Looks like the code to read the response is not working, the following part:

while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
}
On Fri, Nov 30, 2018 at 2:45 PM Rodrigo Peixoto <rodrigopex@...> wrote:
Gustavo,

Are you sure the pins are setup ok? You can try to use a ftdi connector to be sure.

Do you have an dts overlay?

Best regards,
Rodrigo
On Fri, 30 Nov 2018 at 12:59 Gustavo FN <gustavofn@...> wrote:
Thank you Stefan, I'll take a look.

I'll share here the simple code I'm doing but so far it is not working. The pins PA9 and PA10 of my STM32 are connected to an adapter to serial port (TX->RX, RX->TX and same ground, also I powed the adapter at 3.3V STM32 pin), a serial port cable and then connected to the modem LTE serial port (I'll double check if the adapter is working well to).

#include <zephyr.h>
#include <device.h>
#include <gpio.h>
#include <uart.h>

static int myuart_send(struct device *uart, char * szStr) {
    size_t i;
    unsigned char temp;
    for (i = 0; i < strlen(szStr); i++) {
        temp = szStr[i];
        temp = uart_poll_out(uart, temp);
    }
}

#define myuart_UART "UART_1"

void main(void) {
    struct device * uart;

    // uart setup
    uart = device_get_binding(myuart_UART);
    if (!uart) {
        printk("Cannot find myuart uart(%s)!\n", myuart_UART);
        return;
    }

    printk("Sending AT to UART");
    myuart_send(uart,"AT\r");
    printk("Sleeping 500ms");
    k_sleep(500);
    printk("Infinite Loop to read the response from uart1");
    while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
    }
}

What I'm missing? This code should send the command "AT" to the modem and the loop should expect to print the "OK" back.

Thanks everyone,

On Fri, Nov 30, 2018 at 6:58 AM Paul Sokolovsky <paul.sokolovsky@...> wrote:
Hello Stefan,

On Fri, 30 Nov 2018 10:20:19 +0000
"Stefan Jaritz" <stefan@...> wrote:

[]

> Keep in mind when you are on the master branch that the API is
> changing from time to time. p.e. 2 days ago the uart_poll_out
> function changed and broke my demo project. :D

Can you elaborate on this? uart_poll_out() is one of the most stable
functions one can imagine, and we're making commitment to not touch it
with the upcoming refactors of UART APIs (which are required otherwise
to both make it more general and easier to use).

>
>
> Regards!
>
>
> Stefan

[]

--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog



--
Gustavo

--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Gustavo
--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Gustavo


Rodrigo Peixoto <rodrigopex@...>
 

I am always using a blocking way to write and a non-blocking way to read. Have you tried?

On Fri, 30 Nov 2018 at 19:50 Gustavo F N <gustavofn@...> wrote:
Hi Rodrigo,

Yes the pins are okay. I can confirm the STM32 is sending a testing message (I connected the sending UART to my computer and read the input).

Looks like the code to read the response is not working, the following part:

while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
}
On Fri, Nov 30, 2018 at 2:45 PM Rodrigo Peixoto <rodrigopex@...> wrote:
Gustavo,

Are you sure the pins are setup ok? You can try to use a ftdi connector to be sure.

Do you have an dts overlay?

Best regards,
Rodrigo
On Fri, 30 Nov 2018 at 12:59 Gustavo FN <gustavofn@...> wrote:
Thank you Stefan, I'll take a look.

I'll share here the simple code I'm doing but so far it is not working. The pins PA9 and PA10 of my STM32 are connected to an adapter to serial port (TX->RX, RX->TX and same ground, also I powed the adapter at 3.3V STM32 pin), a serial port cable and then connected to the modem LTE serial port (I'll double check if the adapter is working well to).

#include <zephyr.h>
#include <device.h>
#include <gpio.h>
#include <uart.h>

static int myuart_send(struct device *uart, char * szStr) {
    size_t i;
    unsigned char temp;
    for (i = 0; i < strlen(szStr); i++) {
        temp = szStr[i];
        temp = uart_poll_out(uart, temp);
    }
}

#define myuart_UART "UART_1"

void main(void) {
    struct device * uart;

    // uart setup
    uart = device_get_binding(myuart_UART);
    if (!uart) {
        printk("Cannot find myuart uart(%s)!\n", myuart_UART);
        return;
    }

    printk("Sending AT to UART");
    myuart_send(uart,"AT\r");
    printk("Sleeping 500ms");
    k_sleep(500);
    printk("Infinite Loop to read the response from uart1");
    while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
    }
}

What I'm missing? This code should send the command "AT" to the modem and the loop should expect to print the "OK" back.

Thanks everyone,

On Fri, Nov 30, 2018 at 6:58 AM Paul Sokolovsky <paul.sokolovsky@...> wrote:
Hello Stefan,

On Fri, 30 Nov 2018 10:20:19 +0000
"Stefan Jaritz" <stefan@...> wrote:

[]

> Keep in mind when you are on the master branch that the API is
> changing from time to time. p.e. 2 days ago the uart_poll_out
> function changed and broke my demo project. :D

Can you elaborate on this? uart_poll_out() is one of the most stable
functions one can imagine, and we're making commitment to not touch it
with the upcoming refactors of UART APIs (which are required otherwise
to both make it more general and easier to use).

>
>
> Regards!
>
>
> Stefan

[]

--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog



--
Gustavo

--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Gustavo
--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.


Gustavo FN
 

Hi Rodrigo,

Yes the pins are okay. I can confirm the STM32 is sending a testing message (I connected the sending UART to my computer and read the input).

Looks like the code to read the response is not working, the following part:

while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
}

On Fri, Nov 30, 2018 at 2:45 PM Rodrigo Peixoto <rodrigopex@...> wrote:
Gustavo,

Are you sure the pins are setup ok? You can try to use a ftdi connector to be sure.

Do you have an dts overlay?

Best regards,
Rodrigo
On Fri, 30 Nov 2018 at 12:59 Gustavo FN <gustavofn@...> wrote:
Thank you Stefan, I'll take a look.

I'll share here the simple code I'm doing but so far it is not working. The pins PA9 and PA10 of my STM32 are connected to an adapter to serial port (TX->RX, RX->TX and same ground, also I powed the adapter at 3.3V STM32 pin), a serial port cable and then connected to the modem LTE serial port (I'll double check if the adapter is working well to).

#include <zephyr.h>
#include <device.h>
#include <gpio.h>
#include <uart.h>

static int myuart_send(struct device *uart, char * szStr) {
    size_t i;
    unsigned char temp;
    for (i = 0; i < strlen(szStr); i++) {
        temp = szStr[i];
        temp = uart_poll_out(uart, temp);
    }
}

#define myuart_UART "UART_1"

void main(void) {
    struct device * uart;

    // uart setup
    uart = device_get_binding(myuart_UART);
    if (!uart) {
        printk("Cannot find myuart uart(%s)!\n", myuart_UART);
        return;
    }

    printk("Sending AT to UART");
    myuart_send(uart,"AT\r");
    printk("Sleeping 500ms");
    k_sleep(500);
    printk("Infinite Loop to read the response from uart1");
    while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
    }
}

What I'm missing? This code should send the command "AT" to the modem and the loop should expect to print the "OK" back.

Thanks everyone,

On Fri, Nov 30, 2018 at 6:58 AM Paul Sokolovsky <paul.sokolovsky@...> wrote:
Hello Stefan,

On Fri, 30 Nov 2018 10:20:19 +0000
"Stefan Jaritz" <stefan@...> wrote:

[]

> Keep in mind when you are on the master branch that the API is
> changing from time to time. p.e. 2 days ago the uart_poll_out
> function changed and broke my demo project. :D

Can you elaborate on this? uart_poll_out() is one of the most stable
functions one can imagine, and we're making commitment to not touch it
with the upcoming refactors of UART APIs (which are required otherwise
to both make it more general and easier to use).

>
>
> Regards!
>
>
> Stefan

[]

--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog



--
Gustavo

--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Gustavo


Rodrigo Peixoto <rodrigopex@...>
 

Gustavo,

Are you sure the pins are setup ok? You can try to use a ftdi connector to be sure.

Do you have an dts overlay?

Best regards,
Rodrigo

On Fri, 30 Nov 2018 at 12:59 Gustavo FN <gustavofn@...> wrote:
Thank you Stefan, I'll take a look.

I'll share here the simple code I'm doing but so far it is not working. The pins PA9 and PA10 of my STM32 are connected to an adapter to serial port (TX->RX, RX->TX and same ground, also I powed the adapter at 3.3V STM32 pin), a serial port cable and then connected to the modem LTE serial port (I'll double check if the adapter is working well to).

#include <zephyr.h>
#include <device.h>
#include <gpio.h>
#include <uart.h>

static int myuart_send(struct device *uart, char * szStr) {
    size_t i;
    unsigned char temp;
    for (i = 0; i < strlen(szStr); i++) {
        temp = szStr[i];
        temp = uart_poll_out(uart, temp);
    }
}

#define myuart_UART "UART_1"

void main(void) {
    struct device * uart;

    // uart setup
    uart = device_get_binding(myuart_UART);
    if (!uart) {
        printk("Cannot find myuart uart(%s)!\n", myuart_UART);
        return;
    }

    printk("Sending AT to UART");
    myuart_send(uart,"AT\r");
    printk("Sleeping 500ms");
    k_sleep(500);
    printk("Infinite Loop to read the response from uart1");
    while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
    }
}

What I'm missing? This code should send the command "AT" to the modem and the loop should expect to print the "OK" back.

Thanks everyone,

On Fri, Nov 30, 2018 at 6:58 AM Paul Sokolovsky <paul.sokolovsky@...> wrote:
Hello Stefan,

On Fri, 30 Nov 2018 10:20:19 +0000
"Stefan Jaritz" <stefan@...> wrote:

[]

> Keep in mind when you are on the master branch that the API is
> changing from time to time. p.e. 2 days ago the uart_poll_out
> function changed and broke my demo project. :D

Can you elaborate on this? uart_poll_out() is one of the most stable
functions one can imagine, and we're making commitment to not touch it
with the upcoming refactors of UART APIs (which are required otherwise
to both make it more general and easier to use).

>
>
> Regards!
>
>
> Stefan

[]

--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog



--
Gustavo

--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.


Gustavo FN
 

Thank you Stefan, I'll take a look.

I'll share here the simple code I'm doing but so far it is not working. The pins PA9 and PA10 of my STM32 are connected to an adapter to serial port (TX->RX, RX->TX and same ground, also I powed the adapter at 3.3V STM32 pin), a serial port cable and then connected to the modem LTE serial port (I'll double check if the adapter is working well to).

#include <zephyr.h>
#include <device.h>
#include <gpio.h>
#include <uart.h>

static int myuart_send(struct device *uart, char * szStr) {
    size_t i;
    unsigned char temp;
    for (i = 0; i < strlen(szStr); i++) {
        temp = szStr[i];
        temp = uart_poll_out(uart, temp);
    }
}

#define myuart_UART "UART_1"

void main(void) {
    struct device * uart;

    // uart setup
    uart = device_get_binding(myuart_UART);
    if (!uart) {
        printk("Cannot find myuart uart(%s)!\n", myuart_UART);
        return;
    }

    printk("Sending AT to UART");
    myuart_send(uart,"AT\r");
    printk("Sleeping 500ms");
    k_sleep(500);
    printk("Infinite Loop to read the response from uart1");
    while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
    }
}

What I'm missing? This code should send the command "AT" to the modem and the loop should expect to print the "OK" back.

Thanks everyone,

On Fri, Nov 30, 2018 at 6:58 AM Paul Sokolovsky <paul.sokolovsky@...> wrote:
Hello Stefan,

On Fri, 30 Nov 2018 10:20:19 +0000
"Stefan Jaritz" <stefan@...> wrote:

[]

> Keep in mind when you are on the master branch that the API is
> changing from time to time. p.e. 2 days ago the uart_poll_out
> function changed and broke my demo project. :D

Can you elaborate on this? uart_poll_out() is one of the most stable
functions one can imagine, and we're making commitment to not touch it
with the upcoming refactors of UART APIs (which are required otherwise
to both make it more general and easier to use).

>
>
> Regards!
>
>
> Stefan

[]

--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog



--
Gustavo


Paul Sokolovsky
 

Hello Stefan,

On Fri, 30 Nov 2018 10:20:19 +0000
"Stefan Jaritz" <stefan@...> wrote:

[]

Keep in mind when you are on the master branch that the API is
changing from time to time. p.e. 2 days ago the uart_poll_out
function changed and broke my demo project. :D
Can you elaborate on this? uart_poll_out() is one of the most stable
functions one can imagine, and we're making commitment to not touch it
with the upcoming refactors of UART APIs (which are required otherwise
to both make it more general and easier to use).



Regards!


Stefan
[]

--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog


Stefan Jaritz
 

Hey Gustavo,

I had the same problem some moths ago. Some help to get into it:

1.) check how uarts work in ZephyrOS(poll/interrupt driven) https://github.com/zephyrproject-rtos/zephyr/tree/master/tests/drivers/uart/uart_basic_api

2.) maybe you need to setup the uart port, with different pins etc. Then you have to change the device tree. You can start with you test board and follow the includes till you reach the definition of the uart and its pins.

3.) Bluetooth stuff https://github.com/zephyrproject-rtos/zephyr/tree/master/samples/bluetooth

Keep in mind when you are on the master branch that the API is changing from time to time. p.e. 2 days ago the uart_poll_out function changed and broke my demo project. :D


Regards!


Stefan


On 29/11/2018 23:50, Gustavo FN wrote:

Hi everyone,

I am new with Zephyr OS and I have a STM32 nucleo l4rz5i board. I'm using the default UART2 port for console output and I would like to use uart1 to connect to a LTE modem, to be able to send data to an API over AT commands. Basically I need to know how to setup the UART1 port, be able to send commands and read the response from the LTE modem.

As far as I have seen, is no simple uart example in the sample section. So it is difficult for me to figure out how to take the initial steps. Please, has someone did it before and could share how it was done? All the best


Gustavo FN
 

Hi everyone,

I am new with Zephyr OS and I have a STM32 nucleo l4rz5i board. I'm using the default UART2 port for console output and I would like to use uart1 to connect to a LTE modem, to be able to send data to an API over AT commands.

Basically I need to know how to setup the UART1 port, be able to send commands and read the response from the LTE modem.

As far as I have seen, is no simple uart example in the sample section. So it is difficult for me to figure out how to take the initial steps. Please, has someone did it before and could share how it was done?

All the best