startup.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 __CC_ARM
  35. extern int Image$$RW_IRAM1$$ZI$$Limit;
  36. #define STM32_SRAM_BEGIN (&Image$$RW_IRAM1$$ZI$$Limit)
  37. #elif __ICCARM__
  38. #pragma section="HEAP"
  39. #define STM32_SRAM_BEGIN (__segment_end("HEAP"))
  40. #else
  41. extern int __bss_end;
  42. #define STM32_SRAM_BEGIN (&__bss_end)
  43. #endif
  44. /*******************************************************************************
  45. * Function Name : assert_failed
  46. * Description : Reports the name of the source file and the source line number
  47. * where the assert error has occurred.
  48. * Input : - file: pointer to the source file name
  49. * - line: assert error line source number
  50. * Output : None
  51. * Return : None
  52. *******************************************************************************/
  53. void assert_failed(uint8_t* file, uint32_t line)
  54. {
  55. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  56. rt_kprintf(" file %s\r\n", file);
  57. rt_kprintf(" line %d\r\n", line);
  58. while (1) ;
  59. }
  60. /**
  61. * This function will startup RT-Thread RTOS.
  62. */
  63. void rtthread_startup(void)
  64. {
  65. /* init board */
  66. rt_hw_board_init();
  67. /* show version */
  68. rt_show_version();
  69. /* init tick */
  70. rt_system_tick_init();
  71. /* init kernel object */
  72. rt_system_object_init();
  73. /* init timer system */
  74. rt_system_timer_init();
  75. #ifdef RT_USING_EXT_SDRAM
  76. rt_system_heap_init((void*)EXT_SDRAM_BEGIN, (void*)EXT_SDRAM_END);
  77. #else
  78. rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END);
  79. #endif
  80. /* init scheduler system */
  81. rt_system_scheduler_init();
  82. /* init application */
  83. rt_application_init();
  84. /* init timer thread */
  85. rt_system_timer_thread_init();
  86. /* init idle thread */
  87. rt_thread_idle_init();
  88. /* start scheduler */
  89. rt_system_scheduler_start();
  90. /* never reach here */
  91. return ;
  92. }
  93. int main(void)
  94. {
  95. /* disable interrupt first */
  96. rt_hw_interrupt_disable();
  97. /* startup RT-Thread RTOS */
  98. rtthread_startup();
  99. return 0;
  100. }
  101. /*@}*/