startup.c 2.3 KB

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