Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating dji sdk policy file... 串口写失败 #237

Open
shiner-chen opened this issue Jan 17, 2025 · 1 comment
Open

Updating dji sdk policy file... 串口写失败 #237

shiner-chen opened this issue Jan 17, 2025 · 1 comment

Comments

@shiner-chen
Copy link

shiner-chen commented Jan 17, 2025

我想通过psdk在orin agx板上拉取M300 RTK无人机上的视频流,根据官网的操作指南,连接了硬件,在运行psdk的demo程序:dji_sdk_demo_on_jetson, 报以下错误,不知道如何处理?

[0.001][core]-[Info]-[DjiCore_Init:107) Payload SDK Version : V3.10.0-beta.0-build.2190 Jan  9 2025 21:52:37 
[3.079][utils]-[Info]-[DjiSdkVersionAck_Parse:183) Identify aircraft serial number = 1ZNBJAL00C004N, Firmware = 3.4.18.68 
[3.089][adapter]-[Info]-[DjiAccessAdapter_Init:314) Identify aircraft series is Matrice 300 Series 
[3.089][adapter]-[Info]-[DjiAccessAdapter_Init:353) Identify mount position type is Extension Port Type 
[3.101][adapter]-[Info]-[DjiAccessAdapter_Init:475) Identity uart0 baudrate is 230400 bps 
[3.101][adapter]-[Info]-[DjiPayloadNegotiate_Init:134) No need negotiate device info 
[4.266][core]-[Info]-[DjiIdentityVerify_UpdatePolicy:493) Updating dji sdk policy file... 
[5.266][core]-[Info]-[DjiIdentityVerify_UpdatePolicy:493) Updating dji sdk policy file... 
[76.340][core]-[Info]-[DjiIdentityVerify_UpdatePolicy:493) Updating dji sdk policy file... 
[76.356][linker]-[Warn]-[DjiCommand_SendAsyncHandle:965) <0x5239>Command async send retry: index = 10, retryTimes = 65517, 0x0A06->0x0701 0x3C40 
[76.356][linker]-[Error]-[DjiChannel_uartWrite:102) uart write data error 
[76.356][linker]-[Error]-[DjiLinker_SendMsg:198) write data error 
[76.356][linker]-[Warn]-[DjiCommand_SendAsyncHandle:971) Command retry send failed, errorCode:0x000000EC 
[76.360][linker]-[Warn]-[DjiCommand_SendAsyncHandle:965) <0x5237>Command async send retry: index = 8, retryTimes = 65507, 0x0A06->0x0701 0x3C40 
[76.360][linker]-[Error]-[DjiChannel_uartWrite:102) uart write data error 
[76.360][linker]-[Error]-[DjiLinker_SendMsg:198) write data error 
[76.360][linker]-[Warn]-[DjiCommand_SendAsyncHandle:971) Command retry send failed, errorCode:0x000000EC 
[76.360][linker]-[Warn]-[DjiCommand_SendAsyncHandle:965) <0x5238>Command async send retry: index = 9, retryTimes = 65512, 0x0A06->0x0701 0x3C40 
[76.360][linker]-[Error]-[DjiChannel_uartWrite:102) uart write data error 
[76.360][linker]-[Error]-[DjiLinker_SendMsg:198) write data error 
[76.360][linker]-[Warn]-[DjiCommand_SendAsyncHandle:971) Command retry send failed, errorCode:0x000000EC 
[76.367][linker]-[Warn]-[DjiCommand_SendAsyncHandle:965) <0x5236>Command async send retry: index = 7, retryTimes = 65502, 0x0A06->0x0701 0x3C40 
[76.367][linker]-[Error]-[DjiChannel_uartWrite:102) uart write data error 
[76.367][linker]-[Error]-[DjiLinker_SendMsg:198) write data error 
[76.367][linker]-[Warn]-[DjiCommand_SendAsyncHandle:971) Command retry send failed, errorCode:0x000000EC 
[76.373][linker]-[Warn]-[DjiCommand_SendAsyncHandle:965) <0x5234>Command async send retry: index = 5, retryTimes = 65492, 0x0A06->0x0701 0x3C40 
[76.373][linker]-[Error]-[DjiChannel_uartWrite:102) uart write data error 
[76.373][linker]-[Error]-[DjiLinker_SendMsg:198) write data error 
[76.373][linker]-[Warn]-[DjiCommand_SendAsyncHandle:971) Command retry send failed, errorCode:0x000000EC 
[76.376][linker]-[Warn]-[DjiCommand_SendAsyncHandle:965) <0x5235>Command async send retry: index = 6, retryTimes = 65497, 0x0A06->0x0701 0x3C40 
[76.376][linker]-[Error]-[DjiChannel_uartWrite:102) uart write data error 
[76.376][linker]-[Error]-[DjiLinker_SendMsg:198) write data error 
[76.376][linker]-[Warn]-[DjiCommand_SendAsyncHandle:971) Command retry send failed, errorCode:0x000000EC 
[76.378][linker]-[Warn]-[DjiCommand_SendAsyncHandle:965) <0x5233>Command async send retry: index = 4, retryTimes = 65487, 0x0A06->0x0701 0x3C40 
[76.378][linker]-[Error]-[DjiChannel_uartWrite:102) uart write data error 
[76.378][linker]-[Error]-[DjiLinker_SendMsg:198) write data error 
[76.378][linker]-[Warn]-[DjiCommand_SendAsyncHandle:971) Command retry send failed, errorCode:0x000000EC 

