Mediatek Labs LinkIt Connect 7681 Developer'S Manual Download Page 46

 

MediaTek LinkIt™ Connect 7681 Developer's Guide 

 

 

© 2015, 2016 MediaTek Inc. 

Page 41 of 65 

This document contains information that is proprietary to MediaTek Inc. 

Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited. 

 

 

5.

 

Using the APIs 

This section provides information on how to use the MT7681 APIs. For details of the API please 

refer to the 

MediaTek LinkIt Connect 7681 API Reference

The topics covered in this section include: 

 

connecting MT7681 to an AP. 

 

configuring MT7681 as an AP. 

 

using uIP for TCP/IP operations, including: 

o

 

creating a TCP client that connects to a remote TCP server. 

o

 

creating a TCP server and allowing others to connect to it. 

o

 

increasing the available TCP/UDP connections. 

5.1.

 

Connecting MT7681 to an AP 

This section describes how to code MT7681 so that it will always connect to the specified AP. This 

is useful when you don’t want to use Smart Connection but have a specific AP you want to 
connect to. The steps to achieve this are as follows: 

1)

 

disable default Smart Connection 
Open 

mak\MT7681\flags_stak.mk

 (this is the make file for Station mode), scroll to the 

bottom and add following lines before 

#END-OF-FILE#

... 

FUN= -DCFG_SUPPORT_MTK_SMNT=0  # add this line to enable MTK 

SMNT 

#END-OF-FILE# 

2)

 

add the specific AP setting to 

IoT_Cust_SM_Smnt()

.

 

Summary of Contents for LinkIt Connect 7681

Page 1: ...is proprietary to MediaTek Inc Unauthorized reproduction of this information in whole or in part is strictly prohibited M MediaTek LinkIt Connect 7681 Developer s Guide Version 1 2 Release date 12th M...

Page 2: ...uary 2015 Initial release 1 0 31st January 2015 Update to code in 2 4 1 Code your firmware Correction to path names in 3 1 make Typo in FOTA FW description Appendix A 1 1 23rd January 2016 Updated ins...

Page 3: ...iaTek LinkIt Connect 7681 SDK for Windows 7 2 3 Installing MediaTek LinkIt Connect 7681 SDK for Linux 15 2 4 Your First Project 15 3 Tools guide 21 3 1 make 21 3 2 Firmware uploader 21 3 3 Additional...

Page 4: ...e Config Setting 64 Table 18 AP Mode Config Setting 65 Table 19 User Config Setting 65 Figure 1 Block diagram of the MT7681 1 Figure 2 The software architecture of the MT7681 3 Figure 3 Cygwin Net Rel...

Page 5: ...thorized reproduction or disclosure of this information in whole or in part is strictly prohibited Figure 21 The flow of callback function in MT7681 30 Figure 22 The Wi Fi state machine 34 Figure 23 T...

Page 6: ...g Wi Fi in either Wi Fi station or access point AP mode In Wi Fi station mode MT7681 connects to a wireless AP and can then communicate with web services or cloud servers A typical use of this option...

Page 7: ...681 development board The development board consists of a LinkIt Connect 7681 module micro USB port and pins for each of the I O interfaces of the MT7681 chipset This enables you to quickly connect ex...

Page 8: ...requires Cygwin and Ubuntu Linux 1 3 1 Software Architecture The software architecture of the MT7681 provides for access to its hardware features through four APIs Wi Fi API Security API Interface API...

Page 9: ...TA features enabling wireless firmware upgrades Table 2 The Internet APIs of MT7681 Wi Fi Functions WEP WPA Wi Fi security authentication functions Table 3 The Wi Fi functions of MT7681 1 4 LinkIt Con...

Page 10: ...mory Flash RAM 1MB 64KB Power Operate voltage 3 3v GPIO Pins Pin Count Voltage 5 3 3v PWM Output Pins Pin Count Voltage PWM levels 5 3 3v 0 20 UART Set Count Voltage 1 3 3v Wi Fi Spec Station mode Acc...

Page 11: ...ronment Currently MediaTek LinkIt Connect 7681 SDK supports Microsoft Windows and Ubuntu Linux platforms 2 1 1 Microsoft Windows To run MediaTek LinkIt Connect 7681 SDK for Windows the Cygwin environm...

