• Hello ES! We could use some help to get us past the finish line on building the new knowledgebase for the forum.
    Can you donate? Please see our fundraising page. Thank you!

FOC Open Source Firmware for Bafang CAN bus controllers with GD32F303 processor

guys , can someone summarize on the 1st page , what is working and what is not ? can we use any contoller or if some of them risk bricking ? can this be used with besst tool ? is this compatible with bafang Go+ ? etc ?
maybe founder can start patreon page as i think many people would throw few coins to hire full time coder for this
 
This is the off-road mode, not the legal flag.
The speed limitation works only, if the legal flag is set (Coaster Brake Support set to "yes") and the Off-road mode is disabled.
I have Coaster Brake Support set to 'yes' and I'm using the 202 button combination. When I switch the combinations, the number 8 appears on the display. At that point, the throttle is locked at 6 km/h, but the assist speed is still much higher than 25 km/h.
When the display shows 9, off-road mode is activated correctly and the throttle works without limits.


I'm wondering if I should try to modify this mode a bit myself. Could the cat generated below work correctly? If I want to completely disable the throttle in legal flag mode, plus the speed is limited to 25m/h?


// --- START OF MODIFICATION ---
if(MP.legalflag && !MS.offroadflag) {
// Check if pedaling is active (cadence check)
if((uint16_cadence_filtered >> 3) > 15) {
// 1. Speed limit 25km/h (2500 units)
// Power fades between 25km/h and 27km/h
MS.i_q_setpoint_temp = map(MS.Speedx100, 2500, 2700, MS.i_q_setpoint_temp, 0);
}
else {
// 2. Disable power if not pedaling (disables throttle and walk assist)
MS.i_q_setpoint_temp = 0;
}
} //end legalflag
// --- END OF MODIFICATION ---
 
guys , can someone summarize on the 1st page , what is working and what is not ? can we use any contoller or if some of them risk bricking ? can this be used with besst tool ? is this compatible with bafang Go+ ? etc ?
maybe founder can start patreon page as i think many people would throw few coins to hire full time coder for this
I have an older version of the M560, and this software works without any issues. Apparently, all M560 versions share the same processor; I believe it’s the same for the M510 as well, but I’m not certain.
Regardless, it is worth having a BESST interface because if a flashing error occurs via Canable Pro, Canable will no longer recognize the controller. In that case, you have to flash it using BESST. It’s also worth noting that for a successful flash via Canable, you need to increase the delay value to 500 milliseconds in the update window.
Overall, I think almost everything is working well now—the torque sensor works great, and the motor provides smooth assistance without any jerking. The only issue I encountered is the "legal mode" not functioning correctly; in my case, the speed is not being capped at 25 km/h. It would also be good to implement some fixes regarding throttle behavior while in legal mode.

BafangGo app doesn't work with ebics.
to modify parameters we need to connect the controller via canable pro

we can only use the besst interface to upload ebics, we can only modify parameters via canable pro
 
but the assist speed is still much higher than 25 km/h.
What have you defined for the speed limit in the controller tab and the speed limit setting per level in the full assist tab? If you have configured it right, it works properly for sure. I've tested that several times! So don't blame the firmware for not working, unless you have checked your own settings twice! ;)

https://github.com/EBiCS/BAFANG_GD3...98acf3dac788f890df3749/src/CAN_Display.c#L202
https://github.com/EBiCS/BAFANG_GD3...d5a741098acf3dac788f890df3749/src/main.c#L415
https://github.com/EBiCS/BAFANG_GD3...5a741098acf3dac788f890df3749/src/main.c#L1803

BafangGo app doesn't work with ebics.
Would be easy to implement the App specific CAN commands, but is there a need? The app has only very few parameters available and is crappy in general....
 
Last edited:
I have an older version of the M560, and this software works without any issues. Apparently, all M560 versions share the same processor; I believe it’s the same for the M510 as well, but I’m not certain.
Regardless, it is worth having a BESST interface because if a flashing error occurs via Canable Pro, Canable will no longer recognize the controller. In that case, you have to flash it using BESST. It’s also worth noting that for a successful flash via Canable, you need to increase the delay value to 500 milliseconds in the update window.
Overall, I think almost everything is working well now—the torque sensor works great, and the motor provides smooth assistance without any jerking. The only issue I encountered is the "legal mode" not functioning correctly; in my case, the speed is not being capped at 25 km/h. It would also be good to implement some fixes regarding throttle behavior while in legal mode.

BafangGo app doesn't work with ebics.
to modify parameters we need to connect the controller via canable pro

we can only use the besst interface to upload ebics, we can only modify parameters via canable pro
so - with besst i can upload this into motor - 510/560 ?
if i dont have canable i have to use this FW as is ?
out of the box it works better than factory FW ? in what sense ?
walk assist works better ? no overrun on pedals ? smoother start ? smoother power delivery ?
will this work with any display ? is showing more data ?

1778145134923.png
 
guys , can someone summarize on the 1st page , what is working and what is not ? can we use any contoller or if some of them risk bricking ? can this be used with besst tool ? is this compatible with bafang Go+ ? etc ?
maybe founder can start patreon page as i think many people would throw few coins to hire full time coder for this
How to piss off the best coder out there for this, enter pxl666. Remember this is a voluntary thing and what we are getting so far is pretty superb, perhaps it maybe time for the likes @pxl666 to put in a bit of effort themselves and contribute with getting the documented help files into a better state before complaining.
 
no issues with 14s battery ?
The default setting is 52V 14s, so it works fine. It works fine right after flashing (only the default maximum load is 12A, which can be increased via Camable Pro). You can always revert to the original firmware without a problem. It's worth remembering that no one is responsible if something goes wrong with the modification.
 
How to piss off the best coder out there for this, enter pxl666. Remember this is a voluntary thing and what we are getting so far is pretty superb, perhaps it maybe time for the likes @pxl666 to put in a bit of effort themselves and contribute with getting the documented help files into a better state before complaining.
how frustrated you have to be to react this way ? dont go public if you do this for pro users only . github is not really "average user friendly" and i didn't find there in documentation what im asking here...somehow casainho managed to get his OSF 1st page right and explained everything in layman terms ... what is wrong with starting a patreon for this project ??
 
how frustrated you have to be to react this way ? dont go public if you do this for pro users only . github is not really "average user friendly" and i didn't find there in documentation what im asking here...somehow casainho managed to get his OSF 1st page right and explained everything in layman terms ... what is wrong with starting a patreon for this project ??
Create a Github account and I'm sure @stancecoke would more than appreciate a bit of help in getting the documentation supported better. This is maybe where and how you can learn about the OSF, contributing by editing and formatting the documentation ? If you find this to be too demanding then this OSF maybe at this stage, not for you.

Nothing wrong with a patreon account, I think @stancecoke already has a method for you to contribute financially overon Github if you so desire. I always thought that ES was where people helped and contributed by " doing " rather than "buying" as in the EMTB forum where I think you and I have had similar conversations.

Casainho left the OSF he created because users such as yourself demanded too much of his time.
 
What program can I use to compile code into a .bin file? I tried stm32cubeide but encountered too many problems.
 
I have an M510 motor with boot 71 controller, the firmware is for boot 72, is there any way to make it work?
 
The boot is the first hexadecimal character of the firmware, yours is 72 which is for V.3 controllers, mine is 71 which is for V2 controllers, then there are also 90 and 91 which are for V1 controllers. The boot must match, otherwise the update will not start.
I tried to replace the boot with a hex editor, the update procedure works, but the controller remains stuck.
 

Attachments

  • MMG522C4814F802066.2B - Hybridizer.zip
    81.6 KB · Views: 8
Last edited:
I saw now that in github there is the BL3 version which is BOOT 71, I'll try that.
 
different command names etc.
The necessary files are in the repo, so there should be no issues with "wrong" versions.
You should simply import the repo as "existing project"
I'm not at home this weekend, so I can't look up the version I'm using before Sunday evening.
 
Last edited:
I compiled the binary from the untouched v0.008 source code downloaded from GitHub. However, as soon as I try to apply any load to the motor, the BMS triggers 'Discharge Short Circuit' protection and cuts the power.
To compile the project, I modified the linker script (gd32f30x_flash.ld), switching the active lines from line 4 to line 6 (as shown in the attached image) to set the correct offset for the M560. I also patched the resulting .bin file using the crc16_m560_bl38.py script.

What am I doing wrong?
debug mode, optimization level O0
 

Attachments

  • IMG_20260508_174415.jpg
    IMG_20260508_174415.jpg
    7.6 MB · Views: 21
Last edited:
After several days of fiddeling with the M820 bootloader, I got the right hint on mikrocontroller.net :cool:

I hope I can get the M820 running quite soon now...

Edit: is it normal, that the M820 has no throttle input available on the harnish?
On my controller there is no wire from the small connector PCB to the controller PCB for the "ZB" (throttle) pin.

IMG_20260510_195929_666~2.jpg
IMG_20260510_210606_437~2.jpg
 
Last edited:
Back
Top