Skip to content
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

Serial Transmission corrupts some characters #46

Open
martin2250 opened this issue Jun 14, 2018 · 12 comments
Open

Serial Transmission corrupts some characters #46

martin2250 opened this issue Jun 14, 2018 · 12 comments

Comments

@martin2250
Copy link

Hi,

with my setup (STM32 Blue Pill) some chars sent over USB get corrupted in transmission. eg. I get the occasional [BRB:] instead of PRB, sometimes status messages have some wrong characters (both in text and numbers). I have yet to find an error in the transmission from the PC to grbl.

I'm using a single USB cable which is relatively short, though this shouldn't affect the data anyways as USB normally uses CRC. Is CRC disabled for incoming messages like in vUSB? This would explain why (so far) only messages from the PC have been corrupted.

Martin

@robomechs
Copy link

I have the same problem (from grbl -> to PC), but it happens very rarely, and I can't catch it.
Most of all I'm worried that a mistake (error) can occur in meaningful numbers, but so far this has not happened.

@Sombat4t
Copy link

I've used to have this when I use Universal GCode Sender, but after I've wrote my own Gcode sender this problem less and rarely occured. For me, I think the main problem will be the way to interaction of "send and response protocol" not appropriate. Furthermore; this issue will always exist by its nature.

@martin2250
Copy link
Author

Did you publish this custom streamer somewhere? I'm also using my own software (OpenCNCPilot).

For me, I think the main problem will be the way to interaction of "send and response protocol" not appropriate

sorry, what exactly do you mean by that?

Furthermore; this issue will always exist by its nature.

No, this is absolutely not ok. Error checking and handling should be taken care of by the USB protocol.

@Sombat4t
Copy link

Sombat4t commented Jun 27, 2018 via email

@Sombat4t
Copy link

Hi, I think I find the solution for this issue, but no prove. perhaps you want to test on yours. I test on mine. there are no any corrupts or incomplete for real time status message. To do is just lock the "serial_tx_buffer_head" variable in ring buffer as below. Three files added: usb_endp.c, serial.h and serial.c.

  1. File usb_endp.c

volatile uint8_t txUsbLock = 0;

void EP1_IN_Callback (void)
{}

void EP1_IN_Callback2(void)
{
uint16_t USB_Tx_length;
uint8_t head;

txUsbLock = 1;
head = serial_tx_buffer_head;
txUsbLock = 0;

if ((head != serial_tx_buffer_tail))
{
    if (head > serial_tx_buffer_tail)
	    USB_Tx_length = head - serial_tx_buffer_tail;
    else
	    USB_Tx_length = TX_BUFFER_SIZE - serial_tx_buffer_tail + head;

}
void SOF_Callback(void)
{
if(bDeviceState == CONFIGURED) {
/* Check the data to be sent through IN pipe */
if(_GetEPTxStatus(ENDP1) == EP_TX_NAK)
{
EP1_IN_Callback2();
}
}
}

  1. File serial.h
    extern volatile uint8_t txUsbLock;

  2. File serial.c
    void serial_write(uint8_t data) {
    ...
    // Store data and advance head
    serial_tx_buffer[serial_tx_buffer_head] = data;
    while(txUsbLock) {
    if (sys_rt_exec_state & EXEC_RESET) { return; } // Only check for abort to avoid an endless loop.
    }
    serial_tx_buffer_head = next_head;

@martin2250
Copy link
Author

@Sombat4t I'll test that as soon as I can. Thanks!

@Sombat4t
Copy link

Sombat4t commented Jun 29, 2018 via email

@martin2250
Copy link
Author

can you please create a pull request or fork this repo and make your changes to your fork? The code from your comment is incomplete and I can't get it to work.

@Sombat4t
Copy link

Sombat4t commented Jul 8, 2018 via email

@robomechs
Copy link

With this changes it work with OpenCNCPilot.
But it works without changes too. Apparently I need more tests)))
OpenCNCPilot is an interesting program.

@robomechs
Copy link

robomechs commented Jul 31, 2018

without changes (with UGS) 2-3 corrupted lines each 1000 "?":
Error while processing response <<Idle|MPos:0.000,20.000,0.000,0.000|FS:0,0|Pn:XYZA|Ov:P00,100,100|A:S>>: For input string: "P00"

Error while processing response <<Idle|MPos:o.000,20.000,0.000,0.000|FS:0,0|Pn:XYZA|Ov:100,100,100|A:S>>

Error while processing response <<Idle|MPos:0.P00,20.000,0.000,0.000|FS:0,0|Pn:XYZA>>: For input string: "0.P00"

Error while processing response <<Run|MPos:0.s04,0.004,0.004,0.000|FS:30,0|Pn:XYZA>>: For input string: "0.s04"

Error while processing response <<Run|MPo|:0.005,0.005,0.005,0.000|FS:30,0|Pn:XYZA>>

Error while processing response <<Run|MPos:0.004,0.004,0,004,0.000|FS:30,0|Pn:XYZA>>

Error while processing response <<Run|MPo.:0.001,0.001,0.001,0.000|FS:30,0|Pn:XYZA>>

Error while processing response <<Run|MPos:0.011,0.011,0.011,0.000|FS:30.0|Pn:XYZA|Ov:100,100,100|A:S>>: 1

Error while processing response <<Run|MPos:0.005,00005,0.005,0.000|FS:30,0|Pn:XYZA>>

Error while processing response <<Run|MPos:0.004,0.004,0.004,0.000|FS:30,0.Pn:XYZA>>: For input string: "0.Pn:XYZA"

Error while processing response <<Run|MPos:0.017,0.017,0.017,0.000|FS:30,:|Pn:XYZA>>: For input string: ":"

Error while processing response <<Run|MPos:0.017,0.017,01017,0.000|FS:30,0|Pn:XYZA>>

Error while processing response <<Run|MPos:0.012,0.012,0.012,0.000|FS:30P0|Pn:XYZA>>: For input string: "30P0"

Error while processing response <<Run|MPos:81.821,77.277,77.277,0.000|FS:500,07Pn:XYZA>>: For input string: "07Pn:XYZA"

with changes (with UGS) there are no corrupted lines!

@Sombat4t
Copy link

Sombat4t commented Aug 1, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants