User Tools

Site Tools


os:freertos:wsn430

Porting FreeRTOS on the WSN430 hardware platform

Download the latest archive from http://www.freertos.org and extract it. The FreeRTOS source files organization is as follows: there are two important folders. One is Source, it contains the four common files to every architecture with their headers, and the portable folder containing processor specific ports. The other, Demo, contains examples programs for a lot of hardware platforms.

There exists a port of FreeRTOS for the msp430f449 microcontroller on some hardware platform. Thus a few modifications need to be done in order to port it for the WSN430 platform. The port specific source files located in the Source/portable/GCC/MSP430F449 directory are completely compatible with the msp430f1611. Since it is easier to use it directly without renaming it, that’s what we’ll do. The code in this folders contain processor specific functions (such as configuration of the timer responsible for the scheduler tick interrupt.

We are now going to port the demo application to the WSN430 platform. Copy now the folder Demo/msp430_GCC to Demo/WSN430_GCC. There are a few files in it: main.c is the main source code that contains the main function. That’s where the tasks will be created and the scheduler started. The file FreeRTOSConfig.h contains a lot of configurations fields allowing the user to specify the characteristics of the kernel. Must be specified the speed of the main clock, the desired tick rate, the available memory on the target and the maximum number of priorities for example. Finally the file ’makefile’ contains the compiling directives.

The two directories ParTest and serial contain code for the demo application allowing to control the LEDs and a serial communication respectively. In our first tiny program, we won’t need them, they can be deleted. (For information, the target board of the initial port didn’t have LEDs but some LCD segments. It is more time consuming to adapt all the existing functions that to rewrite them)

  • FreeRTOSConfig.h: the included header (#include “msp430x44x.h”) at the top of the file is not for the same msp430. For simplicity, it may be replaced by #include “io.h”. Next the CPU clock frequency contained in the field configCPU_CLOCK_HZ should be updated to 8000000 (8MHz). The tick rate is set to 1000Hz, which is fine, as for the heap size that doesn't need to be increased.
  • makefile: Here we need to update the mmcu used by the compiler by replacing -mmcu= msp430x449 with -mmcu= msp430x1611 in the CFLAGS line. We don’t have to do the same for the PORT PATH line by replacing MSP430F449 since we saw above that the included source files works for both architectures. Finally in the SRC list, we’ll need just the minimal, hence we can remove the lines corresponding to ParTest, serial, flash, integer, comtest and PollQ.
  • main.c: In the main file, the easiest is to erase everything and start from scratch. We’ll go from top to bottom.

The required includes are:

/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"

Then we need some “defines” for simple LEDs handling:

/* LEDs config */
#define mainLED_TASK_PRIORITY (tskIDLE_PRIORITY + 1)
#define LED_OUT P5OUT
#define BIT_BLUE (1 << 6)
#define BIT_GREEN (1 << 5)
#define BIT_RED (1 << 4)

Then the file's prototypes:

/*
* The LEDs flashing tasks
*/
static void vTaskLED0( void *pvParameters );
static void vTaskLED1( void *pvParameters );
static void vTaskLED2( void *pvParameters );
/*
* Perform Hardware initialization.
*/
static void prvSetupHardware( void );

And the main function:

int main( void )
{
  /* Setup the hardware ready for the demo. */
  prvSetupHardware();
 
  /* Start the LEDs tasks */
  xTaskCreate( vTaskLED0, "LED0", configMINIMAL_STACK_SIZE, NULL, mainLED_TASK_PRIORITY, NULL );
  xTaskCreate( vTaskLED1, "LED1", configMINIMAL_STACK_SIZE, NULL, mainLED_TASK_PRIORITY, NULL );
  xTaskCreate( vTaskLED2, "LED2", configMINIMAL_STACK_SIZE, NULL, mainLED_TASK_PRIORITY, NULL );
 
  /* Start the scheduler. */
  vTaskStartScheduler();
 
  /* As the scheduler has been started the demo application
     tasks will be executing and we should never get here! */
  return 0;
}

We have now to develop the task functions:

/* First LED flash task */
static void vTaskLED0( void *pvParameters )
{
  while (1)
  {
    /* Toggle blue LED and wait 500 ticks */
    LED_OUT ^= BIT_BLUE;
    vTaskDelay(500);
  }
}
/* Second LED flash task */
static void vTaskLED1( void *pvParameters )
{
  while (1)
  {
    /* Toggle green LED and wait 1000 ticks */
    LED_OUT ^= BIT_GREEN;
    vTaskDelay(1000);
  }
}
/* Third LED flash task */
static void vTaskLED2( void *pvParameters )
{
  while (1)
  {
    /* Toggle red LED and wait 2000 ticks */
    LED_OUT ^= BIT_RED;
    vTaskDelay(2000);
  }
}

And finally the hardware setup function:

static void prvSetupHardware( void )
{
  int i;
 
  /* Stop the watchdog timer. */
  WDTCTL = WDTPW + WDTHOLD;
 
  /* Setup MCLK 8MHz and SMCLK 1MHz */
  DCOCTL = 0;
  BCSCTL1 = 0;
  BCSCTL2 = SELM_2 | (SELS | DIVS_3) ;
 
  /* Wait for cristal to stabilize */
  do {
    /* Clear OSCFault flag */
    IFG1 &= ~OFIFG;
    /* Time for flag to set */
    for (i = 0xff; i > 0; i--) nop();
  } while ((IFG1 & OFIFG) != 0);
 
  /* Configure IO for LED use */
  P5SEL &= ~(BIT_BLUE | BIT_GREEN | BIT_RED);
  P5OUT &= ~(BIT_BLUE | BIT_GREEN | BIT_RED);
  P5DIR |= (BIT_BLUE | BIT_GREEN | BIT_RED);
}

That’s it! Now you should be able to compile and load the program to the target, assuming required software (mspgcc) and hardware (JTAG FET) are installed and working. The three LEDs should be blinking at different rates!

os/freertos/wsn430.txt · Last modified: 2018/04/13 14:47 (external edit)