BAFANG M215 (BBS01 CAN bus), M315 (BBS02 CAN bus), M510, M560, M820, CR-A101 FOC Open Source EBiCS Firmware for GD32F303 processors

The harness works on the CAN hubmotor controller for sure. There the wires for the lights are not on the harness, but on the controller directly.
That is how i always try to remember it. If a bafang can controller / motor has bungling wires and uses that trapezium 8 pin connector and having separate wires for the lights, it needs what i call for myself a normal 1T4 canbus cable. Like the one you get included if you buy a BBS01B canbus motor and that cable works also on bafang hub controllers if they have separate wires for the lights like you said.

If the motor has all connectors placed in motor housing like M510 and others then it needs cables with wires for the lights integrated in the cable (if you need lights), which is clearly visible if they have wires for lights or not.

Those Chinese pictures are indeed not always correct, like in the picture you mentioned for the hub motor classification, they have red cross for "other brand motor" and "other bafang hub motor". But that 1T4 canbus cable just works fine as long as you use for that hub motor a bafang controller having separate wires for lights.

In the past I have bought some of those different flavors harness cables because sometimes i need them and i also bought some with "open" end. for checking the ports / connections.
 
They can stop the motor using the harness probably because when they press the brake they shorten the 12V on the ground and overcome the current limit and the 12V sourse triggers protection and turns itself off and as result there in no power on other depending entities including STM32
 
Not quite so. You can fit a light that will pull more than the 1A max on that circuit and it will simply restrict the current to 1A.
 
And seems not to be known by many people, as they're still buying much more expensive things instead... ;)
I only have macs in my house and there's no executable available for Apple silicon.
However I ordered the programming cable from Windmeile and I'll try to go with the source code.
In the meantime the K1 has been a good choice, easy and fast.
 
I only have ... Apple silicon
There is a Canable Tool executable for MacOS x64, I didn't even knew, that apple uses ARM processors also meanwhile. ;) Perhaps we can ask @mdi, if he can provide an executable for Apple ARM also.

as result there in no power on other depending entities including STM32
There is a short circuit detection for the light supply obviously, the pin PC0 gets low, if you shorten the 12V to GND, the system keeps running without issues. I've updated the pinout at github:

1771871425221.png
 
Last edited:
Is it possible to compile firmware for older bootloaders? Firmwares for my M510 start with byte 0x90.
 
Is it possible to compile firmware for older bootloaders?
Can you upload an example bin file, then I can check, if it follows the same logic. A flash dump from the processor would be great also, to confirm that the offset is still 0x4000

I've just updated the repo, brake input on PC13 and head light switch by PB10.
Switching the headlight works, I can't test the brake sensor yet, as I'm waiting for the right harness now.

 
Hm, the file name with "CRX10NC" belongs to a NXP processor, looking at this overview:


So the firmware will not be compatible. If you disassemble your motor the next time for maintenance, you should check the imprint on the processor. ;)
 
Last edited:
CRX10NC is for the M510 just the start of firmware naming. But it can matter on the revision which processor is used. i see his file name has i101 in it so probably hardware 1.0 and i believe your M510 firmware had F802 in it so possible hardware 2.0 or maybe 2.1

As example; in the list "which bafang can controller uses which processor" check the M400
The M400 firmware start always with CRX10B no matter which revision or voltage.
But version 1.0 uses NXP and version 2.1 uses an STM so it is actually important that people also give the revision / hardware version because between revisions / hw versions for the same motor there is the possibility that other processors have been used.

And by looking at it again, i noticed i myself forget to mention the hardware version for the M200. It is 1.0 so please add / correct it. My fault :)
And indeed, the best way is to look at the chip itself to see which processor is used.
 
But it can matter on the revision which processor is used
I don't understand this logic. If you look at the zipfile, you find for the M510 five revisions.

1771939839298.png

The filenames seem to have no reference to this Rev/FC clustering :eek:
Looking at the Interrupt Vector Table makes it quite easy, to check if the bin file is for a NXP or for a STM32 (Clone) as they have different address ranges..
Bytes 4-7 after header: Reset handler address, little endian

File MMG522C4814F802006.1 FC2.1.bin:
0x0800420D --> typical for STM32 (Flash start address 0x08000000)
1771941105965.png

File CRX10NC4316i101002.1.0-28-2230-boot3.0-20220721112544.bin
0x0001A565 --> typical for NXP (Flash start address 0x00000000 or 0x00010000)
1771941620851.png
 
Last edited:
That is the bafang logic :) One way or the other i guess they have no problem with it but it certainly is sometimes a mystery to me..
About the maps you showed with revision 1 to 5 maybe they changed or improved some parts in the motor hardware itself ? I had also read somewhere that the torque sensor is different for FC 1.0 and FC 2.0 ?? I don't know if that is really the case.
It's possible Tomblarom has the answers about that.

It seems to me that in the older motors from years back with FC1.0 that they used NXP more often and in later models for same motor with FC 2.0 or 2.1 or newer that they used different processors.
 
But they didn't throw the fuse
I've set the max battery current from 12 amps to 20 amps now. The log shows two starts from standstill with maximum human effort. You can see the torque signal is cut at 3300 mV. I don't know if the human power is calibrated right, but about 500W for a very short time might be feasible for an old man like me :) In the third area, I gave full throttle while standing next to the bike and braking the front wheel, causing the rear wheel to spin on the tar.

1772215002423.png