硬件连接方式如下:

Image

实物图如下:

Image

E-port的拨码开关如下图:

Image

nv-l4t-usb-device-mode-start.sh脚本如下:

#!/bin/bash
set -ex

# Ensure the script runs as root
if [ "$(id -u)" -ne 0 ]; then
    echo "This script must be run as root"
    exit 1
fi

# Load required modules
sudo modprobe configfs
sudo modprobe libcomposite
sudo modprobe usb_f_fs

# Mount configfs if not already mounted
if ! mountpoint -q /sys/kernel/config; then
    sudo mount -t configfs none /sys/kernel/config
fi

script_dir="$(cd "$(dirname "$0")" && pwd)"
. "${script_dir}/nv-l4t-usb-device-mode-config.sh"

# Wait for any modules to load and initialize
for attempt in $(seq 60); do
    udc_dev_t210=700d0000.xudc
    if [ -e "/sys/class/udc/${udc_dev_t210}" ]; then
        udc_dev="${udc_dev_t210}"
        break
    fi
    udc_dev_t186=3550000.usb
    if [ -e "/sys/class/udc/${udc_dev_t186}" ]; then
        udc_dev="${udc_dev_t186}"
        break
    fi
    sleep 1
done
if [ "${udc_dev}" == "" ]; then
    echo No known UDC device found
    exit 1
fi

macs_file="${script_dir}/mac-addresses"
if [ -f "${macs_file}" ]; then
    . "${macs_file}"
