Error: Constant Value Required

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
darvelo
Posts: 6
Joined: Thu Jan 14, 2010 2:11 am

Error: Constant Value Required

Post by darvelo » Thu Jan 14, 2010 2:17 am

Hey all,

I'm trying to compile a project from http://www.raphnet.net/electronique/snes_nes_usb/index_en.php, which was originally designed for the ATmega8, over to the chip ATmega88PA.

I've ported over all the registers, bits, and fuses according to http://www.atmel.com/dyn/resources/prod_documents/doc2553.pdf and I read on this thread: http://forums.obdev.at/viewtopic.php?f=8&t=2663 that there was an issue with the definition of an interrupt, which I changed to the proper "INT0_vect" value in usbdrvasm.S.

Now, when I compile the project, the compiler AVR Studio/avr-gcc gives me a ton of the same error in file usbdrvasm12.S, which is "Constant value required".

I'm using an ATmega88PA with a 12Mhz crystal. F_CPU is set to 12000000L. Any help would be appreciated much. Thanks!

darvelo
Posts: 6
Joined: Thu Jan 14, 2010 2:11 am

Re: Error: Constant Value Required

Post by darvelo » Thu Jan 14, 2010 4:48 am

Well, I used the latest source files from the V-USB download area and the problem went away. I had to hardcode "#define USBATTR_BUSPOWER 0x80" since there was an error with the definition missing and the original source code needed it.

The code compiles, but the USB device is not recognized, and is listed under Windows Device Manager as "Unknown Device." Is there any way I can debug this?

UPDATE: I found that the "Unknown Device" was actually my AVR programmer plugged into the ISP header. When I take it out and unplug and reinsert the USB connector from the board, nothing happens. No audio notification from Windows that a device has been connected, and no visual indicators either. What could be wrong? I'm using the bare hid-data project from the examples folder and an ATmega88PA. Please help.

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Error: Constant Value Required

Post by ulao » Sun Jan 17, 2010 6:31 am

I ported his code over to an 168 same as your chip for the most part, but not the P... That may be the issue..

I had some struggles but was able to make it work. Make sure you do not use 1 watt diods.. They will not work, use 1/2. This goes for all 88/168 chips.

Well, I used the latest source files from the V-USB download area and the problem went away.
Ralphs code had some older files, I had this issue also. And I had to define USBATTR_BUSPOWER as well.

darvelo
Posts: 6
Joined: Thu Jan 14, 2010 2:11 am

Re: Error: Constant Value Required

Post by darvelo » Sun Jan 17, 2010 7:18 pm

Thanks, I just ordered 500mW zener diodes since i was using 1W. I hope this fixes it. I was thinking that the problem could be with my 12MHz crystal or fuses because of what I describe below. I put this code in the infinite for loop to blink an LED every second:

Code: Select all

    for(;;){                /* main event loop */
 //       DBG1(0x02, 0, 0);   /* debug output: main loop iterates */
        wdt_reset();
        usbPoll();
      if(led_on == 1) {
         PORTC &= ~_BV(4);  // turn LED off
         led_on = 0;
         _delay_ms(1000);   // delay 1 second
      }else{
         PORTC |= _BV(4);   // turn LED on
         led_on = 1;
         _delay_ms(1000);
      }
    }
    return 0;

and the LED blinks very erratically. It looks like it blinks on for a second, then dims for about half a second, then full brightness for a second. So I took out the V-USB code completely:

Code: Select all

#define F_CPU 12000000L
#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
   int led_on = 0;
   DDRC = 0x08; // configure output on pin 3

   while(1)
   {
      PORTC |= 0x08;  // output voltage on pin 3
      _delay_ms(1000);
      PORTC &= ~0x08;  // clear voltage on pin 3
      _delay_ms(1000);
   }
    return 0;
}

and the LED stays on forever. Does this sound like a problem with my 12MHz crystal or fuses? I placed it exactly like in the V-USB diagram on pins 9 and 10 with a 20pF cap like the datasheet asked for with fuses E: 0xF9, H: 0xDD, L: 0xDF.

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Error: Constant Value Required

Post by ulao » Mon Jan 18, 2010 12:02 am

Well if you have 1w's in there that is a problem period. As far as the blinks go, it look good? Your fuse are correct.. Here is my blink code but I dont see why yours wont work.


I use the ground for the light not +5..

Code: Select all


#define LED_OFF() do { PORTD |= 0x20; } while(0)
#define LED_ON() do { PORTD &= ~0x20; } while(0)


