-
Notifications
You must be signed in to change notification settings - Fork 61
Open
Labels
topic: documentationRelated to documentation for the projectRelated to documentation for the projecttype: imperfectionPerceived defect in any part of projectPerceived defect in any part of project
Description
The arduino_read function uses the available() routine but it could happen that the STM32 did not return a reply yet.
This problem is what happened when using it on a ESP32-S3 connected to a STM32F4.
When looking at
static port_err_t serial_posix_read(struct port_interface *port, void *buf, size_t nbyte) { serial_t *h; ssize_t r; uint8_t *pos = (uint8_t *)buf; h = (serial_t *)port->private; if (h == NULL) return PORT_ERR_UNKNOWN; while (nbyte) { **r = read(h->fd, pos, nbyte); if (r == 0) return PORT_ERR_TIMEDOUT;** if (r < 0) return PORT_ERR_UNKNOWN; nbyte -= r; pos += r; } return PORT_ERR_OK; }
This code does two things: it reads as many bytes as available directly into a buffer and checks if the total amount read is the same as the expected amount and if not continues to do so. It will also return the timeout error value if the amount read is 0.
I would therefore suggest to replace available() with readBytes() or more precise use the above quoted while loop and use readBytes().
Metadata
Metadata
Assignees
Labels
topic: documentationRelated to documentation for the projectRelated to documentation for the projecttype: imperfectionPerceived defect in any part of projectPerceived defect in any part of project