Skip to content

Conversation

aabadie
Copy link
Contributor

@aabadie aabadie commented Mar 27, 2017

This PR is a rework of the initial SX1276 driver implementation from #6002 that was adapted by @jia200x in #6645.

The idea here is to make it ready for merge as fast as possible (targeting the coming release).

While adapting, I added basic support for SX1272, hence the driver name is changed to sx127x. I also kept the netdev adaptation.

I dropped the lorawan adaptation from #6645 because I think this should be provided as an external package (but maybe I'm wrong) and in a follow-up PR.

Note that I open this PR without heavy testing of the code (I don't have sx1276, only sx1272).

This is the hardware I have.

@aabadie aabadie added Area: drivers Area: Device drivers Type: new feature The issue requests / The PR implemements a new feature for RIOT labels Mar 27, 2017
@aabadie aabadie added this to the Release 2017.04 milestone Mar 27, 2017
@aabadie aabadie force-pushed the driver_sx127x branch 2 times, most recently from 925d23a to 2026c0c Compare March 31, 2017 10:44
Copy link
Member

@PeterKietzmann PeterKietzmann left a comment

Choose a reason for hiding this comment

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

@Cr0s, @jia200x, @aabadie thanks for all your great work. Please answer/address my comments. This is a quite big PR and I think it needs further iterations of review and testing. Until now I did not run tests but I already got my 1272 and 1276 shields.

* @brief SX127X LoRa configuration
* @{
*/
#define RF_FREQUENCY (915000000UL) /**< RF frequency in Hz, 868.9MHz */
Copy link
Member

Choose a reason for hiding this comment

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

Definition and doc not consistent. Maybe we should be able to overwrite this parameter? Especially when looking at the sx1276 which hast two different mudulation frequencies.

#define SX127X_RADIO_WAKEUP_TIME (1000U) /**< [us] */
#define SX127X_RX_BUFFER_SIZE (256) /**< RX buffer size */
#define SX127X_RF_MID_BAND_THRESH (525000000UL) /**< Mid-band threshold */
#define SX127X_CHANNEL_HF (868000000UL) /**< HF channel */
Copy link
Member

Choose a reason for hiding this comment

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

I'm yet not too familiar with that device. How does this parameter correlate to the RF frequency? Also here we should consider other frequencies/channels (?)

Copy link

Choose a reason for hiding this comment

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

SX127x has some kind of differentiation for so-called High and Low-frequency bands. There is a two different matching network layouts are required for both of the bands and two different outputs for each of them are implemented in a device. So we have to differentiate Low (below 868 MHz) and High modes in software by currently used channel frequency to correctly setup device's registers and use correct output that is dependent on a current channel frequency.

gpio_t dio3_pin; /**< Interrupt line DIO3 */
gpio_t dio4_pin; /**< Interrupt line DIO4 (not used) */
gpio_t dio5_pin; /**< Interrupt line DIO5 (not used) */
} sx127x_params_t;
Copy link
Member

Choose a reason for hiding this comment

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

Could you give a hint what the I/O lines are used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

* @ingroup drivers_sx127x
* @{
* @file
* @brief Semtech SX1276 internal functions
Copy link
Member

Choose a reason for hiding this comment

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

127x

Copy link
Member

Choose a reason for hiding this comment

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

... and following

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


#ifndef SX127X_PARAM_DIO3
#define SX127X_PARAM_DIO3 GPIO_PIN(1, 4) /* D5 */
#endif
Copy link
Member

Choose a reason for hiding this comment

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

All needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes


uint16_t sx127x_get_preamble_length(sx127x_t *dev)
{
return 0;
Copy link
Member

Choose a reason for hiding this comment

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

Preamble length always 0?


void sx127x_set_rx_timeout(sx127x_t *dev, uint32_t timeout)
{
dev->settings.window_timeout = timeout;
Copy link
Member

Choose a reason for hiding this comment

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

Just by the name of the function I would have assumed rx_timeout to be set.

@@ -277,6 +300,8 @@ typedef enum {
* transmitting a packet */
NETOPT_STATE_RESET, /**< triggers a hardware reset. The resulting
* state of the network device is @ref NETOPT_STATE_IDLE */
NETOPT_STATE_STANDBY, /**< standby mode. The devices is awake but
* not listening to packets. */
Copy link
Member

Choose a reason for hiding this comment

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

Just out of interest, what do we need this mode for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is because the SX127x transceivers can be put in sleep mode and not listening to incoming packets. I guess this is one potential reason. @jia200x why did you add this ?

Copy link
Member

Choose a reason for hiding this comment

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

Hi, I'm back.
There's a standby mode in LoRa (is not the same as Sleep, the crystal oscillator is still running but doesn't receive packets). It's part of the RX-SINGLE workflow (after an rx timeout, the SX127X automatically goes back to standby, so shouldn't be ignored).

Cheers

NETOPT_LORA_MAX_PAYLOAD, /**< Maximum payload size */
NETOPT_LORA_RANDOM, /**< Random value */
NETOPT_LORA_TIME_ON_AIR, /**< Time on air */

Copy link
Member

Choose a reason for hiding this comment

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

I don't have a solution at hand but I'm wondering if we need/want all these options as generic netopts.

// default:
// break;
// }
//}
Copy link
Member

Choose a reason for hiding this comment

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

This is not so nice.

@aabadie
Copy link
Contributor Author

aabadie commented Apr 3, 2017

@PeterKietzmann thanks for the review, I'll try to address the comments. They all make a lot of sense.

FYI, the test application doesn't work as expected : I see some activity on the other side but no packet received yet.

@aabadie
Copy link
Contributor Author

aabadie commented Apr 3, 2017

@PeterKietzmann, I made small progress today : I can send and receive packet between 2 SX1272 modules. I need to cleanup the branch before pushing though.

Copy link
Member

@dylad dylad left a comment

Choose a reason for hiding this comment

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

Small fixes I saw when testing your PR ;)

* @param[in] dev The sx127x device descriptor
* @return the LoRa implicit mode
*/
bool sx12376_get_implicit_mode(sx127x_t *dev);
Copy link
Member

Choose a reason for hiding this comment

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

sx127x


# Usage
To setup bandwidth parameters, use lora_setup
To change frequency, go to common.h
Copy link
Member

Choose a reason for hiding this comment

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

I think common.h is a legacy from #6002

return 0;
}

int config_channel_cmd(int argc, char **argv)
Copy link
Member

Choose a reason for hiding this comment

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

I think we need more verbose for this one
For example we need to set a random argv[1] to set a channel

@Cr0s
Copy link

Cr0s commented Apr 4, 2017

Thanks for the effort to put these pieces together. Will check that on my SX1276 boards soon.

@aabadie aabadie force-pushed the driver_sx127x branch 2 times, most recently from d9ec5ca to 17332c1 Compare April 4, 2017 11:37
@aabadie
Copy link
Contributor Author

aabadie commented Apr 4, 2017

@PeterKietzmann, @Cr0s, @dylad thanks for your comments.
I just pushed a new branch (force push sorry) where I tried to address the required changes. At least the static tests pass locally and I can exchange messages between 2 modules.

I also refactored a bit the test application.

@aabadie aabadie force-pushed the driver_sx127x branch 2 times, most recently from 3c1cb1e to 1668db8 Compare April 5, 2017 17:08
@aabadie
Copy link
Contributor Author

aabadie commented Apr 6, 2017

@PeterKietzmann @dylad did you find time for some tests ?

@dylad
Copy link
Member

dylad commented Apr 6, 2017

@aabadie I plan to do some tests tomorrow I'll let you know.

BTW, I would like to know if someone has a SX1272RF1BAS board ? I would like to check something...

@PeterKietzmann
Copy link
Member

Unfortunately not. I have 2 x SX1276MB1MAS and 2 x P-NUCLEO-LRWAN1. No SX1272RF1BAS, sorry.

@aabadie
Copy link
Contributor Author

aabadie commented Apr 7, 2017

rebased.

@PeterKietzmann, do you plan to port RIOT to the P-NUCLEO-LRWAN1 ? It will be great and not so difficult I think (stm32l0 are supported by RIOT).

@dylad
Copy link
Member

dylad commented Apr 7, 2017

@aabadie
I did some tests today with my boards but I have (maybe ?) a problem with my SX1272RF1 board. There are old and it seems their revision is not 0x22 (from reg 0x42) because there are engineering sample released long ago. So it supposed to work but without any warranty.

I tried to exchange messages with one SX1276-based board and one of my old SX1272 and It didn't work. (Maybe because my samples are old ?)
But, I found out SX127X_REG_LR_MODEMCONFIG 1&2 are different for SX1272 and SX1276

(SX127X_REG_LR_MODEMCONFIG3 exists for SX1276 but is reserved for SX1272). So several functions cannot work for SX1272 chip like sx127x_set_bandwidth.

It may have others registers differents but I didn't have much time to investigate further.
EDIT: fix typos

@PeterKietzmann
Copy link
Member

@aabadie I'm a bit confused. Actually I thought that you are working with that shield (based on your comment here).

@aabadie
Copy link
Contributor Author

aabadie commented Apr 7, 2017

@PeterKietzmann, sorry, you are right, those are the ones I have... I was thinking of this board: B-L072Z-LRWAN1. This one is very interesting for porting RIOT on.

@aabadie
Copy link
Contributor Author

aabadie commented Apr 7, 2017

@dylad thanks for spotting those differences. I'll look into that.
Testing the communication between the 2 different types (SX1272 and SX1276) is also a good test for interop.

gpio_init_int(dev->params.dio0_pin, GPIO_IN, GPIO_RISING, sx127x_on_dio0_isr, dev);
gpio_init_int(dev->params.dio1_pin, GPIO_IN, GPIO_RISING, sx127x_on_dio1_isr, dev);
gpio_init_int(dev->params.dio2_pin, GPIO_IN, GPIO_RISING, sx127x_on_dio2_isr, dev);
gpio_init_int(dev->params.dio3_pin, GPIO_IN, GPIO_RISING, sx127x_on_dio3_isr, dev);
Copy link
Member

Choose a reason for hiding this comment

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

@aabadie Could you add some verbose if those pins are successfully init or not please ?
I had some surprises with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just pushed a commit @dylad. With ST MCU, the gpio_init_int always return 0 so it won't be helpful. I guess your are trying with a SAMD21 ? Also don't forget to set ENABLE_DEBUG (1) at the beginning of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Out of curiosity, what are the surprises you had ?

Copy link
Member

Choose a reason for hiding this comment

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

Many thanks @aabadie !
I used a SAML21 and I set PA08 as DIO0 without looking and of course..., I just found out PA08 can't be used as external interrupt.
I'll retest tomorrow (if possible) with another pin.

miri64
miri64 previously requested changes Jun 30, 2017
Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

One minor grammatical error left ;-)

