-
Notifications
You must be signed in to change notification settings - Fork 2.1k
drivers/sx127x: rework of implementations from #6645 and #6002 #6797
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
Conversation
925d23a
to
2026c0c
Compare
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.
drivers/include/sx127x.h
Outdated
* @brief SX127X LoRa configuration | ||
* @{ | ||
*/ | ||
#define RF_FREQUENCY (915000000UL) /**< RF frequency in Hz, 868.9MHz */ |
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.
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.
drivers/include/sx127x.h
Outdated
#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 */ |
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.
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 (?)
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.
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.
drivers/include/sx127x.h
Outdated
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; |
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.
Could you give a hint what the I/O lines are used for?
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.
done
* @ingroup drivers_sx127x | ||
* @{ | ||
* @file | ||
* @brief Semtech SX1276 internal functions |
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.
127x
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.
... and following
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.
fixed
|
||
#ifndef SX127X_PARAM_DIO3 | ||
#define SX127X_PARAM_DIO3 GPIO_PIN(1, 4) /* D5 */ | ||
#endif |
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.
All needed?
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.
yes
drivers/sx127x/sx127x_getset.c
Outdated
|
||
uint16_t sx127x_get_preamble_length(sx127x_t *dev) | ||
{ | ||
return 0; |
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.
Preamble length always 0
?
drivers/sx127x/sx127x_getset.c
Outdated
|
||
void sx127x_set_rx_timeout(sx127x_t *dev, uint32_t timeout) | ||
{ | ||
dev->settings.window_timeout = timeout; |
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.
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. */ |
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.
Just out of interest, what do we need this mode for?
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.
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 ?
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.
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
sys/include/net/netopt.h
Outdated
NETOPT_LORA_MAX_PAYLOAD, /**< Maximum payload size */ | ||
NETOPT_LORA_RANDOM, /**< Random value */ | ||
NETOPT_LORA_TIME_ON_AIR, /**< Time on air */ | ||
|
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.
I don't have a solution at hand but I'm wondering if we need/want all these options as generic netopts.
tests/driver_sx127x/main.c
Outdated
// default: | ||
// break; | ||
// } | ||
//} |
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.
This is not so nice.
@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. |
@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. |
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.
Small fixes I saw when testing your PR ;)
drivers/include/sx127x.h
Outdated
* @param[in] dev The sx127x device descriptor | ||
* @return the LoRa implicit mode | ||
*/ | ||
bool sx12376_get_implicit_mode(sx127x_t *dev); |
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.
sx127x
tests/driver_sx127x/README.md
Outdated
|
||
# Usage | ||
To setup bandwidth parameters, use lora_setup | ||
To change frequency, go to common.h |
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.
I think common.h is a legacy from #6002
tests/driver_sx127x/main.c
Outdated
return 0; | ||
} | ||
|
||
int config_channel_cmd(int argc, char **argv) |
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.
I think we need more verbose for this one
For example we need to set a random argv[1] to set a channel
Thanks for the effort to put these pieces together. Will check that on my SX1276 boards soon. |
d9ec5ca
to
17332c1
Compare
@PeterKietzmann, @Cr0s, @dylad thanks for your comments. I also refactored a bit the test application. |
3c1cb1e
to
1668db8
Compare
@PeterKietzmann @dylad did you find time for some tests ? |
@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... |
Unfortunately not. I have 2 x SX1276MB1MAS and 2 x P-NUCLEO-LRWAN1. No SX1272RF1BAS, sorry. |
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). |
@aabadie 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 ?) (SX127X_REG_LR_MODEMCONFIG3 exists for SX1276 but is reserved for SX1272). So several functions cannot work for SX1272 chip like It may have others registers differents but I didn't have much time to investigate further. |
@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. |
@dylad thanks for spotting those differences. I'll look into that. |
drivers/sx127x/sx127x.c
Outdated
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); |
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.
@aabadie Could you add some verbose if those pins are successfully init or not please ?
I had some surprises with this.
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.
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.
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.
Out of curiosity, what are the surprises you had ?
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.
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.
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.
One minor grammatical error left ;-)
drivers/include/sx127x.h
Outdated
@@ -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 |
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.
"Checks"
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.
remaining nit fixed. @dylad please ACK :) |
@aabadie in the meantime you may squash :-). |
squashed |
Somehow my review was not dismissed.... Trying it again
Note : our bug may not be related to RIOT or even to software but nevermind I had to track it and patch it. |
ACK now or monday, what do you prefer ?Now ;)Otherwise, we'll have to postpone and it won't be merged before mid-July at best.I'll announce feature freeze later today or during the week-end.By the way, we retested again with @adjih and it was all good.
|
If we can merged now let's do this ! ACK on my side. |
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.
Proxy-ACK
🎉 We made it |
Can't believe it's merged :) Many thanks to all people involved. Next step is LoraWAN adaption. |
🍻 |
|
Congrats to all involved! |
*/ | ||
typedef struct netdev_radio_lora_packet_info { | ||
uint8_t rssi; /**< RSSI of a received packet */ | ||
uint8_t lqi; /**< LQI of a received packet */ |
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.
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?
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.
indeed it shouldn't be here. I will fix it, since I require it for #11022
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.