Shop OBEX P1 Docs P2 Docs Learn Events
[solved] PropGCC and Code::Blocks Tutorial — Parallax Forums

[solved] PropGCC and Code::Blocks Tutorial

SRLMSRLM Posts: 5,045
edited 2012-11-20 19:42 in Propeller 1
[size=+2]How to use Code::Blocks and PropGCC:[/size]

I plan on using PropGCC with a limited subset of C++, and the C standard library. This post explains how to set up the Code::Blocks IDE to work with PropGCC projects.

[size=+1]Benefits:[/size]
1. Code::Blocks comes with a full suite of code editing tools.
2. Single button compile and download.
3. Compile errors will automatically take you to the correct line in the correct file.

[size=+1]My System:[/size]
This has been tested on Ubuntu 12.04 with Code::Blocks 10.05 and PropGCC v0.3.4. I don't know if this will work on Windows, and I can't test or answer any questions about that.

[size=+1]How it Works:[/size]
Basically, you'll give Code::Blocks a custom Makefile that will do all the compilation, via the Code::Blocks Makefile hooks. To get it to download and execute on the Propeller, you'll trick Code::Blocks into running a script when the Project "Run" command is selected, and this script will call propeller-load and download to the Propeller.

[size=+1]Setting Up a New PropGCC Project:[/size]
0. Make sure that PropGCC is installed correctly. You should be able to run the demo programs from the command line (with their makefiles and propeller-load).
1. Open Code::Blocks, and create a new project (Console type, and C++).
2. Under Project->Properties->Project Settings, check the "This is a custom Makefile" checkbox.
3. Click on the "Build Targets" tab, and change the output filename to "main" (without quotes), and deselect the two check boxes beneath.
4. Change the main.cpp code to the following:
#include <stdio.h>

int main()
{
    printf("Hello World!");
    return 0;
}
5. In your favorite text editor, create a file called "Makefile" (without quotes), with the following contents:
NAME = main

ifndef MODEL
MODEL = lmm
endif

Debug: Makefile $(NAME).cpp
	propeller-elf-g++ -m$(MODEL) -Wall -Os -m32bit-doubles -o $(NAME).elf $(NAME).cpp -lm

cleanDebug:
	rm -f *.o *.elf
6. Create a file called "main", and make it executable. Put the following text in the file:
#!/bin/sh
/opt/parallax/bin/propeller-load -r -t main.elf
7. Test out the build by selecting Build->Build and Run in Code::Blocks

[size=+1]Optional:[/size]
By default, Code::Blocks runs console programs in the "sh" shell environment. I prefer running in the gnome-terminal. To change to gnome-terminal, go to Settings->Environment Settings, and change the "Terminal to launch console programs" option to:
gnome-terminal --disable-factory -t $TITLE -x
I left the "Shell to run commands in" option as is (with /bin/sh -c). Note that this change is global, and affects all Code::Blocks projects.

