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

Possible bug in arduino_read function of "MKRWANFWUpdate_standalone" example sketch #134

Open
CFTechno opened this issue Feb 2, 2024 · 0 comments
Labels
topic: documentation Related to documentation for the project type: imperfection Perceived defect in any part of project

Comments

@CFTechno
Copy link

CFTechno commented Feb 2, 2024

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

https://github.com/facchinm/stm32flash/blob/1d155f293cac0f825c73c39b4d5344113bb67052/serial_posix.c#L270C1-L292C2

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().

@per1234 per1234 changed the title OTA Example - Serial_arduino : possible bug in arduino_read Possible bug in arduino_read function of "MKRWANFWUpdate_standalone" example sketch Feb 2, 2024
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: documentation Related to documentation for the project labels Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: documentation Related to documentation for the project type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants