Saturday, November 12, 2016

myStorm - Achieving the $30 Price Breakthrough!

This post was originally written in late July - during the design phase of myStorm. Unfortunately this and other posts were accidently deleted, but have now been partially recovered.

From now this blog will continue on my Wordpress site


In this part I look a little closer at the target hardware and look at the way in which we are now able to achieve a $30 selling price.


ARM Section

The ARM microcontroller performs several basic functions at different times in the development cycle.

1.  As a non-volatile Flash memory device for holding the FPGA bitfile
2.  As a FPGA programmer communicating the bitfile to the FPGA via an SPI interface.
3. As a general purpose I/O slave processor - by way of serial or fast 8-bit parallel interface 
4. As a system controller for applications where the Raspberry Pi Zero is not present on board.

The microcontroller needs a flash memory of at least 256K bytes. 

I have had experience of the STM32 range of microcontrollers - so these were the obvious choice - but with a tight budget, not stretching to a $4 mcu, we were obliged to follow an alternative strategy.

Some months ago, through my association with the STM32Duino group, I got to hear about some low cost ARM M3 parts from a vendor in China, apparently binary and pin compatible with the STM32 parts . At first, these appeared to be rip-offs of the STM32F103 series, produced by Chinese vendor Giga Devices.  However, further investigation revealed that they were actually a new design, which employed a neat idea to produce a low cost, volume range of ARM Cortex M3 microcontrollers for the Chinese market. And because Giga Device is a Flash Memory manufacturer, their M3 Cortex parts have up to 3Mbytes of flash "on-chip".

Of primary interest, however, was their low cost - a 256Kbyte ARM M3 Cortex by Giga Device sells for about $1.00, saving us $3 on not having to buy a device from STM.

The Raspbery Pi Zero.

When the Raspberry Pi Zero was released in November 2015, it was heralded with a blaze of publicity as a $5 fully functioning Linux computer. Just add keyboard and display with the O/S stored on a microSD card.

With its small size of just 64 x 35 x 5mm, and unbeatable value, it appears to be the ideal solution for a low cost development system.  


20 5V tolerant GPIO lines and 6 12-bit ADC channels (3V3 input) are brought to "Arduino" stye pin headers - so that external shields may be fitted.

Wide assortment of GPIO brought to Arduino shield connectors
6 Analogue Input Lines AN0 - AN5
UART (with bootloader facility) TX, RX
Up to 18 digital lines - including I2C and SPI
Up to 3 differential input 16 bit ADC channels (If STM32F373 fitted)
USB 2.0 connection for programming, data and power
8 bit bidirectional bus interface to FPGA and Pi - Zero with handshaking lines
SPI bus for programming FPGA from bit file

FPGA Section

3 single PMOD connectors
5 double PMOD connectors
8 bit bidirectional bus to Pi-Zero and ARM
LVDS to "Olimex" style 2 x 16 connector
2 x 8 header for direct connection to 32 x 32 RGB matrix display.
100MHz clock oscillator
64K x 16 fast SRAM - can be upgraded to 512K x 16.

Pi Section

Standard 2 x 40 GPIO header for Raspberry Pi GPIO
EEPROM for PIHAT identity

Other

Efficient dual voltage switching regulator
4 USER switches
5 USER LEDs
RESET switch
BOOT switch
All I/O on 0.1" grid - wherever possible

Applications.

1. As a stand alone versatile application controller

2. As an advanced Analogue and Digital  I/O board for the Raspberry  Pi and Pi Zero

3. As a teaching platform for learning 32 bit ARM and FPGA programming.

4.  As a platform for developing Open Core cpus on the FPGA

5. For high speed digital instrumentation - such as DSO or logic analyser

Cost Reduction

Keeping the cost down was a primary concern, yet we wanted to make a board that was genuinely useful.


To achieve this, Alan came up with a unique strategy:

1.  Low cost FPGA with open source tool chain
2.  Low cost ARM - to act as "system integrator" and glue.
3.  On board Pi Zero - to host the open source FPGA tools - user supplies this at $5.00

Having settled on the ICE40HX4K - as the largest ICE40 available in an LQFP package - and thus more easily routed on a 2 layer board than a BGA part, we set about identifying the other key components.

Having seen James Bowman's J1a Forth Processor - a soft core running in an ICE40HX1K part, I wanted to add a fast (10nS) 16 bit wide SRAM - which in a TSSOP-44 package allows parts between 64K and 512K words. With this combination comes the ability to create a number of soft core processors, of which the 16 bit simple processor described in the "Nand to Tetris" course would seem a very suitable candidate.