else
    # Generate unique data
    if [ -f /proc/device-tree/serial-number ]; then
        random="$(md5sum /proc/device-tree/serial-number | cut -c1-12)"
    else
        random="$(echo "no-serial" | md5sum | cut -c1-12)"
    fi
    # Extract 6 bytes
    b1="$(echo "${random}" | cut -c1-2)"
    b2="$(echo "${random}" | cut -c3-4)"
    b3="$(echo "${random}" | cut -c5-6)"
    b4="$(echo "${random}" | cut -c7-8)"
    b5="$(echo "${random}" | cut -c9-10)"
    b6="$(echo "${random}" | cut -c11-12)"
    # Clear broadcast/multicast, set locally administered bits
    b1="$(printf "%02x" "$(("0x${b1}" & 0xfe | 0x02))")"
    # Set 4 LSBs to unique value per interface
    b6_rndis_h="$(printf "%02x" "$(("0x${b6}" & 0xfc | 0x00))")"
    b6_rndis_d="$(printf "%02x" "$(("0x${b6}" & 0xfc | 0x01))")"
    b6_ecm_h="$(printf "%02x" "$(("0x${b6}" & 0xfc | 0x02))")"
    b6_ecm_d="$(printf "%02x" "$(("0x${b6}" & 0xfc | 0x03))")"
    # Construct complete MAC per interface
    mac_rndis_h="${b1}:${b2}:${b3}:${b4}:${b5}:${b6_rndis_h}"
    mac_rndis_d="${b1}:${b2}:${b3}:${b4}:${b5}:${b6_rndis_d}"
    mac_ecm_h="${b1}:${b2}:${b3}:${b4}:${b5}:${b6_ecm_h}"
    mac_ecm_d="${b1}:${b2}:${b3}:${b4}:${b5}:${b6_ecm_d}"
    # Save values for next boot
    echo "mac_rndis_h=${mac_rndis_h}" > "${macs_file}"
    echo "mac_rndis_d=${mac_rndis_d}" >> "${macs_file}"
    echo "mac_ecm_h=${mac_ecm_h}" >> "${macs_file}"
    echo "mac_ecm_d=${mac_ecm_d}" >> "${macs_file}"
fi

mkdir -p /sys/kernel/config/usb_gadget/l4t
cd /sys/kernel/config/usb_gadget/l4t

# If this script is modified outside NVIDIA, the idVendor and idProduct values
# MUST be replaced with appropriate vendor-specific values.
echo 0x0955 > idVendor
echo 0x7020 > idProduct
# BCD value. Each nibble should be 0..9. 0x1234 represents version 12.3.4.
echo 0x0002 > bcdDevice

# Informs Windows that this device is a composite device, i.e. it implements
# multiple separate protocols/devices.
echo 0xEF > bDeviceClass
echo 0x02 > bDeviceSubClass
echo 0x01 > bDeviceProtocol

mkdir -p strings/0x409
if [ -f /proc/device-tree/serial-number ]; then
    serialnumber="$(cat /proc/device-tree/serial-number | tr -d '\000')"
else
    serialnumber=no-serial
fi
echo "${serialnumber}" > strings/0x409/serialnumber
# If this script is modified outside NVIDIA, the manufacturer and product values
# MUST be replaced with appropriate vendor-specific values.
echo "NVIDIA" > strings/0x409/manufacturer
echo "Linux for Tegra" > strings/0x409/product

cfg=configs/c.1
mkdir -p "${cfg}"
cfg_str=""

# Note: RNDIS must be the first function in the configuration, or Windows'
# RNDIS support will not operate correctly.
if [ ${enable_rndis} -eq 1 ]; then
    cfg_str="${cfg_str}+RNDIS"
    func=functions/rndis.usb0
    mkdir -p "${func}"
    echo "${mac_rndis_h}" > "${func}/host_addr"
    echo "${mac_rndis_d}" > "${func}/dev_addr"
    ln -sf "${func}" "${cfg}"

    # Informs Windows that this device is compatible with the built-in RNDIS
    # driver. This allows automatic driver installation without any need for
    # a .inf file or manual driver selection.
    echo 1 > os_desc/use
    echo 0xcd > os_desc/b_vendor_code
    echo MSFT100 > os_desc/qw_sign
    echo RNDIS > "${func}/os_desc/interface.rndis/compatible_id"
    echo 5162001 > "${func}/os_desc/interface.rndis/sub_compatible_id"
    ln -sf "${cfg}" os_desc
fi

# If two USB configs are created, and the second contains RNDIS and ACM, then
# Windows will ignore at the ACM function in that config. Consequently, this
# script creates only a single USB config.
if [ ${enable_acm} -eq 1 ]; then
    cfg_str="${cfg_str}+ACM"
    func=functions/acm.GS0
    mkdir -p "${func}"
    ln -sf "${func}" "${cfg}"
fi

