Skip to content

Conversation

dylad
Copy link
Member

@dylad dylad commented Oct 21, 2021

Contribution description

This PR adds initial support for nRF9160 modem library as a RIOT pkg.
The modem library (and the modem firmware) allow to use NB-IoT, LTE-M and GNSS features for nRF9160 MCUs.
In the current state, only the GNSS service is added. (NB-IoT and LTE-M can be added in a followup PR).

MCU and modem can communicate through the device's RAM and is managed by the Inter-Processor Communication peripheral (IPC).

Unfortunately, the modem library relies on Nordic drivers SDK for handling IPC stuff, thus I add to "emulate" somehow some functions of the Nordic SDK to make the modem library happy.

I think some discussions are needed for specific like the malloc management because some malloc() are made from ISR context by the modem library which is troublesome.

Testing procedure

Run tests/pkg_nrf_modem on nRF9160DK, connect your terminal and go for a quick walk outside.
Please make sure the nRF modem firmware is flashed before testing the application.
You can flash it through nrfconnect application or you can use make nrf_modem/flash_firmware which will use nrfjprog tool.
(This PR also adds nrfjprog as PROGRAMMER).

The application will initialize the GNSS service and will wait for a GPS fix event. Once GPS fix is made, NMEA frame will be displayed on the shell with your current location.

Issues/PRs references

None.

@dylad dylad requested review from chrysn, maribu and kaspar030 October 21, 2021 19:50
@github-actions github-actions bot added Area: boards Area: Board ports Area: build system Area: Build system Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: Kconfig Area: Kconfig integration Area: pkg Area: External package ports Area: tests Area: tests and testing framework Area: tools Area: Supplementary tools labels Oct 21, 2021
@dylad
Copy link
Member Author

dylad commented Oct 21, 2021

For reference, here's the output of the test application:

2021-10-20 15:47:30,788 # main(): This is RIOT! (Version: 2021.10-devel-647-gb3719c-pr/pkg/nrf_modem_gnss_support)
2021-10-20 15:47:30,789 # nRF modem test application
2021-10-20 15:47:30,790 # 
2021-10-20 15:47:31,361 # nRF modem libray initialized
2021-10-20 15:47:31,377 # setup modem OK
> 2021-10-20 15:47:31,379 # [gnss_thread]: starting...
2021-10-20 15:47:31,393 # [gnss_thread]: GNSS Initialized
2021-10-20 15:47:31,408 # [gnss_thread]: Starting GNSS service...
2021-10-20 15:47:31,410 # [gnss_thread]: waiting for fix event...
?
2021-10-20 15:47:49,972 # help
2021-10-20 15:47:50,009 # Command              Description
2021-10-20 15:47:50,012 # ---------------------------------------
2021-10-20 15:47:50,014 # at                   Send an AT command to the modem
2021-10-20 15:47:50,015 # reboot               Reboot the node
2021-10-20 15:47:50,017 # version              Prints current RIOT_VERSION
2021-10-20 15:47:50,019 # pm                   interact with layered PM subsystem
2021-10-20 15:47:50,021 # ps                   Prints information about running threads.
> at AT+CFUN?
2021-10-20 15:47:54,150 # at AT+CFUN?
2021-10-20 15:47:54,151 # +CFUN: 1
2021-10-20 15:47:54,166 # OK
2021-10-20 15:47:54,166 # 
> at AT+CFUN?
2021-10-20 15:48:40,933 # at AT+CFUN?
2021-10-20 15:48:40,934 # +CFUN: 1
2021-10-20 15:48:40,934 # OK
2021-10-20 15:48:40,935 # 
> 2021-10-20 15:48:48,465 # [gnss_thread]: GNSS event FIX
2021-10-20 15:48:48,468 # [gnss_thread: NMEA:$GPRMC,134848.34,A,4839.22542,N,00222.03818,E,0.38,0.00,201021,,,A,V*2F
2021-10-20 15:48:48,468 # 
2021-10-20 15:48:48,471 # [gnss_thread: NMEA:$GPRMC,134848.34,A,4839.22542,N,00222.03818,E,0.38,0.00,201021,,,A,V*2F
2021-10-20 15:48:48,472 # 
2021-10-20 15:48:48,475 # [gnss_thread: NMEA:$GPRMC,134848.34,A,4839.22542,N,00222.03818,E,0.38,0.00,201021,,,A,V*2F
2021-10-20 15:48:48,475 # 
2021-10-20 15:48:48,478 # [gnss_thread: NMEA:$GPRMC,134848.34,A,4839.22542,N,00222.03818,E,0.38,0.00,201021,,,A,V*2F
2021-10-20 15:48:48,478 # 
2021-10-20 15:48:48,481 # [gnss_thread: NMEA:$GPRMC,134848.34,A,4839.22542,N,00222.03818,E,0.38,0.00,201021,,,A,V*2F
2021-10-20 15:48:48,482 # 
2021-10-20 15:48:48,504 # [gnss_thread: NMEA:$GPRMC,134848.34,A,4839.22542,N,00222.03818,E,0.38,0.00,201021,,,A,V*2F
2021-10-20 15:48:48,504 # 
2021-10-20 15:48:48,507 # [gnss_thread: NMEA:$GPRMC,134848.34,A,4839.22542,N,00222.03818,E,0.38,0.00,201021,,,A,V*2F
2021-10-20 15:48:48,507 # 
2021-10-20 15:48:48,511 # [gnss_thread: NMEA:$GPRMC,134848.34,A,4839.22542,N,00222.03818,E,0.38,0.00,201021,,,A,V*2F
2021-10-20 15:48:48,511 # 
2021-10-20 15:48:49,474 # [gnss_thread]: GNSS event FIX
2021-10-20 15:48:49,477 # [gnss_thread: NMEA:$GPRMC,134849.34,A,4839.22676,N,00222.03677,E,0.09,0.00,201021,,,A,V*2F
2021-10-20 15:48:49,478 # 
2021-10-20 15:48:49,481 # [gnss_thread: NMEA:$GPRMC,134849.34,A,4839.22676,N,00222.03677,E,0.09,0.00,201021,,,A,V*2F
2021-10-20 15:48:49,481 # 
2021-10-20 15:48:49,484 # [gnss_thread: NMEA:$GPRMC,134849.34,A,4839.22676,N,00222.03677,E,0.09,0.00,201021,,,A,V*2F
2021-10-20 15:48:49,484 # 
2021-10-20 15:48:49,487 # [gnss_thread: NMEA:$GPRMC,134849.34,A,4839.22676,N,00222.03677,E,0.09,0.00,201021,,,A,V*2F
2021-10-20 15:48:49,488 # 
2021-10-20 15:48:49,491 # [gnss_thread: NMEA:$GPRMC,134849.34,A,4839.22676,N,00222.03677,E,0.09,0.00,201021,,,A,V*2F
2021-10-20 15:48:49,491 # 
2021-10-20 15:48:49,513 # [gnss_thread: NMEA:$GPRMC,134849.34,A,4839.22676,N,00222.03677,E,0.09,0.00,201021,,,A,V*2F
2021-10-20 15:48:49,513 # 
2021-10-20 15:48:49,516 # [gnss_thread: NMEA:$GPRMC,134849.34,A,4839.22676,N,00222.03677,E,0.09,0.00,201021,,,A,V*2F
2021-10-20 15:48:49,517 # 
2021-10-20 15:48:49,520 # [gnss_thread: NMEA:$GPRMC,134849.34,A,4839.22676,N,00222.03677,E,0.09,0.00,201021,,,A,V*2F

