Skip to content

drivers: eth_mcux: adding i.mx-rt support #10875

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

Merged
merged 4 commits into from
Nov 20, 2018

Conversation

agansari
Copy link
Contributor

@agansari agansari commented Oct 26, 2018

Enables Networking hardware on i.MX-RT 1050-EVKB board.
Fixes #8900

  • enables board specific pinout for ethernet connection
  • fixed initialization sequence in eth_mcux
  • pinmux enablement pushed later so sysclock is initalized before

Signed-off-by: Andrei Gansari andrei.gansari@nxp.com

@codecov-io
Copy link

codecov-io commented Oct 26, 2018

Codecov Report

Merging #10875 into master will increase coverage by 0.04%.
The diff coverage is 30.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10875      +/-   ##
==========================================
+ Coverage   48.37%   48.41%   +0.04%     
==========================================
  Files         265      270       +5     
  Lines       42188    42121      -67     
  Branches    10137    10139       +2     
==========================================
- Hits        20408    20394      -14     
+ Misses      17703    17645      -58     
- Partials     4077     4082       +5
Impacted Files Coverage Δ
include/logging/log_core.h 100% <ø> (ø) ⬆️
include/kernel.h 98.48% <ø> (ø) ⬆️
include/bluetooth/gatt.h 100% <ø> (ø) ⬆️
boards/posix/nrf52_bsim/k_busy_wait.c 0% <0%> (ø) ⬆️
subsys/net/lib/mqtt_sock/mqtt_rx.c 0% <0%> (ø)
subsys/net/lib/mqtt_sock/mqtt_transport.c 0% <0%> (ø)
subsys/bluetooth/host/conn.c 32.38% <0%> (-0.33%) ⬇️
subsys/logging/log_msg.c 86.36% <0%> (-0.5%) ⬇️
...bsys/net/lib/mqtt_sock/mqtt_transport_socket_tcp.c 0% <0%> (ø)
include/net/net_context.h 78.94% <100%> (+0.37%) ⬆️
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f60b580...599da04. Read the comment docs.

int irq_lock_key = irq_lock();


if (EIR & (kENET_RxBufferInterrupt | kENET_RxFrameInterrupt))
Copy link
Member

Choose a reason for hiding this comment

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

This does not follow Zephyr coding style. Please place { in the same line as the if() statement like this

if (xxx) {

} else if () {

} else {

}


irq_unlock(irq_lock_key);
}
#endif //CONFIG_SOC_SERIES_IMX_RT
Copy link
Member

Choose a reason for hiding this comment

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

No // comments

@agansari agansari force-pushed the imxrt_netw branch 2 times, most recently from 8b61c82 to 17cf8fd Compare October 29, 2018 13:48
Copy link
Member

@jukkar jukkar left a comment

Choose a reason for hiding this comment

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

LGTM, but please check the issues sanitychecker is reporting at https://app.shippable.com/github/zephyrproject-rtos/zephyr/runs/25592/5/tests

#endif

return 0;
}

SYS_INIT(mimxrt1050_evk_init, PRE_KERNEL_1, 0);
SYS_INIT(mimxrt1050_evk_init, PRE_KERNEL_2, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious, why the change to PRE_KERNEL_2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed pin initialization later so i can use k_busy_wait to reset ethernet PHY chip.

Copy link
Member

Choose a reason for hiding this comment

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

Does a similar change need to be made on frdm_k64f?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

K64F doesn't need this change, PHY is similar, a bit different and differently wired.

Copy link
Contributor

@galak galak left a comment

Choose a reason for hiding this comment

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

Can you fixup the white space issues that checkpatch is reporting
Also, can you add more details about what changes you are making to the ethernet driver itself to support i.MX-RT (i'd pull these changes out into their own commit).

@pfalcon
Copy link
Contributor

pfalcon commented Oct 30, 2018

From commit message:

Enables Newtworking hardware on i.MX-RT 1050-EVKB board.

Please fix typo in "Newtworking".

And the commit message is very bare. Even description of the PR here more detailed than the commit message, even though the commit message is what goes into posterity (into git log, git bisect, etc.). At the very least, it could mention that existing eth_mcux driver is reused for this hardware (which is not obvious and pleasantly (I hope) surprising fact for me).

(Note that "more detailed commit message" is my usual suggestion to pretty big share of patches I review.)

Copy link
Contributor

@pfalcon pfalcon left a comment

Choose a reason for hiding this comment

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

Some suggestions from my side too. At least splitting off ext/ change to a separate commit should be done. (Unless overridden by @galak, @MaureenHelm or someone else in the know.)

if NETWORKING

config NET_L2_ETHERNET
def_bool y if !MODEM_WNCM14A2A
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this truly a good idea here?

IOMUXC_SW_PAD_CTL_PAD_PKE_MASK |
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
IOMUXC_SW_PAD_CTL_PAD_DSE(6));
IOMUXC_SW_PAD_CTL_PAD_PKE_MASK |
Copy link
Contributor

Choose a reason for hiding this comment

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

So, in such cases, Zephyr codestyle requires to align args "in column", using tabs for as long as possible, then spaces. In other words, what was before seems to be right. Also, IMHO, codestyle changes should be separated from functional changes. YMMV

#endif

#ifdef CONFIG_ETH_MCUX_0
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_04_ENET_RX_DATA00, 0U);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have uppercase "U" here and "u" below?

