terjeio / grblHAL

This repo has moved to a new home https://github.com/grblHAL
232 stars 90 forks source link

Ethernet questions for iMXRT 1062 driver #71

Closed phil-barrett closed 4 years ago

phil-barrett commented 4 years ago

I need to arrange a 1 mS timer to call enet_proc_input and enet_poll(). I looked at using driver_delay_ms but that seems like more overhead than necessary. Is there a better way to do that?

From the lwip_websrv we have this in loop(){}:

void loop()
{
  static uint32_t last_ms;
  uint32_t ms;

  enet_proc_input();

  ms = millis();
  if (ms - last_ms > 100)
  {
    last_ms = ms;
    enet_poll();
  }
}

And this is in the T41.c wrapper for lwip.

void enet_proc_input(void)
{
    struct pbuf *p;

    if (!rx_callback)
    {
        if (rx_ready)
            rx_ready = 0;
        else
            return;
    }
    while ((p = enet_rx_next()) != NULL)
    {
        enet_input(p);
    }
}
void enet_poll()
{
    sys_check_timeouts();
    check_link_status();
}
terjeio commented 4 years ago

I am 6 hours+ into a websocket job. Telnet is the preferred protocol because there is no protocol overhead. Websocket is aimed at web-based senders.

terjeio commented 4 years ago

Next is to add SD-card support, a http daemon and then ESP-3D-webui? SD-card support is a given, not sure about the rest. BTW I added a 2K FRAM to your board, it worked out-of-the-box with the EEPROM plugin.

einencool commented 4 years ago

Although I didn't use the ethernet adapter and the option is commented out, I always get an error message while compiling.

In which folder do I have to put the "lwipopts.h" file?

C:\Users\xxxx\AppData\Local\Temp\arduino_build_739742\sketch\enet.c:27:22: fatal error: lwipopts.h: No such file or directory

compilation terminated.

Fehler beim Kompilieren für das Board Teensy 4.1.

terjeio commented 4 years ago

@einencool Can you try with deleting enet.c - it is not needed when ethernet is not in use. I will fix this later.

einencool commented 4 years ago

Hello @terjeio Sadly then the next Message occurs. But no rush, its no Problem, I'm working with the Alarm Connection and have to tram the Spindle, so I really didn't need it essentially today :-)

In file included from C:\Users\csowa\AppData\Local\Temp\arduino_build_671108\sketch\src\networking\TCPStream.c:45:0:

C:\Users\xxxx\AppData\Local\Temp\arduino_build_671108\sketch\src\networking\networking.h:24:22: fatal error: lwip/opt.h: No such file or directory

compilation terminated.

Fehler beim Kompilieren für das Board Teensy 4.1.

terjeio commented 4 years ago

@einencool You have added the networking plugin folder to main/src? Delete it as well.

Networking requires a 3rd party lwip library - will add documentation for that later as well. First we need to verify that networking is ok...

einencool commented 4 years ago

Yes after the first errors I added the folder. I deleted it, and this failure seems to be gone, now I have another issue with the homing section, but I think I'll get it to work in the next hours, Thank you for this fast help :-)

phil-barrett commented 4 years ago

Concentric circles as arcs completed in 7:30 overnight. It was close to the USB time (less than 10 minutes longer).

Will spend this AM testing but I think we are good.

phil-barrett commented 4 years ago

It doesn't look like the connection method (websocket vs telnet) is reported in $i. Perhaps this would be a useful piece of data.

terjeio commented 4 years ago

I termintated my websocket test at 8h+ Latest subversion commit has improved include handling in order to avoid compilation errors. Also added connection status to $I, could be useful for debugging.

Trying to get SD card working but no luck yet, this library works with a test program but not grblHAL for some strange reason. Lack of debugger is a royal pain...

IMO you should add a pin mapping file for your board and perhaps also a matching .c file for the optional GPIO pins available?

phil-barrett commented 4 years ago

Yes, a mapping file has been on my todo list for a while now. I assume it would be a .h file that gets included in driver.c inside an ifdef.

I'm not sure how useful the sd card interface on the T4.1 is. Since the electronics should be in a cabinet to protect them, access to the card reader wouldn't be easy. Maybe there is a variant of the BoB that has the sd slot at the edge of the board so it could be mounted against the case wall.

terjeio commented 4 years ago

I assume it would be a .h file that gets included in driver.c inside an ifdef.

It will be included inside driver.h in a similar way as I have done for a number of other drivers e.g:

https://github.com/terjeio/grblHAL/blob/6124a0a1f6c63da3435bdbbf33f0ce3e428cd2a9/drivers/STM32F4xx/Inc/driver.h#L37-L40

and later in the file:

https://github.com/terjeio/grblHAL/blob/6124a0a1f6c63da3435bdbbf33f0ce3e428cd2a9/drivers/STM32F4xx/Inc/driver.h#L136-L147

The CNC boosterpack will be handled as another board, it will loose its special handling - on my todo list.

I'm not sure how useful the sd card interface on the T4.1

Combined with a http daemon and web UI it can be used to upload gcode, even hold the webui itself. No physical access is required for that.

