Close

Reprogramming Without Soldering

A project log for Motor Shield Reprogramming

Create and flash new firmware for the WeMos D1 Mini Motor Shield.

dehipudeʃhipu 04/21/2017 at 18:108 Comments

Turns out that the procedure in the previous log can be greatly simplified. You don't need an ST-Link programmer, and you don't need to solder anything. Even if your shield is locked, you can unlock and program it with a simple serial adapter. Here is how.

First, clone the repository:

$ git clone https://github.com/pbugalski/wemos_motor_shield
$ cd wemos_motor_shield

Make sure you have arm-none-eabi-gcc installed, and compile it:

$ make
arm-none-eabi-gcc -Wall -g -std=c99 -Os -mlittle-endian -mcpu=cortex-m0 -march=armv6-m -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-Map=motor_shield.map -Iinc src/startup_stm32.s src/main.c src/user_i2c.c src/tb6612.c -o motor_shield.elf -Tstm32f030.ld
arm-none-eabi-objcopy -O binary motor_shield.elf motor_shield.bin
arm-none-eabi-size motor_shield.elf
   text	   data	    bss	    dec	    hex	filename
   2032	   1084	   1056	   4172	   104c	motor_shield.elf

Now, make sure you have stm32flash utility installed. Short the RTS and the 3V pins on the shield together, like this:

And the connect the main pins of the shield to your USB2TTL as follows:

GND ↔ GND

3V3 ↔ 3V3 (or VCC or whatever it is called on your USB2TTL)

D2 ↔ TX

D1 ↔ RX

and connect it to your computer. Now, see if you can communicate with the device:

$ stm32flash /dev/ttyUSB0
stm32flash 0.5

http://stm32flash.sourceforge.net/

Interface serial_posix: 57600 8E1
Version      : 0x31
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0444 (STM32F03xx4/6)
- RAM        : 4KiB  (2048b reserved by bootloader)
- Flash      : 32KiB (size first sector: 4x1024)
- Option RAM : 16b
- System RAM : 3KiB

Now, you can unlock your shield:

$ stm32flash /dev/ttyUSB0 -k
stm32flash 0.5

http://stm32flash.sourceforge.net/

Interface serial_posix: 57600 8E1
Version      : 0x31
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0444 (STM32F03xx4/6)
- RAM        : 4KiB  (2048b reserved by bootloader)
- Flash      : 32KiB (size first sector: 4x1024)
- Option RAM : 16b
- System RAM : 3KiB
Read-UnProtecting flash
Done.

$ stm32flash /dev/ttyUSB0 -u
stm32flash 0.5

http://stm32flash.sourceforge.net/

Interface serial_posix: 57600 8E1
Version      : 0x31
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0444 (STM32F03xx4/6)
- RAM        : 4KiB  (2048b reserved by bootloader)
- Flash      : 32KiB (size first sector: 4x1024)
- Option RAM : 16b
- System RAM : 3KiB
Write-unprotecting flash
Done.
And now you can flash it:
$ stm32flash /dev/ttyUSB0 -v -w motor_shield.bin
stm32flash 0.5

http://stm32flash.sourceforge.net/

Using Parser : Raw BINARY
Interface serial_posix: 57600 8E1
Version      : 0x31
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0444 (STM32F03xx4/6)
- RAM        : 4KiB  (2048b reserved by bootloader)
- Flash      : 32KiB (size first sector: 4x1024)
- Option RAM : 16b
- System RAM : 3KiB
Write to memory
Erasing memory
Wrote and verified address 0x08000c2c (100.00%) Done.

Then disconnect all the wires (including the RTS pin), connect the shield to your WeMos D1 Mini, and it should work.

Discussions

trulala wrote 05/23/2018 at 11:21 point

Hi all, thx for the fix. I would like to use ESPeasy with the D1 mini and motorshield. But currently there is no plugin available, only for the adafruit motor shield. Is anybody able to support me in writing a plugin for ESPeasy?

https://www.letscontrolit.com/forum/viewtopic.php?f=6&t=2844&p=28237#p28237

  Are you sure? yes | no

Nigel Haslam wrote 02/20/2018 at 06:02 point

Hi folks,

I'm struggling to communicate with my motor shield.

Using this Arduino USB2TTl device..

https://www.jaycar.com.au/arduino-compatible-usb-to-serial-adaptor-module/p/XC4464

Which, while it has a switch for 5v /3.3v data power,  seems to lack a 3.3 v power output.  I have stm32flash working on a Raspberry Pi and it flickers the LEDs on the USB2TTL device but fails to initialize the motor shield.

I tried powering the 3.3 v input on the motor shield from a separate serial adaptor that had such an output but I have a feeling I'm not connecting to the right bits.  Not sure how to post an image here but here's a link to an image with  my assumptions and question marked up on the same image as the OP posted at the start of this thread

http://motioncircus.com/WemosMotorConnectionsEdited.jpg

Any suggestions welcome

Thanks for your generous sharing

Sdack

  Are you sure? yes | no

brockmeier.adam wrote 11/26/2017 at 06:26 point

Hey, I hope it's not too late to ask some questions about this! I'm trying my hardest to get this working since I have a project where I'm only driving a stepper motor twice a week and I immediately saw the shield getting stuck in standby after more than ten seconds idle.

I have access to windows and linux (through a Pi) but am having a hell of a time getting a FT232RL adapter to work for programming it. On windows with the STM32 flashing program I can't get it to recognize the board. Via Arduino IDE I'm having even less luck. I'm attempting to follow your guide for linux but having trouble downloading the arm-none-eabi-gcc. Could you please offer some help? My email is brockmeier.adam@gmail.com. I appreciate the help in advance! -Adam

  Are you sure? yes | no

deʃhipu wrote 11/26/2017 at 09:11 point

Hi, you don't need arm-none-eabi-gcc if you use the precompiled images that are available for download in the "files" section of this project.

  Are you sure? yes | no

brockmeier.adam wrote 11/26/2017 at 14:55 point

Oh, that makes it easier. So I did try shorting 3v and RTS and attempting to connect through stm32 flash utility (matching baud rate that you had in the example and making sure it was set the same through device manager) but it would only time out. Any guesses on the issue? D1 and D2 are the pins along the side of the board not the top, correct?

  Are you sure? yes | no

deʃhipu wrote 11/26/2017 at 15:12 point

Correct. Make sure you also have GND and power connected. If it still doesn't work, double-check your connections, check there isn't anything else using that serial port, etc. — it should work.

  Are you sure? yes | no

brockmeier.adam wrote 11/26/2017 at 15:47 point

I got it! The secret must have been a good night's sleep. Thanks for the help!

  Are you sure? yes | no

Marc Evers wrote 10/28/2017 at 20:00 point

Brilliant, I used a Pro Mini USB to serial converter I had lying around, fastest fix ever!

  Are you sure? yes | no