TREK1000 how to interact with board via cli in terminal

Hi all,

We recently purchased the TREK1000 kit and figured out how to print out information to PC’s terminal via USB.

Now we want to control the board via a cli (command line interface) in terminal.

Can we use the USB-to-SPI to achieve this? If so, is there any reference for it?

P.S. I searched the forum and find this “Information on SPI write/read transaction and be found in section 9 PC USB TO SPI PROTOCOL HANDLING EXPLAINED on page 25 in the DecaRanging PC source code description.”
But I fail to find the source code description with this section. Does anyone have a link for that?

Thanks a lot,

I figured out how to do this. For communicating via termnial, I use the virtual com port, which is function of the STM32F105RC chip on TREK1000.
More specifially, for PC-to-Board, I set a flag in the callback function named “CDC_Receive_FS”, which will be called automatically whenever the chip receives data. In my main function, I first initialize the USB with “CDC_Init_RCPT” function, and then check the flag frequently in the while loop. When I detect the flag is set, I copy value (cmdLen of bytes) out the UserRxBufferFS to my own buffer and process it.
For Board-to-PC, please check the source code “dw_main.c”. At the end it contains code reporting range information. I just do almost the same.

For the USB-to-SPI, it’s a function inherited from EVK1000 board. Thanks to Leo, I find more materials about it. :slight_smile: For people interested in it, try downloading the software package of EVK1000

/* Modified functions ---------------------------------------------------------*/

  • @brief Initializes the CDC media low layer over the FS USB IP for receiving
  •     packets from PC
  • @retval USBD_OK if all operations are OK else USBD_FAIL
    uint8_t CDC_Init_RCPT(void)
    Set Application Buffers /
    USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &UserRxBufferFS[0]);
    Prepare OUT Endpoint for reception */
    return (USBD_OK);


  • @brief Data received over USB OUT endpoint are sent over CDC interface

  •     through this function.
  •     This is a callback function. When data were received, the system calls this function.
  •     The received data can be accessed via Buf and Len
  •     @note
  •     This function will block any OUT packet reception on USB endpoint
  •     untill exiting this function. If you exit this function before transfer
  •     is complete on CDC interface (ie. using DMA controller) it will result
  •     in receiving more data while previous ones are still not sent.
  • @param Buf: Buffer of data to be received [not used; instead use default UserRxBufferFS]

  • @param Len: Number of data received (in bytes)

  • @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
    static int8_t CDC_Receive_FS(uint8_t
    Buf, uint32_t Len)
    u_RxStatus.isCmdRcvd = 1; //indicates data were received
    u_RxStatus.cmdLen = *Len;

    USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &UserRxBufferFS[0]);
    return (USBD_OK);
    /* USER CODE END 6 */