Martin Cowen (37)

Design of a processor and board independent driver layer

Reusability is an idea often touted in software, and embedded projects are no exception. In fact, the reasons for needing re-usability or ease of porting are often more pertinent to embedded projects even though the initial use-case doesn't call for them, and speed to market is usually business-critical. Why would the processor (or microcontroller) change after it has been designed-in? After all, the hardware designer has to make lots of decisions which are tied to that specific processor in that specific package, so it would be a lot of work for them to change it. Timescales for embedded projects often require the code to be in progress whilst the hardware is being finalised, PCB laid out and prototypes produced. If we can't start the driver layers until the prototypes are available, then it becomes risky to work on the aspects of the application which depend on the lower layers, even with a well abstracted design. During the pandemic, we saw chip shortages affecting many industries because of large orders by the big players, and large order cancellations which messed up everybody's lead-times. STM32s in particular were impossible to obtain unless you were part of the automotive industry. We found that…

Continue reading...

How to harness the power of generated code in STM32CubeIDE with your custom code

Code generation from ioc STM32CubeIDE is a powerful piece of software, including code generation from a GUI formerly known as CubeMX, a code editing environment and a full debugger. The code generation feature should not be dismissed as a beginner level gimmick because it can be used within a professional environment, saving a huge effort compared to doing that work yourself, when you know how to keep it under control. If you're not aware of how to keep the code generator under control, you could lose code, be unable to get your code where you need it in the files, and feel restricted by it's imposed code structure. The CubeMX part of STM32CubeIDE can be used as a standalone application or integrated into the IDE and uses the [project name].ioc file to store the configuration of the peripherals, drivers and middleware in a text file which can then be displayed in an interactive GUI. One ioc file is used for the project, even for multicore processors, which are configured using two columns of checkboxes. When working with the files generated by CubeMX, it is easy to be so overwhelmed by all the boilerplate lines that you just ignore them and…

Continue reading...

Why I won't do defence work

Quite a large proportion of embedded firmware jobs are in the defence industry. I won't be a part of that and here's why. There's a practical problem and a moral problem. The practical problem is not knowing who the products will be used by, when, and for what purpose. As usual, the BBC comedy show Yes Minister has more truths in it than official statements and procedures. Jim Hacker - "So there's no real control over who the arms go to in the end?" Sir Humphrey Appleby - "Oh indeed there is - the dealer has to provide and end-user certificate which is a signature acceptable to Her Majesty's government that the ultimate customer is in fact an approved user." Jim Hacker - "Is that that a real guarantee? I mean would you be surprised for instance if a British aircraft carrier turned up in the Central African Republic?" Sir Humphrey Appleby - "Well I for one Minister would be very surprised - it's a thousand miles inland" Jim Hacker - "Yes, you know what I mean. What about smaller weapons?" Sir Humphrey Appleby - "Well it's virtually impossible, there's stringent security, rigorous inspection procedures, meticulous scrutiny..." Jim Hacker -…

Continue reading...

Repairing a Panasonic DMR-EX77 PVR

After nearly 10 years of continuous operation, my Panasonic DMR-EX77 PVR died. The display went out and it didn't respond to the remote control. Sometimes this type of failure is just a fuse which has been stressed too many times by the inrush current produced when charging large capacitors in the power supply, but not this time. It was immediately obvious that the electrolytic capacitors had failed. I could see their bulging tops which are designed to blow out in the event of failure. All electrolytic capacitors have an expected lifetime which is mainly due to the wet electrolyte drying out at which point the capacitance drops and the equivalent series resistance goes up. It seems to be a common problem with these PVRs. On this product, the capacitors which needed replacing were identified as C1401, C1402, C4056 & C1557. The service manual explains the disassembly procedure and has the schematic and bill of materials which makes finding replacements easy. I ordered spares from RS Components and disassembled the PVR carefully. Since many different types of screws are used, it is a good idea to stick them down to a sheet of paper with a note of which screw was…

Continue reading...

An Unusual and Fast Bit Reverse Routine

A function to reverse the order of bits in a byte makes for a good interview question. The candidate has to think about loops, shifting and masking as well as the mundane but important issues of function and variable naming, data types, spacing and comments. As opposed to those "gotcha" questions apparently beloved by the tech giants where you have to know some trick, this can be worked through methodically. Once there is a solution on the table, there is an opportunity to talk about optimization for speed and/or space. There are lots of ways to approach this problem, but I suspect that many will take this simple idea of testing each bit and setting the LSB of the output in a loop which shifts up the output and mask one place each time. //bit reverse eg 0x80 return x01 //simple but straightforward approach uint8_t bitreverse_simple(uint8_t input) { uint8_t i, output, mask; output = 0; mask = 0x01; for (i = 8;i > 0;i--) { output <<= 1; if (input & mask) { output |= 1; } mask <<= 1; } return output; }; Testing The Simple Approach First we need to test that this produces correct results by running…

Continue reading...