# Copy system version information into the exposed filesystem image,
# so that any system that's attached to the USB port can identify this device.
# Do this even if $enable_ums!=1, since $fs_img is locally mounted too.
mntpoint="/mnt/l4t-devmode-$$"
rm -rf "${mntpoint}"
mkdir -p "${mntpoint}"
mount -o loop "${fs_img}" "${mntpoint}"
rm -rf "${mntpoint}/version"
mkdir -p "${mntpoint}/version"
if [ -f /etc/nv_tegra_release ]; then
    cp /etc/nv_tegra_release "${mntpoint}/version"
fi
if dpkg -s nvidia-l4t-core > /dev/null 2>&1; then
    dpkg -s nvidia-l4t-core > "${mntpoint}/version/nvidia-l4t-core.dpkg-s.txt"
fi
if [ -d /proc/device-tree/chosen/plugin-manager ]; then
    cp -r /proc/device-tree/chosen/plugin-manager "${mntpoint}/version/plugin-manager"
fi
umount "${mntpoint}"
rm -rf "${mntpoint}"

if [ ${enable_ums} -eq 1 ]; then
    cfg_str="${cfg_str}+UMS"
    func=functions/mass_storage.0
    mkdir -p "${func}"
    ln -sf "${func}" "${cfg}"
    # Prevent users from corrupting the disk image; make it read-only
    echo 1 > "${func}/lun.0/ro"
    echo "${fs_img}" > "${func}/lun.0/file"
fi

if [ ${enable_ecm} -eq 1 ]; then
    cfg_str="${cfg_str}+${ecm_ncm_name}"
    func=functions/${ecm_ncm}.usb0
    mkdir -p "${func}"
    echo "${mac_ecm_h}" > "${func}/host_addr"
    echo "${mac_ecm_d}" > "${func}/dev_addr"
    ln -sf "${func}" "${cfg}"
fi

enable_bulk=1
if [ ${enable_bulk} -eq 1 ]; then
    mkdir -p /dev/usb-ffs
    
    cfg_str="${cfg_str}+BULK1" 
    mkdir -p /dev/usb-ffs/bulk1
    func=functions/ffs.bulk1
    mkdir -p "${func}"
    ln -sf "${func}" "${cfg}"
    mount -o mode=0777 -o uid=2000 -o gid=2000 -t functionfs bulk1 /dev/usb-ffs/bulk1
    /home/chenx/workspace/usb-bulk-configure/startup_bulk /dev/usb-ffs/bulk1 &
    sleep 3


    cfg_str="${cfg_str}+BULK2" 
    mkdir -p /dev/usb-ffs/bulk2
    func=functions/ffs.bulk2
    mkdir -p "${func}"
    ln -sf "${func}" "${cfg}"
    mount -o mode=0777 -o uid=2000 -o gid=2000 -t functionfs bulk2 /dev/usb-ffs/bulk2
    /home/chenx/workspace/usb-bulk-configure/startup_bulk /dev/usb-ffs/bulk2 &
    sleep 3
fi

mkdir -p "${cfg}/strings/0x409"
# :1 in the variable expansion strips the first character from the value. This
# removes the unwanted leading + sign. This simplifies the logic to construct
# $cfg_str above; it can always add a leading delimiter rather than only doing
# so unless the string is previously empty.
echo "${cfg_str:1}" > "${cfg}/strings/0x409/configuration"

# Create and configure the network bridge before setting the UDC device. This
# ensures that no matter how quickly udev events (which run -runtime-start.sh)
# are triggered after setting the UDC device below, the bridge device is
# guaranteed to exist, so -runtime-start.sh is guaranteed to be able to
# configure it.
#
# Set the device to "down" initially; if/when -runtime-start.sh runs in response
# to cable presence, the interface will be set to "up".
/sbin/brctl addbr l4tbr0
/sbin/ifconfig l4tbr0 down

echo "${udc_dev}" > UDC

# Ethernet devices require additional configuration. This must happen after the
# UDC device is assigned, since that triggers the creation of the Tegra-side
# Ethernet interfaces.
#
# This script always assigns any-and-all Ethernet devices to an Ethernet
# bridge, and assigns the static IP to that bridge. This allows the script to
# more easily handle the potentially variable set of Ethernet devices.
#
# If your custom use-case requires separate IP addresses per interface, or
# only ever has one interface active, you may modify this script to skip
# bridge creation, and assign IP address(es) directly to the interface(s).

