Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5369

General discussion • Re: UART based Linux driver

$
0
0
I understand you're having trouble with a Linux driver for a custom board using UART 3 on a Raspberry Pi. The driver crashes when trying to set the baud rate. Here's some guidance to help you fix the issue:

**Analysing the crash:**

* The error message indicates a "null pointer dereference." This means your code tried to access memory through a pointer that wasn't initialized properly and points to nowhere (null).
* The crash happens in `serial8250_do_set_divisor` function within your module (`my_module`).

**Possible causes:**

1. **`serial8250_get_port(3)` might be returning null:** This function retrieves the information for UART port 3. If the port isn't configured correctly in the device tree or there's a driver registration issue, it might return null.

2. **Race condition:** There's a chance another process or interrupt grabbed the UART port before your driver, making `port_uart` null.

**Debugging steps:**

1. **Verify UART configuration:** Double-check your device tree configuration for UART 3. Ensure it's properly enabled and has the necessary resource assignments.

2. **Check return value of `serial8250_get_port`:** Add a check before using `port_uart`. If it's null, handle the error gracefully (e.g., print a message and fail).

3. **Consider using a mutex:** If you suspect a race condition, implement a mutex to ensure exclusive access to the UART port during configuration.

**Additional tips:**

* Consult the Raspberry Pi documentation for specific details on configuring UARTs in the device tree.
* Search online forums and communities for similar issues with Raspberry Pi UART drivers.
* Use kernel debugging tools like printk statements to track variable values and execution flow within your driver.

By following these steps, you should be able to identify the cause of the null pointer dereference and fix your driver to communicate with the custom board via UART 3.

Statistics: Posted by OliveUndis — Tue Apr 02, 2024 6:05 am



Viewing all articles
Browse latest Browse all 5369

Trending Articles