-
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: add kw41zrf #12277
drivers: add kw41zrf #12277
Conversation
@Ilmu011 mind to review the code? You could test it as well on a new phytec board or the kw41 mini |
Originally posted by @benemorius in #10364
Isn't this still the case? |
No I resolved that by having |
@benemorius the PR is big. Could you indicate the fix next to the code? |
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.
At a first glance, the code looks good.
I tested the driver with a kw41z-mini. There are two other nodes with a mrf24j40 radio.
However, I have trouble receiving on the kw41z-mini:
kw41z-mini
2019-10-11 22:11:25,201 # Iface 7 HWaddr: 6D:56 Channel: 26 Page: 0 NID: 0x23
2019-10-11 22:11:25,202 # Long HWaddr: 23:64:63:2B:62:41:6D:56
2019-10-11 22:11:25,205 # TX-Power: 0dBm State: IDLE max. Retrans.: 3 CSMA Retries: 4
2019-10-11 22:11:25,206 # ACK_REQ CSMA L2-PDU:102 MTU:1280 HL:64 RTR
2019-10-11 22:11:25,207 # 6LO IPHC
2019-10-11 22:11:25,208 # Source address length: 8
2019-10-11 22:11:25,209 # Link type: wireless
2019-10-11 22:11:25,211 # inet6 addr: fe80::2164:632b:6241:6d56 scope: local VAL
2019-10-11 22:11:25,212 # inet6 group: ff02::2
2019-10-11 22:11:25,213 # inet6 group: ff02::1
2019-10-11 22:11:25,242 # inet6 group: ff02::1:ff41:6d56
2019-10-11 22:11:25,243 # inet6 group: ff02::1a
2019-10-11 22:11:25,243 #
2019-10-11 22:11:25,244 # Statistics for Layer 2
2019-10-11 22:11:25,245 # RX packets 9 bytes 359
2019-10-11 22:11:25,247 # TX packets 5 (Multicast: 5) bytes 201
2019-10-11 22:11:25,248 # TX succeeded 5 errors 0
2019-10-11 22:11:25,249 # Statistics for IPv6
2019-10-11 22:11:25,250 # RX packets 5 bytes 291
2019-10-11 22:11:25,251 # TX packets 5 (Multicast: 5) bytes 306
2019-10-11 22:11:25,251 # TX succeeded 5 errors 0
2019-10-11 22:11:25,251 #
udp server start 1111
2019-10-11 22:11:50,944 # udp server start 1111
2019-10-11 22:11:50,945 # Success: started UDP server on port 1111
> ping6 ff02::1
2019-10-11 22:12:02,017 # ping6 ff02::1
2019-10-11 22:12:05,003 #
2019-10-11 22:12:05,025 # --- ff02::1 PING statistics ---
2019-10-11 22:12:05,027 # 3 packets transmitted, 0 packets received, 100% packet loss
> ping6 fe80::2123:2323:2323:2322
2019-10-11 22:12:11,650 # ping6 fe80::2123:2323:2323:2322
2019-10-11 22:12:14,665 #
2019-10-11 22:12:14,666 # --- fe80::2123:2323:2323:2322 PING statistics ---
2019-10-11 22:12:14,668 # 3 packets transmitted, 0 packets received, 100% packet loss
> udp send fe80::2123:2323:2323:2322 2222 Hello
2019-10-11 22:12:26,280 # udp send fe80::2123:2323:2323:2322 2222 Hello
2019-10-11 22:12:26,296 # Success: sent 5 byte(s) to [fe80::2123:2323:2323:2322]:2222
ek-lm4f120xl_mrf24j40
2019-10-11 22:11:29,505 # Iface 7 HWaddr: 23:22 Channel: 26 Page: 0 NID: 0x23
2019-10-11 22:11:29,509 # Long HWaddr: 23:23:23:23:23:23:23:22
2019-10-11 22:11:29,515 # TX-Power: 0dBm State: IDLE max. Retrans.: 3 CSMA Retries: 4
2019-10-11 22:11:29,521 # ACK_REQ CSMA L2-PDU:102 MTU:1280 HL:64 RTR
2019-10-11 22:11:29,522 # 6LO IPHC
2019-10-11 22:11:29,526 # Source address length: 8
2019-10-11 22:11:29,528 # Link type: wireless
2019-10-11 22:11:29,534 # inet6 addr: fe80::2123:2323:2323:2322 scope: local VAL
2019-10-11 22:11:29,537 # inet6 group: ff02::2
2019-10-11 22:11:29,540 # inet6 group: ff02::1
2019-10-11 22:11:29,543 # inet6 group: ff02::1:ff23:2322
2019-10-11 22:11:29,546 # inet6 group: ff02::1a
2019-10-11 22:11:29,547 #
2019-10-11 22:11:29,550 # Statistics for Layer 2
2019-10-11 22:11:29,553 # RX packets 6 bytes 244
2019-10-11 22:11:29,557 # TX packets 4 (Multicast: 4) bytes 158
2019-10-11 22:11:29,560 # TX succeeded 4 errors 0
2019-10-11 22:11:29,563 # Statistics for IPv6
2019-10-11 22:11:29,566 # RX packets 6 bytes 370
2019-10-11 22:11:29,570 # TX packets 4 (Multicast: 4) bytes 242
2019-10-11 22:11:29,574 # TX succeeded 4 errors 0
2019-10-11 22:11:29,574 #
> udp server start 2222
2019-10-11 22:11:56,725 # udp server start 2222
2019-10-11 22:11:56,728 # Success: started UDP server on port 2222
> 2019-10-11 22:12:26,283 # PKTDUMP: data received:
2019-10-11 22:12:26,288 # ~~ SNIP 0 - size: 5 byte, type: NETTYPE_UNDEF (0)
2019-10-11 22:12:26,291 # 00000000 48 65 6C 6C 6F
2019-10-11 22:12:26,295 # ~~ SNIP 1 - size: 8 byte, type: NETTYPE_UDP (4)
2019-10-11 22:12:26,298 # src-port: 2222 dst-port: 2222
2019-10-11 22:12:26,300 # length: 13 cksum: 0xeef1
2019-10-11 22:12:26,305 # ~~ SNIP 2 - size: 40 byte, type: NETTYPE_IPV6 (2)
2019-10-11 22:12:26,309 # traffic class: 0x00 (ECN: 0x0, DSCP: 0x00)
2019-10-11 22:12:26,311 # flow label: 0x00000
2019-10-11 22:12:26,314 # length: 13 next header: 17 hop limit: 64
2019-10-11 22:12:26,318 # source address: fe80::2164:632b:6241:6d56
2019-10-11 22:12:26,322 # destination address: fe80::2123:2323:2323:2322
2019-10-11 22:12:26,327 # ~~ SNIP 3 - size: 24 byte, type: NETTYPE_NETIF (-1)
2019-10-11 22:12:26,329 # if_pid: 7 rssi: -35 lqi: 117
2019-10-11 22:12:26,330 # flags: 0x0
2019-10-11 22:12:26,334 # src_l2addr: 23:64:63:2B:62:41:6D:56
2019-10-11 22:12:26,336 # dst_l2addr: 23:23:23:23:23:23:23:22
2019-10-11 22:12:26,340 # ~~ PKT - 4 snips, total size: 77 byte
ping6 ff02::1
2019-10-11 22:12:39,660 # ping6 ff02::1
2019-10-11 22:12:39,676 # 12 bytes from fe80::686a:5673:a259:c87e: icmp_seq=0 ttl=64 rssi=-38 dBm time=9.303 ms # this is the blackpill-128_mrf24j40
2019-10-11 22:12:40,676 # 12 bytes from fe80::686a:5673:a259:c87e: icmp_seq=1 ttl=64 rssi=-38 dBm time=8.656 ms
2019-10-11 22:12:41,676 # 12 bytes from fe80::686a:5673:a259:c87e: icmp_seq=2 ttl=64 rssi=-38 dBm time=8.984 ms
2019-10-11 22:12:41,676 #
2019-10-11 22:12:41,678 # --- ff02::1 PING statistics ---
2019-10-11 22:12:41,684 # 3 packets transmitted, 3 packets received, 0% packet loss
2019-10-11 22:12:41,688 # round-trip min/avg/max = 8.656/8.981/9.303 ms
> udp send fe80::2164:632b:6241:6d56 1111 Test
2019-10-11 22:12:54,030 # udp send fe80::2164:632b:6241:6d56 1111 Test
2019-10-11 22:12:54,036 # Success: sent 4 byte(s) to [fe80::2164:632b:6241:6d56]:1111
@benemorius thanks for taking over @gebart PR, its been a long awaited FEATYRE, it would be really nice to see this driver in soon. @benpicco seemed to have some initial issues, but If you have time to go back to this PR I can help with testing as well and figure out how to push this forward. |
I noticed finally that CSMA was causing a serious bug with this. Actually, anytime the radio tries to backoff and retransmit, it ends up stuck not receiving until after the next time it transmits (supposing it doesn't need CSMA that time too). So it's worse than just not having CSMA. It's been the cause of a lot of unexpectedly silent nodes for me. In fact disabling CSMA like I tried rather hard to get the hardware CSMA in the radio working as intended but I can't get the transmission to begin any time other than immediately. The reference manual isn't the most efficient. Instead I've implemented software CSMA in the driver. This seems to have resolved the silent nodes I used to get from leaving CSMA turned on. I'm getting the refactoring cleaned up and then I'll push an update. |
kw41r-mini is merged, please rebase |
7c114fe
to
44d2cfa
Compare
rebased |
Now this is getting weird. But the thing is it would receive packets with the RIOT firmware that came with the board ( |
@benpicco can you try the latest commit? I was able to reproduce failed packet reception only on the gcc that ships with raspbian. I think you found the bug I once had and was looking for but couldn't remember the details of. For me the latest commit fixes it. |
That fixes it indeed - RX is working now! |
FYI: netif |
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.
First round of review, looks pretty good!
Just something strange I've noticed: when I run the examples/gnrc_border_router
example on a second node (samr21-xpro
), the kw41z-mini
won't get a public IP while other nodes (e.g. avr-rss2
or openmote-b
) do.
I can ping the link-local address of the border router and I can ping the link-local address of the kw41z-mini
just fine, it also answers to broadcast ping and fragmented pings, so this is odd.
Especially since with the original 2019.10-devel-148-g0d867-cleanthismess
image this is working, but not with your telnet-shell
branch.
drivers/kw41zrf/kw41zrf_netdev.c
Outdated
if (num_irqs_queued == num_irqs_handled) { | ||
++num_irqs_queued; |
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 quite get this dance - can num_irqs_queued
ever be something other an 0
or 1
?
I think a atomic_bool
or atomic_int
would work here as well.
drivers/kw41zrf/kw41zrf_xcvr.c
Outdated
/* The implementations for these functions are taken from the vendor provided XCVR | ||
* driver from NXP MCUXpresso. The code has been refactored to eliminate a lot | ||
* of preprocessor conditionals. */ |
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.
Do you still know which version of MCUXpresso this was taken from?
Unless by necessity it's usually a bad idea to modify the vendor files, since it makes updating them impossible.
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 certainly agree in general. My understanding from reading the dialog in #7107 is that this was necessary or at least prohibitively inconvenient to avoid.
The version (which I can't confirm personally) is mentioned in the PR only. I'll add it to this comment.
Ok so you're saying that with a Is the
I've cleaned up my local branch finally and now |
Yes, that's the observation.
I'm using
There are some nice goodies in that branch! I'm keen on that telnet server and ZBoss pkg, but also small fixes like 9b20f53 would be nice to have upstream 😉 |
I used this PR to test #13486 on a
|
@fjmolinas what compiler did you use? |
|
I could try with |
Works for me when built in docker as well. |
I'm able to reproduce the behavior where ping works but no public IP address appears. It's because the router solicitations are coming out malformed for some reason. I can reproduce it with this compiler:
I can't reproduce it with the compiler I use normally:
|
@benpicco can you try the latest commit? Once again the workaround was to convert a |
Yes that fixes it indeed! |
This driver is looking pretty good now - but using |
I changed it to use |
drivers/kw41zrf/kw41zrf_netdev.c
Outdated
|
||
if (!spinning_for_irq) { | ||
irq_is_queued = false; | ||
if (!blocking_for_irq) { | ||
thread_flags_clear(KW41ZRF_THREAD_FLAG_ISR); |
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 blocking_for_irq
is set when this function gets called from kw41zrf_wait_idle()
- when are those flags then cleared?
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.
After looking at it I don't think that if
should even be there. Maybe it used to be needed but now I think it's a bug so I removed it. That leaves blocking_for_irq
being used only for an assertion but I didn't want to remove that one.
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 not seeing those spurious gnrc_netif: possibly lost interrupt
anymore - nice!
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.
My comments have been addressed and the driver is working fine - please squash!
This is the radio found in NXP Kinetis KW41Z, KW21Z. Only 802.15.4 mode is implemented (KW41Z also supports BLE on the same transceiver). The driver uses vendor supplied initialization code for the low level XCVR hardware, these files were imported from KSDK 2.2.0 (framework_5.3.5)
Thanks very much for the review and testing and bug reporting! |
Contribution description
Taken from #7107 by @gebart:
Since #7107 I fixed the known bugs that were reported there and I've used it extensively for months. By now I think it's getting to be a pretty mature radio driver.
Testing procedure
Confirm
gnrc_networking
example works as intended on an frdm-kw41z or usb-kw41z or other kw41z board.Issues/PRs references
Taken from #7107. Compatible with (but does not depend on) #11789.