baerwolf / USBaspLoader

An (V)USB bootloader firmware for AVR-MCUs emulating the popular USBasp for programming itself
Other
178 stars 146 forks source link

Issues when Compiling #3

Closed zaidpirwani closed 11 years ago

zaidpirwani commented 12 years ago

Hi,

I am having a bit strange problem when compiling the downloaded source code.

I downloaded the source code, opened command prompt, went to the extracted folder and typed in make all

a the first attempt, IT WORKED [though it showed a few warnings], however when I try to compile it second time after using make clean or make deepclean and then use make all, it gives error. If I change any parameters in make, it still gives error. I wanted to make it with a 12MHz and had changed the D+/- pins to be same as those on the USBasp as I have a few circuits of that made btu it simply won't compile - gives text region size error (complete error mentioned below) when compiling for ATMega8 and gives some other eeprom error when using ATMega328 etc.

PLEASE HELP

Thanks for your time and work on this bootloader, I wish to use it as arduino as we can't get arduinos easily in my country. Thanks in advance for your time and help.

I will try tonight with same schematic as you mentioned but need to have this MAKE problem resolved soon.

THANKS AGAIN.

Regards,

Zaid Pirwani

Details of my system: Windows 7 Ultimate 32-Bit AVR Toolchain 3.4.1.1195

copy of command prompt =====================FIRST TIME MAKE ALL=============== E:\Dropbox\My Documents\AVR\USBaspLoader-master>make all make[1]: Entering directory E:/Dropbox/My Documents/AVR/USBaspLoader-master/fir mware' usbdrv/usbdrv.h:213:24: warning: 'usbFunctionDescriptor' used but never defined [enabled by default] text data bss dec hex filename 2034 8 54 2096 830 main.bin make[1]: Leaving directoryE:/Dropbox/My Documents/AVR/USBaspLoader-master/firm ware' make[1]: Entering directory E:/Dropbox/My Documents/AVR/USBaspLoader-master/upd ater' updater.c:38:4: warning: #warning I do not know where new "bootloader__do_spm" i s located - assuming "NEW_BOOTLOADER_ADDRESS+(funcaddr___bootloader__do_spm % SP M_PAGESIZE)" [-Wcpp] updater.c:46:4: warning: #warning "TEMP_SPM_PAGEADR" is not defined explicitly - will choose END OF FLASH ! [-Wcpp] . text data bss dec hex filename 3022 2 0 3024 bd0 updater.elf . avrdude -c usbasp -p atmega8 -D -U flash:w:updater.hex:i . make[1]: Leaving directoryE:/Dropbox/My Documents/AVR/USBaspLoader-master/upda ter'

================ SECOND TIME MAKE ALL============== E:\Dropbox\My Documents\AVR\USBaspLoader-master>make all make[1]: Entering directory E:/Dropbox/My Documents/AVR/USBaspLoader-master/fir mware' make[1]: Nothing to be done forall'. make[1]: Leaving directory E:/Dropbox/My Documents/AVR/USBaspLoader-master/firm ware' make[1]: Entering directoryE:/Dropbox/My Documents/AVR/USBaspLoader-master/upd ater' make[1]: Nothing to be done for all'. make[1]: Leaving directoryE:/Dropbox/My Documents/AVR/USBaspLoader-master/upda ter'

==================using MAKE DEEPCLEAN====================== E:\Dropbox\My Documents\AVR\USBaspLoader-master>make deepclean make[1]: Entering directory E:/Dropbox/My Documents/AVR/USBaspLoader-master/upd ater' make[1]: Leaving directoryE:/Dropbox/My Documents/AVR/USBaspLoader-master/upda ter' make[1]: Entering directory E:/Dropbox/My Documents/AVR/USBaspLoader-master/fir mware' make[1]: Leaving directoryE:/Dropbox/My Documents/AVR/USBaspLoader-master/firm ware' c:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\rm.exe: cannot remove `~': I nvalid argument make: ** [deepclean] Error 1

====================== THIRD TIME MAKE ALL======================= ======================without any changes to makefile.inc============== E:\Dropbox\My Documents\AVR\USBaspLoader-master>make all make[1]: Entering directory E:/Dropbox/My Documents/AVR/USBaspLoader-master/fir mware' usbdrv/usbdrv.h:213:24: warning: 'usbFunctionDescriptor' used but never defined [enabled by default] c:/program files/atmel/avr tools/avr toolchain/bin/../lib/gcc/avr/4.6.2/../../.. /../avr/bin/ld.exe: address 0x2024 of main.bin section.text' is not within reg ion text' c:/program files/atmel/avr tools/avr toolchain/bin/../lib/gcc/avr/4.6.2/../../.. /../avr/bin/ld.exe: address 0x2024 of main.bin section.text' is not within reg ion text' collect2: ld returned 1 exit status make[1]: *** [main.bin] Error 1 make[1]: Leaving directoryE:/Dropbox/My Documents/AVR/USBaspLoader-master/firm ware' make: *\ [do_firmware] Error 2

===================== using MAKE DDEEPCLEAN====================== E:\Dropbox\My Documents\AVR\USBaspLoader-master>make deepclean make[1]: Entering directory E:/Dropbox/My Documents/AVR/USBaspLoader-master/upd ater' c:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\rm.exe: cannot remove.o': Invalid argument make[1]: ** [clean] Error 1 make[1]: Leaving directory `E:/Dropbox/My Documents/AVR/USBaspLoader-master/upda ter' make: *\ [clean] Error 2

====================== FOURTH TIME MAKE ALL======================= ======================changed F_CPU to 12M in makefile.inc============== E:\Dropbox\My Documents\AVR\USBaspLoader-master>make all make[1]: Entering directory E:/Dropbox/My Documents/AVR/USBaspLoader-master/fir mware' c:/program files/atmel/avr tools/avr toolchain/bin/../lib/gcc/avr/4.6.2/../../.. /../avr/bin/ld.exe: address 0x2024 of main.bin section.text' is not within reg ion text' c:/program files/atmel/avr tools/avr toolchain/bin/../lib/gcc/avr/4.6.2/../../.. /../avr/bin/ld.exe: address 0x2024 of main.bin section.text' is not within reg ion text' collect2: ld returned 1 exit status make[1]: *** [main.bin] Error 1 make[1]: Leaving directoryE:/Dropbox/My Documents/AVR/USBaspLoader-master/firm ware' make: *\ [do_firmware] Error 2

====================== FIFTH TIME MAKE ALL======================= =========changed F_CPU to 12M and MCU to atmega328 in makefile.inc========== E:\Dropbox\My Documents\AVR\USBaspLoader-master>make all make[1]: Entering directory E:/Dropbox/My Documents/AVR/USBaspLoader-master/fir mware' main.o: In functionmain': main.c:(.text.startup+0xea): undefined reference to __eerd_byte_m8' main.c:(.text.startup+0xf4): undefined reference toeewr_byte_m8' main.c:(.text.startup+0x284): undefined reference to `eewr_byte_m8' main.c:(.text.startup+0x3a8): undefined reference to__eerd_byte_m8' collect2: ld returned 1 exit status make[1]: **\* [main.bin] Error 1 make[1]: Leaving directoryE:/Dropbox/My Documents/AVR/USBaspLoader-master/firm ware' make: *\ [do_firmware] Error 2

baerwolf commented 12 years ago

Hi Zaid Pirwani, thank you for your report.

First of all, you might want to look at: http://matrixstorm.com/avr/tinyusbboard/ (There you also can download toolchains etc...)

Second: Your report indicates numerous problems to me. In long story short your toolchain is buggy AND produces suboptimal code. Instead I explain all errors to you, please first try the official atmel toolchain for windows "avr-toolchain-installer-3.4.1.1195-win32.win32.x86".

(The Linker errors are because of invalid linker-scripts which apply wrong MCU architecture to binary and the huge codesizes are from bad size-optimization)

The next thing seems to be, your selected feature-support is to much on too small ATmega. You have to be careful your firmware fits into the BLS (bootloadersection).

text data bss dec hex filename 2034 8 54 2096 830 main.bin

Text + data have to fit into BLS ! (In this case 2034+8 = 2042 < 2Kib ==> OK)

How big the BLS is, you can read from the datasheet - normally it is 2kib (1k words) on small ICs with only 8kb flash. If then the MCU has lots of interrupts, it may not have enough free memory to support all features of USBaspLoader. (For example atmega8 will fit into 2kib, atmega88 not because of much more intterupts.) In such case you can edit firmware/bootloaderconfig.h to deactivate some features. I recommend to begin with deactivating "HAVE_READ_LOCK_FUSE" and then maybe "HAVE_SPMINTEREFACE". But attantion, "HAVE_SPMINTEREFACE" will deactivate the bootloader-updatefeature and building an updater-firmware make no more sense (and may even fail)... Also ATTANTION with deactivating "HAVE_BLB11_SOFTW_LOCKBIT", since you then have to place BLS protection via LOCKBITs accordingly - otherwise flashing your IC via LOADER might currupt the LOADER!

I hope I could help you and I am looking forward to your response,

regards Stephan

baerwolf commented 11 years ago

In the new version 0.85 I improved auto selection of features. Perhaps you might want to use/test the new version.

Regards Stephan

zaidpirwani commented 11 years ago

Well, sorry but looks like my Win7 is giving more problems that I initially thought so and looks like I will need a re-install [tried all the other solutions] - so will take me a day or 2 to get back upto speed and check the new version - thanks for the update and I will definitely check and inform as soon as I can.

Regards,

Zaid Pirwani

baerwolf commented 11 years ago

I am reporting back with version v0.95.

This version should fix all your major problems. It is extreme optimized and very fine configurable.

Since you haven't reported back in some time, I will close this issue end of this week.

Best regards,

   -Stephan
zaidpirwani commented 11 years ago

Hi, sorry for not getting back to you...

//Have been busy in setting up the new OS and installing everything plus studies etc etc...

THANKS for the update, downloading now and will reply back shortyl

baerwolf commented 11 years ago

I again.

ATmega328 is now successfully tested and works 100%.

Please see https://github.com/baerwolf/USBaspLoader/wiki/TestedDevices for all tested devices.

regards Stephan

zaidpirwani commented 11 years ago

I still am getting the same error of size when building it, with Atmega8 or any other controller, I have Win8 now and have installed the latest AVR Toolchain from atmel and also tried with Atmel Studio 6.

baerwolf commented 11 years ago

Can you send me URL please, so I can test for more details?

zaidpirwani commented 11 years ago

http://www.atmel.com/tools/atmelavrtoolchainforwindows.aspx

http://www.atmel.com/microsite/atmel_studio6/default.aspx

baerwolf commented 11 years ago

It works for me. I setup a WinXP (OS should be pretty much all the same as long as we use the same toolchain) with toolchain mentioned above.

You can have a look via VNC at "icsopenvpnlanaccess.matrixstorm.com:36140", password should be "usbasp".

zaidpirwani commented 11 years ago

I tried with GitHub once more, re-downloaded and re-installed the toolchain and IT WORKED....

The only change I did was to change the clock frequency from 16MHz to 12MHz and it STOPPED working, changed the clock back, looks like I need to keep using 16MHz....

I wanted 12MHz as I ahve several USBasp Boards and I wanted to sue them as they are... with 12MHz crystals..

zaidpirwani commented 11 years ago

THANKS, very much.... hopefully this will work for me now and I won't be botehring you much...

baerwolf commented 11 years ago

Yes, if you change clock-frequency some code might become bigger.

But that is no problem, even on small devices you can start switching of some features within Makefile.inc.

For example ATmega8 default-settings (even for 16MHz) are:

DEFINES_8 = -DCONFIG_USEEXCESSIVE_ASSEMBLER -DCONFIG_NONEED_WATCHDOG -DCONFIG_NO__PRECISESLEEP

From firmware/bootloaderconfig.h you can see what features there are.

For example add "-DCONFIG_NOHAVE_READ_LOCK_FUSE" to disable "the loaders capability to load its lfuse, hfuse and lockbits". Or add "-DCONFIG_NOBOOTLOADER_CAN_EXIT" to disable extra exit via PROGRAM-Button. However you always can restart via reset...

If you want to apply your cfg for another ATmega-Type you must use different variable-names. For ATmega328p it is DEFINES_328 (as it is for ATmega328a etc...).

The variable "DEFINES" is applied to all devices...

If you need just a few bytes, you can try some setups through and you select the best fitting, or the one with the most important features to you. - You choose...

Best regards, Stephan

probonopd commented 11 years ago

Did you get it to run on unmodified USBasp boards? That's what I'm interested in, too.

2012/12/5 Zaid Pirwani notifications@github.com

THANKS, very much.... hopefully this will work for me now and I won't be botehring you much...

— Reply to this email directly or view it on GitHubhttps://github.com/baerwolf/USBaspLoader/issues/3#issuecomment-11044508.

http://www.puredarwin.org/

baerwolf commented 11 years ago

I do not have any of such boards. But I bet it will work (at least with some minor patch).

Assuming your board has same schematics as on http://www.fischl.de/usbasp/ and using the recent USBaspLoader version (v0.95) I will try it out (using atmega8 because of having no atmega88), soon.

Best regards, Stephan

baerwolf commented 11 years ago

Maybe you try the attached configuration. It diffs against recent version of USBaspLoader v0.95 and only ajusts configuration without changing the code ...

All the used information only bases on the theory of T. Fischl's schematics and source code. (So it might not work in practice.) As the bootloader-condition (startin bootloader for reporgram instead of user-prorammed firmware) I selected the "Slock SCK"-Jumper. When placed (PC2 to ND) bootloader will start - firmware otherwise. See the patch for details - Please report soon if this works.

for ATmega88: http://matrixstorm.com/avr/others/USBaspLoader0v95_on_USBaspProgrammerATmega88Hardware.patch

for ATmega8: http://matrixstorm.com/avr/others/USBaspLoader0v95_on_USBaspProgrammerATmega8Hardware.patch

probonopd commented 11 years ago

Hi baerwolf, thanks a lot, I can confirm that this works.

Not all USBasp boards - especially the cheap ones described in

http://jethomson.wordpress.com/2011/08/18/project-ouroboros-reflashing-a-betemcu-usbasp-programmer/

have the "low speed" jumper. Can the reset pin be used as the bootloader condition instead (e.g., plug in, then press reset, then the device goes into bootloader mode)?

(For reference, I documented the steps below - couldn't figure out how to use the Makefile to burn.)

Probably unrelated issue I'm running into:

When I upload the Blink sketch fromthe Arduino IDE it does work, but the blinking is about 10% too slow, I have seen the same behavior on 2 different USBasp boards from 2 different manufacturers. I guess something in my Arduino IDE setup is wrong?

I guess the fact that the timing is off also prevents me from using vusb-for-arduino at the moment.

I'm willing to sponsor a USBasp so that we can turn it into an Arduino-compatible board with working vusb-for-arduino... :-)

wget https://github.com/baerwolf/USBaspLoader/archive/master.zip unzip master.zip cd USBaspLoader-master/ wget http://matrixstorm.com/avr/others/USBaspLoader0v95_on_USBaspProgrammerATmega8Hardware.patch patch -p1 < *patch tar xfvz '/media/ubuntu/boot/avr8-gnu-toolchain-3.4.1.798-linux.any.x86.tar.gz' export PATH=avr8-gnu-toolchain-linux_x86/bin/:$PATH export PATH=/home/ubuntu/USBaspLoader-master/avr8-gnu-toolchain-linux_x86/bin/:$PATH make clean make all

sudo apt-get install avrdude sudo avrdude -c usbasp -p m8 -U lfuse:w:0x1f:m -U hfuse:w:0xc0:m sudo avrdude -patmega8 -cusbasp -Pusb -Uflash:w:./firmware/main.hex:i -Ulock:w:0x0F:m

Plug device in and close the "low speed" jumper

[32995.812341] usb 1-2.1: >new low-speed USB device number 53 using ehci_hcd [32995.912959] usb 1-2.1: >New USB device found, idVendor=16c0, idProduct=05dc [32995.912963] usb 1-2.1: >New USB device strings: Mfr=1, Product=2, SerialNumber=0 [32995.912966] usb 1-2.1: >Product: USBasp [32995.912969] usb 1-2.1: >Manufacturer: www.fischl.de

baerwolf commented 11 years ago

Hi probonopd.

About the thing with the new bootloader-condition I have to think about a little bit longer.

The problem with the speed seems clearer to me:

a) you configured the arduino-hardwaredescription of the USBasp board with 16MHz instead of the real used 12MHz?

b) some cheap chinese USBasp's seems to manufacture wrong atmegas on the board. (They use atmega8>>L<< which is only allowed to be clocked to 8MHz. However they overclock to 12MHz, which can lead to instabilities!)

baerwolf commented 11 years ago

Perhaps you try out http://matrixstorm.com/avr/tinyusbboard/, which is a very cheap "do it yourself" full arduino compatible board.

baerwolf commented 11 years ago

What do you think?

How about using PB4 (MISO) as bootloader condition. It should be placed within the ISP header on the leftmost side and could be grounded by a jumper with the GND-Pin below to enable the bootloader. If not jumpered normal firmware starts up - and programming a normal USBasp programmer onto this thing should be still possible.

Btw. you have to go into the "firmware" subdirectory to "make flash" or "make fuse". (Before this you may have to cnfigure Makefile.inc to your correct avrdude path.) When you do not want to place AVR8-toolchain into global PATH environment (or you have multiple toolchains), you can use the "AVR8TOOLCHAINBINDIR" environment variable therefore instead - the makefile will use this one.

If you agree with the new bootloader condition, I will provide a cfg-patch and a new magic-value for this...

Best regards, Stephan

zaidpirwani commented 11 years ago

Sorry, but I haven't tried on USBasp Boards - I made a board similar to the tinyUSBBoard for my use and am quite happy with it, THANKS Stephen for all the help that you gave... http://zaidpirwani.com/1150

probonopd commented 11 years ago

PB4 (MISO) as bootloader condition sounds like a good idea to me!

Thanks for your help, my remaining issues now are with the timing inside the Arduino environment (one of my USBasp boards indeed has an ATmega8L, but the other has an ATmega8) and getting vusb-for-arduino to run (which i miserably fail at). Anyhow, don't want to hijack this thread...

baerwolf commented 11 years ago

Okay, first here is a new cfg-patch: http://matrixstorm.com/avr/others/USBaspLoader0v95_on_nonStandardUSBaspProgrammerATmega8Hardware.patch for using PB4.

Second, why don't you just open a new issue?

regards, Stephan

baerwolf commented 11 years ago

Btw. could you attach your Arduino boardhardware-description. It helps understand the timing-issue...

Thx