diff --git a/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/main.c b/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/main.c index 3ed62f9..f920ff0 100755 --- a/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/main.c +++ b/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/main.c @@ -61,7 +61,6 @@ int ebyte_main( void ) { /* Init Systick */ systick_config(); -#if 0 /* 板载硬件资源 初始化 */ Ebyte_BSP_Init(); /* (可选) 串口中断接收FIFO 可根据需要自行处理 */ @@ -71,7 +70,7 @@ int ebyte_main( void ) /* 启用无线模块接收 */ Ebyte_RF.EnterReceiveMode( 0 ); /* MCU 开全局中断 */ - Ebyte_BSP_GlobalIntEnable(); +// Ebyte_BSP_GlobalIntEnable(); EBYTE_LOG( "Start PingPong.....\r\n" ); EBYTE_LOG( "Please push button1 or button2.....\r\n" ); @@ -90,7 +89,7 @@ int ebyte_main( void ) } Ebyte_BSP_GlobalIntDisable(); -#endif + Ebyte_BSP_Deinit(); systick_deinit(); } diff --git a/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board.c b/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board.c index e57b2c9..c1e3f0e 100755 --- a/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board.c +++ b/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board.c @@ -23,6 +23,10 @@ #include "ebyte_port.h" #include "ebyte_conf.h" #include "gd32w51x_gpio.h" +#include "gd32w51x_misc.h" +#include "gd32w51x_rcu.h" +#include "gd32w51x_spi.h" +#include "gd32w51x_timer.h" #include "platform_def.h" BSP_BTN_FIFO_t BSP_BTN_FIFO; @@ -43,7 +47,6 @@ void Ebyte_BSP_HSI_Init(void) // CLK_SYSCLKDivConfig( CLK_SYSCLKDiv_1 ); } - void Ebyte_BSP_E48xGPIO_Init(void) { rcu_periph_clock_enable(BSP_GPIO_RCU_E48_GPIO); @@ -54,6 +57,12 @@ void Ebyte_BSP_E48xGPIO_Init(void) gpio_mode_set( BSP_GPIO_PORT_E48_GP4, GPIO_MODE_INPUT, GPIO_PUPD_NONE, BSP_GPIO_PIN_E48_GP4); gpio_mode_set( BSP_GPIO_PORT_E48_GP5, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, BSP_GPIO_PIN_E48_GP5); } + +void Ebyte_BSP_E48xGPIO_Deinit(void) +{ + rcu_periph_clock_disable(BSP_GPIO_RCU_E48_GPIO); +} + /* ! * @brief 初始化所有IO * @@ -77,6 +86,23 @@ void Ebyte_BSP_GPIO_Init(void) // GPIO_Init( BSP_GPIO_PORT_BUTTON_2, BSP_GPIO_PIN_BUTTON_2, GPIO_Mode_In_PU_No_IT ); } +/* ! + * @brief 初始化所有IO + * + * @note 目标硬件: EBYTE E15-EVB02 + */ +void Ebyte_BSP_GPIO_Deinit(void) +{ + /* Button */ + rcu_periph_clock_disable(BSP_GPIO_RCU_E48_BUTTON); + + /* LED */ + rcu_periph_clock_disable(BSP_GPIO_RCU_E48_LED); + + /* E48 */ + Ebyte_BSP_E48xGPIO_Deinit(); +} + /* ! * @brief 通信串口初始化 * @@ -146,6 +172,21 @@ void Ebyte_BSP_SPI_Init( void ) spi_enable(BSP_RF_SPI); } +/* ! + * @brief 无线模块通信SPI接口初始化函数 + */ +void Ebyte_BSP_SPI_Deinit( void ) +{ + /* SPI enable */ + spi_disable(BSP_RF_SPI); + + spi_i2s_deinit(BSP_RF_SPI); + + spi_parameter_struct spi_init_struct; + + rcu_periph_clock_disable(BSP_RF_SPI_CLOCK); +} + /* ! * @brief RF模块SPI通信收/发函数 * @@ -210,6 +251,31 @@ void Ebyte_BSP_TIMER_Init( void ) nvic_irq_enable(TIMER2_IRQn, 0, 0); } +/* ! + * @brief 定时器初始化 + * + * @note 使用了TIM3产生1ms周期性中断 + * TIM3的主时钟为HSI 16MHz, 128分频即为 16 MHz / 128 = 125 000 Hz + * 目标定时1ms 计数周期即为 ( 0.001 x 125000 - 1) = 124 + */ +void Ebyte_BSP_TIMER_Deinit( void ) +{ + nvic_irq_disable(TIMER2_IRQn); + + /* enable a TIMER */ + timer_disable(BSP_RF_TIMER); + /* enable the TIMER interrupt */ + timer_interrupt_disable(BSP_RF_TIMER, TIMER_INT_UP); + /* clear interrupt bit */ + timer_interrupt_flag_clear(BSP_RF_TIMER, TIMER_INT_FLAG_UP); + + /* enable the peripherals clock */ + rcu_periph_clock_disable(BSP_RF_TIMER_RCU); + + /* deinit a TIMER */ + timer_deinit(BSP_RF_TIMER); +} + /* ! * @brief E15-EVB02 板载资源初始化 * @@ -241,6 +307,31 @@ void Ebyte_BSP_Init( void ) Ebyte_BTN_FIFO_Init( &BSP_BTN_FIFO ); } +/* ! + * @brief E15-EVB02 板载资源初始化 + * + * @note 内部时钟HSI x 16MHz + * 用户通信串口 x USART1 + * 无线模块通信接口 x SPI1 + * 定时器 x TIM3 + * 按键 x 2 + * 指示灯 x 2 + */ +void Ebyte_BSP_Deinit( void ) +{ + /* 定时器 初始化 */ + Ebyte_BSP_TIMER_Deinit(); + + /* SPI接口 初始化 */ + Ebyte_BSP_SPI_Deinit(); + + /* 串口 初始化 */ +// Ebyte_BSP_UART_Init(); + + /* IO 初始化 */ + Ebyte_BSP_GPIO_Deinit(); +} + /* ! * @brief 控制LED 开/关/翻转 * diff --git a/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board.h b/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board.h index b2e50c8..326d535 100755 --- a/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board.h +++ b/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board.h @@ -164,6 +164,7 @@ typedef struct extern BSP_BTN_FIFO_t BSP_BTN_FIFO; void Ebyte_BSP_Init( void ); +void Ebyte_BSP_Deinit( void ); void Ebyte_BTN_FIFO_Init(BSP_BTN_FIFO_t *fifo); void Ebyte_BSP_DelayMs( volatile uint32_t nTime ); void Ebyte_BSP_TimerDecrement(void); diff --git a/MBL/source_ns/mbl_ns.c b/MBL/source_ns/mbl_ns.c index 5dacd3e..51a59b3 100644 --- a/MBL/source_ns/mbl_ns.c +++ b/MBL/source_ns/mbl_ns.c @@ -75,7 +75,7 @@ static void jump_to_main_image(uint32_t msp, uint32_t reset) img_reset = (img_fptr_t)reset; - __disable_irq(); +// __disable_irq(); #if defined(__ARM_ARCH_8M_MAIN__) || defined(__ARM_ARCH_8M_BASE__) /* Restore the Main Stack Pointer Limit register's reset value * before passing execution to runtime firmware to make the