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

CMake: Include readline library for MSVC #1259

Closed
wants to merge 1 commit into from

Conversation

mariusgreuel
Copy link
Contributor

Happy new year, everybody! 🥳

Here is my first shot at readline support for MSVC.

Basically, its based on readline 5.0, with the Windows patches from Readline for Windows, plus some additions from me, including:

  • CMake support
  • Some Windows 64-bit pointer fixes

I have not spent much time with this library, but some things appear to work:

  • I can connect via -c urclock - t
  • I can pipe input to avrdude
  • I can redirect an input file to it
  • The readline library does not crash anymore on Ctrl-R

However, there are also a few issues with it, so I do not think its production ready:

  • The readline history is not preserved over sessions
  • The keep alive feature is not very reliable, it seems to eventually time out after some 20 to 30 seconds or so
  • The reconnect feature does not seem to work (using manual reset): I typically get messages such as
avrdude error: protocol expects sync byte 0x20 but got 0x00 in ur_readEF()
avrdude error: unable to read flash page at addr 0x0100
avrdude error: (dump) error reading flash address 0x00100 of part ATtiny167
               read operation not supported on memory type flash
avrdude> avrdude error: protocol expects sync byte 0x20 but got 0xea in urclock_term_keep_alive()
avrdude error: protocol expects sync byte 0x20 but got 0xfc in urclock_term_keep_alive()
dump flash

Reading | -------------------------------------------------- | 0% 0.01 s

avrdude error: protocol expects OK byte 0x1d but got 0xff in urclock_paged_load()
avrdude error: protocol expects sync byte 0x20 but got 0xff in ur_readEF()
avrdude error: unable to read flash page at addr 0x0100
avrdude error: (dump) error reading flash address 0x00100 of part ATtiny167
               read operation not supported on memory type flash
avrdude> avrdude error: protocol expects sync byte 0x20 but got 0x1d in urclock_term_keep_alive()
avrdude error: protocol expects OK byte 0x1d but got 0xff in urclock_term_keep_alive()
avrdude error: protocol expects sync byte 0x20 but got 0x1d in urclock_term_keep_alive()

avrdude> avrdude error: protocol expects sync byte 0x20 but got 0x00 in urclock_term_keep_alive()
avrdude error: protocol expects sync byte 0x20 but got 0xea in urclock_term_keep_alive()
avrdude error: protocol expects sync byte 0x20 but got 0xfc in urclock_term_keep_alive()

@stefanrueger If you have a Windows PC at your hands, could you give this PR a try? Is there anything specific you would like me to try?

Closes #1186

@mariusgreuel mariusgreuel added the enhancement New feature or request label Jan 2, 2023
@mariusgreuel mariusgreuel self-assigned this Jan 2, 2023
@stefanrueger
Copy link
Collaborator

Cool progress! @mariusgreuel

I don't read cmake, so am useless for reviewing the changes (I looked at them and they look good, but I don't know).

| The readline history is not preserved over sessions

I don't think it is in Linux either. This would probably need to be specifically programmed using readline functions; whether one wanted such a thing is another question. All good on that front.

| The reconnect feature does not seem to work (using manual reset)

Do you mean pressing rest on the AVR-board whilst live on avrdude -t? Nice if it works, and I was surprised it did when I tried, but that's defo not a feature I'd like to guarantee or be tasked to program

| The keep alive feature is not very reliable, it seems to eventually time out after some 20 to 30 seconds or so

That's the only thing I would try to fix; I am sure you know how keep-alive works, so it's probably worthwhile investigating this loop and double-checking my massaging of your readytoread() code.

I am particularly pleased that this no longer needs an explicit quit command to leave which you reported earlier as a problem.

@stefanrueger
Copy link
Collaborator

| If you have a Windows PC at your hands, could you give this PR a try? Is there anything specific you would like me to try?

Sadly no... Can you leave the terminal with ctrl-D or ctrl-Z (the EOF character for text input)?

@stefanrueger
Copy link
Collaborator

stefanrueger commented Jan 2, 2023

time out after some 20 to 30 seconds or so

Just wondering whether the Windows readytoread() sees some events (such as mouse movements, pressing the ctrl/shift/alt key etc) that might make it think there is something to read, but there isn't actually, so reading blocks and the terminal times out...

@mcuee
Copy link
Collaborator

mcuee commented Jan 3, 2023

@stefanrueger and @mariusgreuel

The changes in CMake look good to me. Issue 2 is annoying. Issue 1 and Issue 3 are acceptable for me as of now, since there is the same issue under MSYS2 with GNU Readline.

I have found a few issues under Windows.

  1. CTRL-Z does nothing or causes timeout, CTRL-D works as quit but there is a warning after that.
  2. pipe does not quit, need to hit CTRL-C to exit; adding an explicit echo quit can be the workaround under MSYS2 prompt but I am not so sure how to do that under PowerShell or CMD prompt
  3. Timeout may happen if we have a long sleep (edge test cases), as expcted. This also happens with MinGW readline version.
  1. Reset the chip and the terminal session can still be alive with a warning message (need to hit RETURN).
PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1259_msvc -c urclock -P COM6 -p m328p -xshowall

avrdude_pr1259_msvc: AVR device initialized and ready to accept instructions
0 0000-00-00 00.00  application 0 store 0 meta 0 boot 512 o4.4 --s-h-r-- vector 0 (RESET) ATmega328P

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1259_msvc -c urclock -P COM6 -p m328p
 -U .\hex\Blink.ino.standard.hex

avrdude_pr1259_msvc: AVR device initialized and ready to accept instructions
avrdude_pr1259_msvc: device signature = 0x1e950f (probably m328p)
avrdude_pr1259_msvc: Note: flash memory has been specified, an erase cycle will be performed.
                     To disable this feature, specify the -D option.
avrdude_pr1259_msvc: erasing chip
                     delaying chip erase until first -U upload to flash
avrdude_pr1259_msvc: reading input file .\hex\Blink.ino.standard.hex for flash
                     with 924 bytes in 1 section within [0, 0x39b]
                     using 8 pages and 100 pad bytes
avrdude_pr1259_msvc: preparing flash input for device bootloader
avrdude_pr1259_msvc: writing 924 bytes flash ...

Writing | ################################################## | 100% 5.24 s

avrdude_pr1259_msvc: 924 bytes of flash written
avrdude_pr1259_msvc: verifying flash memory against .\hex\Blink.ino.standard.hex

Reading | ################################################## | 100% 3.98 s

avrdude_pr1259_msvc: 924 bytes of flash verified

avrdude_pr1259_msvc done.  Thank you.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1259_msvc -c urclock -P COM6 -p m328p -xshowall

avrdude_pr1259_msvc: AVR device initialized and ready to accept instructions
0 2022-06-10 21.21 Blink.ino.standard.hex 924 store 31298 meta 34 boot 512 
o4.4 --s-h-r-- vector 0 (RESET) ATmega328P


PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1259_msvc -c urclock -P COM6 -p m328p -t

avrdude_pr1259_msvc: AVR device initialized and ready to accept instructions
avrdude_pr1259_msvc: device signature = 0x1e950f (probably m328p)
avrdude> dump flash 0x7e00 0x40

Reading | ################################################## | 100% 0.03 s

7e00  11 24 84 b7 14 be 81 ff  f0 d0 85 e0 80 93 81 00  |.$..............|
7e10  82 e0 80 93 c0 00 88 e1  80 93 c1 00 86 e0 80 93  |................|
7e20  c2 00 80 e1 80 93 c4 00  8e e0 c9 d0 25 9a 86 e0  |............%...|
7e30  20 e3 3c ef 91 e0 30 93  85 00 20 93 84 00 96 bb  | .<...0... .....|

avrdude> (CTRL-D)
avrdude_pr1259_msvc warning: programmer is not responding

avrdude_pr1259_msvc done.  Thank you.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1259_msvc -c urclock -P COM6 -p m328p -t

avrdude_pr1259_msvc: AVR device initialized and ready to accept instructions
avrdude_pr1259_msvc: device signature = 0x1e950f (probably m328p)
avrdude> (CTRL-Z a few times)
avrdude> avrdude_pr1259_msvc warning: programmer is not responding

avrdude> avrdude_pr1259_msvc warning: programmer is not responding
avrdude_pr1259_msvc warning: programmer is not responding
avrdude_pr1259_msvc warning: programmer is not responding
(CTRL-D)
avrdude_pr1259_msvc warning: programmer is not responding

avrdude_pr1259_msvc done.  Thank you.

PS C:\work\avr\avrdude_test\avrdude_bin> echo "r fl 0x7e00 0x30" | .\avrdude_pr1259_msvc  -c urclock
 -P COM6 -p m328p -qqt
avrdude> r fl 0x7e00 0x30
7e00  11 24 84 b7 14 be 81 ff  f0 d0 85 e0 80 93 81 00  |.$..............|
7e10  82 e0 80 93 c0 00 88 e1  80 93 c1 00 86 e0 80 93  |................|
7e20  c2 00 80 e1 80 93 c4 00  8e e0 c9 d0 25 9a 86 e0  |............%...|

avrdude>
avrdude> (need to hit CTRL-C to quit).

$ (echo r fl 0x7e00 0x30; echo quit) | ./avrdude_pr1259_msvc  -c urclock -P COM6 -p m328p -qqt
avrdude> r fl 0x7e00 0x30
7e00  11 24 84 b7 14 be 81 ff  f0 d0 85 e0 80 93 81 00  |.$..............|
7e10  82 e0 80 93 c0 00 88 e1  80 93 c1 00 86 e0 80 93  |................|
7e20  c2 00 80 e1 80 93 c4 00  8e e0 c9 d0 25 9a 86 e0  |............%...|

avrdude> quit

$ (echo r fl 0x7e00 0x30; sleep 3; echo r fl 0x7f00 0x30; echo quit) | ./avrdude_pr1259_msvc
  -c urclock -P COM6 -p m328p -qqt
avrdude> r fl 0x7e00 0x30
7e00  11 24 84 b7 14 be 81 ff  f0 d0 85 e0 80 93 81 00  |.$..............|
7e10  82 e0 80 93 c0 00 88 e1  80 93 c1 00 86 e0 80 93  |................|
7e20  c2 00 80 e1 80 93 c4 00  8e e0 c9 d0 25 9a 86 e0  |............%...|

avrdude> r fl 0x7f00 0xavrdude_pr1259_msvc warning: programmer is not responding
30
avrdude_pr1259_msvc warning: programmer is not responding
avrdude_pr1259_msvc warning: programmer is not responding
avrdude_pr1259_msvc error: unable to read flash page at addr 0x7f00
avrdude_pr1259_msvc error: (dump) error reading flash address 0x07f00 of part ATmega328P
                           read operation not supported on memory type flash
avrdude> quit
avrdude_pr1259_msvc warning: programmer is not responding

C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1259_msvc -c urclock -P COM6 -p m328p -qqt
avrdude> dump flash 0x7e00 0x40
7e00  11 24 84 b7 14 be 81 ff  f0 d0 85 e0 80 93 81 00  |.$..............|
7e10  82 e0 80 93 c0 00 88 e1  80 93 c1 00 86 e0 80 93  |................|
7e20  c2 00 80 e1 80 93 c4 00  8e e0 c9 d0 25 9a 86 e0  |............%...|
7e30  20 e3 3c ef 91 e0 30 93  85 00 20 93 84 00 96 bb  | .<...0... .....|
(hit reset on the Uno clone)
avrdude> avrdude_pr1259_msvc warning: programmer is not responding
(hit RETURN)
avrdude> dump flash 0x7e00 0x40
7e00  11 24 84 b7 14 be 81 ff  f0 d0 85 e0 80 93 81 00  |.$..............|
7e10  82 e0 80 93 c0 00 88 e1  80 93 c1 00 86 e0 80 93  |................|
7e20  c2 00 80 e1 80 93 c4 00  8e e0 c9 d0 25 9a 86 e0  |............%...|
7e30  20 e3 3c ef 91 e0 30 93  85 00 20 93 84 00 96 bb  | .<...0... .....|

avrdude> quit

@mcuee
Copy link
Collaborator

mcuee commented Jan 3, 2023

The following is with MSYS2 mingw64 readline as a comparison.

  1. CTRL-Z does nothing or causes time out error, CTRL-D works as quit but there is a warning after that.
  2. pipe can quit properly
  3. Timeout may happen if we have a long sleep, as expected.
  4. Reset the chip and the terminal session can still be alive with a warning message (need to hit RETURN)
PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c urclock -P COM6 -p m328p -qqt
avrdude> (CTRL-D)
avrdude warning: programmer is not responding
PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c urclock -P COM6 -p m328p -qqt
avrdude> (CTRL-Z) avrdude warning: programmer is not responding 
avrdude warning: programmer is not responding
avrdude warning: programmer is not responding
avrdude warning: programmer is not responding
avrdude warning: programmer is not responding
avrdude warning: programmer is not responding
avrdude warning: programmer is not responding
avrdude warning: programmer is not responding
avrdude warning: programmer is not responding
(CTRL-D)
avrdude warning: programmer is not responding
PS C:\work\avr\avrdude_test\avrdude_bin> echo "r fl 0x7e00 0x30" | .\avrdude  -c urclock -P COM6 -p m328p -qqt
avrdude> r fl 0x7e00 0x30
7e00  11 24 84 b7 14 be 81 ff  f0 d0 85 e0 80 93 81 00  |.$..............|
7e10  82 e0 80 93 c0 00 88 e1  80 93 c1 00 86 e0 80 93  |................|
7e20  c2 00 80 e1 80 93 c4 00  8e e0 c9 d0 25 9a 86 e0  |............%...|

avrdude>

$ (echo r fl 0x7e00 0x30; sleep 3; echo r fl 0x7f00 0x30) | ./avrdude  -c urclock -P COM6 -p m328p -qqt
avrdude> r fl 0x7e00 0x30
7e00  11 24 84 b7 14 be 81 ff  f0 d0 85 e0 80 93 81 00  |.$..............|
7e10  82 e0 80 93 c0 00 88 e1  80 93 c1 00 86 e0 80 93  |................|
7e20  c2 00 80 e1 80 93 c4 00  8e e0 c9 d0 25 9a 86 e0  |............%...|

avrdude> r fl 0x7f00 0xavrdude warning: programmer is not responding
30
avrdude warning: programmer is not responding
avrdude warning: programmer is not responding
avrdude error: unable to read flash page at addr 0x7f00
avrdude error: (dump) error reading flash address 0x07f00 of part ATmega328P
               read operation not supported on memory type flash
avrdude>
avrdude warning: programmer is not responding

C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c urclock -P COM6 -p m328p -qqt
avrdude> dump flash 0x7e00 0x40
7e00  11 24 84 b7 14 be 81 ff  f0 d0 85 e0 80 93 81 00  |.$..............|
7e10  82 e0 80 93 c0 00 88 e1  80 93 c1 00 86 e0 80 93  |................|
7e20  c2 00 80 e1 80 93 c4 00  8e e0 c9 d0 25 9a 86 e0  |............%...|
7e30  20 e3 3c ef 91 e0 30 93  85 00 20 93 84 00 96 bb  | .<...0... .....|
(hit reset button on the Uno clone)
avrdude> avrdude warning: programmer is not responding
(hit RETURN and it can recover)
avrdude> dump flash 0x7e00 0x40
7e00  11 24 84 b7 14 be 81 ff  f0 d0 85 e0 80 93 81 00  |.$..............|
7e10  82 e0 80 93 c0 00 88 e1  80 93 c1 00 86 e0 80 93  |................|
7e20  c2 00 80 e1 80 93 c4 00  8e e0 c9 d0 25 9a 86 e0  |............%...|
7e30  20 e3 3c ef 91 e0 30 93  85 00 20 93 84 00 96 bb  | .<...0... .....|

avrdude> q

@mcuee
Copy link
Collaborator

mcuee commented Jan 3, 2023

