Compiler Explorer

If you are like me – someone who always wants to know what the compiler generates for a piece of source code – then have a look at the Compiler Explorer: A web-based compiler code comparison tool:

Compiler Comparison

Compiler Comparison

Thanks to Matt Godbolt, I can select different compilers and compare their output for a given source code. Very useful to see the impact of a compiler optimization or to compare different GCC compiler versions.

Happy Comparing 🙂

Advertisements

Is Developing for ARM more difficult than for other Architectures?

I believe in ‘life-long-learning’. With this I continue to learn and discover new things every day. I’m writing tutorials to give something back to the community from which I have learned so much.

On top of this, I receive emails on a nearly daily basis, asking for help. Many articles have the origin in such requests or questions. I prefer questions or comments in a public forum, because that way I feel all others can benefit from it. Last week Alessandro contacted me with this:

“Hi Erich,

I hope this find you well! I’m starting to using ARM processors, but I find them quite complicated on the configuration side. I started in the past with PIC micro (PIC16) with asm, and I found them quite straightforward to be configured (clock, IO, peripherals, …). Then I moved myself on C language, and on PIC18 without any big issues.

Now I would really like join the ARM community, I see that these processors are what I’ve always looking for, on energy, calc power, peripherals, and FINALLY on IDE (editor, toolchain and utilities)… AMAZING!!!”

The topic is about how to start learning developing for ARM. Alessandro agreed to make this public, so I thought this might be a good topic for an article?

Firmware

Firmware

Continue reading

Debugging ARM Cortex-M0+ HardFaults

To me, one of the most frustrating things working with ARM Cortex-M cores are the hard fault exceptions. I have lost several hours this week debugging and tracking an instance of a hard fault on an ARM Cortex-M0+ device.

Next assembly step will cause a hard fault

Next assembly step will cause a hard fault

Continue reading

ARM Cortex-M Interrupts and FreeRTOS: Part 3

This is the third part about ARM Cortex-M and how the interrupts are used. In Part 1 I discussed the Cortex-M interrupt system and in Part 2 I showed nested interrupt examples. This part is about FreeRTOS and how it uses the Cortex-M interrupt system.

NXP KV58F ARM Cortex-M7

NXP KV58F ARM Cortex-M7

Continue reading

ARM Cortex-M, Interrupts and FreeRTOS: Part 1