Other applications include digital instrumentation that require large arrays of fast memory - such as digital oscilloscopes and logic analysers.

The lynchpin in this design is the use of a low cost ARM device, not only to provide USB communications,  storage (in flash) of the FPGA bitfile, plus provide a series of ADCs and  5V tolerant GPIO pins and peripherals to augment the FPGA architecture.


Costing

We believe that if an FPGA board sells for around $30 then it will attract a fair bit of attention.

This was going to be tricky - so we set ourselves a BOM on a very tight budget of arount $10 based around the principal components - costed in 100 and 1000 off quantities:

            100 off            1000 off

FPGA        $5.56               $5.37

ARM         $1.20               $1.00
SRAM        $1.69               $1.22
PCB         $0.88               $0.49
Connectors  $0.50               $0.40
Remainder   $0.50               $0.40
    

Sub Total   $10.33              $8.88


LOP         $2.58               $2.22


Total       $12.91              $11.10


Pi Zero     $5.00               $5.00



So in 1000 of quantity, the BOM and manufacturing (LOP = Labour, Operations Profit) comes to a total of around $11, which allows a selling price of about $30.

The customer provides their own Raspberry Pi or Pi Zero, from as little as $5.00.

A Storm in the Making

This post was originally written in late July - during the design phase of myStorm. Unfortunately this and other posts were accidently deleted, but have now been partially recovered.

From now this blog will continue on my Wordpress site

Before rushing into mass production of any new product it is sensible to carry out a pilot production run - to make sure that everything works - before you commit to the expense of full production.

My career for the last 20 years has taken me through several such pilot production runs, for various companies and individuals around the world.  In many cases I was the hardware engineer on the project - and it was therefor expected that I would oversee the pilot and main roduction runs. As a consequence, I have been travelling to Shenzhen, China, many times since 1999.

Over the years, I have worked with many great people over there, who have gone out of their way to ensure that production runs smoothly, and to ease the stress of meeting tight deadlines in a very foreign country. As a result, I have made many good friends, who are willing to get involved or help out, however they can, in any new project.

The tight timescales of the myStorm Project meant that we would have to combine the Pilot Production with an immediate small run of production units, and this naturally put extra demands on time and resources. However, I am pleased to report that everything went as smoothly as expected, and we now have a batch of 50 myStorm boards heading back to the UK.

In this blogpost, I'll try to give a flavour of some of the challenges we have faced over the run up to and then Pilot production run.

Sourcing the Components.

I needed to source at least 50 sets of components for the Pilot Production, and this was further complicated in that some of these were sourced in the UK and needed to be shipped across to Shenzhen in time for production. I then found out from a contact at RS Exports Department, that Chinese Customs were cracking down on small shipments - and as such I would be heavily penalised for import duty, or components would be delayed or confiscated in Customs. This was not what I wanted to hear, as any uncontrolled delay might jeopardise our chances of getting the goods back into the UK by Friday 2nd September.

My task was to source the sets of ICs that would be used on myStorm. This included the ICE40 4K FPGA and the ARM Cortex microcontroller and a couple of smaller parts.

The ICE40 was in short supply in the UK, so I had to purchase from Mouser in the USA and have 33 parts shipped across. These arrived on Thursday 11th August, and were repackaged and ready to ship on Monday 15th, along with the other ICs.

I found the Chinese Customs site very confusing - so I decided to sent the ICs to my friend Eva, in Hong Kong, so that she could fill out the necessary customs declaration in Mandarin, and choose a local courier company who could deliver the ICs across to Toby in Shenzhen.

The distance between Hong Kong and Shenzhen is barely 20 miles,  but with the complication of  "1 Nation 2 systems"  this courier process took about 5 days to complete. Toby received all of the ICs on Monday 22nd August.

Meanwhile, Toby had been visiting the Shenzhen Electronics Market and purchasing all of the smaller items on the BOM - such as the passives, connectors, switches, LEDs etc.  These items are seriously cheap in China - as most of them are locally produced, whereas ICs generally still come from Western Suppliers, and tend to have little price advantage when bought in China.

The Road to Production.

Not quite a Tom Hanks movie, but with enough twists in the plot to challenge the small team we have working in China.

