diff --git a/mqx/cyassl_client/.cproject b/mqx/cyassl_client/.cproject index f75ed3280..dab6c96f2 100644 --- a/mqx/cyassl_client/.cproject +++ b/mqx/cyassl_client/.cproject @@ -3,2583 +3,679 @@ - - + + - - - - - - - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - + + - - - - - - - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mqx/cyassl_client/.project b/mqx/cyassl_client/.project index a2241849c..66202a642 100644 --- a/mqx/cyassl_client/.project +++ b/mqx/cyassl_client/.project @@ -1,80 +1,35 @@ - - - cyassl_client - - - -cyassl - -util_lib - - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder - clean,full,incremental, - - - ?name? - - - - org.eclipse.cdt.make.core.append_environment - true - - - org.eclipse.cdt.make.core.buildArguments - -j6 - - - org.eclipse.cdt.make.core.buildCommand - ${system:ECLIPSE_HOME}/../gnu/bin/mingw32-make - - - org.eclipse.cdt.make.core.buildLocation - ${ProjDirPath}/twrk70f120m_Int_Flash_SramData_Debug - - - org.eclipse.cdt.make.core.contents - org.eclipse.cdt.make.core.activeConfigSettings - - - org.eclipse.cdt.make.core.enableAutoBuild - false - - - org.eclipse.cdt.make.core.enableCleanBuild - true - - - org.eclipse.cdt.make.core.enableFullBuild - true - - - org.eclipse.cdt.make.core.stopOnError - true - - - org.eclipse.cdt.make.core.useDefaultBuildCmd - true - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - full,incremental, - - - - - - org.eclipse.cdt.core.cnature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - - - - MQX_ROOT_DIR - file:/C:/Freescale/Freescale%20MQX%203.8 - - - + + + cyassl_client + + + +cyassl + +util_lib + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + MQX_ROOT_DIR + file:/C:/Freescale/Freescale_MQX_4_1 + + + diff --git a/mqx/cyassl_client/Debugger/K70FN1M0.mem b/mqx/cyassl_client/Debugger/K70FN1M0.mem new file mode 100755 index 000000000..7da747bce --- /dev/null +++ b/mqx/cyassl_client/Debugger/K70FN1M0.mem @@ -0,0 +1,43 @@ +// Memory Configuration File +// +// Description: +// A memory configuration file contains commands that define the legally accessible +// areas of memory for your specific board. Useful for example when the debugger +// tries to display the content of a "char *" variable, that has not yet been initialized. +// In this case the debugger may try to read from a bogus address, which could cause a +// bus error. +// +// Board: +// Kinetis K70FN1M0 +// +// Reference: +// - + + +// All reserved ranges read back 0xBABA... +reservedchar 0xBA + +usederivative "MK70F15" + +// Memory Map: +// ---------------------------------------------------------------------- + +range 0x00000000 0x000FFFFF 4 ReadWrite // 1024KB Code Flash +reserved 0x00100000 0x13FFFFFF +range 0x14000000 0x14003FFF 4 ReadWrite // 16KB Programming accelleration RAM +reserved 0x14004000 0x1FFEFFFF +range 0x1FFF0000 0x1FFFFFFF 4 ReadWrite // 64KB On chip SRAM (TCML) +range 0x20000000 0x2000FFFF 4 ReadWrite // 64KB On chip SRAM (TCMU) +reserved 0x20010000 0x21FFFFFF +range 0x22000000 0x221FFFFF 4 ReadWrite // Aliased to TCMU SRAM bitband +reserved 0x22200000 0x3FFFFFFF +reserved 0x60000000 0x6FFFFFFF // Flexbus for external memory +range 0x70000000 0x7FFFFFFF 4 ReadWrite // DRAM Controller - Write-back +range 0x80000000 0x8FFFFFFF 4 ReadWrite // DRAM Controller - Write-through +reserved 0x90000000 0xDFFFFFFF // Flexbus for external memory +reserved 0xE0100000 0xFFFFFFFF + +// Comment the following line for NFC-projects +reserved 0x400A8000 0x400ABEFF +// Uncomment the following line for NFC-projects +//range 0x400A8000 0x400ABEFF 4 ReadWrite diff --git a/mqx/cyassl_client/Debugger/init_kinetis.tcl b/mqx/cyassl_client/Debugger/init_kinetis.tcl new file mode 100755 index 000000000..467b8ff9f --- /dev/null +++ b/mqx/cyassl_client/Debugger/init_kinetis.tcl @@ -0,0 +1,71 @@ +# this method initializes debug modules which are not affected by software reset +# register names should be referenced including the register group name to improve performance + +proc init_debug_modules {} { + # initialize LR to avoid invalid stack after reset + reg "User\\/System Mode Registers/LR" = 0xFFFFFFFF + + # clear DWT function registers + reg "Core Debug Registers/DEMCR" = 0x1000001 + reg "Data Watchpoint and Trace Unit Registers/DWT_FUNCTION0" = 0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_FUNCTION1" = 0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_FUNCTION2" = 0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_FUNCTION3" = 0x0 + # clear FPB comparators + reg "Flash Patch and Breakpoint Unit Registers/FP_COMP0" = 0x0 + reg "Flash Patch and Breakpoint Unit Registers/FP_COMP1" = 0x0 + reg "Flash Patch and Breakpoint Unit Registers/FP_COMP2" = 0x0 + reg "Flash Patch and Breakpoint Unit Registers/FP_COMP3" = 0x0 + reg "Flash Patch and Breakpoint Unit Registers/FP_COMP4" = 0x0 + reg "Flash Patch and Breakpoint Unit Registers/FP_COMP5" = 0x0 +} + +proc init_trace_modules {} { + # clear DWT registers + reg "Data Watchpoint and Trace Unit Registers/DWT_CTRL" =0x40000000 + reg "Data Watchpoint and Trace Unit Registers/DWT_CYCCNT" =0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_CPICNT" =0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_EXCCNT" =0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_SLEEPCNT" =0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_LSUCNT" =0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_FOLDCNT" =0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_COMP0" =0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_COMP1" =0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_COMP2" =0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_COMP3" =0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_MASK0" =0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_MASK1" =0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_MASK2" =0x0 + reg "Data Watchpoint and Trace Unit Registers/DWT_MASK3" =0x0 + # clear ITM registers + reg "Instrumentation Trace Macrocell Registers/ITM_LAR" =0xc5acce55 + reg "Instrumentation Trace Macrocell Registers/ITM_TER" =0x0 + reg "Instrumentation Trace Macrocell Registers/ITM_TPR" =0x0 + reg "Instrumentation Trace Macrocell Registers/ITM_TCR" =0x0 + reg "Instrumentation Trace Macrocell Registers/ITM_LAR" =0x1 + # reset Funnel registers + reg "Embedded Trace Funnel Registers/ETF_FCR" =0x300 + # clear MCM registers + reg "Core Platform Miscellaneous Control Module (MCM) Registers/MCM_ETBCC" =0x0 + reg "Core Platform Miscellaneous Control Module (MCM) Registers/MCM_ETBRL" =0x0 + # set SCB_VTOR register for RAM + reg "System Control Registers/SCB_VTOR" =0x20000000 +} + +proc envsetup {} { + # Environment Setup + radix x + config hexprefix 0x + config MemIdentifier p + config MemWidth 32 + config MemAccess 32 + config MemSwap off +} + +#------------------------------------------------------------------------------- +# Main +#------------------------------------------------------------------------------- + + envsetup + init_debug_modules + init_trace_modules diff --git a/mqx/cyassl_client/Debugger/mass_erase_kinetis.tcl b/mqx/cyassl_client/Debugger/mass_erase_kinetis.tcl new file mode 100755 index 000000000..2d8b84054 --- /dev/null +++ b/mqx/cyassl_client/Debugger/mass_erase_kinetis.tcl @@ -0,0 +1,31 @@ +# This script performs the mass erase operation for Kinetis targets + +# Command mass erase with system reset and core reset +set mdmapControl [cmdwin::reg MDMAP_C -np] +set mdmapControl [expr $mdmapControl | 0x19] +cmdwin::reg MDMAP_C = $mdmapControl + +# Release system reset while still holding core reset +set mdmapControl [expr $mdmapControl & 0xFFFFFFF7] +cmdwin::reg MDMAP_C = $mdmapControl + +# Wait for the mass erase operation to complete +set done 0 +for {set i 0} {$i < 10} {incr i} { + refresh + set mdmapControl [cmdwin::reg MDMAP_C -np] + if {($mdmapControl & 1) == 0} { + set done 1 + break; + } + wait 50 +} + +# Release the core reset +set mdmapControl [expr $mdmapControl & 0xFFFFFFEF] +cmdwin::reg MDMAP_C = $mdmapControl +if {$done} { + puts "OK: Mass erase succeeded" +} else { + puts "Error: Timeout" +} \ No newline at end of file diff --git a/mqx/cyassl_client/ReferencedRSESystems.xml b/mqx/cyassl_client/ReferencedRSESystems.xml index 0f4419bd0..8c233abc5 100644 --- a/mqx/cyassl_client/ReferencedRSESystems.xml +++ b/mqx/cyassl_client/ReferencedRSESystems.xml @@ -5,12 +5,12 @@ This file is automatically generated and updated by the Eclipse IDE.--> - + - + - + @@ -22,7 +22,7 @@ This file is automatically generated and updated by the Eclipse IDE.--> - + @@ -30,17 +30,17 @@ This file is automatically generated and updated by the Eclipse IDE.--> - - + + - + - + @@ -51,8 +51,8 @@ This file is automatically generated and updated by the Eclipse IDE.--> - - + + @@ -68,8 +68,160 @@ This file is automatically generated and updated by the Eclipse IDE.--> - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -77,9 +229,9 @@ This file is automatically generated and updated by the Eclipse IDE.--> - + - + @@ -91,7 +243,7 @@ This file is automatically generated and updated by the Eclipse IDE.--> - + @@ -99,17 +251,17 @@ This file is automatically generated and updated by the Eclipse IDE.--> - - + + - + - + @@ -120,8 +272,8 @@ This file is automatically generated and updated by the Eclipse IDE.--> - - + + @@ -137,8 +289,8 @@ This file is automatically generated and updated by the Eclipse IDE.--> - - + + \ No newline at end of file diff --git a/mqx/cyassl_client/Sources/include.am b/mqx/cyassl_client/Sources/include.am index dd4b2ffd9..de5221e49 100644 --- a/mqx/cyassl_client/Sources/include.am +++ b/mqx/cyassl_client/Sources/include.am @@ -5,9 +5,16 @@ EXTRA_DIST += \ mqx/cyassl_client/.cproject \ mqx/cyassl_client/.project \ + mqx/cyassl_client/K70FN1M0.mem \ + mqx/cyassl_client/init_kinetis.tcl \ + mqx/cyassl_client/mass_erase_kinetis.tcl \ mqx/cyassl_client/ReferencedRSESystems.xml \ - mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch \ - mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launch + mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_DDRData_Debug_PnE U-MultiLink.launch \ + mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_DDRData_Release_PnE U-MultiLink.launch \ + mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink \ + mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch \ + mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE U-MultiLink.launch \ + mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Release_PnE U-MultiLink.launch EXTRA_DIST += \ mqx/cyassl_client/Sources/main.c \ diff --git a/mqx/cyassl_client/Sources/main.c b/mqx/cyassl_client/Sources/main.c index 3938a87ac..5521ba2a8 100644 --- a/mqx/cyassl_client/Sources/main.c +++ b/mqx/cyassl_client/Sources/main.c @@ -1,239 +1,291 @@ -/* - * main.c - */ - -#include "main.h" -#include "util.h" - -#if !BSPCFG_ENABLE_IO_SUBSYSTEM -#error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined \ - non-zero in user_config.h. Please recompile BSP with this option. -#endif - -#ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED -#error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. \ - Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in \ - user_config.h and recompile BSP with this option. -#endif - -#if defined BSP_SDCARD_ESDHC_CHANNEL -#if ! BSPCFG_ENABLE_ESDHC -#error This application requires BSPCFG_ENABLE_ESDHC defined non-zero in \ - user_config.h. Please recompile libraries with this option. -#endif - -#elif defined BSP_SDCARD_SDHC_CHANNEL - -#if ! BSPCFG_ENABLE_SDHC -#error This application requires BSPCFG_ENABLE_SDHC defined non-zero in \ - user_config.h. Please recompile libraries with this option. -#endif - -#endif - -#if defined (BSP_SDCARD_SPI_CHANNEL) - #define SDCARD_COM_CHANNEL BSP_SDCARD_SPI_CHANNEL -#elif defined (BSP_SDCARD_ESDHC_CHANNEL) - #define SDCARD_COM_CHANNEL BSP_SDCARD_ESDHC_CHANNEL -#elif defined (BSP_SDCARD_SDHC_CHANNEL) - #define SDCARD_COM_CHANNEL BSP_SDCARD_SDHC_CHANNEL -#else - #error "SDCARD low level communication device not defined!" -#endif - -TASK_TEMPLATE_STRUCT MQX_template_list[] = -{ -/* Task number, Entry point, Stack, Pri, String, Auto? */ - {MAIN_TASK, Main_task, 20000, 9, "main", MQX_AUTO_START_TASK}, - {0, 0, 0, 0, 0, 0, } -}; - -/*TASK*----------------------------------------------------- -* -* Task Name : Main_task -* Comments : -* This task sets up the SD card and Ethernet devices, -* then starts the example CyaSSL client. The example -* CyaSSL client connects to a server over SSL and sends -* a simple HTTP GET message, then prints out the reply -* from the server. -* -* To change the IP address and port of the server, -* change the yasslIP and yasslPort variables in -* client_test(). Note that yasslIP needs to be given -* in hexadecimal. -* -*END*-----------------------------------------------------*/ - -void Main_task(uint_32 initial_data) -{ - int ret = 0; - _mqx_int error_code, bytes; - _mqx_uint param; - _mqx_uint sz; - MQX_FILE_PTR com_handle, sdcard_handle, filesystem_handle, partman_handle; - MQX_FILE_PTR cert_file = NULL; - char filesystem_name[] = "a:"; - char partman_name[] = "pm:"; - const char* fileName = "a:\certs\\client-key.der"; - - printf("Starting client example... \n"); - - ret = sdcard_open(&com_handle, &sdcard_handle, &partman_handle, - &filesystem_handle, partman_name, filesystem_name); - - if (ret != 0) { - printf("error: sdcard_open(), ret = %d\n", ret); - _mqx_exit(1); - } - printf("SD card installed to %s\n", filesystem_name); - - setup_ethernet(); - client_test(); - - ret = sdcard_close(&sdcard_handle, &partman_handle, &filesystem_handle, - partman_name, filesystem_name); - - if (ret != 0) { - printf("error: sdcard_close(), ret = %d\n", ret); - _mqx_exit(1); - } - printf("SD card uninstalled.\n"); - - _mqx_exit(0); -} - -void setup_ethernet(void) { - - int error; - _enet_handle ehandle; /* for Ethernet driver */ - _rtcs_if_handle ihandle; - _enet_address address; - - error = RTCS_create(); - if (error) { - err_sys("failed to create RTCS"); - } - - ENET_get_mac_address(BSP_DEFAULT_ENET_DEVICE, ENET_IPADDR, address); - - /* Set up the Ethernet driver */ - error = ENET_initialize(BSP_DEFAULT_ENET_DEVICE, address, 0, &ehandle); - if (error) - err_sys("failed to initialize Ethernet driver"); - - error = RTCS_if_add(ehandle, RTCS_IF_ENET, &ihandle); - if (error) - err_sys("failed to add interface for Ethernet"); - - error = RTCS_if_bind(ihandle, ENET_IPADDR, ENET_IPMASK); - if (error) - err_sys("failed to bind interface for Ethernet"); - -#ifdef GATE_IPADDR - RTCS_gate_add(GATE_IPADDR, INADDR_ANY, INADDR_ANY); -#endif - - printf("Ethernet device %d bound to %X\n", BSP_DEFAULT_ENET_DEVICE, - ENET_IPADDR); -} - -void client_test(void) { - - char msg[64]; - char reply[1024]; - int sockfd, input; - int ret = 0, msgSz = 0; - struct sockaddr_in servaddr; - CYASSL_CTX* ctx; - CYASSL* ssl; - - long yasslIP = 0xa9fea662; /* 169.254.166.98 */ - long yasslPort = 11111; - - CyaSSL_Debugging_ON(); - CyaSSL_Init(); - - ctx = CyaSSL_CTX_new(CyaSSLv3_client_method()); - - if (ctx == 0) - err_sys("setting up ctx"); - - ret = CyaSSL_CTX_use_certificate_file(ctx, clientCert, SSL_FILETYPE_PEM); - if (ret != SSL_SUCCESS) { - err_sys("can't load client cert file, check file"); - } - - ret = CyaSSL_CTX_use_PrivateKey_file(ctx, clientKey, SSL_FILETYPE_PEM); - if (ret != SSL_SUCCESS) { - err_sys("can't load client key file, check file"); - } - - ret = CyaSSL_CTX_load_verify_locations(ctx, caCert, 0); - if (ret != SSL_SUCCESS) { - err_sys("can't load CA cert file, check file"); - } - - /* create socket descriptor */ - sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd == RTCS_SOCKET_ERROR) { - err_sys("socket creation failed"); - } else { - printf("socket created successfully\n"); - } - - /* Unlike most TCP/IP stacks, RTCS requires that sin_port and - * sin_addr needs to be in Host Byte Order, not Network Byte Order. - * This means we shouldn't use htons() when setting these values. */ - memset((char*)&servaddr, 0, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_port = yasslPort; - servaddr.sin_addr.s_addr = yasslIP; - - ret = connect(sockfd, &servaddr, sizeof(servaddr)); - if (ret != RTCS_OK) { - err_sys("connect() failed"); - } else { - printf("Connected to %lx, port %d.\n", servaddr.sin_addr.s_addr, - servaddr.sin_port); - } - - if( (ssl = CyaSSL_new(ctx)) == NULL) { - err_sys("CyaSSL_new failed"); - } - - CyaSSL_set_fd(ssl, sockfd); - - ret = CyaSSL_connect(ssl); - if (ret != SSL_SUCCESS) - err_sys("CyaSSL_connect failed"); - - printf("CyaSSL_connect() ok, sending GET...\n"); - msgSz = 28; - strncpy(msg, "GET /index.html HTTP/1.0\r\n\r\n", msgSz); - if (CyaSSL_write(ssl, msg, msgSz) != msgSz) - err_sys("CyaSSL_write() failed"); - - input = CyaSSL_read(ssl, reply, sizeof(reply)-1); - if (input > 0) { - reply[input] = 0; - printf("Server response: %s\n", reply); - - while(1) { - input = CyaSSL_read(ssl, reply, sizeof(reply)-1); - if (input > 0) { - reply[input] = 0; - printf("%s\n", reply); - } else { - break; - } - } - } - - CyaSSL_shutdown(ssl); - CyaSSL_free(ssl); - CyaSSL_CTX_free(ctx); - CyaSSL_Cleanup(); -} - -/* EOF */ +/* + * main.c + */ + +#include "main.h" +#include "util.h" + +#if !BSPCFG_ENABLE_IO_SUBSYSTEM +#error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined \ + non-zero in user_config.h. Please recompile BSP with this option. +#endif + +#ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED +#error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. \ + Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in \ + user_config.h and recompile BSP with this option. +#endif + +#if defined BSP_SDCARD_ESDHC_CHANNEL +#if ! BSPCFG_ENABLE_ESDHC +#error This application requires BSPCFG_ENABLE_ESDHC defined non-zero in \ + user_config.h. Please recompile libraries with this option. +#endif + +#elif defined BSP_SDCARD_SDHC_CHANNEL + +#if ! BSPCFG_ENABLE_SDHC +#error This application requires BSPCFG_ENABLE_SDHC defined non-zero in \ + user_config.h. Please recompile libraries with this option. +#endif + +#endif + +#if defined (BSP_SDCARD_SPI_CHANNEL) + #define SDCARD_COM_CHANNEL BSP_SDCARD_SPI_CHANNEL +#elif defined (BSP_SDCARD_ESDHC_CHANNEL) + #define SDCARD_COM_CHANNEL BSP_SDCARD_ESDHC_CHANNEL +#elif defined (BSP_SDCARD_SDHC_CHANNEL) + #define SDCARD_COM_CHANNEL BSP_SDCARD_SDHC_CHANNEL +#else + #error "SDCARD low level communication device not defined!" +#endif + +TASK_TEMPLATE_STRUCT MQX_template_list[] = +{ + /* Task number, Entry point, Stack, Pri, String, Auto? */ + {MAIN_TASK, Main_task, 20000, 9, "main", MQX_AUTO_START_TASK}, + {0, 0, 0, 0, 0, 0, } +}; + +/*TASK*----------------------------------------------------- + * + * Task Name : Main_task + * Comments : + * This task sets up the SD card and Ethernet devices, + * then starts the example CyaSSL client. The example + * CyaSSL client connects to a server over SSL and sends + * a simple HTTP GET message, then prints out the reply + * from the server. + * + * To change the IP address and port of the server, + * change the yasslIP and yasslPort variables in + * client_test(). Note that yasslIP needs to be given + * in hexadecimal. + * + *END*-----------------------------------------------------*/ + +void Main_task(uint32_t initial_data) +{ + int ret = 0; + char filesystem_name[] = "a:"; + char partman_name[] = "pm:"; + MQX_FILE_PTR com_handle, sdcard_handle, filesystem_handle, partman_handle; + + printf("Starting client example... \n"); + + ret = sdcard_open(&com_handle, &sdcard_handle, &partman_handle, + &filesystem_handle, partman_name, filesystem_name); + + if (ret != 0) { + printf("error: sdcard_open(), ret = %d\n", ret); + _mqx_exit(1); + } + printf("SD card installed to %s\n", filesystem_name); + + setup_ethernet(); + setup_clock(); + client_test(); + + ret = sdcard_close(&sdcard_handle, &partman_handle, &filesystem_handle, + partman_name, filesystem_name); + + if (ret != 0) { + printf("error: sdcard_close(), ret = %d\n", ret); + _mqx_exit(1); + } + printf("SD card uninstalled.\n"); + + _mqx_exit(0); +} + +void setup_ethernet(void) +{ + int error; + _enet_handle ehandle; /* for Ethernet driver */ + _rtcs_if_handle ihandle; + _enet_address address; + + error = RTCS_create(); + if (error) { + err_sys("failed to create RTCS"); + } + + ENET_get_mac_address(BSP_DEFAULT_ENET_DEVICE, ENET_IPADDR, address); + + /* Set up the Ethernet driver */ + error = ENET_initialize(BSP_DEFAULT_ENET_DEVICE, address, 0, &ehandle); + if (error) + err_sys("failed to initialize Ethernet driver"); + + error = RTCS_if_add(ehandle, RTCS_IF_ENET, &ihandle); + if (error) + err_sys("failed to add interface for Ethernet"); + + error = RTCS_if_bind(ihandle, ENET_IPADDR, ENET_IPMASK); + if (error) + err_sys("failed to bind interface for Ethernet"); + +#ifdef GATE_IPADDR + RTCS_gate_add(GATE_IPADDR, INADDR_ANY, INADDR_ANY); +#endif + + printf("Ethernet device %d bound to %X\n", BSP_DEFAULT_ENET_DEVICE, + ENET_IPADDR); +} + +void setup_clock(void) +{ + uint32_t ret = 0, i = 0; + uint32_t sntp_connected = 0; + uint32_t sntp_max_tries = 3; + TIME_STRUCT time_s; + DATE_STRUCT date_s; + + /* NTP server: nist1-lnk.binary.net */ + _ip_address ipaddr = IPADDR(216,229,0,179); + + for (i = 0; i < sntp_max_tries; i++) { + + printf("Getting time from NTP server [ attempt %d of %d ]...\n", + i+1, sntp_max_tries); + + /* update time from NTP server */ + ret = SNTP_oneshot(ipaddr, 5000); + + if (ret == RTCS_OK) { + sntp_connected = 1; + printf("SNTP successfully updated device time\n"); + break; + } else if (ret == RTCSERR_TIMEOUT) { + printf("SNTP attempt timed out.\n"); + } + + _time_delay(1000); + } + + if (sntp_connected == 0) { + err_sys("SNTP failed to update device time"); + } + + /* print device time, for debug purposes */ + _time_get(&time_s); + _time_to_date(&time_s, &date_s); + printf("Current time: %02d/%02d/%02d %02d:%02d:%02d\n", + date_s.YEAR, date_s.MONTH, date_s.DAY, date_s.HOUR, date_s.MINUTE, + date_s.SECOND); + + return; +} + +int myVerify(int preverify, CYASSL_X509_STORE_CTX* store) +{ + (void)preverify; + char buffer[80]; + + printf("In verification callback, error = %d, %s\n", + store->error, CyaSSL_ERR_error_string(store->error, buffer)); + + return 0; +} + +void client_test(void) +{ + char msg[64]; + char reply[1024]; + int sockfd, input; + int ret = 0, msgSz = 0; + struct sockaddr_in servaddr; + CYASSL_CTX* ctx; + CYASSL* ssl; + + long yasslIP = IPADDR(192,168,1,125); + long yasslPort = 11111; + + /* for debug, compile CyaSSL with DEBUG_CYASSL defined */ + CyaSSL_Debugging_ON(); + + CyaSSL_Init(); + + ctx = CyaSSL_CTX_new(CyaTLSv1_2_client_method()); + if (ctx == 0) + err_sys("setting up ctx"); + + CyaSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify); + + ret = CyaSSL_CTX_use_certificate_file(ctx, clientCert, SSL_FILETYPE_PEM); + if (ret != SSL_SUCCESS) + err_sys("can't load client cert file, check file"); + + ret = CyaSSL_CTX_use_PrivateKey_file(ctx, clientKey, SSL_FILETYPE_PEM); + if (ret != SSL_SUCCESS) + err_sys("can't load client key file, check file"); + + ret = CyaSSL_CTX_load_verify_locations(ctx, caCert, 0); + if (ret != SSL_SUCCESS) + err_sys("can't load CA cert file, check file"); + + /* create socket descriptor */ + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd == RTCS_SOCKET_ERROR) { + err_sys("socket creation failed"); + } else { + printf("socket created successfully\n"); + } + + /* + * Unlike most TCP/IP stacks, RTCS requires that sin_port and + * sin_addr needs to be in Host Byte Order, not Network Byte Order. + * This means we shouldn't use htons() when setting these values. + */ + memset((char*)&servaddr, 0, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_port = yasslPort; + servaddr.sin_addr.s_addr = yasslIP; + + ret = connect(sockfd, &servaddr, sizeof(servaddr)); + if (ret != RTCS_OK) { + err_sys("connect() failed"); + } else { + printf("Connected to %lx, port %d.\n", servaddr.sin_addr.s_addr, + servaddr.sin_port); + } + + if ( (ssl = CyaSSL_new(ctx)) == NULL) + err_sys("CyaSSL_new failed"); + + CyaSSL_set_fd(ssl, sockfd); + + ret = CyaSSL_connect(ssl); + if (ret != SSL_SUCCESS) + err_sys("CyaSSL_connect failed"); + + printf("CyaSSL_connect() ok, sending GET...\n"); + msgSz = 28; + strncpy(msg, "GET /index.html HTTP/1.0\r\n\r\n", msgSz); + if (CyaSSL_write(ssl, msg, msgSz) != msgSz) + err_sys("CyaSSL_write() failed"); + + input = CyaSSL_read(ssl, reply, sizeof(reply)-1); + if (input > 0) { + reply[input] = 0; + printf("Server response: %s\n", reply); + + while (1) { + input = CyaSSL_read(ssl, reply, sizeof(reply)-1); + if (input > 0) { + reply[input] = 0; + printf("%s\n", reply); + } else { + break; + } + } + } + + CyaSSL_shutdown(ssl); + CyaSSL_free(ssl); + CyaSSL_CTX_free(ctx); + CyaSSL_Cleanup(); +} + +/* EOF */ diff --git a/mqx/cyassl_client/Sources/main.h b/mqx/cyassl_client/Sources/main.h index 91c11b339..a00516ebb 100644 --- a/mqx/cyassl_client/Sources/main.h +++ b/mqx/cyassl_client/Sources/main.h @@ -10,52 +10,51 @@ #include #include #include -#include #include #include #include -#define MAIN_TASK 1 +#define MAIN_TASK 1 -extern void Main_task(uint_32); +extern void Main_task(uint32_t); extern void setup_ethernet(void); +extern void setup_clock(void); extern void client_test(void); /* cert file locations */ -static const char* fileName = "a:\certs\\ca-cert.pem"; -static const char* caCert = "a:\certs\\ca-cert.pem"; -static const char* clientCert = "a:\certs\\client-cert.pem"; -static const char* clientKey = "a:\certs\\client-key.pem"; +static const char* caCert = "a:\\certs\\ca-cert.pem"; +static const char* clientCert = "a:\\certs\\client-cert.pem"; +static const char* clientKey = "a:\\certs\\client-key.pem"; static inline void err_sys(const char* msg) { - printf("yassl error: %s\n", msg); - if (msg) - _mqx_exit(1); + printf("yassl error: %s\n", msg); + if (msg) + _mqx_exit(1); } /* PPP device must be set manually and -** must be different from the default IO channel (BSP_DEFAULT_IO_CHANNEL) -*/ + * must be different from the default IO channel (BSP_DEFAULT_IO_CHANNEL) + */ #define PPP_DEVICE "ittyb:" /* -** Define PPP_DEVICE_DUN only when using PPP to communicate -** to Win9x Dial-Up Networking over a null-modem -** This is ignored if PPP_DEVICE is not #define'd -*/ + * Define PPP_DEVICE_DUN only when using PPP to communicate + * to Win9x Dial-Up Networking over a null-modem + * This is ignored if PPP_DEVICE is not #define'd + */ #define PPP_DEVICE_DUN 1 #ifndef ENET_IPADDR - #define ENET_IPADDR IPADDR(169,254,3,3) + #define ENET_IPADDR IPADDR(192,168,1,155) #endif #ifndef ENET_IPMASK - #define ENET_IPMASK IPADDR(255,255,0,0) + #define ENET_IPMASK IPADDR(255,255,255,0) #endif -#define GATE_IPADDR IPADDR(192,168,0,1) +#define GATE_IPADDR IPADDR(192,168,1,1) #endif /* __main_h_ */ diff --git a/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_DDRData_Debug_PnE U-MultiLink.launch b/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_DDRData_Debug_PnE U-MultiLink.launch new file mode 100644 index 000000000..7c99f0cbe --- /dev/null +++ b/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_DDRData_Debug_PnE U-MultiLink.launch @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_DDRData_Release_PnE U-MultiLink.launch b/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_DDRData_Release_PnE U-MultiLink.launch new file mode 100644 index 000000000..4c10ed99b --- /dev/null +++ b/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_DDRData_Release_PnE U-MultiLink.launch @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink b/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink new file mode 100644 index 000000000..f40a58f1c --- /dev/null +++ b/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink @@ -0,0 +1,34 @@ +[BREAKPOINTS] +ShowInfoWin = 1 +EnableFlashBP = 2 +BPDuringExecution = 0 +[CFI] +CFISize = 0x00 +CFIAddr = 0x00 +[CPU] +OverrideMemMap = 0 +AllowSimulation = 1 +ScriptFile="" +[FLASH] +CacheExcludeSize = 0x00 +CacheExcludeAddr = 0x00 +MinNumBytesFlashDL = 0 +SkipProgOnCRCMatch = 1 +VerifyDownload = 1 +AllowCaching = 1 +EnableFlashDL = 2 +Override = 0 +Device="UNSPECIFIED" +[GENERAL] +WorkRAMSize = 0x00 +WorkRAMAddr = 0x00 +RAMUsageLimit = 0x00 +[SWO] +SWOLogFile="" +[MEM] +RdOverrideOrMask = 0x00 +RdOverrideAndMask = 0xFFFFFFFF +RdOverrideAddr = 0xFFFFFFFF +WrOverrideOrMask = 0x00 +WrOverrideAndMask = 0xFFFFFFFF +WrOverrideAddr = 0xFFFFFFFF diff --git a/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launch b/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch similarity index 82% rename from mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launch rename to mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch index cff2bff7c..565be4d16 100644 --- a/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launch +++ b/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch @@ -1,164 +1,182 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE U-MultiLink.launch b/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE U-MultiLink.launch new file mode 100644 index 000000000..565be4d16 --- /dev/null +++ b/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE U-MultiLink.launch @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch b/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Release_PnE U-MultiLink.launch similarity index 87% rename from mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch rename to mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Release_PnE U-MultiLink.launch index 9aa53216f..35d123361 100644 --- a/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch +++ b/mqx/cyassl_client/cyassl_client_twrk70f120m_Int_Flash_SramData_Release_PnE U-MultiLink.launch @@ -1,162 +1,168 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +