-
Notifications
You must be signed in to change notification settings - Fork 155
Fix r/w timeout for Windows ser_send()
#1987
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
Conversation
Difficulty in testing -- how to get working programmer or bootloader to test this PR, eg, working bootloader FW at 100bps/200bps/300bps. |
Example: urboot autobaud bootloader, 16MHz crystal, ATmega2560, CH340.
|
By accident, I was able to reproduce Issue #1986 with a Bluetooth COM port under my Dell Windows 11 Laptop. And I can confirm that this PR fixed the issue. |
Just wondering if you can provide working low baud rate bootloader hex files for Arduino Mega2560 or Arduino Uno, eg, 100bps, 200bps, 300bps and 600bps, if that is even possible. |
Easy: replace
Fixed-rate bootloaders can have a theoretical baud rate range in [F_CPU/16/4096, F_CPU/8/1]. Using the internal 8 MHz clock, you can go down to 150 baud. However, the parser for
8000
... and later set the |
Edit: factory F_CPU is 1 MHz, not 8 MHz, so, you'd need to burn a 1760 baud bootloader (= 110*16) for a 16 MHz F_CPU and then switch to internal F_CPU of 1 MHz to experience 110 baud. Edit edit:
But that needs the |
Autobaud is limited to [F_CPU/8/256, F_CPU/8] but even there has a few blindspots owing to the nature of the integer baud rate division in classic parts. |
Just to say, git main now parses an expanded baud interval of [10 baud, 8 Mbaud] irrespective of whether that's achievable with the given F_CPU. So can ask for 110 baud bootloaders at 1 MHz F_CPU using |
Somehow it does not work at 300bps. I tried 600bps and 1200 bps and both do not work. 2400bps works.
|
2400bps -- working with 16MHz crystal.
Now we change the clock configuration.
Now urboot is supposed to work with 1200 bps (from 16MHz CPU clock down to 8MHz internal clock). Unfortunately it does not work.
Same if I further reduce the internal clock to 1MHz and still it does not work with 150 bps.
|
External clock 16MHz --> 1200bps does not work. But no regression from this PR either, same behavior as avrdude 8.0 release.
|
Internal clock 8MHz --> 1200bps does not work. But no regression from this PR either, same behavior as avrdude 8.0 release.
|
Internal clock 1MHz, no regressions. When it failed, this PR also gives a bit more info.
|
I think this PR is good to go. It sorted out Issue #1986. And the good thing is that I do not see regressions either. |
Not so sure if the following is related to #1982, but git main and this PR works better than avrdude 8.0. 1MHz internal clock, 1800 bps.
|
Same for ATmega328P, 16MHz crystal, 2400bps works, 1200bps do not work. 1800bps --> avrdude 8.0 release does not work. git main and this PR both work.
|
Thanks for verifying that 2400 baud works. I have no idea why 300 baud doesn't. Here is the difference of the two bootloaders:
That difference is down to the initialisation of the 12-bit
The baud rate formula for the asynchronous normal mode ( So, in one case (UBRR0 = 0x0d04) it is 300.03 baud and in the other case (UBRR0 = 0x01a0) it is 2398.08 baud. And, as is usual for 16-bit registers, the high byte is written before the low byte... |
Maybe for lower baud rates the WDT timeout needs increasing? As in |
Hmm. I doubt #1982 has anything to do with this. Internal clocks of classic parts are notoriously inaccurate. F_CPU varies with temperature, too. So handling a board could well move F_CPU. Best to measure F_CPU with a second MCU (say, by timing the period of a blinking LED) and use that frequency for creating a bootloader. |
I understand that the internal clock is not accurate. So the 1MHz internal clock is just for refernce. But I have also done the tests with external 16MHz crystal for both ATmega2560 and ATmega328. The accuracy at room temperature should be pretty decent. The conclusion from my tests are the same.
|
Come to think of that, there is an awful amount of tinkering in |
ATmega328P (Arduino Uno CH340 Clone). Internal 8MHz clock, working up to 2400 bps.
|
Same for 1MHz internal clock.
|
@mcuee Very, very cool experiments. This makes clear that |
PS: I no longer think upping WDT timeout will help |
Low baud rate issue of urboot has been addressed in PR #1993. |
This PR should be good to go as it fixes Issue #1986. |
Fixes #1986.
First there is no bus for 20 years and then there are two buses within a couple of days (unrelated edge cases in low-level serial I/O: one for Posix in PR 1983, the other one for Windows...).
Should be thoroughly tested with serial I/O, best with large parts with large page sizes and low baud rates.