With the components sourced, it was time to deliver them to the pcb assembly factory- so that they could be placed on the solder pasted pcbs and run through the reflow oven.

On Thursday, Toby messaged me to say that the "plate"  - the foil stencil used to apply solder paste to the pads, had a problem and would have to be remade.  This would cost $45 and take 24 hours. Not a huge monetary expense, but a delay in production to Friday/Saturday, leaving us just 5 days to ship the goods out of Shenzhen and back to the UK in time for the FPGA course at OSHCamp 2016.

The solder stencil arrived at the factory late on Friday, and a couple of trial pcbs were made to ensure all was well - and that the voltage regulator circuit was producing a stable 1.2V for VCC and 3.3V as the main digital supply rail.  I had insisted that we do these tests before placing the expensive main ICs - that represent about $15 per board.

The voltage regulator tests went well, and so I was happy to comitt to the 4 panels of 12 boards to be fully populated with all components and run through the assembly and reflow process. Toby worked until 9pm Friday  - to ensure everything was good to go - for an early morning start on Saturday to get the batch of boards completed.

In order that I could be online to assist - it meant me getting up very early Saturday morning - about 4am, which is 11am in Shenzhen.  Toby informed me that the factory were complaining that the pads used for the 0402 components were oversize and that some of the very light 0402 components were "Tomb-stoning".  This is the process where the solder paste on 2 pad components does not melt evenly, and the surface tension effects of the first pad to melt causes the component to erect vertically - just like a tombstone.

This was not good news - and I assured Toby that I had used the standard footprints for 0402 as supplied by EagleCAD.  However - this was probably where I went wrong, and should have read some of the online guides about pad sizes and preventing tombstoning.

Fortunately the problem was not excessive, and any components that did tombstone were easily corrected manually with a soldering iron.  By 6pm Shenzhen time, the pcbs were finished and ready for collection.

Toby and I could then relax - after what had been a long and stressful week.

Summary of additional costs:

Shipping ICs to Hong Kong  from UK     $85
Shipping ICs to Shenzhen plus Chinese import duty (17%)     $165
New solder stencil     $45
Shipping goods by DHL Express to UK

Lessons for the Future

Shipping ICs around the world often attracts additional costs of import duty - worsened if you then need to pay again when they arrive back in the UK.  However because many of the ICs were sourced in the UK and US - we had no real option.  Part of the way through this traumatic 2 weeks, I found out that Mouser have a Chinese Division and that almost all of the Western sourced ICs could be bought from Mouser in Shenzhen - and not attract additional charges. This will be the preferred way - moving forwards into volume production.

Because of delays in the Pilot Production, it left us little time to ship the boards back to the UK - and so a more expensive Express service had to be employed.  With a little more time and a little less rushing around - this would have saved a bit of money.

Brewing Up a Storm

This post was originally written in early July - during the design phase of myStorm. Unfortunately this and other posts were accidently deleted, but have now been partially recovered.

From now this blog will continue on my Wordpress site

This week we saw the arrival of the first batch of myStorm pcbs from Toby in Shenzhen.  The gerbers were sent on Thursday 21st July and pcbs  - plus solder stencil arrived the following Thursday lunchtime - quick work.

Meanwhile Alan and I had been out shopping for the BOM parts - with enough components to build up a small prototype batch of about 5 boards.

We got together on Friday evening at the Surrey and Hants Hackspace, and managed to spend a couple of hours painstakingly placing the 80 or so 0402 parts onto the freshly screen-stenciled - solder pasted sample pcb.

In fading light we retired with more than half the SMT components placed, with a view to completing the task in the fresh morning light - when both our eyes and hand co-ordination would benefit from a good night's sleep.

The placement continued for another 2 hours in the morning and by 11:30 we had a fully placed board. After some basic checks for IC alignment - we turned on Alan's home made hotplate - an aluminium block, with a cartridge heater and a cheap temperature controller. Setting the temperature to about 220C - within 5 minutes the board was starting t show positive signs of solder paste reflow.

The pasting operation had been not 100% successful,  - the definition of the solder pads around the pins was far from perfect - but with the application of heat - and the miracles of surface tensio - the solder flowed beautifully - leaving perfectly soldered pins and 0402 components.

A quick bit of remedial work to fix any "tombstoned" components, I was onto the last leg of this demanding race - and soldering the PMOD and Arduino connectors into the remaining throough-hole locations on the board.

Initial Tests

Check, check and check again - then correct the things you missed.

First we checked for supply to ground shorts - and the 3V3 was connected to 0V  - because a single 0402 100nF decoupling capacitor had moved sideways across its pads and was shorting across them. Easily fixed - but not so easy to spot  in the first place. A few solder bridges between pins on the 64 pin LQFP ARM package - again easily fixed with the soldering iron and a dab of water-solvent based SMT  flux.

Then it was time to apply the 5V power and test the power rails. All appeared well with 1.2V for the Vcore and 3V3 as the digital supply to the ARM and the FPGA.

On first power-up some of the LEDs glowed dimly - and the power light glowed yellow.

Next we had to find a way of getting some life into the ARM chip - an STM32F103RC - the same as used on the Nucleo dev board. I opted to get "Blinky" running - using mBed to program the board.

Downloaded the ST Link Utility - which included the latest drivers and the programming application.  Once this was down loaded it was relatively easy to use the blink example, change the port Pin to PA_15 and flash the LED!

A first success!


Tomorrow - there are 2 more prototype pcbs to populate and bake.  Once you have done the first one - fixed the snags - the rest is easy.

The Missing Posts

In July, I accidently deleted about 6 months of posts. These fortunately have now been partially recovered and moved across to my wordpress site.

I hope you join me on the other site.

Friday, November 11, 2016

Chipstick - a diminutive MSP430 FRAM Forth Computer