if [ ${enable_rndis} -eq 1 ]; then
    /sbin/brctl addif l4tbr0 "$(cat functions/rndis.usb0/ifname)"
    /sbin/ifconfig "$(cat functions/rndis.usb0/ifname)" up
fi

if [ ${enable_ecm} -eq 1 ]; then
    /sbin/brctl addif l4tbr0 "$(cat functions/${ecm_ncm}.usb0/ifname)"
    /sbin/ifconfig "$(cat functions/${ecm_ncm}.usb0/ifname)" up
fi

cd - # Out of /sys/kernel/config/usb_gadget

# Create a local disk device that exposes the same filesystem image that's
# exported over USB. This will allow local users to see the files too.
/sbin/losetup -f -r "${fs_img}"

exit 0

hal_uart.h 内容如下:运行device-mode脚本后,我的usb虚拟串口名称是ttyGS0,而不是你们指南说的ttyACM0.

#ifndef HAL_UART_H
#define HAL_UART_H

/* Includes ------------------------------------------------------------------*/
#include "stdint.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <string.h>
#include "stdlib.h"

#include "dji_platform.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Exported constants --------------------------------------------------------*/
//User can config dev based on there environmental conditions
#define LINUX_UART_DEV1 "/dev/ttyUSB0"
#define LINUX_UART_DEV2 "/dev/ttyGS0"

/* Exported types ------------------------------------------------------------*/

/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode HalUart_Init(E_DjiHalUartNum uartNum, uint32_t baudRate, T_DjiUartHandle *uartHandle);
T_DjiReturnCode HalUart_DeInit(T_DjiUartHandle uartHandle);
T_DjiReturnCode HalUart_WriteData(T_DjiUartHandle uartHandle, const uint8_t *buf, uint32_t len, uint32_t *realLen);
T_DjiReturnCode HalUart_ReadData(T_DjiUartHandle uartHandle, uint8_t *buf, uint32_t len, uint32_t *realLen);
T_DjiReturnCode HalUart_GetStatus(E_DjiHalUartNum uartNum, T_DjiUartStatus *status);

#ifdef __cplusplus
}
#endif

#endif // HAL_UART_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

根据lsusb -d 0955:7020 -v 输出的内容,将hal_usb_bulk.h 文件中bulk配置如下:


/* Exported constants --------------------------------------------------------*/
#define LINUX_USB_BULK1_EP_IN_FD "/dev/usb-ffs/bulk1/ep1"
#define LINUX_USB_BULK1_EP_OUT_FD "/dev/usb-ffs/bulk1/ep2"

#define LINUX_USB_BULK1_INTERFACE_NUM (7)
#define LINUX_USB_BULK1_END_POINT_IN (0x88)
#define LINUX_USB_BULK1_END_POINT_OUT (0x05)

#define LINUX_USB_BULK2_EP_IN_FD "/dev/usb-ffs/bulk2/ep1"
#define LINUX_USB_BULK2_EP_OUT_FD "/dev/usb-ffs/bulk2/ep2"

#define LINUX_USB_BULK2_INTERFACE_NUM (8)
#define LINUX_USB_BULK2_END_POINT_IN (0x89)
#define LINUX_USB_BULK2_END_POINT_OUT (0x06)

#define LINUX_USB_VID (0x0955)
#define LINUX_USB_PID (0x7020)

/* Exported types ------------------------------------------------------------*/
@dji-dev
Copy link
Contributor

dji-dev commented Jan 17, 2025

Agent comment from Leon in Zendesk ticket #127344:

您好,请问下您使用的是板载串口还是USB-TTL,这个主要是串口相关的报错,建议您更换下串口连接链路,或者调整一下波特率。同时您可以确认下无人机的固件版本是否为最新。

°°°

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants