# Porting the main\_blinky.c from the CORTEX-R4\_TI\_CCS5 sample code to the LAUNCHXL2-RM46

**URL:** <https://forums.freertos.org/t/porting-the-main-blinky-c-from-the-cortex-r4-ti-ccs5-sample-code-to-the-launchxl2-rm46/8726>\
**Category:** Texas Instruments\
**Created:** [January 31, 2020, 5:31am UTC](https://forums.freertos.org/t/porting-the-main-blinky-c-from-the-cortex-r4-ti-ccs5-sample-code-to-the-launchxl2-rm46/8726 "2020-01-31T05:31:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlie](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@charlie](https://forums.freertos.org/u/charlie)\
**Post date:** [January 31, 2020, 5:31am UTC](https://forums.freertos.org/t/porting-the-main-blinky-c-from-the-cortex-r4-ti-ccs5-sample-code-to-the-launchxl2-rm46/8726/1 "2020-01-31T05:31:11Z")

</div>

I am porting the main\_blinky.c code from the CORTEX-R4\_TI\_CCS sample code to the LAUNCHXL2-RM46 launchpad board. I’m using CCS v9.10 and FreeRTOS Kernel V10.2.1.

The sample code uses the ParTest.c functions vParTestInitialise and vParTestToggleLED. I have modified both of these functions to reference gioPORTB instead of the hetPORT, and to toggle the two LED’s attached to PORTB bits 1, and 2. I have also modified the ulLEDBits to be 1 and 2, which are the port B bits connected to USER LED A and B.

It seems like the code should work but doesn’t. Any ideas would be greatly appreciated!

partest.c:

```auto
/* Port bits connected to LEDs. */
const unsigned long ulLEDBits[] = { 1, 2 }; //PortB LED bits
/* 1 turns a LED on*/
const unsigned long ulOnStates[] = { 1, 0 };

const unsigned long ulNumLEDs = sizeof( ulLEDBits ) / sizeof( unsigned long );

/*-----------------------------------------------------------*/

void vParTestInitialise( void )
{
unsigned long ul;

	/* Initalise the IO ports that drive the LEDs */
    gioSetDirection( gioPORTB, 0xFF );

	/* Turn all the LEDs off. */
	for( ul = 0; ul < ulNumLEDs; ul++ )
	{
	    gioSetBit( gioPORTB, ulLEDBits[ul], !ulOnStates[ul] );
	}
}
/*-----------------------------------------------------------*/

void vParTestSetLED( unsigned long ulLED, signed long xValue )
{	
	if( ulLED < ulNumLEDs )
	{
		if( xValue == pdFALSE )
		{
			xValue = !ulOnStates[ulLED];
		}
		else
		{
			xValue = ulOnStates[ulLED];
		}
		gioSetBit( gioPORTB, ulLEDBits[ulLED], xValue );
	}
}
/*-----------------------------------------------------------*/

void vParTestToggleLED( unsigned long ulLED )
{
unsigned long ulBitState;

	if( ulLED < ulNumLEDs )
	{
	    ulBitState = gioGetBit( gioPORTB, ulLEDBits[ulLED] );
	    gioSetBit( gioPORTB, ulLEDBits[ulLED], !ulBitState );
	}
}

```

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [January 31, 2020, 2:22pm UTC](https://forums.freertos.org/t/porting-the-main-blinky-c-from-the-cortex-r4-ti-ccs5-sample-code-to-the-launchxl2-rm46/8726/2 "2020-01-31T14:22:56Z")

</div>

Unless I’m missing something, I don’t think this is a FreeRTOS question, but rather a hardware question…all the same:

There is nothing in these functions that requires the scheduler to be running, so I suggest you just develop and test these functions from main() - before calling vTaskStartScheduler() - just to make your life easier.

I would then suggest looking through the examples TI provide with the board to find some that use the LEDs - try running that example to see the LEDs working - then just copy that. It might be something to do with how the hardware is initialised, before you actually access the LEDs. Perhaps even before calling gioSetDirection() you may need to set up the type of output.

---

<div class="post-metadata">

**Author:** ![charlie](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@charlie](https://forums.freertos.org/u/charlie)\
**Post date:** [February 1, 2020, 3:59am UTC](https://forums.freertos.org/t/porting-the-main-blinky-c-from-the-cortex-r4-ti-ccs5-sample-code-to-the-launchxl2-rm46/8726/3 "2020-02-01T03:59:42Z")

</div>

Thank you for your response. What you said about setting up the port for the type of output was the key; I was not calling gioInit(). The port is now working. Thank you.

I do have a question now that is freeRTOS related: the LEDs are not blinking at the programmed rate of 1000 msec, but at about 320mS. I changed configCPU\_CLOCK\_HZ to 16000000 in FreeRTOSConfig.h and the mainQUEUE\_SEND\_FREQUENCY\_MS to 1000 in main\_blinky.c. What am I missing?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 1, 2020, 5:58pm UTC](https://forums.freertos.org/t/porting-the-main-blinky-c-from-the-cortex-r4-ti-ccs5-sample-code-to-the-launchxl2-rm46/8726/4 "2020-02-01T17:58:32Z")

</div>

Are you 100% sure that configCPU\_CLOCK\_HZ is set to frequency of the clock used to generate the tick interrupt?

What do you have configTICK\_RATE\_HZ set to?

---

<div class="post-metadata">

**Author:** ![charlie](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@charlie](https://forums.freertos.org/u/charlie)\
**Post date:** [February 1, 2020, 7:48pm UTC](https://forums.freertos.org/t/porting-the-main-blinky-c-from-the-cortex-r4-ti-ccs5-sample-code-to-the-launchxl2-rm46/8726/5 "2020-02-01T19:48:43Z")

</div>

I measured the crystal freq on a scope at 16MHz and set:  
configCPU\_CLOCK\_HZ = 16000000  
configTICK\_RATE\_HZ = 1000  
mainQUEUE\_SEND\_FREQUENCY\_MS = ( 1000 / portTICK\_PERIOD\_MS )

The toggle occurs at a 320mS rate instead of a 1000mS rate.

Are there any other timing settings that would affect this? I don’t see any.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 1, 2020, 9:03pm UTC](https://forums.freertos.org/t/porting-the-main-blinky-c-from-the-cortex-r4-ti-ccs5-sample-code-to-the-launchxl2-rm46/8726/6 "2020-02-01T21:03:38Z")

</div>

The crystal speed is unlikely to be the speed that feeds the clock as it will go through a PLL or other subsystem.

---

<div class="post-metadata">

**Author:** ![charlie](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@charlie](https://forums.freertos.org/u/charlie)\
**Post date:** [February 1, 2020, 10:45pm UTC](https://forums.freertos.org/t/porting-the-main-blinky-c-from-the-cortex-r4-ti-ccs5-sample-code-to-the-launchxl2-rm46/8726/7 "2020-02-01T22:45:49Z")

</div>

Thanks for that - it’s fixed. I now understand the clock source / tree / pll etc…

Thanks very much for your help. You definitely move me forward a lot. I really appreciate your time.
