mirror of https://github.com/wolfSSL/wolfssh.git
228 lines
5.7 KiB
C
228 lines
5.7 KiB
C
/* main.c
|
|
*
|
|
* Copyright (C) 2014-2024 wolfSSL Inc.
|
|
*
|
|
* This file is part of wolfSSH.
|
|
*
|
|
* wolfSSH is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* wolfSSH is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/* Example for main.c with STM32Cube/wolfssh_test.c */
|
|
|
|
#if 0 /* EXAMPLE main.c */
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "main.h"
|
|
#include "cmsis_os.h"
|
|
#include "lwip.h"
|
|
|
|
RNG_HandleTypeDef hrng;
|
|
|
|
UART_HandleTypeDef huart2;
|
|
|
|
/* Definitions for defaultTask */
|
|
osThreadId_t defaultTaskHandle;
|
|
const osThreadAttr_t defaultTask_attributes = {
|
|
.name = "defaultTask",
|
|
.stack_size = 128 * 4,
|
|
.priority = (osPriority_t) osPriorityNormal,
|
|
};
|
|
/* Definitions for myTask02 */
|
|
osThreadId_t myTask02Handle;
|
|
const osThreadAttr_t myTask02_attributes = {
|
|
.name = "myTask02",
|
|
.stack_size = 3000 * 4,
|
|
.priority = (osPriority_t) osPriorityLow,
|
|
};
|
|
|
|
void SystemClock_Config(void);
|
|
static void MX_GPIO_Init(void);
|
|
static void MX_RNG_Init(void);
|
|
static void MX_USART2_UART_Init(void);
|
|
void StartDefaultTask(void *argument);
|
|
extern void wolfSSHTest(void *argument);
|
|
|
|
/* Retargets the C library printf function to the USART. */
|
|
#include <stdio.h>
|
|
#ifdef __GNUC__
|
|
int __io_putchar(int ch)
|
|
#else
|
|
int fputc(int ch, FILE *f)
|
|
#endif
|
|
{
|
|
HAL_UART_Transmit(&huart2, (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)
|
|
{
|
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
HAL_Init();
|
|
|
|
/* USER CODE BEGIN Init */
|
|
setvbuf(stdin, NULL, _IONBF, 0);
|
|
setvbuf(stdout, NULL, _IONBF, 0);
|
|
setvbuf(stderr, NULL, _IONBF, 0);
|
|
/* USER CODE END Init */
|
|
|
|
/* Configure the system clock */
|
|
SystemClock_Config();
|
|
|
|
/* Initialize all configured peripherals */
|
|
MX_GPIO_Init();
|
|
MX_RNG_Init();
|
|
MX_USART2_UART_Init();
|
|
|
|
/* Init scheduler */
|
|
osKernelInitialize();
|
|
|
|
/* creation of defaultTask */
|
|
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
|
|
|
|
/* creation of myTask02 */
|
|
myTask02Handle = osThreadNew(wolfSSHTest, NULL, &myTask02_attributes);
|
|
|
|
/* Start scheduler */
|
|
osKernelStart();
|
|
|
|
/* Infinite loop */
|
|
while (1) {}
|
|
}
|
|
|
|
void SystemClock_Config(void)
|
|
{
|
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
|
|
/** Initializes the RCC Oscillators according to the specified parameters
|
|
* in the RCC_OscInitTypeDef structure.
|
|
*/
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
|
RCC_OscInitStruct.PLL.PLLM = 13;
|
|
RCC_OscInitStruct.PLL.PLLN = 195;
|
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
RCC_OscInitStruct.PLL.PLLQ = 5;
|
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/** Initializes the CPU, AHB and APB buses clocks
|
|
*/
|
|
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_3) != 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_USART2_UART_Init(void)
|
|
{
|
|
|
|
huart2.Instance = USART2;
|
|
huart2.Init.BaudRate = 115200;
|
|
huart2.Init.WordLength = UART_WORDLENGTH_8B;
|
|
huart2.Init.StopBits = UART_STOPBITS_1;
|
|
huart2.Init.Parity = UART_PARITY_NONE;
|
|
huart2.Init.Mode = UART_MODE_TX_RX;
|
|
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
if (HAL_UART_Init(&huart2) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
}
|
|
|
|
static void MX_GPIO_Init(void)
|
|
{
|
|
|
|
/* GPIO Ports Clock Enable */
|
|
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
__HAL_RCC_GPIOG_CLK_ENABLE();
|
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
|
|
}
|
|
|
|
|
|
void StartDefaultTask(void *argument)
|
|
{
|
|
/* init code for LWIP */
|
|
MX_LWIP_Init();
|
|
/* Infinite loop */
|
|
for(;;)
|
|
{
|
|
osDelay(1);
|
|
}
|
|
}
|
|
|
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
{
|
|
if (htim->Instance == TIM1) {
|
|
HAL_IncTick();
|
|
}
|
|
}
|
|
|
|
void Error_Handler(void)
|
|
{
|
|
__disable_irq();
|
|
while (1) {}
|
|
}
|
|
|
|
#ifdef USE_FULL_ASSERT
|
|
void assert_failed(uint8_t *file, uint32_t line)
|
|
{
|
|
/* User can add his own implementation to report the file name and line number,
|
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
}
|
|
#endif /* USE_FULL_ASSERT */
|
|
|
|
|
|
#endif /* EXAMPLE main.c */
|
|
|