0%

TI-MSP432E401Y开发指南

概述

  • 本篇基本都是参照TI官网的页面教程去实践学习的.所以一打开SimpleLink™ 以太网 MSP432E401Y MCU LaunchPad™ 开发套件页面,就会看到一个描述,下面很简单明确的指明开始用LaunchPad的步骤:
    • 第 1 步:购买 MSP-EXP432E401Y LaunchPad
    • 第 2 步:下载 MSP432 SDK
    • 第 3 步:完成开箱即用体验并接受 SimpleLink Academy 培训
    • SimpleLink™以太网MSP432E401Y微控制器LaunchPad™开发套件是针对基于SimpleLink™ Arm® Cortex®-M4F的以太网MCU的直观评估平台.以太网 LaunchPad开发套件通过集成以太网MAC和一系列有线通信接口(包括:USB-OTG,CAN,Quad-SPI(QSSI),I2C,SPI,UART以及其他串行协议)将重点放在 MSP432E401Y MCU上.
    • MSP432E4 MCU采用了120MHz Arm Cortex-M4F CPU、1MB 闪存、256kB SRAM和先进的加密加速器,为开发人员提供大量的处理资源,从而实现有线和无线连接栈及处理算法,开发稳健的以太网解决方案.开发人员可利用大量SimpleLink无线MCU BoosterPack™插件模块和SimpleLink软件SDK插件,向应用无缝添加无线连接和云集成,从而构建支持物联网且可互操作的智能工业网关应用.
    • SimpleLink MCU SDK Driver中的代码可以在所有SimpleLink MCU中100%可移植,所以即使需求改变,改用新的SimpleLink MCU也并不意味着必须重新开始.

开箱即用体验

  • 这里的原教程是在TI Resource Explorer里面,它的具体的路径是Software > SimpleLink MSP432E4-SDK-3.30.00.22> SimpleLink Academy-3.30.01.00 > LaunchPad Out of Box Experience > MSP432E401Y LaunchPad Out of Box Experience
  • 这里开箱使用体验是在Exosite loT 云平台进行的,所以要先在该平台上注册一个帐号.但是现在看来,还要付费才可以使用,所以就没有试用了.
  • Pin脚定义图:
    msp432e401y_pinout.png

CC3120 BoosterPack插件模块

-CC3100 & CC3200 UniFlash

  • SimpleLink Academy/Overview的页面里找到了这个CC3120 BoosterPack 开箱体箱示例链接,它的真实在路径是CC3120 BoosterPack Out of Box Experience
  • SimpleLink SDK Wi-Fi Plugin Documentation Overview,这里选择的TIREX的绝对路径是/Software/SimpleLink SDK Plugins/Connectivity/SimpleLinkSDKWiFiPlugin(2.40.00.22)/Examples/Development Tools/MSP432E401Y LaunchPad/Demos/ethernet_wifi_tcp_echo/项目,还具体细分的不同操作系统,不同的工具平台:
    • FreeRTOS
      • CCS Compiler
      • GCC Compiler
      • IAR Compiler
    • TI-RTOS
      • CCS Compiler
      • GCC Compiler
      • IAR Compiler
  • 如果在网页中打开的上述工程,可以使用右角Import导入到CCS Cloud中,如果在桌面版的CCS IDE中的Resource Explorer上述工程可以直接导入到本地的workerspace目录里.
    tre-example-import.png

TI 云工具平台

  • 通过浏览器打开https://dev.ti.com会看到一个左边栏加中间一个九宫的格的工具列表.从上到下,从左到右,依次是Resource Explorer,CCS Cloud,SysConfig,UniFlash,GUI Composer Gallery,BoosterPack Checker,PinMux,E2E Community.CCS Cloud是一个网页版CCS IDE它可以从Resource Explorer导入示例工程,可以查看与编辑代码,但是不可以在线编译生成目标文件.
    msp-432-clount-device-detected.png

  • CCS Cloud
    ![CCS Cloud - default.png](/img/ti/CCS Cloud - default.png)

  • 左侧边栏会提示安装TI CLOUD AGENT会提升使用体验.这里是使用Firefox浏览器,它会在浏览里安装TICloudAgent Bridge插件.如果是使用Google Chrome浏览器会提示无法安装浏览器插件,因为墙的原因.安装完插件还会提示下载安装TI Cloud Agent Application.安装完成Agent之后,刷新页面,侧边栏会提示安装一些必要的设备驱动,用于Device detected.如果它检测到支持的设备在线,会在侧边栏里显示设备的ID号,Serial号,以及相应的Get Started!导航链接,这里的连接MSP-EXP432E401Y会出现对应的GUI Composer Gallery,Resource Expolrer,SimpleLink Acdemy三个链接.

  • 下面是使用在线版的UniFlash.
    ![exp432-E401Y UniFlash.png](/imgs/ti/exp432-E401Y UniFlash.png)

    • 打开Resource Expolrer > /Development/Kits and Boards/MSP432E401Y LaunchPad会有该设备的详细描述,与《用户手册》等官方资料.
    • 打开SimpleLink Acdemy > /Software/SimpleLink MSP432E4 SDK (3.30.00.22)/SimpleLink Academy (3.30.01.00)/Overview会有进入最新的SDK的学院教程页面.

桌面版IDE安装(CCSv9)

安装

ccs920-install.png

安装 SDK

通过使用TI Resource Explorer安装

  • CCSv9首面板里Getting Started页里有Resource Explorer(Examples & Docs),New Proejct, Import Proejct三个快捷链接.这里选择打开Resources Explorer,打开会一直显示Starting TIREX ...,视本机的网速快慢而定,如果偶然打开它了,最好是把自己需要用到的SDK全部下载到本地,防止失联.
    ccs920-resource-expolrer.png

  • 打开可以设置 SDK 的下载路径,如下:
    ccsv9-res-settings.png
    ccs920-tre-plugin-install.png

  • 因为学习一种单片机的最好的方法是查看它官方的文档与SDK的示例,TI的官方文档与SDK示例非常丰富,除了线上的dev.ti.com可以在线查看之外,一般手动下载的SDK压缩包里,除了库文件之外还有文档与工具,这里是学习它最权威的资料.一个典型的SDK目录结构如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
~$ simplelink_msp432e4_sdk_3_30_00_22$ tree -L 2
.
├── changelog.html
├── docs
│   ├── Documentation_Overview.html
│   ├── driverlib
│   ├── grlib
│   ├── mbedtls
│   ├── ndk
│   ├── ns
│   ├── simplelink_mcu_sdk
│   ├── tidrivers
│   ├── tiposix
│   ├── tirtos
│   ├── tiutils
│   └── usblib
├── examples
│   ├── nortos
│   └── rtos
├── imports.mak.windows
├── kernel
│   ├── freertos
│   ├── makefile
│   ├── nortos
│   └── tirtos
├── license_simplelink_msp432e4_sdk_3_30_00_22.txt
├── manifest_simplelink_msp432e4_sdk_3_30_00_22.html
├── release_notes_simplelink_msp432e4_sdk_3_30_00_22.html
├── source
│   ├── third_party
│   └── ti
└── tools
├── examples
├── iar
├── image_reformer
└── usblib

手动安装

  • 因为Resource Explorer在国内访问很不稳定,经常打不开,所以打开时可以先把这些文件下载下来,或者打包起来移到其它电脑的新系统里安装.只要在Window > Preferences > Code Composer Studio > Products添加要SDK的路径,就可以把相应的SDK文件安装上来了.

导入官方CCS示例工程

  • 这里使用一个官方Demo来测试一下板子组件是否运行正常,ethernet_wifi_tcp_echo它位于TIREX的目录下/Software/SimpleLink SDK Plugins/Connectivity/SimpleLink SDK WiFi Plugin (2.40.00.22)/Examples/Development Tools/MSP432E401Y LaunchPad/Demos/ethernet_wifi_tcp_echo/,很显然这里还需要安装SimpleLink SDK WiFi Plugin-2.40.00.22版本的SDK我这里选择是FreeRTOS,所以还要指定 FreeRTOS的目录.

设置FreeRTOS目录

  • 如果工程中有用到FreeRTOS的但是又没有指定它的路径,会报下面的错误.
    1
    2
    3
    4
    **** Build Finished ****
    Buildfile generation error occurred..
    Required variable 'FREERTOS_INSTALL_DIR'cannot be resolved or is pointing to a non-existent location.
    See 'Preferences > CCS > Build > Variables' page to define this variable before building this project.
    ccs920-prj-build-var-settings.png

设置工程参数

  • SysConfig
  • Syscfg 配置或查看,应该是属于类似STM32CubeMX的工具,如果使用Syscfg配置,就会根据配置的参数,在工程目录下自动生成Debug/syscfg/{Board.h,Board.c文件,相当于把图行里配置参数自动生成代码,一般SimpleLink SDK的示例工程都会带有Syscfg支持,如果自建工程没有话,可以在工程目录新建一个后缀名为.syscfg的文件,打开工程的Properties > Build > Sysconfig > Summary of falgs set: 加入下面设置:
1
2
# 注意,SDK_DIR 是SDK的根目录绝对路径.
-s "<SDK_DIR>/simplelink_msp432e4_sdk_4_10_00_13/.metadata/product.json" -o "syscfg" --compiler ccs
  • ,IDE识别后,会调用系统内的SysConfg来向导编辑与配置.如果不喜欢此工具,也可以手动生成这样的板子定义文件.
    ccsv9-syscfg.png

  • 导入ethernet_wifi_tcp_echo到本地CCS里后,要详细阅读ethernet_wifi_tcp_echo_MSP_EXP432E401Y_freertos_ccs/README.html文档.下面是按照文档提示,需要修改network_if.h里的SSIDSECURITY_KEY,也就是说要把它配置成可以连接到你周围的WIFI.

  • 这下面是在工程里main_freertos.c添加一段测试FreeRTOS创建多任务的示例.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    const char *pcTextForTask1 = "Task 1 is running\r\n";
    const char *pcTextForTask2 = "Task 2 is running\r\n";
    static void vTaskFunction(void *pvParameters)
    {
    char *pcTaskName;

    pcTaskName = (char*)pvParameters;
    for(;;)
    {
    printf("%s",pcTaskName);
    vTaskDelay(250);
    }
    }

    int main(void)
    {
    /* 此处代码省略 */
    ......
    /* 创建测试任务*/
    xTaskCreate(vTaskFunction,
    "Task 1",
    1000,
    (void*)pcTextForTask1,
    1,
    NULL);
    xTaskCreate(vTaskFunction,
    "Task 2",
    1000,
    (void*)pcTextForTask2,
    1,
    NULL);
    vTaskStartScheduler();
    return (0);
    }

  • 上述修改保存后,接上板子,按F11直接Debug运行,如果无错,就会在 IDE下方的Console窗口看到不断交错输出Task 2 is running,Task 1 is running信息.

  • 再打开另一个终端使用minicom -o -b 115200 -D /dev/ttyACM0打开会看到如下信息:

1
2
3
4
5
[WLAN EVENT] STA Connected to the AP: lcy-y1s-2.4G , BSSID: 20:76:93:0:ac:8
[NETAPP EVENT] IP acquired by the device
WiFi Interface has connected to lcy-y1s-2.4G
WiFi Interface IP Address is 192.168.1.115
WiFi Interface connected and started
  • 按文档提示,用 putty打开一个telnet 连接到192.168.1.115:1000端口.就会显示如下:
    1
    2
    WiFi: Creating thread clientfd = 1
    wifi0: start clientfd = 0x1
  • 在TI驱动程序库中,提供了两种编程模型来支持用户的程序开发:直接寄存器访问(DRA)模型和软件驱动程序(SD)模型.

CC3100BOOST无线WIFI模块

  • 若要对CC31XXBOOST 板进行编程,必须具备CC31XXEMUBOOST板,这里使用USB-to-TTL的板子来代替与它通信.原来看文档以为一定要使用FTDI的芯片,买了一块FT232H进行连接,不知道为什么不稳定,经常No ACK.手上还有一块CP2102的芯片用的很好.CC3100芯片在后续的Uniflash v4不提供支持的,最新支持的版本的是uniflash v3.4.1.00012,同时只支持i386平台,经测试,安装在Debian 7 (i386)能正常使用.
1
2
3
4
5
6
7
8
9
CP2102       CC3100BOOST
TX -> RX
RX <---- TX
GND ----- GND
nHIB # 这里没用控制它,手动按SW3来触发
nRST # 这里没用控制它,手动按SW2来触发

# 这里不使用CP2102来对CC3100BOOST供电,把CC3100BOOST上的J8(1-2)短接,使用USB为模块供电.

Format格式化SPI闪存

  • Serial Flash型号Micron公司的25PX80VP是8Mb容量也就是1M字节.Uniflashv3 先选择Format格式化,下拉选择1M.中间有提示--- please restart the device ---,此时可以按下模块上的SW3或者是SW2按键一秒,按手册上来说,这本应是用一个GPIO来自动触发它的.

查看文件系统

  • Format完成之后,选择List Files System,会在下方的Debug Console里看到类似如下:.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    [07:12:41] INFO: setting break signal
    [07:12:41] INFO: --- please restart the device --- # 要按SW2重启才能继续进行.
    [07:12:43] INFO: connection succeeded
    [07:12:43] INFO: getting storage list
    [07:12:43] INFO: > Executing Operation: Init
    [07:12:43] INFO: reading version info
    [07:12:43] INFO: DEVICE CC3100 ES1.32
    [07:12:43] INFO: reading version info
    [07:12:45] INFO: > Executing Operation: ListFileSystem
    [07:12:45] INFO: extracting file system information...
    [07:12:45] INFO: Serial Flash block size: 4096 bytes
    [07:12:45] INFO: Serial Flash capacity: 256 blocks

    [07:12:45] INFO: file start size fail total size filename
    [07:12:45] INFO: index block [BLKs] safe [BLKs]
    [07:12:45] INFO: ----------------------------------------------------------------------------
    [07:12:45] INFO: N/A 0 5 N/A 5 FATFS
    [07:12:45] INFO:


    [07:12:45] INFO: Flash usage
    [07:12:45] INFO: -------------------------
    [07:12:45] INFO: used space: 5 blocks
    [07:12:45] INFO: free space: 251 blocks
    [07:12:45] INFO: memory hole: [5-255]
    [07:12:45] INFO: > Executing Operation: Disconnect
    [07:12:46] Operation ListFileSystem returned.

uniflashv3-uart-3100.png

烧入Service Pack Programming

  • 这里的Service Pack Programming来自于CC3100SDK,现在最新(后面可能不更新了)SDK版本的1.3.0,ServicePack最新是1.0.1.14-2.12.2.8 ,了解更多信息可以查看SDK内的各种文档说明.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
07:16:07] INFO: --- please restart the device ---
[07:16:09] INFO: connection succeeded
[07:16:09] INFO: getting storage list
[07:16:09] INFO: > Executing Operation: ServicePackProgramming
[07:16:09] INFO: Path to the service pack file: /home/lcy/servicepack_1.0.1.14-2.12.2.8.bin
[07:16:09] INFO: reading version info
[07:16:09] INFO: CC3100Z Device detected.
[07:16:09] INFO: NWP/MAC/PHY Version from Service Pack:
[07:16:09] INFO: NWP version: 0.0.0.0
[07:16:09] INFO: MAC version: 0.0.0.0
[07:16:09] INFO: PHY version: 0.0.0.0
[07:16:09] INFO: reading version info
[07:16:09] INFO: DEVICE CC3100 ES1.32
[07:16:09] INFO: reading version info
[07:16:11] INFO: downloading NWP CODE
[07:16:11] INFO: Erase storage FLASH
[07:16:11] INFO: erase storage succeeded
[07:16:11] INFO: erase storage completed
[07:16:12] INFO: Verifying Data...
[07:16:12] INFO:

Verification OK
[07:16:13] INFO: Downloading file "/sys/servicepack.ucf" with size 38160
[07:16:18] INFO:

New Token is 0x0
[07:16:18] INFO: Download complete
[07:16:18] INFO: > Executing Operation: Disconnect
[07:16:18] Operation ServicePackProgramming returned.

// 再用 List File System 查看文件系统.

[07:22:37] INFO: --- please restart the device ---
[07:22:39] INFO: connection succeeded
[07:22:39] INFO: getting storage list
[07:22:39] INFO: > Executing Operation: Init
[07:22:39] INFO: reading version info
[07:22:39] INFO: DEVICE CC3100 ES1.32
[07:22:39] INFO: reading version info
[07:22:41] INFO: > Executing Operation: ListFileSystem
[07:22:41] INFO: extracting file system information...
[07:22:41] INFO: Serial Flash block size: 4096 bytes
[07:22:41] INFO: Serial Flash capacity: 256 blocks

[07:22:41] INFO: file start size fail total size filename
[07:22:41] INFO: index block [BLKs] safe [BLKs]
[07:22:41] INFO: ----------------------------------------------------------------------------
[07:22:41] INFO: N/A 0 5 N/A 5 FATFS
[07:22:41] INFO: 4 5 66 no 66 /sys/servicepack.ucf
[07:22:41] INFO:


[07:22:41] INFO: Flash usage
[07:22:41] INFO: -------------------------
[07:22:41] INFO: used space: 71 blocks
[07:22:41] INFO: free space: 185 blocks
[07:22:41] INFO: memory hole: [71-255]
[07:22:41] INFO: > Executing Operation: Disconnect
[07:22:41] Operation ListFileSystem returned.

配置CC31xx/CC32xx Config Groups

  • 这是配置模块的功能,功能比较多(Device Role,Station,AP,P2P,Profiles,HTTP Server,DHCP Server,mDNS Client,Smart Config),根据自己用途去配置.这里把设备角色(Device Role)选择成Station模式,勾选上Update.勾选上Update后,再打开主菜单Operation>Program就会烧写一个/sys/mode.cfg文件,
    uniflashv3-uart-3100-DeviceRole.png
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
[07:32:39] Begin Program operation.
[07:32:40] INFO: > Executing Operation: Connect
[07:32:42] WARNING: flush succeeded
[07:32:42] INFO: setting break signal
[07:32:42] INFO: --- please restart the device ---
[07:32:48] INFO: connection succeeded
[07:32:48] INFO: getting storage list
[07:32:48] INFO: > Executing Operation: Init
[07:32:48] INFO: reading version info
[07:32:48] INFO: DEVICE CC3100 ES1.32
[07:32:48] INFO: reading version info
[07:32:50] INFO: > Executing Operation: Program
[07:32:50] INFO: > File name: /sys/mcuimg.bin, Update: false, Erase: false
[07:32:50] INFO: > File name: /cert/ca.pem, Update: false, Erase: false
[07:32:50] INFO: > File name: /cert/client.pem, Update: false, Erase: false
[07:32:50] INFO: > File name: /cert/private.key, Update: false, Erase: false
[07:32:50] INFO: > File name: /sys/macadd.bin, Update: false, Erase: true
[07:32:50] INFO: > Erase File: /sys/macadd.bin
[07:32:50] INFO: erasing file "/sys/macadd.bin"
[07:32:50] INFO: deleting file "/sys/macadd.bin"
[07:32:50] INFO: erase file completed
[07:32:50] INFO: > File name: /sys/mode.cfg, Update: true, Erase: false
[07:32:50] INFO: > Size of file = 80
[07:32:50] INFO: > Update File: /sys/mode.cfg
[07:32:50] INFO: Downloading file "/sys/mode.cfg" with size 80
[07:32:50] INFO:

New Token is 0x0
[07:32:50] INFO: Download complete
[07:32:50] INFO: Verifying Data...
[07:32:50] INFO: get file
[07:32:50] INFO: Done. Reading 80 bytes
[07:32:50] INFO:

Verification OK
[07:32:51] INFO: > Updated Token value: 0x0
[07:32:51] INFO: > File name: /sys/ipcfg.ini, Update: false, Erase: false
[07:32:51] INFO: > File name: /sys/ap.cfg, Update: false, Erase: false
[07:32:51] INFO: > File name: /sys/devname.cfg, Update: false, Erase: false
[07:32:51] INFO: > File name: /sys/mdns.cfg, Update: false, Erase: false
[07:32:51] INFO: > File name: /sys/dhcpsrv.cfg, Update: false, Erase: false
[07:32:51] INFO: > File name: /sys/httpsrv.cfg, Update: false, Erase: false
[07:32:51] INFO: > File name: /sys/pref.net, Update: false, Erase: false
[07:32:51] INFO: > File name: /sys/smartconfigkeys.cfg, Update: false, Erase: false
[07:32:51] INFO: > File name: /sys/stacfg.ini, Update: false, Erase: false
[07:32:51] INFO: > File name: /sys/p2p.cfg, Update: false, Erase: false
[07:32:51] INFO: > File name: /sys/pmcfg.ini, Update: false, Erase: false
[07:32:51] INFO: > Executing Operation: Disconnect
[07:32:51] Operation Program returned.
// 再次查看
[07:33:07] Begin ListFileSystem operation.
[07:33:08] INFO: > Executing Operation: Connect
[07:33:10] WARNING: flush succeeded
[07:33:10] INFO: setting break signal
[07:33:10] INFO: --- please restart the device ---
[07:33:16] INFO: connection succeeded
[07:33:16] INFO: getting storage list
[07:33:16] INFO: > Executing Operation: Init
[07:33:16] INFO: reading version info
[07:33:16] INFO: DEVICE CC3100 ES1.32
[07:33:16] INFO: reading version info
[07:33:18] INFO: > Executing Operation: ListFileSystem
[07:33:18] INFO: extracting file system information...
[07:33:19] INFO: Serial Flash block size: 4096 bytes
[07:33:19] INFO: Serial Flash capacity: 256 blocks

[07:33:19] INFO: file start size fail total size filename
[07:33:19] INFO: index block [BLKs] safe [BLKs]
[07:33:19] INFO: ----------------------------------------------------------------------------
[07:33:19] INFO: N/A 0 5 N/A 5 FATFS
[07:33:19] INFO: 4 5 66 no 66 /sys/servicepack.ucf
[07:33:19] INFO: 6 71 1 yes 2 /sys/mode.cfg # 多了一个配置文件.
[07:33:19] INFO:


[07:33:19] INFO: Flash usage
[07:33:19] INFO: -------------------------
[07:33:19] INFO: used space: 73 blocks
[07:33:19] INFO: free space: 183 blocks
[07:33:19] INFO: memory hole: [73-255]
[07:33:19] INFO: > Executing Operation: Disconnect
[07:33:19] Operation ListFileSystem returned.

CC3120BOOST无线Wifi模块

  • CC3120 BoosterPack™插件模块(CC3120BOOST)是一块可轻松连接到TI Launchpad套件的电路板(为MSP-EXP432P401R提供的软件示例);从而能够进行快速软件开发.CC3120BOOST可插入到高级仿真BoosterPack(CC31xxEMUBOOST),还可连接到使用SimpleLink Studio仿真MCU的PC.最后,此套件还可通过适配器板连接到除TI Launchpad套件之外的任何低成本,低功耗MCU平台.
  • 根据simplelink_sdk_wifi_plugin_2_40_00_22文档说明,支持IPv4 and IPv6 TCP/IP Stack,但是在实际应用中,发现无法连接到IPv6 Socket,但是可以获取DHCPv6的地址.查看了SDK源码发现了API的分层调用SlNetSock_connect > SlNetIfWifi_connect > sl_Connect,打开源码发现如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
~$ cat simplelink_sdk_wifi_plugin_2_40_00_22/source/ti/drivers/net/wifi/sl_socket.h
[....]
/*!
\brief Initiate a connection on a socket

Function connects the socket referred to by the socket
descriptor sd, to the address specified by addr. The addrlen
argument specifies the size of addr. The format of the
address in addr is determined by the address space of the
socket. If it is of type SOCK_DGRAM, this call specifies the
peer with which the socket is to be associated; this address
is that to which datagrams are to be sent, and the only
address from which datagrams are to be received. If the
socket is of type SOCK_STREAM, this call attempts to make a
connection to another socket. The other socket is specified
by address, which is an address in the communications space
of the socket.


\param[in] sd Socket descriptor (handle)
\param[in] addr Specifies the destination addr\n
sockaddr:\n - code for the
address format. On this version
only AF_INET is supported.\n -
socket address, the length
depends on the code format

\param[in] addrlen Contains the size of the structure pointed
to by addr

\return On success, a socket handle.\n
On a non-blocking connect a possible negative value is SL_EALREADY.
On failure, negative value.\n
SL_POOL_IS_EMPTY may be return in case there are no resources in the system
In this case try again later or increase MAX_CONCURRENT_ACTIONS

\sa sl_Socket
\note belongs to \ref client_side
\warning
*/
#if _SL_INCLUDE_FUNC(sl_Connect)
_i16 sl_Connect(_i16 sd,
const SlSockAddr_t *addr,
_i16 addrlen);
#endif
[....]

下载第一个测试工程Network_termial

  • 下面是是使用Code Composer Stduio导入simplelink_sdk_wifi_plugin_2_40_00_22/examples/rtos/MSP_EXP432E401Y/demos/network_terminal,调试运行如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    ~$ sudo minicom -o -b 115200 -D /dev/ttyACM0

    Welcome to minicom 2.7.1

    OPTIONS: I18n
    Compiled on May 6 2018, 08:02:47.
    Port /dev/ttyACM0, 15:41:53

    Press CTRL-A Z for help on special keys

    user:
    ============================================
    Network Terminal Example Ver: 1.0.1.0
    ============================================

    CHIP: 0x30000000
    MAC: 2.0.0.0
    PHY: 2.2.0.6
    NWP: 3.10.0.5
    ROM: 0
    HOST: 3.0.1.46
    MAC address: f0:c7:7f:18:1b:72

    ============================================

    ================================================================================
    Available commands:

    help scan setpolicy wlanconnect
    wlan_ap_start wlan_ap_stop wlandisconnect connected_stations
    ping send recv createfilter
    enablefilter disablefilter deletefilter enablewowlan
    mdnsadvertise mdnsquery radiotool p2pstart
    p2pstop SoftRoamingEnable SoftRoamingDisable AntSelectionEnable
    AntSelectionDisable CoexEnable CoexDisable Countrycode
    clear

    ================================================================================
    user:

  • 如上面所示,通过连接UART会得到shell接口,比如运行:scan -n 20会扫描到周围的AP,wlan_ap_start可以把模块切换成AP模式运行.具体支持的命令详细内容可以查看该工程内的README.html文件.

Uniflash v5

  • CC3120相对于CC3100主要是增加了securitylower power的性能,CC3120R的模块如此,要对CC3X20BOOST板进行编程,必须具备CC31XXEMUBOOST板.它也可以用通过UART接口对它进行ServerPack更新.按照这里CC3120: Only UART Interface between CC3120 and MSP432E401Y指导是可以用MSP432E401Y板载的XDS110去烧写,接线方式如下:
1
2
3
4
5
6
7
LauchPad  XDS110 (J101)            CC3120BOOST
GND -------- GND
3V3 -------- 3V3
5V -------- 5V
TX -------> RX
RX <------- TX
RST -------- nHIB
  • 上述连接方式,成功连接过一次,后面测试时就无法连接成功一直超时,这个还不知道为什么.后面是使用一个CP210x USB-UART去连接的,使用模块上的USB PWR对模块独立供电,模块上的J7(1-2)短接.CP210x与要模块接就只有三线:TX-RX,TX-RX,GND-GND.同时使用UniFlash.desktop打开的图形配置界面,无法指定端口.下面是使用dslite.sh脚本去运行的.

  • 如下图所示,SLImageCreator是用python2写的,并使用PyInstaller把它编译成本的执行文件,从而避免了源码暴露.但是可以使用PyInstaller的工具pyi-archive_viewer把它解压还原回来.下面尝试把它的SLImageCreator内容解压到本地文件SLImageCreator.py.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    ~$ pyi-archive_viewer ../SLImageCreator
    pos, length, uncompressed, iscompressed, type, name
    [(0, 2410208, 2410208, 0, 'z', 'out00-PYZ.pyz'),
    (2410208, 172, 237, 1, 'm', 'struct'),
    (2410380, 1169, 2788, 1, 'm', 'pyimod01_os_path'),
    (2411549, 3950, 11334, 1, 'm', 'pyimod02_archive'),
    (2415499, 5629, 18438, 1, 'm', 'pyimod03_importers'),
    (2421128, 2453, 6604, 1, 's', 'pyiboot01_bootstrap'),
    (2423581, 437, 923, 1, 's', 'pyi_rth_pkgres'),
    (2424018, 20959, 119615, 1, 's', 'SLImageCreator')]
    ? X
    extract name? SLImageCreator # 选取 SLImageCreator
    to filename? SLImageCreator.py
    ? Ctrl+D # 在当前目录下会有SLImageCreator.py文件.
  • uniflash_5.0.0/simplelink/imagecreator/bin里的libpython2.7.so.1.0是引用系统库,再链接到本目录的.但运行是出现下面的错误.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
ti/uniflash_5.0.0/simplelink/imagecreator$ tree bin/
bin/
├── BuildProgrammingImage
├── BuildProgrammingImage.g2
├── Crypto.Cipher._AES.x86_64-linux-gnu.so
├── Crypto.Cipher._DES3.x86_64-linux-gnu.so
├── Crypto.Cipher._DES.x86_64-linux-gnu.so
├── Crypto.Hash._SHA256.x86_64-linux-gnu.so
├── Crypto.Util._counter.x86_64-linux-gnu.so
├── Crypto.Util.strxor.x86_64-linux-gnu.so
├── libftd2xx.so
├── libpython2.7.so.1.0 > /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
├── libusb-1.0.so
├── SLImageCreator
└── xds110reset

0 directories, 13 files