The power meter showed 22amps peak current and 725W peak afterwards. Not too bad, I think :cool:
The used battery is very old, 725W/22A = 33V. So 8V voltage drop at 22 amps. You can see in the chart, that the battery current drops while human power stays high when the cadence (and with it the BEMF) increases. On an 48V battery with less voltage drop, the fun would be much higher, I guess 💪 (or it would shred the gears and clutch immedeatly :ROFLMAO: )

1772215384288.png
1772215332297.png
 
Last edited:
I've just pre-released the V0.003.
Head light and break switch should be working now. I've added an off-road feature also. If the legal flag is set, you can toggle between off-road and street mode by executing a user settable sequence of up- and down button clicks.
You can set the "MagicNumber" by the canable tool (field max motor rpm is used). By default it is Eco - 0 - Eco (Magic Number = 202). You have to press the next button within one second, otherwise, the sequence is reset. The display shows a short acknoledge if toggling was successful, it shows "9" if the offroad mode is enabled and "8" if it is disabled.
With the off-road mode enabled the speed limit is disabled and the 6kph limit for the throttle without pedaling is disabled.
When switching on the system, the street mode is active, if the legal flag is set.


You can define up to 4 button clicks for a valid sequence. The "Magic Number" is constructed from the assist level representaton in the Bafang CAN protocol.

0 -> 0
Eco -> 2
Tour -> 4
Sport ->6
Sport+ -> 8
Boost -> 9

A first click is needed to wake up the algorithm, it is ignored. The second click is on the ones place, the third click on the tens place, the fourth on the hundreds place, and the fifth click on the thousands place. So if you choose the sequence Eco-Tour-Sport-Tour, your "Magic Number" ist 4642

 
Last edited:
the 6kph limit for the throttle without pedaling
I've improved the code, it was very nervous before, just a very little movement of the pedals made the throttle signal kick in. Now I have set the limit to filtered 15/min cadence before the throttle works above 6kph.
Here is the log of a test ride in street mode and in offroad mode, it's working properly now.

regards
stancecoke

1772472648943.png
 
Last edited:
a few fitted new controllers and reported they wouldn’t run until the motor had been calibrated using the BESST tool.
I've just pre-released V0.004 that implements the position sensor calibration. Take off the chain before starting the procedure, as described for the original firmware also.
It's tested with my hardware, but of course we need feedback from the community, if it works for all motor/controller combiniations...
Volunteers, step forward! :cool:

regards
stancecoke

 
I've implemented the reset to factory settings and the push assist over the weekend.
So almost everything is working now.
What are the advantages over the original firmware?!
- max motor torque user settable
- max battery current user settable
- off-road mode switchable on the display
- assistance behaviour user tunable

We could test out the real hardware limits now, how much torque the gears and the clutch can take, how much current the controller hardware and the motor coils can take.
No fancy VESC mods or tuning dongles are needed, no need to solder or to open the motor housing, just a Canable or a BESST ;)

 
Last edited:
So almost everything is working now.
One thing missing is the battery indicator. I've implemented a LookUpTable quick and dirty to estimate the SOC. In long term we could add coulomb counting, but as there is almost no feedback on this project since now, I don't want to put too much effort into this topic.
Of course the indicator shows the voltage sag under load also, as the value is not filtered at the moment, but this gives you an indication of the state of health of your battery additionally ;) Here an example graph for a 10s battery.

1773773790351.png
 
Last edited:
Приветствую дорогой друг.
Читаю и подписан на твой труд. Буду бетта тестером, у меня есть парк из разных ebike с разными моторами и батареями но bafang))). На данный момент, у меня есть мотор м510 с контроллером новой версии 3.0, я с тобой делился прошивкой под данный контролер. Есть мотор с контроллером 2.1, на котором я и опробую твою версию ПО. Надеюсь мотор не превратится в кирпич))) Но если и так, у меня есть в запасе пару запасных контроллеров на замену. ))) Меня интересуют только один важный момент. Как тебе известно, есть разработчик которой модифицировал прошивку на маленьком моторе серии М, тот который на 250Вт, думаю ты знаешь о чем я. Так вот, я ее протестировал, и она очень мне понравилась, в особенности, что показания SOC cчитывались контроллером или/и отображались на дисплее с увеличенной периодичностью, так как будто бмс передавала эти показания по кан шине. Но в наших батареи такой бмс нет. Скажи насколько возможно реализовать такую функцию в твоей прошивке? Да, и важный момент, возможно снизить порог снижения мощности по показанием SOC до 15% c 25% по умолчанию. Да на данный момент интересует прошивка на 48В, так как в основном у меня велики на это напряжение. Все тесты и результаты обязательно опубликую
 
Thank you for the feedback. The SOC estimation is implemented in the same way as in the Fake Taxi project, see #169. It's without filtering at the moment. Adding a filter is no problem of course.
There is no power reduction at low SOCs. But of course, with a constant max battery current, the max electric power will be lower at lower voltage.
 
Hm, I don't know, if the M560 uses the same pin functions as the M510. As I have no M560, I can't test it. But I can prepare a bin file with the M560 specific header "73 42 82 00 40" and you can just test it. Which bootloader version has your controller?
 
Last edited:
Hm, I don't know, if the M560 uses the same pin functions as the M510. As I have no M560, I can't test it. But I can prepare a bin file with the M560 specific header "73 42 82 00 40" and you can just test it. Which bootloader version has your controller?
M560 uses M510 controller. I didn't find the bootloader version in the canable. Where can I find it?
 
Back
Top