Author Topic: Project Template For AVR GCC Compiler  (Read 43878 times)

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Project Template For AVR GCC Compiler
« on: November 03, 2010, 11:38:36 am »
Hi,
I think the project template for AVR GCC is obsolete. The 'fuse, lock & signature' information is not extracted from the resulting hex file which should be programmed into the correct areas on the ucontroller and not into the flash. I know u guys are not embedded programmers mostly but that's a serious issue for embedded programmers using AVR, GCC and Codeblocks. ;) So I modified the current template to update the scripts and added some extra stuff like defining the '$MCU' variable to be used in tools menu to automate the programming process, etc... Will it be ok if I attach the template here for some1 to verify and I'll try to help and make other changes if need be?

Also there is another important issue, can the tools menu be compiler specific? Like it shows only the tools linked to the compiler chosen. That would be great when working with lots of mcus which need their own programming and debugging command scripts. Thnx...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Project Template For AVR GCC Compiler
« Reply #1 on: November 03, 2010, 03:50:36 pm »
Will it be ok if I attach the template here for some1 to verify and I'll try to help and make other changes if need be?
Yes.

Also there is another important issue, can the tools menu be compiler specific?
this makes no sense. A tool must not be compiler related at all. In fact all tools I've embedded are not related to any compiler. So how to differ?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Project Template For AVR GCC Compiler
« Reply #2 on: November 03, 2010, 05:15:55 pm »
Also there is another important issue, can the tools menu be compiler specific?
this makes no sense. A tool must not be compiler related at all. In fact all tools I've embedded are not related to any compiler. So how to differ?

Say I'm developing with AVRGCC, I wrote the code, compiled it. Then I need to download the code into the microcontroller. Here comes the distinction. I have quite a few options here if I'm using the debugger in 'debugwire' mode then I need to download the code also in 'debugwire' mode which is specific to AVR. Or if in ISP or JTAG, those make another 2 commands for the 'avrdude' on the tools menu. Then I may decide not to program the fuse bits everytime and insert another entry for program without fuse bits. I also need to run the 'gdb-server' (avarice for AVR, gdb-proxy for msp430 or openocd for ARM maybe) before I run the debugger so add another entry. When I said compiler specific I meant target specific which in case turns out to be compiler specific. It will be a long list if these are all on the same menu for all the targets, it would be a tidy version if tools menu could be customised to the compiler like same shortcuts for same actions but target specific executables. Just an idea. ;)

I attached the script file. Need a little more work I think.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Project Template For AVR GCC Compiler
« Reply #3 on: November 03, 2010, 05:42:50 pm »
Then I need to download the code into the microcontroller. Here comes the distinction.
Are you aware that there is also a "commands only" project type, where you can in the pre- or post-compilations steps add commands using macro expansion very well. Using virtual targets you can "baind" these targets to the compiler you've chosen to compile the actual compilation. Maybe this fits your needs better than pressing everything into the tools menu.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Project Template For AVR GCC Compiler
« Reply #4 on: November 03, 2010, 06:00:06 pm »
Hmm any tutorial on this?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Project Template For AVR GCC Compiler
« Reply #5 on: November 03, 2010, 06:21:04 pm »
Hmm any tutorial on this?
I believe it's pretty straight forward. You can read the docs about virtual targets, macro expansions and project settings if you want to:
http://www.codeblocks.org/docs/main_codeblocks_en.html
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Project Template For AVR GCC Compiler
« Reply #6 on: November 04, 2010, 10:08:54 am »
Well ok, now I got what u mean but I still think using a shortcut would be easier. Just curious, whether it's logical or not, would it be easy to implement a compiler specific menu item?

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Project Template For AVR GCC Compiler
« Reply #7 on: December 30, 2010, 01:53:29 pm »
I modified the template further to make some changes related with the filename extensions and added the extraction of the signature byte. The template extracts the fuse data into seperate files for 'hex' output depending on the fuse byte so the programming of the AVR can be automated with the following command:

Code
avrdude -c dragon_isp -P usb -p $(MCU) -u -U flash:w:${TARGET_OUTPUT_FILE}.hex -U eeprom:w:${TARGET_OUTPUT_FILE}.eep -U lfuse:w:${TARGET_OUTPUT_FILE}.lfs -U hfuse:w:${TARGET_OUTPUT_FILE}.hfs -U efuse:w:${TARGET_OUTPUT_FILE}.efs -U lock:w:${TARGET_OUTPUT_FILE}.lock

