-
Notifications
You must be signed in to change notification settings - Fork 21
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
Cannot flash due to "Problem reading Hex file" #3
Comments
diff --git a/ihex.c b/ihex.c
index 860a8ad..642d54f 100644
--- a/ihex.c
+++ b/ihex.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <ctype.h>
#include <string.h>
#include "ihex.h"
@@ -131,6 +132,7 @@ uint8_t IHEX_ReadFile(FILE *fp, uint8_t *data, uint16_t maxlen, uint16_t *max_ad
uint8_t i;
uint8_t byte;
char str[128];
+ char *end;
addr = 0;
segment = 0;
@@ -138,6 +140,10 @@ uint8_t IHEX_ReadFile(FILE *fp, uint8_t *data, uint16_t maxlen, uint16_t *max_ad
{
if (fgets(str, sizeof(str), fp) == NULL)
return IHEX_ERROR_FILE;
+ // trim whitespace on the right
+ end = str + strlen(str) - 1;
+ while (end > str && isspace((unsigned char) *end)) end--;
+ end[1] = '\0';
if (strlen(str) < IHEX_MIN_STRING)
return IHEX_ERROR_FMT;
len = IHEX_GetByte(&str[IHEX_OFFS_LEN]);
diff --git a/ihex.h b/ihex.h
index d2f2f83..e96c6cf 100644
--- a/ihex.h
+++ b/ihex.h
@@ -6,7 +6,7 @@
#include <stdbool.h>
#define IHEX_LINE_LENGTH 16
-#define IHEX_MIN_STRING 12
+#define IHEX_MIN_STRING 11
#define IHEX_OFFS_LEN 1
#define IHEX_OFFS_ADDR 3 (taken from: https://stackoverflow.com/a/122721) |
Hello, thank you for your message, i will check it with Windows version and commit the fix as soon as possible. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
I'm trying to flash a simple blink example to an ATmega4809, which was compiled with PlatformIO.
updiprog
cannot read the hex file, however.After adding a few debug statements, the culprit appears to be the sanity check in
IHEX_ReadFile
:updiprog/ihex.c
Lines 148 to 149 in 3741ea7
The left side returns
44
whilestrlen(str)
returns45
.If I just add another
+ 1
on the left side as an override, the program is flashed correctly and my LED blinks. Isstrlen()
handling theCRLF
(see below) incorrectly?I'm on
Linux 5.5.4-arch1-1 x86_64
.Sources
src/blink.c
:.pio/build/mega/firmware.hex
:The hexdump shows that lines are terminated with
\x0d\x0a
, i.e. "CRLF":The text was updated successfully, but these errors were encountered: