October 12, 2024, 03:29:49 PM

USB communication in DM 2.7

Started by KeesZagers, October 16, 2012, 02:22:55 PM

Previous topic - Next topic

KeesZagers

Not sure if I should use this forum or a mail directly to support for this. However I think others also ran into these problems and I think I have a solution for them.

Problems are only related to the USB terminal communication.

1. When connection with USB terminal is made after the first keypress the bootup message is diplayed. However this message is terminated after "www.olimex.com," and the "Based On MMBasic By Geoff Graham" is skipped or part of it is displayed after the prompt. Spitting into the sources I discovered that this was due to the fact that the maximum USB-Tx-buffer is limited to 64 bytes and the buffer is copied to the USB port only once, so only 64 bytes are displayed. As far as I could determine there was no reason why this buffer could not be bigger, so I made it 256 bytes and the complete message is displayed now.

2. I hoped that the solution for problem 1 would also solve my other problem. Unfortunately it was not the case. When printing strings I detected that sometimes parts of the string were duplicated on a line (only on the USB terminal; not on the video output). First I thought this had to do something with the terminal program (Teraterm), however when using Hyperterm the same thing happened. So I wrote a simple testprogram:

10 CLS
20 TIMER=0
30 FOR x=10000 TO 20000
40 PRINT x,"012345678901234567890123456789"
50 PAUSE 1
60 NEXT
70 PRINT TIMER
>

The program first run gave 7 errorlines; second one 8. The errors are random. An examples is:

14081  012345678901234567890123456789
14082  01234567890123414082    0123567890123456789
14083  012345678901234567890123456789

Leaving out the delay in line 50 resulted in even more errors. A longer delay in line 50 did not cure the problem.
As I'm looking for an application where I'm using the USB port also for direct logging information on another system, this was unacceptable for me.

In the sources I found that the PRINT command is copying the characters one-by-one in the USB Tx buffer and an ISR routine for USB is copying the buffer to the USB port and emptying the buffer. So 2 independant processes. Every now and then this however seems not to function.

As I increased the maximum Tx buffer to 256, it should be possible to fit a complete string into the buffer. So I disabled the sending of the Tx buffer when a PRINT command is started and enabled it again at the end. After that I created a short delay to be sure that an USB interrupt has occured again before the next PRINT.

This seems to work fine. I also tested it with a 240 byte string, without any problem. Only 3 files (main.c, commands.c and mmbasic.h) are modified. I can mail them to Olimex or maybe upload them anywhere.

BTW I also tested the program on MMBasic4. I did not find the problem in there anymore, but I was supprised about the timing:

The timer at the end of the program gave the following results (with both USB and video connected):

Original DM 2.7004: 49970
The fixed software: 49971
MMBasic 4: 76188

Conclusion good to have more functionality, but the performance is worse.

Anyway I have the impression that the implementation of the PRINT command could be optimised. If I run the testprogram with a string of 240 bytes, the program runs for more than 4.5 minutes.

Cheers

Kees

olimex

my guess is that you overflow the USB buffer

KeesZagers

Sorry, I'm not reporting a problem. I'm giving a solution for an existing problem.

And I'm sure it is not an overflow of the USB buffer. Standard the USB Tx bufer is 64 bytes. If you print a message of 30 or 40 bytes, every now and then it goes wrong, even if you pause 10 msec between the print statements. In my opinion it depends on which stage the PRINT command is, when the USB interrupt occurs.

At least the problem is solved for me by now. If you want others to make profit of it, I'm willing to help.

Kees

olimex

sorry I didnt read carefully you message
you can make pull request on github with your changes, we will review and merge

KeesZagers

I have no experience further experience with github, but probably I have to registrate if I want to upload files. I don't like that for the moment.

So I made a ZIP (including readme) of the changes and uploaded that to my own website. Here you can find it:

http://www.si-kwadraat.nl/olimex/changes18102012.zip

olimex

thanks! this works also, I will apply these changes