board.c 3.0 KB
Newer Older
Z
zhongjiequan 已提交
1
/*
2
 * Copyright (c) 2006-2021, RT-Thread Development Team
Z
zhongjiequan 已提交
3
 *
4
 * SPDX-License-Identifier: Apache-2.0
Z
zhongjiequan 已提交
5 6 7 8 9 10 11 12
 *
 * Change Logs:
 * Date           Author       Notes
 * 2017-09-19     Quintin.Z    the first version
 */

#include <rthw.h>
#include <rtthread.h>
S
SummerGift 已提交
13
#include <finsh.h>
Z
zhongjiequan 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#include "sysinit.h"
#include "board.h"
#include "drv_uart.h"
#include "nv32.h"

#define portNVIC_SYSTICK_CTRL           ( ( volatile uint32_t *) 0xe000e010 )
#define portNVIC_SYSTICK_LOAD           ( ( volatile uint32_t *) 0xe000e014 )
#define portNVIC_INT_CTRL               ( ( volatile uint32_t *) 0xe000ed04 )
#define portNVIC_SYSPRI2                ( ( volatile uint32_t *) 0xe000ed20 )
#define portNVIC_SYSTICK_CLK            0x00000004
#define portNVIC_SYSTICK_INT            0x00000002
#define portNVIC_SYSTICK_ENABLE         0x00000001
#define portNVIC_PENDSVSET              0x10000000
#define portMIN_INTERRUPT_PRIORITY      ( 255UL )
#define portNVIC_PENDSV_PRI             ( portMIN_INTERRUPT_PRIORITY << 16UL )
#define portNVIC_SYSTICK_PRI            ( portMIN_INTERRUPT_PRIORITY << 24UL )

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#ifdef __CC_ARM
extern int Image$$RW_IRAM1$$ZI$$Limit;
#define NV32_SRAM_BEGIN    (&Image$$RW_IRAM1$$ZI$$Limit)
#elif __ICCARM__
#pragma section="HEAP"
#define NV32_SRAM_BEGIN    (__segment_end("HEAP"))
#else
extern int __bss_end;
#define NV32_SRAM_BEGIN    (&__bss_end)
#endif

/*******************************************************************************
* Function Name  : assert_failed
* Description    : Reports the name of the source file and the source line number
*                  where the assert error has occurred.
* Input          : - file: pointer to the source file name
*                  - line: assert error line source number
* Output         : None
* Return         : None
*******************************************************************************/
void assert_failed(uint8_t* file, uint32_t line)
{
53 54 55
    rt_kprintf("\n\r Wrong parameter value detected on\r\n");
    rt_kprintf("       file  %s\r\n", file);
    rt_kprintf("       line  %d\r\n", line);
56

57
    while (1) ;
58
}
Z
zhongjiequan 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

/**
 * This is the timer interrupt service routine.
 *
 */
void SysTick_Handler(void)
{
    /* enter interrupt */
    rt_interrupt_enter();

    rt_tick_increase();

    /* leave interrupt */
    rt_interrupt_leave();
}


/**
 * This function will initial STM32 board.
 */
void rt_hw_board_init()
{
    /* Configure the SysTick */
    *(portNVIC_SYSTICK_LOAD) = ( 40000000 / RT_TICK_PER_SECOND ) - 1UL;
    *(portNVIC_SYSTICK_CTRL) = portNVIC_SYSTICK_CLK | portNVIC_SYSTICK_INT | portNVIC_SYSTICK_ENABLE;

    rt_hw_uart_init();

    /* Call components board initial (use INIT_BOARD_EXPORT()) */
#ifdef RT_USING_COMPONENTS_INIT
    rt_components_board_init();
#endif


#ifdef RT_USING_CONSOLE
    rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif

97

98 99 100
#ifdef RT_USING_HEAP
    rt_system_heap_init((void*)NV32_SRAM_BEGIN, (void*)NV32_SRAM_END);
#endif
Z
zhongjiequan 已提交
101 102
}

103
int cmd_reset(int argc, char** argv)
Z
zhongjiequan 已提交
104 105 106 107 108
{
    NVIC_SystemReset();

    return 0;
}
109
MSH_CMD_EXPORT_ALIAS(cmd_reset, reset, restart the system);
Z
zhongjiequan 已提交
110 111

/*@}*/