10 Questions when Reviewing Embedded Code

Design News posted a great article “10 Questions to Consider When Reviewing Code” and I’m just posting the list here. Follow the link for the full article with the details behind each question.

  1. Does the Program build without warnings?
  2. Are there any blocking functions?
  3. Are there any potential infinite loops?
  4. Should this function parameter be a const?
  5. Is the code’s cyclomatic complexity less than 10?
  6. Has extern been limited with a liberal use of static?
  7. Do all if…else if… conditionals end with an else? And all switch statements have a default?
  8. Are assertions and/or input/output checks present?
  9. Are header guards present?
  10. Is floating point mathematics being used?

My personal pet peeve is #3 – I am constantly reviewing that uses WHILE loops waiting for a hardware bit to change state. But what if the hardware bit is broken? Then the device is DEAD. Always have some sort of timeout and use a FOR loop instead of a WHILE loop. At least the code will move on and won’t be dead. Maybe it won’t work properly because of the broken hardware but at least the device can limp along.

How to support Over-The-Air (OTA) firmware update now that Micron has End-Of-Lifed the NVM Z-Wave needs

Sigma Designs Z-Wave chips rely on an external non-volatile memory (NVM) to store the routing tables and other data that needs to survive a power-loss. Unfortunately, Sigma chose an NVM that is single-sourced and what is even more unfortunate is that the source, Micron, has decided to End-Of-Life (EOL) the part in March of 2018. Semiconductor companies like Micron regularly EOL parts as technology moves on so I can’t fault them for that. Micron  gave plenty of warning as the EOL notice went out in 2013 giving you 5 years to prepare for the end. I and many other Z-Wave manufacturers didn’t realize the EOL until a couple of months ago when the NVM became out-of-stock at virtually all distributors! This shut down production lines and we were unable to build product! A potentially company killing event. Fortunately Micron was able to restock and we were able to ship product with only a slight delay. This temporary unavailability raises the critical nature of finding a replacement soon.

What are the Z-Wave NVM options?

Before deciding which NVM to use, you have to decide if you want to support Over-The-Air (OTA) firmware update or not. I highly recommend OTA because Z-Wave continues to evolve and being able to update the firmware in the field is a huge advantage. OTA requires enough NVM storage to hold a complete firmware image of the Z-Wave module which is 128K bytes AND the routing tables which is roughly another 32K bytes. The firmware image can be compressed which allows you to use a 1Mbit (128K byte) NVM but the price for a 2Mbit vs. 1Mbit is tiny and in some cases the larger ones are cheaper than the smaller ones because they are on a newer silicon technology.

Without OTA use commodity EEPROM

If you decide to not have OTA, the NVM options are not affected by the EOL because for slave devices you don’t even need an NVM. Simple slaves can store small amounts of application data in the on-chip FLASH of the Z-Wave chip. This saves the cost, size and power of the external NVM so in some cases this is the best way to go. For very small battery-powered devices like a key-fob, this is the way to go.

Routing slaves or controllers require an external NVM such as the  Atmel AT25256 32Kbit EEPROM. The EEPROM is a commodity device supported by several manufacturers so there is no EOL issue with these devices. Controllers and routing slaves need to store  the routing tables in NVM which are many K bytes of data. The EEPROM devices are well suited to this task because you can write to single bytes of the EEPROM at a time. The serial FLASH chips are not able to write to single bytes which is the major problem. Gateways or other controllers with another micro on-board can update the Z-Wave firmware using either the SPI pins or the UART/USB. The code to burn the firmware into the Z-Wave chip has to be written by you or contact Express Controls and we can sell you a small package to do it.

With OTA use a single source serial FLASH

If you decide to include OTA in your product (and I highly recommend it), then your only solution is to use the Adesto Tech AT45DB0xx family of serial FLASH chips. The Sigma 500 Series Integration Guide (document number INS12213) lists only the Adesto part as the sole supported option at the moment. Sigma is actively looking for alternatives but there don’t appear to be any at the moment. The problem I have with the Adesto part is that it is only available from Adesto, there is no second source. This is a unique part and worse, it has a completely unique pinout as shown below. Using the Adesto part REQUIRES PCB RE-LAYOUT! Existing designs that have already passed FCC regulatory and Z-Wave compliance may not be able to switch to the Adesto part because of the pinout differences. The pinout of each part is shown below. The pins are completely scrambled. The signals are basically the same function but their placement is scrambled.

Z-Wave Experts consulting and IoT product development

The only solution is to put both footprints on the PCB to enable the option of purchasing whichever part is available and cost-effective.

Why doesn’t Sigma support commodity serial FLASH chips? The problem with commodity serial FLASH chips is that they require you to erase an entire sector (4096 bytes) any time you want to write even one byte of data. The Micron and Adesto parts both have Page Write capabilities where a page is only 256 bytes. Every time you write a single byte of data to the NVM the Sigma code will READ 256 bytes, erase the entire 256 bytes (which is a single SPI command), and the write the 256 bytes with the updated byte of data. Any time you write more than one byte to the EEPROM you should be using the MemoryPutBuffer command and not the MemoryPutByte. Supporting commodity FLASH chips would require reading/storing/writing 16 times more data with each write. That would slow many operations down to the point of unusability.

Comparing the NVM Parts

The Adesto part is specifically designed for IoT devices and has a number of really handy features. Specifically it has an Ultra Deep Sleep mode of only 1uA. The Adesto NVM has a wide voltage range which ensures it will work in battery-powered devices even as the battery approaches its end of life. The Sigma Z-Wave 500 series chips are able to operate down to 2.3V and the Adesto part is well below that.

The table below gives a breakdown of the options for NVM with Z-Wave. Using the on-chip FLASH for a few dozen bytes of application storage is of course the lowest cost option but limits the routing capabilities of the node. This option is ideal for Key-fobs or other very space/cost constrained devices that don’t need OTA. The EEPROM is fine for controllers that can be reprogrammed using a second micro. The Micron part is not recommended since it will soon be unavailable. The Adesto part is expensive and is single sourced and has a unique pinout but it is the only solution at the moment.

PinOut NA Std Std Non-Std
OTA No No Yes Yes
Size on-chip 32Kb 2Mb 2Mb
Write 1 byte 1 byte 256 bytes 256 bytes
Vcc 2.3-3.6V 1.8-5.5V 2.7-3.6V 1.65-3.6V
Sleep 0 10uA 10uA 1uA
Cost1 $0.00 $0.32 $0.42 $0.75
Use Case Small battery powered devices like Key Fobs Controllers with second micro for firmware update OBSOLETE! Recommended

If Sigma can figure out how to work with the larger 4Kbyte sector sizes of commodity serial FLASH chips then the cost of a Z-Wave device can drop by over 50 cents resulting in a couple of dollar cheaper retail price. All Z-Wave manufacturers should be pressuring Sigma to come up with a cheaper solution.


  1. NVM costs are 1K pricing from online distributors Q1 2017 and should be used for comparison purposes only – your results will vary