Sunday, November 29, 2015

The Frustrations of a Casual C Coder

mbed to the Rescue!

Last weekend I had all the frustration of trying to develop code for the STM32F746, and was forced to use Keil' s code size limited IDE, and an unwelcome foray into STM's hardware abstraction later HAL.

Previously my benchmark tests had been developed on a mix of the Arduino, STM32-Arduino, CooCox and Keil MDK IDEs. Trying to juggle so many IDEs and HAL as well was becoming counter productive and not at all a rewarding experience. There has to be a better way.

During the week, I started to look again at using the STM32F7 Discovery board for a small project, and was pleased to see that this target platform is now fully supported by mbed.

I had dabbled with mbed last year when building an experimental motor control board and found it a useful means to put together small applications quickly - so I thought I'd give it another go using the STM32F7 Discovery board.

I can now say that I was pleased with the progress with using mbed for this board -   so I have decided that from now on, that I will try to standardise my ARM project developments using the mbed compiler.

The mbed online IDE presents a clean modern look, is easy to use and removes a lot of the complex clutter that a conventional multi-platform IDE presents. The only downside is that the online compiler does not directly support debugging - but a separate project GCC4MBED makes use of the CMSIS-DAP debugging and programming output via a USB port.

It appears that if you want to work across several targets, that there is still not yet one solution that fits all, and it will always be necessary to do some juggling between different toolchains.

The rest of this post is an autobiographical account of my various dealings with microcontrollers - over the last 35 years.

Early Beginnings.

My first introduction to personal computers was over 35 years ago when my secondary school bought an early Z80 machine, the Research Machines RM-380Z, housed in a 19" rack. These machines were bought by the Isle of Man Board of Education, under a nationwide government initiative to introduce computers into schools on the Isle of Man - a full 2 years ahead of the BBC Micro initiative.

So my early experience of personal computers was sitting at a black and white monitor, writing in fairly standard, interactive BASIC, and this is more or less how it remained for the next 5 or 6 years or so - through a progression of machines including ZX81, Spectrum, BBC B, Apple II, Tatung Einstein and several others.

Other experiences included writing a fair amount of assembly language - mostly in Z80, and mostly without the benefit of a machine that actually ran a Z80 assembler!   Assembly by hand, using paper, pencil and a table of mnemonics and opcodes is brutally tough, especially when you then have to then use an Apple II, to create an eprom from the hand assembled code you had just written.  With a code, program erase cycle of some 20 minutes - coding mistakes were frustratingly painful and time consuming.

However - as a naive 18 year old in the technology backwaters of the Isle of Man, I was unaware that tools like hex editors actually existed, and the possibilities of getting a Z80 assembler on a Z80 machine - in a small company that had invested a lot in an Apple II - seemed somewhat remote.

Sometime later, I wrote a Z80 disassembler in ZX Basic, and I also adapted a Z80 monitor program to allow hex dump and hex editing - and that was the extent of my tool chains up until the late 1980s when I believe the Tatung Einstein a CP/M machine I bought half price, end of line, was the first machine to offer these tools as part of the CP/M package.

Forth

Forth is a fascinating language that has captivated me since I was a teenager at school.  I probably first heard a rumour about it around 1982 - and that it had been used to control radio telescopes 10 years earlier. Byte Magazine ran a special edition on Forth in 1980 - which I later found in a technical library.

My first copy was ZX81 ROM-Forth - and it was a copy.  As students in an electronic engineering department we had access to an eeprom programmer, and a good friend, Hadyn and I bought a legitimate ROM between us from an advert in the back of a computer magazine, and then ran off a copy at the soonest practical opportunity. ZX81 ROM Forth was a sophisticated yet quirky product, somewhat ahead of it's time, but sufficient to teach me the basics of the language. It was also much faster than interpreted ZX81 BASIC.  This was probably my first introduction to the notion of swapping ROMs to get a computer to do a completely different task.

In the Summer of '84 Hadyn andd I took a day trip to London (from North Wales) to trawl the electronic music shops (elecrosynth was all the rage) and electronic surplus stores off the Tottenham Court Road. There in "Henry's Radio"  I spotted a Jupiter Ace - again end of line - so I snapped that up cheaply.

Forth was somewhat frustrating on those early UK 8-bit machines. The only means of saving a program was on an audio cassette, which was not entirely successful everytime.

By the late 1980's I had more or less given up programming personal computers, became a user of other peoples applications, and dropped high level coding entirely for about the next decade.  By the time I got back to it the world had moved on significantly....

I wrote some 68000 assembly language for a company that made scientific instruments, but this was all so alien to me compared to Z80, that I was kind of "in at the deep-end" and struggling to keep above water.  From hand-assembling a few lines of code, to working on a multi-module was a big leap - and not one that I managed to achieve successfully.  I left that company shortly afterwards....

PIC Practice

I had known about PICs since about 1995, but had no practical experience of them. I joined a telecoms company in late spring of 1998 and I worked on some telephone dialler products.  During this time I worked out some PIC machine code routines to perform many of the basic telephone signalling tones, including DTMF send and receive, V23 modem send and receive, American payphone "Nickel Tones" and several others.  This was a productive time for me, and with nothing but a PIC and a R-2R resistor ladder network as a primitive audio DAC - I developed code that in the wrong hands could create network chaos.  However wireline telecom development was very much on the way out, so there was another career change on the horizon.

A Baptism of C

I took a management role for a company in the midlands that were doing early asset tracking and wireless telematics - using a combination of GPS receiver coupled to a GSM modem module.  Their code was also running on a PIC, but this time in C.  In my year as a manager there, I watched other developers struggle with C, and me not having the experience to assist.

In 2005 I dabbled with a budget C compiler for PIC.  The language was still so alien to anything I had experienced, I put C firmly on the back burner for another few years.

A colleague urged me to have another look - telling me that "it was not too bad once go get into it". This would happen a few years further on - when I was first introduced to Arduino.

I took a job in central London that were developing a smart energy monitor.  The source code for this was in PIC C for the receiver and 8051 C for the transmitter unit.  I was involved in product testing, and we built a test system and other gadgets, based around the Arduino.

Arduino was the first product that sufficiently de-mystified the C language for me to begin to make some progress with it.

My first exposure and early experiences with Arduino gave me sufficient confidence to stick at C - which conveniently brings us up to 2010.  The last 5 years of this rambling account, will be the subject of a later post.






No comments:

Post a Comment