Windows Is Depressing

Ok, here’s a super odd bug on Windows. I started getting a bunch of errors in various programs.

CoolTerm said: “Runtime Error” with “Failure Condition: mutex.mLockFile”

CoolTerm error

Process Explorer complained that it was “Unable to extract 64-bit image. Run Process Explorer from writeable directory.”

Process Explorer Error

This of course didn’t make sense, as the program was in a writeable folder, but then it dawned on me that both of these programs could be trying to use my account’s TEMP folder.

So, I’m super annoyed. Somehow my user account’s TEMP folder got wiped out, and replaced as a file instead, which obviously can’t contain more files.

Temp folder is a file now?

The solution in this case was to erase the Temp file and create a new TEMP folder. But it is insane to me that all the programs that rely on a writeable TEMP folder would give such terrible hints that this was the problem’s source. It also would be awesome if Windows would autorepair this condition at startup.

Atmel Studio Device Pack Problems

Atmel Studio has bad package handling.

If, after updating your Device Packs, you start getting problems using the Device Programming window:

23:38:28: [ERROR] Unhandled exception while parsing part description file C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.0.90\atdf\ATmega328P.atdf
23:38:36: [ERROR] Unhandled exception while parsing part description file C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.0.90\atdf\ATmega325.atdf
23:38:38: [ERROR] Unhandled exception while parsing part description file C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.0.90\atdf\ATmega645A.atdf
23:38:40: [ERROR] Unhandled exception while parsing part description file C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.0.90\atdf\ATmega1284.atdf

The problem is that for some reason, the %LOCALAPPDATA%\Local\Atmel\AtmelStudio\7.0\atPacks.db file doesn’t get updated to reflect the paths to the new packages.

I suspect that this might be because for some reason running the Device Pack Manager requires Administrator privileges, but the atPacks.db file is generated on a per-user basis. So probably the code is getting confused as to which %LOCALAPPDATA% folder it needs to write to.

In any case, the atPacks.db file isn’t updated, which you can see if you open up the file (which is a standard SQLite database) in an SQLite browser:

Device Pack update fail.

Here’s the fix:

  • Open Windows Explorer
  • Enter %LOCALAPPDATA%\Atmel\AtmelStudio\7.0 in the location bar
  • Delete atPacks.db.

Atmel Studio will regenerate the atPacks.db file when it starts again. (Which makes you wonder why they don’t just do the detection at start all of the time, which takes negligible time if you have an SSD. You do have an SSD, don’t you?)

printf() isn’t always your friend

One thing you can say about embedded microprocessors: Running out of stack, heap, and flash memory is actually possible, and a difference of 8 kilobytes can actually make or break your code.

In these cases of memory pressure, you need to wring out all of the most dubious code in your codebase. Usually, this takes the form of removing parts of the C library or other transitively-included libraries that add bulk but are not strictly necessary.

Here’s a an example project that overran the runtime boundaries on a Nordic nRF51 Development Kit. Note that the total flash size is approaching the maximum-available user program storage space. Looking at the linker script, it’s apparent that there’s a total of 148KB available for programs and 20744 bytes of available for RAM:

On the particular chip I’m using, there’s a total of 256KB flash and 32KB of RAM. The first ~16KB are chewed up by a bootloader, the next ~110KB are chewed up by the SoftDevice code. So that leaves around 148KB free for user code. But this may not be a hard rule. The minute I crossed the ~120KB code-size mark, I started getting hard faults at runtime:

When the chip jumps into a situation of hard error, the kit will start flashing its LEDs in a criss-cross repeating pattern, like so:

If you’re watching the serial port, the error string Operator new out of memory may appear.

Remove printf()

Turns out that printf() on an ARM Cortex-M0 adds 8 kilobytes to the program size, which is about 1/16th of the usable flash memory on the chip.

Removing all instances of printf() can help:

Out of Memory

The bigger problem appears to be the fact that the program runs out of memory. Examining the compiler output, it’s clear that the Total RAM memory in use is, in both of the above cases, dangerously close to the total RAM limit stated in the Linker script.

And in fact, in a different program that I’ve been working on, even though the total Flash memory is even smaller than the above, the total RAM memory in use is enough to throw the whole program over the edge:

What else can be thrown out? Stay tuned.

Turning on the verbose compile options, one can see a ton of compiler defines, of which some might be removed to disable certain pieces of code in the underlying architecture:

Smartphone / Tablet / Ultrabook Holder

I spent a bit too much time playing video games the past few weeks, so my “you need to be productive” meter finally tripped, and I spent a few hours making a “smart device” holder to make up for it.

It was actually not nearly as hard as I thought it would be, but there’s a lot of magic in the design work and design software that I will have to absorb before I’m nearly as good as one of my coworkers (to be fair, she’s a MechE):

smartphone tablet ultrabook holder