CooCox Hello World


As per my previous post, I started yesterday playing with a 32bit ARM processor, using the LM3S8962 evaluation board.

However, this comes with an evaluation version of the IAR compiler, which is limited to 32KB max code size and buying a licence is prohibitively expensive. Not only this, but the GUI seems somehow old and overcrowded, probably perfect for engineers that do this all day, but quite a steep learning curve for a beginner…

So here comes CooCox which is a “new and highly-integrated software development environment for ARM cortex M3 and M0 based microcontrollers, which includes all the tools necessary to develop high-quality software solutions in a timely and cost effective manner“.

It also includes CoOS which is a small real time OS, similar I suppose to the more well known FreeRTOS ?

So here’s how it looks the CoIDE, Eclipse based, quite clean and nice to use !

CoIDE - a clean and easy to use, Eclipse based IDE

The IDE seems to have an integrated flash programming software, but it needs a dedicated hardware, the CoLinkEx which I don’t have.

So I’m just generating the .bin file with CooCox and flashing it on to the LM3S8962 board, using the Flash Programmer provided by LuminaryMicro:

LuminaryMicro flash programmer that works with my LM3S8962 evaluation board

And finally, here’s my “hello world” program:

#include "hw_memmap.h" // for the base address of the memories and peripherals.
#include "hw_types.h"
#include "gpio.h"
#include "sysctl.h"

#define LED GPIO_PF2_LED1

int main(void)
{
 /* Set the clocking to run from PLL at 50 MHz */
 SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);

 /* Enable peripherals */
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

 /* Configure Status LED as output */
 GPIOPadConfigSet(GPIO_PORTF_BASE, LED,    GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
 GPIODirModeSet  (GPIO_PORTF_BASE, LED,    GPIO_DIR_MODE_OUT);

 while(1)
 {
 GPIOPinWrite(GPIO_PORTF_BASE, LED, 0);
 SysCtlDelay(7000000); // # each delay is 3 CPU cycles per tick. If the clock is 50Mhz, then 7 millions * 3 = roughly half a second
 GPIOPinWrite(GPIO_PORTF_BASE, LED, 1);
 SysCtlDelay(7000000);
 }
}

And the same program, BUT using CoOS and one thread:

#include "hw_memmap.h" // for the base address of the memories and peripherals.
#include "hw_types.h"
#include "gpio.h"
#include "sysctl.h"

#include <OsConfig.h>                   /*!< CoOS configure header file*/
#include <CoOs.h>                   /*!< CoOS header file               */


#define LED GPIO_PF2_LED1
#define  TASK_STK_SIZE  128

OS_STK       taskA_Stk[TASK_STK_SIZE];


void initBoard(void){
 /* Set the clocking to run from PLL at 50 MHz */
 SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);

 /* Enable peripherals */
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

 /* Configure Status LED as output */
 GPIOPadConfigSet(GPIO_PORTF_BASE, LED,    GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
 GPIODirModeSet  (GPIO_PORTF_BASE, LED,    GPIO_DIR_MODE_OUT);
}

void taskA(void* pdata){
 while(1){
 GPIOPinWrite(GPIO_PORTF_BASE, LED, 0);
 CoTimeDelay(0, 0, 0, 500); // now we can use specific timing functions that come with CoOS
 GPIOPinWrite(GPIO_PORTF_BASE, LED, 1);
 CoTimeDelay(0, 0, 0, 500); // delay of 0 hrs 0 mins 0 secs and 500 ms
 }
}

int main(void){
 initBoard();

 CoInitOS();
 // name of the task method / NO arguments / priority 1 / the stack to use / stack size
 CoCreateTask(taskA, (void *)0, 1, &taskA_Stk[TASK_STK_SIZE - 1], TASK_STK_SIZE);
 CoStartOS();

 while(1);
}
Advertisements

One Response to CooCox Hello World

  1. Pingback: Wii Motion Plus gyros on LM3S8962 (I2C on CooCox) « Robotics / Electronics / Physical Computing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: