AVR-Doper with 16Mhz crystal

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
mvdoornik
Posts: 2
Joined: Wed Aug 15, 2007 9:22 am

AVR-Doper with 16Mhz crystal

Post by mvdoornik » Fri Aug 31, 2007 2:42 pm

Hi,

Previously, I have programmed an ATMega8535 @ 16Mhz with the HID Bootloader code, which works fabulously. With avr-gcc, I can now program the entire thing in C from Vim with a single press of <F5> using nothing more than just a USB connection. Sweet! What more could I possibly want? ;-)

Well...

Just to get a feel for the possibilities, I've downloaded the AVR-Doper package. As the USB pinout matches what I have (Port D pins 2 and 3), I figured it would be easy. First try at compiling the original code worked a treat, no problems at all. After adding

Code: Select all

#define USB_CFG_CLOCK_KHZ 16000

to usbconfig.h, compiling fails:

Code: Select all

$ make
avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=atmega8535 -DDEBUG_LEVEL=0 -x assembler-with-cpp -c usbdrv/usbdrvasm.S -o usbdrv/usbdrvasm.o
usbdrv/usbdrvasm16.S: Assembler messages:
usbdrv/usbdrvasm16.S:226: Error: operand out of range: 64
make: *** [usbdrv/usbdrvasm.o] Error 1


So, what am I missing here? I'm using avr-gcc 4.1.0 on Ubuntu Feisty 7.04.

Any help is appreciated, as I really want to get this USB stuff (especially serial communication and HID devices, think 'Arduino') going!

Marc.

Grendel
Rank 4
Rank 4
Posts: 167
Joined: Sat Dec 16, 2006 9:53 pm
Location: Oregon, USA
Contact:

Post by Grendel » Fri Aug 31, 2007 11:24 pm

You also have to change F_CPU in hardware.h BTW.

Just tried it w/ the doper version currently up for grabs -- after switching to 16MHz, latest WinAVR (avr-gcc 4.1.2, avr-libc 1.4.6) errors when linking:

Code: Select all

avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=atmega8 -DDEBUG_LEVEL=0 -o main.bin usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o hvprog.o isp.o serial.o stk500protocol.o timer.o utils.o vreg.o main.o
usbdrv/usbdrvasm.o: In function `overflow':
usbdrv/usbdrvasm.s: (.text+0x14e): relocation truncated to fit: R_AVR_7_PCREL against `no symbol'
make: *** [main.bin] Error 1

Branch out of range ?

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

Post by christian » Sat Sep 08, 2007 8:30 pm

Yes, the relative branch range is exceeded by one instruction if all endpoints are enabled (as it is required for AVR-Doper).

You can fix this by moving the code block around handleIn3:

Code: Select all

#if USB_CFG_HAVE_INTRIN_ENDPOINT && USB_CFG_HAVE_INTRIN_ENDPOINT3
handleIn3:
    lds     cnt, usbTxLen3      ;[43]
    sbrc    cnt, 4              ;[45]
    rjmp    sendCntAndReti      ;[46] 48 + 16 = 64 until SOP
    sts     usbTxLen3, x1       ;[47] x1 == USBPID_NAK from above
    ldi     YL, lo8(usbTxBuf3)  ;[49]
    ldi     YH, hi8(usbTxBuf3)  ;[50]
    rjmp    usbSendAndReti      ;[51] 53 + 12 = 65 until SOP
#endif


just before the bitstuffN label:

Code: Select all

#if USB_CFG_HAVE_INTRIN_ENDPOINT    /* placed here due to relative jump range */
handleIn1:                      ;[38]
#if USB_CFG_HAVE_INTRIN_ENDPOINT3
; 2006-06-10 as suggested by O.Tamura: support second INTR IN / BULK IN endpoint
    ldd     x2, y+2             ;[38]
    sbrc    x2, 0               ;[40]
    rjmp    handleIn3           ;[41]
#endif
    lds     cnt, usbTxLen1      ;[42]
    sbrc    cnt, 4              ;[44] all handshake tokens have bit 4 set
    rjmp    sendCntAndReti      ;[45] 47 + 16 = 63 until SOP
    sts     usbTxLen1, x1       ;[46] x1 == USBPID_NAK from above
    ldi     YL, lo8(usbTxBuf1)  ;[48]
    ldi     YH, hi8(usbTxBuf1)  ;[49]
    rjmp    usbSendAndReti      ;[50] 52 + 12 + 64 until SOP
#endif

#if USB_CFG_HAVE_INTRIN_ENDPOINT && USB_CFG_HAVE_INTRIN_ENDPOINT3
handleIn3:
    lds     cnt, usbTxLen3      ;[43]
    sbrc    cnt, 4              ;[45]
    rjmp    sendCntAndReti      ;[46] 48 + 16 = 64 until SOP
    sts     usbTxLen3, x1       ;[47] x1 == USBPID_NAK from above
    ldi     YL, lo8(usbTxBuf3)  ;[49]
    ldi     YH, hi8(usbTxBuf3)  ;[50]
    rjmp    usbSendAndReti      ;[51] 53 + 12 = 65 until SOP
#endif

; USB spec says:
; idle = J
; J = (D+ = 0), (D- = 1)
; K = (D+ = 1), (D- = 0)
; Spec allows 7.5 bit times from EOP to SOP for replies

bitstuffN:
    eor     x1, x4          ;[5]
    ldi     x2, 0           ;[6]
    nop2                    ;[7]
    nop                     ;[9]
    out     USBOUT, x1      ;[10] <-- out
    rjmp    didStuffN       ;[0]

mvdoornik
Posts: 2
Joined: Wed Aug 15, 2007 9:22 am

Post by mvdoornik » Tue Sep 18, 2007 3:56 pm

Thanks, Christian! As soon as I can find the time, I'll check it out. Unfortunately, work dictates otherwise at present...

Post Reply