import usbasp project in Atmel Studio

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

 

I'm importing usbasp (http://www.fischl.de/usbasp/) project into avr studio 7

 

I have:

1) create new Gcc c++ executable project

2) copied all usbasp folder here: C:\Users\Giuseppe\Documents\Atmel Studio\7.0\GccApplication1\GccApplication1

 

Under usbasp folder there is usbdrv folder.

So I have changed path:

 

/*

#include "usbasp.h"
#include "usbdrv.h"
#include "isp.h"
#include "clock.h"
#include "tpi.h"
#include "tpi_defs.h"

*/

#include "C:\Users\Giuseppe\Documents\Atmel Studio\7.0\GccApplication1\GccApplication1\usbdrv\usbasp.h"
#include "C:\Users\Giuseppe\Documents\Atmel Studio\7.0\GccApplication1\GccApplication1\usbdrv\usbdrv.h"
#include "C:\Users\Giuseppe\Documents\Atmel Studio\7.0\GccApplication1\GccApplication1\usbdrv\isp.h"
#include "C:\Users\Giuseppe\Documents\Atmel Studio\7.0\GccApplication1\GccApplication1\usbdrv\clock.h"
#include "C:\Users\Giuseppe\Documents\Atmel Studio\7.0\GccApplication1\GccApplication1\usbdrv\tpi.h"
#include "C:\Users\Giuseppe\Documents\Atmel Studio\7.0\GccApplication1\GccApplication1\usbdrv\tpi_defs.h"

 

but when compile this error is generate:

 

char usbDescriptorDevice[];  <----

 

Error    455        variable 'usbDescriptorDevice' must be const in order to be put into read-only section by means of '__attribute__((progmem))'   

C:\Users\Giuseppe\Documents\Atmel Studio\7.0\GccApplication1\GccApplication1\usbdrv\usbdrv.h    GccApplication1

 

 

 

why?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I have changed path:

Don't do that. Use "Directories" (which passes a -I to the compiler/preprocessor) so  "C:\Users\Giuseppe\Documents\Atmel Studio\7.0\GccApplication1\GccApplication1\usbdrv" would be entered just once.

 

But when "" is used with #include the first place it looks is in the same directory as where the .c files is anyway so as long as all the .c and .h are in the same directory then the headers will be found anyway.

 

As to the error you are getting it has NOTHING to do with header inclusion anyway!

 

The fact is that up to avr-gcc version 4.6 you could do things like:

char somedata[] PROGMEM = { 1,2,3,4,5 };

but from avr-gcc 4.6 onwards it now insits that when PROGMEM (or variants of it that use __attribute__((progmem))) are used the data must have the "const" modifier so such a line would need to be modified to (the more technically correct):

const char somedata[] PROGMEM = { 1,2,3,4,5 };

to say that the stuff that is in flash is unchangeable (because it is). The USBAsp code dates from about avr-gcc 4.3 so the code is not written to know about this. Studio 6.2 has compiler version 4.8 (and if you use Studio 7 it is 4.9) so you need to add "const" wherever the error messages tell you it is required.

 

(or install an old 4.3 .. 4.5 compiler to be used by Studio - but this is an inferior way to proceed)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well,   it is a bit of a pain to import it into AS7.

 

1.  gunzip and untar the distribution into your AS7.0 directory.

2.  you will find the source code is in the usbasp.2011-05-28/firmware/ directory.

3.  Create a new AS7 GCC C project.   Call it usbasp_as7    or whatever you like

4.  Browse to the firmware directory

5.  Do NOT create a new directory for the Solution

6.  Select ATmega8 as the Target

7.  This should create the Project.

8.  Now you have to tell it what files to use:

8.1 Delete the "main.c" that AS7 gave you

9.  Select the C, S, H files from firmware and "Add as Link"

10.  Select the S, H files from firmware/usbdrv and "Add as Link"

11.  In Properties->Toolchain->C->Directories.   Browse for the firmware and firmware/usbdrv directories and add (as relative path)

12.  The project should build.

 

You will get errors because the current compiler wants const PROGMEM instead of PROGMEM.

A simple kludge is to edit the usbportability.h file:

#include <avr/io.h>
#ifdef __ASSEMBLER__
#   define _VECTOR(N)   __vector_ ## N   /* io.h does not define this for asm */
#else
#   include <avr/pgmspace.h>
#undef PROGMEM
#define PROGMEM const __flash
#endif

The default for AS6 / AS7 is to always Copy instead of Add as Link.   I suggest that you always keep the original distribution.    But any development is made on the Linked files.    Otherwise you have no idea what is coming from where.

 

Life is a lot simpler with Makefiles.   You can of course just tell AS7 to use the original distribution Makefile.   But hey-ho,   I expect that you like finger-clicking.

 

David.

Last Edited: Fri. Oct 16, 2015 - 12:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

 

I have use directory and add const before PROGMEM

 

#if !(USB_CFG_DESCR_PROPS_DEVICE & USB_PROP_IS_RAM)
const PROGMEM
#endif
 

Now this is the error:

