startup.c 2.6 KB

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