@@ -545,7 +545,7 @@ uint8_t sx127x_get_coding_rate(const sx127x_t *dev);
void sx127x_set_coding_rate(sx127x_t *dev, uint8_t coderate);

/**
* @brief Check is the SX127X LoRa RX single mode is enabled/disabled
* @brief Check if the SX127X LoRa RX single mode is enabled/disabled
Copy link
Member

Choose a reason for hiding this comment

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

"Checks"

@miri64 miri64 dismissed their stale review June 30, 2017 16:44

Apart from the (minor) error, I'm fine with merging. Since I can not test I dismiss my review and leave the ACK to @dylad (I may proxy-ACK if they ACK'd). Please squash.

@aabadie
Copy link
Contributor Author

aabadie commented Jun 30, 2017

remaining nit fixed. @dylad please ACK :)

@miri64
Copy link
Member

miri64 commented Jun 30, 2017

@aabadie in the meantime you may squash :-).

@aabadie
Copy link
Contributor Author

aabadie commented Jun 30, 2017

squashed

@miri64 miri64 dismissed their stale review June 30, 2017 17:16

Somehow my review was not dismissed.... Trying it again

@dylad
Copy link
Member

dylad commented Jun 30, 2017

in fact what you are trying to do is not legal
@aabadie you're perfectly right and I know the EU regulation but I'm testing ;)
To tell you the truth, I'm currently digging into my code to spot a potential LoRa rx issue which kills reception.
I'm tracking a bug that I'm unable to reproduce at my company place but it seldom happens at my client's place. We're still not sure where the bug is located but I'm investigating. I would like to flood in reception one of our nodes to simulate a dense urban area using radio to check if I can create possible issue on reception.

Note : our bug may not be related to RIOT or even to software but nevermind I had to track it and patch it.

@dylad
Copy link
Member

dylad commented Jun 30, 2017

@aabadie @miri64
Sorry I cannot re-test the last commit right now. Best I can do is monday evening.
My last test was fine and I like the recent changes.
ACK now or monday, what do you prefer ? :)

@aabadie
Copy link
Contributor Author

aabadie commented Jun 30, 2017 via email

@miri64
Copy link
Member

miri64 commented Jun 30, 2017

@aabadie then let @adjih ACK ;-)

@aabadie
Copy link
Contributor Author

aabadie commented Jun 30, 2017 via email

@miri64
Copy link
Member

miri64 commented Jun 30, 2017

I think I'll postpone this one finally...

Why is @adjih already gone? Then I'll proxy-ACK for both @adjih and @dylad... Two witnesses except you of a working device make me confident enough.

@dylad
Copy link
Member

dylad commented Jun 30, 2017

If we can merged now let's do this ! ACK on my side.

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

Proxy-ACK

@miri64 miri64 merged commit d61be01 into RIOT-OS:master Jun 30, 2017
@miri64
Copy link
Member

miri64 commented Jun 30, 2017

🎉 We made it

@dylad
Copy link
Member

dylad commented Jun 30, 2017

Great news ! It was a very long way to go ;)
BTW, you can safely close #6002 (dunno for #6645)

@aabadie
Copy link
Contributor Author

aabadie commented Jun 30, 2017

Can't believe it's merged :)

Many thanks to all people involved. Next step is LoraWAN adaption.

@aabadie
Copy link
Contributor Author

aabadie commented Jun 30, 2017

🍻

@dylad
Copy link
Member

dylad commented Jun 30, 2017

Next step is LoraWAN adaption. 👍
Let's do it !

@emmanuelsearch
Copy link
Member

Congrats to all involved!

@aabadie aabadie mentioned this pull request Jun 30, 2017
5 tasks
@aabadie aabadie deleted the driver_sx127x branch February 26, 2018 12:22
*/
typedef struct netdev_radio_lora_packet_info {
uint8_t rssi; /**< RSSI of a received packet */
uint8_t lqi; /**< LQI of a received packet */
Copy link
Member

Choose a reason for hiding this comment

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

I just had a look at this code again due to an unrelated issue I discussed with @kYc0o, so sorry for the "late review" ;-).

In the recv() function of this driver it says that LoRA has no LQI, so why is it in this struct?

Copy link
Member

Choose a reason for hiding this comment

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

indeed it shouldn't be here. I will fix it, since I require it for #11022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR 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.