Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2017-07-24 Tanek the first version
  9. * 2018-11-12 Ernest Chen modify copyright
  10. */
  11. #include <stdint.h>
  12. #include <rthw.h>
  13. #include <rtthread.h>
  14. #include "usart.h"
  15. #include "main.h"
  16. #define _SCB_BASE (0xE000E010UL)
  17. #define _SYSTICK_CTRL (*(rt_uint32_t *)(_SCB_BASE + 0x0))
  18. #define _SYSTICK_LOAD (*(rt_uint32_t *)(_SCB_BASE + 0x4))
  19. #define _SYSTICK_VAL (*(rt_uint32_t *)(_SCB_BASE + 0x8))
  20. #define _SYSTICK_CALIB (*(rt_uint32_t *)(_SCB_BASE + 0xC))
  21. #define _SYSTICK_PRI (*(rt_uint8_t *)(0xE000ED23UL))
  22. // Updates the variable SystemCoreClock and must be called
  23. // whenever the core clock is changed during program execution.
  24. extern void SystemCoreClockUpdate(void);
  25. void SysInit(void);
  26. // Holds the system core clock, which is the system clock
  27. // frequency supplied to the SysTick timer and the processor
  28. // core clock.
  29. extern uint32_t SystemCoreClock;
  30. static uint32_t _SysTick_Config(rt_uint32_t ticks)
  31. {
  32. if ((ticks - 1) > 0xFFFFFF)
  33. {
  34. return 1;
  35. }
  36. _SYSTICK_LOAD = ticks - 1;
  37. _SYSTICK_PRI = 0xFF;
  38. _SYSTICK_VAL = 0;
  39. _SYSTICK_CTRL = 0x07;
  40. return 0;
  41. }
  42. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
  43. #define RT_HEAP_SIZE 2048
  44. static uint32_t rt_heap[RT_HEAP_SIZE]; // heap default size: 4K(1024 * 4)
  45. RT_WEAK void *rt_heap_begin_get(void)
  46. {
  47. return rt_heap;
  48. }
  49. RT_WEAK void *rt_heap_end_get(void)
  50. {
  51. return rt_heap + RT_HEAP_SIZE;
  52. }
  53. #endif
  54. /**
  55. * This function will initial your board.
  56. */
  57. void rt_hw_board_init()
  58. {
  59. /* System Clock Update */
  60. SystemCoreClockUpdate();
  61. /* System Tick Configuration */
  62. _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  63. SysInit();
  64. /* Call components board initial (use INIT_BOARD_EXPORT()) */
  65. #ifdef RT_USING_COMPONENTS_INIT
  66. rt_components_board_init();
  67. #endif
  68. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
  69. rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
  70. #endif
  71. }
  72. void SysInit(void)
  73. {
  74. HAL_Init();
  75. extern void SystemClock_Config(void);
  76. SystemClock_Config();
  77. extern void MX_GPIO_Init(void);
  78. MX_GPIO_Init();
  79. //MX_I2C1_Init();
  80. MX_USART1_UART_Init();
  81. }
  82. #if !TRICE_OFF
  83. // ms32 is a 32-bit millisecond counter, counting circular in steps of 1 every ms.
  84. uint32_t ms32 = 0;
  85. #endif
  86. int main(void)
  87. {
  88. #if !TRICE_OFF
  89. TriceInit(); // This so early, to allow trice logs inside interrupts from the beginning. Only needed for RTT.
  90. TriceHeadLine(" ????????????-F030R8 ");
  91. #endif
  92. //int i = 1;
  93. //int q = 58;
  94. //int d = i + q;
  95. rt_kprintf("%s\n", __func__);
  96. //test_softbreakpoint();
  97. #if !TRICE_OFF
  98. SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; // enable SysTick interrupt
  99. LogTriceConfiguration();
  100. SomeExampleTrices(3);
  101. #endif
  102. /* USER CODE END 2 */
  103. /* Infinite loop */
  104. /* USER CODE BEGIN WHILE */
  105. while (1)
  106. {
  107. #if !TRICE_OFF
  108. static uint32_t lastMs = 0;
  109. if( lastMs != ms32 ){ // each ms
  110. lastMs = ms32;
  111. #if TRICE_DIAGNOSTICS == 1
  112. static uint32_t msDiag = 0;
  113. msDiag++;
  114. if(msDiag >= 3000 ){
  115. msDiag = 0;
  116. TriceLogDiagnosticData();
  117. }
  118. #endif
  119. static uint32_t msCheck = 0;
  120. msCheck++;
  121. if(msCheck >= 1000 ){
  122. msCheck = 0;
  123. SomeExampleTrices(5);
  124. }
  125. #if (TRICE_BUFFER == TRICE_RING_BUFFER) || (TRICE_BUFFER == TRICE_DOUBLE_BUFFER)
  126. static uint32_t msTransfer = 0;
  127. msTransfer++;
  128. if(msTransfer >= 100 ){
  129. msTransfer = 0;
  130. // Serve deferred trice transfer every few ms or if TRICE_BUFFER is getting filled. With an RTOS put this in a separate task.
  131. // In TRICE_RING_BUFFER && TRICE_SINGLE_PACK_MODE TriceTransfer can transmit only 1 Trice per call, so call it every 1ms then.
  132. // In TRICE_DOUBLE_BUFFER TriceTransfer transmits one half buffer.
  133. TriceTransfer(); // serve deferred output
  134. }
  135. #if TRICE_RING_BUFFER_OVERFLOW_WATCH == 1
  136. WatchRingBufferMargins();
  137. #endif
  138. #endif // #if ( TRICE_BUFFER == TRICE_RING_BUFFER) || ( TRICE_BUFFER == TRICE_DOUBLE_BUFFER)
  139. }
  140. /* USER CODE END WHILE */
  141. /* USER CODE BEGIN 3 */
  142. #endif // #if !TRICE_OFF
  143. }
  144. return 0;
  145. }
  146. void SysTick_Handler(void)
  147. {
  148. #if !TRICE_OFF
  149. ms32++;
  150. #endif
  151. /* enter interrupt */
  152. rt_interrupt_enter();
  153. rt_tick_increase();
  154. /* leave interrupt */
  155. rt_interrupt_leave();
  156. }