linklayer / cantact

Drivers and Command Line Interface for CANtact tools
http://cantact.io
MIT License
46 stars 11 forks source link

Device not found Error #3

Closed antman1p closed 3 years ago

antman1p commented 4 years ago

On Ubuntu, when I run can -v dump I get a Device not found Error. ifconfig -a shows can0. The red AND green lights are on, on the cantact.

ericevenchick commented 4 years ago

Hi, thanks for reporting this issue!

Could you provide the tail end of the output for dmesg? It should look something like

[177119.097238] usb 1-7.4.1.4.1: New USB device found, idVendor=1d50, idProduct=606f, bcdDevice= 0.00
[177119.097239] usb 1-7.4.1.4.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[177119.097240] usb 1-7.4.1.4.1: Product: CANtact gs_usb
[177119.097240] usb 1-7.4.1.4.1: Manufacturer: Linklayer
[177119.097241] usb 1-7.4.1.4.1: SerialNumber: 000000000002
[177119.103271] gs_usb 1-7.4.1.4.1:1.0: Configuring for 1 interfaces

It sounds like ether the VID/PID are not what this driver expects, or the driver is failing to detach the device from the kernel gs_usb driver.

brainstorm commented 3 years ago

@ericevenchick I'm having the same error on OSX Catalina 10.15.7:

$ brew install lsusb
(...)
$ lsusb
Bus 020 Device 010: ID 05ac:100e Apple Inc. USB3.0 Hub
Bus 020 Device 009: ID 05ac:100f Apple Inc. USB2.0 Hub
Bus 020 Device 033: ID ad50:60c4 ad50 CANtact dev  Serial: 001600024153430820333937
Bus 020 Device 012: ID 05ac:1460 Apple Inc. USB-C Digital AV Multiport Adapter  Serial: DLC725707H0G2KQAR
Bus 000 Device 001: ID 1d6b:PTLP Linux Foundation USB 3.0 Bus

Then when trying to play a bit with the cantact Rust CLI I'm getting this:

$ ./target/debug/can cfg --channel 0 --bitrate 500000
Channels:
    0 -> Channel { bitrate: 500000, enabled: true, loopback: false, monitor: false, fd: false, data_bitrate: 500000 }
    1 -> Channel { bitrate: 500000, enabled: true, loopback: false, monitor: false, fd: false, data_bitrate: 500000 }

$ ./target/debug/can dump
error: DeviceError(DeviceNotFound)

Full disclosure, I'm reusing one of my STM32F042G6 project dev boards instead of an actual CANtact to get acquainted with this device SINCE I JUST PURCHASED THE CANTACT-PRO and can't wait until it starts shipping post 8th January to Australia ;)

With very minor cantact-fw mods (USB pin remapping is needed due to my STM32 package) I got my dev board flashed with cantact firmware (v1, not PRO):

--- a/Src/stm32f0xx_hal_msp.c
+++ b/Src/stm32f0xx_hal_msp.c
@@ -70,10 +70,10 @@ void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
     __CAN_CLK_ENABLE();

     /**CAN GPIO Configuration
-    PB8     ------> CAN_RX
-    PB9     ------> CAN_TX
+    PB4     ------> CAN_RX
+    PB5     ------> CAN_TX
     */
-    GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
+    GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
@@ -99,10 +99,10 @@ void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan)
     __CAN_CLK_DISABLE();

     /**CAN GPIO Configuration
-    PB8     ------> CAN_RX
-    PB9     ------> CAN_TX
+    PB4     ------> CAN_RX
+    PB5     ------> CAN_TX
     */
-    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9);
+    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_4|GPIO_PIN_5);

   /* USER CODE BEGIN CAN_MspDeInit 1 */

diff --git a/Src/system_stm32f0xx.c b/Src/system_stm32f0xx.c
index 9cd1ca7..29db7cf 100644
--- a/Src/system_stm32f0xx.c
+++ b/Src/system_stm32f0xx.c
@@ -196,6 +196,12 @@ void SystemInit(void)
   /* Reset HSI14 bit */
   RCC->CR2 &= (uint32_t)0xFFFFFFFE;

