Adding a Delay to the ARM DAPLink Bootloader

The ARM mbed USB MSD bootloader which is used on many silicon vendor boards has a big problem: it is vulnerable to operating systems like Windows 10 which can brick your board (see “Bricking and Recovering OpenSDA Boards in Windows 8 and 10“). To recover the board, typically a JTAG/SWD programmer has to be used. I have described in articles (see links section) how to recover from that situation, including using an inofficial new bootloader which (mostly) solves the problem. The good news is that ARM (mbed) has released an official and fixed bootloader. The bad news is that this bootloader does not work on every board because of a timing issue: the bootloader mostly enters bootloader mode instated executing the application.

DAPLink in Bootloader Mode

DAPLink in Bootloader Mode

Continue reading

Advertisements

SQUIX ESP8266 based E-Paper WiFi Weather Station

I’m a fan of all kind of weather stations. When Daniel Eichhorn twittered about his new version using an E-Paper display module, I immediately preordered one. I decided to build a station with a custom enclosure, so here is my version of a 3D printed version, featuring magnets so it can be attached to the fridge:

E-Paper Weather Station

E-Paper Weather Station

Continue reading

Tutorial: Porting BLE+NRF Kinetis Design Studio Project to MCUXpresso IDE

The tools and IDE market is constantly changing. Not only there is every year at least one new major Eclipse IDE release, the commercial tool chain and IDE vendors are constantly changing the environment too. For any ARM Cortex-M development, the combination of Eclipse with the GNU tool chain provided by ARM Inc. is the golden standard. But this does not mean that things can be easily moved from one IDE package to another.

While moving between Eclipse versions and GNU versions is usually not a big deal at all, moving between the Eclipse build tool integration is usually not simple. While the GNU MCU Eclipse plugins are widely used (see Breathing with Oxygen: DIY ARM Cortex-M C/C++ IDE and Toolchain with Eclipse Oxygen), the Eclipse based IDEs from the silicon vendors or commercial Eclipse toolchain vendors are using  their own GNU toolchain integration. Which means the project files are not compatible :-(.

NXP FRDM-KW41Z Board

NXP FRDM-KW41Z Board

Continue reading

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 🙂

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