Toggling an LED on a Kinetis K70 board

by Crossware 23. March 2016 12:32

Toggling a pin is one of the first things to do on a new microcontroller board.

Our board has an LED on port B pin 18 and the C code for toggling that pin is shown below.

The program is built to run in the SRAM of the K70 microcontroller avoiding the need to over-write anything in the on-chip flash memory.

main()
{
    // disable the watchdog timer
    g_pWDOG->UNLOCK = 0XC520;
    g_pWDOG->UNLOCK = 0XD928;
    g_pWDOG->STCTRLH &= ~WDOG_WDOGEN;
    // enable the PORTB module
    g_pSIM->SCGC5 |= SCGC5_PORTB;
    // set PTB18 to ALT1 (GPIO)
    g_pPORTB->PCR18 &= ~(PORT_MUX0 | PORT_MUX1 | PORT_MUX2);
    g_pPORTB->PCR18 |= 1 << 8;
    // set PTB18 as an output
    g_pGPIOB->PDDR = 1 << 18;
    while (1)
    {
        // toggle the PTB18
        g_pGPIOB->PTOR = 1 << 18;
        for (int i = 0; i < 100000; i++);
    }
}

 

Tags: , ,

Blog

Switches and LEDs on the ADSP-CM408F EZ-KIT Lite Board from 'No Boot - idle' mode

by Crossware 26. August 2014 18:32

We like examples to be as simple as possible and this is as simple as we can make it for controlling both the switches and the LEDs on the ADSP-CM408F EZ-KIT Lite Board.

The switches SW4 and SW5 are disabled by default and so from a 'No Boot - idle' mode, the soft switches must be configured.  This means sending commands to the U40 chip using the TWI interface.

The TWI clock and data pins are not multiplexed and so there is no need to configure the GPIO in order to use them.

Possibly we could get away with fewer while loops in the code below and we could also run the TWI at a faster speed.  But it works as written and that should get you started.

Pressing SW4 turns on LED1 and turns off LED2.  Pressing SW5 turns on LED3 and turns off LED4.

 

#include "xstdsys.h"

#define DELAY 100000

#define LED1PIN 7
#define LED2PIN 6
#define LED3PIN 5
#define LED4PIN 9

#define SW4PIN 10
#define SW5PIN 8

main()
{
    g_pTWI0->CLKDIV = 0XFFFF;
    g_pTWI0->MSTRADDR = 0X0020;    // U40
    g_pTWI0->CTL = TWI_CTL_EN;

    // set register 13 (gpiob) U40 to 0X3E
    // register 1 (iodirb) defaults to 0XFF and so need not be configured
    g_pTWI0->MSTRCTL &= ~(TWI_MSTRCTL_DCNT0 | TWI_MSTRCTL_DCNT1 | TWI_MSTRCTL_DCNT2 | TWI_MSTRCTL_DCNT3 | TWI_MSTRCTL_DCNT4 | TWI_MSTRCTL_DCNT5 | TWI_MSTRCTL_DCNT6 | TWI_MSTRCTL_DCNT7);
    g_pTWI0->MSTRCTL |= 0X02 << 6;    // transmit 2 bytes
    g_pTWI0->TXDATA8 = 0X13;    // GPIOB
    g_pTWI0->MSTRCTL |= TWI_MSTRCTL_EN;
    while (g_pTWI0->FIFOSTAT & (TWI_FIFOSTAT_TXSTAT0 | TWI_FIFOSTAT_TXSTAT1));
    while ((g_pTWI0->ISTAT & TWI_ISTAT_TXSERV) == 0);
    g_pTWI0->ISTAT = TWI_ISTAT_TXSERV;
    g_pTWI0->TXDATA8 = 0X3E;     // leds and switches enabled
    while ((g_pTWI0->ISTAT & TWI_ISTAT_MCOMP) == 0);
    g_pTWI0->ISTAT = TWI_ISTAT_TXSERV | TWI_ISTAT_MCOMP;


    g_pPORTF->INEN_SET = 1 << SW4PIN;    // enable input
    g_pPORTE->INEN_SET = 1 << SW5PIN;    // enable input
    g_pPORTE->DIR_SET = 1 << LED1PIN;     // set as output
    g_pPORTE->DIR_SET = 1 << LED2PIN;     // set as output
    g_pPORTE->DIR_SET = 1 << LED3PIN;     // set as output
    g_pPORTE->DIR_SET = 1 << LED4PIN;     // set as output

    while (1)                   
    {
        if (g_pPORTF->DATA & (1 << SW4PIN))
        {
            g_pPORTE->DATA_SET = 1 << LED1PIN;
            g_pPORTE->DATA_CLR = 1 << LED2PIN;
        }
        else
        {
            g_pPORTE->DATA_CLR = 1 << LED1PIN;
            g_pPORTE->DATA_SET = 1 << LED2PIN;
        }
        if (g_pPORTE->DATA & (1 << SW5PIN))
        {
            g_pPORTE->DATA_SET = 1 << LED3PIN;
            g_pPORTE->DATA_CLR = 1 << LED4PIN;
        }   
        else
        {
            g_pPORTE->DATA_CLR = 1 << LED3PIN;
            g_pPORTE->DATA_SET = 1 << LED4PIN;
        }
    }
}