+  /* Remap pins for USB, see:
+   * https://community.st.com/s/question/0D50X00009XkghG/solved-stm32f042-can-init-problem
+  */
+  RCC->APB2ENR |= RCC_APB2ENR_SYSCFGCOMPEN;
+  SYSCFG->CFGR1 |= (uint32_t)SYSCFG_CFGR1_PA11_PA12_RMP;
+
   /* Disable all interrupts */
   RCC->CIR = 0x00000000;
brainstorm commented 3 years ago

Fun fact, on a Linux machine (old but gold kernel 3.2.x), I'm only getting a bare VID:PID (i.e just ad50:60c4) instead of a proper enumeration string like I get on OSX:

Bus 020 Device 033: ID ad50:60c4 ad50 CANtact dev  Serial: 001600024153430820333937

I doubt it's related, but there are a few warnings referring to the pointer signedness when compiling cantact-fw and specifically related to those strings:

arm-none-eabi-gcc -DCORE_M0 -D HSI48_VALUE=48000000 -D HSE_VALUE=16000000 -D CANTACT_BUILD_NUMBER=0 -DSTM32F042x6 -IDrivers/CMSIS/Include -IDrivers/CMSIS/Device/ST/STM32F0xx/Include -IDrivers/STM32F0xx_HAL_Driver/Inc -IInc -IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc -IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc  -mcpu=cortex-m0 -mthumb -Wall -g -ffunction-sections -fdata-sections -Os -Os -c -o build/stm32f0xx_hal_msp.o Src/stm32f0xx_hal_msp.c
Src/usbd_desc.c: In function 'USBD_FS_ProductStrDescriptor':
Src/usbd_desc.c:72:33: warning: pointer targets in passing argument 1 of 'USBD_GetString' differ in signedness [-Wpointer-sign]
   72 | #define USBD_PRODUCT_STRING_FS  "CANtact" " " CANTACT_SW_VER
      |                                 ^~~~~~~~~
      |                                 |
      |                                 char *
Src/usbd_desc.c:209:21: note: in expansion of macro 'USBD_PRODUCT_STRING_FS'
  209 |     USBD_GetString (USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
      |                     ^~~~~~~~~~~~~~~~~~~~~~
In file included from Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h:36,
                 from Src/usbd_desc.c:37:
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h:90:39: note: expected 'uint8_t *' {aka 'unsigned char *'} but argument is of type 'char *'
   90 | void USBD_GetString         (uint8_t *desc, uint8_t *unicode, uint16_t *len);
      |                              ~~~~~~~~~^~~~
Src/usbd_desc.c:72:33: warning: pointer targets in passing argument 1 of 'USBD_GetString' differ in signedness [-Wpointer-sign]
   72 | #define USBD_PRODUCT_STRING_FS  "CANtact" " " CANTACT_SW_VER
      |                                 ^~~~~~~~~
      |                                 |
      |                                 char *
Src/usbd_desc.c:213:21: note: in expansion of macro 'USBD_PRODUCT_STRING_FS'
  213 |     USBD_GetString (USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
      |                     ^~~~~~~~~~~~~~~~~~~~~~
In file included from Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h:36,
                 from Src/usbd_desc.c:37:
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h:90:39: note: expected 'uint8_t *' {aka 'unsigned char *'} but argument is of type 'char *'
   90 | void USBD_GetString         (uint8_t *desc, uint8_t *unicode, uint16_t *len);
      |                              ~~~~~~~~~^~~~
Src/usbd_desc.c: In function 'USBD_FS_ManufacturerStrDescriptor':
Src/usbd_desc.c:70:34: warning: pointer targets in passing argument 1 of 'USBD_GetString' differ in signedness [-Wpointer-sign]
   70 | #define USBD_MANUFACTURER_STRING "CANtact"
      |                                  ^~~~~~~~~
      |                                  |
      |                                  char *
Src/usbd_desc.c:227:19: note: in expansion of macro 'USBD_MANUFACTURER_STRING'
  227 |   USBD_GetString (USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h:36,
                 from Src/usbd_desc.c:37:
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h:90:39: note: expected 'uint8_t *' {aka 'unsigned char *'} but argument is of type 'char *'
   90 | void USBD_GetString         (uint8_t *desc, uint8_t *unicode, uint16_t *len);
      |                              ~~~~~~~~~^~~~
Src/usbd_desc.c: In function 'USBD_FS_ConfigStrDescriptor':
Src/usbd_desc.c:74:41: warning: pointer targets in passing argument 1 of 'USBD_GetString' differ in signedness [-Wpointer-sign]
   74 | #define USBD_CONFIGURATION_STRING_FS    "CDC Config"
      |                                         ^~~~~~~~~~~~
      |                                         |
      |                                         char *
Src/usbd_desc.c:279:21: note: in expansion of macro 'USBD_CONFIGURATION_STRING_FS'
  279 |     USBD_GetString (USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h:36,
                 from Src/usbd_desc.c:37:
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h:90:39: note: expected 'uint8_t *' {aka 'unsigned char *'} but argument is of type 'char *'
   90 | void USBD_GetString         (uint8_t *desc, uint8_t *unicode, uint16_t *len);
      |                              ~~~~~~~~~^~~~
Src/usbd_desc.c:74:41: warning: pointer targets in passing argument 1 of 'USBD_GetString' differ in signedness [-Wpointer-sign]
   74 | #define USBD_CONFIGURATION_STRING_FS    "CDC Config"
      |                                         ^~~~~~~~~~~~
      |                                         |
      |                                         char *
Src/usbd_desc.c:283:21: note: in expansion of macro 'USBD_CONFIGURATION_STRING_FS'
  283 |     USBD_GetString (USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h:36,
                 from Src/usbd_desc.c:37:
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h:90:39: note: expected 'uint8_t *' {aka 'unsigned char *'} but argument is of type 'char *'
   90 | void USBD_GetString         (uint8_t *desc, uint8_t *unicode, uint16_t *len);
      |                              ~~~~~~~~~^~~~
Src/usbd_desc.c: In function 'USBD_FS_InterfaceStrDescriptor':
Src/usbd_desc.c:75:34: warning: pointer targets in passing argument 1 of 'USBD_GetString' differ in signedness [-Wpointer-sign]
   75 | #define USBD_INTERFACE_STRING_FS "CDC Interface"
      |                                  ^~~~~~~~~~~~~~~
      |                                  |
      |                                  char *
Src/usbd_desc.c:299:21: note: in expansion of macro 'USBD_INTERFACE_STRING_FS'
  299 |     USBD_GetString (USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h:36,
                 from Src/usbd_desc.c:37:
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h:90:39: note: expected 'uint8_t *' {aka 'unsigned char *'} but argument is of type 'char *'
   90 | void USBD_GetString         (uint8_t *desc, uint8_t *unicode, uint16_t *len);
      |                              ~~~~~~~~~^~~~
Src/usbd_desc.c:75:34: warning: pointer targets in passing argument 1 of 'USBD_GetString' differ in signedness [-Wpointer-sign]
   75 | #define USBD_INTERFACE_STRING_FS "CDC Interface"
      |                                  ^~~~~~~~~~~~~~~
      |                                  |
      |                                  char *
Src/usbd_desc.c:303:21: note: in expansion of macro 'USBD_INTERFACE_STRING_FS'
  303 |     USBD_GetString (USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h:36,
                 from Src/usbd_desc.c:37:
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h:90:39: note: expected 'uint8_t *' {aka 'unsigned char *'} but argument is of type 'char *'
   90 | void USBD_GetString         (uint8_t *desc, uint8_t *unicode, uint16_t *len);
      |                              ~~~~~~~~~^~~~
brainstorm commented 3 years ago

@ericevenchick Here's how it looks in my (old) linux machine, btw (no can0 interface as @antman1p points out, am I missing loading some kernel module?):

$ lsusb 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 413c:a005 Dell Computer Corp. Internal 2.0 Hub
Bus 001 Device 003: ID 0b97:7761 O2 Micro, Inc. Oz776 1.1 Hub
Bus 005 Device 016: ID ad50:60c4        <-------- Only VID:PID, no "CANTACT" strings like in OSX
Bus 001 Device 005: ID 0483:2016 SGS Thomson Microelectronics Fingerprint Reader
Bus 001 Device 006: ID 0b97:7762 O2 Micro, Inc. Oz776 SmartCard Reader

$ uname -a
Linux biobit 3.2.0-61-generic-pae #93-Ubuntu SMP Fri May 2 21:46:08 UTC 2014 i686 i686 i386 GNU/Linux

$ dmesg
(...)
[  839.640159] usb 5-1: new full-speed USB device number 16 using uhci_hcd
[  839.812272] cdc_acm 5-1:1.0: This device cannot do calls on its own. It is not a modem.
[  839.812331] cdc_acm 5-1:1.0: ttyACM0: USB ACM device

$ ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:1c:23:14:0d:a1  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:18 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:724 errors:0 dropped:0 overruns:0 frame:0
          TX packets:724 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:51145 (51.1 KB)  TX bytes:51145 (51.1 KB)

wlan0     Link encap:Ethernet  HWaddr 00:0e:8e:0d:fe:0d  
          inet addr:10.1.1.35  Bcast:10.1.1.255  Mask:255.255.255.0
          inet6 addr: fdd2:f6ab:51e1:0:30e4:ce13:d249:9bc2/64 Scope:Global
          inet6 addr: fdd2:f6ab:51e1:0:20e:8eff:fe0d:fe0d/64 Scope:Global
          inet6 addr: fe80::20e:8eff:fe0d:fe0d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4628 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3275 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:3696703 (3.6 MB)  TX bytes:528172 (528.1 KB)

Whereas on OSX the USB reads well:

CANtact dev:

  Produkt-ID:   0x60c4
  Tillverkar-ID:    0xad50
  Version:  2.00
  Serienummer:  001600024153430820333937
  Hastighet:    Upp till 12 Mbit/s
  Tillverkare:  CANtact
  Plats-ID: 0x14124200 / 27
  Tillgänglig ström (mA):   500
  Nödvändig ström (mA): 100
  Extra arbetsström (mA):   0
ericevenchick commented 3 years ago

Oh, this looks like the original CANtact firmware which does USB serial to CAN is probably not what you want. Instead, give the candlelight firmware (https://github.com/candle-usb/candleLight_fw) a go. It implements gs_usb and should work with SocketCAN and these newer tools.

CANtact Pro doesn't do this serial thing at all, it just implements gs_usb. Serial over USB has bottlenecks and is generally not good.

brainstorm commented 3 years ago

Oh, thanks! I just tested it with a minor fix for my specific IC package which needs some of the remapping I mentioned before but with a similar HAL API call:

diff --git a/src/main.c b/src/main.c
index 47b63b5..22c28f8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -215,6 +215,8 @@ void SystemClock_Config(void)

        HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

+       __HAL_REMAP_PIN_ENABLE(HAL_REMAP_PA11_PA12);
+
        /* SysTick_IRQn interrupt configuration */
        HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
 }

And the tooling seems to work now, so I just need to drop a CAN transceiver IC to my repurposed dev board (https://github.com/brainstorm/bbtrackball-rs) and I'll be in business, thanks mate!

Just a minor tweak: could you add a warning message on the "old" cantact_fw repo's README.md? That can save a bit of time/head scratching to other folks, cheers! ;)

brainstorm commented 3 years ago

(...) it just implements gs_usb. Serial over USB has bottlenecks and is generally not good.

@ericevenchick On that point, I'm very curious about the issues you found with serial over USB (a.k.a CDC ACM? SLCAN?)... I don't quite understand how gs_usb is superior or more reliable when the underlying abstraction are both implemented as just queues (I guess?).

brainstorm commented 3 years ago

Sorry to hijack this issue as I did, @antman1p, I faced your issue under Linux and solved it as the README.md states.

Perhaps @ericevenchick can close this issue now I reckon?