LED’s for Kinetis, simplified

Sometimes it takes a while until things get better. Same thing applies to software: from time to time a refactoring and simplification makes sense. Especially if the underlying technology has been improved. With CodeWarrior for MCU10.3 available, it is time to refactor the LED component.

The ‘old’ way using GPIO_LDD

In my tutorial about using LED’s with the Freedom board, I showed how to use an LED component. For this, I used GPIO_LDD as this was the only way possible at this time:



GPIO_LDD is rather complex to set up. Even more, it was not possible to use a single interface for my LED. I had to add a dual interface. The connection from the LED component to the GPIO_LDD was done with special settings in the LED component properties:

GPIO_LDD Connection

GPIO_LDD Connection

So for ARM/Kinetis, it was using a LDD interface, where it was using BitIO for every other architecture. BitIO is using BitIO_LDD

The new way: BitIO is using BitIO_LDD

With the availability of CodeWarrior for MCU10.3, things finally have been improved: it is possible to use BitIO_LDD :-). CodeWarrior for MCU10.3 supports now the earlier BitIO component, and interfaces it automatically with the BitIO_LDD sub-component. With this, it is possible that I get rid of my LDD interface :-). Which makes everything easier to use.

Migrating to the new component

Unfortunately I have not found a good way to make things backward compatible. This means if you use that new LED component V1.047 or later, you need to configure it for the LED used. To transform a project from the ‘old’ the new simplified way, following steps need to be performed:

  1. Download the new LED component and install it in CodeWarrior/Processor Expert
  2. Open in CodeWarrior the project. The LED’s will show errors as not configured properly yet.
  3. Remove the GPIO_LDD’s used for the LEDs
  4. For each LED, configure the LED pin according to the pin connection:

    Configuring LED Pin

    Configuring LED Pin

What happens is that for each LED, the BitIO sub-component will automatically add and configure a BitIO_LDD component:

BitIO_LDD Component

BitIO_LDD Component

:idea: Creating new projects will automatically use the new LED interface, so no extra step is needed.


Although things are not backward compatible, the usage of the new LED component is now simpler with the usage of BitIO_LDD. The new LED component is available here. I have updated the Freedom Board example projects too.

Happy LEDing :-)

17 thoughts on “LED’s for Kinetis, simplified

  1. Pingback: PWM and Shell for a LED | MCU on Eclipse

  2. Pingback: Back to Basic(s) with the Freedom Board | MCU on Eclipse

  3. Hi Erich,

    I am not able to compile the generated inline assembly code by using either GCC or ARM compilers. Is there anything I need to do to make my code compile?

    For example, this piece of code, which simply waits for 10 CPU cycles,

    /* This function will wait 10 CPU cycles (including call overhead). */
    asm {
    /* NOTE: this is not really accurate, as not sure yet about the cycle counts */
    nop /* assuming one cycle for nop */
    nop /* assuming one cycle for nop */
    nop /* assuming one cycle for nop */
    nop /* assuming one cycle for nop */
    nop /* assuming one cycle for nop */
    nop /* assuming one cycle for nop */
    nop /* assuming one cycle for nop */
    nop /* assuming one cycle for nop */
    nop /* assuming one cycle for nop */
    nop /* assuming one cycle for nop */

    ARM compiler complains
    ./Generated_Code/WAIT1.c(51): error: #20: identifier “asm” is undefined
    While GCC compiler complains
    ./Generated_Code/WAIT1.c(51): error: expected ‘(‘ before ‘{‘ token
    ./Generated_Code/WAIT1.c(53): error: unknown type name ‘nop’
    ./Generated_Code/WAIT1.c(55): error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘nop’

    And this piece of code
    __asm void Cpu_EnterCritical(volatile uint8_t *SR_reg) {
    PUSH {R0,R1}
    CPSID i
    STRB R1, [R0]
    POP {R0,R1}
    BX LR
    ALIGN 4

    gives this error in GCC compiler
    ./Generated_Code/Cpu.c(132): error: expected ‘(‘ before ‘void’
    ARM compiler didn’t complain anything, but it might just be that it halted before it.

    Thanks a lot!


      • Good to hear that things are working now :-). But I’m wondering why you had this problem, because CodeWarrior automatically sets the correct compiler. Do you know why you had a wrong setting?


      • I am not actually using Code Warrior (because I don’t have its license). I am just using the stand alone processor expert software to generate code, convert that into a Keil Microvision project and compile/debug it there. I didn’t realize that by default the code is generated in Code Warrior syntax.

        By the way, what other compilers do you support, other than the CW compiler and GNU compiler?


      • You do not need a CodeWarrior license: without a license, it is limited to 64 KByte code size for Kinetis-L which is a lot. Other CPUs have even a 128 KByte limit, so plenty of room to do development free of charge.
        And I support right now IAR, CW and GCC compiler syntax. As long as it is ‘C’, no issue with other compilers. But of course the assembly language syntax is many times different for different compilers (like in the WAIT module).


  4. Pingback: Tutorial: Enlightning the Freedom KL25Z Board | MCU on Eclipse

  5. Pingback: Using the FRDM-KL25Z as USB Keyboard | MCU on Eclipse

  6. Pingback: Tutorial: Ultra Low Cost 2.4 GHz Wireless Transceiver with the FRDM Board | MCU on Eclipse

  7. Pingback: First Steps with the Freescale TWR-K64F120M | MCU on Eclipse

What do you think?

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