Page 12: ...1 Installing Cygwin Download the appropriate Cygwin installation package to match your Windows environment from the Cygwin website namely setup x86 exe for 32 bit machines or setup x86 64 exe for 64...

Page 13: ...disclosure of this information in whole or in part is strictly prohibited In the Select Root Install Directory screen see Figure 5 click Next to accept the default setting Figure 5 Accept the default...

Page 14: ...tly prohibited In the Select Your Internet Connection screen see Figure 7 define your proxy if you use one otherwise use Direct Connection and click Next Figure 7 Use the direct connection unless you...

Page 15: ...this information in whole or in part is strictly prohibited The installer now downloads details and displays progress in the Progress screen see Figure 9 Figure 9 The installer downloads information...

Page 16: ...uthorized reproduction or disclosure of this information in whole or in part is strictly prohibited The easiest way to select make and gcc code is by expanding Devel and scrolling down to find gcc cor...

Page 17: ...strictly prohibited Click Next The Resolving Dependencies screen see Figure 12 displays showing details of any dependent packages for your selection click Next Figure 12 Details of any dependent pack...

Page 18: ...y issues with the installation Review any issues and determine what if any action you need to take if any Click Next Figure 14 Any post install script errors are displayed In the Create Icons screen s...

Page 19: ...ult you ll need to 1 modify the tool chain s configuration file which is located at C chosen folder nds32le elf newlib v2j cygwin andes bat so that the highlighted code in the following code example m...

Page 20: ...s Now locate the Src folder and make sure the three shell script files flash_merge sh flash_merge_xip164 sh and header sh are executable by running chmod as follows linux Src chmod 755 sh linux Src ls...

Page 21: ...subCurTimer subPreTimer 1000 subPreTimer subCurTimer iot_gpio_read 2 input polarity get gpio mode and value iot_gpio_output 2 input 1 2 change gpio to output mode with the reversed value Simply locat...

Page 22: ...bytes out sta MT7681_sta bin 4 out sta MT7681_sta_header bin For more details on the commands available for make see section 3 1 make 2 4 2 2 Source Code compilation on Linux To compile the source cod...

Page 23: ...ure 17 Figure 17 Connect the LinkIt Connect 7681 development board to a USB cable 2 identify the COM port on which the development board is connected by opening Device Manager from Control Panel see F...

Page 24: ...ython script as follows If you don t have Python installed get it from the downloads section at python org and install Open cmd using the Cygwin shell might not work and execute mt7681_uploader py f o...

Page 25: ...gistered for FTDI USB Serial Device 77 530861 ftdi_sio 2 2 1 0 FTDI USB Serial Device converter detected 77 531049 usb 2 2 Detected FT232RL 77 531052 usb 2 2 Number of endpoints 2 77 531056 usb 2 2 En...

Page 26: ...ll create a log file as follows out sta build_sta log for a Wi Fi station image build out sta build_ap log for an access point AP image build 3 2 Firmware uploader The firmware uploader is provided as...

Page 27: ...issues are encountered with uploads please refer to the troubleshooting guide section 6 2 Firmware upload errors 3 3 Additional tools The following additional tools may be useful a text code editor or...

Page 28: ...from the code provided the structure of the source code files including where the files you would modify are the boot flow of the MT7681 and where your software is run the user callbacks available for...

Page 29: ...authorized reproduction or disclosure of this information in whole or in part is strictly prohibited 4 2 Source File Structure The source files for MT7681 firmware must be stored in specific locations...

Page 30: ...T7681_station bin MT7681_ap bin MT7681_recovery_old bin MT7681_all bin This full image can be written to MT7681 using a hardware flash programmer burner through the SPI interface This is useful when t...

Page 31: ...the customizable folder 4 2 3 Header files Header files are stored in the src folder in files with the format libandesxxx a 4 2 4 Build settings folder Build configuration setting files are stored in...

Page 32: ...MT7681 then jumps to SRAM address 0 and starts to run 3 Recovery Calibration Mode Recovery Calibration Image will start a 4 seconds timer and wait for a command from UART o If no command is received...

Page 33: ...ly prohibited PC can connect to it and it can create TCP UDP connection with other devices in the LAN or WLAN Figure 20 The boot sequence of MT7681 4 3 2 UART log at Boot up stage During the boot sequ...

