mkiiskila / mynewt_serial_uploader Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
Hello, I don't currently have write access, but the current code does not return proper error codes on failures. I've added a small patch file below. It would be nice to get this merged in for use in automated tests.
index e1d9dd0..0bcfdf6 100755
--- a/serial_upload.c
+++ b/serial_upload.c
@@ -506,6 +506,7 @@ main(int argc, char **argv)
{
HANDLE fd;
int rc;
+ int ret = EXIT_SUCCESS;
cmdname = argv[0];
state.imgchunk = 512;
@@ -535,9 +536,13 @@ main(int argc, char **argv)
rc = echo_ctl(0);
if (rc == 0) {
rc = img_upload();
+ } else {
+ ret = EXIT_FAILURE;
}
if (rc == 0) {
rc = reset_device();
+ } else {
+ ret = EXIT_FAILURE;
}
#if 0
if (echo_ctl(1)) {
@@ -547,5 +552,5 @@ main(int argc, char **argv)
free(state.file);
fflush(stderr);
fflush(stdout);
- return 0;
+ return ret;
}
Hi, I ran into an issue running this on Alpine Linux. The cfsetspeed()
call should take the POSIX portable bit defines (B#####
). A patch is provided below.
index e553cfd..b648f03 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,7 @@ tinycbor/src/%.c:
serial_upload: $(SRCS) serial_upload.h
@echo serial_upload
- cc -o serial_upload -ggdb -Wall -I tinycbor/src -I . $(SRCS)
+ $(CC) -o serial_upload -ggdb -Wall -I tinycbor/src -I . $(SRCS)
clean:
rm serial_upload
diff --git a/serial_upload_unix.c b/serial_upload_unix.c
index 9e83884..d169ec8 100644
--- a/serial_upload_unix.c
+++ b/serial_upload_unix.c
@@ -24,6 +24,7 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <errno.h>
@@ -64,9 +65,43 @@ port_setup(int fd, unsigned long speed)
ECHONL | ECHOCTL | ECHOPRT | ECHOKE | FLUSHO | NOFLSH |
TOSTOP | PENDIN | IEXTEN);
+#if defined(__posix__)
+ speed_t sp;
+ switch(speed) {
+ case 921600:
+ sp = B921600;
+ break;
+ case 460800:
+ sp = B460800;
+ break;
+ case 230400:
+ sp = B230400;
+ break;
+ case 115200:
+ sp = B115200;
+ break;
+ case 57600:
+ sp = B57600;
+ break;
+ case 38400:
+ sp = B38400;
+ break;
+ case 19200:
+ sp = B19200;
+ break;
+ case 9600:
+ sp = B9600;
+ break;
+ default:
+ sp = B115200;
+ break;
+ }
+ rc = cfsetspeed(&tios, sp);
+#elif defined(__APPLE__)
rc = cfsetspeed(&tios, (speed_t)speed);
+#endif
if (rc < 0) {
- fprintf(stderr, "%s: cfsetspeed(%lu) failed\n", cmdname, speed);
+ fprintf(stderr, "%s: cfsetspeed(%lu) failed: %s\n", cmdname, speed, strerror(errno));
return rc;
}
At the moment it does not happen automatically, and by default Linux serial ports are slow pollers.
So the user has to either scriptify this or set it manually.
Basically this setting:
cat /sys/bus/usb-serial/devices/ttyUSB0/latency_timer 16
echo 1 > /sys/bus/usb-serial/devices/ttyUSB0/latency_timer
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.