@dylad dylad added the Type: new feature The issue requests / The PR implemements a new feature for RIOT label Oct 21, 2021
@dylad dylad force-pushed the pr/pkg/nrf_modem_gnss_support branch from 736ea9f to b39d4cc Compare February 17, 2022 21:01
@dylad
Copy link
Member Author

dylad commented Feb 17, 2022

@leandrolanzieri Could you take a look at this one ?

Just rebased to lastest master

Copy link
Contributor

@leandrolanzieri leandrolanzieri left a comment

Choose a reason for hiding this comment

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

Some initial comments, I'll try to test this on hardware during this week.

# Give the possibility to user to flash nRF modem firmware
# To do so, use make nrf_mode/flash_firmware
ifneq (,$(filter nrf_modem, $(USEPKG)))
include $(RIOTMAKE)/nrf_modem_fw.inc.mk
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not exist in this commit yet. You probably will need to split differently.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll change it (and mark it as resolved so I won't forget) when this PR will be squashed.

@@ -0,0 +1,19 @@
PKG_NAME=nrf_modem
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we better have this package as sdk_nrfxlib? With pseudomodules we could choose what to compile and we could reuse it (thinking about crypto here ;)

return sema_wait_timed_ztimer(sema, ZTIMER_MSEC, 0);
}
else if (timeout == NRF_MODEM_OS_FOREVER) {
return sema_wait_timed_ztimer(sema, ZTIMER_MSEC, UINT32_MAX);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we loop here until success?

@@ -0,0 +1,106 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't fully understand what this layer is doing. The documentation mentions only the implementation of nrf_modem_os.c based on nrf_modem_os.h, why do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the libmodem.a call these functions. Unfortunately, it seems that this library relies (without any mention in the doc as far as I can tell) on nordic sdk for using the IPC peripheral which is needed for proper operations. I had to reimplement these functions using Nordic terminology so I could successfully link the lib against my code as I don't want to pull their whole SDK into RIOT...

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. So you took the implementation from this library? Wouldn't it be cheaper to add it as a package? I think it may turn to be an overhead to maintain a driver that is basically what they already have upstream. Or is there maybe some advantage other than not pulling the package once, which I fail to see here?

Copy link
Member Author

Choose a reason for hiding this comment

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

So you took the implementation from this library?

Yes.

Wouldn't it be cheaper to add it as a package?

I don't think so. This can be done but at first I wanted to avoid all the pain adding such a big pkg for a single file in one PR.

@dylad
Copy link
Member Author

dylad commented Feb 21, 2022

Thanks for the review ! I'll try to fix everything by the end of the week.

@@ -0,0 +1,14 @@
#include download firmware information from nrf_modem pkg
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should make this independent of the package. I'd move it to its dedicated directory in dist/tools, as it really does not need the package, it downloads the firmware independently. What do you think?


# Give the possibility to user to flash nRF modem firmware
# To do so, use make nrf_mode/flash_firmware
ifneq (,$(filter nrf_modem, $(USEPKG)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, we could make this independent of the package being required right? It's just flashing the modem firmware

@@ -0,0 +1,12 @@
include ../Makefile.tests_common

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
BOARD ?= nrf9160dk

@leandrolanzieri
Copy link
Contributor

Sadly I can't get this to work yet :( I'm hitting two issues:

  1. Can't seem to be able to connect with make term, no tty device appears.
  2. I attempted to debug which seems to work, but when flash the test application I get:
### Starting Debugging ###
SEGGER J-Link GDB Server V7.62a Command Line Version

JLinkARM.dll V7.62a (DLL compiled Feb 23 2022 17:02:35)

-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     3333
SWO raw output listening port: 2332
Terminal I/O port:             4444
Accept remote connection:      yes
Generate logfile:              off
Verify download:               off
Init regs on start:            off
Silent mode:                   on
Single run mode:               off
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 NRF9160_XXAA
Target interface:              SWD
Target interface speed:        2000kHz
Target endian:                 little

Reading symbols from /home/leandro/Work/RIOT/tests/pkg_nrf_modem/bin/nrf9160dk/tests_pkg_nrf_modem.elf...
Remote debugging using :3333
0xeffffffe in ?? ()
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/leandro/Work/RIOT/tests/pkg_nrf_modem/bin/nrf9160dk/tests_pkg_nrf_modem.elf 
[New Thread 57005]

Thread 2 received signal SIGTRAP, Trace/breakpoint trap.
[Switching to Thread 57005]
0xeffffffe in ?? ()

Note that this not happen in hello-world for instance. The modem flashing seemed to be successful.

@dylad
Copy link
Member Author

dylad commented Mar 2, 2022

That's weird, did you flash successfully the modem firmware before flashing the app ?
Could you also try to use nrfconnect tool ? There is a AppImage available on Linux to flash the firmware.
Maybe something is wrong with nrfjprog regarding modem firmware loading.

@leandrolanzieri
Copy link
Contributor

leandrolanzieri commented Mar 11, 2022

That's weird, did you flash successfully the modem firmware before flashing the app ?

I did, the process seemed fine.

Could you also try to use nrfconnect tool ? There is a AppImage available on Linux to flash the firmware. Maybe something is >wrong with nrfjprog regarding modem firmware loading.

I tried that but the application does not find my device, so I can't update the firmware with it

@dylad
Copy link
Member Author

dylad commented Mar 11, 2022

I tried that but the application does not find my device, so I can't update the firmware with it

I've almost done all the required changes, I'll retry the whole process on my hardware, squash and push ASAP.

dylad added 7 commits March 13, 2022 21:36
As this firmware is needed for proper nrf_modem operations, add it as pkg in dist/tools and provide a easy way to users for flashing it through nrfjprog as this is the only PROGRAMMER that can flash it.
As this package contains several features, currently limit it to nrf_modem as of now. Adding new features support can be made by create the appropriate Makefile and a pseudomodule.
This auto_init is board specific as some parameters pass through AT commands depends on hardware capabilities, thus this init should be at board level
@dylad dylad force-pushed the pr/pkg/nrf_modem_gnss_support branch from 84917bb to ac5ca06 Compare March 15, 2022 20:07
@github-actions github-actions bot added the Area: sys Area: System label Mar 15, 2022
@dylad
Copy link
Member Author

dylad commented Mar 15, 2022

@leandrolanzieri I've updated and squashed this PR, ready for second round of review.
I hope I've addressed all previous comments.

@aabadie
Copy link
Contributor

aabadie commented Apr 21, 2022

needs rebase

@benpicco benpicco requested a review from jnohlgard April 21, 2022 19:39
@stale
Copy link

stale bot commented Nov 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Nov 2, 2022
@benpicco benpicco mentioned this pull request Feb 10, 2023
5 tasks
@dylad dylad added State: don't stale State: Tell state-bot to ignore this issue and removed State: stale State: The issue / PR has no activity for >185 days labels Jun 30, 2023
@Teufelchen1
Copy link
Contributor

Hey hey,

@dylad can you do a rebase?
@leandrolanzieri you second review is still needed!

@dylad
Copy link
Member Author

dylad commented Mar 19, 2024

I took a quick glance at nrfxlib.
Looks like we're are now at nrf_modem v2.6 (this PR is using 1.3 !) so we can say this is severely outdated.
As of now, rebasing this PR makes no sense. It needs a rewrite.
Thus, I am closing it with the hope the come up with a new version at some point.

@dylad dylad closed this Mar 19, 2024
@dylad dylad removed the State: don't stale State: Tell state-bot to ignore this issue label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: build system Area: Build system Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: Kconfig Area: Kconfig integration Area: pkg Area: External package ports Area: sys Area: System Area: tests Area: tests and testing framework Area: tools Area: Supplementary tools Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants