MT7681 Io T WIFI Firmware Programming Guide V1.0
User Manual:
Open the PDF directly: View PDF .
Page Count: 32
Download | ![]() |
Open PDF In Browser | View PDF |
al ti en MT7681 IoT Wi‐Fi Firmware Co nf id Programming Guide 1.0 Release date: 2014‐8‐8 at ek Version: © 2014 MediaTek Inc. di This document contains information that is proprietary to MediaTek Inc. Me Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited. Specifications are subject to change without notice. Revision History Revision Author Description 01.03.2014 First v0.01 Jinchuan Initial draft for MT7681 IoT Firmware Programming Guide. 01.16.2014 v0.02 Jiayi Update Flash Layout and Flash API Update Folder Structure 01.24.2014 v0.03 Jinchuan Update Flash Layout and Flash API:spi_flash_write() Add Section: AT Command Usage 03.22.2014 v0.04 Jinchuan Jerry Add FIRMWARE boot UP flow Add Customer Hook Function Add Flash settings Load/Storage Add Timer APIs Modify Interfae APIs Modify Flash Partitions 04.15.2014 v0.05 Jinchuan Jerry Modify File Structure Modify GPIO Interface Description and GPIO/Pin Mode Set Modify Flash Partitions Add New PWM API Add Customer UART‐TO‐WIFI Function Add Customer Hook Function for Smart Connection 05.16.2014 v0.07 Jinchuan nf id en ti al Date at ek Co Add IoT_gpio_read() Add IoT_Cust_Set_GPIINT_MODE(); IoT_Cust_Get_GPIINT_MODE(); IoT_Cust_GPIINT_Hdlr() Add GetMsTimer() Add Security API Update Firmware Boot Up Flow Update Customer Hootk Functioin Update File Structure Update IoT_led_pwm(): led_num range in soft pwm mode Delete ATCmd about TCP/UDP di 05.30.2014 Jinchuan 8.8.2014 Add APIs for Rxfilter control Add Set channel API Add Rx Packet API: STARxDoneInterruptHandle Add Tx Packet API: mt76xx_dev_send Add APIs for MD5: RT_MD5() … v0.09 Jinchuan Add Wifi State Machine Flow chart Update Rxfilter API’s Notes Update IoT_Cmd_Set_Channel API’s channel range Update ATCmd Channel Switch: AT#Channel ‐b0 ‐c6 Add AT cmd for Smart Connection entry: AT#Smnt Add spi_flash_write_func() description Update spi_flash_write () description and Add design flow Add HW Timer1 Interrupt Function V1.0 Jinchuan Update Rx Filter Description Correct API name as: RT_AES_Decrypt, Me 07.09.2014 v0.08 RT_ AES _Encrypt Add Sample code descript for AES ECB/CBC Decrypt/Encrypt Add IoT_send_udp_directly() API to send udp packet Add AsicSetChannel() API Add SPI Cmd table in the section of “Flash Driver” 1.1 Flow Chart Symbols .......................................................................................................................................... 5 1.2 Keywords .......................................................................................................................................................... 5 ti 2 Introduction................................................................................................................................................................... 5 SW Structure ................................................................................................................................................................. 6 en 1 al Contents Flow chart ......................................................................................................................................................... 6 id 2.1 File Structure ................................................................................................................................................................. 6 4 FIRMWARE boot UP flow .............................................................................................................................................. 7 5 Wifi Connection State Machine Flow ............................................................................................................................ 7 6 Customer Hook Function............................................................................................................................................... 8 7 Customer UART‐TO‐WIFI Function ................................................................................................................................ 9 8 Flash settings Load/Storage ........................................................................................................................................ 10 9 AT Command ............................................................................................................................................................... 13 ek Co nf 3 Flow chart: ...................................................................................................................................................... 13 9.2 Function Description ....................................................................................................................................... 13 How to add a new AT command ..................................................................................................................... 14 di 9.3 at 9.1 10 Data Command............................................................................................................................................................ 14 Me 10.1 11 Flow chart: ...................................................................................................................................................... 14 10.2 Function Description ....................................................................................................................................... 15 10.3 How to add a new Data command ................................................................................................................. 15 WIFI MAC APIS............................................................................................................................................................. 16 11.1 Rx Filter Control .............................................................................................................................................. 16 11.2 MAC Control ................................................................................................................................................... 16 12 Security APIS................................................................................................................................................................ 18 13 Timer APIs.................................................................................................................................................................... 20 SW Timer APIs. ................................................................................................................................................ 20 13.2 HW timer1 interrupt function ......................................................................................................................... 21 al Interfae APIs ................................................................................................................................................................ 21 Flash Driver ..................................................................................................................................................... 21 14.2 UART ............................................................................................................................................................... 23 14.3 LED / PWM ...................................................................................................................................................... 24 14.4 GPIO ................................................................................................................................................................ 25 14.5 GPIO/Pin Mode Set ......................................................................................................................................... 27 en ti 14.1 id 14 13.1 Flash Partitions ............................................................................................................................................................ 28 16 Compiler Setup ............................................................................................................................................................ 30 17 AT Command Usage .................................................................................................................................................... 31 nf 15 Display version ................................................................................................................................................ 31 17.2 Reboot the system .......................................................................................................................................... 31 17.3 Set Default ...................................................................................................................................................... 31 17.4 Switch channel ................................................................................................................................................ 31 17.5 Configure UART interface ............................................................................................................................... 31 at ek Co 17.1 Update Firmware from Uart ........................................................................................................................... 31 17.7 Enter into Smart Connection State ................................................................................................................. 31 di 17.6 Me 17.8 Enter into Deep sleep mode ........................................................................................................................... 32 1 INTRODUCTION The 7681 IoT Wi‐Fi structure could be divided into two layers (HW layer, Firmware Layer); This document aims to help the programmers understand the 7681 Wi‐Fi Firmware architecture and how to do the customization, such as AT command or Data command Flow Chart Symbols 1.2 Keywords nf id en ti al 1.1 Base Band Processor SEC: Security Engine PBF: Packet Buffer PDMA: Programmable Direct Memory Access FCE: Frame Control Engine Me di at ek Co BBP: 2 SW STRUCTURE Flow chart initialize the HW registers to enable HW interfaces and Wi‐Fi function Wi‐Fi State machine: a single loop to control Wi‐Fi Tx, Rx, and process the Data command, AT command nf HW init: id en ti al 2.1 Data Command handler: handle the Data command which received from Wi‐Fi AT Command handler: FILE STRUCTURE Co 3 handle the AT command which received from UART \cust\main_pub.c , Main entry \cust\wifi_task_pub.c , Wifi Task Function , Rx Handler \cust\iot_customer.c , The Initial Hook and setting load/storage \cust\iot_at_cmd.c , handle the AT command which received from UART Me di at ek \cust\rtmp_data_pub.c \cust\iot_at_cmd_utility.c ,the common api for AT command usage \cust\iot_parse.c ,handle the Data command which received from Wi‐Fi \cust\tcpip\*.c , the source code and sample code for TCP UDP \mak\MT7681\ , store the configuration for compiler or linker \mak\MT7681\flags_sta.mk , store the macros for all station mode source code \mak\MT7681\flags_ap.mk , store the macros for all AP mode source code \out\ , store the files which created by compiler \out\build.log , the compiling log \out\MT7681.bin , the target binary file \src\include , the header files libandessta.a , library for MT7681 Station Mode libandesap.a , library for MT7681 AP Mode MT7681_all.bin , The Image for FW upgrade by Flash writer (include Loader.bin, EEPROM.bin, RecoveryFW.bin, StationFW.bin, APFW.bin) FIRMWARE BOOT UP FLOW nf id en ti al 4 5 Co LoaderÆ Recovery Mode Æ Loader Æ STA/AP FW The Boot up flow is: WIFI CONNECTION STATE MACHINE FLOW STA Mode v1.40: * When Scan, Auth, Assoc, 4Way, DHCP fail, not back to smart connection state ek * Smart Connection state is only triggered by following methods: 1: There is no valid content in Flash Sta Config region at 2: 7681 receive AT Cmd: AT#Smnt Customer maybe change this process, to make smnt state can be entered with other method Me di by control ATSetSmnt flag al ti en id nf Co 6 CUSTOMER HOOK FUNCTION Me di at ek Iot_customer.c IoT_Cust_Ops() is used to register callback function , which could be called by Wifi main function When and where this callback function will be used, please see next picture for the details al ti en id nf 7 CUSTOMER UART‐TO‐WIFI FUNCTION Me di at ek Co Iot_customer_uart2wifi.c IoT_Cust_uart2wifi_data_handler() : It is the key function for uart‐to‐wifi transmission. It is the bridge between uart module and TCP/IP module of WiFi. In the sample code, uip_send() is called to send data from uart to wifi. al IoT_Cust_uart2wifi_init() : In the sample code, every 300 ms , or when the uart rx content is larger than 10, en a uart‐to‐wifi transmission judgment will be triggered. ti You can use it to configure uart‐to‐wifi timer interval and uart trigger count. IoT_Cust_uart2wifi_detect_gpio_input_change () : id You can use it to define your own input status change. In the sample code, when the input of gpio2 is high, uart rx is switched to pure data mode; nf otherwise, it is switched to AT cmd mode. Note: Co Uart‐to‐wifi function collides with data parser uart rx function, so you must set DATAPARSING_UARTRX_SUPPORT to 0 first. FLASH SETTINGS LOAD/STORAGE at 8 ek When and where these functions will be used, please see next picture for the details Iot_customer.c The default settings on User/Common config block of the flash , Me di system shall used these default settings , if there is no content or the content is invalid, the detail implementation is on the iot_customer.c al ti en IOT_COM_CFG: IOT_COM_CFG, Please do not modify this structure, because the Wi‐Fi main task / TCP IP will use this structure for nf module initialization or operation Can be customized, because only iot_parser.c, iot_custom.c Co IOT_USR_CFG: IOT_USR_CFG id There are two structures: will use this structure Notice:Both of above two structures are mapping with Flash Layout, and the settings load/reset is optimized for code size slim by macro “FLASH_STRUCT_MAPPING 1” with this condition. Me di at ek If the structure is not mapping with Flash Layout, “FLASH_STRUCT_MAPPING” should be set as 0 al ti en id nf Co Example A: Modify IOT Server IP to {172.133.125.12} Change #define DEFAULT_IOT_SERVER_IP {182.148.129.91} to {172.133.125.12} ek Method1: Method2: not modify DEFAULT_IOT_SERVER_IP, but use FLASH API to write the new value to related at position of the FLASH, thus, while MT7681 reboot or power on again, the new settings on flash will be load Me di Example B: Add a Uart2Wifi Length parameter to User Config Block Step1: add new macro in flash_mapping.h to indicate Uart2Wifi position on the flash, Step2: Add new member on IOT_USR_CFG structure Step3: Add a default value macro, just like: #define DEFAULT_IOT_SERVER_IP Step4: Add load/reset implementation for Uart2Wifi on {182.148.129.91} load_usr_cfg(), rest_usr_cfg() 9 AT COMMAND Flow chart: 9.2 Function Description id z en ti al 9.1 INT32 IoT_parse_ATcommand (PUCHAR cmd_buf, INT32 at_cmd_len); Description: This function parses AT command from the Uart port. It classifies the commands and call respective nf functions to parse the commands. Paramters: cmd_buf ‐‐‐‐ Pointer to AT command buffer [IN]: at_cmd_len ‐‐‐‐ Length of the AT command. Co [IN]: Return Values:Return negative if error occurs. Remarks: The command header “AT#” is removed before entering this function. INT32 IoT_exec_ATcommand_uart (PUCHAR cmd_buf, INT32 at_cmd_len) ek z Return zero, otherwise. Description:This function parses uart AT command. at Paramters: [IN]: cmd_buf ‐‐‐‐ Pointer to uart AT command buffer [IN]: at_cmd_len ‐‐‐‐ Length of the uart AT command. Return Value : Return negative if error occurs. Return zero, otherwise. : None. di Remark INT32 IoT_exec_ATcommand_netmode (PUCHAR cmd_buf, INT32 at_cmd_len) Description:This function parses netmode AT command. Me z Paramters: [IN]: cmd_buf ‐‐‐‐ Pointer to netmode AT command buffer [IN]: at_cmd_len ‐‐‐‐ Length of the netmode AT command. Return Value : Return negative if error occurs. Return zero, otherwise. Remark: None. 9.3 How to add a new AT command en ti al 1) Add a new else/if branch for the new AT command type in the function IoT_parse_ATcommand. 2) Add a new parsing function for the new type. IoT_exec_ATcommand_netmode can be a template. id 10 DATA COMMAND Me di at ek Co nf 10.1 Flow chart: 10.2 Function Description z INT32 IoT_proc_app_packet(UCHAR sock_num, PUCHAR packet , UINT16 rawpacketlength); Description: This function parses control protocol packet in the application layer. It removes protocol header and call respective functions to parse the data header and data content. Parameters sock_num ‐‐‐‐ socket number of the current TCP/UDP transmission [OUT]: packet ‐‐‐‐ Pointer to protocol header [OUT]: rawpacketlength ‐‐‐‐ Length of the packet al [OUT]: Remark: sock_num is used to distinguish different TCP/UDP transmission z INT32 IoT_proc_app_func_pkt (DataHeader* DataHeader, UINT16 FuncType, en IoTPacketInfo *PacketInfo); ti Return Value: Return zero. Description: This function parses control protocol packet of the function type. Parameters ‐‐‐‐ Pointer to data header FuncType ‐‐‐‐ the function command type [OUT] : PacketInfo ‐‐‐‐ packet information that is used when sending the response. nf Return Value: Return zero. Remark: None. INT32 IoT_proc_app_mgt_pkt(DataHeader* Dataheader, UINT16 MgtType, Co z id [OUT]: DataHeader [OUT]: IoTPacketInfo *PacketInfo); Description: This function parses control protocol packet of the management type. Parameters ‐‐‐‐ Pointer to data header ek [OUT] : Dataheader [OUT] : MgtType ‐‐‐‐ the management command type [OUT]: ‐‐‐‐ packet information that is used when sending the response. PacketInfo at Return Value: Return zero. Remark: None. di 10.3 How to add a new Data command 1. function related command 1) Add new command in the structure t_FunctionCommand. Me 2) Add a new select/case branch in the function IoT_proc_app_func_pkt 2. management related command 1) Add new command in the structure t_ManagementCommand. 2) Add a new select/case branch in the function IoT_proc_app_mgt_pkt 3. command of other class 1) Add new type in the structure t_CommandType. 2) Add new parsing function for the new type. IoT_proc_app_func_pkt can be a template. 3) Add a new type and its parsing function in the function IoT_proc_app_pkt 11 WIFI MAC APIS 11.1 Rx Filter Control z UINT16 IoT_Get_RxFilter(VOID) Description: Get Rx filter about frame receive None al Parameters z Co nf id en ti Return value:Rx filter value, the definition of the setting as blow table UINT16 IoT_Set_RxFilter(UINT16 Value) Description: Set Rx filter about frame receive Parameters [IN]: Value ‐‐‐‐ The Rx Filter value , the settings refers to above table it should same as Input Parameter when bit5=1, both BC/MC packet shall be dropped, even if bit6=0. at Notes: ek Return value:the value actually write to RxFilter, di Notes: Rx Filter shall be reset to 0x7f97 when Wifi State Change by function wifi_state_chg() 11.2 MAC Control z IoT_Cmd_Set_Channel (UINT8 Channel) Me Description: switch Current Channel Parameters [IN]: Channel ‐‐‐‐ The new channel shall be switched to, Channel Range [1~14] Return value:None z INT AsicSetChannel (UCHAR ch, UCHAR bw, UCHAR ext_ch) Description: switch Current Channel, bandwidth and channel setting Parameters [IN]: ch , Channel number, ‐‐‐‐ [1~14] if 'bw' is BW_40, 'ch' is Center channel [IN]: bw , Bandwidth ‐‐‐‐ [BW_20, BW40] [IN]: ext_ch, 11n bandwidth setting ‐‐‐‐ [EXTCHA_NONE, EXTCHA_ABOVE, EXTCHA_BELOW] Return value:0 Remark: if 'bw'=BW_20, 'ext_ch' should be EXTCHA_NONE or EXTCHA_ABOVE, these two options have the same effect for BW_20. al if 'bw'=BW_20, 'ext_ch' should not be EXTCHA_BELOW Example: AsicSetChannel (8, BW_40, EXTCHA_ABOVE) ti It means: 7681 will change to Center channel 8, and bandwidth 40 with 40MHz above mode In this case, primary channel is 6 ‐‐‐‐ n = [3~11] AsicSetChannel (m, BW_40, EXTCHA_BELOW) ‐‐‐‐ m = [8‐11] Me di at ek Co nf id AsicSetChannel (n, BW_40, EXTCHA_ABOVE) en If your want to scan all primary channels [1~13] in 802.11n mode, it is possible to start scan with the below inputs z INT rtmp_bbp_set_bw(UINT8 bw) Description: switch Current Bandwidth Parameters [IN]: bw ‐‐‐‐ The new bandwidth shall be switched to, Return value: Always TRUE bandwidth Range [0:BW20, 1:BW40] z BOOLEAN STARxDoneInterruptHandle (pBD_t pBufDesc) Description: Wifi MAC Rx packet handler Parameters [IN]: pBufDesc ‐‐‐‐ The received Rx descriptor, include Rx MAC content and Rx Info Return value: FALSE if the Rx packet is invalid, VOID mt76xx_dev_send(void) al z TRUE if the Rx packet is valid Description: Send uip Tx packet Parameters None Notes: z ti Return value: None This function will copy data from “uip_buf” to Tx Descriptor and send it to wireless INT32 IoT_send_udp_directly(uip_ipaddr_t *DstAddr, en PUCHAR DstMAC, UINT16 SrcPort, UINT16 DstPort, id PUCHAR pPayload UINT16 PayloadLen) Description: This function is used to send packet with UDP format directly nf Parameters ‐‐‐‐ The pointer of destination IP address [IN]:DstMAC ‐‐‐‐ The pointer of destination MAC address [IN]:SrcPort ‐‐‐‐ The udp port of source [IN]:DstPort ‐‐‐‐ The udp port of destination [IN]:pPayload ‐‐‐‐ The pointer of payload which shall be send to destination [IN]:PayloadLen ‐‐‐‐ The length of payload which shall be send to destination Co [IN]:DstAddr 1=input parameter is invalid ek Return value:0=successful, 2=allocate free queue buffer fail 12 SECURITY APIS VOID RT_AES_Decrypt(UINT8 at z UINT CipherBlock[]. KeyLen, UINT CipherBlockSize, UINT8 Key[], UINT8 PlainBlock[], UINT *PlainBlockSize); Description: This function is used to decrypt data with AES algorithm di Parameters [IN]: CipherBlock[] ‐‐‐‐ The block of cipher text, 16Bytes(128bit) each block [IN]:CipherBlockSize ‐‐‐‐ The length of block of cipher text in bytes Me [IN]:Key[] ‐‐‐‐ Cipher key , it maybe 16,24 or 32bytes [IN]:KeyLen ‐‐‐‐ The length cipher key in bytes [IN] : ‐‐‐‐ PlanBlockSize The length of allocated plain block in bytes [OUT] : PlanBlock[] ‐‐‐‐ Plain block to store plain text [OUT] : PlanBlockSize ‐‐‐‐ The length of real used plain block in bytes Return value:None z VOID RT_ AES _Encrypt(UINT8 PlainBlock[], UINT *PlainBlockSize, UINT8 Key[], UINT KeyLen, UINT8 CipherBlock[]. UINT CipherBlockSize); Description: This function is used to Decrypt data with AES algorithm Parameters [IN] : PlanBlock[] ‐‐‐‐ The block of Plain text, 16bytes(128bit) each block [IN] : PlanBlockSize ‐‐‐‐ The length of block [IN]:Key[] ‐‐‐‐ Cipher key , it maybe 16,24 or 32bytes [IN]:KeyLen ‐‐‐‐ The length cipher key in bytes [IN]:CipherBlockSize ‐‐‐‐ The length of allocated cipher block in bytes ‐‐‐‐ cipter text [OUT]:CipherBlockSize ‐‐‐‐ The length of real used cipher block in bytes ti [OUT]:CipherBlock[] al of plain text in bytes Return value:None RT_AES_Decrypt(), RT_ AES _Encrypt() are only 16 Bytes input 16 Bytes output for PlainBlock and CipherBlock INT32 RtmpPasswordHash(PSTRING password, PUCHAR ssid, INT32 Description: This function is used to calculate the PMK Parameters ‐‐‐‐ ASCLL string up to 63 characters in length [IN] : ‐‐‐‐ octect string up to 32 octects ‐‐‐‐ length of ssid in octects [IN]:ssid_len [OUT]:output ‐‐‐‐ must be 40 octects in length and 0~32octects(256bits) is the key Co Return value:None z VOID __romtext RT_MD5 ( const UINT8 Message[], Description: MD5 algorithm Parameters UINT MessageLen, ‐‐‐‐ Message context ek [IN]:message [IN]:messageLen ‐‐‐‐ The length of message in bytes [OUT]: digestMessage ‐‐‐‐ Digest message Me di at Return Value: None z VOID __romtext RT_MD5_Init (MD5_CTX_STRUC *pMD5_CTX) Description: Initial Md5_CTX_STRUC Parameters [IN]:pMD5_CTX PUCHAR output); nf [IN] : password ssid ssid_len id z en There are some sample codes in iot_aes_pub.c , the entry of AES ECB,CBC sample code is AES_Sample() Pointer to Md5_CTX_STRUC UINT8 DigestMessage[]) Return Value: z None VOID __romtext RT_MD5_Append (MD5_CTX_STRUC *pMD5_CTX, const UINT8 Message[], UINT MessageLen) Description: The message is appended to block. If block size > 64 bytes, the MD5_Hash will be called. Pointer to MD5_CTX_STRUC Message Message context MessageLen The length of message in bytes z None VOID __romtext RT_MD5_End (MD5_CTX_STRUC *pMD5_CTX, UINT8 DigestMessage[]) Description: 1. Append bit 1 to end of the message 3. Transform the Hash Value to digest message Parameters [IN] pMD5_CTX Pointer to MD5_CTX_STRUC Digest message nf [OUT] digestMessage Return Value: None Co 13 TIMER APIS 13.1 SW Timer APIs. z id 2. Append the length of message in rightmost 64 bits en Return Value: ti pMD5_CTX al Parameters: VOID cnmTimerInitTimer( IN P_TIMER_T prTimer, IN PFN_MGMT_TIMEOUT_FUNC pfFunc, ek IN UINT_32 u4Data IN UINT_32 u4Data2) Description: This function is used to initialize a timer at Parameters ‐‐‐‐ Pointer to a timer structure [IN]:pfFunc ‐‐‐‐ Pointer to the call back function [IN]:u4Data ‐‐‐‐ parameter for call back function [IN]:u4Data2 ‐‐‐‐ parameter for call back function di [IN]:prTimer Return value:None VOID cnmTimerStartTimer (IN P_TIMER_T prTimer, Me z IN UINT_32 u4TimeoutMs) Description: This function is used to start a timer Parameters [IN]:prTimer ‐‐‐‐ Pointer to a timer structure [IN]:u4TimeoutMs ‐‐‐‐ Timeout to issue the timer and callback function Return value:None z VOID cnmTimerStopTimer(IN P_TIMER_T prTimer) Description: This function is used to stop a timer (unit:ms) Parameters [IN]:prTimer ‐‐‐‐ Pointer to a timer structure Return value:None There is a example on IoT_customer.c UINT32 GetMsTimer(VOID) Description: Get the time from system start (Unit: 1ms) al z Parameters Return value:the counter value ti 13.2 HW timer1 interrupt function The Frequency for hardware timer 1 interrupt, Range [1~10] 10 /*T = 1/TICK_HZ_HWTIEMR1*/ IoT_Cust_HW_Timer1_Hdlr will be triggered every 100ms (That is T=1/10) ek Above example: Co nf id en #define TICK_HZ_HWTIMER1 14 INTERFAE APIS 14.1 Flash Driver void spi_flash_erase_SE(uint32 address) at z Description: This function is used to erase the sector in which the address specifies. Parameters ‐‐‐‐ the address in flash to be erased di [IN]:addr Return value: None void spi_flash_erase_BE(uint32 address) Me z Description: This function is used to erase the block in which the address specifies. Parameters [IN]:addr ‐‐‐‐ the address in flash to be erased Return value: None Note: 1. Due to the characteristic of flash, erase the sector/block where data is to be written is mandatory before write anything to flash. 2. The size of sector/block of one flash is different. Please check the datasheet of using flash. 3. above two APIs will erase a sector or a block, please consider if there are some data should not be erased in one sector/block before using those two APIs . z int32 spi_flash_read(uint32 addr, uint8 *data, uint16 len) Description: This function is used to read specified data from flash Parameters ‐‐‐‐ The offset which the reading data stored on the flash [IN]:len ‐‐‐‐ The data length need to read [OUT]:data ‐‐‐‐ The pointer indicate the reading data al [IN]:addr z ti Return value:0 means successful, non‐zero means fail int32 spi_flash_read_m2(uint32 addr, uint8 *data, uint16 len) Description: This function is used to read specified data from flash with SPI command method z int32 spi_flash_write_func(uint32 addr, uint8 *data, uint16 len) Parameters id Description: This function is used to write specified data to flash en The function has the same effect with spi_flash_read() ‐‐‐‐ The offset which the data will be write on the flash [IN]:len ‐‐‐‐ The data length need to write [IN]:data ‐‐‐‐ The pointer indicate the writing data nf [IN]:addr Return value: 0 means successful, non‐zero means fail Notes: ThisAPI will write data to flash offset “addr” directly, z Co If the flash sector which the “addr” belongs to is not be erased first, This API will write data to flash unsuccessful int32 spi_flash_write(uint32 addr, uint8 *data, uint16 len) Description: This function is used to write specified data to flash Parameters [IN]:len [IN]:data ‐‐‐‐ The offset which the data will be write on the flash ek [IN]:addr ‐‐‐‐ The data length need to write ‐‐‐‐ The pointer indicate the writing data Return value: 0 means successful, non‐zero means fail at Notes:As the RAM limitation, the len must <= FLASH_OFFESET_WRITE_BUF (4KB) This API will erase Sector first then Æ store original data Æ merge the modified data Æ write back to sector Thus, 1: if you want to write some data to flash, please do not call spi_flash_erase_SE() or spi_flash_erase_BE() to Me di erase flash again, but just call spi_flash_write(). 2: As this API will erase sector, thus, need avoid calling this API with High Frequency al ti en id nf at ek Co SPI Command description 14.2 UART z INT32 IoT_uart_input(UINT_8 *msg, INT32 count); Description: This function reads a given length of data from the uart port. di Parameters [IN] :msg ‐‐‐‐ Pointer to a uart rx buffer [OUT] :count ‐‐‐‐ Length of data to read Me Return Value: Return zero. Remark:None. z INT32 IoT_uart_output(UINT_8 *msg, INT32 count); Description:This function writes a given length of data to the uart port. Parameters [OUT] : msg ‐‐‐‐ Pointer to a uart tx buffer [OUT] : count ‐‐‐‐ Length of data to write Return Value:Return zero. Remark:None. 14.3 LED / PWM z INT32 IoT_led_pwm (INT32 led_num, INT32 brightness); Description:This function configures the brightness of a led. Parameters [Ex: led_num is led controller number, range (1~ 3).. Led_num=1 , use Pin26 as Led/PWM Led_num=2, use pin31 as Led/PWM Led_num=3, use pin30 as Led/PWM ] In software pwm mode, [OUT] :brightness use Pin31 as Led/PWM Led_num=1, use pin30 as Led/PWM Led_num=2, use pin29 as Led/PWM Led_num=3, use pin28 as Led/PWM Led_num=4, use pin27 as Led/PWM ] id ‐‐‐ Brightness level of led. In hardware pwm mode, range (0 ~ 5) In software pwm mode, range (0 ~ 20). nf Return Value: Led_num=0 , en [Ex: led_num is gpio number , range (0~ 4). Return ‐1 if led_num is invalid. Return 0, otherwise. Co Remark 1) Two pwm mode is supported. al ‐‐‐‐ In hardware pwm mode, ti [OUT] :led_num If IOT_PWM_TYPE==1, hardware pwm mode is used. If IOT_PWM_TYPE==2(default type), software pwm mode is used. 2) Level 0 is off. Level 5 is the brightest in hardware pwm mode. Level 0 is off. Level 20 is the brightest in software pwm mode. ek 3) Software pwm mode consumes more CPU resources. However, it has high frequency and more brightness levels. 4) In Hardware PWM mode, at if you want to cancel PWM mode for pin26, 31, 30 and set them as GPIO mode need call IoT_gpio_output(5 , 0), IoT_gpio_output(0 , 0), IoT_gpio_output(1 , 0) The pin and GPIO relationship, please refer to section:“GPIO/Pin Mode Set” di z VOID IoT_software_pwm_addset (INT32 led_num, INT32 brightness) Description:This function configures a gpio pin to software pwm mode and set the brightness level. It absolute same as IoT_led_pwm() in soft PWM mode Me Parameters [OUT] :led_num ‐‐‐‐ Specify the gpio number which is to be configured to software pwm mode. Should be ranged from 0 to 4 [OUT] :brightness ‐‐‐ Brightness level of led. Available only In software pwm mode, should be ranged from 0 to 20. Return Value: Return ‐1 if led_num is invalid. Return 0, otherwise. Remark 1) This API is available. only if software pwm mode is used 2) Level 0 is off. Level 20 is the brightest in software pwm mode. z INT32 IoT_software_pwm_del (INT32 led_num) Description:This function changes a gpio pin from software pwm mode back to gpio mode Parameters [OUT] :led_num ‐‐‐‐ Specify the gpio number which is to be changed. Should be ranged from 0 to 4 Return Value: Return ‐1 if led_num is invalid. Return 0, otherwise. al Remark 1) This API is available. only if software pwm mode is used z INT32 IoT_gpio_read (INT32 gpio_num, UINT8 *pVal, UINT8 *pPolarity); Parameters en Description:This function set the GPIO as input mode, and read it’s input value ti 14.4 GPIO [IN]: gpio_num ‐‐‐‐ Specify the gpio number. Should be ranged from 0 to 6. [OUT]: pPolarity [OUT]: pVal ‐‐‐‐ read the gpio polarity, 0=Output Mode, 1=Input Mode 0=low, 1=High id ‐‐‐‐ read the gpio status, Return Value: none Remarks: nf The GPIO/Pin Mode Set please refer to section: “GPIO/Pin Mode Set” We can set one specific GPIO’s mode/value INT32 IoT_gpio_input(INT32 gpio_num, UINT32 *input); Co z at one time with following APIs Description:This function set the GPIO as input mode, and read it’s input value Parameters [IN]: gpio_num [OUT] : input ‐‐‐‐ Specify the gpio number. Should be ranged from 0 to 6 ‐‐‐‐ the input status of the given gpio number. 0 is low. 1 is high. ek Return Value: Return ‐1 if gpio_num is invalid. Return ‐2 if input is invalid. Return zero, Otherwise. at Remarks: The GPIO/Pin Mode Set please refer to section: “GPIO/Pin Mode Set” INT32 IoT_gpio_output(INT32 gpio_num, INT32 output); di z Description: This function configures the output status of a gpio. Parameters Me [IN] : [OUT]: gpio_num output ‐‐‐‐ Specify the gpio number. Should be ranged from 0 to 6 ‐‐‐‐ the output status of the given gpio number. 0 is low. 1 is high. Return Values: Return ‐1 if gpio_num is invalid. Return ‐2 if output is invalid. Return 0, otherwise. Remarks: The GPIO/Pin Mode Set please refer to section: “GPIO/Pin Mode Set” We can set several GPIOs mode/value z at one time with following APIs INT32 IoT_gpio_batch_modify_mode(INT32 output_bitmap); Description: This function configures a batch of gpio pins to output mode Parameters [OUT] : output_bitmap ‐‐‐‐ Specify the gpio output mode bitmap. Bit(i) stands for gpio(i). Should be ranged from 00000B to 11111B Return Values: Return 0 Remarks: 1. The GPIO/Pin Mode Set please refer to section: “GPIO/Pin Mode Set” INT32 IoT_gpio_batch_modify_output_value(INT32 output_bitmap, INT32 value_bitmap); Description: This function configures a batch of gpio pins to output high. Parameters output_bitmap ‐‐‐‐ Specify the gpio output mode bitmap. id [OUT] : en z ti al 2. If output_bitmap is 10001B, gpio0 and gpio4 will be set to output mode Bit(i) stands for gpio(i). Should be ranged from 00000B to 11111B. [OUT]: value_bitmap ‐‐‐‐ Specify the gpio output status bitmap. nf Bit(i) stands for gpio(i). Should be ranged from 00000B to 11111B. Return Values: Return 0 Remarks: Co 1. The GPIO/Pin Mode Set please refer to section: “GPIO/Pin Mode Set” 2. This function does not change gpio pins to output mode. It modifies the output value only 3. If output_bitmap is 10001B, and value_bitmap is 10000B, di at ek gpio0 will be set to low, and gpio4 will be set to high z UINT8 IoT_Cust_Set_GPIINT_MODE(IN UINT8 GPIO_Num, IN UINT8 Val) Description: Set GPIO interrupt mode Me Parameters [IN] : GPIO_Num ‐‐‐‐ [0~6]. [IN]: Val ‐‐‐‐ 0: no trigger, 2: Return Values: z [0~4] 1: falling edge trigger rising edge trigger 0‐ Success, 3:both falling adn rising edge trigger 1‐invalid input UINT8 IoT_Cust_Get_GPIINT_MODE(OUT UINT16* pGPI_INT_MODE) Description: Set GPIO interrupt mode Parameters [OUT] : GPI_STS [1:0]: GPIO1 Interrupt mode [3:2]: GPIO0 Interrupt mode [5:4]: GPIO2 Interrupt mode [7:6]: GPIO3 Interrupt mode [9:8]: GPIO4 Interrupt mode al [11:10]: GPIO5 Interrupt mode [13:12]: GPIO6 Interrupt mode For each GPIO's interrupt mode 2: 1: falling edge trigger rising edge trigger ti 0: no trigger, 3:both falling adn rising edge trigger Return Values: None VOID IoT_Cust_GPIINT_Hdlr(IN UINT8 GPI_STS); en z Description: This Handler shall be called as any GPIO Interrput be triggered Parameters 0‐ Success, 1‐invalid input 14.5 GPIO/Pin Mode Set CHIP Pin IOT_PWM_TYPE 0 1 2 (HW PWM Mode) (SW PWM Mode) GPIO 0 PWM2 GPIO0 / PWM1 Pin 30 GPIO 1 PWM3 GPIO1 / PWM2 GPIO 2 GPIO 2 GPIO2 / PWM3 GPIO 3 GPIO 3 GPIO3 / PWM4 GPIO 4 GPIO 4 GPIO4 / PWM5 Pin 26 Uart Tx PWM1 / Uart Tx Uart Tx Pin 25 Uart Rx Uart Rx Uart Rx Pin 28 at Pin 27 ek Pin 31 Pin 29 di Remark Me The GPIO list as below: Co Current, We use IOT_PWM_TYPE=2, nf Return Values: id [IN] : GPIO_Num ‐‐‐‐ [0~6]. GPIO0~6 Interrupt status PWM: 20Hz, Level(0~5) PWM: 50Hz, Level(0~20) Level 0 =off Level 0 =off Level 5= brightest Level 20= brightest ek at di Me al ti en id nf Co 15 FLASH PARTITIONS ek at di Me al ti en id nf Co ti only 256B of data can be read from FLASH to RAM, (use IoTpAd.flash_rw_buf[256] ) Then rewrite the data to corresponding place after being modified. http://forum.andestech.com/viewtopic.php?f=23&t=576&p=672 Me di at ek Co nf id http://forum.andestech.com/viewtopic.php?f=23&t=587 en 16 COMPILER SETUP Please refer to description on the Andes web al Note: 1. As the limitation of RAM size, while do flash read/write at a time, 17 AT COMMAND USAGE 17.1 Display version Command: Ver Argument Descriptions: None AT#Ver+enter al Example: 17.2 Reboot the system Command: Reboot Example: AT#Reboot+enter Set Default Command: en 17.3 ti Argument Descriptions: None Default Argument Descriptions: ‐sAT#Default+enter id Example: Command: Channel nf 17.4 Switch channel Argument Descriptions: ‐b (0 for BW_20, 1 for BW_40) ‐c AT#Channel ‐b0 ‐c 6+enter Co Example: (1~14) Remarks: when set 1 to ‐b, the ‐c means central channel for BW40 17.5 Configure UART interface Command: Uart ek Argument Descriptions: ‐b (57600, 115200, 230400 , …) ‐w (5, 6, 7, 8) at ‐p (0 for no parity, 1 for odd, 2 for even) ‐s (1 for 1bit, 2 for 2bits, 3 for 1.5bits) Example: AT#Uart ‐b 57600 ‐w 7 ‐p 1 ‐s 1 +enter Remarks: dlr= round(systemclock/(16* baudrate), 0) di actual baudrate = systemclock/(16* dlr) You can find more supported baudrate for your system according the formula and experiment Me 17.6 Update Firmware from Uart Command: UpdateFW Argument Descriptions: ‐t Example: Remarks: AT# UpdateFW +enter should be enabled on Recovery mode, X‐modem shall be start up after implement this command 17.7 Enter into Smart Connection State Command: Argument Descriptions: Smnt Example: Remarks: AT# Smnt+enter when this cmd be input to 7681, 7681 need change state machine to Smnt state, and start to listen packet in the air to do smart connection 17.8 Enter into Deep sleep mode Command: PowerSaving Argument Descriptions: ‐t al ‐l (1~5) (0~0xFFFFFF (unit:: us)) ‐r AT#PowerSaving ‐l1 ‐t0xFFFFFF+enter AT#PowerSaving ‐r +enter ti Example: Remarks: 7681 will go to sleep when get cmd ”AT#PowerSaving ‐l1 ‐t0xFFFFFF”, and awake after 0xFFFFFF(us) (The Power Saving mode is also in improving , so turn this Cmd off by default temporary , if customer want to test Me di at ek Co nf id en power saving in present, they can turn this Cmd on in MT7681_sta.mk )
Source Exif Data:
File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.4 Linearized : No Tagged PDF : Yes XMP Toolkit : Adobe XMP Core 4.0-c316 44.253921, Sun Oct 01 2006 17:14:39 Producer : Acrobat Distiller 8.1.0 (Windows) Company : MediaTek Inc. Source Modified : D:20140808101558 Creator Tool : Acrobat PDFMaker 8.1 for Word Modify Date : 2014:08:08 18:18:46+08:00 Create Date : 2014:08:08 18:16:30+08:00 Metadata Date : 2014:08:08 18:18:46+08:00 Document ID : uuid:61a506bb-8740-4aef-b572-a5dabbbba5c5 Instance ID : uuid:cda29518-b87d-4857-9abc-12e75d7247b6 Subject : 477 Format : application/pdf Creator : mtk Title : Has XFA : No Page Count : 32 Page Layout : OneColumn Author : mtkEXIF Metadata provided by EXIF.tools