bootloadHID atmega128
bootloadHID atmega128
I have having a world of trouble trying to implement bootloadHID on the atmeaga128. For the life of me I just cant get it to work. The setup I am using has two 3.6v zeners, D- = D4 , D+ = D0, and a 16mhz crystal. I know my hardware works because the example data-hid firmware (when configured) runs like a dream. For the bootloadHID config I have
Makefile....
DEVICE = atmega128
BOOTLOADER_ADDRESS = 1E000
F_CPU = 16000000
bootloaderconfig
#define USB_CFG_IOPORTNAME D
#define USB_CFG_DMINUS_BIT 4
#define USB_CFG_DPLUS_BIT 0
bootloaderconfig
#define USB_CFG_IOPORTNAME D
#define USB_CFG_DMINUS_BIT 4
#define USB_CFG_DPLUS_BIT 0
FuseBits
Low: 0xAF High: 0x91
BODLEVEL
BODEN Programed
SUT1
SUT00 Programed
CKSEL3
CKSEL2
CKSEL1
CKSEL0
OCDEN
JTAGEN Programed
SPIEN Programed
EESAVE Programed
BOOTSZ1 Programed
BOOTSZ0 Programed
BOOTTRST
M103C
WDTON
I also added
#define F_CPU = 16000000
to the top of main.c just to be safe.
With this setup when I short out the jumper it runs the boot loader firmware. But windows can't detect it. I thought it could have been a timing issue so I replaced the 16mhz crystal with a 12mhz resonator (it's all I had) and changed the fcp_u to 12000000 and still nothing. But again when I configure it for the hid-data example it works like a dream. If anyone has a suggestion I would love to hear it as I have been trying to do this for about a week and just can't get it to work. I am starting to think that bootloadHID isn't compatible with the atmega128. But I'm sure it's something small and stupid I'm missing.
Makefile....
DEVICE = atmega128
BOOTLOADER_ADDRESS = 1E000
F_CPU = 16000000
bootloaderconfig
#define USB_CFG_IOPORTNAME D
#define USB_CFG_DMINUS_BIT 4
#define USB_CFG_DPLUS_BIT 0
bootloaderconfig
#define USB_CFG_IOPORTNAME D
#define USB_CFG_DMINUS_BIT 4
#define USB_CFG_DPLUS_BIT 0
FuseBits
Low: 0xAF High: 0x91
BODLEVEL
BODEN Programed
SUT1
SUT00 Programed
CKSEL3
CKSEL2
CKSEL1
CKSEL0
OCDEN
JTAGEN Programed
SPIEN Programed
EESAVE Programed
BOOTSZ1 Programed
BOOTSZ0 Programed
BOOTTRST
M103C
WDTON
I also added
#define F_CPU = 16000000
to the top of main.c just to be safe.
With this setup when I short out the jumper it runs the boot loader firmware. But windows can't detect it. I thought it could have been a timing issue so I replaced the 16mhz crystal with a 12mhz resonator (it's all I had) and changed the fcp_u to 12000000 and still nothing. But again when I configure it for the hid-data example it works like a dream. If anyone has a suggestion I would love to hear it as I have been trying to do this for about a week and just can't get it to work. I am starting to think that bootloadHID isn't compatible with the atmega128. But I'm sure it's something small and stupid I'm missing.
Re: bootloadHID atmega128
sorry if im very very wrong.. but F_CPU isnt defined at khz? you got it at hz
YUP, i was wrong.. F_CPU is at Hz
YUP, i was wrong.. F_CPU is at Hz
Re: bootloadHID atmega128
Thanks for your response! Anything helps! I also have an update. I hooked up the mcu to my computer and enabled debugging level 2.
The output looks like this
00:
FF:
FF:
FF:
FF:
FF:
00:
(repeats)
Now here's the thing I know I got the address and clock settings because I'm getting valid debugging information. The strange thing is it keeps resetting. It seems to run through the main loop like 5 times then restart the firmware (or so it looks). I'm going to have to keep working on it. I just kills me that the hid-data example works and not bootloadHID. It's got to be something in the config......
P.S. has anyone got bootloadHID to work on an atmega128 yet?
The output looks like this
00:
FF:
FF:
FF:
FF:
FF:
00:
(repeats)
Now here's the thing I know I got the address and clock settings because I'm getting valid debugging information. The strange thing is it keeps resetting. It seems to run through the main loop like 5 times then restart the firmware (or so it looks). I'm going to have to keep working on it. I just kills me that the hid-data example works and not bootloadHID. It's got to be something in the config......
P.S. has anyone got bootloadHID to work on an atmega128 yet?
Re: bootloadHID atmega128
Man that took way to long!!!!!!!!!!!!! The problem I posted about last was the result of my fuse bits being set wrong(I find it odd that the firmware was still running.... but what the hell.). But the problem with windows not detecting the device was still their. So I started debugging the code ....... and after like.. two days I found it. The problem is with the memory address's being out of range of PROGMEM. It turns out that it wasn't a simple configuration issue (unless theirs something I'm missing) but a compatibility issue with avr-usb. The problem lies in the usbDeviceRead() function. Their is no issue as long as PROGMEM stays below the 64k mark, however with bootloadHID and the atmega128 the firmware is flashed beyond that point. I had to change
uchar c = USB_READ_FLASH(r);
to
uchar c = pgm_read_byte_far(r);
it gives an warning..... but I don't care because it works
So to anyone who is trying to get bootloadHID to work on an atmega128 try this
//(usbdrv.c)
//around line: 504
//function usbdeviceread()
//change
uchar c = USB_READ_FLASH(r);
//to
uchar c = pgm_read_byte_far(r);
if anyone has a better work around suggestion I would like to hear it because mine is vary crude and to the point. I'm just a hacker and a sloppy one at that
uchar c = USB_READ_FLASH(r);
to
uchar c = pgm_read_byte_far(r);
it gives an warning..... but I don't care because it works
So to anyone who is trying to get bootloadHID to work on an atmega128 try this
//(usbdrv.c)
//around line: 504
//function usbdeviceread()
//change
uchar c = USB_READ_FLASH(r);
//to
uchar c = pgm_read_byte_far(r);
if anyone has a better work around suggestion I would like to hear it because mine is vary crude and to the point. I'm just a hacker and a sloppy one at that
Re: bootloadHID atmega128
mmm i cant get it recognized by windows.. i ve got an atmega328p so i tried what you posted by the winavr says warning and then error:
i think maybe i dont need a far pointer address
Code: Select all
[b]usbdrv/usbdrv.c: In function 'usbDeviceRead':
usbdrv/usbdrv.c:504: warning: implicit declaration of function 'pgm_read_byte_far'[/b]
main.c: In function 'main':
main.c:226: warning: unused variable 'j'
main.c:226: warning: unused variable 'i'
main.c: At top level:
usbdrv/usbdrv.h:211: warning: 'usbFunctionDescriptor' used but never defined
usbdrv/usbdrv.h:218: warning: 'usbSetInterrupt' declared 'static' but never defined
avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=atmega328p -DF_CPU=12800000 -DDEBUG_LEVEL=0 -o main.bin usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o -Wl,--section-start=.text=7000
[b]main.o: In function `main':
main.c:(.text+0x30c): undefined reference to `pgm_read_byte_far'
make.exe: *** [main.bin] Error 1[/b]
i think maybe i dont need a far pointer address
Re: bootloadHID atmega128
rodmolina wrote:i think maybe i dont need a far pointer address
Correct. You only need the far access w/ devices that have more than 64k of FLASH memory. In other words: If a device doesn't have the RAMPZ (extended Z-pointer) register you don't need far access.
#if defined(RAMPZ)
[use far routines]
#else
[use normal routines]
#endif
Re: bootloadHID atmega128
I'm surprised to hear that pgm_read_byte_far() works in this case because the address is only 16 bit. If anybody has a good point WHY this works, we can add an #ifdef to usbportability.h (but on what condition?) or add a usbconfig.h option.
Re: bootloadHID atmega128
guest wrote:I had to change uchar c = USB_READ_FLASH(r); to uchar c = pgm_read_byte_far(r);
Thank you very much! You saved my project. I've been trying to make it work @ ATmega128A for couple hours.
Adam