-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial standalone sx126x driver [WIP] #15795
Open
keever50
wants to merge
2
commits into
apache:master
Choose a base branch
from
keever50:sx126x_lora_driver
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,432
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
Documentation/components/drivers/wireless/lpwan/sx126x.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
================== | ||
SX126x LoRa driver | ||
================== | ||
**Currently experimental. Changes can happen in the near future** | ||
|
||
.. image:: https://www.thethingsnetwork.org/docs/lorawan/transceivers/SX1261.jpg | ||
|
||
Short introduction SX126x | ||
========================= | ||
The SX126x is a LoRa chip by Semtech. Sometimes also found in chips with a different name but the same or similar sillicon underneath. | ||
The older variant is the SX127x, even with its higher number. The SX126x series promises to improve the link budget. They also added extra spreading factors. | ||
|
||
Userspace API | ||
============= | ||
This driver is controlled as a character device and using IOCTL commands. At the time of writing this 24 February, 2025, there is no common API **yet** for LoRa devices and other RF devices under ``/lpwan``. | ||
Currently this driver is controlled using older and driver specific IOCTL commands. | ||
|
||
Basic RF IOCTL | ||
-------------- | ||
See ``nuttx/wireless/ioctl.h`` : ``WLIOC_x`` for setting the basic radio parameters such as frequency and power. | ||
Please note that frequency and power may be limited by the lower driver part at board logic. | ||
|
||
Driver dedicated IOCTL | ||
---------------------- | ||
See ``nuttx/wireless/lpwan/sx126x.h`` : ``SX126XIOC_x`` for the commands. | ||
|
||
* The packet type is set using ``SX126XIOC_PACKETTYPESET`` which takes ``sx126x_packet_type_e`` enums. **Currently only LoRa packet type is supported.** | ||
|
||
* LoRa modulation and LoRa packets are configured using ``SX126XIOC_LORACONFIGSET`` which takes a pointer to a ``sx126x_lora_config_s`` struct. This struct contains two seperate structures for modulation and packet config. It is recommended to follow the SX126x datasheet at https://www.semtech.com/products/wireless-rf/lora-connect/sx1262 that gives more details about each parameter. | ||
|
||
Reading / Writing | ||
----------------- | ||
Reading and writing is done with the ``read`` and ``write`` functions. | ||
|
||
* ``write`` directly transmits the given bytes using the IOCTL configured parameters. **Does not support polling or timeout yet.** | ||
|
||
* ``read`` takes a pointer to ``sx126x_read_header_s``, which contains information about the received packet. **RSSI and SNR aren't implemented yet**. *Note that packets are always received, even when the CRC (checked using ``.crc_error``) failed.* | ||
|
||
Board implementation | ||
==================== | ||
The driver can be registered in board logic using ``sx126x_register``, which takes an SPI bus, lower driver and the path. | ||
More information about ``struct sx126x_lower_s`` parameters can be found in detail under ``nuttx/wireless/lpwan/sx126x.h`` : ``struct sx126x_lower_s``. | ||
|
||
This driver supports multiple instances using ``dev_number`` found in ``sx126x_lower_s``. This is done so multiple channels of LoRa can work at the same time. | ||
|
||
**Do not assign random numbers in get_pa_values. This can damage the device depending on model. Refer to the manual** | ||
|
||
Testing | ||
======= | ||
A simple ping-pong test is made to test the device. This code can be used as an example. It is found here https://pastebin.com/71CdKZvm | ||
It takes the following parameters: | ||
|
||
* ``-f`` sets frequency in hz. The range is board depended. | ||
* ``-b`` sets the bandwidth in kHz and automatically selects the closest sx126x supported bandwidth. | ||
* ``-s`` sets the spreading factor between 5 and 12. | ||
* ``-p`` sets the power in dBm. The range is board depended. Also PA setting depended. | ||
* ``-t`` perform transmit. Transmit the following bytes. | ||
* ``-r`` perform receive. Receives and print. | ||
* ``-x`` perform transmit and receive. Transmits following bytes and attempts to receives immidiately. To be used with ``-e`` echo | ||
* ``-e`` perform echo. Listen and repeat. | ||
|
||
.. image:: https://private-user-images.githubusercontent.com/9679272/415904583-3a979608-6386-4b51-8d0e-acf09d918299.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDA0MjAwODIsIm5iZiI6MTc0MDQxOTc4MiwicGF0aCI6Ii85Njc5MjcyLzQxNTkwNDU4My0zYTk3OTYwOC02Mzg2LTRiNTEtOGQwZS1hY2YwOWQ5MTgyOTkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIyNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMjRUMTc1NjIyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MDk5MDk1NzY2MjYzMGJlNWVkMWFiYTAwNWU0OGM3N2JkMDBmN2Q5Yzk0MDY3MjNkY2IxZWM5MzM2Nzc4YWM5NSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.6JOsN_-uyyxnlxHg33Bt_WT5DFSO_i-Uh4coi-8xpEc | ||
|
||
:alt: Running sx126x -f 869250000 -b 250 -s 10 -p 22 -x "HELLO" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# ############################################################################## | ||
# drivers/wireless/lpwan/sx126x/CMakeLists.txt | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more contributor | ||
# license agreements. See the NOTICE file distributed with this work for | ||
# additional information regarding copyright ownership. The ASF licenses this | ||
# file to you under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
# | ||
# ############################################################################## | ||
if(CONFIG_LPWAN_SX126X) | ||
target_sources(drivers PRIVATE sx126x.c) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# | ||
# For a description of the syntax of this configuration file, | ||
# see the file kconfig-language.txt in the NuttX tools repository. | ||
# | ||
|
||
if LPWAN_SX126X | ||
|
||
config LPWAN_SX126X_RFFREQ_DEFAULT | ||
int "SX126X default RF frequency Hz" | ||
default 869252000 | ||
|
||
config LPWAN_SX126X_SF_DEFAULT | ||
int "SX126X default spreading factor" | ||
default 10 | ||
|
||
config LPWAN_SX126X_BW_DEFAULT | ||
int "SX126X default bandwidth kHz" | ||
default 125 | ||
|
||
config LPWAN_SX126X_CR_DEFAULT | ||
int "SX126X default coding rate" | ||
default 8 | ||
|
||
config LPWAN_SX126X_MAX_DEVICES | ||
int "SX126X maximum devices" | ||
default 1 | ||
|
||
endif # DRIVERS_LPWAN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
############################################################################ | ||
# drivers/wireless/lpwan/sx126x/Make.defs | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. The | ||
# ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance with the | ||
# License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
############################################################################ | ||
|
||
# Include SX126X drivers into the build | ||
|
||
ifeq ($(CONFIG_LPWAN_SX126X),y) | ||
|
||
CSRCS += sx126x.c | ||
|
||
# Include SX126X build support | ||
|
||
DEPPATH += --dep-path wireless$(DELIM)lpwan$(DELIM)sx126x | ||
VPATH += :wireless$(DELIM)lpwan$(DELIM)sx126x | ||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)drivers$(DELIM)wireless$(DELIM)lpwan$(DELIM)sx126x | ||
|
||
endif # CONFIG_LPWAN_SX126X |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include the image in the repository, external links can disappear or be moved to other URL