Recovered from an accidental delete!

    Last week, I wrote about the $5 Forth Computer, and showed an early breadboard version using an MSP430FR2433 mounted on a prototyping adaptor and plugged into a breadboard.

    Well, I am pleased to report that the batch of 20 prototype pcbs have arrived back from the manufacturer earlier today and the build of the first unit is underway.

    The following pictures show the build sequence - starting from the bare pcb

    Top side of unpopulated ChipStick board - millimetre scale!
    Underside of ChipStick pcb with locations for SRAM and USB converter IC



    ChipStick with USB connector, regulator and MCU added


    The ChipStick design has the following features:

    1. MSP430FR2433 with 15.5K FRAM and 4K SRAM
    2. External SRAM or FRAM device connected via SPI on USCI B0
    3. CH340G USB to serial converter IC on detachable section of board
    4. 3V3 voltage regulator
    5. Reset Switch and User LED
    6. 20 Pin DIL footprint to allow insertion into G2 Launchpad socket.
    7. Programmable by SBW or BSL

    ChipStick - code loaded and Flashing LED (before sunrise)




    Next Time:

    Fast Forth - by Jean-Michel Thoorens

    This is an implementation of a Direct Threaded Code Forth, written in MSP430 assembly language.  It communicates with a terminal program TeraTerm, at 921600 baud.

    I have it running on an MSP430FR5739 - can I port it to the '2433 on te ChipStick?
    00

  • 03/27/16--02:11: ChipStick - Applications
  • Introduction

    ChipStick is a tiny 16 bit microcomputer attached to a PC via a USB cable. It comes with up to 256K bytes of non-volatile memory - uniquely using ferro-electric memory.

    It has up to 16 accessible GPIO lines - which include a mix of SPI, I2C, UART, Timer and ADC channels.

    ChipStick may be plugged into a breadboard or stripboard and act as an intelligent programmable controller interfacing with other circuitry.

    ChipStick can also act as a Digital Debug Tool (DDT), with jumper wire attached, - used to debug/develop low voltage (3V3) target hardware.

    In each case, the extendable Scripting Language SIMPLEX may be tailored to the exact requirements of the user' application.

    ChipStick is based on non-volatile ferroelectric technology.  This means that your applications and any recorded data remain in memory even after power down.

    ChipStick may be extended in hardware to meet the requirements of the application - this is planned through both a series of larger expansion boards (based on low cost 50x50mm format) and stackable micro-modules that match the DIL 20 socket format.

    Applications

    With these primary applications in mind, ChipStick has been designed to be as versatile as possible - within the constraints of the small footprint.

    As a debug tool, it is no bigger than a USB Stick - easily carrier around with essential hacking tools.

    I have designed it as a socketable component that can easily be added to a board - where a small amount of intelligence is required, or for bridging between sensor devices. It can also collect or send data to SPI devices and bridge that back to the PC via the UART channel.

    Equally, it could be used as a small test equipment device to exercise, monitor or control prototype hardware - it has 16 GPIO lines - including two full SPI ports. These can be attached to the target hardware, and using the SIMPLEX scripting language, the various target hardware can be exercised and data reported back to the PC.

    With the right SIMPLEX script, it can be used to transfer a hex, bin or ascii file from the PC to the target under development.

    The external memory may be used for sensing and datalogging applications, capturing waveforms, playing back arbitrary waveforms - as a signal generator.  The ADC channels may be used as a low bandwidth oscilloscope, test meter or for monitoring changing physical quantities in science experiments.

    ChipStick takes much advantage from the trend in modern sensors and peripherals to connect via the SPI or I2C bus. The MSP430FR2433 device provides up to 3 separate SPI buses.

    ChipStick can be interfaced to Wirelss and WiFi modules such as the RFM69 and the low cost ESP-01.

    Suitable sensors include accelerometers, gyroscopes, digital compass, temperature, pressure, loadcells etc.

    For basic GPIO operations - common shift registers may be used with the SPI bus such as the 74HC595 for 8-bits output - for driving LED arrays, the high power TPIC6B595 for driving stepper motors, and the 74HC165 for 8-bit inputs.

    Using a LED driver IC - such as the MAX7219 or AS1100 series - up to 8 digits or an 8x8 array of LEDs may be driven from the SPI port.

    OLED and LCD graphics displays may also be driven from SPI  with a couple of control signals.


    Educational Applications

    ChipStick as been designed with education and experimentation in mind.

    It can be used specifically to assist in the teaching of electronics, computer science and interactive coding.

    It is versatile enough to meet the needs of high-school and university undergraduates, plus simple enough meet the requirements of the maker and hacker community.

    The small size of ChipStick allows it to be used to give intelligence and connectivity in situations where other technology is just too bulky to fit - with the programmer section detached it is only 26.5 x 11mm - small enough to fit inside a 4x2 Lego block!

    It's low cost means that it can deployed in areas where other solutions might prove too expensive.

    Here are a few of the educational applications:

    Teaching Forth.


    Forth is an interactive language and can be best taught with hardware that creates a stimulating interactive environment.  This includes the use of LEDs, sound, touch and movement (such as stepper motors and servos).

    The MSP430 is a good fit for a "traditional" Forth machine - with 16 bit Von Neuman architecture.

    MSP430FR2433 with 16K FRAM and 4K RAM is reminiscent of the early minicomputers that Charles Moore would have first coded Forth onto in the late 1960s.

    I have added the external SPI memory - specifically so that users can experiment and learn about interpreted languages running on virtual machines. OK - single byte access to external RAM takes approx 30uS - but block access is 3uS per byte. ChipStick will come with a 128Kx8 external SRAM 23LC1024, or FRAM to special order.

    The SPI buses on the MSP430FR2433 allow expansion hardware like sensors and shift registers, LED & graphic display drivers etc to easily be added - with minimum of wiring.



    Teaching Coding

    ChipStick is not limited to Forth  - it is easily programmed in C with CCS or Energia, BASIC or in native MSP430 assembly language.

    Teaching Digital Electronics

    ChipStick can animate electronics in a low cost way not previously possible.  With a breadboard and a few LEDs and switches, ChipStick can form the central controller of many digital projects.

    It's ability to easily interface to displays, sensors and actuators allows it to make projects exciting.

    ChipStick can also be used to exercise digital electronics, and report results back to a PC for display on a graphical user interface. In teaching environments where real hardware may not be possible or practical - ChipStick can use virtual hardware and achieve most of the same educational aims.

    Making & Hacking

    As a result of it's low cost, ChipStick can be used in projects where other solutions may seem over expensive. Projects no longer need to be stripped down, to salvage the $20 Arduino for another purpose.  ChipSticks will be supplied in multi-packs at very low prices - so that the cost of the device is no longer seen to be a barrier to creativity.

    ChipStick is compatibe with Energia - an "Arduino Like" IDE. This allows an easy transition to the new device from familiar territory.

Building Chipstick

Recovered from an accidentally deleted blog!

Nobody is expecting you to build a ChipStick from scratch - unless you are very keen.

The ability to work with tiny SMT parts is not one everyone possesses, but it can quite easily be learned, and with practice, good results are possible with the simplest of tools and equipment.

This post follows the construction process step by step - for the curious - or for those brave or foolish to wish to follow in my footsteps.

Equipment

