startup.c 2.4 KB

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