phil-barrett commented 4 years ago

ok, good point. will have to take a look at that.

phil-barrett commented 4 years ago

I added this code to driver.c at line 823 (in reportIP()) so I could see what protocol was running.

    if(services.telnet) hal.stream.write(":telnet");
    if(services.websocket) hal.stream.write(":websocket");
terjeio commented 4 years ago

I did it like this in the lates subversion commit, didn't you see that?

static void reportIP (void)
{
    hal.stream.write("[IP:");
    hal.stream.write(enet_ip_address());
    hal.stream.write("]\r\n");
    if(services.telnet || services.websocket) {
        hal.stream.write("[NETCON:");
        hal.stream.write(services.telnet ? "Telnet" : "Websocket");
        hal.stream.write("]\r\n");
    }
}
phil-barrett commented 4 years ago

I just did an SVN update and did not get that code so something is off.

phil-barrett commented 4 years ago

I am pulling from Trunk/GRBL/Driver Teensy4

terjeio commented 4 years ago

Commit #4924 is the latest here.

bilde

Right click driver.c and select TortoiseSVN > Show log to get the info above. Your version shows in bold.

phil-barrett commented 4 years ago

This is weird. In file explorer, I go to driver.c and right click/update. It says it's at 4942 but when I look at the file, it is not at 4942. Since I modified driver.c, I'm guessing it refuses to update it. Wish it would have told me that. I deleted driver.c, did a full update and got the correct one.

That solved all the problems I was having. USB connect works now. Deleting the call to hal.debug_out() is what triggered the non-update. I need to spend a bit more time understanding tortoise... sigh.

terjeio commented 4 years ago

I need to spend a bit more time understanding tortoise

I guess you have copied an older version over the one from commit 4942. A new update will do nothing then. If you want to undo your changes you can use TortoiseSVN >Revert, to see what you have changed use TortoiseSVN > Diff.

Got the SDCard plugin working and the sun is out after a long break so I'll take a little break from coding. Will commit the latest changes to subversion first.

phil-barrett commented 4 years ago

I will give it a test. Now that I understand Tortoise better, it might be a little smoother.

Enjoy the sun while you can!

phil-barrett commented 4 years ago

For a static IP address, an invalid IP address, Gateway or Mask causes Teensy to not connect via USB. I made an error entering the Gateway address, power-cycled the teensy and tried to connect via USB. Got the insidious "Waiting for Controller (...)" message in TSender. I had to reload grblHAL to get it to talk to me. Ideally, TSender would validate IP addresses but it's still possible to get an invalid one.

terjeio commented 4 years ago

Changing network settings should not change anything immediately, a hard reset should be required to make them active. At least if the stack is already active. I have added a reboot entry point to the HAL that could be used - but this is not always a good solution either as any USB or network connection will be lost...

Invalid IP addresses should not be accepted, but I do not know how good theip4addr_aton() check I use is. I need to update the sender to handle error reporting for setting changes as well, now it silently ignores them. How does it behave when the settings commands are issued from a terminal? (I am running a long websocket test now that I do not want to interrupt).

USB hanging for invalid addresses could be in the network stack? Needs investigation.

phil-barrett commented 4 years ago

For what it's worth, I muffed the Gateway. It was still a valid IP addr, just not a valid Gateway addr.

Catching all possible errors is impossible. For example, if you are in class C, say. 192.168.2.xxx and enter a valid IP Addr outside of it like 192.168.1.100.

Using a terminal app, grblHAL takes an invalid IP addr and GW($301= or $302=) without complaining. It does not accept malformed ip addrs - silently ignores them. With a bad IPAddr or GW, I am able to connect via USB. So, this is probably a TSender issue. Sorry for putting it in the wrong place.

Changing network settings should not change anything immediately, a hard reset should be required to make them active.

I agree. But, I have some thoughts about TSender to make it easier for the average user. Will comment there.

phil-barrett commented 4 years ago

I built against Paul's lwip (from https://github.com/PaulStoffregen/teensy41_ethernet) and it ran using telnet overnight with no problems.

For anyone wanting to build with enet: download the zip file from the above github repository, copy the lwip directory tree to .../Arduino/libraries and then build. (surprisingly, this is not stated anywhere that I could find. If you don't know, how do you know?)

terjeio commented 4 years ago

For users wanting to try ethernet: the code updates required are not yet available on github! Coming soon.

@phil-barrett The easiest way to install a library is to use the menu Sketch > Include Library > Add .ZIP Library... from the IDE?

phil-barrett commented 4 years ago

Well, yes, it would, if it worked. It's not in an arduino library format - you get "Specified folder/zip does not contain a valid library". Thus, one needs to go the manual route.

terjeio commented 4 years ago

Well, yes, it would, if it worked. It's not in an arduino library format

Then I am going to link to ddrowns fork as it can be imported via the IDE menu.

I have completed a couple of 12h+ jobs with that version, and also used it during development, so it should be ok.

terjeio commented 4 years ago

I close this as ethernet support for T4.1 is now in the master branch. Open a new issue if additional problems appears.