board.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2017-09-19 Quintin.Z the first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <finsh.h>
  13. #include "sysinit.h"
  14. #include "board.h"
  15. #include "drv_uart.h"
  16. #include "nv32.h"
  17. #define portNVIC_SYSTICK_CTRL ( ( volatile uint32_t *) 0xe000e010 )
  18. #define portNVIC_SYSTICK_LOAD ( ( volatile uint32_t *) 0xe000e014 )
  19. #define portNVIC_INT_CTRL ( ( volatile uint32_t *) 0xe000ed04 )
  20. #define portNVIC_SYSPRI2 ( ( volatile uint32_t *) 0xe000ed20 )
  21. #define portNVIC_SYSTICK_CLK 0x00000004
  22. #define portNVIC_SYSTICK_INT 0x00000002
  23. #define portNVIC_SYSTICK_ENABLE 0x00000001
  24. #define portNVIC_PENDSVSET 0x10000000
  25. #define portMIN_INTERRUPT_PRIORITY ( 255UL )
  26. #define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL )
  27. #define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL )
  28. #ifdef __CC_ARM
  29. extern int Image$$RW_IRAM1$$ZI$$Limit;
  30. #define NV32_SRAM_BEGIN (&Image$$RW_IRAM1$$ZI$$Limit)
  31. #elif __ICCARM__
  32. #pragma section="HEAP"
  33. #define NV32_SRAM_BEGIN (__segment_end("HEAP"))
  34. #else
  35. extern int __bss_end;
  36. #define NV32_SRAM_BEGIN (&__bss_end)
  37. #endif
  38. /*******************************************************************************
  39. * Function Name : assert_failed
  40. * Description : Reports the name of the source file and the source line number
  41. * where the assert error has occurred.
  42. * Input : - file: pointer to the source file name
  43. * - line: assert error line source number
  44. * Output : None
  45. * Return : None
  46. *******************************************************************************/
  47. void assert_failed(uint8_t* file, uint32_t line)
  48. {
  49. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  50. rt_kprintf(" file %s\r\n", file);
  51. rt_kprintf(" line %d\r\n", line);
  52. while (1) ;
  53. }
  54. /**
  55. * This is the timer interrupt service routine.
  56. *
  57. */
  58. void SysTick_Handler(void)
  59. {
  60. /* enter interrupt */
  61. rt_interrupt_enter();
  62. rt_tick_increase();
  63. /* leave interrupt */
  64. rt_interrupt_leave();
  65. }
  66. /**
  67. * This function will initial STM32 board.
  68. */
  69. void rt_hw_board_init()
  70. {
  71. /* Configure the SysTick */
  72. *(portNVIC_SYSTICK_LOAD) = ( 40000000 / RT_TICK_PER_SECOND ) - 1UL;
  73. *(portNVIC_SYSTICK_CTRL) = portNVIC_SYSTICK_CLK | portNVIC_SYSTICK_INT | portNVIC_SYSTICK_ENABLE;
  74. rt_hw_uart_init();
  75. /* Call components board initial (use INIT_BOARD_EXPORT()) */
  76. #ifdef RT_USING_COMPONENTS_INIT
  77. rt_components_board_init();
  78. #endif
  79. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  80. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  81. #endif
  82. #ifdef RT_USING_HEAP
  83. rt_system_heap_init((void*)NV32_SRAM_BEGIN, (void*)NV32_SRAM_END);
  84. #endif
  85. }
  86. int cmd_reset(int argc, char** argv)
  87. {
  88. NVIC_SystemReset();
  89. return 0;
  90. }
  91. MSH_CMD_EXPORT_ALIAS(cmd_reset, reset, restart the system);
  92. /*@}*/