The easiest way to dive in to ARM programming

[Brad] has been very excited about an ARM Cortex-M0 chip released by NXP; it’s a fully featured ARM microcontroller, and is, quite amazingly, stuffed into a hobbyist and breadboard-friendly DIP-28 package. After finding a supplier for this chip, [Brad] dove in and put together a great tutorial for programming an ARM on the breadboard using open source tools.

The chip in question is NXP’s LPC1114FN28, a 28-pin breadboard friendly chip we’ve posted about before. After finding a single supplier for this microcontroller (only $1.26 for one chip!), [Brad] pulled out his breadboard and started wiring things up.

Because this microcontroller has an on-board oscillator, wiring up a breadboard and putting in a breakout for an FTDI cable was a snap. After configuring a toolchain and writing a bit of code, the only issue was uploading the code to the chip. This was handled by the lpc21isp programming tool, slightly modified and configured by [Brad] to support his favorite microcontroller.

The LPC1114FN28 is an impressive bit of kit, and with free tools to program the damn thing, we can’t wait for a homebrew ARM dev board to show up.

Comments

  1. David says:

    32k flash, 4k of RAM, SPI, Serial, ADC, and I2C? Only $1.50? I’m not so updated but for this price, I only know the PIC12F683 (2kW flash, 128 B ram, 256 B E²PROM, ADC, PWM and only 6 I/O!). Which is the best PIC model near this price (with ADC). I Have PIC16F628A with plenty of legs but with the painfull lack oof ADC.

  2. Beat707 says:

    Loved the price, and yes, those chip are great, too bad they are a pain to program, so I will check those tutorials up and see if it helps things out. I also got the FEZ Panda and turned it into an ARM dev. board, by removing C#. hehehe, it works, as its also a NXP chip inside the FEZ Panda.

    Now, if only eBay would sell those chips…

    • David says:

      I checked eBay a minute after the read. Frustrating!

      • Beat707 says:

        Indeed, see my post below, expensive shipping, just sad, very sad… well, I guess I could check with some American friends and see if shipping is cheaper by using a friend to purchase and route those here? :-\

    • David says:

      For brazilians (como nós), eBay is the only option.

      • Beat707 says:

        I asked SparkFun.com to carry those, maybe if more people ask? ;-) I use them to ship things here in Brazil, cheaper shipping, and they also send as replacement parts, which is nice. If you haven’t used SparkFun.com yet, check it out, its a nice alternative for buying stuff from Brazil. Most stuff is a bit more expensive, so if its not on eBay, its there, but with a higher price. But still cheaper than buying on other sites like AVNET.

      • n0lkk says:

        Any hackerspaces in Brazil? Selling electronic components could be a fundraising opportunity for a hackerspace or any other tech orientated group. I’m not going to say it would be simple matter devoid of effort, but it should be worthy of investigation.

  3. Beat707 says:

    Hummmm, AVNET is stupid, $ 60 USD for shipping 10 chips to Brazil?!?!?!? That’s just sad… :-((((((

    • davidcdean says:

      Holy cow, $60? You think someone inside the US could just buy them and ship to Brazil for much less?

    • dizot says:

      I try to avoid buying anything in small quantities from Avnet, and I’m a domestic customer. They generally have better pricing than their big competitors [Mouser, Arrow, Newark, Digikey, etc], but their shipping costs are high and their packaging practices laughable. They have, on multiple occasions, sent me *really big* boxes to ship maybe 2 QFN chips. They charge the appropriate amount for a box that big. But a $0.45US stamp would have covered it. All of the big distributors do it, but Avnet and Arrow are the absolute worst in my experience.

    • Beat707 says:

      Its actually soccer, and oil is expensive here, and I hate samba. ;-)

      Ok, as for shipping, I can’t just order more to accommodate shipping, as stupid local laws don’t allow me to order anything that is price+shipping > $ 50 USD without having to pay 90% of extra custom taxes and some other fees.

      Resuming, anything above 50 bucks will get you nearly 3 times the price in fees. :-(

      Its a stupid country, really lame laws…

      • tidux says:

        You don’t like Samba? Do you use NFS, then?

        :P

      • putyn says:

        that problem exists in other countries too – for example in Romania i can only purchase goods worth of 10$ anything more and i have to pay duty taxes – good thing the ladies from the postal office have no idea what electronics components are worth

        as for shipping from USA – ive found someone on arduino forum who was willing to buy from mouser/digikey and ship to romania for as low as 10-15$ (that was the total cost shipping from vendor to him and from him to me)

  4. lucas says:

    I wonder…. wouldn’t it be easier to dive into ARM programming using qemu? That way, you wouldn’t be required to get hold of the hardware first. Of course, it is more fun to play with the hardware and see an actual LED blink (for instance). But diving in using qemu does eliminate the issue of having to produce the hardware before getting started.

    • cantido says:

      I’m not sure why you have to get into “ARM” coding.. if anything you need to learn the peripheral set your selected chip has and not specifically “ARM”. Once you have GCC and Newlib running most of the time the instruction set is interchangeable. For example I have code that runs on ARM7, H8 and m68k without any changes .. and most of the time the code I write is no different to that I would write if I was targeting Linux.

  5. Kompteck says:

    I got 5 free samples of the LPC1114FN28 months ago directly from NXPs through their university program. After reading this I ask myself “why?”. All this code modification and rigging can be avoided. I use LPCXpresso for my ARM programming and you can get a cheap lpc-link devboard from them that is explicitly designed for you to be able to cut off the JTAG programmer from the rest of the PCB and use it as a standalone JTAG for this and any other NXP ARM processor.

  6. Kuy says:

    Surely the easiest way to get into ARM development is with a board I designed specifically for loyal Hack a Day readers (including me!)

    http://www.kickstarter.com/projects/kuy/galago-make-things-better

    Galago is the smallest ARM dev board with an on-board programmer/debugger (a priceless feature) plus it supports GCC and GDB on Mac, Linux and Windows. Best of all, I designed it for you!

  7. Red (at) Szsz.pl says:

    $80 (or $120) for shipping to EU is a deal breaker…

  8. M4CGYV3R says:

    Or you could just reprogram a GameBoy Advance/DS

  9. Kingofl337 says:

    This chip has a serial boot loader, you just tie pin 24 to ground and reset.

  10. coward says:

    Is it safe to run an LED straight off the pin like that? (except PIO0_7)

  11. Uhrheber says:

    Funny, I’m just in the middle of writing nearly the same post for my blog.
    But unlike Brad, I’ve glued the programming interface onto the Chip, so I can use it also as a USB I/O for my breadboard.

  12. Uhrheber says:

    I’d recommend to use the excellent (and free) CooCox IDE with this mcu.

    http://www.coocox.org/

  13. TubeLover says:

    I designed a product using the Code Red tools (Ecclipse and GCC-based) for a LPC1111 some time ago. It is really powerful compared to 8bit controllers, and the timers are good. The code red tools worked well too, and I used the expresso without problems. The drawbacks are high power consumption. When running 48MHz I used 17mA (which is OK) and something like 8-11mA when in sleep (which is hardly worth the effort). Output drivers as not fast, and I needed to add some tinylogic to drive a MOSFET for switch mode conversion. Back then there were no EEPROM, but I can see, it has been added since. I would love to use one again.

  14. Chris Gorman says:

    Been playing with this chip for the past few weeks and I have to say it’s pretty awesome. I’m using it to control everything (drive motors, steppers, sensors, path finding logic) for a small robot project. And it’s so inexpensive that if more processing power is needed you can just throw another uProc into the mix. I am a big fan of opensource (and I appreciate the folks who make it happen), however for $38 you can get the Olimex ARM-JTAG-COOCOX programmer for Serial Wire Debug that enables on chip debugging and flashing. Combine that with the free version of Keil MDK-ARM (install the MDK driver from COOCOX.com) and you have a very nice workflow with minimal setup. The free version of Keil MDK is limited to 32K flash… but that happens to be the size of the flash on these devices.

    There are some comments about ARM being notoriously difficult to program. With more capability there is usually more complexity. But with the right abstraction layer(s) in place, this complexity can be mitigated. For example, most of the examples I’ve come across use standard bit shifting and masking to set the registers. This makes the code very hard to read and also error prone. My preference is to use C++ and overlay the uint32_t register with a structure containing named bitfields. The bitfields are written to look like the LPC11xx User Manual, so there is less room for error. For example:

    // LPC_IOCON->PIO0_8
    // I/O configuration for pin PIO0_8/MISO0/CT16B0_MAT0 (R/W)
    struct _PIO0_8
    {
    uint32_t FUNC : 3; // pin function
    uint32_t MODE : 2; // pull up/down resistor mode
    uint32_t HYS : 1; // Hysteresis.
    uint32_t reserved0 : 4;
    uint32_t OD : 1; // Selects pseudo open-drain mode
    uint32_t reserved1 : 21;
    };

    I then use inline functions to cast the ptr to register to the structure and then set/get the bit field values.

    #define PIO0_8_FUNC_GPIO 0x0
    #define PIO0_8_FUNC_MISO 0x1
    #define PIO0_8_FUNC_TIMER 0x2
    inline void IOCON_PIO0_8_FUNC(uint32_t val)
    {
    ((_PIO0_8*)&LPC_IOCON->PIO0_8)->FUNC = val;
    }

    The end result is code that reads like the LPC11xx User Manual and is just as efficient as C implementations because of the inlines. And best of all I let the compiler figure out all of the masks and bit shifts for me. Here is what programming the 16-bit timer for PWM looks like with these inline functions:

    void SetupPWM()
    {
    // Enables clock for 16-bit counter/timer 0
    SYSCON_SYSAHBCLKCTRL_CT16B0(SYSAHBCLKCTRL_ENABLE);
    // setup pin 1 for PWM output
    IOCON_PIO0_8_FUNC(PIO0_8_FUNC_TIMER);
    // disable pullup resistor pin 1
    IOCON_PIO0_8_MODE(PIO0_8_MODE_NO_RESISTOR);
    // set timer prescaler
    TMR16B0_PR_Set(SystemFrequency/10000); // TC = 10Khz
    // set match register 3 to reset TC
    TMR16B0_MCR_MR3R(MCR_ENABLE);
    // set PWM duty cycle
    TMR16B0_MR3_Set(100); // 100Hz
    // set pulse width
    TMR16B0_MR0_Set(0); // 0%
    // enable PWM mode on match register 0 (MR0)
    TMR16B0_PWMC_PWMEN0(PWMC_ENABLE);
    // enable counter
    TMR16B0_TCR_CEn(TCR_ENABLE);
    // reset timers
    //TMR16B0_TCR_CRst(TCR_RESET);
    }

    Of course this function could be wrapped in another abstraction, but at least the code is easy to read (imo). For anyone interested, I keep my code at github.com/engineergorman/lpc1114fn28. If you want to help build out the abstraction for all functions on the chip please let me know. Hope this helps some folks getting started.

  15. Harty says:

    here is a small project with LPC1114FN28 – an electronic dice:

    http://www.hwhardsoft.de/english/projects/electronic-dice/

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

Follow

Get every new post delivered to your Inbox.

Join 94,463 other followers