static void blinkLed(int n_times)
{
if (n_times == 0 )  return;
char i;
DDRD |= 0x20;
   LED_OFF();
   while (n_times--)
   {
      LED_ON();
      for (i=0; i<20; i++) _delay_ms(10);
      LED_OFF();
      for (i=0; i<50; i++) _delay_ms(10);
   }   

}

darvelo
Posts: 6
Joined: Thu Jan 14, 2010 2:11 am

Re: Error: Constant Value Required

Post by darvelo » Mon Jan 18, 2010 3:58 am

Thanks for the blinky code. I had to replace that chip because I tried a different fuse set that broke it and I can't get it to work again without extra equipment. I put in a new chip and tried a new, blank project with just your code and the blink works perfectly, so I put that code into the hid-data project to use it for debugging:

Code: Select all

static void blinkLed(int n_times)
{
if (n_times == 0 )  return;
char i;
DDRC |= 0x08;
   LED_OFF();
   while (n_times--)
   {
      LED_ON();
      for (i=0; i<1; i++) _delay_ms(1000);
      LED_OFF();
      for (i=0; i<1; i++) _delay_ms(1000);
   }   

}


Code: Select all

int main(void)
{
uchar   i;
   
   DDRC |= 0x08;

     blinkLed(5);   /* <---------------------- it's blinking time */

     wdt_enable(WDTO_1S);
    /* Even if you don't use the watchdog, turn it off here. On newer devices,
     * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
     */
 //   DBG1(0x00, 0, 0);       /* debug output: main starts */
    /* RESET status: all port bits are inputs without pull-up.
     * That's the way we need D+ and D-. Therefore we don't need any
     * additional hardware initialization.
     */
    odDebugInit();
    usbInit();
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    i = 0;
    while(--i){             /* fake USB disconnect for > 250 ms */
        wdt_reset();
        _delay_ms(1);
    }
    usbDeviceConnect();
    sei();
 //   DBG1(0x01, 0, 0);       /* debug output: main loop starts */
    for(;;){                /* main event loop */
 //       DBG1(0x02, 0, 0);   /* debug output: main loop iterates */
        wdt_reset();
        usbPoll();
     }
    return 0;
}


First I put the code right after DDRC to test if it would blink right. Windows makes a "USB Connected" sound and the light blinks great, 1s per on, 1s per off 5 times and stays on forever (since I wire my LED backwards lol). Then Windows makes a "USB Disconnected" sound.

I put the blink line anywhere after wdt_enable(WDTO_1S) and before usbDeviceConnect and this is what happens: blinks both on and off in the span of 1s forever. Windows makes no sounds.

I put the line right after usbDeviceConnect: Windows "USB Connected" sound, LED takes ~1.5 seconds to blink both on and off again (taking slightly longer to turn on), blinks like that forever.

Line placed anywhere after sei(): LED goes very low intensity blinks on/off (can barely see it) in ~1.5s, Windows makes "USB connected" sound every 5 seconds.

I'm not sure if these results are related to the zener diodes.. the only way I'll know for sure is when my order comes in and I replace the ones I have. Different things happen depending on where I put the blink code. I especially find it strange that the light would blink forever if it's not in a loop.. maybe the device is disconnecting and reconnecting constantly. Placing the line after sei() seems to dis/reconnect the device. I'll update the status once I put the diodes in, but if anything looks weird but fixable to you, please let me know. Thank you for your help so far ulao, you're awesome!

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Error: Constant Value Required

Post by ulao » Mon Jan 18, 2010 5:10 am

Cant say for sure on that funky-nes.. but the diods will make for troubles..

On that note.. Do your self a favor.. Scratch Ralf's code, if you have not already, to reset the device. Un solder his bridge from pd0 to pd1, and control the pull up with usv-v.. Ralf's did not have the latest when he designed it.

Desolder pd1, and desolder the 1.5 pull up on the +5 end. Solder the 1.5 to pd1. and use this code.

Code: Select all

static void usbReset(void)
{
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
   uchar i = 0;
    while(--i){                // USB disconnect for >250ms
        _delay_ms(1);
    };
    usbDeviceConnect();
}


I dont use the timer registers so I take them out also.

darvelo
Posts: 6
Joined: Thu Jan 14, 2010 2:11 am

Re: Error: Constant Value Required

Post by darvelo » Tue Feb 16, 2010 1:26 am

I got the 500mW zener diodes and that solved the whole problem.

In the meantime I got an ATmega8 so I'm gonna use that for the SNES code for now, but if I have time I will definitely try porting over to the Mega88PA with your advice.

Thanks, ulao.

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Error: Constant Value Required

Post by ulao » Tue Feb 16, 2010 6:46 am

glad to help.

Post Reply