---
# System prepended metadata

title: mazu-radar01 and IWR1642BOOST (mmwave)
tags: [Embedded]

---

mazu-radar01 and IWR1642BOOST (mmwave)  
====
###### tags: `Embedded`
# [Mazu Radar01]
- [Source code](https://github.com/octoberskyTW/mazu-radar01)
- [Task force](https://docs.google.com/spreadsheets/d/1Gdp5GuuY8-10Y96f18PdeT0apUSxCbdzLPBlInAsUro/edit?usp=sharing)
Board: https://www.ti.com/tool/IWR1642BOOST
Chip: https://www.ti.com/product/IWR1642
- [IWR1642 Evaluation Module (board information)](https://www.ti.com/lit/ug/swru521c/swru521c.pdf?ts=1592057867403&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FIWR1642)
    - Board hardware component Getting start guide
    - on-chip C67x DSP core: DSS
    - low-power ARM R4F controllers: MSS
    - PC connection: The connectivity is provided through the micro USB connector over the onboard XDS110
(TM4C1294NCPDT) emulator.
![](https://i.imgur.com/oLX1DLn.png)
- [IWR1642 Bootloader Flow](https://www.ti.com/lit/an/swra563/swra563.pdf?ts=1592058543226&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FIWR1642)

![](https://i.imgur.com/H8mMn18.png)

![](https://i.imgur.com/4hL09L2.png)
## Download SDK for Linux
- [MMWAVE-SDK Product downloads](https://software-dl.ti.com/ra-processors/esd/MMWAVE-SDK/latest/index_FDS.html)
## UniFlash (Load image tool)
https://www.ti.com/tool/download/UNIFLASH

- [mmwave_uniflash_user_guide](https://software-dl.ti.com/ccs/esd/uniflash/mmwave/mmwave_uniflash_user_guide_v1.0.pdf)
- [Vital Sign Getting start guide](https://dev.ti.com/tirex/explore/node?node=APLdiAlfz1KJDByv3CnI.A__AocYeEd__LATEST)

This soft link provides instructions to execute the following command on the Linux machine to resolve the error detected.
```
sudo ln -sf /lib/x86_64-linux-gnu/libudev.so.1 /lib/x86_64-linux-gnu/libusb-0.1.so.4
```

Make sure your host could reconized the device
```shell
lsusb 
Bus 001 Device 011: ID 0451:bef3 Texas Instruments, Inc. 

ls /dev/tty*
/dev/ttyACM0
/dev/ttyACM1
```
Jumper:
![](https://i.imgur.com/xpx7njj.png)


Run the Flash tool:
```shell=
cd uniflash_6.0.0/node-webkit
./nw
```
Choose the Demo Image
![](https://i.imgur.com/H72wKgS.png)

Select the com port
![](https://i.imgur.com/XJ5Bttk.png)


Return to the Program tab, `power cycle` the device and click on Load Images

When the flash procedure completes, UniFlash’s console should indicate: [SUCCESS] Program Load completed
successfully

Power off the board and remove the jumper from only header SOP2 (this puts the board back in functional
mode)

> [name=Dung-Ru Tsai]ToDo
I think when we develope the firmware, make board become to Debug mode. Because the flash has limit access times.
> ToDo [Command line interface for load image](http://downloads.ti.com/ccs/esd/uniflash/docs/latest_qsguide.html#Command%20Line%20Interface)

### Demo on the Web
Please check the mmwave_sdk_user_guide.pdf in `3. 3. Running the Demos`.
![](https://i.imgur.com/7E2oS0W.png)

- [mmWaveDemoVisualizer](https://dev.ti.com/gallery/view/mmwave/mmWave_Demo_Visualizer/ver/3.4.0/)

### Interact with command Line
`sudo apt-get install cutecom`

### DSS uart Output Data Analysis
packages/ti/demo/xwr16xx/mmw/include/mmw_output.h
- 40 bytes Header:
    - `struct MmwDemo_output_message_header_t`
- TLV:Type: 4 bytes,  Length: 4 bytes, payload
    - `struct MmwDemo_output_message_tl_t`
- Example:
```
# Header
0201 0403 0605 0807 0300 0403 c002 0000
4216 0a00 0100 0000 a107 f006 0300 0000
0500 0000 0000 0000 
# TLV0: MMWDEMO_OUTPUT_MSG_DETECTED_POINTS, length 0x30
0100 0000 3000 0000
bf88 a7bd 85be f83c 0000 0000 0000 0000
ff60 df3d 33f1 de3f 0000 0000 0000 0000
a9db f8bf 58ba f03f 0000 0000 0000 0000
# TLV2: MMWDEMO_OUTPUT_MSG_DETECTED_POINTS_SIDE_INFO, length: 0x0c
0700 0000 0c00 0000 
f000 ff02 1401 f102 ed00 b202
```
![](https://i.imgur.com/0EgBgnN.png)
```clike=
typedef struct MmwDemo_output_message_header_t
{
    /*! @brief   Output buffer magic word (sync word). It is initialized to  {0x0102,0x0304,0x0506,0x0708} */
    uint16_t    magicWord[4];

    /*! brief   Version: : MajorNum * 2^24 + MinorNum * 2^16 + BugfixNum * 2^8 + BuildNum   */
    uint32_t     version;

    /*! @brief   Total packet length including header in Bytes */
    uint32_t    totalPacketLen;

    /*! @brief   platform type */
    uint32_t    platform;

    /*! @brief   Frame number */
    uint32_t    frameNumber;

    /*! @brief   Time in CPU cycles when the message was created. For XWR16xx/XWR18xx: DSP CPU cycles, for XWR14xx: R4F CPU cycles */
    uint32_t    timeCpuCycles;

    /*! @brief   Number of detected objects */
    uint32_t    numDetectedObj;

    /*! @brief   Number of TLVs */
    uint32_t    numTLVs;

    /*! @brief   For Advanced Frame config, this is the sub-frame number in the range
     * 0 to (number of subframes - 1). For frame config (not advanced), this is always
     * set to 0. */
    uint32_t    subFrameNumber;
} MmwDemo_output_message_header;
```


- `static void MmwDemo_transmitProcessedOutput`

```clike
    tlvIdx = 0;
    /* Send detected Objects */
    if ((pGuiMonSel->detectedObjects == 1) || (pGuiMonSel->detectedObjects == 2) &&
        (result->numObjOut > 0))
    {
        UART_writePolling (uartHandle,
                           (uint8_t*)&tl[tlvIdx],
                           sizeof(MmwDemo_output_message_tl));

        /*Send array of objects */
        UART_writePolling (uartHandle, (uint8_t*)objOut,
                           sizeof(DPIF_PointCloudCartesian) * result->numObjOut);
        tlvIdx++;
    }
```
[mmWave.h](https://github.com/MMwaveOctomap/OctomapROS/blob/7f77a82eb279e84871314985f6f09d52849462e7/ti_mmwave_rospkg/include/mmWave.h)
```clike
/**
 * @brief
 *  笛卡尔坐标系中定义的点信息数据结构
 *
 */
typedef struct DPIF_PointCloudCartesian_t
{
    /*! @brief  x  */
    float  x;
    /*! @brief  y  */
    float  y;
    /*! @brief  z  */
    float  z;
    /*! @brief  多普勒速度　*/
    float    velocity;
}DPIF_PointCloudCartesian;
```
- My Python rada01 parser for original demo data `MmwDemo_output_message_header`. ([Link](https://github.com/octoberskyTW/mazu-radar01/blob/master/utils/radar01_toolbox.py))

# Send HTTP Request to Server
- [Refresh the Network system programming](https://github.com/angrave/SystemProgramming/wiki#8-networking)
- [高效能 Web 伺服器開發](https://hackmd.io/@sysprog/fast-web-server?fbclid=IwAR2V1SBEQPfrMEBE190VNij2sMFX9jFLTOXkvZ_X_QTmUkiiEuYWZLft2aA#%E9%AB%98%E6%95%88%E8%83%BD-Web-%E4%BC%BA%E6%9C%8D%E5%99%A8%E9%96%8B%E7%99%BC)
- [Build a simple-http server from scratch](https://medium.com/from-the-scratch/http-server-what-do-you-need-to-know-to-build-a-simple-http-server-from-scratch-d1ef8945e4fa)
- [HTTP Request Message request](https://notfalse.net/39/http-message-format)
## Use EPOLL Build HTTP socket Server/Client
- [sehttpd](https://hackmd.io/@ldotrg/rkRm9KJR8)
- [kecho](https://hackmd.io/@sysprog/linux2020-kecho)
- [khttpd](https://hackmd.io/@sysprog/linux2020-khttpd)

# Ringbuffer: Communicate between two thread
- [2020 quiz13 mmap 及 memfd](https://hackmd.io/@sysprog/linux2020-quiz13)
- [2020 quiz16 ring buffer](https://hackmd.io/@sysprog/linux2020-quiz16)

# 2020/07/05 First link
![](https://i.imgur.com/fMDoR88.png)


# Reference
- [IWR1642 datasheet](https://www.ti.com/lit/ds/symlink/iwr1642.pdf?ts=1592057704649&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FIWR1642)
- [Technical Reference Manual](https://www.ti.com/lit/ug/swru522e/swru522e.pdf?ts=1592106720478)
- [Serial Programming Guide on POSIX](https://www.cmrr.umn.edu/~strupp/serial.html)
    - [How to set up serial communication on linux](https://stackoverflow.com/questions/15890903/how-to-properly-set-up-serial-communication-on-linux)
    - [Serial port source code example](https://stackoverflow.com/questions/6947413/how-to-open-read-and-write-from-serial-port-in-c)
    - [LINUX USB SERIAL SENDING 0X0D RECEIVING 0X0A ISSUE](https://importgeek.wordpress.com/2013/11/05/linux-usb-serial-sending-0x0d-receiving-0x0a-issue/)


### 1.2 Applications
- Industrial Sensor for Measuring Range, Velocity, and Angle
- Tank Level Probing Radar
- Displacement Sensing
- Field Transmitters
- Traffic Monitoring
- Proximity Sensing
- Security and Surveillance
- Factory Automation Safety Guards
- People Counting
- Motion Detection

# Driver Vital Sign

[Driver Vital Sign](http://dev.ti.com/tirex/explore/node?node=APLdiAlfz1KJDByv3CnI.A__AocYeEd__LATEST)



## Install the SDK 
- (Reference `mmwave_sdk_user_guide.pdf` 4.5.2.2)
1. Download the SDK from TI [site](https://software-dl.ti.com/ra-processors/esd/MMWAVE-SDK/latest/index_FDS.html)
```shell=
chmod +x mmwave_sdk_03_04_00_03-Linux-x86-Install.bin
mkdir -p /home/jake/Workspace/mazu-radar01-device/mmwave_sdk
./mmwave_sdk_03_04_00_03-Linux-x86-Install.bin
```
Install to the `mazu-radar01-device/mmwave_sdk` path.
2. Set up environment variable
```shell=
cd mazu-radar01-device/mmwave_sdk/mmwave_sdk_03_04_00_03/packages/scripts/unix

vim setenv.sh
export MMWAVE_SDK_DEVICE=iwr16xx
```
The install SDK path should be following
```shell=
export MMWAVE_SDK_TOOLS_INSTALL_PATH=/home/jake/Workspace/mazu-radar01-device/mmwave_sdk

export MMWAVE_SDK_TOOLS_INSTALL_PATH=/home/jake/Workspace/mmwave-sdk2.0
```
3. Install dependency
```shell
sudo dpkg --add-architecture i386
sudo apt-get install build-essential
sudo apt-get --assume-yes install mono-complete
```
4. Run setenv.sh

Every time use new terminal please reload the script
```bash
pushd /home/jake/Workspace/mazu-radar01-device/mmwave_sdk/mmwave_sdk_03_04_00_03/packages/scripts/unix/
source setenv.sh
```
- Vital sign using SDK 02-00
```bash
cd ~/Workspace/mmwave-sdk2.0/mmwave_sdk_02_00_00_04/packages/scripts/unix $ 
source setenv.sh
```
5. Build the demo code
```shell=
cd ~/Workspace/mazu-radar01-device/original_driver_vital_sign/vitalSigns_target
make all
```
Success Result:
```shell
/home/jake/Workspace/mazu-radar01-device/mmwave_sdk/mmwave_sdk_03_04_00_03/packages/scripts/ImageCreator/multicore_image_generator/MulticoreImageGen LE 37 0x00000006 xwr16xx_mmw_demo.bin 0x35510000 xwr16xx_mmw_demo_mss.bin 0xb5510000 /home/jake/Workspace/mazu-radar01-device/mmwave_sdk/mmwave_sdk_03_04_00_03/packages/../firmware/radarss/xwr16xx_radarss_rprc.bin 0xd5510000 xwr16xx_mmw_demo_dss.bin
Number of Input Files 3
Number of zeros 16
Number of zeros 48
Number of zeros 24

/home/jake/Workspace/mazu-radar01-device/mmwave_sdk/mmwave_sdk_03_04_00_03/packages/scripts/ImageCreator/crc_multicore_image/crc_multicore_image xwr16xx_mmw_demo.bin xwr16xx_mmw_demo.bin.tmp
size of App Image is 310784 bytes
cur_crc_read_addr 128
cur_crc_read_addr 116288
cur_crc_read_addr 152064

>>>> Binary CRC32 = c739490b <<<<
>>>> Total bytes in binary file 310788 <<<<

**************************************************************************
Built the flash binary xwr16xx_mmw_demo.bin
**************************************************************************
```
# JSON-C construct device data as JSON format
Download the json-c: https://github.com/json-c/json-c/wiki
- [release tar](https://s3.amazonaws.com/json-c_releases/releases/index.html)
- [Hello world example](https://gist.github.com/alan-mushi/19546a0e2c6bd4e059fd)
```shell=
tar xzf json-c-0.14.tar.gz
mkdir build
cd build
cmake ..
make all test 
sudo make install
```
Build and linke libary
```shell=
JSON_C_DIR=/path/to/json_c/install
CFLAGS += -I$(JSON_C_DIR)/include/json-c
LDFLAGS+= -L$(JSON_C_DIR)/lib -ljson-c
```



