-
Flashing multiple images with two stlinkv2 at once
04/27/2020 at 19:47 • 0 commentsMultiple Programmers! I have a project where I need to have two STM8's with different code on them in the same circuit. So, I wanted to build a programmer that could simultaneously put code on two STM8's at once using two USB plugged stlinkv2 programmers. The programmer is based on a raspberry pi 3 B+ and I used raspbian buster full as the OS. It has the compliler and almost all the bits needed right out of the box. I had to install libusb dev to build the stm8flash binary.
Then I ran into a snag.
The stlink's showed up as /dev/stlinkv2_2 and /dev/stlinkv2_3 so I figured that I'd simply point the stm8flash at them thusly:
stm8flash -c stlinkv2 -d /dev/stlinkv2_2 -p stm8s103f3 -s flash -w IMG1.hex
and
stm8flash -c stlinkv2 -d /dev/stlinkv2_3 -p stm8s103f3 -s flash -w IMG2.hex
No dice. The stm8flash simply flashes to the first one it sees both times. You need to pass stm8flash the -S flag with the stlinkv2's internal serial number. Then I had to dig in and learn about serial numbers. I tried the usual things, lsusb -v, and dmesg, and digging around in /proc, and usb-devices and so on. No matter where I pulled the serial number from, it was a string of unintelligible and some non-printable characters. I could not
It then dawned on me that I had the source for stm8flash. *lightbulb*
At line 233 of main.c (at least in my copy), I found this:
// print programmer data if no serial number specified
if(!pgm_serialno_specified) {
fprintf(stderr, "Programmer %d: %s %s, Serial Number:%s\n", numOfProgrammers, vendor, device, serialno_hex);
}I'm not sure how the logic is intended to be triggered to print the serial number from command line use of stm8flash. It seems like if there is more than one programmer, and the serial is not specified, it should print them, but it did not work that way for me. However, if you copy the fprintf() statement to outisde of the if() { }, then it prints them regardless, and you get a nice happy hexidicimal string that works with stm8flash. Since I had my system copy installed in /usr/local/bin, I just used the local source copy to print out serial numbers and I'm sure one could probably not kludge it up like me, but I was being impatient.
pi@raspberrypi:~/stm8flash-master $ ./stm8flash -d /dev/stlinkv2_3 -c stlinkv2 -p stm8s103f3 -u Determine OPT area WARNING: More than one programmer found but no serial number given. Programmer 1 will be used: Programmer 1: STMicroelectronics STM32 STLink, Serial Number:553F6606483F57541227073F Programmer 1: STMicroelectronics STM32 STLink, Serial Number:553F6606483F57541227073F Programmer 2: STMicroelectronics STM32 STLink, Serial Number:503F6F06483F57562156203F Programmer 2: STMicroelectronics STM32 STLink, Serial Number:503F6F06483F57562156203F Due to its file extension (or lack thereof), "Workaround" is considered as RAW BINARY format! Tries exceeded
Now to flash the multiple images to their respective STM8's, I just run this:
stm8flash -c stlinkv2 -d /dev/stlinkv2_2 -p stm8s103f3 -S 553F6606483F57541227073F -s flash -w IMG1.hex
and
stm8flash -c stlinkv2 -d /dev/stlinkv2_3 -p stm8s103f3 -S 503F6F06483F57562156203F -s flash -w IMG2.hex
-
Quickly Adapt Project to stm8ef-modular-build
04/18/2020 at 17:43 • 1 commentI have been able to quickly apply Thomas's new modular approach to my project. Thank you! I grabbed a zip file of the stm8ef-modular-build repo and extracted it on my linux box. I have sdcc and supporting software installed there. First I edited the board.fs and put in a little cusomization for what I needed. This file contains the forth code you will be running at the end of your build, after the target is flashed with your new image. If you write things to NVM here and then COLD or WIPE and start it, the newly programmed micro will now be your own custom embedded device. By default it will display an analog input on the LEDs as a number from 0 to 1023, which you can scale how you like in the show function, for example:
4 ADC! ADC@ 1000 1023 */ .
This would result in scaling the full range of the input (a voltage from 0-3.3V or from 0-5V depending on your supply, use a regulated supply) to a number between 0 and 1000. You could scale up from 1023 as well.
If you're building for a different chip, edit the target.inc to reflect the correct memory layout. I basically changed all the STM8S003F3 to STM8S103F3 (which is really just this one line for my chip). This is probably a bit pedantic and may not be necessary.
EEPROMEND = 0x427F ; STM8S103F3: 640 bytes EEPROM
Pay attention to boardcore.inc when you assemble your project for pin numbers and GPIO settings. The file globconf.inc controls some of the features you're going to use or not use. You can turn things on and off simply here. If you don't want a serial console, say you need to use those pins for something else, you can turn of the UART that is on those pins.
HAS_TXUART = 0 ; No UART TXD, word TX! HAS_RXUART = 0 ; No UART RXD, word ?RX
There is a README.md file in the DEMO directory, read that in addition to the top level README for all this info and more. When you're done with your edits you type make, and if you've got all your ducks in a row, it builds the image, flashes it onto your device (that you have connected with your STLINKV2). Say you have another terminal open, maybe with e4thcom running in it, and you've got a usb-ttl converter connected to the serial console pins on your device as well, you can talk directly to the forth instance running your newly coded environment.
Now why would you even want do this? The way I had to go about this before was to clone a whole board, like the W1209-CA, directory in the stm8ef repo, modify all the .fs and .inc files, and the top level Makefile to get it to work. This was a great way to learn it, but using the modular repo is so much easier and faster.