I've been at this for ages . Trying to compile the code below and getting a verbose listing below that with the final error messages. I suspect V-USB needs compiling but I thought that happened on startup if you put it in the libraries ?
It does not find the functions ?
I put V-USB into the libraries and I thought it got compiled on Arduino IDE opening ?
Its just not finding the functions and I suspect they are not compiling or its an error with version 1.0.1
Can anyone help?
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include "usbdrv.h"
#define F_CPU 16000000L
#include <util/delay.h>
USB_PUBLIC uchar usbFunctionSetup(uchar data[8]) {
return 0; // do nothing for now
}
int main() {
uchar i;
wdt_enable(WDTO_1S); // enable 1s watchdog timer
usbInit();
usbDeviceDisconnect(); // enforce re-enumeration
for(i = 0; i<250; i++) { // wait 500 ms
wdt_reset(); // keep the watchdog happy
_delay_ms(2);
}
usbDeviceConnect();
sei(); // Enable interrupts after re-enumeration
while(1) {
wdt_reset(); // keep the watchdog happy
usbPoll();
}
return 0;
}
Possibly because V-USB is designed for standalone atmega mpus, and not for Arduinos. You may get a better response on the V-USB site's forum http://forums.obdev.at/viewforum.php?f=8.
rather than post the library here the library I am using is V-USB full specs of which are here
The library is downloaded and part of it (one directory "usbdrv") is placed in your sketchbook /library folder which then makes available the ".c" and ".h" files . You copy "usbconfig-prototype.h" and make a configuration file for yourself which is "usbconfig.h" which is also saved in that folder.
The program I am trying to compile is
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include "usbdrv.h"
#define F_CPU 16000000L
#include <util/delay.h>
USB_PUBLIC uchar usbFunctionSetup(uchar data[8]) {
return 0; // do nothing for now
}
int main() {
uchar i;
wdt_enable(WDTO_1S); // enable 1s watchdog timer
usbInit();
usbDeviceDisconnect(); // enforce re-enumeration
for(i = 0; i<250; i++) { // wait 500 ms
wdt_reset(); // keep the watchdog happy
_delay_ms(2);
}
usbDeviceConnect();
sei(); // Enable interrupts after re-enumeration
while(1) {
wdt_reset(); // keep the watchdog happy
usbPoll();
}
return 0;
}
The problem I get is
VUSBExample1.cpp.o: In function main': VUSBExample1.cpp:22: undefined reference to usbInit()'
VUSBExample1.cpp:35: undefined reference to `usbPoll()'
http://forums.obdev.at/viewforum.php?f=8 I have a post there but it does not seem to get much response because they are not interested in Arduino IDE . They program direct to the chip.
It must be possible with Arduino I just need some knowlegeable person to look closely at the error and point me in the right direction.
I have managed to get it to compile with a bit of tinkering, but whether or not it works after what I have done I have no idea without properly studying the code (which at first glance appears that it was definitely not designed with Arduino in mind).
Part of the problem is that it is written in C not C++, and the compiler seems to be having a hissy fit with the files named .c - Don't know why, I'm not an expert. I have renamed them to .cpp and also changed all of the extern functions to be extern "C" which I believe tells the compiler to treat them as C functions - Again, not an expert.
I haven't got the hardware setup to test the modifications, but by all means try it out and see if it works. If not, V-USB are the best people to ask (or someone who knows C/C++ better - I have only been coding with C for 2 years). http://www.railways-in-miniature.co.uk/electronics/arduino/usbdrv.zip
Thanks Tom-This thread moves along quickly -I missed this
Believe it or not I woke up this am with the same thought -to rename all "C" files to ".cpp" and see what happened on starting Arduino IDE
I had not even considered the "extern C" though
I D/L your changed files removed the ones I had in the library and fired up the IDE and program again with no change in the result unfortunately.
I will however keep studying it . It does not give an error message on start of the IDE so I am assuming it is compiling something - just have to find out what.
There is a difference between the way C and C++ use pointer - specifically the C++ specification doesn't allow for the implicit conversion of (void*) pointers to type pointers (such as (usbRequest_t *)). These must be cast correctly. So in any of the examples where you find anything like:
Any implementations the the libraries extern functions must be written within the extern "C" {} block to specify they should be treated as C functions. (See the example sketch)
You have to ensure your wiring is correct - USB runs at 3.3v level, which means your IC needs to run at 3.3v, or you need 3.6v zener diodes between D+ and GND, and between D- and GND. In the file above I have drawn the way I wired the board. In my case as I didn't have an zeners to hand, I used a pair of 1N4148 diodes in series with the +5v from the USB port and the arduino mega +5v rail. This forces the mega to run at just under 3.5V which is acceptable.
If you use a different IC to the Mega, such as a Tiny chip or an Uno, you will need to use the corrent pins. D+ should be on the pin connected to INT0. D- doesn't matter which pin it is connected to. You also need to specify the port and bits you have chosen in the usbconfig.h file (under the heading "Hardware Config"):
/* ---------------------------- Hardware Config ---------------------------- */
#define USB_CFG_IOPORTNAME D
/* This is the port where the USB bus is connected. When you configure it to
* "B", the registers PORTB, PINB and DDRB will be used.
*/
#define USB_CFG_DMINUS_BIT 1
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
* This may be any bit in the port.
*/
#define USB_CFG_DPLUS_BIT 0
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
* This may be any bit in the port. Please note that D+ must also be connected
* to interrupt pin INT0! [You can also use other interrupts, see section
* "Optional MCU Description" below, or you can connect D- to the interrupt, as
* it is required if you use the USB_COUNT_SOF feature. If you use D- for the
* interrupt, the USB interrupt will also be triggered at Start-Of-Frame
* markers every millisecond.]
Then example sketch is a bit of fun. If all goes well when you plug it in, after a couple of seconds you should see the mouse moving round in circles. It may have to install the drivers first (generic USB mouse driver).
Gee thanks so much for the time you have put in Tom
I'll study that and get back to you.
My first run got this error on
if(usbInterruptIsReady()){
/* called after every poll of the interrupt endpoint /
advanceCircleByFixedAngle();
DBG1(0x03, 0, 0); / debug output: interrupt report prepared */
usbSetInterrupt((unsigned char *)&reportBuffer, sizeof(reportBuffer));
}
Mouse:149: error: 'usbInterruptIsReady' was not declared in this scope
Mouse:153: error: 'usbSetInterrupt' was not declared in this scope
Mouse.cpp:158: warning: function declared 'noreturn' has a 'return' statement
This is declared on line 220 or so of usbdrv.h
I'm running this on a mega328p
Where did you put the usbdrv folder? It needs to go in the \libraries\ folder, not the documents folder otherwise it doesn't work.
Also did you delete the old usbdrv folder? Renaming it doesn't work as it still remembers the old files for some reason.
All I know for sure is the example sketch compiles fine for me.
Which version of the IDE are you using? I doubt it will make a difference, but I am trying to work out what could be different between your computer and mine as it works perfectly for me for both Uno and Mega.
Version 1.0.1
I'm using a Duemilanov board with 328p
I left usbconfig.h as you had it-I have made no changes anywhere atm
I have
binutils-avr_2.20
gcc-avr_4.5.3
avr-libc_1.6.7
Christo:
Quite late in this discussion, but I have found an Arduino port of V-USB here: Google Code Archive - Long-term storage for Google Code Project Hosting.
It seems as if RancidBacon has wrapped the exported functions as follows to make them compatible with Arduino's C++ environment:
There seem to be other changes too and other examples.
I d/l and used this library and the demos compiled OK but I don't know how to use the library yet.
That was the purpose here so I'll now endeavor to get a bit of a look at it -Thanks Christo
I would like to get your example up and running too Tom . Perhaps it will reveal itself with more study on my part -Thanks for the start