Configure Qt Creator to support AVR
-
The problem is that I can not make Qt Creator work without Qmake if the project is with .pro (1)
And how can I make the Qt to compile a program using the compiler selected other than the default one... I need for AVR or PIC systems like ATmega 2560 in my case.
I've attached some photos for you to see the settings that I currently have and the error that I'm getting when I'm trying to enable AVR kit!many thanks
-
Not very sure what is AVR. Your kit configuration is not proper. Hence kit is showing you red mark. Is it a embedded box ? Have you compiled the Qt for that specific device ?
-
all fine with your Kit.
Just don't use a qmake projects for BareMetal! Use QBS or, maybe CMake instead (I'm not sure about CMake).
PS: We in our projects are use QBS everywhere.
-
@arsinte_andrei said in Configure Qt Creator to support AVR:
and how do I write a qbs project that will run gcc-avr
Just create the QBS project as usual (see QBS documentation). The GCC will be automatically called by QtC/QBS to compile your project (as I see, you already has a configured Kit for that). Just choose desired Kit as usual for your project when you will open it from QtC. You can create your QBS project even in notepad. :)
@arsinte_andrei said in Configure Qt Creator to support AVR:
and also to do the upload using avrdude?
Hmm.. no.. We in our projects use Atmel Studio directly to update an FW. We did not have time to play with avrdude. Also, did not have time to puck-up the AVR gdb server for debugging.
PS: So, it is one cons in this solution, related with QBS. But, you can write own rules for what you want, IMHO (just read QBS docu, examples, sources :) ). It is simple.
PS2: Or, you can take CMake, but I never tried that for BareMetal.
-
ok.. what I've done so far...
after looking at some examples I've created myself a template to be easy to start a new project in Qt for AVR.
So I'll remain with qmake for the sake of knowing it a bit - (qbs is also easy and cmake also)project.pr file
TEMPLATE = app AVR_MCU = $$lower(%{atpMCU}) AVR_FCPU = "%{atpSpeed}UL" AVR_PROGRAMMER = %{atpProgrammer} AVR_PORT = %{atpPort} QT -=gui core CONFIG += c++11 CONFIG -= app_bundle CONFIG -= qt DESTDIR = ../bin TARGET = %{ProFileName} INCLUDEPATH += /usr/lib/avr/include/ DEFINES = %{atpAVRinclude} #C compiler QMAKE_CC = /usr/bin/avr-gcc QMAKE_CFLAGS += -c -g -Os -w -ffunction-sections -fdata-sections QMAKE_CFLAGS += -MMD -mmcu=$$AVR_MCU -DF_CPU=$$AVR_FCPU #C++ compiler QMAKE_CXX = /usr/bin/avr-g++ QMAKE_CXXFLAGS += -c -g -Os -w -ffunction-sections -fdata-sections QMAKE_CXXFLAGS += -fno-exceptions -fno-threadsafe-statics QMAKE_CXXFLAGS += -MMD -mmcu=$$AVR_MCU -DF_CPU=$$AVR_FCPU # linker QMAKE_LINK = /usr/bin/avr-gcc QMAKE_LFLAGS = -w -Os -Wl,--gc-sections -mmcu=$$AVR_MCU QMAKE_LIBS = -lm #hex file QMAKE_POST_LINK += /usr/bin/avr-objcopy -O ihex -j .text -j .data -S ${TARGET} ${TARGET}.hex SOURCES += \ main.cpp
wizard.json
{ "version": 1, "supportedProjectTypes": [ "Qt4ProjectManager.Qt4Project" ], "id": "A.atpAVR", "category": "B.AVR", "trDescription": "Creates an AVR qmake-based project.", "trDisplayName": " C/C++ AVR", "trDisplayCategory": "AVR", "icon": "atmega168.jpg", "featuresRequired": [ "QtSupport.Wizards.FeatureQt" ], "enabled": "%{JS: [ %{Plugins} ].indexOf('QmakeProjectManager') >= 0}", "options": [ { "key": "ProFileName", "value": "%{JS: Util.fileName('%{ProjectDirectory}/%{ProjectName}', 'pro')}" }, { "key": "IsTopLevelProject", "value": "%{JS: !'%{Exists:ProjectExplorer.Profile.Ids}'}" }, {"key" : "atpAVRinclude" , "value" : "__AVR_%{atpIcType}__"}, { "key": "atpMCU", "value": "%{atpIcType}" }, { "key": "atpSpeed", "value": "%{atpAVRSpeed}" }, { "key": "atpProgrammer", "value": "%{atpPrg}" }, { "key": "atpPort", "value": "%{atpAVRPort}" } ], "pages": [ { "trDisplayName": "Project Location", "trShortTitle": "Location", "typeId": "Project", "data": { "trDescription": "This wizard creates an AVR project for you to use with Qt Creator." } }, { "trDisplayName": "The type of the IC that you want to program", "trShortTitle": "Ic Type", "typeId": "Fields", "enabled": "%{JS: ! %{IsSubproject}}", "data": [ { "name": "atpIcType", "trDisplayName": "Microcontroller name:", "type": "ComboBox", "data": { "index": 0, "items": [ { "trKey": "ATmega2560", "value": "ATmega2560" }, { "trKey": "ATmega168", "value": "atmega168" }, { "trKey": "ATmega320", "value": "atmega320" } ] } }, { "name": "atpAVRSpeed", "type": "LineEdit", "trDisplayName": "Frequency value in HZ:", "mandatory": true, "data": { "trText": "16000000" } }, { "name": "atpPrg", "trDisplayName": "Programmer type:", "type": "ComboBox", "data": { "index": 0, "items": [ { "trKey": "USBasp", "value": "usbasp" }, { "trKey": "FT232H", "value": "UM232H" }, { "trKey": "Arduino Uno", "value": "arduino" } ] } }, { "name": "atpAVRPort", "type": "LineEdit", "trDisplayName": "Programmer port used:", "mandatory": true, "data": { "trText": "usb" } } ] }, { "trDisplayName": "Project Management", "trShortTitle": "Summary", "typeId": "Summary" } ], "generators": [ { "typeId": "File", "data": [ { "source": "project.pro", "target": "%{ProFileName}", "openAsProject": true }, { "source": "main.cpp", "target": "main.cpp", "openAsProject": false }, { "source": "../../git.ignore", "target": "%{ProjectDirectory}/.gitignore", "condition": "%{JS: %{IsTopLevelProject} && '%{VersionControl}' === 'G.Git'}" } ] } ] }
and also main.cpp
/* Project: %{ProFileName} MCU: %{atpMCU} FRENQUENCY: %{atpSpeed} Created using QtCreator by Andrei Arsinte */ #ifndef F_CPU #define F_CPU %{atpSpeed}UL #endif #include <avr/io.h> #include <avr/delay.h> #define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT)) #define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT)) #define FLIPBIT(ADDRESS,BIT) (ADDRESS ^= (1<<BIT)) #define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT)) #define SETBITMASK(x,y) (x |= (y)) #define CLEARBITMASK(x,y) (x &= (~y)) #define FLIPBITMASK(x,y) (x ^= (y)) #define CHECKBITMASK(x,y) (x & (y)) #define VARFROMCOMB(x, y) x #define BITFROMCOMB(x, y) y #define C_SETBIT(comb) SETBIT(VARFROMCOMB(comb), BITFROMCOMB(comb)) #define C_CLEARBIT(comb) CLEARBIT(VARFROMCOMB(comb), BITFROMCOMB(comb)) #define C_FLIPBIT(comb) FLIPBIT(VARFROMCOMB(comb), BITFROMCOMB(comb)) #define C_CHECKBIT(comb) CHECKBIT(VARFROMCOMB(comb), BITFROMCOMB(comb)) #define Status_LED PORTB, PB7 //use pin PB7 from port B as status led int main(void) { SETBIT(DDRB, PB7); //set PB7 as output while(true) { C_SETBIT(Status_LED); //led on _delay_ms(1000); C_CLEARBIT(Status_LED); //led off _delay_ms(1000); } return 0; }
so far so good - everything is working.. now the update I'll put it as an avrdude upload when we run the project. so in your Projects RUN settings just add a custom executable and put there the avrdude - seams everything is fine.. any new ideas??
does anyone want this template?? is free... -
and now is working...
just press run and it will upload hex file to the chipanyway if anyone know how to generate the command line arguments from the .pro file variables...