CAN Bootloader
- johu
- Site Admin
- Posts: 6411
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 287 times
- Been thanked: 1379 times
- Contact:
Re: CAN Bootloader
USART update fits in as well
3924 bytes
The protocol is unchanged so it will work with legacy wifi modules
I have reduced the transmitted page size back to 1k to stay compatible.
3924 bytes
The protocol is unchanged so it will work with legacy wifi modules
I have reduced the transmitted page size back to 1k to stay compatible.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
-
- Posts: 271
- Joined: Mon Jan 18, 2021 12:39 pm
- Location: Edinburgh, Scotland, UK
- Has thanked: 54 times
- Been thanked: 82 times
Re: CAN Bootloader
I'm afraid your CAN protocol needs some more work to handle the multiple device case. Without additional identifiers it's quite racey and prone to failures.
When two devices come up at roughly the same time your client responds to the first '3' packet it sees. What if this wasn't the correct board? If you put the ID in the initial '3' the updater can wait until it sees the correct board start then respond (or timeout). That way things proceed in lockstep with only one updater and board communicating and everyone else ignoring and moving on.
Also, I'd be wary of leaving the non-ID code in the bootloader and updater. Sounds like a license to brick boards.
When two devices come up at roughly the same time your client responds to the first '3' packet it sees. What if this wasn't the correct board? If you put the ID in the initial '3' the updater can wait until it sees the correct board start then respond (or timeout). That way things proceed in lockstep with only one updater and board communicating and everyone else ignoring and moving on.
Also, I'd be wary of leaving the non-ID code in the bootloader and updater. Sounds like a license to brick boards.
- johu
- Site Admin
- Posts: 6411
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 287 times
- Been thanked: 1379 times
- Contact:
Re: CAN Bootloader
So you're saying if a node is late it will miss the magic packet and not go into update mode. Good point.
I could remove the non-ID code from the boot loader and leave it to the update script to just mirror back the first ID it sees. I certainly want a non-ID command because most setups will not have more than one OI board on the bus. Well, this is for the python script which I don't see a majority of people using.
The standard case should be an ESP32 module on the CAN bus. I think I'll put the relevant word of the processor serial in two places: an SDO object and a special line in the json output "serial": { "value": 0, "unit": "0=1234ABCD", ... }
Then the wifi module can obtain it and present a drop down with the serial number and perhaps the version string.
As always, sane node id assignment is instrumental for getting the CAN based comms to work.
I could remove the non-ID code from the boot loader and leave it to the update script to just mirror back the first ID it sees. I certainly want a non-ID command because most setups will not have more than one OI board on the bus. Well, this is for the python script which I don't see a majority of people using.
The standard case should be an ESP32 module on the CAN bus. I think I'll put the relevant word of the processor serial in two places: an SDO object and a special line in the json output "serial": { "value": 0, "unit": "0=1234ABCD", ... }
Then the wifi module can obtain it and present a drop down with the serial number and perhaps the version string.
As always, sane node id assignment is instrumental for getting the CAN based comms to work.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
-
- Posts: 271
- Joined: Mon Jan 18, 2021 12:39 pm
- Location: Edinburgh, Scotland, UK
- Has thanked: 54 times
- Been thanked: 82 times
Re: CAN Bootloader
Mirroring back on demand seems like a good compromise for systems where you know the topology.
I intend on implementing CAN updating as part of the openinverter_can_tool. My longer term vision is to be able to manage all aspects of an OI system over CAN. The Tesla M3 inverter sort of forces my hand in this regard.
I intend on implementing CAN updating as part of the openinverter_can_tool. My longer term vision is to be able to manage all aspects of an OI system over CAN. The Tesla M3 inverter sort of forces my hand in this regard.
- johu
- Site Admin
- Posts: 6411
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 287 times
- Been thanked: 1379 times
- Contact:
Re: CAN Bootloader
Same here, the BMS forces me And I think it will be quite neat not to have to juggle with multiple wifi modules anymore.
Currently doing the special SDO indexes for load, save, reset, obtain json
If you want to follow along, I'm on the master branch of libopeninv and testing in stm32-template. I have merged can_new_structure onto the master branch which separates CAN hardware abstraction and user protocols such as custom mapping and SDO.
The inverter is still on the float branch for the simple reason that it still uses the old message mapping structure. When going to the new structure (with more dynamic memory mapping, float gain and offset) it wouldn't be able to load messages anymore unless some converter is implemented.
Currently doing the special SDO indexes for load, save, reset, obtain json
If you want to follow along, I'm on the master branch of libopeninv and testing in stm32-template. I have merged can_new_structure onto the master branch which separates CAN hardware abstraction and user protocols such as custom mapping and SDO.
The inverter is still on the float branch for the simple reason that it still uses the old message mapping structure. When going to the new structure (with more dynamic memory mapping, float gain and offset) it wouldn't be able to load messages anymore unless some converter is implemented.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
-
- Posts: 271
- Joined: Mon Jan 18, 2021 12:39 pm
- Location: Edinburgh, Scotland, UK
- Has thanked: 54 times
- Been thanked: 82 times
Re: CAN Bootloader
Will have a look and see about adding support to oic. Was planning on working on load, save and reset commands soon but haven't started that this week. My code base has a different CAN framework for $reasons but it should be straight forward to adapt. Thanks.
- EV_Builder
- Posts: 1201
- Joined: Tue Apr 28, 2020 3:50 pm
- Location: The Netherlands
- Has thanked: 17 times
- Been thanked: 37 times
- Contact:
Re: CAN Bootloader
IMHO first package just should Tx it's ID. In that way you guarantee that only one device will respond to the correct ID later on with the magic byte. That's UpTo python GUI.
Converting an Porsche Panamera
see http://www.wdrautomatisering.nl for bespoke BMS modules.
see http://www.wdrautomatisering.nl for bespoke BMS modules.
- johu
- Site Admin
- Posts: 6411
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 287 times
- Been thanked: 1379 times
- Contact:
Re: CAN Bootloader
Yes, that is how it's done now. It still contains the loader version number for future extensions and the ID in the last 4 bytes. It then only reacts if the updater responds with the correct ID
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
-
- Posts: 271
- Joined: Mon Jan 18, 2021 12:39 pm
- Location: Edinburgh, Scotland, UK
- Has thanked: 54 times
- Been thanked: 82 times
Re: CAN Bootloader
Just tried this code on my STM32 Bluepill based inverter. It doesn't seem to send anything out on the CAN bus at boot. The serial bootloader part works fine. I tried running the CAN bus at 800k as well as 500k. The CAN interface works fine when running the main firmware (5.24.R, master and new_can_module branches). I've not tried debugging it further.
- EV_Builder
- Posts: 1201
- Joined: Tue Apr 28, 2020 3:50 pm
- Location: The Netherlands
- Has thanked: 17 times
- Been thanked: 37 times
- Contact:
Re: CAN Bootloader
There are multiple CAN 0 pins. If I recall correctly the oi boards often use the af ones.
Converting an Porsche Panamera
see http://www.wdrautomatisering.nl for bespoke BMS modules.
see http://www.wdrautomatisering.nl for bespoke BMS modules.
- johu
- Site Admin
- Posts: 6411
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 287 times
- Been thanked: 1379 times
- Contact:
Re: CAN Bootloader
It uses PA11 and PA12, the primary ones
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
-
- Posts: 271
- Joined: Mon Jan 18, 2021 12:39 pm
- Location: Edinburgh, Scotland, UK
- Has thanked: 54 times
- Been thanked: 82 times
- johu
- Site Admin
- Posts: 6411
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 287 times
- Been thanked: 1379 times
- Contact:
Re: CAN Bootloader
One difference between running the loader and stm32-sine is the clock source. Loader uses the internal oscillator which is less accurate (factory trimmed to 1% deviation). Could that cause trouble? Do you see any activity on a scope?
EDIT: actually UART would also look invalid if it were that...
EDIT: actually UART would also look invalid if it were that...
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
-
- Posts: 271
- Joined: Mon Jan 18, 2021 12:39 pm
- Location: Edinburgh, Scotland, UK
- Has thanked: 54 times
- Been thanked: 82 times
Re: CAN Bootloader
Nothing on the CAN TX pin out of reset until I provoke it by sending an SDO request. Weirdly I can't connect to the device with my ST-Link v2 (clone) or official Nucleo-64 ST-Link. This *used* to work fine. I've had the board for years and it is a genuine STM32F103. Wonder if upgrading has splatted something important.
- EV_Builder
- Posts: 1201
- Joined: Tue Apr 28, 2020 3:50 pm
- Location: The Netherlands
- Has thanked: 17 times
- Been thanked: 37 times
- Contact:
Re: CAN Bootloader
"You provoke by sending sdo request?" How is that exactly?
Converting an Porsche Panamera
see http://www.wdrautomatisering.nl for bespoke BMS modules.
see http://www.wdrautomatisering.nl for bespoke BMS modules.
- johu
- Site Admin
- Posts: 6411
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 287 times
- Been thanked: 1379 times
- Contact:
Re: CAN Bootloader
When you send 0x601 (assuming node id 1) you get a reply back
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- EV_Builder
- Posts: 1201
- Joined: Tue Apr 28, 2020 3:50 pm
- Location: The Netherlands
- Has thanked: 17 times
- Been thanked: 37 times
- Contact:
Re: CAN Bootloader
Thought we talked bootloader?
Converting an Porsche Panamera
see http://www.wdrautomatisering.nl for bespoke BMS modules.
see http://www.wdrautomatisering.nl for bespoke BMS modules.
-
- Posts: 271
- Joined: Mon Jan 18, 2021 12:39 pm
- Location: Edinburgh, Scotland, UK
- Has thanked: 54 times
- Been thanked: 82 times
Re: CAN Bootloader
I've found that erasing and flashing the bootloader via the USART boot ROM on the STM32 seems to improve things. I now get two CAN frames emitted to 0x7de as expected.
The can-updater.py has a problem. It sends out extended ID frames rather than standard ones. I found that sticking "is_extended_id=False," on each call to can.Message() was required to make it work. is_extended_id defaults to True and it's been like that since 2019 according to git-blame.
The serial upload on the bootloader doesn't seem to work well. I found I had to press the reset button after uploading on the web interface to get it to actually start the upgrade process. This did complete successfully though. Not analysed in depth but I wonder if it's a bit racey and perhaps relied on the watchdog resetting it previously to get enough "2" characters?
The can-updater.py has a problem. It sends out extended ID frames rather than standard ones. I found that sticking "is_extended_id=False," on each call to can.Message() was required to make it work. is_extended_id defaults to True and it's been like that since 2019 according to git-blame.
The serial upload on the bootloader doesn't seem to work well. I found I had to press the reset button after uploading on the web interface to get it to actually start the upgrade process. This did complete successfully though. Not analysed in depth but I wonder if it's a bit racey and perhaps relied on the watchdog resetting it previously to get enough "2" characters?
- johu
- Site Admin
- Posts: 6411
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 287 times
- Been thanked: 1379 times
- Contact:
Re: CAN Bootloader
Very odd all this.
Also noticed the extended frames but since it still worked I didn't dig deeper. Will add is_extended_id=False anyway.
With a valid firmware already present, the serial protocol sends a "reset\n" command which causes an immediate reset into the boot loader. So the resetting isn't part of the boot loader. It works well here. Any chance you try another board?
Also noticed the extended frames but since it still worked I didn't dig deeper. Will add is_extended_id=False anyway.
With a valid firmware already present, the serial protocol sends a "reset\n" command which causes an immediate reset into the boot loader. So the resetting isn't part of the boot loader. It works well here. Any chance you try another board?
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
-
- Posts: 271
- Joined: Mon Jan 18, 2021 12:39 pm
- Location: Edinburgh, Scotland, UK
- Has thanked: 54 times
- Been thanked: 82 times
Re: CAN Bootloader
I don't know what's going on. Loading the regular bootloader back on and replacing with the CAN causes everything to behave itself. I'm now able to upgrade bootloaders and firmware via CAN or serial every time. Still no working SWD/ST-Link. Will get another Bluepill as the only other STM32 board I've got is a Nucleo which is too different to be useful. Sorry for any confusion.
I'd guess the extended CAN ID behaviour differences is probably down to the CAN adapter I'm using behaving differently from yours.
I'd guess the extended CAN ID behaviour differences is probably down to the CAN adapter I'm using behaving differently from yours.
Re: CAN Bootloader
Hi Johannes. I'm working on integrating your can bootloader into my future projects as the one I used previously was a bit of shit show. Functionality of the bootloader itself and the Python script work great. The anomaly I'm running into is that after setting the address offset in my linker, I get a strange reset behavior every 1200ms or so. My main application uses ST's HAL, but I have it stripped back to only an LED blink and hitting a reset button to get in into the bootloader for the test.
That out of the way, the only breadcrumb I could find is that in the RCC_CSR register, the LSIRDY and LSION bits show as set on the debugger, but if I load the blink only application compiled to the standard base address, these are not set. It would appear that there is an incomplete timer teardown from the bootloader, or is this LSI needed to make the transition to the application? Just thought Id ping you to see if any of that made sense from an expected function standpoint. Vector table appears to be correctly offset per the application 8k application address offset.
Testing is being done on an STM32F105RBT6
That out of the way, the only breadcrumb I could find is that in the RCC_CSR register, the LSIRDY and LSION bits show as set on the debugger, but if I load the blink only application compiled to the standard base address, these are not set. It would appear that there is an incomplete timer teardown from the bootloader, or is this LSI needed to make the transition to the application? Just thought Id ping you to see if any of that made sense from an expected function standpoint. Vector table appears to be correctly offset per the application 8k application address offset.
Testing is being done on an STM32F105RBT6
Formerly 92 E30 BMW Cabrio with Tesla power
-
- Posts: 260
- Joined: Sun Feb 20, 2022 4:23 am
- Location: N. Wiltshire. UK
- Has thanked: 21 times
- Been thanked: 129 times
Re: CAN Bootloader
Watchdog is initialised in the bootloader, so a iwdg reset is required before the 2sec timer expires. Application address is 0x08001000 ( 4k offset from bootloader start address ).
Re: CAN Bootloader
Ahhhhhhh that would make sense. The iwdg reset flag was set as well, but I didn't think anything of it since I hadn't initialized it in the application. Ill try rectifying that later. Thanks
EDIT: kicked the dog a bit. That did the trick! Thanks.
EDIT: kicked the dog a bit. That did the trick! Thanks.
Formerly 92 E30 BMW Cabrio with Tesla power