A programmer is a device used to program a microcontroller. Usually, it is just another microcontroller with a special program to communicate with a host (PC) and download a program to a device (MCU). However, most the time, programming a MCU requires a high voltage (> 5V) which would dissuade me from making my own because it would require some kind of level converter, but the MSP430 can be programmed entirely within 3.3V!
Once everything is working, the workflow using this custom programmer is only a tiny bit more involved than a real programmer. I still write and compile all my code in Code Composer Studio. Then, I run the python script, hit the reset button on the STM32, and that's it! I am willing to accept the 2 extra button presses in exchange for a free programmer.
Software:
I took the source code from slau320. I decided I only wanted to use the JTAG interface and not Spy-Bi-Wire (SBW), so I deleted all the code for SBW to get rid of the clutter. Then, I stepped through the program trying to see what was happening and cross-referencing the User's Guide. After I confirmed that the code worked, I wrote a routine which would receive a program from UART and program the device. Before writing the program, I made sure to validate the program and erase the correct flash sectors. Then, I wrote a python script that would run on the host (my PC) and send a program file over the UART to the STM32.
Hardware:
I used an STM32L432KC as a programmer because its what I had, and my goal was to program a MSP430G2231 because they are simple, cheap, and available in a PDIP package. In STM32CubeID, in the .ioc file I added some outputs for TMS, TCK, TDO, TEST, RESET, and an input for TDI. On the prototype board I connected all those signals to the correct pins on the DIP-14 socket and two more for +3V3 and GND. I decided to connect them with removable connectors so that I could potentially build a development board later.
Usage:
To tell Code Composer studio to output a hex file, you need to right click the project in the Project Explorer and then Preferences -> Build -> MSP430 Hex Utility -> Enable MSP430 Hex Utility. Next, go Output Format Options -> set Output Format to Intel hex (--intel, -i) from the dropdown. Then, run the python script with python3 msp430programmer.py <tty> 115200 <path-to-hex-file>. Restart the STM32 by pressing the physical restart button.
Expected output:
$ python3 msp430programmer.py /dev/ttyACM0 115200 '/hdd/CCSTUDIO/workspace_v12/white_noise/Release/white_noise.hex' [Host] Opening serial port /dev/ttyACM0 at 115200 baud rate starting... [Host] Programmer is ready [Host] Opening file /hdd/CCSTUDIO/workspace_v12/white_noise/Release/white_noise.hex [Host] Writing file length 416 to programmer... [Host] Writing file to programmer... Verifying .hex file... Connecting to target... Got JTAG ID: 0x0089 -vSuccessfully connected to target 0xf201 Erasing target flash... Writing target flash... Successfully wrote target flash. Time elapsed 0:00.259 Shutting down JTAG connection... [Host] Exit
To find the tty on your device you can do
ls /dev/ | grep tty.usb
on MacOS or
sudo dmesg | grep tty
on Linux.