Skip to content

python-can: GsUsbBus was not properly shut down #144

@golovinengineer

Description

@golovinengineer

Describe the bug

After programming a custom STM32405RG board and trying to run a test Python script get an error: "GsUsbBus was not properly shut down".
Test script is following:

import can
import usb
import usb.core

dev = usb.core.find(idVendor=0x1209, idProduct=0xCA01)

with can.Bus(interface="gs_usb", channel=0, bitrate=1000000) as bus:
    pass

Logs of cannectivity firmware are:

*** Booting Zephyr OS build 9c1fbc8a86ad ***
17:49:20.460: *** CANnectivity firmware v1.2.0-35-ge075c51a7e48 ***
17:49:20.460: [00:00:00.000,000] <dbg> gs_usb: gs_usb_register_channel: channel 0 features = 0x0000203b
17:49:20.460: [00:00:00.000,000] <dbg> gs_usb: gs_usb_register_channel: channel 1 features = 0x0000203b
17:49:20.460: [00:00:00.010,000] <dbg> gs_usb: gs_usb_init: initialized class instance 0x2000082c, interface number 0
17:49:20.460: [00:00:00.010,000] <inf> main: CANnectivity firmware initialized with 2 channels

First I think it is macOS acting up, but same error on Ubuntu VM. I've tried main branch and 1.2-branch with the same result. I've built with next_usb stack with the same result.
The hardware is working, I've built Blinky and cdc_acm samples to check my board config and USB are okay. Also another firmware working well on same Ubuntu VM.
libusb is installed.

To Reproduce

  1. Build firmware on main branch/1.2-branch
  2. Flash firmware regularly
  3. Try to run python script mentioned above

Expected behavior

Script passes without error

Board device tree

/dts-v1/;
#include <st/f4/stm32f405Xg.dtsi>
#include <st/f4/stm32f405rgtx-pinctrl.dtsi>
#include <zephyr/dt-bindings/input/input-event-codes.h>

/ {
	model = "Robotics Hardware Solutions FPCAN Board";
	compatible = "rhs,fpcan", "st,stm32f405";

	chosen {
		zephyr,console = &zephyr_udc0;
		zephyr,shell = &zephyr_udc0;
		zephyr,sram = &sram0;
		zephyr,flash = &flash0;
		zephyr,ccm = &ccm0;
		zephyr,canbus = &can1;
	};

	leds {
		compatible = "gpio-leds";

		state_led: state_led {
			gpios = <&gpioa 0 GPIO_ACTIVE_HIGH>;
			label = "State LED";
		};

		rx1_led: rx1_led {
			gpios = <&gpioa 1 GPIO_ACTIVE_HIGH>;
			label = "CAN1 RX LED";
		};

		tx1_led: tx1_led {
			gpios = <&gpioa 2 GPIO_ACTIVE_HIGH>;
			label = "CAN1 TX LED";
		};

		rx2_led: rx2_led {
			gpios = <&gpioa 3 GPIO_ACTIVE_HIGH>;
			label = "CAN2 RX LED";
		};

		tx2_led: tx2_led {
			gpios = <&gpioa 4 GPIO_ACTIVE_HIGH>;
			label = "CAN2 TX LED";
		};
	};


	aliases {
		led0 = &state_led;
		led1 = &rx1_led;
		led2 = &tx1_led;
		led4 = &rx2_led;
		watchdog0 = &iwdg;
		sdhc0 = &sdmmc1;
	};
};

&clk_lsi {
	status = "okay";
};

&clk_hse {
	clock-frequency = <DT_FREQ_M(8)>;
	status = "okay";
};

&pll {
	div-m = <4>;
	mul-n = <168>;
	div-p = <2>;
	div-q = <7>;
	clocks = <&clk_hse>;
	status = "okay";
};

&rcc {
	clocks = <&pll>;
	clock-frequency = <DT_FREQ_M(168)>;
	ahb-prescaler = <1>;
	apb1-prescaler = <4>;
	apb2-prescaler = <2>;
};

&can1 {
	pinctrl-0 = <&can1_rx_pb8 &can1_tx_pb9>;
	pinctrl-names = "default";
	status = "okay";
};

&can2 {
	pinctrl-0 = <&can2_rx_pb5 &can2_tx_pb6>;
	pinctrl-names = "default";
	status = "okay";
};

zephyr_udc0: &usbotg_fs {
	pinctrl-0 = <&usb_otg_fs_dm_pa11 &usb_otg_fs_dp_pa12>;
	pinctrl-names = "default";
	status = "okay";
};

&iwdg {
	status = "okay";
};

&backup_sram {
	status = "okay";
};

Environment

  • Target board: custom stm32f405rg board with CAN transceiver
  • OS: macOS 26.1/Ubuntu 24.04
  • Toolchain: Zephyr SDK version 17.0
  • CANnectivity Git commit SHA: e075c51
  • Zephyr RTOS Git commit SHA: 9c1fbc8a86ad0f57190b6b84dd19bd88a189dc49

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions