Advertisement
Guest User

NonSecure main.c

a guest
Nov 23rd, 2023
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.86 KB | None | 0 0
  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.c
  5.   * @brief          : Main program body
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * Copyright (c) 2023 STMicroelectronics.
  10.   * All rights reserved.
  11.   *
  12.   * This software is licensed under terms that can be found in the LICENSE file
  13.   * in the root directory of this software component.
  14.   * If no LICENSE file comes with this software, it is provided AS-IS.
  15.   *
  16.   ******************************************************************************
  17.   */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "app_threadx.h"
  21. #include "main.h"
  22. #include "string.h"
  23.  
  24. /* Private includes ----------------------------------------------------------*/
  25. /* USER CODE BEGIN Includes */
  26.  
  27. /* USER CODE END Includes */
  28.  
  29. /* Private typedef -----------------------------------------------------------*/
  30. /* USER CODE BEGIN PTD */
  31.  
  32. /* USER CODE END PTD */
  33.  
  34. /* Private define ------------------------------------------------------------*/
  35. /* USER CODE BEGIN PD */
  36.  
  37. /* USER CODE END PD */
  38.  
  39. /* Private macro -------------------------------------------------------------*/
  40. /* USER CODE BEGIN PM */
  41.  
  42. /* USER CODE END PM */
  43.  
  44. /* Private variables ---------------------------------------------------------*/
  45.  
  46. ETH_TxPacketConfig TxConfig;
  47. ETH_DMADescTypeDef  DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */
  48. ETH_DMADescTypeDef  DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */
  49.  
  50. ETH_HandleTypeDef heth;
  51.  
  52. /* USER CODE BEGIN PV */
  53.  
  54. /* USER CODE END PV */
  55.  
  56. /* Private function prototypes -----------------------------------------------*/
  57. void SystemClock_Config(void);
  58. static void MX_GPIO_Init(void);
  59. static void MX_ETH_Init(void);
  60. /* USER CODE BEGIN PFP */
  61.  
  62. /* USER CODE END PFP */
  63.  
  64. /* Private user code ---------------------------------------------------------*/
  65. /* USER CODE BEGIN 0 */
  66.  
  67. /* USER CODE END 0 */
  68.  
  69. /**
  70.   * @brief  The application entry point.
  71.   * @retval int
  72.   */
  73. int main(void)
  74. {
  75.   /* USER CODE BEGIN 1 */
  76.  
  77.   /* USER CODE END 1 */
  78.  
  79.   /* MCU Configuration--------------------------------------------------------*/
  80.  
  81.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  82.   HAL_Init();
  83.  
  84.   /* USER CODE BEGIN Init */
  85.  
  86.   /* USER CODE END Init */
  87.  
  88.   /* Configure the system clock */
  89.   SystemClock_Config();
  90.  
  91.   /* USER CODE BEGIN SysInit */
  92.  
  93.   /* USER CODE END SysInit */
  94.  
  95.   /* Initialize all configured peripherals */
  96.   MX_GPIO_Init();
  97.   MX_ETH_Init();
  98.   /* USER CODE BEGIN 2 */
  99.  
  100.   /* USER CODE END 2 */
  101.  
  102.   MX_ThreadX_Init();
  103.  
  104.   /* We should never get here as control is now taken by the scheduler */
  105.   /* Infinite loop */
  106.   /* USER CODE BEGIN WHILE */
  107.   while (1)
  108.   {
  109.     /* USER CODE END WHILE */
  110.  
  111.     /* USER CODE BEGIN 3 */
  112.   }
  113.   /* USER CODE END 3 */
  114. }
  115.  
  116. /**
  117.   * @brief System Clock Configuration
  118.   * @retval None
  119.   */
  120. void SystemClock_Config(void)
  121. {
  122.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  123.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  124.  
  125.   /** Configure the main internal regulator output voltage
  126.   */
  127.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
  128.  
  129.   while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
  130.  
  131.   /** Initializes the RCC Oscillators according to the specified parameters
  132.   * in the RCC_OscInitTypeDef structure.
  133.   */
  134.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  135.   RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS_DIGITAL;
  136.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  137.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLL1_SOURCE_HSE;
  138.   RCC_OscInitStruct.PLL.PLLM = 5;
  139.   RCC_OscInitStruct.PLL.PLLN = 100;
  140.   RCC_OscInitStruct.PLL.PLLP = 2;
  141.   RCC_OscInitStruct.PLL.PLLQ = 2;
  142.   RCC_OscInitStruct.PLL.PLLR = 2;
  143.   RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1_VCIRANGE_2;
  144.   RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1_VCORANGE_WIDE;
  145.   RCC_OscInitStruct.PLL.PLLFRACN = 0;
  146.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  147.   {
  148.     Error_Handler();
  149.   }
  150.  
  151.   /** Initializes the CPU, AHB and APB buses clocks
  152.   */
  153.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  154.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
  155.                               |RCC_CLOCKTYPE_PCLK3;
  156.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  157.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  158.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  159.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  160.   RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;
  161.  
  162.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  163.   {
  164.     Error_Handler();
  165.   }
  166. }
  167.  
  168. /**
  169.   * @brief ETH Initialization Function
  170.   * @param None
  171.   * @retval None
  172.   */
  173. static void MX_ETH_Init(void)
  174. {
  175.  
  176.   /* USER CODE BEGIN ETH_Init 0 */
  177.  
  178.   /* USER CODE END ETH_Init 0 */
  179.  
  180.    static uint8_t MACAddr[6];
  181.  
  182.   /* USER CODE BEGIN ETH_Init 1 */
  183.  
  184.   /* USER CODE END ETH_Init 1 */
  185.   heth.Instance = ETH;
  186.   MACAddr[0] = 0x00;
  187.   MACAddr[1] = 0x80;
  188.   MACAddr[2] = 0xE1;
  189.   MACAddr[3] = 0x00;
  190.   MACAddr[4] = 0x00;
  191.   MACAddr[5] = 0x00;
  192.   heth.Init.MACAddr = &MACAddr[0];
  193.   heth.Init.MediaInterface = HAL_ETH_RMII_MODE;
  194.   heth.Init.TxDesc = DMATxDscrTab;
  195.   heth.Init.RxDesc = DMARxDscrTab;
  196.   heth.Init.RxBuffLen = 1536;
  197.  
  198.   /* USER CODE BEGIN MACADDRESS */
  199.  
  200.   /* USER CODE END MACADDRESS */
  201.  
  202.   if (HAL_ETH_Init(&heth) != HAL_OK)
  203.   {
  204.     Error_Handler();
  205.   }
  206.  
  207.   memset(&TxConfig, 0 , sizeof(ETH_TxPacketConfig));
  208.   TxConfig.Attributes = ETH_TX_PACKETS_FEATURES_CSUM | ETH_TX_PACKETS_FEATURES_CRCPAD;
  209.   TxConfig.ChecksumCtrl = ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC;
  210.   TxConfig.CRCPadCtrl = ETH_CRC_PAD_INSERT;
  211.   /* USER CODE BEGIN ETH_Init 2 */
  212.  
  213.   /* USER CODE END ETH_Init 2 */
  214.  
  215. }
  216.  
  217. /**
  218.   * @brief GPIO Initialization Function
  219.   * @param None
  220.   * @retval None
  221.   */
  222. static void MX_GPIO_Init(void)
  223. {
  224. /* USER CODE BEGIN MX_GPIO_Init_1 */
  225. /* USER CODE END MX_GPIO_Init_1 */
  226.  
  227.   /* GPIO Ports Clock Enable */
  228.   __HAL_RCC_GPIOG_CLK_ENABLE();
  229.   __HAL_RCC_GPIOH_CLK_ENABLE();
  230.   __HAL_RCC_GPIOC_CLK_ENABLE();
  231.   __HAL_RCC_GPIOA_CLK_ENABLE();
  232.  
  233. /* USER CODE BEGIN MX_GPIO_Init_2 */
  234. /* USER CODE END MX_GPIO_Init_2 */
  235. }
  236.  
  237. /* USER CODE BEGIN 4 */
  238.  
  239. /* USER CODE END 4 */
  240.  
  241. /**
  242.   * @brief  Period elapsed callback in non blocking mode
  243.   * @note   This function is called  when TIM6 interrupt took place, inside
  244.   * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  245.   * a global variable "uwTick" used as application time base.
  246.   * @param  htim : TIM handle
  247.   * @retval None
  248.   */
  249. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  250. {
  251.   /* USER CODE BEGIN Callback 0 */
  252.  
  253.   /* USER CODE END Callback 0 */
  254.   if (htim->Instance == TIM6) {
  255.     HAL_IncTick();
  256.   }
  257.   /* USER CODE BEGIN Callback 1 */
  258.  
  259.   /* USER CODE END Callback 1 */
  260. }
  261.  
  262. /**
  263.   * @brief  This function is executed in case of error occurrence.
  264.   * @retval None
  265.   */
  266. void Error_Handler(void)
  267. {
  268.   /* USER CODE BEGIN Error_Handler_Debug */
  269.   /* User can add his own implementation to report the HAL error return state */
  270.   __disable_irq();
  271.   while (1)
  272.   {
  273.   }
  274.   /* USER CODE END Error_Handler_Debug */
  275. }
  276.  
  277. #ifdef  USE_FULL_ASSERT
  278. /**
  279.   * @brief  Reports the name of the source file and the source line number
  280.   *         where the assert_param error has occurred.
  281.   * @param  file: pointer to the source file name
  282.   * @param  line: assert_param error line source number
  283.   * @retval None
  284.   */
  285. void assert_failed(uint8_t *file, uint32_t line)
  286. {
  287.   /* USER CODE BEGIN 6 */
  288.   /* User can add his own implementation to report the file name and line number,
  289.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  290.   /* USER CODE END 6 */
  291. }
  292. #endif /* USE_FULL_ASSERT */
  293.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement