simavr USB and atmega32u4

151 views
Skip to first unread message

Flop

unread,
Jun 28, 2015, 11:18:30 AM6/28/15
to sim...@googlegroups.com
Hello list,

I'm trying to get simavr to work with the ATmega32u4 which uses a USB serial.

The sketch I'm using is a simple code that reads the serial and echo back everything it receives (compiled .hex attached):

int incomingByte = 0;    // for incoming serial data

void setup() {
   
Serial.begin(9600);    // opens serial port, sets data rate to 9600 bps
}

void loop() {
 
if (Serial.available() > 0) {
    incomingByte
= Serial.read();
   
Serial.print((char)incomingByte);
 
}  
}

Also attached to this post is the sim_mega32u4.c definition file that I wrote using the datasheet, the AVR-libc headers and the help of other sim_*.c cores.
The USB definition is taken from the other USB core sim_90usb162.c which was already there.

When I run this sketch with simusb, the device /dev/ttyACM0 appears as expected, and I'm able to connect with minicom and type some chars on the keyboard.
However, I observe that the code loops on Serial.available() because the return value is always 0, which means no data is available on the serial line.

Then I tried to track down the problem by adding print statements here and there, and it looks like the one-char buffer passes through:
  • the vhci_usb_thread loop
  • avr_ioctl(p->avr, AVR_IOCTL_USB_READ, &pkt) in vhci_usb.c
  • avr_usb_ioctl, in avr_usb.c, which goes in the case AVR_IOCTL_USB_WRITE
  • and finally ep_fifo_usb_write() in avr_usb.c

In this file, it looks like we encounter the following line, and apparently the running core never gets the character. At least it's how I understand it.

        if (epstate->ueintx.rxouti) {
               
return AVR_IOCTL_USB_NAK;
       
}

I'm a little bit short on new ideas and what to check in order to get this working.

Any ideas ? Does this sound it comes from my core definitions ? From something else ?


On a side note, the vhci kernel module and library from the git repos mentioned in the USB readme of simavr seem to compile and run without the need for the provided patches.

sketch_jun28a.cpp.hex
sim_mega32u4.c

Flop

unread,
Jun 28, 2015, 12:42:52 PM6/28/15
to sim...@googlegroups.com
Le dimanche 28 juin 2015 17:18:30 UTC+2, Flop a écrit :
Hello list,

I'm trying to get simavr to work with the ATmega32u4 which uses a USB serial.

I forgot to mention, the sketch was compiled with the arduino IDE and an Arduino Micro as build target (it uses the Atmega32u4 of course).
Hence the IDE automatically added all the code and headers necessary for USB and Serial communications to the sketch.

best regards

Flop

unread,
Jun 28, 2015, 2:47:55 PM6/28/15
to sim...@googlegroups.com
I've added some debug to avr_usb.c, here is a few lines that look relevant:

pkt cnt 0, buf len 1, buf contents: c
ep_fifo_usb_write: return success
raise_ep_interrupt: irq num 2
pkt cnt 0, buf len 1 buf contents: d
ep_fifo_usb_write: no write: rxouti is set
buf: d
pkt cnt 0, buf len 1 buf contents: e
ep_fifo_usb_write: no write: rxouti is set
buf: e

this is what happens when I type the letters "cde" into the minicom.

So if I interpret this correctly, it seems that the first typed char, which is "c" is "sent" to the core, but then, all subsequent characters that are typed cannot be sent because RXOUTI is set.

Unfortunately I can't break where I want using avr-gdb because it doesn't want to place breakpoints in the flash region (see my other thread), so I'm not able to check in the simulated core is this first character is indeed gotten...
Still trying harder !

regards
Reply all
Reply to author
Forward
0 new messages