BBSHD-FW: Open Source Firmware for BBSHD Motor Controller

Discussions related to motors other than hub motors.
This includes R/C motors, botttom bracket, roller and geared drives.
Post Reply
danielnilsson9   1 mW

1 mW
Posts: 19
Joined: Jan 05 2021 3:09pm

BBSHD-FW: Open Source Firmware for BBSHD Motor Controller

Post by danielnilsson9 » Jul 28 2022 10:20am

This open source project is finally ready for release!

This firmware is intended to replace the original Bafang firmware on the BBSHD motor controller and can be flashed using the standard programming cable. Almost all functionality of original firmware has been reimplemented and more special features
has been added.

This firmware is compatible with all displays that works with the original firmware. A custom configuration tool is provided since BafangConfigTool is not compatible due to a different set of supported parameters.

Supported Hardware (v1.0.0)
BBSHD Controller revision 1.4 and 1.5.

NOTE:
The release contains two different firmware files, one for 1.4 and one for 1.5, you must flash the correct version or it will not work.

1.4 -> STC15W4K56S4
1.5 -> IAP15W4K61S4

Do not flash on any other revision without access to the original firmware (for that revision) to restore or you may brick your controller. If you have a bricked controller of an older revision, please proceed and let me know of the outcome.

It is a good idea to have access to the bafang original firmware files in case you want to roll back for any reason.

Download & Install
https://github.com/danielnilsson9/bbshd-fw

Highlights (v.1.0.0)
  • A bit more power without hardware modifications! (max 32A).
  • No upper voltage limit in software, can by default run up to 63V (maximum rating of components).
  • Support lower voltage cutoff for use with e.g. 36V battery.
  • Smooth Throttle/PAS override.
  • Optional separate set of street legal & offroad assist levels which can be toggled by a key combination.
  • Support setting road speed limit per assist level.
  • Support setting cadence limit per assist level.
  • Support cruise assist levels (i.e. motor power without pedal or throttle input).
  • Display motor/controller temperature (shown in range field on display).
  • Use of speed sensor is optional.
  • Use of display is optional.
Limitations (v1.0.0)
  • No battery SOC calculation implemented yet, set display to show battery voltage instead.
  • No range estimation, the range field on the display will show motor temperature instead.
  • Combining high motor power with low speed limit may cause jerkey behaviour when approaching speed limit (not usually an issue).
  • Low voltage cutoff is a bit crude, it does not limit power when approaching LVC.
    When limit has been hit controller is disabled and needs to be restarted by power cycle.
  • Reporting of some motor technical error codes is missing (e.g. current sense resistor and phase line errors).
Since this is an open source firmware alternative the possibilities for future improvements are endless, if you have any suggestions, just let me know.

Configuration Tool
To give you a hint of available options.

Image

Image

john61ct   100 GW

100 GW
Posts: 8579
Joined: Dec 18 2018 2:06pm

Re: BBSHD-FW: Open Source Firmware for BBSHD Motor Controller

Post by john61ct » Jul 28 2022 8:58pm

Wow!

What a great contribution to the community, Thank You!!

Sorry if an obvious question, is this using true FOC?

thread discussing definition

viewtopic.php?t=105139

danielnilsson9   1 mW

1 mW
Posts: 19
Joined: Jan 05 2021 3:09pm

Re: BBSHD-FW: Open Source Firmware for BBSHD Motor Controller

Post by danielnilsson9 » Jul 29 2022 1:45am

See here https://github.com/danielnilsson9/bbshd ... l-Protocol

Basically the BBSHD controller has two different microcontrollers where one is only focused on doing BLDC control and the other does everything else. The communicate with each other through a serial line.

This firmware only replace the firmware on the "everything else" controller. The other one cannot be flashed without taking the controller pcb out of the housing and removing some of the potting on the bottom.

It is something that is on my list to investigate if it would be possible to provide an optional firmware for this MCU too, but I have not put much work into it yet. It is sort of a rare MCU and there does not exist a cheap flashing device for uploading software.

This is what I got:

User Manual:
https://github.com/danielnilsson9/bbshd ... 11-NEC.pdf

Flash Programming Protocol:
https://github.com/danielnilsson9/bbshd ... x3-pgm.pdf

Development environment that could be used in "evaluation mode" which I believe is enough:
https://www.renesas.com/us/en/document/ ... 0?r=488821

Here is a project which seems to be able to dump the flash to extract original firmware:
https://github.com/AndrewGBelcher/78K0R_flash_leaker

It also seems to implement more of the programming protocol and could potentially be used for programming the chip.

Also, I have access to source code for an implementation on FOC on this exakt microcontroller (no idea about the quality) which I found a while ago.

I might give this a shot someday, if I can get a shell project running which works and can be flashed I'm sure there are a lot of folks here on the forum that could help with the BLDC control firmware.