SMT Hot Air Rework station with choice of nozzles - I used 8mm
Soldering iron with "needle" tip
Soldering sponge
Flux pen or water soluble SMT flux
Tweezers (stainless steel - non-magnetic)
0.38mm 60/40 solder (Don't struggle with lead-free - it's dreadful).
x10 magnifying eyepiece
good overall lighting - use spot light or bright daylight
scalpel or craft knife
3rd Hand
Bluetack - stick the pcb to the bench to stop it moving
De-Solder braid - accidents can happen
Patience - set a day aside for this, without interruptions
Use a Flux Pen to flux the footprint of the main IC
Flux is essential for good solder wetting.  Use it liberally on the multipin footprints - such as mcu and other ICs.  I use a rosin flux pen for convenience, but there are now some water soluble fluxes that wash off the board with water and an old toothbrush.

Use a soldering iron and add some solder to the IC pads
but not the centre one!
MCU footprint with solder applied
These boards have been "hot air solder levelled" or HASL.  They are easy to solder, but for IC pins you need to build up a little more solder thickness on the pads - and don't forget to flux well.

Flux the underside of the IC package
and also reflux the pads on the board 
I first position the mcu centrally on the footprint pads with tweezers.  The flux heps to hold it in place.  Check from the sides that al the pins line up, and check again that Pin 1 is in the correct position!!

Set the temperature of the hot air tool to between 370C and 400C.

When happy with positioning -  use the hot air tool about 20mm above the IC and swirl the air around the IC in slow circular motions - about once every second.  I count to 20, and usually the solder has melted and the IC is sitting squarely on the board - and not moved to either side.   Don't spend more than 30 seconds with heat on any one component.  Leave to cool - it will be hot!

The mcu successfully soldered in position using hot air reflow tool
Now go around the pins with soldering iron checking every joint is good
Next I use the needle point tipped iron and rework every pin.  I check that the solder reflows and that the soldered joints are bright silver an "fresh". There should be a neat solder fillet between the board and every contact of the QFN package.


Repeat 13 more times!
At this stage - I put the boards into a programming jig and made sure that they accepted the programmed code. If not I inspected carefully and reworked where necessary.

Voltage regulator and decoupling capacitors added - USB next 
I then proceeded to put the remainder of the smaller components onto the top of the board - leaving the bulkier mini USB socket until I had completed all the work on the underside of the pcb first!




























Underside of board with USB converter on left and 128K SRAM on right
Topside completed - undergoing testing


Four completed units - with penny for scale


Choice of pins - left are for breadboard, right are to fit DIL 20  IC socket

Bootloading Chipstick - the tiny MSP430 FRAM board

A Post from March to July 2016 - recovered after an accidental deleting session!

New and recovered posts can be found at my Wordpress site

Just over a month ago I talked about the MSP430 bootloader - commonly known as BSL - or bootstrap-loader.

Almost every MSP430 has the facility to load code via this ROM based bootloader - and when first introduced about 15 years ago, it was ahead of its time. The clever engineers at Texas Instruments wanted a simple "Backdoor" method of getting code into the device, using nothing more than a 9 pin serial com port, some trivial level shifting electronics and a modest program running on a PC.

Whilst the 9 pin serial port may have long since disappeared, the BSL is still present in almost every chip - and not just for a UART connection, but for I2C and SPI interfaces too.

With the advent of ferroelectric, non-volatile FRAM memory in the recent range of MSP430 mcus there is all the more reason to want to leverage on the strengths  of the BSL and develop neat new means to get code into these often understated devices.  With a wireless or Bluetooth connection - firmware over the air (FOTA) becomes practical, and also "self-replicating" gadgets - where one MSP430 equipped gadget can "clone itself" into another unprogramed device - ideal for kids sharing hardware around the playground.

What I have Learned this Month

I have now been using this bootloader on and off for a month,  and wanted to share with you what I have learned - in the hope that things are easier for those that may wish to follow in my footsteps.

All the information is out there - it's just not all in one place, and a lot of time has been spent finding snippets here and there, and trying to make sense of it all.  Like Captain Kirk said... "Our continuing, 5 year mission......"

To start off, you might wish to look at the following TI  documentation

Main Bootloader Specification

MSP430FR4xx / MSP430FR2xx Users Manual

MSP430FR4xx and MSP430FR2xx Bootloader (BSL)


Hardware Initialisation

The basic idea is that the PC uses the DTR line and the RTS line of the USB to Serial converter to create a pulse sequence which when recognised by internal state machine hardware, causes the MCU to enter Boot Mode.

The hardware sequence needed to invoke the Bootloader mode
                          

The key points are that there are 2 pulses on the RST/TEST line, the first is 10mS longs and the second is 20mS long.  The RESET line  (DTR) rises whilst the 2nd RST pulse is still high, and approximately at half way through its duration.

This sequence has been chosen because it uses both edges and levels to encode the BSL envoke command, and the hardware that responds to this sequence is unlikely to be falsely triggered by any spurious noise or other accidental stimulii.

In theory, any bit of hardware that can generate this pattern can be used to invoke BSL mode, all it does is cause the mcu to jump into the bootloader code and the /RESET and TEST lines have no further function within the body of the programming process that follows immediately after this pulse sequence.

After the BSL start sequence has been sent,  the Tx and Rx lines become active as data and acknowledgements are sent between the PC and the MSP430.  This can be at 9600 baud, with even parity, but some faster BSL programs begin at 9600 baud and request a step up to a faster baudrate for the duration of the programming. 

At the end of the programming sequence, the PC returns the TEST line high - as shown on the right of the sketch above.

Ideally the reset line should go low and then high to issue a rest pulse - but this is dependent on the PC application and is not always the case.

This may seem simple so far - but then there is the old saying "If it can go wrong, it will go wrong".

The problem arises in that over the 6 generations of MSP430  - there have been several different start sequences, for the families of 1xx, 2xx, 4xx  5xx,  6xx and FRxx devices.

As the hardwware to drive the bootloader evolved from a simple 9 pin RS232 Comm port - where some of the handshaking lines are inverted, the original specification was aimed at what was easiest to implement from a standard serial port.

In addition, some MSP430 devices share their /RESET and TEST pins with JTAG functions - so to differentiate between JTAG commands and BSL commands sometimes one or both of RST and DTR shown above are inverted.

Here are a few pointers to get you up and running quickly

1. Make sure that /RESET connects to DTR and TEST connects to RTS - easily mixed up.
2. As a temporary hack, be prepared to add a P-FET to invert DTR line so that /RESET is active low. See picture below
3. Some PC applications allow you to swap or individually invert the RTS and DTR lines - but only available for 1xx, 2xx, 4xx.

A P-FET and 10K resistor were added to invert the DTR signal for /RESET





PC Software 

I have found at least 3 variations of  PC BSL Scripting applications.  Here are the links:

Open Source from FlyingCamp Design

FlyingCamp BSL Library

FlyingCamp BSL - Utility   (1xx, 2xx, 4xx only)



There may be more available,  but I struggled to find anything that gave me exactly what I needed.

In the end, despite the msp430-bsl-utility being almost exactly what I needed with the means to swap and individually invert RTS and DTR.   However this utility was not compatible with 5xx and 6xx Bootloaders.

To make the bootloader work, I had to use the 5XX mode and invert the DTR (RESET) signal using a P- FETtransistor  - in order to match the signal diagram above.

Once you can generate the correct boot sequence - the rest is fairly easy.

The script for the BSL is very short   - use a filename such as  script1.txt

MODE 5xx COM9                                                    // Set 5XX mode with USB VCP on COM9
RX_PASSWORD                                                     // Use Default Password  (optional)
MASS_ERASE                                                         // Erase the device
RX_DATA_BLOCK_FAST blink_2433.txt                // Send the TI TXT file  blink_2433.txt
SET_PC 0xC400                                                      //  Set the Program Counter to 0XC400 - ready to run

The comments are for explanatory purposes only - although if you include them in the script, comments should be on separate lines to any script instruction

To use this, put the bsl_scripter.exe,  the script1.txt and the blink_2433.txt file all in the same directory.

Run by typing 

bsl_scripter.exe script1.txt

Typical output session from BSL_scripter



If all goes well, this takes a couple of seconds to run - after DTR has been allowed to go high again at the end of the programming.

Further work required - should be possible to invert DTR in software -   so that it doesn't need the hardware hack with the transistor.  The BSL utility GUI is the way to go, if someone with Python skills would just hack it to handle 5xx bootloader format

The programmer should be modified so that it releases DTR at the end of the programming sequence - so that the code autoruns after loading.


A neat way of programming a MSP430 with very simple USB-serial converter - just need 10% more effort in the PC software to allow it to handle the newer parts - without having to resort to command line and P-FETS!




Thursday, July 21, 2016

