HIDKeys and UART

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply

HIDKeys and UART

Post by jarekk » Tue Jul 31, 2007 12:55 pm

Hi everybody,

I've got an intriguing question on HIDkeys and UART.
My firmware should run in the following way:
whenever the attiny2313 running HIDkeys receives a message on the
UART it should simulate pressing a key on the keyboard. The HIDkeys runs
without problems, with a button attached to the attiny I can make it work fine.

Unfortunately I have strange problems with UART. The following is the main loop
of "my" (yeah, it is rather yours) firmware.

//wdt_reset(); /* watchdog is DISABLED for now */
if(UCSRA & (1 << RXC)){
// received data, pull that data out of the internal buffer
//if (j=='d') {

if (state!=STATE_IDLE && usbInterruptIsReady()) {
if (state==STATE_SEND_KEY_DOWN) {
key = 1;
} else if (state==STATE_SEND_KEY_UP) {
key = 0;
usbSetInterrupt(reportBuffer, sizeof(reportBuffer));

If defined this way, it works -- every time I get something on the USART (and here
it doesn't matter what it is), a key-press is simulated.
Now the strange thing comes: when I enable the innocent "if (j=='d')" the whole
thing stops working. Whenever I send something on the UART ('d' or not 'd'), the
firmware seems to reset, i.e. a new enumeration is started on windows. The device
fails to simulate any key presses.

When I was trying to make this run at all (without UART, with a button) I have had
this strange resettings already. I had the impression that it was sometimes
one line of simple code added in the main-loop which made this happen. This looks
a little like timing problems to me, but I do not have an idea why exactly this
could have happened.

Do you have an idea in which direction I should look? If you have any concrete
tests I could run, let me know, I'll be happy to provide you with more information.



Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Wed Aug 01, 2007 4:43 pm

This looks like a stack overflow to me. The device would not suffer a RESET otherwise. Or a hardware problem which triggers brownout or other sources of reset.

Post Reply