From 379c6d0ad812369eed357786150c541d4ab60d7c Mon Sep 17 00:00:00 2001 From: Takashi Kojo Date: Mon, 1 Jan 2018 12:18:08 +0900 Subject: [PATCH] dummy RTC --- IDE/MDK5-ARM/Projects/CryptBenchmark/main.c | 34 +++-- IDE/MDK5-ARM/Projects/CryptTest/main.c | 67 ++++++++- IDE/MDK5-ARM/Projects/EchoClient/main.c | 151 ++++++++++++++++---- IDE/MDK5-ARM/Projects/EchoServer/main.c | 52 ++++--- IDE/MDK5-ARM/Projects/SimpleClient/main.c | 82 +++++------ IDE/MDK5-ARM/Projects/SimpleServer/main.c | 61 ++++---- 6 files changed, 317 insertions(+), 130 deletions(-) diff --git a/IDE/MDK5-ARM/Projects/CryptBenchmark/main.c b/IDE/MDK5-ARM/Projects/CryptBenchmark/main.c index 97a229aaf..a07918c8f 100644 --- a/IDE/MDK5-ARM/Projects/CryptBenchmark/main.c +++ b/IDE/MDK5-ARM/Projects/CryptBenchmark/main.c @@ -28,8 +28,20 @@ #include "wolfcrypt/test/test.h" #include +/* Dummy definition for test RTC */ +#define RTC_YEAR 2018 +#define RTC_MONTH 1 +#define RTC_DAY 1 + +#if defined(STM32F7xx) +#include "stm32f7xx_hal.h" +#elif defined(STM32F4xx) +#include "stm32f2xx_hal.h" +#elif defined(STM32F2xx) +#include "stm32f2xx_hal.h" +#endif + #warning "write MPU specific Set ups\n" - static void SystemClock_Config (void) { } @@ -42,18 +54,22 @@ static void CPU_CACHE_Enable (void) { } -extern uint32_t os_time; - #ifdef RTE_CMSIS_RTOS_RTX +extern uint32_t os_time; +static time_t epochTime; + uint32_t HAL_GetTick(void) { - return os_time; + return os_time; } -#endif time_t time(time_t *t){ - return os_time ; + return epochTime ; } +void setTime(time_t t){ + epochTime = t; +} +#endif #ifdef WOLFSSL_CURRTIME_OSTICK @@ -124,9 +140,11 @@ int main() HAL_Init(); /* Initialize the HAL Library */ SystemClock_Config(); /* Configure the System Clock */ - #if !defined(NO_FILESYSTEM) + #if !defined(NO_FILESYSTEM) init_filesystem (); - #endif + #endif + + setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60); printf("=== Start: Crypt Benchmark ===\n") ; benchmark_test(arg) ; diff --git a/IDE/MDK5-ARM/Projects/CryptTest/main.c b/IDE/MDK5-ARM/Projects/CryptTest/main.c index 8ab894134..386ce6609 100644 --- a/IDE/MDK5-ARM/Projects/CryptTest/main.c +++ b/IDE/MDK5-ARM/Projects/CryptTest/main.c @@ -28,9 +28,22 @@ #include "wolfcrypt/test/test.h" #include +#include + +/* Dummy definition for test RTC */ +#define RTC_YEAR 2018 +#define RTC_MONTH 1 +#define RTC_DAY 1 + +#if defined(STM32F7xx) +#include "stm32f7xx_hal.h" +#elif defined(STM32F4xx) +#include "stm32f2xx_hal.h" +#elif defined(STM32F2xx) +#include "stm32f2xx_hal.h" +#endif #warning "write MPU specific Set ups\n" - static void SystemClock_Config (void) { } @@ -43,6 +56,53 @@ static void CPU_CACHE_Enable (void) { } + +#ifdef RTE_CMSIS_RTOS_RTX +extern uint32_t os_time; +static time_t epochTime; + +uint32_t HAL_GetTick(void) { + return os_time; +} + +time_t time(time_t *t){ + return epochTime ; +} + +void setTime(time_t t){ + epochTime = t; +} +#endif +#ifdef WOLFSSL_CURRTIME_OSTICK + +#include +extern uint32_t os_time; + +double current_time(int reset) +{ + if(reset) os_time = 0 ; + return (double)os_time /1000.0; +} + +#else + +#include +#define DWT ((DWT_Type *) (0xE0001000UL) ) +typedef struct +{ + uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */ + uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */ +} DWT_Type; + +extern uint32_t SystemCoreClock ; + +double current_time(int reset) +{ + if(reset) DWT->CYCCNT = 0 ; + return ((double)DWT->CYCCNT/SystemCoreClock) ; +} +#endif + /*----------------------------------------------------------------------------- * Initialize a Flash Memory Card *----------------------------------------------------------------------------*/ @@ -68,13 +128,14 @@ static void init_filesystem (void) { } #endif + /*----------------------------------------------------------------------------- * mian entry *----------------------------------------------------------------------------*/ - int main() { void * arg = NULL ; + MPU_Config(); CPU_CACHE_Enable(); HAL_Init(); /* Initialize the HAL Library */ @@ -84,6 +145,8 @@ int main() init_filesystem (); #endif + setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60); + printf("=== Start: Crypt test === \n") ; wolfcrypt_test(arg) ; printf("=== End: Crypt test ===\n") ; diff --git a/IDE/MDK5-ARM/Projects/EchoClient/main.c b/IDE/MDK5-ARM/Projects/EchoClient/main.c index 37aab6c0e..f8014b496 100644 --- a/IDE/MDK5-ARM/Projects/EchoClient/main.c +++ b/IDE/MDK5-ARM/Projects/EchoClient/main.c @@ -23,39 +23,66 @@ #include #endif -#include -#include +#include "wolfssl/wolfcrypt/settings.h" +#include "cmsis_os.h" /* CMSIS RTOS definitions */ +#include "rl_net.h" /* Network definitions */ +#include + +#if defined(STM32F7xx) +#include "stm32f7xx_hal.h" +#elif defined(STM32F4xx) #include "stm32f2xx_hal.h" -#include "cmsis_os.h" -#include "rl_net.h" -#include +#elif defined(STM32F2xx) +#include "stm32f2xx_hal.h" +#endif -#include +//-------- <<< Use Configuration Wizard in Context Menu >>> ----------------- + +// RTC: for validate certificate date +// Year <1970-2099> +#define RTC_YEAR 2018 +// Month <1=>Jan<2=>Feb<3=>Mar<4=>Apr<5=>May<6=>Jun<7=>Jul<8=>Aut<9=>Sep<10=>Oct<11=>Nov<12=>Dec +#define RTC_MONTH 1 +// Day <1-31> +#define RTC_DAY 1 +// + +//------------- <<< end of configuration section >>> ----------------------- +#warning "write MPU specific Set ups\n" +static void SystemClock_Config (void) { + +} +#warning "write MPU specific Set ups\n" +static void SystemClock_Config (void) { + +} + +static void MPU_Config (void) { + +} + +static void CPU_CACHE_Enable (void) { -/*----------------------------------------------------------------------------- - * Initialize Clock Configuration - *----------------------------------------------------------------------------*/ -void SystemClock_Config(void) { - #warning "write MPU specific System Clock Set up\n" } /*----------------------------------------------------------------------------- * Initialize a Flash Memory Card *----------------------------------------------------------------------------*/ #if !defined(NO_FILESYSTEM) -#include "rl_fs.h" +#include "rl_fs.h" /* FileSystem definitions */ + static void init_filesystem (void) { int32_t retv; retv = finit ("M0:"); - if (retv == 0) { + if (retv == fsOK) { retv = fmount ("M0:"); - if (retv == 0) { + if (retv == fsOK) { printf ("Drive M0 ready!\n"); } else { - printf ("Drive M0 mount failed!\n"); + printf ("Drive M0 mount failed(%d)!\n", retv); } } else { @@ -64,6 +91,68 @@ static void init_filesystem (void) { } #endif + +void net_loop(void const *arg) +{ + while(1) { + net_main (); + osThreadYield (); + } +} + +osThreadDef(net_loop, osPriorityNormal, 2, 0); + +#ifdef RTE_CMSIS_RTOS_RTX +extern uint32_t os_time; +static time_t epochTime; + +uint32_t HAL_GetTick(void) { + return os_time; +} + +time_t time(time_t *t){ + return epochTime ; +} + +void setTime(time_t t){ + epochTime = t; +} +#endif + +#ifdef WOLFSSL_CURRTIME_OSTICK + +#include +extern uint32_t os_time; + +double current_time(int reset) +{ + if(reset) os_time = 0 ; + return (double)os_time /1000.0; +} + +#else + +#include +#define DWT ((DWT_Type *) (0xE0001000UL) ) +typedef struct +{ + uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */ + uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */ +} DWT_Type; + +extern uint32_t SystemCoreClock ; + +double current_time(int reset) +{ + if(reset) DWT->CYCCNT = 0 ; + return ((double)DWT->CYCCNT/SystemCoreClock) ; +} +#endif + +/*---------------------------------------------------------------------------- + Main Thread 'main': Run Network + *---------------------------------------------------------------------------*/ +#include typedef struct func_args { int argc; char** argv; @@ -71,30 +160,38 @@ typedef struct func_args { extern void echoclient_test(func_args * args) ; -/*----------------------------------------------------------------------------- - * mian entry - *----------------------------------------------------------------------------*/ int myoptind = 0; char* myoptarg = NULL; -int main() -{ - func_args args ; - args.argc = 1 ; +int main (void) { + static char *argv[] = + { "client" } ; + static func_args args = + { 1, argv } ; + + MPU_Config(); /* Configure the MPU */ + CPU_CACHE_Enable(); /* Enable the CPU Cache */ + HAL_Init(); /* Initialize the HAL Library */ + SystemClock_Config(); /* Configure the System Clock */ - SystemClock_Config (); #if !defined(NO_FILESYSTEM) init_filesystem (); #endif - netInitialize() ; - osDelay(300) ; + net_initialize (); + #if defined(DEBUG_WOLFSSL) printf("Turning ON Debug message\n") ; wolfSSL_Debugging_ON() ; #endif - printf("Starting EchoClient, Enter messages to EchoServer (\"quit\" to quit the program)\n") ; + setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60); + + osThreadCreate (osThread(net_loop), NULL); + echoclient_test(&args) ; - printf("End of EchoClient\n") ; + + while(1) + osDelay(1000); } + diff --git a/IDE/MDK5-ARM/Projects/EchoServer/main.c b/IDE/MDK5-ARM/Projects/EchoServer/main.c index 2b6fee08c..daab6aa30 100644 --- a/IDE/MDK5-ARM/Projects/EchoServer/main.c +++ b/IDE/MDK5-ARM/Projects/EchoServer/main.c @@ -29,6 +29,15 @@ #include "rl_net.h" /* Network definitions */ #include +#ifdef WOLFSSL_STM32_CUBEMX +#if defined(STM32F7xx) +#include "stm32f7xx_hal.h" +#elif defined(STM32F4xx) +#include "stm32f2xx_hal.h" +#elif defined(STM32F2xx) +#include "stm32f2xx_hal.h" +#endif +#endif //-------- <<< Use Configuration Wizard in Context Menu >>> ----------------- @@ -61,6 +70,19 @@ //------------- <<< end of configuration section >>> ----------------------- +#warning "write MPU specific Set ups\n" +static void SystemClock_Config (void) { + +} + +static void MPU_Config (void) { + +} + +static void CPU_CACHE_Enable (void) { + +} + /*----------------------------------------------------------------------------- * Initialize a Flash Memory Card @@ -98,23 +120,23 @@ void net_loop(void const *arg) osThreadDef(net_loop, osPriorityLow, 2, 0); - -extern uint32_t os_time; -static time_t epoctime = 0; - #ifdef RTE_CMSIS_RTOS_RTX +extern uint32_t os_time; +static time_t epochTime; + uint32_t HAL_GetTick(void) { - return os_time; + return os_time; } -#endif time_t time(time_t *t){ - return epoctime ; + return epochTime ; } void setTime(time_t t){ - epoctime = t;; + epochTime = t; } +#endif + #ifdef WOLFSSL_CURRTIME_OSTICK @@ -161,10 +183,7 @@ int myoptind = 0; char* myoptarg = NULL; int main (void) { - - struct tm *tm_gm; - time_t now; - static char *argv[] = + static char *argv[] = { "server" } ; static func_args args = { 1, argv } ; @@ -173,21 +192,18 @@ int main (void) { HAL_Init(); /* Initialize the HAL Library */ SystemClock_Config(); /* Configure the System Clock */ - setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60); - now = time(NULL); - tm_gm = gmtime(&now); - printf("RTC=%04d/%02d/%02d\n", tm_gm->tm_year + 1900, tm_gm->tm_mon + 1, tm_gm->tm_mday); - #if !defined(NO_FILESYSTEM) init_filesystem (); #endif net_initialize (); - #if defined(DEBUG_WOLFSSL) + #if defined(DEBUG_WOLFSSL) printf("Turning ON Debug message\n") ; wolfSSL_Debugging_ON() ; #endif + setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60); + osThreadCreate (osThread(net_loop), NULL); echoserver_test(&args) ; diff --git a/IDE/MDK5-ARM/Projects/SimpleClient/main.c b/IDE/MDK5-ARM/Projects/SimpleClient/main.c index 16c2304dc..09f8bcded 100644 --- a/IDE/MDK5-ARM/Projects/SimpleClient/main.c +++ b/IDE/MDK5-ARM/Projects/SimpleClient/main.c @@ -29,7 +29,13 @@ #include "rl_net.h" /* Network definitions */ #include +#if defined(STM32F7xx) #include "stm32f7xx_hal.h" +#elif defined(STM32F4xx) +#include "stm32f2xx_hal.h" +#elif defined(STM32F2xx) +#include "stm32f2xx_hal.h" +#endif //-------- <<< Use Configuration Wizard in Context Menu >>> ----------------- @@ -39,7 +45,7 @@ // IP Address // Static IPv4 Address // Default: "192.168.1.1" -#define REMOTE_IP "192.168.1.1" +#define REMOTE_IP "192.168.10.4" // Port // Default: "11111" @@ -66,9 +72,7 @@ // //------------- <<< end of configuration section >>> ----------------------- - #warning "write MPU specific Set ups\n" - static void SystemClock_Config (void) { } @@ -81,6 +85,7 @@ static void CPU_CACHE_Enable (void) { } + /*----------------------------------------------------------------------------- * Initialize a Flash Memory Card *----------------------------------------------------------------------------*/ @@ -115,25 +120,24 @@ void net_loop(void const *arg) } } -osThreadDef(net_loop, osPriorityNormal, 2, 0); - - -extern uint32_t os_time; -static time_t epoctime = 0; +osThreadDef(net_loop, osPriorityLow, 2, 0); #ifdef RTE_CMSIS_RTOS_RTX +extern uint32_t os_time; +static time_t epochTime; + uint32_t HAL_GetTick(void) { - return os_time; + return os_time; } -#endif time_t time(time_t *t){ - return epoctime ; + return epochTime ; } void setTime(time_t t){ - epoctime = t;; + epochTime = t; } +#endif #ifdef WOLFSSL_CURRTIME_OSTICK @@ -142,8 +146,8 @@ extern uint32_t os_time; double current_time(int reset) { - if(reset) os_time = 0 ; - return (double)os_time /1000.0; + if(reset) os_time = 0 ; + return (double)os_time /1000.0; } #else @@ -160,8 +164,8 @@ extern uint32_t SystemCoreClock ; double current_time(int reset) { - if(reset) DWT->CYCCNT = 0 ; - return ((double)DWT->CYCCNT/SystemCoreClock) ; + if(reset) DWT->CYCCNT = 0 ; + return ((double)DWT->CYCCNT/SystemCoreClock) ; } #endif @@ -180,53 +184,45 @@ int myoptind = 0; char* myoptarg = NULL; int main (void) { - - struct tm *tm_gm; - time_t now; - static char *argv[] = - { "client", "-h", REMOTE_IP, "-p", REMOTE_PORT, + static char *argv[] = + { "client", "-h", REMOTE_IP, "-p", REMOTE_PORT, "-v", " ", OTHER_OPTIONS } ; - static func_args args = - { sizeof(argv)/sizeof(*argv[0]), argv } ; + static func_args args = + { sizeof(argv)/sizeof(*argv[0]), argv } ; - char *verStr[] = { "SSL3", "TLS1.0", "TLS1.1", "TLS1.2", "TLS1.3"}; - #define VERSIZE 2 - char ver[VERSIZE]; - + char *verStr[] = { "SSL3", "TLS1.0", "TLS1.1", "TLS1.2", "TLS1.3"}; + #define VERSIZE 2 + char ver[VERSIZE]; + MPU_Config(); /* Configure the MPU */ CPU_CACHE_Enable(); /* Enable the CPU Cache */ - HAL_Init(); /* Initialize the HAL Library */ SystemClock_Config(); /* Configure the System Clock */ - setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60); - now = time(NULL); - tm_gm = gmtime(&now); - printf("RTC=%04d/%02d/%02d\n", tm_gm->tm_year + 1900, tm_gm->tm_mon + 1, tm_gm->tm_mday); - #if !defined(NO_FILESYSTEM) init_filesystem (); #endif net_initialize (); - #if defined(DEBUG_WOLFSSL) - printf("Turning ON Debug message\n") ; - wolfSSL_Debugging_ON() ; + #if defined(DEBUG_WOLFSSL) + printf("Turning ON Debug message\n") ; + wolfSSL_Debugging_ON() ; #endif snprintf(ver, VERSIZE, "%d", TLS_VER); argv[6] = ver; - printf("SSL/TLS Client(%d)\n ", sizeof(argv)/sizeof(argv[0])) ; + printf("SSL/TLS Client(%d)\n ", sizeof(argv)/sizeof(argv[0])) ; printf(" Remote IP: %s, Port: %s\n Version: %s\n", argv[2], argv[4], verStr[TLS_VER]) ; - printf(" Other options: %s\n", OTHER_OPTIONS); - - osThreadCreate (osThread(net_loop), NULL); + printf(" Other options: %s\n", OTHER_OPTIONS); + setTime((time_t)((RTC_YEAR-1970)*365*24*60*60) + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60); + + osThreadCreate (osThread(net_loop), NULL); client_test(&args) ; - - while(1) - osDelay(1000); + + while(1) + osDelay(1000); } diff --git a/IDE/MDK5-ARM/Projects/SimpleServer/main.c b/IDE/MDK5-ARM/Projects/SimpleServer/main.c index fdd14ecc3..8834ad39f 100644 --- a/IDE/MDK5-ARM/Projects/SimpleServer/main.c +++ b/IDE/MDK5-ARM/Projects/SimpleServer/main.c @@ -29,6 +29,13 @@ #include "rl_net.h" /* Network definitions */ #include +#if defined(STM32F7xx) +#include "stm32f7xx_hal.h" +#elif defined(STM32F4xx) +#include "stm32f2xx_hal.h" +#elif defined(STM32F2xx) +#include "stm32f2xx_hal.h" +#endif //-------- <<< Use Configuration Wizard in Context Menu >>> ----------------- @@ -60,9 +67,8 @@ // //------------- <<< end of configuration section >>> ----------------------- - + #warning "write MPU specific Set ups\n" - static void SystemClock_Config (void) { } @@ -111,23 +117,22 @@ void net_loop(void const *arg) osThreadDef(net_loop, osPriorityLow, 2, 0); - -extern uint32_t os_time; -static time_t epoctime = 0; - #ifdef RTE_CMSIS_RTOS_RTX +extern uint32_t os_time; +static time_t epochTime; + uint32_t HAL_GetTick(void) { - return os_time; + return os_time; } -#endif time_t time(time_t *t){ - return epoctime ; + return epochTime ; } void setTime(time_t t){ - epoctime = t;; + epochTime = t; } +#endif #ifdef WOLFSSL_CURRTIME_OSTICK @@ -154,8 +159,8 @@ extern uint32_t SystemCoreClock ; double current_time(int reset) { - if(reset) DWT->CYCCNT = 0 ; - return ((double)DWT->CYCCNT/SystemCoreClock) ; + if(reset) DWT->CYCCNT = 0 ; + return ((double)DWT->CYCCNT/SystemCoreClock) ; } #endif @@ -174,38 +179,29 @@ int myoptind = 0; char* myoptarg = NULL; int main (void) { - - struct tm *tm_gm; - time_t now; - static char *argv[] = - { "server", "-p", SERVER_PORT, - "-v", " ", OTHER_OPTIONS } ; - static func_args args = - { sizeof(argv)/sizeof(*argv[0]), argv } ; + static char *argv[] = + { "server", "-p", SERVER_PORT, + "-v", " ", OTHER_OPTIONS } ; + static func_args args = + { sizeof(argv)/sizeof(*argv[0]), argv } ; - char *verStr[] = { "SSL3", "TLS1.0", "TLS1.1", "TLS1.2", "TLS1.3"}; - #define VERSIZE 2 - char ver[VERSIZE]; + char *verStr[] = { "SSL3", "TLS1.0", "TLS1.1", "TLS1.2", "TLS1.3"}; + #define VERSIZE 2 + char ver[VERSIZE]; MPU_Config(); /* Configure the MPU */ CPU_CACHE_Enable(); /* Enable the CPU Cache */ - HAL_Init(); /* Initialize the HAL Library */ SystemClock_Config(); /* Configure the System Clock */ - setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60); - now = time(NULL); - tm_gm = gmtime(&now); - printf("RTC=%04d/%02d/%02d\n", tm_gm->tm_year + 1900, tm_gm->tm_mon + 1, tm_gm->tm_mday); - #if !defined(NO_FILESYSTEM) init_filesystem (); #endif net_initialize (); - #if defined(DEBUG_WOLFSSL) - printf("Turning ON Debug message\n") ; - wolfSSL_Debugging_ON() ; + #if defined(DEBUG_WOLFSSL) + printf("Turning ON Debug message\n") ; + wolfSSL_Debugging_ON() ; #endif snprintf(ver, VERSIZE, "%d", TLS_VER); @@ -214,6 +210,7 @@ int main (void) { printf("SSL/TLS Server\n ") ; printf(" Server Port: %s\n Version: %s\n", argv[2], verStr[TLS_VER]) ; printf(" Other options: %s\n", OTHER_OPTIONS); + setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60); osThreadCreate (osThread(net_loop), NULL);