Edit:
Upon further investigation I believe UFD79F9211 has been rebranded to UFD78F1000 by Renesas. The have the exact same architecture, memory map and pin layout. Hopefully the tooling provided by Renesas will produce binaries targeting UFD78F1000 that also works on UFD79F9211.

Edit2:
I have looked at the controller PCB and there are no current sense resistors for any phase phase so we cannot due "true FOC".
The MCU that runs the BLDC control can measure battery current and battery voltage.
This will put us in the same situation as TSDZ2 firmware which implements a simplified form of FOC i believe, based on a motor model and the measured battery voltage and current? Which I guess we could to for the BBSHD/(BBS02 eventually) since is just has to work with two different motors.

I know very little about BLDC/FOC etc at the moment, if I messed something up here, please correct me.
Last edited by danielnilsson9 on Jul 29 2022 9:00am, edited 1 time in total.

User avatar
Cybernetica   100 µW

100 µW
Posts: 7
Joined: Jul 19 2022 3:21am

Re: BBSHD-FW: Open Source Firmware for BBSHD Motor Controller

Post by Cybernetica » Jul 29 2022 5:39am

This is absolutely fantastic news!

As a BBS02 owner I sent 10$ donation to help you get BBS02 controller.

I encourage everyone who owns BBSXX to do the same whether it's to support BBSHD developent or to speed up the release of BBS02 version.

Thank you!

TenMile   100 µW

100 µW
Posts: 8
Joined: Aug 08 2020 3:10pm

Re: BBSHD-FW: Open Source Firmware for BBSHD Motor Controller

Post by TenMile » Jul 29 2022 2:07pm

Can anyone expand on how the "No Display" would work? How would you select PAS levels etc?


User avatar
fechter   100 GW

100 GW
Posts: 15868
Joined: Dec 31 2006 3:23pm
Location: California Bay Area, USA

Re: BBSHD-FW: Open Source Firmware for BBSHD Motor Controller

Post by fechter » Jul 30 2022 10:59am

Great work! I'll have to check it out. I sort of hate messing with my BBSHD since it's running nicely now, but it has a couple of the known annoying issues.
"One test is worth a thousand opinions"

SuperSl0w   10 mW

10 mW
Posts: 22
Joined: Dec 22 2018 11:48am

Re: BBSHD-FW: Open Source Firmware for BBSHD Motor Controller

Post by SuperSl0w » Jul 31 2022 11:29am

This is supurb. Already donated $10 for this guys hard work. This is what the bbshd needs, custom fw!

danielnilsson9   1 mW

1 mW
Posts: 19
Joined: Jan 05 2021 3:09pm

Re: BBSHD-FW: Open Source Firmware for BBSHD Motor Controller

Post by danielnilsson9 » Jul 31 2022 2:27pm

TenMile wrote:
Jul 29 2022 2:07pm
Can anyone expand on how the "No Display" would work? How would you select PAS levels etc?
You won't. You only have on level, you startup assist level selected when configuring the firmware. You can do the same with the original firmware really. It is mostly useful when running a throttle only setup, but it would also work with the "variable PAS" mode where you set assist level power using the throttle but still have to pedal to receive the power.

On another note, has anyone tried running this firmware with a gear sensor? I the power gap wide enough for smooth shifting or does it need to be tuned for a nicer experience? I don't have a gear sensor and haven't tested that function.

caleb7   1 mW

1 mW
Posts: 14
Joined: Sep 23 2020 4:55pm

Re: BBSHD-FW: Open Source Firmware for BBSHD Motor Controller

Post by caleb7 » Aug 04 2022 7:12am

63V support opens door to 15s li-ion batteries without modifications? That should make some happy. With maximum of 32A current enabled, that would be equal to 1700-2000W range. I have no idea about how efficiency would get affected by this though.

By the way I don't see anything about gear sensor in "Limitations", I guess it works.

Bengy22   10 mW

10 mW
Posts: 21
Joined: Dec 31 2019 2:42pm

Re: BBSHD-FW: Open Source Firmware for BBSHD Motor Controller

Post by Bengy22 » Aug 05 2022 10:00pm

Anyone have a photo of what the display would look like with this firmware, maybe even with a bafang 860c? I too have been very happy with my current firmware, even did the shunt mod to 45a (which I assume wouldn't cause any problems with this firmware other than reporting the wrong amps like currently it does) but I do like how this will show the temps. I already put a thermistor on the controller side but having it built into the display would be nice.

IceBandit   1 µW

1 µW
Posts: 1
Joined: Jul 11 2022 1:37am

Re: BBSHD-FW: Open Source Firmware for BBSHD Motor Controller

Post by IceBandit » Aug 07 2022 7:14pm

Looks like a great mod. Well done.
I'd love to see a setup that uses a hidden switch to toggle the entire display to show a 250w street legal setup (Australian nanny state law) so that when the cops show up to inspect your setup it deceives them into thinking its all good! :)) Slap a 250w sticker on the motor as well. But for normal ops one could revert back to the standard setup.

Post Reply