How to blink LED with QuickStart

Posted by Petr Hapal on 24 January 2013 | 0 Comments

Tags: , , , ,

I've discussed CodeWarrior installation and QuickStart configuration in my previous post. Here I would like to describe how to simply work with GPIO and blink LED. I have MC56F8006DEMO kit from Freescale so this example is created using it. If you have another kit or application you should choose appropriate processor type and use correct GPIO port. We will start creating a new project. Start CodeWarrior IDE, click File -> New... and in the dialog select DSP56800E Quick Start r2.x Stationary (if there is no such target your installation was not sucessful). Fill project name and project location (see picture below).

New project dialog

Click OK and processor selection dialog will appear. Choose appropriate processor (I have MC56F8006DEMO kit) and click OK.

Processor selection dialog

Default project tree will appear. Click main.c to open it. Now you should select your JTAG device - USB TAP is selected as default so if you have LPT JTAG please change it in Target settings (described one of previous posts).

Default project tree, main.c

QuickStart is set of on-chip drivers, functions and macros which helps you to start easily without wide platform kowledge. It contains graphical configuration tool that allows quick peripheral configuration using mouse. Lets see a piece of main.c:

 

    /* initialize SYS module - initialize system clock, power management, ... */

    ioctl(SYS, SYS_INIT, NULL);

    /* configure COP module  - initialize watchdog */

    ioctl(COP, COP_INIT, NULL);

    /* configure all GPIO modules - initialize GPIO module */

    ioctl(GPIO, GPIO_INIT_ALL, NULL);

    /* initialize interrupt controller and enable interrupts */

    ioctl(WINTC, WINTC_INIT, NULL);

    archEnableInt();

    /* initialize SYS module - initialize system clock, power management, ... */
    ioctl(SYS, SYS_INIT, NULL);
    /* configure COP module  - initialize watchdog */
    ioctl(COP, COP_INIT, NULL);
    /* configure all GPIO modules - initialize GPIO module */
    ioctl(GPIO, GPIO_INIT_ALL, NULL);
    /* initialize interrupt controller and enable interrupts */
    ioctl(WINTC, WINTC_INIT, NULL);
    archEnableInt();

ioctl stands for "I/O control" and it is a control macro for module configuration. First parameter is module name, second is command and last is data. You can see comperhesive docummentation in QuickStart users manual (see download links at the end). Our application will configure system module, watchdog, GPIO and interrupt controller. If you would like to use another peripheral (e.g. SCI) you should add another ioctl(SCI, SCI_INIT, NULL); for example. Lets see MC56F8006DEMO kit documentation now. We see that there are 6 LEDs at PA0/PWM0 to PA5/PWM5. Press Ctrl+F12 (or another shortcut you've entered during QuickStart configuration). Graphical configuration tool will appear (if not your installation was not successful).

Graphical configuration tool

MC56F8006 has a lot of peripherals connected out. But it has only QFP48 package. Each pin has multiple functionality (shared). You should select what peripheral will be routed out from/in to package simply by clicking checkboxs in graphical IC view. You should have GPIO_A0 to GPIO_A5 checked for our example. Now click GPIO_A in left peripheral tree and check it to enable. Now lets configure GPIO.

Graphical configuration tool - GPIO_A setup

You should select Output direction for Pin0 to Pin5. Click save icon and close configuration tool. Now we will change our source in following way:

 

/* Software delay function */

void delay()

{

long i;

for (i = 0; i < 1000000; i++)

{

asm(nop); // Do nothing instruction

}

}

 

void main (void) 

{

 

    /* initialize SYS module */

    ioctl(SYS, SYS_INIT, NULL);

    /* configure COP module */

    ioctl(COP, COP_INIT, NULL);

    /* configure all GPIO modules */

    ioctl(GPIO, GPIO_INIT_ALL, NULL);

    /* initialize interrupt controller and enable interrupts */

    ioctl(WINTC, WINTC_INIT, NULL);

    archEnableInt();

 

    while(1)

    {

    /* set bit3 to 5 to log. L */

    ioctl(GPIO_A, GPIO_CLEAR_PIN, BIT_3 | BIT_4 | BIT_5);

    /* set bit0 to 2 to log. H */

    ioctl(GPIO_A, GPIO_SET_PIN, BIT_0 | BIT_1 | BIT_2);

    delay();

    /* set bit3 to 5 to log. H */

    ioctl(GPIO_A, GPIO_SET_PIN, BIT_3 | BIT_4 | BIT_5);

    /* set bit0 to 2 to log. L */

    ioctl(GPIO_A, GPIO_CLEAR_PIN, BIT_0 | BIT_1 | BIT_2);

    delay();

     

         /* feed the watchdog periodically */

         ioctl(COP, COP_CLEAR_COUNTER, NULL);

    }

}

I hope there is nothing to say - there is software delay() function and we are changing port pins output logic level using GPIO_CLEAR_PIN and GPIO_SET_PIN functions.

Connect USB cable to kit for power supply. You do not have to install drivers. Connect JTAG adaptor.

Freescale MC56F8006DEMO kit

Now you can press F7 to build and F5 to flash and debug. Application will stop in beginning of main() after download. You can run by F5 or step in/over by F11/F10. Well done! You have created your first application on 56800/E platform.

DSP56800E_Quick_Start_Users_Manual.pdf

MC56F8006DEMO_UserGuide.pdf

project.zip

Post your comment

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments