123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- #if 0
- #include "wolfssl_example.h"
- #include "wolfssl/wolfcrypt/settings.h"
- CRYP_HandleTypeDef hcryp;
- __ALIGN_BEGIN static const uint32_t pKeyCRYP[6] __ALIGN_END = {
- 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000};
- HASH_HandleTypeDef hhash;
- RNG_HandleTypeDef hrng;
- RTC_HandleTypeDef hrtc;
- UART_HandleTypeDef huart4;
- #ifndef SINGLE_THREADED
- #ifdef CMSIS_OS2_H_
- osThreadId_t defaultTaskHandle;
- const osThreadAttr_t wolfCryptDemo_attributes = {
- .name = "wolfCryptDemo",
- .priority = (osPriority_t) osPriorityNormal,
- .stack_size = WOLF_EXAMPLES_STACK
- };
- #else
- osThreadId defaultTaskHandle;
- #endif
- #endif
- void SystemClock_Config(void);
- static void MX_GPIO_Init(void);
- static void MX_CRYP_Init(void);
- static void MX_HASH_Init(void);
- static void MX_RNG_Init(void);
- static void MX_UART4_Init(void);
- static void MX_RTC_Init(void);
- #include <stdio.h>
- #ifdef __GNUC__
- int __io_putchar(int ch)
- #else
- int fputc(int ch, FILE *f)
- #endif
- {
- HAL_UART_Transmit(&HAL_CONSOLE_UART, (uint8_t *)&ch, 1, 0xFFFF);
- return ch;
- }
- #ifdef __GNUC__
- int _write(int file,char *ptr, int len)
- {
- int DataIdx;
- for (DataIdx= 0; DataIdx< len; DataIdx++) {
- __io_putchar(*ptr++);
- }
- return len;
- }
- #endif
- int main(void)
- {
-
- HAL_Init();
-
- setvbuf(stdin, NULL, _IONBF, 0);
- setvbuf(stdout, NULL, _IONBF, 0);
- setvbuf(stderr, NULL, _IONBF, 0);
-
- SystemClock_Config();
-
- MX_GPIO_Init();
- MX_CRYP_Init();
- MX_HASH_Init();
- MX_RNG_Init();
- MX_UART4_Init();
- MX_RTC_Init();
- MX_SPI1_Init();
- MX_UART4_Init();
- #ifdef SINGLE_THREADED
- wolfCryptDemo(NULL);
- #else
-
- osKernelInitialize();
-
-
- #ifdef CMSIS_OS2_H_
- defaultTaskHandle = osThreadNew(wolfCryptDemo, NULL, &wolfCryptDemo_attributes);
- #else
- osThreadDef(defaultTask, wolfCryptDemo, osPriorityNormal, 0, WOLF_EXAMPLES_STACK);
- defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
- #endif
-
- osKernelStart();
-
-
- while (1) {}
- #endif
- }
- static void SystemClock_Config(void)
- {
- RCC_OscInitTypeDef RCC_OscInitStruct = {0};
- RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
- RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
-
- __HAL_RCC_PWR_CLK_ENABLE();
- __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
-
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
- RCC_OscInitStruct.HSIState = RCC_HSI_ON;
- RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
- RCC_OscInitStruct.LSIState = RCC_LSI_ON;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
- RCC_OscInitStruct.PLL.PLLM = 8;
- RCC_OscInitStruct.PLL.PLLN = 160;
- RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
- RCC_OscInitStruct.PLL.PLLQ = 7;
- if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
- Error_Handler();
- }
-
- RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
- RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
- if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) {
- Error_Handler();
- }
- PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
- PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
- if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
- Error_Handler();
- }
- }
- static void MX_CRYP_Init(void)
- {
- hcryp.Instance = CRYP;
- hcryp.Init.DataType = CRYP_DATATYPE_32B;
- hcryp.Init.pKey = (uint32_t *)pKeyCRYP;
- hcryp.Init.Algorithm = CRYP_TDES_ECB;
- hcryp.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
- if (HAL_CRYP_Init(&hcryp) != HAL_OK) {
- Error_Handler();
- }
- }
- static void MX_HASH_Init(void)
- {
- hhash.Init.DataType = HASH_DATATYPE_32B;
- if (HAL_HASH_Init(&hhash) != HAL_OK) {
- Error_Handler();
- }
- }
- static void MX_RNG_Init(void)
- {
- hrng.Instance = RNG;
- if (HAL_RNG_Init(&hrng) != HAL_OK) {
- Error_Handler();
- }
- }
- static void MX_RTC_Init(void)
- {
- RTC_TimeTypeDef sTime = {0};
- RTC_DateTypeDef sDate = {0};
-
- hrtc.Instance = RTC;
- hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
- hrtc.Init.AsynchPrediv = 127;
- hrtc.Init.SynchPrediv = 255;
- hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
- hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
- hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
- if (HAL_RTC_Init(&hrtc) != HAL_OK) {
- Error_Handler();
- }
-
- sTime.Hours = 0x0;
- sTime.Minutes = 0x0;
- sTime.Seconds = 0x0;
- sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
- sTime.StoreOperation = RTC_STOREOPERATION_RESET;
- if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK) {
- Error_Handler();
- }
- sDate.WeekDay = RTC_WEEKDAY_MONDAY;
- sDate.Month = RTC_MONTH_JANUARY;
- sDate.Date = 0x1;
- sDate.Year = 0x0;
- if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK) {
- Error_Handler();
- }
- }
- static void MX_UART4_Init(void)
- {
- huart4.Instance = UART4;
- huart4.Init.BaudRate = 115200;
- huart4.Init.WordLength = UART_WORDLENGTH_8B;
- huart4.Init.StopBits = UART_STOPBITS_1;
- huart4.Init.Parity = UART_PARITY_NONE;
- huart4.Init.Mode = UART_MODE_TX_RX;
- huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart4.Init.OverSampling = UART_OVERSAMPLING_16;
- if (HAL_UART_Init(&huart4) != HAL_OK) {
- Error_Handler();
- }
- }
- static void MX_GPIO_Init(void)
- {
-
- __HAL_RCC_GPIOC_CLK_ENABLE();
- }
-
- void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
- {
- if (htim->Instance == TIM1) {
- HAL_IncTick();
- }
- }
- void Error_Handler(void)
- {
-
- while(1)
- {
- }
- }
- #ifdef USE_FULL_ASSERT
- void assert_failed(uint8_t *file, uint32_t line)
- {
-
- }
- #endif
- #if 0
- extern uint8_t _end;
- extern uint8_t _estack;
- extern uint32_t _Min_Stack_Size;
- void* _sbrk(ptrdiff_t incr)
- {
- static uint8_t* __sbrk_heap_end = NULL;
- const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
- const uint8_t* max_heap = (uint8_t *)stack_limit;
- uint8_t* prev_heap_end;
-
- if (__sbrk_heap_end == NULL) {
- __sbrk_heap_end = &_end;
- }
-
- if (__sbrk_heap_end + incr > max_heap) {
- errno = ENOMEM;
- return (void *)-1;
- }
- prev_heap_end = __sbrk_heap_end;
- __sbrk_heap_end += incr;
- return (void*)prev_heap_end;
- }
- #endif
- #endif
|