The ARM Cortex-M microcontroller are insanely popular. And it features a flexible and powerful nested vectored interrupt controller (NVIC). But for many, including myself, the Cortex-M interrupt system can be counter-intuitive, complex, inconsistent and confusing, leading to many bugs and lots of frustration :-(.

NXP KV58F ARM Cortex-M7

ARM Cortex-M7: NXP KV58

Understanding the NVIC and the ARM Cortex-M interrupt system is essential for every embedded application, but even for if using an realtime operating system: if you mess up with interrupts, very bad things will happen….

Continue reading

Assembly Files in Eclipse CDT Projects

My embedded applications are implemented mostly in C, a few in C/C++. But all of them have one or few assembly files included too: Assembly programming is the needed to do low-level things so it is a natural part of a true embedded application. For example I use often an assembly file for the application startup code.

I have run into a nasty Eclipse CDT issue which deals with assembly files projects. Here is a quizz for you: can you spot the problem in my project below?

Startup Assembly Code

Startup Assembly Code

Continue reading

GNU gcc printf() and BuiltIn Optimizations

Readers of my blog know: I’m not a fan of printf(), and I think for many good reasons. Still printf() is widely used, and the GNU gcc tries to optimize things. This is observed with a simple example: If I’m writing

printf("a");

Then the code produced (ARM Cortex-M0+ with GNU ARM Embedded 4.9 2015q2 gives:

movs r0, #97    ; 0x61
bl 0xa98

Instead of calling printf(), it is calling putchar()! Why is that?

PutChar instead of Printf

PutChar instead of Printf

Continue reading

NVIC: Disabling Interrupts on ARM Cortex-M and the Need for a Memory Barrier Instruction

Mastering interrupts is critical to make an embedded application reentrant. The challenge with reentrancy is that things might be implemented in a wrong way and the issue might just show up sporadically (see “EnterCritical() and ExitCritical(): Why Things are Failing Badly“). The ARM Cortex interrupt controller is named NVIC (Nested Vectored Interrupt Controller).

ARM Cortex NVIC Registers

ARM Cortex NVIC Registers

Continue reading

Debugging ARM Cortex-M Hard Faults with GDB Custom Command

In “A Processor Expert Component to Help with Hard Faults” I’m using a C handler with some assembly code, created with Processor Expert, to help me with debugging hard faults on ARM Cortex-M. Inspired by a GNU gdb script here, I have now an alternative way. As this approach is using the GDB command line approach, it works both with an Eclipse GUI and with using GDB in command line mode only :-).

GDB script to debug ARM Hard Faults

GDB script to debug ARM Hard Faults

Continue reading

Tutorial: How to Erase the FLASH with the GNU GDB debugger

I have several applications where I store application specific information in the microcontroller FLASH memory (see “Configuration Data: Using the Internal FLASH instead of an external EEPROM“). I have run into issues recently with the Segger J-Link GDB server as by default it does *not* erase all the FLASH memory. So the question is: How can I erase all (or part) of the FLASH memory with GDB (e.g. in Kinetis Design Studio or in Eclipse)?

Memory Monitor with Erased Flash

Memory Monitor with Erased Flash

Continue reading

GNU Libs with Debug Information: Rebuilding the GNU ARM Libraries

With my DIY tool chain (see “Constructing a Classroom IDE with Eclipse for ARM“) I get a complete tool chain. I do not need to build that tool chain from the sources for Windows, as all the binaries are nicely pre-compiled and made available. But there is one issue I face from time to time: as the libraries provided by ARM do not come with sources and debug information enabled, I end up with that “No source available for …” message in the debugger:

No Source Available

No Source Available

The solution is to grab the C/C++ library sources from the ARM launchpad site and get it built locally the way I need it.

Continue reading

EnterCritical() and ExitCritical(): Why Things are Failing Badly

I have carefully implemented my firmware. It works perfectly for hours, days, months, maybe for years. I there would not be a problem: the firmware crashes sporadically :-(. Yes, I’m using watchdogs to recover, but hey: it is a serious problem. And because it happens only under rare and special conditions, it is hard to track it down or to debug it.

Accessing shared data

Accessing shared data from the main application and from an interrupt

The thing is: these nightmares exist, and they are real and nasty. I’m pushing my students hard on this topic: It is about how to protect critical sections. And what could go wrong. And here is just yet another example: how it can go badly wrong if you are not careful. And it took me a while too to realize where the problem is. It was not a fun ride….

Continue reading

DIY Free Toolchain for Kinetis: Part 8 – Processor Expert, Eclipse and GNU ARM Eclipse Plugins

There has been many new releases these days: Freescale released Processor Expert Driver Suite 10.3, and Liviu Ionescu released new GNU ARM Eclipse Plugins with new and updated documentation. So time for me to show how this all comes together 🙂

Processor Expert Driver Suite 10.3 Project with GNU ARM Eclipse Build Tools

Processor Expert Driver Suite 10.3 Project with GNU ARM Eclipse Build Tools

It is now easier than ever before to use the GNU ARM Eclipse plugins and Processor Expert. There are still some manual steps, and this post is about all the details to get it working as smooth as possible.

Continue reading

Zumo Robot assembled

This week we were busy with building and documenting the first robots based on the Zumo Robot Chassis PCB.

Chassis Base PCB

The chassis is designed to hook up the FRDM-KL25Z board from Freescale. It is using parts from Pololu (chassis, motors, DC-DC converter, line sensor, H-Bridge, encoders):

ZumoBaseBoardOverview

Zumo Base Board Overview

Continue reading

DIY Free Toolchain for Kinetis: Part 2 – Eclipse IDE

This is the second part of a multi-part tutorial about how to set up an open source tool chain with GNU ARM gcc + Eclipse to build and debug an application for Kinetis ARM devices.

List of Tutorials

Eclipse Kepler

Eclipse Kepler

Continue reading

A Processor Expert Component to Help with Hard Faults

Ahrg! Again my ARM application crashed somewhere and I ended up in a HardFault exception :-(. In my earlier post I used a handler to get information from the processor what happened. But it is painful to add this handler again and again. So I decided to make things easier for me: with a special HardFault Processor Expert component :-).

After adding this HardFault component to my project, it automatically adds an entry to the vector table. So no manual steps are needed: having the component in the project and enabled will do the needed steps.

Continue reading

Debugging Hard Faults on ARM Cortex-M

It is as bad as this: my application stopped in an unhandled interrupt service routine:

Cpu_Interrupt

Cpu_Interrupt

That does not tell much. I’m using Processor Expert generated code, and with this all my ‘unhandled’ vectors are pointing the same handler:

Continue reading

MCU10.2 Update 1.0.0 released

The update 1.0.0 for the MCU10.2 release has been published on the Freescale CW MCU V10.2 Updates & Patches web site. Downloading the 500 MByte zip file and installing the update will take a while. After downloading I select Help > Install New Software … and specify the archive file.

Note: In general uninstalling an eclipse update is not possible. If you want to keep our original MCU10.2 on the side, then follow this trick: Copy your existing MCU10.2 installation folder and rename it (say to ‘MCU10.2_without_update’). Then apply the update to the normal MCU10.2. If you want to revert to the version without the update, simple delete the updated installation and rename the one without the update again. No need to reinstall things again. And you can use both the updated version and the normal version in parallel too: simply launch the eclipse\cwide you want 🙂

Time to read the release notes and dig into what has been changed and improved.

Continue reading

Go, assembly, go!

As mentioned in my post about the memory view:  I want to go down to the bits and bytes. Same applies to programming: I want to get down to the assembly instruction level, the heavy metal world :-).

Although it sounds a little bit weird in the age of object-oriented programming and C++, but sometimes I need to do ‘assembly level only’ programming on a 32bit controller too. CodeWarrior for MCU offers assembly only project creation for all the 8bit microprocessors, but for the 32bit including the ColdFire it assumes that the usual way is to use C and C++? Yes, it offers C and C++ and you can add assembly files. But how to do assembly only?
Continue reading