Facebook
From Gruff Terrapin, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 208
  1.  
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.c
  5.   * @brief          : Main program body
  6.   ******************************************************************************
  7.   * This notice applies to any and all portions of this file
  8.   * that are not between comment pairs USER CODE BEGIN and
  9.   * USER CODE END. Other portions of this file, whether
  10.   * inserted by the user or by software development tools
  11.   * are owned by their respective copyright owners.
  12.   *
  13.   * Copyright (c) 2019 STMicroelectronics International N.V.
  14.   * All rights reserved.
  15.   *
  16.   * Redistribution and use in source and binary forms, with or without
  17.   * modification, are permitted, provided that the following conditions are met:
  18.   *
  19.   * 1. Redistribution of source code must retain the above copyright notice,
  20.   *    this list of conditions and the following disclaimer.
  21.   * 2. Redistributions in binary form must reproduce the above copyright notice,
  22.   *    this list of conditions and the following disclaimer in the documentation
  23.   *    and/or other materials provided with the distribution.
  24.   * 3. Neither the name of STMicroelectronics nor the names of other
  25.   *    contributors to this software may be used to endorse or promote products
  26.   *    derived from this software without specific written permission.
  27.   * 4. This software, including modifications and/or derivative works of this
  28.   *    software, must execute solely and exclusively on microcontroller or
  29.   *    microprocessor devices manufactured by or for STMicroelectronics.
  30.   * 5. Redistribution and use of this software other than as permitted under
  31.   *    this license is void and will automatically terminate your rights under
  32.   *    this license.
  33.   *
  34.   * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  35.   * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  36.   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  37.   * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  38.   * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  39.   * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  40.   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  42.   * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  43.   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44.   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  45.   * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46.   *
  47.   ******************************************************************************
  48.   */
  49. /* Includes ------------------------------------------------------------------*/
  50. #include "main.h"
  51. #include "stm32f7xx_hal.h"
  52. #include "fatfs.h"
  53. #include "sdmmc.h"
  54. #include "gpio.h"
  55.  
  56. /* USER CODE BEGIN Includes */
  57. #include "stm32746g_discovery_lcd.h"
  58. /* USER CODE END Includes */
  59.  
  60. /* Private variables ---------------------------------------------------------*/
  61.  
  62. /* USER CODE BEGIN PV */
  63. FIL myFile;
  64. /* Private variables ---------------------------------------------------------*/
  65.  
  66. /* USER CODE END PV */
  67.  
  68. /* Private function prototypes -----------------------------------------------*/
  69. void SystemClock_Config(void);
  70.  
  71. /* USER CODE BEGIN PFP */
  72. /* Private function prototypes -----------------------------------------------*/
  73. extern void LCD_Config(void);
  74. /* USER CODE END PFP */
  75.  
  76. /* USER CODE BEGIN 0 */
  77.  
  78. /* USER CODE END 0 */
  79.  
  80. /**
  81.   * @brief  The application entry point.
  82.   *
  83.   * @retval None
  84.   */
  85. int main(void)
  86. {
  87.   /* USER CODE BEGIN 1 */
  88.   /* USER CODE END 1 */
  89.         FRESULT res;
  90.         unsigned int n;
  91.   /* MCU Configuration----------------------------------------------------------*/
  92.  
  93.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  94.   HAL_Init();
  95.  
  96.   /* USER CODE BEGIN Init */
  97.  
  98.   /* USER CODE END Init */
  99.  
  100.   /* Configure the system clock */
  101.   SystemClock_Config();
  102.  
  103.   /* USER CODE BEGIN SysInit */
  104.  
  105.   /* USER CODE END SysInit */
  106.  
  107.   /* Initialize all configured peripherals */
  108.   MX_GPIO_Init();
  109.   MX_SDMMC1_SD_Init();
  110.   MX_FATFS_Init();
  111.   /* USER CODE BEGIN 2 */
  112.         //wywołuję funkcje konfigurujcą LCD
  113.         LCD_Config();
  114.         //ustawiam podstawowe parametry LCD
  115.         BSP_LCD_SelectLayer(0);
  116.         BSP_LCD_Clear(LCD_COLOR_BLUE);
  117.         BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
  118.         BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
  119.         BSP_LCD_SetFont(&Font16);
  120.         BSP_LCD_SetTransparency(0,255);
  121.         BSP_LCD_SetTransparency(1,255);
  122.        
  123.         res=f_open(&myFile,"0:log.csv",FA_CREATE_NEW|FA_WRITE);
  124.        
  125.         if (res==FR_OK || res==FR_EXIST){
  126.                 for(int i=0;i<10;i++){
  127.                 f_write(&myFile, "0; data; 1; 2; 3; \n",sizeof("0; data; 1; 2; 3; \n"),&n);
  128.                 }
  129.                 f_close(&myFile);
  130.         }
  131.   /* USER CODE END 2 */
  132.  
  133.   /* Infinite loop */
  134.   /* USER CODE BEGIN WHILE */
  135.   while (1)
  136.   {
  137.  
  138.   /* USER CODE END WHILE */
  139.  
  140.   /* USER CODE BEGIN 3 */
  141.  
  142.   }
  143.   /* USER CODE END 3 */
  144.  
  145. }
  146.  
  147. /**
  148.   * @brief System Clock Configuration
  149.   * @retval None
  150.   */
  151. void SystemClock_Config(void)
  152. {
  153.  
  154.   RCC_OscInitTypeDef RCC_OscInitStruct;
  155.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  156.   RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
  157.  
  158.     /**Configure the main internal regulator output voltage
  159.     */
  160.   __HAL_RCC_PWR_CLK_ENABLE();
  161.  
  162.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
  163.  
  164.     /**Initializes the CPU, AHB and APB busses clocks
  165.     */
  166.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  167.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  168.   RCC_OscInitStruct.HSICalibrationValue = 16;
  169.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  170.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  171.   RCC_OscInitStruct.PLL.PLLM = 10;
  172.   RCC_OscInitStruct.PLL.PLLN = 210;
  173.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  174.   RCC_OscInitStruct.PLL.PLLQ = 7;
  175.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  176.   {
  177.     _Error_Handler(__FILE__, __LINE__);
  178.   }
  179.  
  180.     /**Initializes the CPU, AHB and APB busses clocks
  181.     */
  182.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  183.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  184.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  185.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  186.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  187.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  188.  
  189.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  190.   {
  191.     _Error_Handler(__FILE__, __LINE__);
  192.   }
  193.  
  194.   PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SDMMC1|RCC_PERIPHCLK_CLK48;
  195.   PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48SOURCE_PLL;
  196.   PeriphClkInitStruct.Sdmmc1ClockSelection = RCC_SDMMC1CLKSOURCE_CLK48;
  197.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  198.   {
  199.     _Error_Handler(__FILE__, __LINE__);
  200.   }
  201.  
  202.     /**Configure the Systick interrupt time
  203.     */
  204.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  205.  
  206.     /**Configure the Systick
  207.     */
  208.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  209.  
  210.   /* SysTick_IRQn interrupt configuration */
  211.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  212. }
  213.  
  214. /* USER CODE BEGIN 4 */
  215.  
  216. /* USER CODE END 4 */
  217.  
  218. /**
  219.   * @brief  This function is executed in case of error occurrence.
  220.   * @param  file: The file name as string.
  221.   * @param  line: The line in file as a number.
  222.   * @retval None
  223.   */
  224. void _Error_Handler(char *file, int line)
  225. {
  226.   /* USER CODE BEGIN Error_Handler_Debug */
  227.   /* User can add his own implementation to report the HAL error return state */
  228.   while(1)
  229.   {
  230.   }
  231.   /* USER CODE END Error_Handler_Debug */
  232. }
  233.  
  234. #ifdef  USE_FULL_ASSERT
  235. /**
  236.   * @brief  Reports the name of the source file and the source line number
  237.   *         where the assert_param error has occurred.
  238.   * @param  file: pointer to the source file name
  239.   * @param  line: assert_param error line source number
  240.   * @retval None
  241.   */
  242. void assert_failed(uint8_t* file, uint32_t line)
  243. {
  244.   /* USER CODE BEGIN 6 */
  245.   /* User can add his own implementation to report the file name and line number,
  246.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  247.   /* USER CODE END 6 */
  248. }
  249. #endif /* USE_FULL_ASSERT */
  250.  
  251. /**
  252.   * @}
  253.   */
  254.  
  255. /**
  256.   * @}
  257.   */
  258.  
  259. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  260.