startup.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * File : startup.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2006-08-31 Bernard first implementation
  23. * 2011-06-05 Bernard modify for STM32F107 version
  24. */
  25. #include <rthw.h>
  26. #include <rtthread.h>
  27. #include <stm32l4xx.h>
  28. #include "board.h"
  29. /**
  30. * @addtogroup STM32
  31. */
  32. /*@{*/
  33. extern int rt_application_init(void);
  34. #ifdef RT_USING_FINSH
  35. extern int finsh_system_init(void);
  36. extern void finsh_set_device(const char* device);
  37. #endif
  38. #ifdef __CC_ARM
  39. extern int Image$$RW_IRAM1$$ZI$$Limit;
  40. #define STM32_SRAM_BEGIN (&Image$$RW_IRAM1$$ZI$$Limit)
  41. #elif __ICCARM__
  42. #pragma section="HEAP"
  43. #define STM32_SRAM_BEGIN (__segment_end("HEAP"))
  44. #else
  45. extern int __bss_end;
  46. #define STM32_SRAM_BEGIN (&__bss_end)
  47. #endif
  48. /*******************************************************************************
  49. * Function Name : assert_failed
  50. * Description : Reports the name of the source file and the source line number
  51. * where the assert error has occurred.
  52. * Input : - file: pointer to the source file name
  53. * - line: assert error line source number
  54. * Output : None
  55. * Return : None
  56. *******************************************************************************/
  57. void assert_failed(uint8_t* file, uint32_t line)
  58. {
  59. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  60. rt_kprintf(" file %s\r\n", file);
  61. rt_kprintf(" line %d\r\n", line);
  62. while (1) ;
  63. }
  64. /**
  65. * This function will startup RT-Thread RTOS.
  66. */
  67. void rtthread_startup(void)
  68. {
  69. /* init board */
  70. rt_hw_board_init();
  71. /* show version */
  72. rt_show_version();
  73. /* init tick */
  74. rt_system_tick_init();
  75. /* init kernel object */
  76. rt_system_object_init();
  77. /* init timer system */
  78. rt_system_timer_init();
  79. #ifdef RT_USING_EXT_SDRAM
  80. rt_system_heap_init((void*)EXT_SDRAM_BEGIN, (void*)EXT_SDRAM_END);
  81. #else
  82. rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END);
  83. #endif
  84. /* init scheduler system */
  85. rt_system_scheduler_init();
  86. /* init application */
  87. rt_application_init();
  88. /* init timer thread */
  89. rt_system_timer_thread_init();
  90. /* init idle thread */
  91. rt_thread_idle_init();
  92. /* start scheduler */
  93. rt_system_scheduler_start();
  94. /* never reach here */
  95. return ;
  96. }
  97. int main(void)
  98. {
  99. /* disable interrupt first */
  100. rt_hw_interrupt_disable();
  101. /* startup RT-Thread RTOS */
  102. rtthread_startup();
  103. return 0;
  104. }
  105. /*@}*/