Error    0        ld returned 1 exit status    collect2.exe    GccApplication1

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

 

I have use directory and add const before PROGMEM

 

#if !(USB_CFG_DESCR_PROPS_DEVICE & USB_PROP_IS_RAM)
const PROGMEM
#endif
 

Now this is the error:

Error    0        ld returned 1 exit status    collect2.exe    GccApplication1

 

********************************************************

MAKE FILE

********************************************************

#
#   Makefile for usbasp
#   20061119   Thomas Fischl        original
#   20061120   Hanns-Konrad Unger   help: and TARGET=atmega48 added
#

# TARGET=atmega8    HFUSE=0xc9  LFUSE=0xef
# TARGET=atmega48   HFUSE=0xdd  LFUSE=0xff
# TARGET=at90s2313
TARGET=atmega8
HFUSE=0xc9
LFUSE=0xef

# ISP=bsd      PORT=/dev/parport0
# ISP=ponyser  PORT=/dev/ttyS1
# ISP=stk500   PORT=/dev/ttyS1
# ISP=usbasp   PORT=/dev/usb/ttyUSB0
# ISP=stk500v2 PORT=/dev/ttyUSB0
ISP=usbasp
PORT=/dev/usb/ttyUSB0

help:
	@echo "Usage: make                same as make help"
	@echo "       make help           same as make"
	@echo "       make main.hex       create main.hex"
	@echo "       make clean          remove redundant data"
	@echo "       make disasm         disasm main"
	@echo "       make flash          upload main.hex into flash"
	@echo "       make fuses          program fuses"
	@echo "       make avrdude        test avrdude"
	@echo "Current values:"
	@echo "       TARGET=${TARGET}"
	@echo "       LFUSE=${LFUSE}"
	@echo "       HFUSE=${HFUSE}"
	@echo "       CLOCK=12000000"
	@echo "       ISP=${ISP}"
	@echo "       PORT=${PORT}"

COMPILE = avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=$(TARGET) # -DDEBUG_LEVEL=2

OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o isp.o clock.o tpi.o main.o

.c.o:
	$(COMPILE) -c $< -o $@
#-Wa,-ahlms=$<.lst

.S.o:
	$(COMPILE) -x assembler-with-cpp -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.

.c.s:
	$(COMPILE) -S $< -o $@