@stefanrueger and @mariusgreuel

So to me the main problem is with piping (can not quit properly), which is kind of annoying.

time out after some 20 to 30 seconds or so

Just wondering whether the Windows readytoread() sees some events (such as mouse movements, pressing the ctrl/shift/alt key etc) that might make it think there is something to read, but there isn't actually, so reading blocks and the terminal times out...

As for timeout, it does happen to MSYS2 readline version occasionally as well without hitting special modifier keys (CTRL-Shift-Alt etc). I have not reproduced the issue with this PR yet with the Optiboot 4.4 bootloader but I think it will happen sometimes.

Once you hit CTRL/Shift/ALT or even CAPLOCK, I can see the keep-alive fast blinking LEDs are gone and it will cause cause timeout.
As @stefanrueger mentioned, that may be due to the limitation of Windows readytoread() function. It would be nice to fix this as well. But if this can not be easily fixed, I am okay to postpone the fix after 7.1 release.

Copy link
Collaborator

@mcuee mcuee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change in CMake scripts are fine.

There is still one issue I would like to fix, which is the piping problem (need explict "echo quit"..

@mcuee mcuee mentioned this pull request Jan 3, 2023
@mcuee
Copy link
Collaborator

mcuee commented Jan 3, 2023

As for timeout, it does happen to MSYS2 readline version occasionally as well without hitting special modifier keys (CTRL-Shift-Alt etc). I have not reproduced the issue with this PR yet with the Optiboot 4.4 bootloader but I think it will happen sometimes.

I did a test just now, after 30 minutes it did not time out. But sometime later (not so sure when, say after about one hour), it did time out.

avrdude> avrdude_pr1259_msvc error: unable to write: sorry no info avail
avrdude_pr1259_msvc error: unable to write: sorry no info avail
avrdude_pr1259_msvc error: unable to write: sorry no info avail
avrdude_pr1259_msvc error: unable to write: sorry no info avail
avrdude_pr1259_msvc error: unable to write: sorry no info avail
...

@mariusgreuel
Copy link
Contributor Author

@mcuee Thanks for the extra testing.

I looked a little at the problem with time-outs yesterday, and it appears that avrdude gets stuck while calling rl_callback_read_char, and hence term_keep_alive is no longer called. The problem occurs on a 'virtual keypress', such as just pressing CTRL.

It is a problem with the WIN32 readytoread implementation in combination with rl_getc. Either readytoread needs to perform more filtering, or rl_getc needs to return some special value to indicate there were only virtual events in the queue. I will see into this.

@stefanrueger
Copy link
Collaborator

@mariusgreuel If you have control over rl_getc() then it's probably easiest for readytoread() to actually reading one character with a timeout (say 100 ms). If it receives a character it can be stashed away to be returned by rl_getc() that is called by readline. If it times out, well it returns a zero giving control back to the terminal that can keep the board alive.

@stefanrueger
Copy link
Collaborator

control over rl_getc()

Apparently it's possible to roll it yourself: From https://tiswww.case.edu/php/chet/readline/readline.html

Variable: rl_getc_func_t * rl_getc_function

If non-zero, Readline will call indirectly through this pointer to get a character from the input stream. By default, it is set to rl_getc, the default Readline character input function (see Character Input). In general, an application that sets rl_getc_function should consider setting rl_input_available_hook as well.

@mcuee
Copy link
Collaborator

mcuee commented Jan 3, 2023

To debug the pipe issue, I was thinking that the older version of readline used here (5.00) may have some issues similar to libedit, as seen in PR #1207.

So I apply the following patch and it indeed sorted out the pipe issue.

WIth this mod, it seems to me this PR is good enough for 7.0 release. We can fix the remaining issues later. But of course it will be even better to fix the WIN32 readytoread implementation.

  1. Keep alive is still working
  2. Pipe works as well
  3. Timeout may happen if we have a long sleep (not a major problem).
  4. Reset the chip and the terminal session can still be alive with a warning message (need to hit RETURN)
PS C:\work\avr\avrdude_test\avrdude-fork> git diff
diff --git a/src/term.c b/src/term.c
index 1d36b68d..fa9f46f3 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1432,7 +1432,7 @@ int terminal_mode(PROGRAMMER *pgm, struct avrpart *p) {
   // EditLine (NetBSD, MacOS) has issues with that, so only use it when
   // running interactively.
   // EditLine uses version 4.2 (0x0402).
-  if (isatty(fileno(stdin)) || (rl_readline_version >= 0x0500))
+  if (isatty(fileno(stdin)) || (rl_readline_version > 0x0500))
     return terminal_mode_interactive(pgm, p);
 #endif
   return terminal_mode_noninteractive(pgm, p);

PS C:\work\avr\avrdude_test\avrdude-fork> cd . .\avrdude_bin\
PS C:\work\avr\avrdude_test\avrdude_bin> cp ..\avrdude-fork\out\build\x64-Release\src\avrdude.exe 
.\avrdude_pr1259_msvc_mod.exe

PS C:\work\avr\avrdude_test\avrdude_bin> echo "r fl 0x3e00 0x40" | .\avrdude_pr1259_msvc_mod
 -c urclock -P COM3 -p m168p -t

avrdude_pr1259_msvc_mod: AVR device initialized and ready to accept instructions
avrdude_pr1259_msvc_mod: device signature = 0x1e940b (probably m168p)
avrdude>
Reading | ################################################## | 100% 0.04 s

3e00  01 c0 b7 c0 11 24 84 b7  90 e8 90 93 61 00 10 92  |.....$......a...|
3e10  61 00 88 23 61 f0 98 2f  9a 70 92 30 41 f0 81 ff  |a..#a../.p.0A...|
3e20  02 c0 97 ef 94 bf 28 2e  80 e0 c6 d0 e9 c0 85 e0  |......(.........|
3e30  80 93 81 00 82 e0 80 93  c0 00 88 e1 80 93 c1 00  |................|

avrdude>
avrdude_pr1259_msvc_mod done.  Thank you.

@stefanrueger
Copy link
Collaborator

@mcuee Good catch. I've changed the threshold straight away, which reduces the problem set for Windows.

@mariusgreuel
Copy link
Contributor Author

mariusgreuel commented Jan 3, 2023

I managed to filter the relevant events in readytoread, however, the library is still giving me trouble. Apparently, readline 5.0 does not return from rl_callback_read_char when certain key combos such as CTRL-R are pressed, but is stuck in its own loop. It seems this behavior got fixed somewhere between 5.0 and 8.0. Which makes me think I am not really keen on merging the Windows patches into the 7.1 release...

I have to do some more digging...

@mcuee
Copy link
Collaborator

mcuee commented Jan 3, 2023

I managed to filter the relevant events in readytoread, however, the library is still giving me trouble. Apparently, readline 5.0 does not return from rl_callback_read_char when certain key combos such as CTRL-R are pressed, but is stuck in its own loop. It seems this behavior got fixed somewhere between 5.0 and 8.0. Which makes me think I am not really keen on merging the Windows patches into the 7.1 release...

I have to do some more digging...

@mariusgreuel

Yes that one seems to be the hard part.

I will agree with you here not to merge this PR into 7.1 release. You have done a lot to get this PR into this kind of working stage, I think we can try something after 7.1 release.

One possible debugging option to see if Windows GNU Readline 8.0 really fix the issue is to dynamic link to the MSYY2 MinGW libreadline.dll to see if that helps to sort out the issue. You will also need libtermcap.dll in that case.

@stefanrueger
Copy link
Collaborator

filter the relevant events in readytoread

@mariusgreuel Sounds great. Would you want to merge these into the current readytoread() before 7.1 is released? It's better to lose connection on ctrl-R only rather than every touch of shift, ctrl, caps lock, fn-key, alt key ...

@mcuee
Copy link
Collaborator

mcuee commented Jan 3, 2023

Current PR behavior.

  1. Keep alive is still working
  2. Pipe works as well
  3. Timeout may happen if we have a long sleep (not a major problem).
  4. Reset the chip and the terminal session can still be alive with a warning message (need to hit RETURN)
  5. CTRL/SHIFT/ALT and CAPSLOCK will cause time out. This seems to be one of the main issue.
  6. CTRL-D will be able to quit, albeit with a warning.
PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1259_msvc_v1 -c urclock -P COM3 -p m168p -t
avrdude> CTRL-D
avrdude_pr1259_msvc_v1 warning: programmer is not responding

avrdude_pr1259_msvc_v1 done.  Thank you.
  1. CTRL-R will prompt something strange
PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1259_msvc_v1 -c urclock -P COM3 -p m168p -t

avrdude_pr1259_msvc_v1: AVR device initialized and ready to accept instructions
avrdude_pr1259_msvc_v1: device signature = 0x1e940b (probably m168p)
(reverse-i-search)`':

@stefanrueger
Copy link
Collaborator

stefanrueger commented Jan 3, 2023

(reverse-i-search)

Ahhh - reverse incremental search in the history of previously typed commands. Type fox and you will get the last w ee 17 "the quick brown fox.... command. Splendid.

@stefanrueger
Copy link
Collaborator

| 4. Reset the chip and the terminal session can still be alive with a warning message (need to hit RETURN)

This is not really a feature, and we shouldn't expect this to work...

@mcuee
Copy link
Collaborator

mcuee commented Jan 4, 2023

Since this PR is not ready, the official 7.1 Windows binary will be using MSVC build without GNU Readline support.

  1. Keep alive will not work, terminal mode -c urclock -t will not work as it will time out.
  2. Pipe will work and it will be used as a workaround.

This will be the same as default MSYS2 mingw32/mingw64 build, which is without GNU Readline support.

@stefanrueger and @mariusgreuel
In this case, I am thinking we need to promote the warning message up a bit. Right now only -vv will print out the warning.

Another thing is that the shell command echo "d fl 0 32; quit" | tr \; \\n | avrdude -t -curclock does not work for Windows CMD or Powershell. Maybe we can just say echo "dump flash 0 32" | avrdude -t -curclock

But I am okay if you think no need to change.

PS C:\work\avr\avrdude_bin\avrdude_git-msvc-x64> .\avrdude -c urclock -P COM3 -p m168p -t -vv

avrdude: Version 7.0-20230103 (8b0c998)
         Copyright the AVRDUDE authors;
         see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

         System wide configuration file is C:\work\avr\avrdude_bin\avrdude_git-msvc-x64\avrdude.conf

avrdude: compiled without readline library, cannot use avrdude -t -c urclock interactively
         but it is still possible to pipe: echo "d fl 0 32; quit" | tr \; \\n | avrdude -t -curclock
...
...

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.07 s

avrdude: device signature = 0x1e940b (probably m168p)
avrdude>

PS C:\work\avr\avrdude_bin\avrdude_git-msvc-x64> echo "d fl 0 32; quit" | tr \; \\n |.\avrdude -c urclock -P COM3 -p m168p -t
C:\Program Files (x86)\Atmel\AVR Tools\AVR Toolchain\bin\tr.exe: missing operand after `\\'
Two strings must be given when translating.
Try `C:\Program Files (x86)\Atmel\AVR Tools\AVR Toolchain\bin\tr.exe --help' for more information.
\\n: The term '\\n' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

PS C:\work\avr\avrdude_bin\avrdude_git-msvc-x64> echo "d fl 0 32; quit" |.\avrdude -c urclock -P COM3 -p m168p -t

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e940b (probably m168p)
avrdude> Usage: d <memory> <addr> <len>
       d <memory> <addr> ...
       d <memory> <addr>
       d <memory> ...
       d <memory>
avrdude>
avrdude done.  Thank you.

PS C:\work\avr\avrdude_bin\avrdude_git-msvc-x64> echo "d fl 0 32" |.\avrdude -c urclock -P COM3 -p m168p -t

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e940b (probably m168p)
avrdude>
Reading | ################################################## | 100% 0.02 s

0000  0c 94 61 00 0c 94 73 00  0c 94 73 00 0c 94 73 00  | .a. .s. .s. .s.|
0010  0c 94 73 00 0c 94 73 00  0c 94 73 00 0c 94 73 00  | .s. .s. .s. .s.|

avrdude>
avrdude done.  Thank you.

@mcuee
Copy link
Collaborator

mcuee commented Jan 4, 2023

The arduino-pack version will use MinGW32 and GNU Readline, similar to MSYS2 mingw32 build with GNU Readline.

  1. Keep alive will work. -c urclock -t will work.
  2. Pipe works as well
  3. Timeout may happen if we have a long sleep (not a major problem).
  4. CTRL/SHIFT/ALT and CAPSLOCK will cause time out. This seems to be one of the main issue.

But to me it is still quite acceptable to live with Issue No 4 for Arduino, since they do not really care about terminal mode.

@mcuee
Copy link
Collaborator

mcuee commented Jan 4, 2023

@umbynos

Just FYI as well. I believe the terminal mode limitation is of no concerns to Arduino.

@mcuee
Copy link
Collaborator

mcuee commented Jan 4, 2023

@mariusgreuel

Just wondering if you know what will be the equivalent for the following two under Windows CMD prompt. Thanks.

echo "d fl 0 32; quit" | tr \; \\n | ./avrdude -c urclock -P COM6 -p m328p -qqt
(echo r fl 0x7e00 0x30; sleep 3; echo r fl 0x7f00 0x30; echo quit) | ./avrdude -c urclock -P COM6 -p m328p -qqt

@mariusgreuel
Copy link
Contributor Author

As I do not see how to get this PR production ready anytime soon, here is an old idea that I would like to resurrect: #1264

@mcuee
Copy link
Collaborator

mcuee commented Jan 4, 2023

@mariusgreuel

Wonderful job. PR #1264 exceeded my expectations! I will only request a minor version update as it works better than Readline 5.0 for Windows.

C:\work\avr\avrdude_test\avrdude-fork [pr-msvc-readline-plan-b ≡ +0 ~1 -0 !]> git diff
diff --git a/src/msvc/readline.cpp b/src/msvc/readline.cpp
index 786bf247..667ff7ad 100644
--- a/src/msvc/readline.cpp
+++ b/src/msvc/readline.cpp
@@ -13,7 +13,7 @@
 #include "readline/readline.h"
 #include "readline/history.h"

-int rl_readline_version = 0x0500;
+int rl_readline_version = 0x0502;

 static char* rl_prompt;
 static rl_vcpfunc_t* rl_handler;

@mariusgreuel
Copy link
Contributor Author

Closing this in favor of #1264.

@mcuee
Copy link
Collaborator

mcuee commented Jan 5, 2023

(echo r fl 0x7e00 0x30; sleep 3; echo r fl 0x7f00 0x30; echo quit) | ./avrdude -c urclock -P COM6 -p m328p -qqt

In the end I convert this into a batch file for Windows CMD and Powershell.
Edit: this is not correct.

C:\work\avr\avrdude_test\avrdude_bin> cat .\test1.bat
@echo off
echo r fl 0x7e00 0x30 |.\avrdude_pr1264_msvc_v1 -c urclock -P COM6 -p m328p -qqt
timeout 10 > nul
echo r fl 0x7f00 0x30 |.\avrdude_pr1264_msvc_v1 -c urclock -P COM6 -p m328p -qqt
@echo on
C:\work\avr\avrdude_test\avrdude_bin> .\test1.bat
avrdude> 7e00  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
7e10  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
7e20  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

avrdude>
avrdude> 7f00  fa 9a f9 9a 31 96 da 13  f4 cf 23 c0 a0 e0 b1 e0  |....1.....#.....|
7f10  4d d0 1f c0 c3 30 41 f4  33 d0 c8 2f 3d d0 85 91  |M....0A.3../=...|
7f20  1b d0 c1 50 e1 f7 15 c0  c1 30 71 f4 29 d0 c8 2f  |...P.....0q.)../|

avrdude>
C:\work\avr\avrdude_test\avrdude_bin>

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

Successfully merging this pull request may close these issues.

Readline support for MSVC
3 participants