This considers an 'AVR Dragon' is used as programmer hardware. '$MCU' is the variable that contains the mcu type information which I had included in the template before. If an ATXMEGA mcu is used, the template should be further modified to extract the other fuse bytes. The current template distributed with CodeBlocks lacks the extraction of 'fuse, lock & signature' bytes from the resulting flash file which may cause problems if those bytes are used. So I request this template to be verified and used in further distributions. I only modified the original template so the thanks and credits go to the original author.

May I also request 'Project/properties/debugger/additional shell commands' option to be implemented as soon as possible. It's a very important feature for the embedded programmer. ;) And 1 last question, do I have an option to redirect standart output to say 'debugger' tab for my custom tools on the tools menu?

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Project Template For AVR GCC Compiler
« Reply #8 on: January 13, 2011, 10:59:11 pm »
I updated the script. It now has the option to extract the fuse, lock and signature files if needed. The extraction of the fuse byte into separate files needs the installation of 'srec_cat' and is only available for hex output. As said before I only modified the script, thanks and credits goes to the original author. Should I insert my name into the script to inform about the changes or leave it as it is?

Regarding my previous post I guess no one is interested in this script to be verified, is there some specific developer responsible for the embedded part of codeblocks I have to contact? Please advice!

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Project Template For AVR GCC Compiler
« Reply #9 on: January 20, 2011, 01:40:57 pm »
I managed to make a patch after a couple of hours to get used to svn. I made it for the debuggers branch located in 'svn://svn.berlios.de/codeblocks/branches/wxpropgrid_debugger', do I also have to make it for the trunk? File is attached, don't know if it requires a specific naming though. Thnx...

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Project Template For AVR GCC Compiler
« Reply #10 on: January 20, 2011, 01:44:08 pm »
The wizards are the same in both branches, but you're mixing tabs and spaces for indenting, please use only spaces, as the original script
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Project Template For AVR GCC Compiler
« Reply #11 on: January 20, 2011, 02:27:05 pm »
Sorry didn't know about the tabs, I'm a newbie in svn. Here is a new 1, I hope I didn't miss any tab.

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Project Template For AVR GCC Compiler
« Reply #12 on: April 10, 2011, 04:47:43 pm »
Ok I made the patch for the corrected version of the template. I've further enhanced the template to include some settings for the programmer and debugger. These settings can be used in the 'tools' commands to further automate the launching of the programmer or debugger with appropriate settings for the project like connection type, hardware type etc... I'll provide a patch for that newer version if there is interest. I also provided the actual files in case they can be used by copying directly.

I have some questions about the matter:
1-When I edit the template by right clicking in the 'new project' window, I can only edit the .script file but not the .xrc file. So when I save my work cb only copies the .script file to corresponding folder under 'documents and settings' but not the .xrc file. When I manually copy the .xrc file there it uses the default .xrc file under the codeblocks installation folder. Is there a way to make cb use the custom .xrc file in the 'docs and settings/...' path? Currently the only way I can find is to copy the custom file over the default file under the installation path.
2-When a custom variable is defined with spaces in it like '--jtag usb', cb uses it with quotes. I mean it inserts it like -> "--jtag usb". Is there a way to get rid of the quotes ""?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Project Template For AVR GCC Compiler
« Reply #13 on: April 10, 2011, 06:14:26 pm »
I have reformatted your patch to more closely match the CB team formatting standard. (Removed Tabs from Script Code)
And, I made a proper SVN patch out of it. (Removed the path to your local hard drive)

 
« Last Edit: April 10, 2011, 06:25:23 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Project Template For AVR GCC Compiler
« Reply #14 on: April 11, 2011, 12:30:42 am »
I apologize for the errors. I'm very new to SVN or any other version control system, it took about an hour to make that patch. ;) I tried to not to use tabs in the .script file but there were already tabs in the .xrc file so I used them where appropriate. I'll try to be more careful with the .script file next time. I have definitely no idea how to create a proper match. I use subcommander (sc) for svn. First I made sc download the debuggers branch on my hard drive then I copied the modified files into that path and then I right clicked somewhere and chose the 'diff' option. It seems I need to investigate more when I have the time.