Projet voilier 4IRA1 Arnaud Vergnet Marino Benassai Bastien Picco Yohan Simard
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.c 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /**
  2. ******************************************************************************
  3. * @file Templates_LL/Src/main.c
  4. * @author MCD Application Team
  5. * @brief Main program body through the LL API
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. #include "stm32f1xx_ll_rcc.h" // utile dans la fonction SystemClock_Config
  20. #include "stm32f1xx_ll_utils.h" // utile dans la fonction SystemClock_Config
  21. #include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config
  22. #include "Sail.h"
  23. #include "Roll.h"
  24. #include "Display.h"
  25. #include "Orientation.h"
  26. #include "Scheduler.h"
  27. #include "Accelerometer.h"
  28. #include "RFEmitter.h"
  29. #include "stdio.h"
  30. void SystemClock_Config(void);
  31. // Compteur de secondes
  32. int secCounter = 0;
  33. /* Private functions ---------------------------------------------------------*/
  34. /**
  35. * @brief Effectue la tache de fond (programmee toutes les ms)
  36. * @note
  37. * @param None
  38. * @retval None
  39. */
  40. void backgroundTask()
  41. {
  42. // Compte les millisecondes et secondes
  43. static int msCounter;
  44. msCounter++;
  45. if (msCounter == 1000) {
  46. msCounter = 0;
  47. secCounter++;
  48. }
  49. Sail_background();
  50. Roll_background();
  51. Orientation_background();
  52. }
  53. /**
  54. * @brief Configure les peripheriques
  55. * @note
  56. * @param None
  57. * @retval None
  58. */
  59. void configurePeripherals()
  60. {
  61. Sail_conf();
  62. Roll_conf();
  63. Display_conf();
  64. Orientation_conf();
  65. }
  66. /**
  67. * @brief Demarre les peripheriques
  68. * @note
  69. * @param None
  70. * @retval None
  71. */
  72. void startPeripherals()
  73. {
  74. Sail_start();
  75. Roll_start();
  76. Display_start();
  77. }
  78. /**
  79. * @brief Main program
  80. * @param None
  81. * @retval None
  82. */
  83. int main(void)
  84. {
  85. /* Configure the system clock to 72 MHz */
  86. SystemClock_Config();
  87. /* Add your application code here */
  88. configurePeripherals();
  89. startPeripherals();
  90. Scheduler_conf(backgroundTask);
  91. Scheduler_start();
  92. while (1) {
  93. // Display_background(secCounter);
  94. }
  95. //// ADC 2 marche niquel, ADC1 ne marche pas :(
  96. // ADC_conf(ADC1);
  97. // ADC_start(ADC1);
  98. //
  99. // ADC_conf(ADC2);
  100. // ADC_start(ADC2);
  101. //
  102. // while (1) {
  103. // val1 = ADC_readRaw(ADC1, 10);
  104. // val2 = ADC_readRaw(ADC2, 10);
  105. // }
  106. }
  107. /**
  108. * @brief System Clock Configuration
  109. * The system Clock is configured as follow :
  110. * System Clock source = PLL (HSE)
  111. * SYSCLK(Hz) = 72000000
  112. * HCLK(Hz) = 72000000
  113. * AHB Prescaler = 1
  114. * APB1 Prescaler = 2
  115. * APB2 Prescaler = 1
  116. * HSE Frequency(Hz) = 8000000
  117. * PLLMUL = 9
  118. * Flash Latency(WS) = 2
  119. * @param None
  120. * @retval None
  121. */
  122. void SystemClock_Config(void)
  123. {
  124. /* Set FLASH latency */
  125. LL_FLASH_SetLatency(LL_FLASH_LATENCY_2);
  126. /* Enable HSE oscillator */
  127. // ********* Commenter la ligne ci-dessous pour MCBSTM32 *****************
  128. // ********* Conserver la ligne si Nucleo*********************************
  129. // LL_RCC_HSE_EnableBypass();
  130. LL_RCC_HSE_Enable();
  131. while(LL_RCC_HSE_IsReady() != 1)
  132. {
  133. };
  134. /* Main PLL configuration and activation */
  135. LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9);
  136. LL_RCC_PLL_Enable();
  137. while(LL_RCC_PLL_IsReady() != 1)
  138. {
  139. };
  140. /* Sysclk activation on the main PLL */
  141. LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
  142. LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
  143. while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
  144. {
  145. };
  146. /* Set APB1 & APB2 prescaler*/
  147. LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2);
  148. LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
  149. /* Set systick to 1ms in using frequency set to 72MHz */
  150. LL_Init1msTick(72000000); // utile lorsqu'on utilise la fonction LL_mDelay
  151. /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */
  152. LL_SetSystemCoreClock(72000000);
  153. }
  154. /* ============== BOARD SPECIFIC CONFIGURATION CODE END ============== */
  155. #ifdef USE_FULL_ASSERT
  156. /**
  157. * @brief Reports the name of the source file and the source line number
  158. * where the assert_param error has occurred.
  159. * @param file: pointer to the source file name
  160. * @param line: assert_param error line source number
  161. * @retval None
  162. */
  163. void assert_failed(uint8_t *file, uint32_t line)
  164. {
  165. /* User can add his own implementation to report the file name and line number*/
  166. printf("Wrong parameters value: file %s on line %d", file, line);
  167. /* Infinite loop */
  168. while (1)
  169. {
  170. }
  171. }
  172. #endif
  173. /**
  174. * @}
  175. */
  176. /**
  177. * @}
  178. */
  179. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/