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