~$ uniflash_5.0.0/simplelink/imagecreator/bin$ ./SLImageCreator
[....]
ImportError: cannot import name RAND_egd
SLImageCreator returned -1
  • 获取信息,下面的命令参考来自swru469g.pdf文档.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    uniflash_5.0.0$ ./dslite.sh --mode cc31xx device info --json --port /dev/ttyUSB0
    Executing the following command:
    > ./SLImageCreator device info --json --port /dev/ttyUSB0

    For more details and examples, please refer to the UniFlash Quick Start guide.

    Config file (cfg.json) doesn't exist, using defaults
    INFO:root:COM PORT /dev/ttyUSB0
    INFO:slbootloader.slbootloader:Connecting to device
    INFO:slbootloader.slbootloader:--- Please power off the device ---
    Press ENTER to continue
    INFO:slbootloader.slbootloader:Power off
    INFO:slbootloader.slbootloader:Set break signal
    INFO:slbootloader.slbootloader:--- Please power on the device ---
    INFO:slbootloader.slbootloader:Power on
    INFO:slbootloader.slbootloader:Clear break signal
    INFO:slbootloader.slbootloader:Connection succeeded
    INFO:slbootloader.slbootloader:Received storage list
    {
    "mac_address": "f0:c7:7f:18:1b:72",
    "hw_ver": 48,
    "secure": true,
    "device_type": "CC3120",
    "prog_mac_address": null
    }

GUI图形配置

1
uniflash_5.0.0$ ./dslite.sh --mode cc31xx gui_cfg --port /dev/ttyUSB0
  • 成功后转为后台进程,并用系统默认的浏览器打开一个网页,如下:
    uniflash-msp432e4-cc3120r-selected.png
  • 创建一个工程文件,如下:
    uniflash-msp432e4-cc3120r-new-project.png
  • 连接模块,注意:点击connect后,要手动按一下模块上的SW3或SW2复位它,才能连接到.
    uniflashv5-cc3120r-connect.png

Simple配置

  • 如图所示,这Uniflash v5Uniflash v3的界面有很大不同,这个界面只有两个选项Start Role (Station,P2P,Access Point)Service Pack File Name,
    这里的Service Pack File Name文件来自于simplelink_sdk_wifi_plugin_2_40_00_22/tools/cc31xx_tools/servicepack-cc3x20/sp_3.10.0.5_2.0.0.0_2.2.0.6.bin,关于Service Pack内容详情,可以查看SDK内的文档.

Anvanced配置

Genernal
  • 注意,工程类型选成Development模式是不能随意更改MAC Address的,会报错SL_ERROR_FS_DEVELOPMENT_BOARD_WRONG_MAC.
System Setting
Files
  • 使用Online User Files查看模块内的文件系统内容,如下:
    uniflashv5-cc3120r-online-user-files.png

SysConfig

简介

  • SysConfig是一个为了帮助简单配置与加快软件开发图形工具.它是基于node.js平台开发,数据定义结构是基于JSON格式.STM32旗下对应类似工具叫STM32CubeMX.

配置

  • 它是一个独立工具安装包,可以把它安装在$CCS_ROOT/ccs/utils/下面.也可以安装到其它位置,创建一个链接到$CCS_ROOT/ccs/utils/sysconfCCS IDE调用,工程根目录下的.syscfg类型的文件会调用sysconfigCCS IDE打开编辑,如果文件缺少必要的定义或者格式错误,SysConfig会报错,并向导用户新建一个可用的配置.编译时,会先调用$CCS_ROOT/ccs/utils/sysconfig/sysconfig_cli.sh"解析.syscfg内容,会在(Debug|Release)目录创建syscfg目录,会自动的生成ti_drivers_config.c,ti_drivers_config.h,ti_net_config.c这些个文件.它的图形编辑界面如下:
    sysconfig_msp432e401y.png

  • 使用文本编辑器打开工程中的.syscfg格式如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    cat mqttclient_wifi.syscfg
    /**
    * These arguments were used when this file was generated. They will be automatically applied on subsequent loads
    * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments.
    * @cliArgs --board "/ti/boards/MSP_EXP432E401Y" --product "simplelink_msp432e4_sdk@4.20.00.12"
    * @versions {"data":"2020021217","timestamp":"2020021217","tool":"1.4.0+1234","templates":"2020021217"}
    */
    const CC3120BOOST = scripting.addHardware("/ti/boards/boosterpacks/CC3120BOOST", "boosterpack2");

    /**
    * Import the modules used in this configuration.
    */
    const Display = scripting.addModule("/ti/display/Display", {}, false);
    const Display1 = Display.addInstance();
    const GPIO = scripting.addModule("/ti/drivers/GPIO");
    [...省略多行..]
    const SlNet = scripting.addModule("/ti/net/SlNet", {}, false);
    const SlNet1 = SlNet.addInstance();

    /**
    * Write custom configuration values to the imported modules.
    */
    Display1.$hardware = system.deviceData.board.components.XDS110UART;
    Display1.$name = "UART0";
    Display1.uart.$name = "MSP_EXP432E401Y_UART0";
    Display1.uart.uart.$name = "MyUART1";

    GPIO3.$name = "MSP_EXP432E401Y_SDSPI_CS";
    GPIO3.mode = "Output";
    GPIO3.outputStrength = "High";
    GPIO3.initialOutputState = "High";
    GPIO3.gpioPin.$assign = "boosterpack.8";

    GPIO4.$hardware = CC3120BOOST.components.CS;
    GPIO4.$name = "MSP_EXP432E401Y_CS_pin";
    GPIO4.initialOutputState = "High";
    GPIO4.outputStrength = "High";

    I2C1.$name = "MSP_EXP432E401Y_I2C2";
    I2C1.i2c.$name = "MyI2C1";
    I2C1.i2c.$assign = "I2C2";
    I2C1.i2c.sdaPin.$assign = "boosterpack2.10";
    I2C1.i2c.sclPin.$assign = "boosterpack2.9";

    [....省略多行...]

  • 在最新工具版本中(1.4以上),.syscfg文件中必须要有@cliArgs --board "/ti/boards/MSP_EXP432E401Y",就是说必须要指定一个可用的--board参数,否则会无法打开并编辑它.再来看一下文件中的@cliArgs --board "/ti/boards/MSP_EXP432E401Y" --product "simplelink_msp432e4_sdk@4.20.00.12"这一行,它其实定义了这个Sysconfig文件的类型定义的来源及解析方式.simplelink_msp432e4_sdk@4.20.00.12是对应工程引用的SDK的版本,打开SDK的源码路径如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 注意SDK名与版本号.
~$ tree -L 2 simplelink_msp432e4_sdk_4_20_00_12/source/ti/boards/.meta
simplelink_msp432e4_sdk_4_20_00_12/source/ti/boards/.meta
├── boosterpacks
│   ├── BOOSTXL-BASSENSORS.syscfg.json
│   ├── BOOSTXL-SHARP128.syscfg.json
│   ├── BP-BASSENSORSMKII.syscfg.json
│   ├── CC3200AUDBOOST.syscfg.json
│   ├── LPSTK-SENSORS.syscfg.json
│   └── MSP430BOOST-SHARP96.syscfg.json
├── components
│   ├── analogInput.json
│   ├── button.json
│   ├── digitalInput.json
│   ├── digitalOutput.json
│   ├── i2c.json
│   ├── led_dimmable.json
│   ├── led.json
│   ├── spi25xFlash.json
│   ├── spiBus.json
│   ├── spiSelect.json
│   ├── uart.json
│   ├── usb.json
│   └── xds110Uart.json
├── MSP432E411Y_BGAEVM.syscfg.json
└── MSP_EXP432E401Y.syscfg.json

2 directories, 21 files

  • 如上所示,SysConfig工具定义的出厂资源描述文件是位于$SDK/source/ti/boards/.meta下,而且它是有分层定义设计的,MSP_EXP432E401Y.syscfg.json是板子定义.components是一些外设模块的定义.boosterpacks是一些可扩展组件的定义,它定义管脚与规格是支持MSP_EXP432E401Y扩展的.