Tags: , ,

Blog

Toggling LEDs on ADSP-CM408F EZ-KIT Lite Board

by Crossware 26. August 2014 18:12

Here is the simplest example C program we can devise for toggling the LEDs on the ADSP-CM408F EX-KIT Lite Board.

All LEDs are on Port E.  By default the LEDs are enabled and so the soft switched do not need to be configured.  Only the GPIO directions need to be set to make them outputs.

#include "xstdsys.h"

#define DELAY 100000

#define LED1PIN 7
#define LED2PIN 6
#define LED3PIN 5
#define LED4PIN 9

main()
{
    // the following four lines could be combined into one if desired
    g_pPORTE->DIR_SET = 1 << LED1PIN;    // set as output
    g_pPORTE->DIR_SET = 1 << LED2PIN;    // set as output
    g_pPORTE->DIR_SET = 1 << LED3PIN;    // set as output
    g_pPORTE->DIR_SET = 1 << LED4PIN;    // set as output

    while (1)                   
    {
        for (volatile int i = 0; i < DELAY; i++);
        g_pPORTE->DATA_SET = 1 << LED1PIN;
        for (volatile int i = 0; i < DELAY; i++);
        g_pPORTE->DATA_CLR = 1 << LED1PIN;
        for (volatile int i = 0; i < DELAY; i++);
        g_pPORTE->DATA_SET = 1 << LED2PIN;
        for (volatile int i = 0; i < DELAY; i++);
        g_pPORTE->DATA_CLR = 1 << LED2PIN;
        for (volatile int i = 0; i < DELAY; i++);
        g_pPORTE->DATA_SET = 1 << LED3PIN;
        for (volatile int i = 0; i < DELAY; i++);
        g_pPORTE->DATA_CLR = 1 << LED3PIN;
        for (volatile int i = 0; i < DELAY; i++);
        g_pPORTE->DATA_SET = 1 << LED4PIN;
        for (volatile int i = 0; i < DELAY; i++);
        g_pPORTE->DATA_CLR = 1 << LED4PIN;
    }
}

 

Tags: , ,

Blog

Switches and LEDs on the ADSP-CM408F EZ-KIT Lite Board

by Crossware 15. August 2014 16:11

We are developing support for Analog Device's ADSP-CM40x microcontrollers.

We received our ADSP-CM408F EZ-KIT Lite board on Monday and set about investigating the operation of the JTAG/SWD debugger interface.  Pretty soon we could download and run programs in SRAM.  (Lots of omissions and errors in ADI's reference manual though so it took a lot longer to get there than it should have!)

As usual during such developments we incrementally work our way though the peripherals adding register definitions, simple context menu wizards, simulation and so on, testing that things work along the way.

There are lots of examples for this board provided by ADI but we couldn't find anything remotely simple.  So here is how to read the input switches SW4 and SW5 and illiminate the LEDs LED1 and LED 2:

// Initial CPP Source File
#include "xstdsys.h"

main()
{
    // use the Wizards (see Wizards menu) to configure the on-chip peripherals
    g_pPORTF->INEN_SET = 1 << 10;
    g_pPORTE->INEN_SET = 1 << 8;
    g_pPORTE->DIR_SET = 1 << 7;
    g_pPORTE->DIR_SET = 1 << 6;

    while (1)                   
    {
        if (g_pPORTE->DATA & (1 << 8))
            g_pPORTE->DATA_SET = 1 << 7;
        else
            g_pPORTE->DATA_CLR = 1 << 7;
        if (g_pPORTF->DATA & (1 << 10))
            g_pPORTE->DATA_SET = 1 << 6;
        else
            g_pPORTE->DATA_CLR = 1 << 6;
    }
}

Pressing SW4 illuminates LED2 and pressing SW5 illuminates LED1.  That's all there is to it if the board boots in the factory configuration (SPI master boot mode with POST installed).

However, the installed POST program has already configured the Soft Configuration switches.  To use the switches and LEDs from 'No Boot - idle' mode, the Soft Configuration switches must be configured.

Tags: , ,

Blog

Support for NXP ARM9 LPC29xx Family

by Crossware 18. September 2013 11:50

We have just released support for NXP ARM9 LPC29xx family of microcontrollers.

See this page for more details of this support:

www.crossware.com/Arm/Lcp29xx

Tags:

Blog

ColdFire Parallel Port Debugging on Windows 7

by Crossware 26. April 2013 07:38

We do not have a Windows 7 PC which has a parallel port and so we have never been able to try a ColdFire parallel port BDM interface on this operating system.  It was clear that parallel port debugging on the 64-bit version of Windows 7 was not going to be possible because our parallel port driver is a kernel driver and is not signed.  As such, Windows 7 64-bit edition will not allow it to be installed under any circumstances.

Now we have information from one of our ColdFire customers who has recently migrated our ColdFire Suite to new PCs that use Windows 7 32-bit edition.  They report that parallel port debugging with our ColdFire Suite and the P&E Micro parallel port BDM interface works successfully.

Tags:

Blog

First jState supporting Development Suite released

by Crossware 3. May 2012 15:01

jState is our new Javascript simulator extension interface.  With the V8 Javascript engine integrated into the environment, extending the Crossware Cortex-M3 simulator is fast and simple.

The STM32 Development Suite is the first package to incorporate jState and a new evaluation version is available: STM32 Development Suite Download.

For an introduction to jState see: jState Overview

For more details see:  jState Documentation

Tags: , , , , ,

Blog

Additional options when purchasing on-line

by Crossware 2. April 2012 17:38

We have added additional options to our on-line shop.

Firstly it is now possible to select Royal Mail Airmail as a carrier option for international shipments.  This delivery option takes longer (sometimes a lot longer - more than 4 weeks for Mexico!) but offers a cost saving over our traditional Fedex International Priority shipment method.

Secondly, we have added PayPal as a payment option so you can purchase items using your PayPal account.  Initially, payments will be processed in pounds sterling.  We will implement additional currencies when we become more familiar with the PayPal system.

Tags:

Blog

Simulator Extensions using Javascript

by Crossware 20. March 2012 15:13

 

We have integrated Google's V8 Javascript engine into the Crossware environment and is now possible for the simulators to be extended using Javascript.

We've called this interface jState and the next version of Crossware Cortex-M3 simulator will support jState.

You can find more information on jState here: jState - Javascript Simulator Extension Interface

 

Tags: ,

Blog

Suppressing integral promotion in the Crossware 8051 C Compiler

by Crossware 22. February 2012 09:09

We have recently been asked how to put the /Op option on the command line of the Crossware 8051 C Compiler when building from within the Embedded Development Studio IDE.

We do not recommend that the /Op option is applied from the command line.  It can lead to unpredictable results and applying it across a whole module or a whole project can potentially lead to hard to track down faults.

Instead we recommend that it is applied to specific functions using the optimize pragma.

Here is the html version manual page for the /Op option:

http://www.crossware.com/smanuals/c8051/suppress.html

At the bottom of that page is a link to the page for the optimize pragma:

http://www.crossware.com/smanuals/c8051/optimize.html

So you would do something like this:

unsigned char a, b, c, d;

#pragma optimize("p", on)

func()
{
    a = (b + c) / d;
}

#pragma optimize( "", on )

In this example, only the expressions in the function func() will have integral promotion suppressed.


Nevertheless, it is possible to apply command line options that are not specifically supported by the IDE by using the CCommandLine entry in a target.ini file.  See this page:

http://www.crossware.com/smanuals/estudio/_t117.html

Tags:

Blog

About this blog

This is where you will find topical information that we think might be useful to you.

Month List