You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Elias Hawa <el...@gmail.com> on 2025/06/05 19:36:09 UTC

Changing USART baud rate in sensor driver

Hello everyone,

I'm currently working on a sensor driver for the Quectel L86-M33 GNSS
module. It communicates over UART and is very feature rich, allowing users
to send commands over UART to modify things such as position fix interval
and device baud rate (default at 9600).

I'm able to correctly send commands to the device to change its baud rate,
but I've so far been unsuccessful in figuring out how to change the baud
rate of the UART device. So far I've attempted to change the baud rate
using `file_ioctl` and termios within the device driver but had no luck. I
also experimented with using termios calls in userspace but also had no
success there. In each instance, the device would crash shortly after
attempting to change the baud rate of the UART device.

I've confirmed that commands are being sent correctly as changing the baud
rate of the GNSS module without changing the baud rate of the UART device
returns illegible text.

Any help is appreciated,
Elias

Re: Changing USART baud rate in sensor driver

Posted by Nathan Hartman <ha...@gmail.com>.
On Thu, Jun 5, 2025 at 3:37 PM Elias Hawa <el...@gmail.com> wrote:

> Hello everyone,
>
> I'm currently working on a sensor driver for the Quectel L86-M33 GNSS
> module. It communicates over UART and is very feature rich, allowing users
> to send commands over UART to modify things such as position fix interval
> and device baud rate (default at 9600).
>
> I'm able to correctly send commands to the device to change its baud rate,
> but I've so far been unsuccessful in figuring out how to change the baud
> rate of the UART device. So far I've attempted to change the baud rate
> using `file_ioctl` and termios within the device driver but had no luck. I
> also experimented with using termios calls in userspace but also had no
> success there. In each instance, the device would crash shortly after
> attempting to change the baud rate of the UART device.
>
> I've confirmed that commands are being sent correctly as changing the baud
> rate of the GNSS module without changing the baud rate of the UART device
> returns illegible text.
>
> Any help is appreciated,
> Elias



Hi Elias,

I assume the UART whose BAUD rate you wish to change is a peripheral of
your microcontroller chip?

What microcontroller arch are you using?

Note that the termios and/or ioctl are calling an upper half driver, but in
order for these calls to be successful--that is, in order for them to work
properly and actually change your UART BAUD rate--there has to be an
implementation in the lower half driver.

In NuttX, the concept of upper half and lower half drivers can be summed up
as follows: the upper half is device independent and shared by all
architectures; the lower half driver is device-specific. This is documented
here:
https://nuttx.apache.org/docs/latest/components/drivers/index.html

I did some work on the UART code to add some missing termios and ioctl
support on the architectures I use and am able to test. You can look
through some of the PRs I did, in case it helps you find your way around
the code.

For example:

PR-8465
https://github.com/apache/nuttx/pull/8465

might be relevant. In that one, I made the CTS/RTS termios or ioctls work
on Tiva architecture.

You might see what code was added in that PR. The changes were in up_ioctl
of that arch. That's part of the lower half driver. In that same function
you'll likely see the entry point for altering the BAUD rate.

Then, find the corresponding code of your arch and see if such handling is
missing. If so, adding it will probably solve the issue.

Hope this helps,

Nathan

Re: Changing USART baud rate in sensor driver

Posted by Michał Łyszczek <mi...@bofc.pl>.
On 2025-06-05 15:36:09, Elias Hawa wrote:
> Hello everyone,
> 
> I'm currently working on a sensor driver for the Quectel L86-M33 GNSS
> module. It communicates over UART and is very feature rich, allowing users
> to send commands over UART to modify things such as position fix interval
> and device baud rate (default at 9600).
> 
> I'm able to correctly send commands to the device to change its baud rate,
> but I've so far been unsuccessful in figuring out how to change the baud
> rate of the UART device. So far I've attempted to change the baud rate
> using `file_ioctl` and termios within the device driver but had no luck. I
> also experimented with using termios calls in userspace but also had no
> success there. In each instance, the device would crash shortly after
> attempting to change the baud rate of the UART device.

Well, on normal unix you'd set speed with

    fd = open("/dev/ttyS0", ...);
    tcgetattr(fd, &tty)
    cfsetispeed(&tty, B9600);
    tcsetattr(fd, TCSANOW, &tty)

I never used dynamic baudrate on nuttx, but I would expect it to work as well.

You may want to step into tcsetattr() and see where it gets you. Maybe your
platform cannot set new baudrate properly?

And how does the driver crash? Do you have any stack trace? Again, this may
indicate that your platform just cannot set new baudrate.

-- 
.-----------------.-------------------.----------------------.-----------------.
| Michal Lyszczek | Embedded C, Linux |   Company Address    |  .-. opensource |
| +48 727 564 419 | Software Engineer | Akacjowa 10a; 55-330 |  oo|  supporter |
| https://bofc.pl `----.--------------: Brzezinka Sredzka PL | /`'\      &     |
| GPG FF1EBFE7E3A974B1 | Bits of Code | NIP:   813 349 58 78 |(\_;/) programer |
`----------------------^--------------^----------------------^-----------------'