michalkowalczyk

Untitled

Apr 18th, 2021
465
149 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.   ******************************************************************************
  3.   * @file    GPIO/GPIO_IOToggle/Src/main.c
  4.   * @author  MCD Application Team
  5.   * @brief   This example describes how to configure and use GPIOs through
  6.   *          the STM32F4xx HAL API.
  7.   ******************************************************************************
  8.   * @attention
  9.   *
  10.   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  11.   * All rights reserved.</center></h2>
  12.   *
  13.   * This software component is licensed by ST under BSD 3-Clause license,
  14.   * the "License"; You may not use this file except in compliance with the
  15.   * License. You may obtain a copy of the License at:
  16.   *                        opensource.org/licenses/BSD-3-Clause
  17.   *
  18.   ******************************************************************************
  19.   */
  20.  
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "main.h"
  23.  
  24. /** @addtogroup STM32F4xx_HAL_Examples
  25.   * @{
  26.   */
  27.  
  28. /** @addtogroup GPIO_IOToggle
  29.   * @{
  30.   */
  31.  
  32. /* Private typedef -----------------------------------------------------------*/
  33. /* Private define ------------------------------------------------------------*/
  34. /* Private macro -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36.  
  37. /* Private function prototypes -----------------------------------------------*/
  38. static void SystemClock_Config(void);
  39. void MX_UART7_UART_Init(void);
  40. void HAL_UART_MspInit(UART_HandleTypeDef* huart);
  41.  
  42. /* Private functions ---------------------------------------------------------*/
  43.  
  44. /**
  45.   * @brief  Main program
  46.   * @param  None
  47.   * @retval None
  48.   */
  49.  
  50. // The main structure of the UART setup
  51. UART_HandleTypeDef huart2;
  52.  
  53. int main(void)
  54. {
  55.   /* This sample code shows how to use GPIO HAL API to toggle LED3 and LED4 IOs
  56.     in an infinite loop. */
  57.  
  58.   /* STM32F4xx HAL library initialization:
  59.        - Configure the Flash prefetch
  60.        - Systick timer is configured by default as source of time base, but user
  61.          can eventually implement his proper time base source (a general purpose
  62.          timer for example or other time source), keeping in mind that Time base
  63.          duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
  64.          handled in milliseconds basis.
  65.        - Set NVIC Group Priority to 4
  66.        - Low Level Initialization
  67.      */
  68.   HAL_Init();
  69.  
  70.   /* Configure the system clock to 100 MHz */
  71.   SystemClock_Config();
  72.  
  73.   // Call custom function to initialize UART7.
  74.   MX_UART7_UART_Init();
  75.  
  76.   // Send a greeting to the trace device (skipped on Release).
  77.   trace_puts("UART Demonstration start!");
  78.  
  79. //  char *msg = "STM32F413H Disco says Hello\r\n";
  80.   char *msg = "HELLO Michal Kowalczyk hello ARM\r\n";
  81.  
  82.   while(1) {
  83.       trace_puts("UART transmit");
  84.       HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), 0xFFFF);
  85.   }
  86.   // Infinite loop, never return.
  87. }
  88.  
  89. /**
  90.  * UART7 custom init function
  91.  * The main goal of this function is to setup a structure
  92.  * UART_HandleTypeDef referring to UART parameters. If You want
  93.  * to change for example bit rate of parity of the UART protocol
  94.  * then You need to change this function.
  95.  * */
  96. void MX_UART7_UART_Init(void)
  97. {
  98.   huart2.Instance = UART7;
  99.   huart2.Init.BaudRate = 9600;
  100.   huart2.Init.WordLength = UART_WORDLENGTH_8B;
  101.   huart2.Init.StopBits = UART_STOPBITS_1;
  102.   huart2.Init.Parity = UART_PARITY_NONE;
  103.   huart2.Init.Mode = UART_MODE_TX_RX;
  104.   huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  105.   HAL_UART_Init(&huart2);
  106. }
  107.  
  108. /**
  109.  * Setup of the UART params is not enough. You need to setup
  110.  * proper GPIO port - it depends where You connect your cabels with
  111.  * USB-UART converter
  112.  */
  113. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  114. {
  115.   GPIO_InitTypeDef GPIO_InitStruct;
  116.  
  117.   if(huart->Instance==UART7)
  118.   {
  119.     /* Peripheral clock enable */
  120.     __GPIOF_CLK_ENABLE();
  121.     __UART7_CLK_ENABLE();
  122.  
  123.     /**USART3 GPIO Configuration
  124.     PF7 (D1)    ------> UART7_TX
  125.     PF6 (D0)    ------> UART7_RX
  126.     */
  127.     GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
  128.     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  129.     GPIO_InitStruct.Pull = GPIO_NOPULL;
  130.     GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  131.     GPIO_InitStruct.Alternate = GPIO_AF8_UART7;
  132.     HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
  133.   }
  134. }
  135.  
  136. /**
  137.   * @brief  System Clock Configuration
  138.   *         The system Clock is configured as follow :
  139.   *            System Clock source            = PLL (HSE)
  140.   *            SYSCLK(Hz)                     = 100000000
  141.   *            HCLK(Hz)                       = 100000000
  142.   *            AHB Prescaler                  = 1
  143.   *            APB1 Prescaler                 = 2
  144.   *            APB2 Prescaler                 = 1
  145.   *            HSE Frequency(Hz)              = 8000000
  146.   *            PLL_M                          = 8
  147.   *            PLL_N                          = 200
  148.   *            PLL_P                          = 2
  149.   *            PLL_Q                          = 7
  150.   *            PLL_R                          = 2
  151.   *            VDD(V)                         = 3.3
  152.   *            Main regulator output voltage  = Scale1 mode
  153.   *            Flash Latency(WS)              = 3
  154.   * @param  None
  155.   * @retval None
  156.   */
  157. static void SystemClock_Config(void)
  158. {
  159.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  160.   RCC_OscInitTypeDef RCC_OscInitStruct;
  161.   HAL_StatusTypeDef ret = HAL_OK;
  162.  
  163.   /* Enable Power Control clock */
  164.   __HAL_RCC_PWR_CLK_ENABLE();
  165.  
  166.   /* The voltage scaling allows optimizing the power consumption when the device is
  167.      clocked below the maximum system frequency, to update the voltage scaling value
  168.      regarding system frequency refer to product datasheet.  */
  169.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  170.  
  171.   /* Enable HSE Oscillator and activate PLL with HSE as source */
  172.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  173.   RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
  174.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  175.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  176.   RCC_OscInitStruct.PLL.PLLM = 8;
  177.   RCC_OscInitStruct.PLL.PLLN = 200;
  178.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  179.   RCC_OscInitStruct.PLL.PLLQ = 7;
  180.   RCC_OscInitStruct.PLL.PLLR = 2;
  181.   ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
  182.  
  183.   if(ret != HAL_OK)
  184.   {
  185.     while(1) { ; }
  186.   }
  187.  
  188.   /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
  189.      clocks dividers */
  190.   RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  191.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  192.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  193.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;  
  194.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;  
  195.   ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
  196.   if(ret != HAL_OK)
  197.   {
  198.     while(1) { ; }  
  199.   }
  200. }
  201.  
  202. #ifdef  USE_FULL_ASSERT
  203.  
  204. /**
  205.   * @brief  Reports the name of the source file and the source line number
  206.   *         where the assert_param error has occurred.
  207.   * @param  file: pointer to the source file name
  208.   * @param  line: assert_param error line source number
  209.   * @retval None
  210.   */
  211. void assert_failed(uint8_t *file, uint32_t line)
  212. {
  213.   /* User can add his own implementation to report the file name and line number,
  214.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  215.  
  216.   /* Infinite loop */
  217.   while (1)
  218.   {
  219.   }
  220. }
  221. #endif
  222.  
  223. /**
  224.   * @}
  225.   */
  226.  
  227. /**
  228.   * @}
  229.   */
  230.  
  231. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  232.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×