clean:
	rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.bin *.o main.s usbdrv/*.o

# file targets:
main.bin:	$(OBJECTS)
	$(COMPILE) -o main.bin $(OBJECTS) -Wl,-Map,main.map

main.hex:	main.bin
	rm -f main.hex main.eep.hex
	avr-objcopy -j .text -j .data -O ihex main.bin main.hex
#	./checksize main.bin
# do the checksize script as our last action to allow successful compilation
# on Windows with WinAVR where the Unix commands will fail.

disasm:	main.bin
	avr-objdump -d main.bin

cpp:
	$(COMPILE) -E main.c

flash:
	avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -U flash:w:main.hex

fuses:
	avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -u -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m

avrdude:
	avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -v

# Fuse atmega8 high byte HFUSE:
# 0xc9 = 1 1 0 0   1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
#        ^ ^ ^ ^   ^ ^ ^------ BOOTSZ0
#        | | | |   | +-------- BOOTSZ1
#        | | | |   + --------- EESAVE (don't preserve EEPROM over chip erase)
#        | | | +-------------- CKOPT (full output swing)
#        | | +---------------- SPIEN (allow serial programming)
#        | +------------------ WDTON (WDT not always on)
#        +-------------------- RSTDISBL (reset pin is enabled)
# Fuse atmega8 low byte LFUSE:
# 0x9f = 1 0 0 1   1 1 1 1
#        ^ ^ \ /   \--+--/
#        | |  |       +------- CKSEL 3..0 (external >8M crystal)
#        | |  +--------------- SUT 1..0 (crystal osc, BOD enabled)
#        | +------------------ BODEN (BrownOut Detector enabled)
#        +-------------------- BODLEVEL (2.7V)
#
# Fuse atmega48 high byte hfuse:
# 0xdf = 1 1 0 1   1 1 1 1     factory setting
#        ^ ^ ^ ^   ^ \-+-/
#        | | | |   |   +------ BODLEVEL (Brown out disabled)
#        | | | |   + --------- EESAVE (don't preserve EEPROM over chip erase)
#        | | | +-------------- WDTON (WDT not always on)
#        | | +---------------- SPIEN (allow serial programming)
#        | +------------------ DWEN (debug wire is disabled)
#        +-------------------- RSTDISBL (reset pin is enabled)
# 0xdd = ext.reset, no DW, SPI, no watchdog, no save eeprom, BOD 2.7V
# Fuse atmega48 low byte lfuse:
# 0x62 = 0 1 1 0   0 0 1 0     factory setting
#        ^ ^ \ /   \--+--/
#        | |  |       +------- CKSEL 3..0 (internal 8Mhz Oszillator)
#        | |  +--------------- SUT 1..0 (start-up time)
#        | +------------------ CKOUT (no clock output)
#        +-------------------- CKDIV8 (divide clock by 8)
# 0xdc = divide/1,no clock output,fast raising power,low Pw Oszil. 3..8 Mhz
# 0xe0 = divide/1,no clock output,fast raising power,external Oszil.
# 0xff = divide/1,no clock output,slow raising power,low Pw Oszil 8..  Mhz

SERIAL = `echo /dev/tty.USA19QI*`
UISP = uisp -dprog=$S -dserial=$(SERIAL) -dpart=auto
# The two lines above are for "uisp" and the AVR910 serial programmer connected
# to a Keyspan USB to serial converter to a Mac running Mac OS X.
# Choose your favorite programmer and interface.

uisp:	all
	$(UISP) --erase
	$(UISP) --upload --verify if=main.hex
************************************************************************************************

 

 

**********************************************

BUILD OUTPUT

**********************************************

    Shell Utils Path C:\Program Files\Atmel\Studio\7.0\shellUtils
    C:\Program Files\Atmel\Studio\7.0\shellUtils\make.exe all 
collect2.exe(0,0): error: ld returned 1 exit status
Done building project "GccApplication1.cppproj" -- FAILED.

**********************************************

 

 

Last Edited: Fri. Oct 16, 2015 - 01:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now this is the error:

Need to see the real error. Forget the manky "Error List" which has a habit of throwing away the real reason and show us the build output where the error was first thrown.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well,  we have no idea what your error is.    Especially if you do not quote the full Error message.

 

Why are you building this firmware?

It comes with ready-built HEX files in the /bin directory

 

The German firmware is not nearly as good as the Chinese firmware that you get in a $3 USBASP dongle.

 

If you want to use the hardware for something else or change the functionality,   yes,  you would be editing the source code and building from scratch.

 

Somehow,   if you have a "real" application,  you would think up a better name than "GccApplication1"

 

As Cliff (and I) explained,   you tell the IDE any Directories to search.    And tell the IDE any global SYMBOLS or special flags.

You can use the same setup for any V-USB project.    i.e. the usbdrv/ files

You just need the application files and the configuration header file to change for each project.

 

David.

 

Edit.   You are building a C++ project when it should be a C project.    And AS7 will generate and use its own Makefile.    It will only use your "external Makefile" if you jump through special hoops.

Last Edited: Fri. Oct 16, 2015 - 01:46 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have copied all appeare in Error List Tab

I need to compile for change USB_CFG_VENDOR_ID and USB_CFG_DEVICE_ID.

 

In attachment a complete project

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

 

what pratically I have do for use external make file in AVR Studio 7??

 

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why not explain WHY you want to build this from scratch?

 

It is useful to know HOW a Makefile project is organised.    And HOW to turn it into an IDE project.     It is fairly inevitable that you have to do most of it by hand.    e.g. adding Files as links,   adding Search directories for #include files,  ...

 

There is a limited amount of automation in the File->Import menu.    e.g. Import from an AS4 project.

 

Quite honestly,   it is easier to build from the Distribution rather than try to mangle it into an IDE.

If fischl.de had wanted to distribute an AS4, AS6 or AS7 project,   they would have done so.

 

Since they give you a .GZ archive,   why not use it as God intended?

1.   Unpack it into a fresh directory.

2.   cd to /firmware at the command line

3.   type make

 

Yes,   there are several different targets you can "make".    And several things that you can configure if you are doing something "unusual"

 

We are quite happy to help you along the way with the "mangle it for IDE" approach

Or to guide you through the 3 steps involved with "how God intended" i.e. Makefile

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

as said in previous post I need to build for change UID and VID

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

as said in previous post I need to build for change PID and VID

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you serious?

So you just need to add step 2A. Edit the PID and VID. Then do step 3 : type make

Believe me, even the professionals on this forum would stick with the "distribution" if they only want to make one trivial edit.

You have changed the file geography. This will involve nightmares.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sorry guys but last time I do this was many years ago....at university :-)

Little bit patience

 

C:\usbasp\firmware>make main.hex
avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=atmega8  -c usbdrv/usbdrv.c -o usbdrv/usbdrv.o
process_begin: CreateProcess(NULL, avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=atmega8 -c usbdrv/usbdrv.c -o usbdrv/usbdrv.o, ...) failed.
make (e=2): Impossibile trovare il file specificato.
make: *** [usbdrv/usbdrv.o] Error 2

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is avr-gcc.exe in your PATH?

 

EDIT: actually there's a way to ensure that it that involves Studio. When you are running Studio there's an entry on the Tools menu to "Start Command Prompt", if you do that then the environment used for the DOS box has the PATH set to use the avr-gcc.exe that comes with Studio. So if you start that command prompt then navigate to where the files are then "make" it should work.

 

Just one thing though, if you change the VID/PID then avrdude will not be able to "see" the USBAsp so you will end up having to write your own PC software to drive it - so why would you ever want to rebuild it with a different VID/PID anyway?

Last Edited: Fri. Oct 16, 2015 - 03:59 PM