自定义资源文件

  • 下面是参照了官方源码,在boosterpacks中定义了CC3120BOOST.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    cat boosterpacks/CC3120BOOST.syscfg.json

    /*
    * ======== CC3120BOOST.syscfg.json ========
    * 这里是对照MSP-EXP432E401Y Rev 1.0 BoosterPack II 管脚定义的. 对照 SWRU457A PDF文档
    * CC3120 SimpleLinkTM Wi-Fi ® BoosterPackTM Plug-InModule and IoT Solution
    * 排针顺序查看官方 MSP_EXP432E401Y_CC3120BOOST.syscfg.json里的BoosterPack Standard Header #2 部分
    */
    {
    "name": "CC3120BOOST",
    "displayName": "CC3120BOOST",
    "description": "CC3120BOOST Wifi BoosterPack II",
    "longDescription": "The [__CC3120BOOST__](https://www.ti.com/tool/CC3120BOOST) BoosterPack&trade; SimpleLink™ Wi-Fi® CC3120 wireless network processor BoosterPack™ plug-in module ",
    "headerType": "BoosterPack 40 pin",
    "components": {
    "CC3120BOOST_SPI": {
    "displayName": "CC3120BOOST SPI Bus",
    "description": "CC3120BOOST SPI bus",
    "longDescription": "CC3120BOOST SPI bus",
    "type": "SPI_BUS",
    "signals" : {
    /* PQ0: BoosterPack standard: SPI CLK */
    "SCLK" : {"type": "SPI_SCLK", "connection" : 7},
    /* PQ1: BoosterPack standard: SPI FSS */
    "SS" : {"type": "SPI_SS", "connection" : 12},
    /* PQ2: BoosterPack standard: SPI MOSI */
    "MOSI" : {"type": "SPI_MOSI", "connection" : 15},
    /* PQ3: BoosterPack standard: SPI MISO */
    "MISO" : {"type": "SPI_MISO", "connection" : 14}
    }
    },
    "CC3120BOOST_UART": {
    "definition": "/ti/boards/components/uart.json",
    "connections": {
    "RXD": 4, /* PP1 */
    "TXD": 3 /* PP0 */
    }
    },
    "IRQ": {
    "displayName": "IRQ",
    /* "definition": "/ti/boards/components/digitalInput.json",*/
    /* PM7 这里要注手册说明这里是OUT,对应于MSP432E401Y的管脚就是IN,所以这里是INPUT,下同. */
    "signals": {
    "INTERRUPT": {
    "type": "DIN",
    "settings": {
    "pull": "None"
    },
    "connection": 19
    }
    }
    },
    "CS": {
    "displayName": "CS",
    "definition": "/ti/boards/components/digitalOutput.json",
    /* PP5 */
    "connections": { "OUTPUT" : 18 }
    },
    "nHIB": {
    "displayName": "nHIB",
    "description": "nHIB power pin",
    "longDescription": "nHIB power pin",
    "definition": "/ti/boards/components/digitalOutput.json",
    /* *RX */
    "connections": { "OUTPUT" : 5 }
    },
    "nRESET": {
    "displayName": "nRESET",
    "definition": "/ti/boards/components/digitalOutput.json",
    /* RST */
    "connections": { "OUTPUT" : 16 }
    },
    "NWP_LOG_TX": {
    "displayName": "NWP_LOG_TX",
    "definition": "/ti/boards/components/digitalInput.json",
    /* PH0 */
    "connections": { "INPUT" : 34 },
    "settings": {
    "DIN": {
    "pull": "Pull Up",
    "interruptTrigger": "Raising Edge"
    }
    }
    },
    "WLAN_LOG_TX": {
    "displayName": "WLAN_LOG_TX",
    "definition": "/ti/boards/components/digitalInput.json",
    /* PH1 */
    "connections": { "INPUT" : 33 },
    "settings": {
    "DIN": {
    "pull": "Pull Up",
    "interruptTrigger": "Raising Edge"
    }
    }
    }
    }
    }
  • 在工程目录内的.syscfg文件里加上const CC3120BOOST = scripting.addHardware("/ti/boards/boosterpacks/CC3120BOOST","boosterpack2");这一行,打开SysConfig编辑界面如下:
    sysconfig_cc3120boost

  • 如上图所示,这里还自定义一个板子的定义,就是在/ti/boards/MSP_EXP432E401Y基础上删除了MICROUSB定义,命名为/ti/boards/MSP_EXP432E401Y_WITHOUT_USB,但是自定义的CC3120BOOST文件还是不能添加nRESET,nHIB这两个管脚,还是与板子的定义有冲突,这也可能是为什么官方不出一个boosterpacks/CC3120BOOST的组件.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"MICROUSB": {
"displayName": "USB Micro Connector",
"description": "USB Micro-A / -B Connector",
"definition": "/ti/boards/components/usb.json",
"connections": {
"DM": "93", /* PL7 */
"DP": "94", /* PL6 */
"ID": "95", /* PB0 */
"VBUS": "96", /* PB1 */
"EPEN": "127", /* PD6 */
"PFLT": "128", /* PD7 */
"CLK": "92", /* PB3 */
"D0": "81", /* PL0 */
"D1": "82", /* PL1 */
"D2": "83", /* PL2 */
"D3": "84", /* PL3 */
"D4": "85", /* PL4 */
"D5": "86", /* PL5 */
"D6": "106", /* PP5 */
"D7": "105", /* PP4 */
"DIR": "104", /* PP3 */
"NXT": "103", /* PP2 */
"STP": "91" /* PB2 */
}
}

CC2650 Module BoosterPack蓝牙模块

烧写蓝牙固件

  • Windows端可以使用SmartRF FlashProgrammer2来烧写,但是需要一根标准JTAG线,且要把MSP432E4 LaunchPad上的J101跳线TDI,TDO,TCK,TMS,RST去掉,只留GND,3V3这两根跳线,使用标准的10pin JTAG线从J102连接XDS-110 JTAG调试信号,具体操作如下图所示.
    msp432e4-smartrf-fp.jpg
    srf-fp2.jpg
  • Linux端使用UniFlash命令行来烧写,UniFlash本身是一个GUI烧写的工具,在选择目标设备有两种:On-chip是透过JTAG烧写,Serial是通过serial bootloader烧写.但是我在实际中用On-Chip烧写失败,用命令行烧写是显示成功的.接线与跳线部分还是上图那样,先要用UniFlash生成一个ccxml配置文件,具体如下图,点击Start后,按上方的download.ccxml保存到文件夹内.
    uniflash-msp432e4-cc2650f128.png
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
./dslite.sh -c ~/CC2650F128.ccxml --list-device-cmds
Executing the following command:
> /fulllpath/uniflash_5.0.0/deskdb/content/TICloudAgent/linux/ccs_base/DebugServer/bin/DSLite flash
-c ~/CC2650F128.ccxml --list-device-cmds

For more details and examples, please refer to the UniFlash Quick Start guide.

Cortex_M3_0: GEL Output: Memory Map Initialization Complete.
Cortex_M3_0: GEL Output:
-------------------------------------------------
COMMAND DESCRIPTION
PinReset Reset CC13xx/CC26xx device using reset pin.
MassErase Erase flash using mass erase (cannot be combined with
other operations). If the device debug interface is
locked, a target configuration file (.ccxml) with
argument custom="no" must be used.
-------------------------------------------------


./dslite.sh -c ~/CC2650F128.ccxml --post-flash-device-cmd PinReset -e -v
-f /fullpath/simplelink_sdk_ble_plugin_3_20_00_24/source/ti/snp/cc2650/simple_np_cc2650bp_uart_pm_sbl_2_02_01_18a_merge.hex
Executing the following command:
> /fullpath/uniflash_5.0.0/deskdb/content/TICloudAgent/linux/ccs_base/DebugServer/bin/DSLite flash -c ~/CC2650F128.ccxml
--post-flash-device-cmd PinReset -e -f
-v /fullpath/simplelink_sdk_ble_plugin_3_20_00_24/source/ti/snp/cc2650/simple_np_cc2650bp_uart_pm_sbl_2_02_01_18a_merge.hex

