startup.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * File : startup.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Develop Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2006-08-31 Bernard first implementation
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include <stm32f2xx.h>
  17. #include "board.h"
  18. /**
  19. * @addtogroup STM32
  20. */
  21. /*@{*/
  22. extern int rt_application_init(void);
  23. #ifdef RT_USING_FINSH
  24. extern void finsh_system_init(void);
  25. extern void finsh_set_device(const char* device);
  26. #endif
  27. #ifdef __CC_ARM
  28. extern int Image$$RW_IRAM1$$ZI$$Limit;
  29. #elif __ICCARM__
  30. #pragma section="HEAP"
  31. #else
  32. extern int __bss_end;
  33. #endif
  34. #ifdef DEBUG
  35. /*******************************************************************************
  36. * Function Name : assert_failed
  37. * Description : Reports the name of the source file and the source line number
  38. * where the assert error has occurred.
  39. * Input : - file: pointer to the source file name
  40. * - line: assert error line source number
  41. * Output : None
  42. * Return : None
  43. *******************************************************************************/
  44. void assert_failed(u8* file, u32 line)
  45. {
  46. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  47. rt_kprintf(" file %s\r\n", file);
  48. rt_kprintf(" line %d\r\n", line);
  49. while (1) ;
  50. }
  51. #endif
  52. /**
  53. * This function will startup RT-Thread RTOS.
  54. */
  55. void rtthread_startup(void)
  56. {
  57. /* init board */
  58. rt_hw_board_init();
  59. /* show version */
  60. rt_show_version();
  61. /* init tick */
  62. rt_system_tick_init();
  63. /* init kernel object */
  64. rt_system_object_init();
  65. /* init timer system */
  66. rt_system_timer_init();
  67. #ifdef RT_USING_HEAP
  68. #if STM32_EXT_SRAM
  69. rt_system_heap_init((void*)STM32_EXT_SRAM_BEGIN, (void*)STM32_EXT_SRAM_END);
  70. #else
  71. #ifdef __CC_ARM
  72. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)STM32_SRAM_END);
  73. #elif __ICCARM__
  74. rt_system_heap_init(__segment_end("HEAP"), (void*)STM32_SRAM_END);
  75. #else
  76. /* init memory system */
  77. rt_system_heap_init((void*)&__bss_end, (void*)STM32_SRAM_END);
  78. #endif
  79. #endif
  80. #endif
  81. /* init scheduler system */
  82. rt_system_scheduler_init();
  83. #ifdef RT_USING_DFS
  84. /* init sdcard driver */
  85. #if STM32_USE_SDIO
  86. rt_hw_sdcard_init();
  87. #else
  88. rt_hw_msd_init();
  89. #endif
  90. #endif
  91. rt_hw_rtc_init();
  92. /* init application */
  93. rt_application_init();
  94. #ifdef RT_USING_FINSH
  95. /* init finsh */
  96. finsh_system_init();
  97. finsh_set_device("uart1");
  98. #endif
  99. /* init timer thread */
  100. rt_system_timer_thread_init();
  101. /* init idle thread */
  102. rt_thread_idle_init();
  103. /* start scheduler */
  104. rt_system_scheduler_start();
  105. /* never reach here */
  106. return ;
  107. }
  108. int main(void)
  109. {
  110. /* disable interrupt first */
  111. rt_hw_interrupt_disable();
  112. /* startup RT-Thread RTOS */
  113. rtthread_startup();
  114. return 0;
  115. }
  116. /*@}*/