Page 34: ...Task 53637 4 4 User callbacks MT7681 firmware provides callback functions that will be called when specific events occur The main callback functions you ll use are iot_cust_preinit iot_cust_init iot_c...

Page 35: ...nction in MT7681 4 4 3 iot_cust_preinit iot_cust_preinit is called once at system start up Code should NOT do anything related to UART or GPIO here because they are not initialized at this stage It s...

Page 36: ...kes to execute You can add your own logic here for example void iot_cust_subtask1 void static int32 i 0 printf_high Hello world d n i This code will result in the message Hello world being output from...

Page 37: ...to WIFI_STATE_SCAN o otherwise the machine goes back to WIFI_STATE_INIT If the AT command AT Smnt is received MT7681 will go into this state immediately WIFI_STATE_SCAN When MT7681 gets target AP sett...

Page 38: ...e 0 MT7681 is preparing to send an Assoc request o Sub state 1 MT7681 is waiting for an Assoc response WIFI_STATE_4WAY MT7681 and the target AP undertake a 4 Way Handshake process and negotiate the PT...

Page 39: ...001 output timer log period to notice system alive SM 2 Sub 0 Change to WIFI_STATE_SCAN SM 3 Sub 0 Change to WIFI_STATE_AUTH is going to send Auth Request Auth with ssid belkin auth mode 9 output the...

Page 40: ...mall RAM so it cannot buffer frames for stations MT7681 AP mode only supports 802 11b g 4 6 2 Station mode MT7681 can be set in station mode In this mode it s able to connect to an AP and get an IP ad...

Page 41: ...on SSID password and AuthMode is broadcast When powered up the device containing an MT6781 listens to detect the broadcast and can consume it to obtain its wireless network settings The transmissions...

Page 42: ...I stops the Wi Fi broadcast of the Smart Connection packet The syntax of this API are as follows int StopSmartConnection void The return values from the API are listed in Table 13 Returned value Meani...

Page 43: ...nnect to the defined AP During this process the MT7681 writes a log to UART here is an example Recovery Mode start to running recovery Calibration image Recovery Mode end to running recovery Calibrati...

Page 44: ...is proprietary to MediaTek Inc Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited To force MT7681 to redo the Smart Connection process either use AT...

Page 45: ...s strictly prohibited 4 7 2 Smart Connection API for iOS A similar interface to that provided for Android is offered for iOS Compared to coding a Smart Connection app for Android iOS requires an addit...

Page 46: ...ions including o creating a TCP client that connects to a remote TCP server o creating a TCP server and allowing others to connect to it o increasing the available TCP UDP connections 5 1 Connecting M...

Page 47: ...detected in scan state again if AuthMode WPA PMK will be calculated in scan state pIoTStaCfg AuthMode Ndis802_11AuthModeOpen pIoTStaCfg SsidLen strlen Ssid pIoTStaCfg PassphaseLen strlen Passphase si...

Page 48: ...K_TKIPAESMIX MT7681 s Default SSID in AP mode define Default_Ssid MT7681_AP1 MT7681 s Default Password in AP mode define Default_Password 12345678 If there are no valid AP settings in Flash MT7681 use...

Page 49: ...for detail log of client connection In AP mode only 3 clients may connect to a MT7681 at the same time 5 3 Using uIP for TCP IP operations This section provides an introductory guide to using uIP micr...

Page 50: ...emote server 1 Initialize the connection Use uip_connect to create the connection In the example below a connection to port 9999 of 192 168 1 1 with the local port is set as 8888 is defined File iot_t...

Page 51: ...RT and includes a timer that sends hello to UART every 5 seconds also File iot_tcp_app c void app_handle_connection void static struct timer user_timer create a timer static bool app_init FALSE if uip...

Page 52: ...rt displaying hello periodically You can also type characters back these should be output on UART of MT7681 5 3 2 Create a TCP server and allow others to connect This section describes how to create a...

Page 53: ...uip_appdata uip_datalen if uip_poll if app_init FALSE timer_expired user_timer printf_high TCP Server timer is expired TX n uip_send hello n 6 timer_set user_timer 5 CLOCK_SECOND app_init TRUE iot_tcp...

Page 54: ...number of connections that can be made at the same time is defined as shown below in uip confg h While it isn t recommended the number of connections can be increased however be aware that doing so wi...

Page 55: ...build_sta log Compiling src wifi wifi_task_pub c bin sh mtktools Andestech BSPv320 toolchains nds32le elf newlib v2j bin nds32le elf gcc No such file or directory The most likely issues are that the...

Page 56: ...stom o In function iot_cust_subtask1 text iot_cust_subtask1 0x6 undefined reference to iot_get_ms__time obj sta iot_custom o In function iot_cust_subtask1 text iot_cust_subtask1 0xa undefined referenc...

Page 57: ...the following is a typical debug log Recovery Mode start to running recovery Calibration image Recovery Mode end to running recovery Calibration image start to running station image SM 0 Sub 0 Change...

Page 58: ...id or iOS app You can also print out the following variables to UART in wifi_state_machine when MT7681 is in WIFI_STATE_SCAN mode to check if the input parameters are correct void wifi_state_machine v...

Page 59: ...packet to MT7681 AP APPeerAuthReqAction MAC 69 df dd 29 62 f4 MacTableInsertEntry 280 pEntryWcid 0 APHandleRxMgmtFrame 260 SUBTYPE_AUTH MT7681 AP deal with the received Auth Req packet send back Auth...

Page 60: ...r disclosure of this information in whole or in part is strictly prohibited If MT7681 is set to open mode no WEP WPA in use PMK Update and the log related to 4 way handshake should not be listed You c...

Page 61: ...DIS_802_11_WEP_STATUS PNDIS_802_11_WEP_STATUS NDIS_802_11_ENCRYPTION_STATUS PNDIS_802_11_ENCRYPTION_STATUS typedef enum _NDIS_802_11_AUTHENTICATION_MODE Ndis802_11AuthModeOpen Ndis802_11AuthModeShared...

Page 62: ...ponsive board If your LinkIt Connect 7681 development board becomes unresponsive 1 attempt to reboot the board using either AT Reboot or the hardware reset button see Figure 25 2 reload the recovery f...

Page 63: ...external Flash There are two types of Flash layout used Flash layout with XIP region size of 60KB Flash layout with XIP region size of 164KB It s acceptable to use external serial Flash of 512KB but 1...

Page 64: ...ASH_OFFSET_WRITE_BUF_START 0xB3000 4KB define FLASH_OFFSET_RESERVE_8_START 0xB4000 4KB define FLASH_OFFSET_OTA_START 0xB5000 292KB define FLASH_OFFSET_RESERVE_9_START 0xFE000 4KB define FLASH_OFFSET_E...

Page 65: ...ictly prohibited Setting the specific Flash layout for XIP region 60KB or 164KB is done in the Makefile as follows After changing FLASH_XIP_164 It is must compile all Firmwares Recovery STA AP Then up...

Page 66: ...000 EEPROM 4 0x1000 Factory Calibration image MT7681E2_EEPROM layout_20140330 bin 0x18000 Common Config 4 0x1000 0x19000 Station Mode Config 4 0x1000 0x1A000 AP Mode Config 4 0x1000 0x1B000 User Confi...

Page 67: ...PROM 4 0x1000 Factory Calibration image MT7681E2_EEPROM layout_20140330 bin 0x18000 Common Config 4 0x1000 0x19000 Station Mode Config 4 0x1000 0x1A000 AP Mode Config 4 0x1000 0x1B000 User Config 4 0x...

Page 68: ...re Update Status 1 2 0x18003 I O Mode select 1 3 0x18004 Reserved 1 20 4 0x18018 UART Baud rate 4 24 0x1801C UART Data bits 1 28 0x1801D UART Parity bits 1 29 0x1801E UART Stop bits 1 30 0x1801F Reser...

Page 69: ...Mode Config region in Flash is shown in Table 17 These items are loaded when MT7681 calls load_sta_cfg reset by calling reset_sta_cfg stored from RAM by calling store_sta_cfg Offset Section Size Byte...

Page 70: ...ID 32 7 0x1A027 SSID Len 1 39 0x1A028 Physical Mode 1 40 0x1A029 AP Channel 1 41 0x1A02A AuthMode 1 42 0x1A02B AP Password 32 43 0x1A04B AP Password Len 1 75 0x1A04C Beacon Interval 2 76 0x1A04E DTIM...

Reviews: