grblHAL / RP2040

grblHAL driver for RP2040 (Pi Pico)
Other
103 stars 44 forks source link

Keyboard Jogging does not work when using Ethernet-to-uart module #77

Closed fireup924 closed 8 months ago

fireup924 commented 8 months ago

When using IOSender and communicating via Ethernet-Uart module, the Keyboard jog does not work and gives a "G-code words consist of a letter and a value. Letter was not found." error.

I traced it down to this section of protocol.c on line 890 hal.stream.cancel_read_buffer(); commenting this line out and adding system_set_exec_state_flag(EXEC_MOTION_CANCEL); seem to fix the problem.

case CMD_JOG_CANCEL:
  char_counter = 0;
  drop = true;
  //hal.stream.cancel_read_buffer();
  if (state_get() & STATE_JOG) // Block all other states from invoking motion cancel.
       system_set_exec_state_flag(EXEC_MOTION_CANCEL);
  if(grbl.on_jog_cancel)
      grbl.on_jog_cancel(state_get());
  break;

I'm not sure if this is the right fix for this? I seems the keyboard jog command for IOSender is sending a 0x85 and a $J= in the same line and cause the hal.stream.cancel_read_buffer() to trim some of the Jog string...

terjeio commented 8 months ago

I assume this is with the RP2040 driver. The issue seems to be that the code for flushing the RX buffer that also attempts to empty the RX FIFO upsets something. Commenting out the FIFO flushing part resolves the issue. I guess I'll have to figure out how to empty the FIFO without causing side-effects.

fireup924 commented 8 months ago

Yes, it's on a RP2040. I wasn't sure if it's was only RP2040 so I tested it on ESP32 and Teensy4 and they don't have the same issue.

fireup924 commented 8 months ago

Thank you for the fix. It works now without having to touch the core code in protocol.c

terjeio commented 8 months ago

It works now without having to touch the core code in protocol.c

I spent a lot of time fixing jog cancel that intermittently failed with the legacy code inherited from Grbl, so I suspected the issue was somewhere else. What is odd is that somehow spurious characters get inserted in the input buffer when attempting to flush the RX FIFO. The solution was not to flush it since characters received after the jog cancel command are not problematic and should be kept anyway...