dalathegreat / Nissan-LEAF-Battery-Upgrade

Software and guides for upgrading LEAFs to bigger and newer batteries
GNU General Public License v3.0
217 stars 39 forks source link

Flashing 2 Port STM32 ARM Based CAN Bridge Using Linux #38

Open riceke opened 5 days ago

riceke commented 5 days ago

Hello Dala!

First, I just wanted to thank you for all the fantastic work you have been doing with the CAN bridge software! It made it possible for me to upgrade my 2012 LEAF with a 40kWh battery instead of having to retire it and buy a new car.

I know that this is not really an issue per se (as you clearly state that Windows is needed for flashing), but I do not use Windows (the person that helped me with the upgrade does though) and I wanted to try and see if I can flash a new version of the firmware using STLINK and/or STM32CubeProgrammer under Linux.

I have the ST Link V2 USB device connected to the JTAG interface on the STM32F105/F107 based 18 in 1 CAN filter board and I have been able to flash the contents of the 'canbridge.srec' file onto the board and also verified the flash contents against the file.

But, when I replace the same type board, currently in my LEAF, with my newly flashed board it does not work (a lot of CAN bus errors and so forth). Putting back the Windows programmed board makes everything work again.

I am investigating, to start with, that the CPU on my board really executes the code in flash (i.e. starting at 0x08000000) and that it is not instead just executing an initial bootloader (may need setting of some option bytes), but I am also wondering if there is something additional missing that is done by the "magic" 'BridgeFlasher.exe'.

Is there any source available for the 'BridgeFlasher.exe'? I have seen some screen dumps where it says that it successfully patched the 'canbridge.srec' file before flashing it. Exactly what needs patching in the 'canbridge.srec' file and why?

Any other ideas that could point me in a working direction?

Thank you very much for your attention and have a nice day!

dalathegreat commented 4 days ago

Hi @riceke , I switched to linux also a few weeks back, so we will have to get this working :)

Originally when development started, we were still on closed source, and a bit worried about the source code leaking. The original toolchain did some magic with the bits as a copyright protection method. This was not developed by me, it was one of my kind Patreons who set the entire thing up. I will ask them if we could reverse the need for this somehow, I am not so familiar with the STM32 platform to do it myself 😅

I will let you know shortly!

riceke commented 4 days ago

Hello Dala!

Thank you for your prompt reply!

I figured out that the unused pin (or hole) on the JTAG connector is actually the STM32 BOOT0 pin and wiring it to GND makes the CPU boot from flash (at least while I am debugging via the JTAG interface), so I am one step closer, I think.

I will try to test in my LEAF as soon as possible and let you know if it makes any difference.

Thanks!