Run Sample Code

2022-08-09
No Rating

After registering a PSDK enterprise account, please download the sample code provided by PSDK and supplement the application information in the sample code, and obtain the sample program by compiling, debugging, and burning. After binding DJI's hardware platform on DJI Assistant 2, you can run the sample program to learn how to use PSDK to develop a load device with the help of the sample program.

Tips: To run RTOS or Linux sample code on other development boards or operating systems, please refer to Cross-platform portingopen in new window.

Get sample code

After register as a DJI PSDK enterprise user, you can download the DJI PSDK development kit. Get the sample code provided by DJI in the PSDK development kit, learn how to use the PSDK to develop a payload device with the help of the sample code, and use the sample code to quickly develop a fully functional payload device.

Create payload application

After obtaining the permissionopen in new window to develop payload products using PSDK, please go to the User Centeropen in new window to create a payload application and obtain the application ID and application key, as shown in Figure 1. Fill in the application information.

Figure 1. Fill in the application information

Note: To improve your development efficiency, please correctly fill in the application name, ID, Key, and developer account in the sample code, otherwise the compiled sample program will not function properly.

Run RTOS sample code

Note: This article takes the STM32F4 Discovery development board as an example to introduce the steps and methods of running the RTOS sample code.

Burn Bootloader

  1. Use Keil MDK IDE to open the project file mdk_bootloader.uvprojx located in the sample/sample_c/platform/rtos_freertos/stm32f4_discovery/project/mdk_bootloader/.
  2. Use Keil MDK IDE to compile the project as a sample program.
  3. burn the compiled sample program into the load device (such as the STM32F4_discovery development board).

Related Reference:

  • Implement Bootloader: platform/rtos_freertos/stm32f4_discovery/bootloader
  • Project directory of Bootloader: platform/rtos_freertos/stm32f4_discovery/project/mdk_bootloader

Fill Application Information

  1. Use Keil IDE to open the project file mdk_app.uvprojx located in the sample/sample_c/platform/rtos_freertos/stm32f4_discovery/project/mdk/.
  2. Fill in the sample/sample_c/platform/rtos_freertos/application/dji_sdk_app_info.h file with the name, ID, Key, License, developer account, and specified baud rate of the application.
#define USER_APP_NAME               "your_app_name"
#define USER_APP_ID                 "your_app_id"
#define USER_APP_KEY                "your_app_key"
#define USER_APP_LICENSE            "your_app_license"
#define USER_DEVELOPER_ACCOUNT      "your_developer_account"
#define USER_BAUD_RATE              "460800"

Compile and burn

  • Use Keil MDK IDE to compile the sample code as a sample program.
  • After compiling the sample code, burn the compiled program into the load device (such as the STM32F4_discovery development board).
  • To debug the sample program, please set the baud rate of the serial debugging tool to: 921600.

Run the Linux sample code

Note: This article takes **Manifold 2-C as an example to introduce the steps and methods of running the Linux sample code.

Fill Application Information

  • Replace the application name, ID, Key, License, developer account and specified baud rate in the samples/sample_c/platform/linux/manifold2/application/dji_sdk_app_info.h file.
#define USER_APP_NAME               "your_app_name"
#define USER_APP_ID                 "your_app_id"
#define USER_APP_KEY                "your_app_key"
#define USER_APP_LICENSE            "your_app_license"
#define USER_DEVELOPER_ACCOUNT      "your_developer_account"
#define USER_BAUD_RATE              "460800"
  • Fill in the corresponding serial port names in the LINUX_UART_DEV1 and LINUX_UART_DEV2 macros in the samples/sample_c/platform/linux/manifold2/hal/hal_uart.h file.
#define LINUX_UART_DEV1    "/dev/your_com"
#define LINUX_UART_DEV2    "/dev/your_com"
  • Use the ifconfig command to view the name of the network port device currently communicating with the drone, and fill in the LINUX_NETWORK_DEV macro in the samples/sample_c/platform/linux/manifold2/hal/hal_network.h file.
#define LINUX_NETWORK_DEV    "your_network_name"

Compile the sample program

  • Compile the sample code

Enter the directory of the sample code: sample/platform/linux/manifold2/project, and use the following command to compile the sample code into a sample program.

  1. mkdir build
  2. cd build
  3. cmake ..
  4. make
  • Execute C language sample program
    • Go to the directory of the sample program: cd build/bin/
    • Use the sudo ./dji_sdk_demo_linux command to run the sample program
  • Execute the C++ language sample program
    • Go to the directory of the sample program: cd build/bin/
    • Use the sudo ./dji_sdk_demo_linux_cxx command to run the sample program

Application binding (using Xport or Skyport V2)

After binding the SkyPort V2 with the sample program through DJI Assistant 2, when the payload device is mounted on the drone, the payload device will automatically run the sample program compiled or burned by the developer.

Illustrate:

  • When using DJI Assistant 2 to bind or debug the payload device, please turn on the "Data Authorization" switch in the "Configuration" tab in the upper right corner of the software, otherwise DJI Assistant 2 will not be able to bind or debug the payload device normally.
  • After the initial binding of SkyPort V2, when using the same SkyPort V2 on different drones, there is no need to re-bind the sample program.
  1. Mount the payload device (such as Manifold 2-C) or development board (such as STM32F407IGH6-EVAL) on the DJI drone, and connect the DJI drone to the computer at the same time.
  2. Log in to DJI Assistant 2 using the account in App Information, and click the "Payload SDK" tab to enter the PSDK hardware platform interface.
  3. On the PSDK hardware platform interface, click the "Bind" button to bind the hardware platform, sample program, and DJI drone.
  4. After the binding is successful, the binding status in the PSDK hardware platform interface will be displayed as bound, as shown in Figure 2. Application binding.

Figure 2. Application binding

  1. Confirm that the baud rate of the communication between the PSDK adapter and the PSDK payload is 460800 (the communication baud rate of the PSDK sample program is 460800);

Figure 3. Setting the communication baud rate

  1. After the application is bound successfully, the payload device will automatically run the sample program.

Binding Troubleshooting

1. Troubleshooting SkyPort V2

Error CodeDescriptionSolution
1Unable to get the information of the payload. 1. Confirm that the hardware platform is properly connected.
2. Confirm that the payload control program developed based on PSDK runs normally.
2Account illegal. Please confirm that the user information in payload device control program is the same as that in bound adapter.
3Unable to obtain the authentication information. Please submit the log of the payload to DJI technical support team for troubleshooting.
4SkyPort verification failed.
5Authentication information incorrect.
6Binding information stored failed.
7Unable to get the SN.

2. Application Service Troubleshooting

Error Code Description Solution
400SN doesn't exist. Please submit the log of the payload to DJI technical support team for troubleshooting.
500Server exception.
700The payload's applications is no found.
701Verification failed.
702Binding error.

3.Assistant software troubleshooting

Error Code Description Solution
3The network is abnormal. Please make sure your computer can access the Internet.
4Software Error Reinstall the Assistant2 or restart your computer.
5FTP Error.

Compilation troubleshooting

Error when compiling sample code with Keil MDK: "error: L6050U"

  • Cause of failure: Keil MDK is not activated.
  • Workaround: Please activate Keil MDK before compiling sample code with Keil MDK.