Skip to content
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

Draft: Add LoRa Basics Modem radio drivers and LoRaWAN stack #77495

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

Salamandar
Copy link
Contributor

@Salamandar Salamandar commented Aug 23, 2024

This pull request adds support for the Semtech transceivers with the "radio drivers", and for the LoRaWAN stack, both provided by the LoRa Basics Modem project (https://github.com/Lora-net/SWL2001)

This PR adds:

  • A new external module, the repository SWL2001 from Semtech
  • Duplicated drivers for LR11xx and SX126x LoRa transceivers -> I postfixed the compatible with -new, but what's the guideline on that ?
    • The drivers don't expose any API as the LBM repository provides one and the LBM stack uses the "RAL" "Radio Abstraction Layer". We might need to create an ad-hoc API for Zephyr.
  • The LoRaWAN subsystem based on the LBM stack
    • The subsys actually only contains the Kconfig and the source for the "main stack thread". The rest of the code and bindings lives in the module.
    • I named the drivers lora_lbm and subsys lorawan_lbm, to differentiate from the loramac-node implementations.
  • Samples: driver samples written from scratch and LBM "examples" ported from the SWL2001 repository.
    • Those ported examples come with the app_helpers code in modules/lora_basics_modem for portability purpose, but this should be cleaned up.

EDIT: I splitted this PR in half : this PR contains only code that was written with zephyr in mind. The samples that still need porting are in https://github.com/salamandar/zephyr/tree/lbm_samples

@zephyrbot zephyrbot added area: Samples Samples area: Shields Shields (add-on boards) labels Aug 23, 2024
@Salamandar Salamandar changed the title Add LoRa Basics Modem radio drivers and LoRaWAN stack Draft: Add LoRa Basics Modem radio drivers and LoRaWAN stack Aug 23, 2024
@zephyrbot
Copy link
Collaborator

zephyrbot commented Aug 23, 2024

The following west manifest projects have been modified in this Pull Request:

Name Old Revision New Revision Diff
lora_basics_modem N/A Lora-net/SWL2001@feature/zephyr N/A

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@zephyrbot zephyrbot added manifest manifest-lora_basics_modem DNM This PR should not be merged (Do Not Merge) labels Aug 23, 2024
@zafersn
Copy link

zafersn commented Aug 26, 2024

Hi, @Salamandar, did you have chance to test this with CONFIG_PM?

When I enable it, join requests always fail. still investigating this issue...

Any idea what the issue could be?

P.S.
I was also working on porting this basic lib to zephyr and finished it just couple of days ago. and just noticed your implementation now :)

@Salamandar Salamandar force-pushed the lora_basics_modem branch 2 times, most recently from d74b021 to abbb834 Compare August 26, 2024 11:35
@zafersn
Copy link

zafersn commented Aug 26, 2024

Hi @Salamandar I’m not sure if this is the best place to discuss build failures, but I wanted to share these with you. If there’s a more appropriate forum or person for this, please let me know.

here are errors: when I build your pull request:

Probably you know, but anyway:

disable wdt:
CONFIG_WATCHDOG=n

got error:

zephyr/modules/lora_basics_modem/app_helpers/smtc_hal_zephyr/smtc_hal_watchdog.c:57: undefined reference to `__device_dts_ord_115'

workaround for now.

void hal_watchdog_reload(void)
{
#ifdef CONFIG_WATCHDOG
	 wdt_feed(prv_wdt_dev, prv_wdt_channel_id);
#endif
}

disabling all region supports:
CONFIG_LORA_BASICS_MODEM_ENABLE_ALL_REGIONS=n

compiling is ok but

*** Booting Zephyr OS build v3.7.0-rc3-124-gabbb8340c2af ***
[00:00:00.000,000] <inf> smtc_modem: Periodical uplink (60 sec) example is starting
[00:00:00.000,000] <inf> smtc_modem: Modem Initialization
[00:00:00.203,000] <inf> smtc_modem: Use soft secure element for cryptographic functionalities
[00:00:00.203,000] <inf> smtc_modem_hal: Opened flash area of size 65536
[00:00:00.203,000] <err> smtc_modem: Invalid Region 0x01
[00:00:00.203,000] <err> smtc_modem: Region (0x1) in nvm context not supported
[00:00:00.203,000] <wrn> smtc_modem: No valid lr1mac context --> Factory reset
[00:00:00.261,000] <inf> smtc_modem: stack_id 0
[00:00:00.261,000] <inf> smtc_modem: DevNonce = 0
[00:00:00.261,000] <inf> smtc_modem: JoinNonce = 0xff ff ff, NetID = 0xff ff ff
[00:00:00.261,000] <inf> smtc_modem: Region = CN470
[00:00:00.261,000] <inf> smtc_modem: LoRaWAN Certification is disabled on stack 0
[00:00:00.261,000] <inf> smtc_modem: lorawan_alcsync_services_init task_id 7, service_id 0, CURRENT_STACK:0
[00:00:00.261,000] <wrn> smtc_modem: stream_services_init
[00:00:00.261,000] <wrn> smtc_modem: lfu_services_init
[00:00:00.290,000] <inf> smtc_modem: Modem event callback
[00:00:00.290,000] <inf> smtc_modem: Event received: RESET
[00:00:00.290,000] <err> smtc_modem: Invalid Region 0x01
[00:00:00.291,000] <err> smtc_modem: In WEST_TOPDIR/wsc/periodical_uplink_semtec/src/main_periodical_uplink.c - modem_event_callback (line 373): SMTC_MODEM_RC_INVALID
[00:00:00.291,000] <inf> smtc_modem: smtc_modem_join_network
[00:00:00.291,000] <inf> smtc_modem: Start a new join sequence in 3 seconds on stack 0
[00:00:00.291,000] <inf> smtc_modem: Starting loop...
[00:00:00.291,000] <inf> smtc_modem: Sleeping for 3000ms
[00:00:03.291,000] <inf> smtc_modem: Sleeping for 0ms
[00:00:03.291,000] <inf> smtc_modem: Sleeping for 10000ms
[00:00:06.859,000] <inf> smtc_modem: modem_tpm_radio_busy_lbt
[00:00:06.859,000] <inf> smtc_modem: Sleeping for 10000ms

Ill share the quick workaround solution shortly

@Salamandar Salamandar force-pushed the lora_basics_modem branch 3 times, most recently from 7330245 to 4caafc9 Compare August 26, 2024 17:49
…b org)

This project will be used in the next commits.

Signed-off-by: Félix Piédallu <[email protected]>
@Salamandar Salamandar force-pushed the lora_basics_modem branch 5 times, most recently from bcb80a0 to 16fdee2 Compare August 26, 2024 19:40
@Salamandar
Copy link
Contributor Author

Hi @Salamandar I’m not sure if this is the best place to discuss build failures, but I wanted to share these with you. If there’s a more appropriate forum or person for this, please let me know.
disable wdt: CONFIG_WATCHDOG=n

Ah yeah, that's "expected". The code in the samples and lora_basics_modem/app_helpers mostly is copy-pasta from the official samples and example codes, and it's not really "portable" nor configurable yet. I'll work towards a cleaner code in this PR.

@Salamandar Salamandar force-pushed the lora_basics_modem branch 12 times, most recently from f129e6c to a899b07 Compare August 27, 2024 17:19
Add the module, subsys, drivers for LoRa Basics Modem.
Add Salamandar (Félix Piédallu) to its maintainers.

Signed-off-by: Félix Piédallu <[email protected]>
This module provides:
* The cmake files for LoRa Basics Modem
* The "HAL" described here:
  https://github.com/Lora-net/SWL2001/blob/master/lbm_lib/PORTING_GUIDE.md
* Reimplementations of the logging functions in smtc_modem_hal_dbg_trace.h

Signed-off-by: Félix Piédallu <[email protected]>
Those drivers are actually device tree bindings, and HAL/BSP as described
in https://github.com/Lora-net/SWL2001/blob/master/lbm_lib/PORTING_GUIDE.md

Signed-off-by: Félix Piédallu <[email protected]>
Those shields are sold by Semtech and are arduino compatible.

Signed-off-by: Félix Piédallu <[email protected]>
ping_pong is an automatic ping-pong example between two LBM boards
ping_shell is a manual ping-like example between two LBM boards

Signed-off-by: Félix Piédallu <[email protected]>
This stack is based on the lora_basics_modem external module.

It provides configuration for LBM as well as a standalone
"main" LBM thread that needs to be manually started.

Signed-off-by: Félix Piédallu <[email protected]>
@ndrs-pst
Copy link
Contributor

@KajbaM, forgive the ping!
Since IRNAS has implemented similar functionality with the Lora Basic Modem for Zephyr,
it would be fantastic to get insights on this PR.
Your experience with SWL2001-Zephyr would be incredibly helpful. Thank you!

@TjazVracko
Copy link
Contributor

@ndrs-pst I work at IRNAS and will submit a review. This is more or less a continuation of our work by Semtech, so we might have some additional insight.

Hopefully, this gets merged, so we can all benefit :)

Copy link
Contributor

@TjazVracko TjazVracko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some general comments and suggestions.

Other maintainers should leave comments about more Zephyr-specific topics.


If this is merged, you will then have 2 LoRaWAN stacks in Zephyr - LBM and LoRaMAC-Node.
Since LBM is the new and supported one, could LoRaMAC-Node be removed? It should be trivial to implement the Zephyr LoRa and LoRaWAN APIs on top of LBM.
Thoughts?

modules/lora_basics_modem/CMakeLists.txt Outdated Show resolved Hide resolved
west.yml Show resolved Hide resolved
modules/lora_basics_modem/common.cmake Outdated Show resolved Hide resolved
modules/lora_basics_modem/lr11xx.cmake Outdated Show resolved Hide resolved
Comment on lines +96 to +97
LOG_WRN("Resetting the MCU");
k_sleep(K_SECONDS(1)); /* Sleep a bit so logs are printed. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOG_WRN("Resetting the MCU");
k_sleep(K_SECONDS(1)); /* Sleep a bit so logs are printed. */
LOG_WRN("Resetting the MCU");
LOG_PANIC();

Use LOG_PANIC to flush the logs.

Comment on lines +242 to +246
/* FIXME: That whole storage bit should be revamped to something more generic,
* that would remove the whole read-erase-write logics and leverage the zephyr flash stack.
* Maybe split the flash in half, one with contexts and one with store-and-forward.
* Maybe remove the store-and-forward circularfs backend and just use NVS.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the storage code bellow seems very experimental.
Maybe remove it for now and only have the user-callback option?

I think the Zephyr community should help out here with suggestions on how to implement this in the best way.

if (smtc_modem_is_irq_flag_pending()) {
continue;
}
LOG_INF("Sleeping for %dms", sleep_time_ms);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOG_INF("Sleeping for %dms", sleep_time_ms);
LOG_DBG("Sleeping for at most %dms", sleep_time_ms);

So that logs are less spammy.

Comment on lines +289 to +293
config LORA_BASICS_MODEM_NUMBER_OF_STACKS
int "Number of LoRa Basics Modem stacks (only 1 is supported for now)"
default 1
help
Number of stacks to be used by the modem library.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since 1 is the only valid value, this should not be user-assignable:

Suggested change
config LORA_BASICS_MODEM_NUMBER_OF_STACKS
int "Number of LoRa Basics Modem stacks (only 1 is supported for now)"
default 1
help
Number of stacks to be used by the modem library.
config LORA_BASICS_MODEM_NUMBER_OF_STACKS
int
default 1 # only 1 is supported for now
help
Number of stacks to be used by the modem library.

{
LOG_INF("===== SX126x TX CW example =====");

apps_common_lr11xx_system_init(context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use apps_common_ functions here, but there is no apps_common module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Process area: Samples Samples area: Shields Shields (add-on boards) DNM This PR should not be merged (Do Not Merge) manifest manifest-lora_basics_modem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants