startup.c 2.4 KB

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