Flash-based Configuration Data Using The ld Linker

Here is an easy way to store and use configuration data in the flash memory of a microcontroller.

This places the configuration data at a specific absolute memory address and uses no special pragmas to enable read access.

This is a slight reworking and consolidation of what MCU on Eclipse suggests, and slightly easier than marking variables with __attribute__((section(".etwas"))) all the time, though that is useful in other cases. Also, the SEGGER J-Link debugger on my development kit was always erasing the configuration data (as I’d placed it between other code and data, at a pretty low flash address), which was the opposite of the problem MCU on Eclipse was having. So, I needed a way to protect specific flash regions from getting erased, as Kinetis Design Studio has no easy options for this.

Continue reading Flash-based Configuration Data Using The ld Linker

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.

EAGLE CAD Custom Parts Gotchas

Here are some notes and reminders to myself, things to double and triple-check when creating a custom part.

These are things that I’ve messed up.

Package Creation

EAGLE Layers

Top (or Bottom) means exposed copper on the board, use the “Land Pattern” information in the datasheet to create these pads:

Land pattern = the exposed copper

tStop (bStop) means no colored solder mask applied in this area, so the copper is cleanly exposed, usually a bit larger than the copper pads:

qfn24-solder-mask-is-tstop

tCream (bCream) shows the size of the stencil openings, usually a bit smaller than the size of the copper pads:

qfn24-stencil-is-tcream

Note that the dimensions of tStop > Top > tCream, which makes sense. tCream is the smallest, because you usually actually don’t want your solder going all the way to the edge of the exposed copper. You get short circuits that way.

The tCream Stencils Are Usually Pretty Messed Up

One huge issue encountered quite frequently when using SMD parts in EAGLE is that the tCream pad sizes simply put too much solder paste onto the board.

tcream-equals-pad-size

People need to remember to adjust their device Packages and shrink the tCream rectangles, particularly for large pads that could cover a lot of paste and cause shorts under the package.

The default SMD part in EAGLE has tCream covering the entire pad, which will probably be a problem.

You can use the Design Rule Check -> Masks -> Cream setting to shrink the size of the stencil by some amount, but it’s not clear that this is the most effective way to design the stencil. It may require more specific, per-Package tuning. Using the DRC setting applies the rules to all SMD devices in the design.

drc-cream-change

But this doesn’t make sense, for instance, for simple devices like a 0805 resistor or capacitor, as having a lot of solder most likely will not cause a reflow short to occur.

And using these settings may cause problems for certain 3-terminal SMD chips.

Grid Units and Size

When creating surface-mount part packages, go to the command-entry bar (which might be in inches):

EAGLE CAD Grid Default

And type:

grid mm; grid alt mm;

And the system will then be thinking in millimeters:

EAGLE CAD Grid Default (mm)

You might want to set the grid to match the grid pattern in the datasheet. Let’s say you’re creating a VQFN12 part, with a 0.5mm pitch:

Land Pattern VQFN12

Then you can see that each pin center is offset by 0.5mm. So you can tell EAGLE CAD to set up a grid and alt grid this way by saying:

grid mm 1; grid alt mm 0.5;

Through-Hole Pads

When creating a through-hole via / pad it doesn’t automatically create a tStop mask that can be easily soldered to. I’ve gotten bit by this. It will create a plated through-hole, but not a copper pad. This is evil.

Where We Seem To Have Arrived (A Non-Technical Post)

Fifteen years ago, I took part in an essay competition run by the Ohio State University’s Glenn School of Public Policy and Management. The essay prompt asked whether and how the Internet would have effect on politics and in what way it might improve democracy in America.

I won second place, based on what I thought to be mildly-biased reasoning from the judges. That is, I said that the Internet might not actually help improve civic engagement, and I’m pretty sure they felt that it would. Which is, of course, what the first-place winner’s essay said. (I read it, he had a lot of charts and graphs cribbed from various places to back his argument, but it wasn’t particularly well-written.)

But this was the early ‘aughts, and the Internet still held some kind of mystical promise. The dotcom crash had happened, of course, but Google was slowly happening and the promise of unfettered, unlimited, unbridled access to information was something most people thought would make the world a better place. ISIS hadn’t happened yet, though September 11 had. Social media wasn’t a thing, domestic surveillance was still mostly analog.

Unfortunately, I think my thesis is still correct: The Internet didn’t enable the kind of democracy we will need to effectively use what resources we have left, before we collapse as a species.

The fact is that the Internet has allowed people to amplify and justify their innate tendencies. It has allowed people of similar dispositions to join forces, for sure. But it hasn’t given people reasons to change their dispositions. And by that, I mean, it certainly hasn’t helped people of conservative tendencies to realize that their beliefs, and especially the exercise of those beliefs onto others, have no place in modern pluralistic societies.

The two things that fix this: the broad distribution of prosperity and the right of women to control their reproductive destiny, are both now under major stress.

The Internet hasn’t led to a broader distribution of prosperity, nor led to public policy that prioritizes this outcome.

There’s a hilarious question I’ve been asked before: Communism or Capitalism, which one is better?

The answer, of course, is neither. At their late stages (earlier so in Communism) they both colossally misallocate resources. If neither system allocates resources appropriately, both will eventually run out of them. There’s no suspension of belief inherent to either system that prevents that outcome.

Efficient supply chain management, abundant and cheap container shipping, end-to-end tracking from production to point of sale, these things help a corporation and a society as a machine to be more efficient. But it’s driving a trickle-up economics, a mechanism for efficiently extracting capital from labor in even the most minimal arbitrage situations. And when advanced machine learning and AI start getting applied, they will learn to make this process even more efficient, with the corresponding ruthless effects on people.

By also discounting negative externalities and by entirely ignoring mispriced nonrenewable and limited resources, these machines eventually will recursively optimize for the worst possible outcomes for humanity itself, while simultaneously optimizing for the best possible outcome for system revenue and cost of goods sold.

It’s not clear how to fix this, besides throwing out a catch-all “more people need to get more educated” cliché. Even then, it’s not clear that education is actually fixing this situation either, given the current generation’s intent to run in fear intellectually from anything that might remotely threaten it.

In order to survive comfortably into the next century, we absolutely need strong democracies and prosperous societies, across the globe. But it is even less clear to me now how we get there from here. We seem to be in a resonating negative feedback loop, more and more rapidly destroying itself and everything around us.

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?)