Comments

  • jazzedjazzed Posts: 11,803
    edited 2012-11-19 16:18
    @SLRM,

    Thanks for this contribution. Sound's like you're set and ready to go.

    Cheers.
    --Steve
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-11-19 17:30
    Wow, this is gold. I was going to spend tonight trying to get this working. Thanks ++

    I downloaded wxSmith which makes adding buttons and textboxes etc easy. In the past I've written low level code to draw lines and boxes and fonts and buttons, so with some higher level code it ought to be possible to pull this all together and write and debug a GUI program on a PC, then change the compiler in code::blocks and maybe a software flag and run the same program on a propeller.
  • edited 2012-11-19 17:45
    Hi SLRM,

    It look great, I just test it on the Windows XP platform with codeblocks 10.05 and it works.
    I always want to use Code::Blocks as a Propeller IDE, but I am not good at writing the Makefile.

    Thanks for give me a good solution.


    I also did a little change to your setting(I have a little experiment on using the codeblocks).


    Actually, I have an other way to download the binary to RAM or EEPROM. And I also need to do some changes to your original Makefile.
    So I am going to copy some of your post and change to a window version.
    My PropGCC is installed into "D:\propgcc"


    [SIZE=+1]Setting Up a New PropGCC Project:[/SIZE]
    0. Make sure that PropGCC is installed correctly. You should be able to run the demo programs from the command line (with their makefiles and propeller-load).
    1. Open Code::Blocks, and create a new project (Console type, and C++).(Because you can define this in the Makefile, so no need to be C++)
    2. Under Project->Properties->Project Settings, check the "This is a custom Makefile" checkbox.
    3. Click on the "Build Targets" tab, and change the output filename to "main" (without quotes), and deselect the two check boxes beneath.(Because you can define this in the makefile, so don't care about the output name, I actually use the default output name "a.out")
    4. Change the "main.c" code to the following:
    5. Multiple file project: create and add file "test.c" to the project

    main.c
    #include <propeller.h>
    int main()
    {
        output_pin0();
        while(1)
        {
            toggle_pin0();
            waitcnt(CLKFREQ/20 + CNT);
        }
        return 0;
    }
    


    test.c
    #include <propeller.h>
    #define PIN_0 (1<<0)
    void output_pin0(void)
    {
        DIRA |= PIN_0;
    }
    void toggle_pin0(void)
    {
        OUTA ^= PIN_0;
    }
    
    



    6. In your favorite text editor, create a file called "Makefile" (without quotes), with the following contents:(I changed the Makefile, to support multiple files, and the output files name so that the follow setting can be used to other project)
    Code:
    PROJECT_FILES_NAME = main.c test.c
    COMPILE_FLAGS = -Wall -Os -m32bit-doubles -lm
    CC = D:\propgcc\bin\propeller-elf-gcc
    
    
    ifndef MODEL
    MODEL = lmm
    endif
    
    
    Release: Makefile $(PROJECT_FILES_NAME)
        $(CC) -m$(MODEL) $(COMPILE_FLAGS) $(PROJECT_FILES_NAME)
    
    
    cleanRelease:
        rm -f *.o *.elf *.out
    



    Set up the Download Tools
    7. Download setting
    Codeblocks software "Tools"->"Configure Tools"
    1) ["Add separator"(Option)]"Add"
    2) Name: "Propeller GCC Download RAM"
    Executable: "D:\propgcc\
    D:\propgcc\bin\propeller-load.exe -r .a.out"
    Click "OK"

    3) "Add" more to the tools

    4) Name: "Propeller GCC Download RAM(Termial)"
    Executable: "D:\propgcc\
    D:\propgcc\bin\propeller-load.exe -r -t .a.out"
    Click "OK"

    3) "Add" more to the tools

    4) Name: "Propeller GCC Download EERPOM"
    Executable: "D:\propgcc\
    D:\propgcc\bin\propeller-load.exe -r -e .a.out"
    Click "OK"

    Click "OK", now you can see three tools were added to the menu.

    You have to "compile" and "download"
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2012-11-20 11:43
    can you use spin and pasm through code blocks as well?
  • RossHRossH Posts: 5,462
    edited 2012-11-20 17:03
    SRLM wrote: »
    Basically, you'll give Code::Blocks a custom Makefile that will do all the compilation, via the Code::Blocks Makefile hooks. To get it to download and execute on the Propeller, you'll trick Code::Blocks into running a script when the Project "Run" command is selected, and this script will call propeller-load and download to the Propeller.

    Hi SLRM,

    This is good stuff - but you don't need to do this step. Code::Blocks has a built-in replacement for the Unix "make" utility that works under both Windows and Linux. There is no need to use Makefiles with Code::Blocks, and by doing so you may end up defeating some of the benefits of using Code::Blocks - especially when it comes to complex projects.

    The Code::Blocks compiler plugin already fully supports GCC, so you should be able to achieve what you are trying to do with some simple configuration "tweaks" - e.g. to tell Code::Blocks the location and executable filenames of your PropGCC compiler, linker etc. Everything else should "just work".

    Ross.
  • SRLMSRLM Posts: 5,045
    edited 2012-11-20 18:57
    @John
    Setting up Project:
    1. I choose the C++ option so that when you click the "new file" button, the default options are for .h and .cpp files.
    3. Yes, the selection of "main" is important because that's what the "run" command tries to execute. If you're not using that feature of the tutorial, you are correct: it isn't needed.

    Download Tools:
    Yes, that is one other way of doing it. I like the options of being able to download to various locations via adding custom commands.

    Just to clarify for thread readers, however, this way won't allow you to use the "build and run" command for single button compile and download.


    @rwgast
    Yes, but you won't have syntax highlighting or anything more than a basic editor. I use Gedit for Spin/PASM: http://forums.parallax.com/showthread.php?140139-Gedit-Spin-Syntax-Highlighting-gt-Solution!


    @Ross
    I found two issues with using the Code::Blocks built in build system:
    1. You can't compile to a different file than the file that the "run" command expects to execute. So, you can't have a single button compile and download cycle.
    2. You can't edit the compiler flags to add Propeller specific options (ok, maybe there is an XML file somewhere, but I don't want to get into that).
  • RossHRossH Posts: 5,462
    edited 2012-11-20 19:42
    SRLM wrote: »
    @Ross
    I found two issues with using the Code::Blocks built in build system:
    1. You can't compile to a different file than the file that the "run" command expects to execute. So, you can't have a single button compile and download cycle.
    2. You can't edit the compiler flags to add Propeller specific options (ok, maybe there is an XML file somewhere, but I don't want to get into that).

    I agree about (1) - I use an entry on the Tools menu to do the download - The tool knows the output file name of the project just compiled, so while you can't have a "single button" solution, you can have "two button" solution.

    As for (2), you can add your own custom compile or link flags - there are entries in the build options to allow you to do so. I used to have to do this for Catalina before I added a Catalina-specific version of the "compiler" plugin.

    Ross.
Sign In or Register to comment.