startup.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2006-08-31 Bernard first implementation
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <stm32f2xx.h>
  13. #include "board.h"
  14. /**
  15. * @addtogroup STM32
  16. */
  17. /*@{*/
  18. extern int rt_application_init(void);
  19. #if defined(__CC_ARM) || defined(__CLANG_ARM)
  20. extern int Image$$RW_IRAM1$$ZI$$Limit;
  21. #elif __ICCARM__
  22. #pragma section="HEAP"
  23. #else
  24. extern int __bss_end;
  25. #endif
  26. #ifdef DEBUG
  27. /*******************************************************************************
  28. * Function Name : assert_failed
  29. * Description : Reports the name of the source file and the source line number
  30. * where the assert error has occurred.
  31. * Input : - file: pointer to the source file name
  32. * - line: assert error line source number
  33. * Output : None
  34. * Return : None
  35. *******************************************************************************/
  36. void assert_failed(u8* file, u32 line)
  37. {
  38. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  39. rt_kprintf(" file %s\r\n", file);
  40. rt_kprintf(" line %d\r\n", line);
  41. while (1) ;
  42. }
  43. #endif
  44. /**
  45. * This function will startup RT-Thread RTOS.
  46. */
  47. void rtthread_startup(void)
  48. {
  49. /* init board */
  50. rt_hw_board_init();
  51. /* show version */
  52. rt_show_version();
  53. /* init tick */
  54. rt_system_tick_init();
  55. /* init kernel object */
  56. rt_system_object_init();
  57. /* init timer system */
  58. rt_system_timer_init();
  59. #ifdef RT_USING_HEAP
  60. #if STM32_EXT_SRAM
  61. rt_system_heap_init((void*)STM32_EXT_SRAM_BEGIN, (void*)STM32_EXT_SRAM_END);
  62. #else
  63. #if defined(__CC_ARM) || defined(__CLANG_ARM)
  64. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)STM32_SRAM_END);
  65. #elif __ICCARM__
  66. rt_system_heap_init(__segment_end("HEAP"), (void*)STM32_SRAM_END);
  67. #else
  68. /* init memory system */
  69. rt_system_heap_init((void*)&__bss_end, (void*)STM32_SRAM_END);
  70. #endif
  71. #endif
  72. #endif
  73. /* init scheduler system */
  74. rt_system_scheduler_init();
  75. /* init application */
  76. rt_application_init();
  77. /* init timer thread */
  78. rt_system_timer_thread_init();
  79. /* init idle thread */
  80. rt_thread_idle_init();
  81. /* start scheduler */
  82. rt_system_scheduler_start();
  83. /* never reach here */
  84. return ;
  85. }
  86. int main(void)
  87. {
  88. /* disable interrupt first */
  89. rt_hw_interrupt_disable();
  90. /* startup RT-Thread RTOS */
  91. rtthread_startup();
  92. return 0;
  93. }
  94. /*@}*/