Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

board.c 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #include "coredump.h"
  55. COREADUMP_PRINT_VARIABLE_DEFINE(rt_heap);
  56. /**
  57. * This function will initial your board.
  58. */
  59. void rt_hw_board_init()
  60. {
  61. /* System Clock Update */
  62. SystemCoreClockUpdate();
  63. /* System Tick Configuration */
  64. _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  65. SysInit();
  66. /* Call components board initial (use INIT_BOARD_EXPORT()) */
  67. #ifdef RT_USING_COMPONENTS_INIT
  68. rt_components_board_init();
  69. #endif
  70. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
  71. rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
  72. #endif
  73. }
  74. void SysInit(void)
  75. {
  76. HAL_Init();
  77. extern void SystemClock_Config(void);
  78. SystemClock_Config();
  79. extern void MX_GPIO_Init(void);
  80. MX_GPIO_Init();
  81. //MX_I2C1_Init();
  82. MX_USART1_UART_Init();
  83. }
  84. int main(void)
  85. {
  86. int i = 1;
  87. int q = 58;
  88. int d = i + q;
  89. //rt_kprintf("%s\n", __func__);
  90. test_softbreakpoint();
  91. return 0;
  92. }
  93. void SysTick_Handler(void)
  94. {
  95. /* enter interrupt */
  96. rt_interrupt_enter();
  97. rt_tick_increase();
  98. /* leave interrupt */
  99. rt_interrupt_leave();
  100. }