Also, so far Zephyr doesn't use that "suffixed U" style. (So far, yes).

Copy link
Member

@MaureenHelm MaureenHelm left a comment

Choose a reason for hiding this comment

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

Please make the driver changes in a separate commit from the soc and board changes.

#include <fsl_gpio.h>

#ifdef CONFIG_ETH_MCUX_0
gpio_pin_config_t enet_gpio_config = {
Copy link
Member

Choose a reason for hiding this comment

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

Dedent this block and make the variable static const.

GPIO_PinInit(GPIO1, 9, &enet_gpio_config);
GPIO_PinInit(GPIO1, 10, &enet_gpio_config);

/* pull up the ENET_INT before RESET. */
Copy link
Member

Choose a reason for hiding this comment

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

Please add to the comment that you're resetting the PHY

#endif

return 0;
}

SYS_INIT(mimxrt1050_evk_init, PRE_KERNEL_1, 0);
SYS_INIT(mimxrt1050_evk_init, PRE_KERNEL_2, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Does a similar change need to be made on frdm_k64f?

@@ -932,6 +951,30 @@ static void eth_mcux_ptp_isr(void *p)
}
#endif

#ifdef CONFIG_SOC_SERIES_IMX_RT
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to avoid direct dependencies on the SoC like this. If you add interrupt-names = "COMMON" to the dts, you can make this condition #ifdef ETH_IRQ_COMMON instead.

}
#endif /* CONFIG_SOC_SERIES_IMX_RT */

#ifdef CONFIG_SOC_SERIES_KINETIS_K6X
Copy link
Member

Choose a reason for hiding this comment

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

Change this to #ifdef ETH_IRQ_RX and wrap the other isr's similarly with #ifdef ETH_IRQ_TX and #ifdef ETH_IRQ_ERR_MISC

#if CONFIG_SOC_SERIES_IMX_RT
IRQ_CONNECT(ENET_IRQn, CONFIG_ETH_MCUX_0_IRQ_PRI,
eth_mcux_dispacher_isr, DEVICE_GET(eth_mcux_0), 0);
irq_enable(ENET_IRQn);
Copy link
Member

Choose a reason for hiding this comment

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

Use the irq number from dts instead of CMSIS

@agansari agansari force-pushed the imxrt_netw branch 2 times, most recently from f3e7f81 to f41267f Compare November 5, 2018 11:10
@@ -33,7 +33,9 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#include "fsl_enet.h"
#include "fsl_phy.h"
#ifdef CONFIG_SOC_SERIES_KINETIS_K6X
#include "fsl_port.h"
Copy link
Member

Choose a reason for hiding this comment

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

Is this include needed at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was needed in case of unique mac, SIM definition was not included.
No longer required.

Copy link
Member

Choose a reason for hiding this comment

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

Let's remove it then

@@ -30,15 +30,15 @@
#size-cells = <1>;

itcm0: itcm@0 {
reg = <0x00000000 0x20000>;
reg = <0x00000000 0x80000>;
Copy link
Member

@MaureenHelm MaureenHelm Nov 5, 2018

Choose a reason for hiding this comment

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

This doesn't make sense. We have 512 KB SRAM that gets partitioned into ITCM, DTCM, and OCRAM. They can't all be 512 KB.

Rather than changing these partitions, we need to add a min_flash and/or min_ram requirement to the failing sample/test yaml.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, i just looked at memory map and not FlexRam.
Thank you for yaml suggestion.

@agansari
Copy link
Contributor Author

agansari commented Nov 7, 2018

@pfalcon and @galak can you please help me test this pull request on both i.MX RT and K64F for backward compatibility?

Copy link
Member

@MaureenHelm MaureenHelm left a comment

Choose a reason for hiding this comment

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

Looks pretty good. I still need to test on hardware

@@ -33,7 +33,9 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#include "fsl_enet.h"
#include "fsl_phy.h"
#ifdef CONFIG_SOC_SERIES_KINETIS_K6X
#include "fsl_port.h"
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove it then

@@ -33,9 +33,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#include "fsl_enet.h"
#include "fsl_phy.h"
#ifdef CONFIG_SOC_SERIES_KINETIS_K6X
#include "fsl_port.h"
Copy link
Member

Choose a reason for hiding this comment

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

Move this change to the previous commit

@@ -15,3 +15,4 @@ ram: 128
flash: 128
supported:
- spi
- netif:eth
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 also update the board doc to reflect that ethernet is now supported?

@agansari agansari force-pushed the imxrt_netw branch 2 times, most recently from 59c501b to d3dc1c0 Compare November 7, 2018 16:14
@agansari agansari requested a review from dbkinder as a code owner November 7, 2018 16:14
@agansari agansari force-pushed the imxrt_netw branch 2 times, most recently from 61dd607 to 45fc2dc Compare November 7, 2018 16:19
Copy link
Contributor

@dbkinder dbkinder left a comment

Choose a reason for hiding this comment

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

+1 for doc changes

@galak
Copy link
Contributor

galak commented Nov 14, 2018

Some suggestions from my side too. At least splitting off ext/ change to a separate commit should be done. (Unless overridden by @galak, @MaureenHelm or someone else in the know.)

I don't think it needs its own commit

@galak
Copy link
Contributor

galak commented Nov 14, 2018

@pfalcon still have issues?

@pfalcon pfalcon dismissed their stale review November 14, 2018 16:15

Oops, sorry, forgot I had -1 here.

@pfalcon
Copy link
Contributor

pfalcon commented Nov 14, 2018

Dismissed my -1, sorry, completely forgot I had it there.

(Submitters, feel free to ping reviewers in such cases.)

@@ -41,4 +41,13 @@
#define DT_UART_MCUX_LPUART_3_CLOCK_NAME DT_NXP_KINETIS_LPUART_4018C000_CLOCK_CONTROLLER
#define DT_UART_MCUX_LPUART_3_CLOCK_SUBSYS DT_NXP_KINETIS_LPUART_4018C000_CLOCK_NAME

#define DT_ETH_MCUX_0_NAME ETH_LABEL
Copy link
Contributor

Choose a reason for hiding this comment

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

Would prefer to see this be:

#define DT_ETH_MCUX_0_NAME DT_NXP_KINETIS_ETHERNET_402D8000_LABEL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@galak I've made the change you requested
@galak @pfalcon Thank you for your reviews!

Copy link
Contributor

Choose a reason for hiding this comment

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

Sadly, I don't have much to be thanked for - it's on my TODO to test this patch on real hw, but unfortunately I can't to it due to other tasks I got into. I just hope that other folks tested it. (I'll get to it to of course.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's taking me some time to test i.MX RT and backward checking K64F, this i why I didn't ping earlier. Patch looks okay so far.

Enables Networking hardware on i.MX-RT type drivers.
Reuses the same eth_mcux driver used by Kinetis family; initialization
sequence refactored to work with this board as well. Unlike Kinetis
family, i.MX has a single ENET interrupt and we need to discriminate
between interrupts using a status register.

Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
Enables Networking hardware on i.MX-RT 1050-EVKB board.
Pinout enabled board specific etherenet connection, also pin
initialization was moved later to PRE_KERNEL_2 in order to have
sysclock initialized before.

Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
In order to prevent failing tests on i.MX RT the following samples were
limited to a minimum 140k of flash: http_client, http_server,
socket/echo_client and sockets/echo_server.

Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
Board documentation updated with Networking related infomation.

Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
@pfalcon
Copy link
Contributor

pfalcon commented Nov 19, 2018

@agansari : FYI, I'm very, very close to help with testing this (at least on frdm_k64f). I actually hoped to do this today, but as usually happens, discovered a trail of regressions on approaching that. For you reference, my standard test plans are described in https://github.com/pfalcon/zephyr/wiki/NetworkingTestPlan (again, they don't work with current master, and require patches - new and old).

@pfalcon
Copy link
Contributor

pfalcon commented Nov 20, 2018

Ok, testing: frdm_k64f with samples/net/sockets/dumb_http_server, master 57a6858 + this patch + #7831, as required for reliable frdm_k64f operation (not related to the changes in this PR in any way, master is broken).

ab -n1000 http://192.0.2.1:8080/ works as expected. Specifically:

Complete requests:      1000
Failed requests:        0
Total transferred:      2181000 bytes
HTML transferred:       2122000 bytes
Requests per second:    118.71 [#/sec] (mean)
Time per request:       8.424 [ms] (mean)
Time per request:       8.424 [ms] (mean, across all concurrent requests)
Transfer rate:          252.85 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.1      1       2
Processing:     5    8   0.2      8      11
Waiting:        4    7   0.2      7       7
Total:          6    8   0.2      8      11

Percentage of the requests served within a certain time (ms)
  50%      8
  66%      8
  75%      8
  80%      8
  90%      8
  95%      9
  98%      9
  99%      9
 100%     11 (longest request)

@pfalcon
Copy link
Contributor

pfalcon commented Nov 20, 2018

Ok, now frdm_k64f + big_http_download:

First iteration went ok:

***** Booting Zephyr OS zephyr-v1.13.0-2040-g4b22b4c6ce *****
Preparing HTTP GET request for http://archive.ubuntu.com:80/ubuntu/dists/xenial/main/installer-amd64/current/images/hd-media/vmlinuz
addrinfo @0x20008238: ai_family=2, ai_socktype=1, ai_protocol=6, sa_family=2, sin_port=5000
sock = 0
7015896 bytes
Hash: 337c37d7ec00348414224baa6bdb2d43f2a34ef5676bafcdcad916f148b5b317
Total downloaded so far: 6MB

It seems to be even faster with this patch ;-). (I'm kidding, it's as slow as usual. In all fairness, I don't add d/l speed calculation to not scare off people.)

But on 2nd iter:

sock = 0
[00:00:01.642,867] <err> eth_mcux.eth_rx: Failed to get fragment buf
1158170 bytes

Well, that unlikely has anything to do with the driver changes, and should be a transient error.

@pfalcon
Copy link
Contributor

pfalcon commented Nov 20, 2018

Ok, as there're no regressions with frdm_k64f, let me approve this. Otherwise, I of course take a chance to bootstrap me with mimxrt1050_evk testing.

Copy link
Contributor

@pfalcon pfalcon left a comment

Choose a reason for hiding this comment

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

Tested on frdm_k64f

@agansari
Copy link
Contributor Author

@pfalcon i.MX RT will have some issues, some samples are too big for iTCM memory, but thye will run if they fit.
Thank you for taking time on regressive testing. Can we automate these tests?

@pfalcon
Copy link
Contributor

pfalcon commented Nov 20, 2018

Can we automate these tests?

Well, that's definitely the aim various parties want to achieve, e.g. I know that NXP has some internal system (@dleach02 told), on Linaro level we want to integrate more HW testing into mostly barebones testing, Zephyr recently added real-board testing into its "sanitycheck" testsuite. But what can I say more if the current situation is that mainline has networking stack setting which semi-break frmd_k64f (#7831), and for half a year (it's actually longer than that) it can't come to resolution?

All in all, before we'll be able to run tests automatically, we need to get used to run tests consistently manually. And https://github.com/pfalcon/zephyr/wiki/NetworkingTestPlan is my modest contribution towards that.

@pfalcon
Copy link
Contributor

pfalcon commented Nov 20, 2018

@pfalcon
Copy link
Contributor

pfalcon commented Nov 20, 2018

@agansari, Maybe you can confirm something to me. So, when I work with a board which has mbed bootloader, I usually follow the least-resistance way, and just copy zephyr.bin files to mass-storage device the said bootloader offers. So far, that doesn't work with mimxrt1050_evk. Symptoms are as described here: https://community.nxp.com/thread/486834 , and I wonder if that reply nails:

For I.MXRT1050 EVKB, Drag and drop function is not supported.

Did you ever use the I.MXRT1050 in mbed-like way?

@agansari
Copy link
Contributor Author

@pfalcon I only used j-link debugging, haven't tried mbed bootloader, let me test that.

@galak galak merged commit bf988dc into zephyrproject-rtos:master Nov 20, 2018
@pfalcon
Copy link
Contributor

pfalcon commented Nov 20, 2018

@agansari: Ok, "mystery" solved. With default-as-shipped mbet bootloader, there's no jlink support. After jlink firmware installed, there's no mbed flash-drive any longer. I was able to get hello_world running all in all. Will continue with eth testing tomorrow. And hope to submit update to the board doc.

@pfalcon
Copy link
Contributor

pfalcon commented Nov 21, 2018

@agansari : So far, bad news - no response from Eth on imxrt, nothing in stats after pings. What I noticed is that both LEDs on Eth jack always light up for me, even without cable. And they never blink. Do you have the same?

And just reinsuring - I didn't see all the jumpers on the board being described in user guide. I don't need change any jumpers, do I?

@agansari
Copy link
Contributor Author

@pfalcon yes, the leds light up from the begining, but they blink on pings for example. There is no need for jumpers or deep switches changes.

@pfalcon
Copy link
Contributor

pfalcon commented Nov 21, 2018

Ok, let's continue in #11586

@agansari agansari deleted the imxrt_netw branch December 9, 2019 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable mcux ethernet driver on iMX RT1050
8 participants