OpenSourceEBike / TSDZ2-Smart-EBike

Flexible OpenSource firmware for TongSheng TSDZ2 mid drive ebike motor
GNU General Public License v3.0
255 stars 131 forks source link

Usage of the serial bootloader #1

Open shadow974 opened 6 years ago

shadow974 commented 6 years ago

The STM8 plattform has an embedded Bootloader which listens to commands in the very first seconds of the bootup-procedure. It has to be enabled by the option-bytes and is deactivated when read-protection is enabled (so no chance for first-time-usage)

https://github.com/gicking/stm8gal is a complete replacement for stm8flash and running on Linux and Windows (should do on mac, too)

Im going to test this on all of my available hardware (motor, LCD3, XH18).

The bootloader should be activated on any new installations...

ncvanleeuwen commented 6 years ago

First working examples: https://github.com/endlesscadence/stm8-experiments

shadow974 commented 6 years ago

Why are you coding your own flash-tool? Is stm8gal not working on windows?

sbridger commented 5 years ago

It would be potentially useful if the firmware has a serial commend that makes it jump into the bootloader. I understand that the bootloader has entry points for this.

When using bluetooth powered by the bike, the bluetooth link (probably) is not up, before the natural power-on bootloader phase has ended.

geeksville commented 5 years ago

btw: if this option bit was turned on for the TSDZ2, I think it would be not-hard to make a special build for the SW102 display that enables the following workflow (for wireless sw updates of the motor code):

casainho commented 5 years ago

The firmware on TSDZ2 is only about 25% free, so, no point to use bootloader.

See that original firmware is within the limit of 16kbybtes flash memory. We are using 32 kbytes even if the microcontroller reference says it is 16 kbytes.

geeksville commented 5 years ago

Though I wasn't clear: the STM8 includes a bootloader in the mask rom which is automatically started if the option bits are set to start it (so it doesn't cost flash)

On Fri, Aug 9, 2019 at 2:14 PM casainho notifications@github.com wrote:

The firmware on TSDZ2 is only about 25% free, so, no point to use bootloader.

See that original firmware is within the limit of 16kbybtes flash memory. We are using 32 kbytes even if the microcontroller reference says it is 16 kbytes.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/OpenSource-EBike-firmware/TSDZ2-Smart-EBike/issues/1?email_source=notifications&email_token=AABXB2P7AM5BFWT74IWSWALQDXMZ5A5CNFSM4FZAFEGKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD37ZEGY#issuecomment-520065563, or mute the thread https://github.com/notifications/unsubscribe-auth/AABXB2I3NYR6TBPWKKDYGV3QDXMZ5ANCNFSM4FZAFEGA .

sbridger commented 5 years ago

Enabling the bootloader in the display would also be (potentially more) useful, as the display doesn't have a connector for the programmer. Once bootloader was enabled the display can be reflashed through the serial connector. (and the display can be sealed up permanently again)

Probably also working for the STM32 based ones, as I understand they also use same type of bootloader.

As I said above, you could also add a serial command to jump into the bootloader

geeksville commented 5 years ago

For the SW102 we've (where we is @lowperformer) have already enabled the bootloader. Only the initial programming requires opening the case. All further updates are done via Bluetooth from an Android or iOS phone.

The benefit of having the bootloader on for the motor is that after pushing an update to the display, the display can then update the motor.

(Sent from a phone - please ignore typos)

On Sat, Aug 10, 2019, 22:22 sbridger notifications@github.com wrote:

Enabling the bootloader in the display would also be (potentially more) useful, as the display doesn't have a connector for the programmer. Once bootloader was enabled the display can be reflashed through the serial connector. (and the display can be sealed up permanently again)

Probably also working for the STM32 based ones, as I understand they also use same type of bootloader.

As I said above, you could also add a serial command to jump into the bootloader

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/OpenSource-EBike-firmware/TSDZ2-Smart-EBike/issues/1?email_source=notifications&email_token=AABXB2KYWEPNUX4OOMBEI43QD6OZFA5CNFSM4FZAFEGKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4A2IMQ#issuecomment-520201266, or mute the thread https://github.com/notifications/unsubscribe-auth/AABXB2OMB2XPNF5ERUMKGD3QD6OZFANCNFSM4FZAFEGA .

geeksville commented 5 years ago

Btw: In a couple of weeks I should receive a new bike (yay! new bike day!) and I'll be moving my TSDZ2 over to that bike. Since I will have everything all apart I'll do two things:

If the motor still works for me, I'll change the wiki instructions to have the byte set to have the bootloader ON. This would a) allow us to close this bug ;-) and b) allow future software updates to be installed directly from the display CPU with no need for a STLINK.

casainho commented 5 years ago

It is the motor firmware itself that controls the option bytes, so I think you should change on firmware only. I think that now on wiki there is no mention to the option bytes anymore.

geeksville commented 5 years ago

Good point. It can be set straight from the hex file.

(Sent from a phone - please ignore typos)

On Tue, Aug 27, 2019, 21:38 casainho notifications@github.com wrote:

It is the motor firmware itself that controls the option bytes, so I think you should change on firmware only. I think that now on wiki there is no mention to the option bytes anymore.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/OpenSource-EBike-firmware/TSDZ2-Smart-EBike/issues/1?email_source=notifications&email_token=AABXB2L7N554JJSJI6YLNJLQGX6KVA5CNFSM4FZAFEGKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5J3TFY#issuecomment-525580695, or mute the thread https://github.com/notifications/unsubscribe-auth/AABXB2PNP3Z3I44V2DIXTT3QGX6KVANCNFSM4FZAFEGA .