For more details and examples, please refer to the UniFlash Quick Start guide.

DSLite version 9.1.0.1655
Configuring Debugger (may take a few minutes on first launch)...
Initializing Register Database...
Initializing: IcePick_C
Executing Startup Scripts: IcePick_C
Initializing: CS_DAP_0
Executing Startup Scripts: CS_DAP_0
Initializing: Cortex_M3_0
Executing Startup Scripts: Cortex_M3_0
[.....]
sorting and removing duplicate symbols: 100%
Cortex_M3_0: GEL Output: Doing Pin Reset ...
  • 参数解释,具体更详细的参数说明,dslite.sh --help.
    • -c 指定ccxml配置文件的位置.
    • -e 详细显示模式
    • -f 烧写文件,这个固件文件可以在simplelink_sdk_ble_plugin_3_20_00_24官方的SDK里面.
    • -v 烧写完成后,校验烧写文件.

单片机入门

  • 时钟周期
    • 时钟周期也称为振荡周期,定义为时钟脉冲的倒数(时钟周期就是单片机外接晶振的倒数,例如12M的晶振,它的时间周期就是1/12us),是计算机中最基本的、最小的时间单位,也称节拍脉冲或T周期.在一个时钟周期内,CPU仅完成一个最基本的动作.对于某种单片机,若采用了1MHZ的时钟频率,则时钟周期为1us;1秒(s)等于1000毫秒(ms),等于1000000微秒(us).
    • 1秒(s) = 1000毫秒(ms)
      1毫秒(ms) = 1000微秒(us)
      1微秒(us) = 1000纳秒(ns)
      1纳秒(ns) = 1000皮秒(ps)
    • 在8051单片机中把一个时钟周期定义为一个节拍(用P表示),二个节拍定义为一个状态周期(用S表示).
  • 机器周期
    • 在计算机中,为了便于管理,常把一条指令的执行过程划分为若干个阶段,每一阶段完成一项工作.例如:取指令、读存储器、写存储器等,这每一项工作称为一个基本操作.完成一个基本操作所需要的时间称为机器周期.一般情况下,一个机器周期由若干个S周期(状态周期)组成.8051系列单片机的一个机器周期同6个S周期(状态周期)组成.前面已经说过一个时钟周期定义为一个节拍(用P表示),二个节拍定义为一个状态周期(用S表示),8051单片机的机器周期由6个状态周期组成,也就是说一个机器周期=6个状态周期=12个时钟周期.
  • 指令周期
    • 指令周期是执行一条指令所需要的时间,一般由若干个机器周期组成.指令不同,所需的机器周期数也不同.对于一些简单的的单字节指令,在取指令周期中,指令取出到指令寄存器后,立即译码执行,不再需要其它的机器周期.对于一些比较复杂的指令,例如:转移指令、乘法指令,则需要两个或者两个以上的机器周期.

字节顺序

  • 对于单一的字节(a byte),大部分处理器以相同的顺序处理位元(bit),因此单字节的存放方法和传输方式一般相同.

位序

  • 对于多字节数据,如整数(32位机中一般占4字节),在不同的处理器的存放方式主要有两种,以内存中0x0A0B0C0D的存放方式为例,分别有以下几种方式

  • 大端(Big-Endian)

    • 高位字节存储在低位内存地址,低位字节存储在高位内存地址
    • 如:地址方向是左低右高,数据以8bit为单位时:0x0A0B0C0D ,数据以16bit为单位时:0x0A0B0C0D
    • 网络传输一般采用大端序,也被称之为网络字节序,或网络序.IP协议中定义大端序为网络字节序.
    • 先传高位(MSB)的串行协议:
      • I2C
      • SPI
      • 摩尔斯电码
  • 小端(Little-Endian)

    • 低位字节存储在低位内存地址,高位字节存储在高位内存地址.
    • 如:地址方向是左低右高,数据以8bit为单位时:0x0D0C0B0A ,数据以16bit为单位时:0x0C0D0A0B.
    • 先传低位(LSB)的串行协议:
      • RS-232
      • RS-422
      • RS-485
      • USB
      • 以太网(虽然高字节先传,但每一字节内低位先传)
  • 最高有效位MSB(the most significant bit)

    • 指多字节序列中具有最大权重的字节.在大端序中,msb即指最左端的位.对于有符号二进制数,负数采用反码或补码形式,此时msb用来表示符号,msb为1表示负数,0表示正数.
  • 最低有效位LSB(the least significant bit)

    • 指多字节序列中最小权重的字节,是指一个二进制数字中的第0位(即最低位),权值为2^0,可以用它来检测数的奇偶性.与之相反的称之为最高有效位.在大端序中,lsb指最右边的位.
  • 不同编码的字节顺序标

  • 编码 表标(16进制)
    UTF-16(大端序) FE FF
    UTF-16(小端序) FF FE
    UTF-32(大端序) 00 00 FE FF
    UTF-32(小端序) FF FE 00 00

安装自己的Mosquitto服务器

  • 开启简单用户认证
    1
    2
    3
    4
    5
    // 创建文件,并添加一个用户.
    ~$ sudo mosquitto_passwd -c /etc/mosquitto/passwd sammy
    // 添加一个用户
    ~$ sudo mosquitto_passwd /etc/mosquitto/passwd user2

发行版安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
~$ sudo apt-get install mosquitto -y
~$ sudo cat > /etc/mosquitto/conf.d/default.conf<<EOF
autosave_interval 1800
persistence_file m2.db
connection_messages true
log_timestamp true

listener 1883
protocol mqtt

listener 8883
# protocol mqtt
# cafile /etc/mosquitto/certs/ca.crt
# keyfile /etc/mosquitto/certs/privkey.pem
# certfile /etc/mosquitto/certs/fullchain.pem

allow_anonymous false
password_file /etc/mosquitto/passwd
EOF
  • 配置websockets,需要用的证书文件.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
~# ln -svf /etc/letsencrypt/live/<domain>/privkey.pem  /etc/mosquitto/certs/privkey.pem
~# ln -svf /etc/letsencrypt/live/<domain>/fullchain.pem /etc/mosquitto/certs/fullchain.pem
~$ sudo cat > /etc/mosquitto/conf.d/websockets.conf<<EOF
listener 8080
protocol websockets

listener 8083
protocol websockets
# cafile /etc/mosquitto/certs/ca.crt
keyfile /etc/mosquitto/certs/privkey.pem
certfile /etc/mosquitto/certs/fullchain.pem
websockets_log_level 3
EOF

~$ ufw allow 8080/tcp
~$ ufw allow 8883/tcp
~$ systemctl restart mosquitto
mosquitto -c /etc/mosquitto/mosquitto.conf -v

客户端测试

1
~$ mosquitto_sub -h 192.168.1.178 -u test -P test123 -t /lcy/cc3120/sw2
1
~$ mosquitto_pub -h 192.168.1.178 -u test -P test123 -t /lcy/cc3120/sw2 -m 0

源码安装

  • 如果要尝试新功能,可以如下操作.
    1
    2
    3
    4
    5
    6
    ~$ apt-get install cmake libwebsockets-dev libwebsockets8 libc-ares-dev uthash-dev -y
    ~$ git clone https://github.com/eclipse/mosquitto
    ~$ mkdir -pv mosquitto/build && cd mosquitto/build
    ~$ cmake -DWITH_SRV=yes -DWITH_WEBSOCKETS=yes -DWITH_THREADING=yes -DWITH_TLS=yes -DWITH_DOCS=no ../
    ~$ make WITH_SRV=yes WITH_WEBSOCKETS=yes WITH_TLS=yes WITH_DOCS=no -j4
    ~$ make install/local

调试程序跑飞的原因

  • Saving program counter in Fault ISR

  • Debugging Hard Fault & Other Exceptions

  • Diagnosing Software Faults

  • MSP432E401Y SimpleLink™ User Guide.pdf

  • How to debug a HardFault on an ARM Cortex-M MCU

  • A Practical guide to ARM Cortex-M Exception Handling

  • 在开发嵌入式系统程序时,会碰到各种无理头的问题,最严重是它跑飞了,直接进了faultISR(void)里去while.不知道是那里出错了,首先在faultISR(void)函数开始处下一个断点,这里是通过目标map文件找到该文件的指针地址,进入到工程编译成后的Debug内,打开xxx.map,文本搜寻faultISR, 如下图所示,faultISR.text段内的0x00041724的位置.
    ccsv9_map_search_faultISR.png

  • CCS IDE的调试状态下,打开CCS Debug > Disassembly,输入0x00041724搜索,设置断点.再重新运行一次调试.
    ccsv9_debug_registers_disasmbly.png

  • 此时程序跑飞后停在了faultISR(void)处,再根据系统内在各种寄存器来定位出错的位置.
    ccsv9_debug_registers_core.png

  • 如上图所示,在CCS Debug > Registers > Core Registers内会看到PC,SP,LR三个寄存器名,关于寄存器的技术细节一定要参照《Cortex M3与M4权威指南》这本手册书去理解,还有MSP432E401Y SimpleLink™ User Guide.pdf的手册.这里如果显示LRvalue是一个非法无效的值如: 0xFFFFFFFE,就参考SP的值,把SP内的值输入到CCS Debug > Memory Browser内.
    ccsv9_debug_memory_browser.png

  • 如上图所示,从0x2003FFE0开始每4个字节对应一个寄存器,它们依次是R0,R1,R2,R3,R12,LR,PC,XPSR,先用工具链内的objdump把目标烧写文件反汇编到一个文本文件:

1
~$ ./ccs920/ccs/tools/compiler/ti-cgt-arm_18.12.6.LTS/bin/arm-none-eabi-objdump -d  xxxxxx.out  > ~/mps432-debug.txt
  • 如上图所示,按顺序查看到LR的值是0x00031A01,打开msp432-debug.txt,查找31a00,就会找到对应出错的函数位置.
EXC_RETURN Value Mode to Return To Stack to use
0xFFFFFFF1 Handler Mode MSP
0xFFFFFFF9 Thread Mode MSP
0xFFFFFFFD Thread Mode PSP
0xFFFFFFE1 Handler Mode (FPU Extended Frame) MSP
0xFFFFFFE9 Thread Mode (FPU Extended Frame) MSP
0xFFFFFFED Thread Mode (FPU Extended Frame) PSP

调试Bus Fault

ccsv9_debug_registers_nvic_fault_addr.png

  • 当中断在faultISR时,查看到NVIC里的寄存器的值如上图所示,这里NVIC Fault Status (NVIC_FAULT_STAT)的值是0x00008200这里代表它是一个Usage Fault,再展开显示详情Divide-by-Zero Usage Fault.,参考来源《Cortex M3与M4权威指南》第七章,7.4 “优先级定义”,表7.5, 还有参考MSP432E401Y SimpleLink™ User Guide.pdf,1.5小节《内存模型》表1-15 Memory Map.
  • 在这里NVIC Fault Address (NVIC_FAULT_ADDR)的值显示是0x2004.0014,参考表1-15 Memory Map它出错是在SRAM里.假如是:0x4003.100C表示出错在Timer1这个硬件地址,是一个Bus Fault,它的出错主要原因的:程序去访问了没有使能的外设,需要先使能,再访问.
  • objectdump出错.
    1
    2
    ~$ ./ccs920/ccs/tools/compiler/ti-cgt-arm_18.12.6.LTS/bin/arm-none-eabi-objdump --help
    arm-none-eabi-objdump: loadlocale.c:129: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed.
  • 设置LANG环境变量.export LANG=/usr/lib/locale/en_US,再次运行正常.

Energia

  • Installing the LaunchPad drivers
  • Energia是一个开源和社区驱动型集成开发环境(IDE)与软件框架与Arduino的设计理念是一样的.Energia基于接线框架,为微控
    制器编程提供了直观的编码环境和由易于使用的功能API及库构成的可靠框架.Energia支持多种 TI 处理器,主要包括可从LaunchPad开发生态系统获得的处理
    器.Energia是开源产品,源代码可从github获得.
  • 总体来说,Energia是从Arduino分支出来,但是支持的库不是很多,而且最新的版本是2019出的,后续版本好像没有看到.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
~$ cat /etc/udev/rules.d/71-ti-permissions.rules
SUBSYSTEM=="usb",ENV{DEVTYPE}=="usb_device",ATTRS{idVendor}=="0403",ATTRS{idProduct}=="a6d0",MODE:="0666"
SUBSYSTEM=="usb",ENV{DEVTYPE}=="usb_device",ATTRS{idVendor}=="0403",ATTRS{idProduct}=="a6d1",MODE:="0666"
SUBSYSTEM=="usb",ENV{DEVTYPE}=="usb_device",ATTRS{idVendor}=="0403",ATTRS{idProduct}=="6010",MODE:="0666"
SUBSYSTEM=="usb",ENV{DEVTYPE}=="usb_device",ATTRS{idVendor}=="1cbe",ATTRS{idProduct}=="00fd",MODE:="0666"
SUBSYSTEM=="usb",ENV{DEVTYPE}=="usb_device",ATTRS{idVendor}=="1cbe",ATTRS{idProduct}=="00ff",MODE:="0666"
SUBSYSTEM=="usb",ENV{DEVTYPE}=="usb_device",ATTRS{idVendor}=="0451",ATTRS{idProduct}=="bef1",MODE:="0666"
SUBSYSTEM=="usb",ENV{DEVTYPE}=="usb_device",ATTRS{idVendor}=="0451",ATTRS{idProduct}=="bef2",MODE:="0666"
SUBSYSTEM=="usb",ENV{DEVTYPE}=="usb_device",ATTRS{idVendor}=="0451",ATTRS{idProduct}=="bef3",MODE:="0666"
SUBSYSTEM=="usb",ENV{DEVTYPE}=="usb_device",ATTRS{idVendor}=="0451",ATTRS{idProduct}=="bef4",MODE:="0666"
SUBSYSTEM=="usb",ENV{DEVTYPE}=="usb_device",ATTRS{idVendor}=="0451",ATTRS{idProduct}=="f432",MODE:="0666"
SUBSYSTEM=="usb",ENV{DEVTYPE}=="usb_device",ATTRS{idVendor}=="0d28",ATTRS{idProduct}=="0204",MODE:="0666"
KERNEL=="hidraw*",ATTRS{busnum}=="*",ATTRS{idVendor}=="0d28",ATTRS{idProduct}=="0204",MODE:="0666"
ATTRS{idVendor}=="0451",ATTRS{idProduct}=="bef0",ENV{ID_MM_DEVICE_IGNORE}="1"
ATTRS{idVendor}=="0c55",ATTRS{idProduct}=="0220",ENV{ID_MM_DEVICE_IGNORE}="1"
KERNEL=="ttyACM[0-9]*",MODE:="0666"

SUBSYSTEM=="usb", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="c32a", MODE="0660", GROUP="dialout", RUN+="/sbin/modprobe ftdi-sio" RUN+="/bin/sh -c '/bin/echo 0451 c32a > /sys/bus/usb-serial/drivers/ftdi_sio/new_id'"

谢谢支持