Setting CAN Bus address by GPIO

Hey community,

I use the old odrive 3.6 dual Drive SW version 0.5.6
and I want to change the odrive CAN Bus address by setting a GPIO pin high or low (like i2 chips).
Unfortunately I am not too firm with odrive firmware.
So far I set dev0.config.gpio8_mode = GpioMode.DIGITAL_PULL_UP which I want to use as address switch.

the code so far:

    bool can_add_pin_state = get_gpio(8).read();
    if(axis.config_.dir_gpio_pin ==0){ // AXIS0
        if(can_add_pin_state)
            axis.config_.can.node_id = 2;
        else
            axis.config_.can.node_id = 4;
    }
    else{ //AXIS1
        if(can_add_pin_state)
            axis.config_.can.node_id = 3;
        else
            axis.config_.can.node_id = 5;
    }

The question is, where in Firmware I should add the “address switching” code to immediately change the CAN address during runtime if the GPIO State change.

Would be nice to get some help THX

Changing it during runtime is going to be a pretty complicated endeavor. All the CAN stuff is only initialized during boot - so you’d likely have to check / set CAN address on ODrive power-on or reboot only - e.g. in the board initialization setup.

Thanks, for your answere,
But for some reason I can change the CAN address during runtime using the USB Interface without save configuration or reboot
It uses the new address imidetly
So i think it should be possible

if someone needs. Not nice but it works

void CANSimple::handle_can_message(const can_Message_t& msg) {
// Frame
// nodeID | CMD
// 6 bits | 5 bits
uint32_t nodeID = get_node_id(msg.id);

for (auto& axis : axes) {

    if ((axis.config_.can.node_id == nodeID) && (axis.config_.can.is_extended == msg.isExt)) {
           //TODO NOT WORKING
        bool can_add_pin_state = get_gpio(8).read();
        if(axis.config_.dir_gpio_pin ==0){ // AXIS0
            if(can_add_pin_state)
                axis.config_.can.node_id = 2;
            else
                axis.config_.can.node_id = 4;
        }
        else{ //AXIS1
            if(can_add_pin_state)
                axis.config_.can.node_id = 3;
            else
                axis.config_.can.node_id = 5;
        }

        do_command(axis, msg);
        return;
    }
}

}