-
Notifications
You must be signed in to change notification settings - Fork 2k
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
drivers/mrf24j40: Add mrf24j40 radio support #6277
Conversation
Just a site note: apparently the mail address you're using for your git commits seems not to be added to your GitHub profile. |
Thanks for the notice, should be fixed now |
Whoops, something went wrong there |
And some git stupidity of my own. Driver should be uncrustified and static check gives green on everything except a PR squash message |
@PeterKietzmann, you have the hardware in Hamburg, right? Any candidate for review and testing? |
Yes I have and Hauke should as well. The candidate is me but I can't promise to have an in-detail review and test until next Friday (feature freeze) |
Hi Folks, |
Yes, I also do have 2 of these somewhere in my drawer. So do I get this right, that this PR is an alternative (or even successor) of #5792? |
It's a successor. Wanted to give it a quick try tomorrow but as this needs adoptions to the SPI rework I assume it might be too late for this release. But the next hack'n'ack is coming and this driver has been on my todo list for so long. |
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.
Some minor style issues and simplifications
@@ -18,6 +18,19 @@ ifneq (,$(filter at86rf2%,$(USEMODULE))) | |||
endif | |||
endif | |||
|
|||
ifneq (,$(filter mrf24j40,$(USEMODULE))) | |||
USEMODULE += mrf24j40 |
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 line strikes me as quite useless...
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 that one is directly copied from the at86rf2% above it. While it makes sense there, it looks indeed useless here.
/** | ||
* @brief Maximum possible packet size in byte | ||
*/ | ||
#define MRF24J40_MAX_PKT_LENGTH (IEEE802154_FRAME_LEN_MAX) |
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.
Why redefine IEEE802154_FRAME_LEN_MAX
here?
*/ | ||
#define MRF24J40_DEFAULT_ADDR_SHORT (0x0230) | ||
#define MRF24J40_DEFAULT_ADDR_LONG (0x1222334455667788) | ||
/** @} */ |
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 use the newly (to be) introduced uuid
module for address generation -> #6314
#define MRF24J40_MIN_CHANNEL (IEEE802154_CHANNEL_MIN) | ||
#define MRF24J40_MAX_CHANNEL (IEEE802154_CHANNEL_MAX) | ||
#define MRF24J40_DEFAULT_CHANNEL (IEEE802154_DEFAULT_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.
again, IMHO no need to redefine, just use the IEEE802154 defines directly
#endif | ||
|
||
#define MRF24J40_PARAMS_DEFAULT { .spi = MRF24J40_PARAM_SPI, \ | ||
.spi_speed = MRF24J40_PARAM_SPI_SPEED, \ |
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.
indention one off
@@ -0,0 +1,16 @@ | |||
APPLICATION = driver_mrf24j40 |
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.
Though I appreciate the effort put into this test application, I tend to say we can savely drop it. Testing the driver would simply be:
- build the
examples/gnrc_networking
withUSEMODULE=mrf24j40 BOARD=BLBLBLBL make
- set/get options (addresses, channel, pan)
- send packets
- done
Or did I miss any additional functionality provided by this test app?
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.
It is basically the same driver test as the driver_at86rf2xx
test (so, not much effort). Since (I believe) the gnrc_networking
example also has a test on the link layer (the function called txtsnd
) I agree.
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.
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.
(also, if all other drivers are able to send via IP and not via mrf24j40
it is safe to assume that device is at fault ;-))
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.
So this test should be removed then?
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. Please remove it. One can use gnrc_networking
or default
. Later #5286 will unify these tests anyway.
I fixed the first set of issues. |
@bergzand that would be awesome in any way! But to have a realistic idea if this would make it into the release I will try to connect one until the afternoon |
@bergzand sorry I didn't make it yesterday but now I gave it a shot and I was pretty happy to see the state of the driver. I used |
cdd7012
to
dec8822
Compare
@PeterKietzmann Thank you for testing the driver.
The number of retransmissions is unfortunately not configurable. Blame Microchip for that one.
I just rebased the driver and added another commit applying the uuid implementations. Besides my node having a different (static) IPv6 address now, everything seems to work. I should have some time today to apply the SPI API change, but your call if you want to hurry things up or test a bit more before merging |
Test removed |
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.
@bergzand I added a bunch of comments. Mostly concerning style issues, probably not even introduced by you. However, now that you shepherd this, please adapt them. In addition it would be great if you scan over the code yourself because I didn't repeat to comment same errors multiple times.
Most likely we will postpone the feature freeze until Monday. In that case there is still some time to adapt this PR.
I will do further tests with this PR but I have a good feeling about it in general.
Before making new commits I propose to squash.
* @brief Interface definition for MRF24J40 based drivers | ||
* | ||
* @author neo@nenaco.de | ||
* @author koen@bergzand.net |
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.
The copyright above indicates that @TobiasFredersdorf was the (initial?) author of this file. Please make the copyright and authors clear. The authors line should include a name, -if you insist to stay anonymous take an alias- and a valid mail address
|
||
/** | ||
* @defgroup drivers_mrf24j40 MRF24J40 based drivers | ||
* @ingroup drivers_netdev |
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 use this group: drivers_netdev_netdev2
* @author koen@bergzand.net | ||
*/ | ||
|
||
#ifndef MRF24J40_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.
Here and everywhere else, please remove the trailing underscores as done in #6407
* | ||
* @return Number of retransmissions (3) | ||
*/ | ||
uint8_t mrf24j40_get_max_retries(mrf24j40_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.
Seems redundant as this parameter is not adjustable. But I won't stall this PR for that reason.
* | ||
* @param[in] dev device to read from | ||
* | ||
* @return the currently set (2-byte) short address |
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 functions below do not return errors or are not documented properly
netdev->event_callback(netdev, NETDEV2_EVENT_TX_COMPLETE); | ||
} | ||
} | ||
#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.
I assume the whole block from 546:566 is not only relevant for netstats?
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 assumed it was irrelevant since in sys/net/gnrc/link_layer/netdev2/gnrc_netdev2.c
the switch statement also has the same ifdef around the handlers of those callback options (sys/net/gnrc/link_layer/netdev2/gnrc_netdev2.c 76:83. If you want the ifdef removed or minimized, I'm okay with that, but as it is now, it saves an SPI transfer when L2 stats are not enabled and I would like to keep that
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.
@bergzand thanks for the explanation. Leave it as is for now. Probably I will come back to you on that point.
netdev->event_callback(netdev, NETDEV2_EVENT_RX_COMPLETE); | ||
} | ||
dev->pending &= ~(MRF24J40_TASK_RX_READY); | ||
} // end of RXIF check |
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.
Comment style
#endif | ||
|
||
} | ||
/* RECEIVE INTERRUPT OCCURED */ |
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.
why capitaly?
* @file | ||
* @brief Auto initialization for mrf24j40 network interfaces | ||
* | ||
* @author <neo@nenaco.de> |
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.
Copyright and author?
* @{ | ||
*/ | ||
#define MRF24J40_MAC_STACKSIZE (THREAD_STACKSIZE_DEFAULT) | ||
#define MRF24J40_MAC_PRIO (THREAD_PRIORITY_MAIN - 4) |
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 use
#ifndef MRF24J40_MAC_PRIO
#define MRF24J40_MAC_PRIO (GNRC_NETDEV2_MAC_PRIO)
#endif
97b991d
to
acb85e4
Compare
@bergzand that's great. Thanks a lot! Now we 'only' have to wait for SPI but this one is just the next in the queue. |
87cf8e4
to
2dc914c
Compare
Rebased after the merge of #4780 |
@bergzand wow that was fast :-)! I will give it a last try tomorrow (don't have the hardware with me). @haukepetersen please dismiss your change request. Has been addressed. |
I noticed the SPI API merge fast due to an email notification, and a rebase+push is not that much work. :-) I've added a check to the initialization function so that when debugging is enabled in |
I can't get it running any more. No time to debug now but it must be that the program hangs before main() starts. Besides of that, please squash you commits to one. The first commit message looks fine. |
BTW: It is -as you expected- that the SPI communication during |
Squashed. @PeterKietzmann With my current setup (nucleo-f401 with an mrf24j40), I have to call |
That function is already called here. Tried your last step anyway but w/o success |
by the way, the handling of the
Seems like this has been copied in parts from the very bad example of the |
Also the SPI bus is used quite inefficient -> the bus is 'acquired' for every single transfer. Ideally, this should be done only once for each block of transfers, e.g. 'acquire' bus access at the beginning of the initialization or a packet transfer and release it only after the initialization of the packet transfer is complete... |
Initial work has been done by students and yes, the atmel driver acted as a start point for that. @bergzand was so nice to take this PR over. However, we can clean up that driver afterwards (if we want to) but in case we can get this running with the SPI rework in the next 1-2 hours I'd vote for taking this PR in. |
Just wanted to state my concerns, I don't see them as blocker for this PR... Regarding the 'not-working' state, I can't see anything in the code. But I don't have my device here so that I can help debugging. Have you tried running it with different boards? |
@haukepetersen thank you for your recommendations. I would prefer solving the issues after this PR, unless you consider them blocking for this PR. I would not be suprised if there are some bad practices copied from the at86rf2xx by me or @Nenaco. If you could create issues for them and assign them to me, I can solve them as soon as i've got time for them. |
@bergzand: I don't see them as blocker and they might as well be addressed in follow-up PR(s). |
Allright. After I figured out that nucelo-l1 boards are buggy, I can't flash my stm32f0discovery any more, this implementation does not work with stm32f4 and stm32f3 discovery I tried the the samr21-xpro, pulling out the dependency to the |
Ok I will merge this now. Already added it to the list in #6437. Please help making this driver work with the STM32Fx boards again. Feature freeze will be announces soon. Fixes should be backported to the release branches then. Don't forget! |
@PeterKietzmann Is it possible for you to check whether this is an issue with the mrf24j40 module or that the SPI module with the STM32Fx boards is broken somehow? I currently run the code from this PR on both a nucleo-f401 (stm32f401RE) and a maple-mini (stm32f103) so I would really like to know if I can reproduce your error. Could this be Nucleo-L1 specific? Furthermore, maybe the problem on the stm32f4 is caused by #6460. |
Actually, it might be, that there is something buggy in the STMs SPI driver (though I wonder how that happened after our extensive testing sessions for the new SPI driver): @kaspar030 was running into trouble today also, when testing the |
@bergzand do you have a stm32f4discovery board available? I gave it a try again after #6492 was merged but still hangs somewhere during initialization. The radio works as expected with an Atmel samr21-xpro and stand-alone SPI and GPIO look fine on a stm32f4disco board. My configuration is:
|
@PeterKietzmann I've borrowed an stm32f4discovery from a friend and I couldn't get it to work either. It seems that it passes the communications check, but hangs when trying a rf state machine. Can you confirm that in your case it also hangs in a loop at https://github.com/RIOT-OS/RIOT/blob/master/drivers/mrf24j40/mrf24j40_getset.c#L476 ? |
This patch collection adds support for the mrf24j40 radio from microchip.
supported:
not supported:
As visible in the commits, this PR builds on the initial work of @Nenaco, but the whole driver logic is rewritten to prevent a deadlock. I hope I've fixed most of the comments from the original PR ( #5792).