A Perfect Storm


After 11 years of Blogger, I am increasingly frustrated with it's lack of sensible features - like the all important code window.

As such I am looking for alternatives - but for the meantime some recent posts will now be available here:

https://folknologylabs.wordpress.com/2016/07/21/a-perfect-storm/

So long and thanks for all the fish.......

Tuesday, March 15, 2016

The $5 FORTH Computer

The MSP430 makes an excellent choice for a Forth Computer.  It already has a 16 bit architecture, and the Von Neuman  unified memory space makes dealing with data and instructions somewhat simpler. It's choice of low power, non volatile FRAM memory makes it virtually unique in the microcontroller market.

FRAM has a fast write cycle - about 100 times the speed of Flash, and with a life of 10E +14 cycles - it will not wear out anytime soon.   EEprom is made redundant with FRAM, and the boundary between FRAM and SRAM can be moved - so that FRAM is used as RAM - allowing up to 8MHz operation.

The MSP430FR2433 is a new addition to the FRAM range of microcontrollers and at  $1.50 it is very affordable. Add to this an external SRAM or FRAM memory and you have the makings of a powerful little machine.  With volume production, it's possible to have a complete Forth system for around $5 - including the USB programming adaptor.

Performance wise, it's not in the ARM class, not even close, but at 16MHz full speed, it will run about 4 times the throughput of the Arduino R3.

One of it's strengths is that it has been blessed with 3 communications ports - allowing a rich mix of asynchronous UART and synchronous SPI hardware to be added.

The MSP430 may be programmed with a variety of Forths, including Mecrisp, Amforth and 4E4th - the latter having a special port of Camel Forth available specifically for FRAM operation.

Recently I came across Fast Forth by Jean-Michel Thoorens - this is Direct Threaded Code, and has support for SD card.  Programming is done making use of TeraTerm for file sending - at a full 921600 Baud.   It was designed specifically for MSP430 with FRAM - needing just  8K bytes of FRAM.

Forth was designed as a complete, self contained  tool-chain - including Editor, Compiler and Assembler - all the tools that you need to develop code,  at your fingertips - present on the target chip.   Now for the first time we can have all of this on a tiny, manageable 20 pin DIL module - complete with it's own USB programming interface.

The communications interfaces include UART, SPI and I2C.  There are up to 6 port pins available for use as GPIO,  peripheral selects or ADC inputs.

Need to add more I/O? No problem - can be done using simple shift registers clocked off one of the two available SPI ports.

Want to build a WiFi or Bluetooth robot - again no problem. Just drive the stepper motors using a shift register or high power driver  - such as the TPIC6B595 

The SPI port may be used to read a PS/2 keyboard, or I2C will interface nicely to a Wii Nunchuck controller.

ChipStick will accept an external static RAM (23K256 or 23LC1024) up to 128Kx8, or a SPI FRAM of up to 256Kx8.  In streaming mode the speed is about 3uS per byte (for long streams) allowing 32K to be transferred in 100mS.

It should even be possible to experiment with monochrome video output by clocking data out of the SRAM using SPI.



Erm  - Wrong Chipsticks!

ChipStick will be a fully functioning FRAM MSP430 Forth System!

It's nice to have a hobby in which something useful can be designed over a weekend. That's the case with ChipStick - conceived on Friday evening after work - and off to meet it's maker (my pcb board house) at the end of Sunday evening.

ChipStick is the solution to the modern problem that not enough microcontrollers are breadboard friendly - so I just sat down and designed what I needed - a neat 20 pin DIL module - based on the MSP430FR2433.

ChipStick is probably the smallest computer I have worked on, but despite it's small size I have managed to pack a lot in. The MSP430FR2433 has 15.5Kbytes of FRAM and 4Kbytes of SRAM. There are 3 communication ports UART &  SPI, an external memory  - either SRAM or FRAM and up to 4 x 10 bit ADC channels.

The external memory is either a 23K256 SRAM - and there's facility for battery or super-cap backup, or a non-volatile FRAM device.  Either way it extends the memory by a useful 32K to 256K bytes.

ChipStick comes with a detachable programmer section - which consists of the USB- serial converter IC and the 3V3 regulator.  Without the programmer section  ChipStick is just 27 x 11mm  - and that's small enough to fit inside a 2 x 4 LEGO block!

The programmer section is however fairly unobtrusive and can be kept in place - even when the device is plugged into a Launch Pad pcb.