diff --git a/MBL/platform/gdm32/cmsis_core/mbl_system_gdm32.c b/MBL/platform/gdm32/cmsis_core/mbl_system_gdm32.c index 61f6128..f85e7ef 100644 --- a/MBL/platform/gdm32/cmsis_core/mbl_system_gdm32.c +++ b/MBL/platform/gdm32/cmsis_core/mbl_system_gdm32.c @@ -42,6 +42,11 @@ } \ } + +#define __SYSTEM_CLOCK_180M_PLLP_40M_HXTAL (uint32_t)(180000000) + +uint32_t SystemCoreClock = __SYSTEM_CLOCK_180M_PLLP_40M_HXTAL; + /*! \brief configure the system clock to HXTAL \param[in] none diff --git a/MBL/platform/gdm32/gd32w51x_it.c b/MBL/platform/gdm32/gd32w51x_it.c index 6900ffa..4675b7a 100644 --- a/MBL/platform/gdm32/gd32w51x_it.c +++ b/MBL/platform/gdm32/gd32w51x_it.c @@ -34,6 +34,8 @@ OF SUCH DAMAGE. #include "gd32w51x_it.h" #include "rom_export.h" +#include +#include /*! \brief this function handles NMI exception @@ -127,3 +129,25 @@ void UsageFault_Handler(void) while(1){ } } + +/*! + \brief this function handles SysTick exception + \param[in] none + \param[out] none + \retval none +*/ +void SysTick_Handler(void) +{ + delay_decrement(); +} + +/*! + \brief This function handles TIMER2 interrupt request. + \param[in] none + \param[out] none + \retval none +*/ +void TIMER2_IRQHandler(void) +{ + __TIMER2_IRQHandler(); +} diff --git a/MBL/platform/gdm32/systick.c b/MBL/platform/gdm32/systick.c new file mode 100644 index 0000000..5ffd5e9 --- /dev/null +++ b/MBL/platform/gdm32/systick.c @@ -0,0 +1,94 @@ +/*! + \file systick.c + \brief the systick configuration file + + \version 2021-10-30, V1.0.0, firmware for GD32W51x +*/ + +/* + Copyright (c) 2021, GigaDevice Semiconductor Inc. + + Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + 3. Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +OF SUCH DAMAGE. +*/ + +#include "gd32w51x.h" +#include "systick.h" + +volatile static uint32_t delay; + +/*! + \brief configure systick + \param[in] none + \param[out] none + \retval none +*/ +void systick_config(void) +{ + /* setup systick timer for 1MHz interrupts */ + if (SysTick_Config(SystemCoreClock / 1000000U)) { + /* capture error */ + while(1); + } + + /* configure the systick handler priority */ + NVIC_SetPriority(SysTick_IRQn, 0x00U); +} + +/*! + \brief delay a time in milliseconds + \param[in] count: count in milliseconds + \param[out] none + \retval none +*/ +void delay_1us(uint32_t count) +{ + delay = count; + + while(0U != delay); +} + +/*! + \brief delay a time in milliseconds + \param[in] count: count in milliseconds + \param[out] none + \retval none +*/ +void delay_1ms(uint32_t count) +{ + delay = count * 1000; + + while(0U != delay); +} + +/*! + \brief delay decrement + \param[in] none + \param[out] none + \retval none +*/ +void delay_decrement(void) +{ + if (0U != delay) + delay--; +} diff --git a/MBL/platform/gdm32/systick.h b/MBL/platform/gdm32/systick.h new file mode 100644 index 0000000..a2fca6e --- /dev/null +++ b/MBL/platform/gdm32/systick.h @@ -0,0 +1,49 @@ +/*! + \file systick.h + \brief the header file of systick + + \version 2021-10-30, V1.0.0, firmware for GD32W51x +*/ + +/* + Copyright (c) 2021, GigaDevice Semiconductor Inc. + + Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + 3. Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +OF SUCH DAMAGE. +*/ + +#ifndef SYSTICK_H +#define SYSTICK_H + +#include + +/* configure systick */ +void systick_config(void); +/* delay a time in milliseconds */ +void delay_1us(uint32_t count); +/* delay a time in milliseconds */ +void delay_1ms(uint32_t count); +/* delay decrement */ +void delay_decrement(void); + +#endif /* SYSTICK_H */ diff --git a/MBL/source_ns/CMakeLists.txt b/MBL/source_ns/CMakeLists.txt index 971119c..f68ae55 100644 --- a/MBL/source_ns/CMakeLists.txt +++ b/MBL/source_ns/CMakeLists.txt @@ -57,16 +57,21 @@ target_sources(${TARGET_EXE} ${PROJECT_SOURCE_DIR}/NSPE/Firmware/GD32W51x_standard_peripheral/Source/gd32w51x_qspi.c ${PROJECT_SOURCE_DIR}/NSPE/Firmware/GD32W51x_standard_peripheral/Source/gd32w51x_rcu.c ${PROJECT_SOURCE_DIR}/NSPE/Firmware/GD32W51x_standard_peripheral/Source/gd32w51x_usart.c + ${PROJECT_SOURCE_DIR}/NSPE/Firmware/GD32W51x_standard_peripheral/Source/gd32w51x_spi.c + ${PROJECT_SOURCE_DIR}/NSPE/Firmware/GD32W51x_standard_peripheral/Source/gd32w51x_timer.c ) target_sources(${TARGET_EXE} PRIVATE ../platform/gdm32/cmsis_core/mbl_system_gdm32.c ../platform/gdm32/gcc/mbl_startup_gdm32.s + ../platform/gdm32/gd32w51x_it.c + ../platform/gdm32/systick.c ) target_include_directories(${TARGET_EXE} PRIVATE + ${PROJECT_SOURCE_DIR}/MBL/platform/gdm32/ ${PROJECT_SOURCE_DIR}/NSPE/Firmware/GD32W51x_standard_peripheral/Include ${CMAKE_CURRENT_SOURCE_DIR}/drivers/CMT2310/0_Project/Uart_PingPong/ ${CMAKE_CURRENT_SOURCE_DIR}/drivers/CMT2310/0_Project/Uart_PingPong/ebyte/ @@ -87,6 +92,10 @@ target_link_options(${TARGET_EXE} -Wl,-Map=${TAGET_PROJECT_DIR}/GCC/output/bin/${TARGET_EXE}.map ) +get_target_property(LINK_FLAGS ${TARGET_EXE} LINK_OPTIONS) +string(REGEX REPLACE "(.*)-u._printf_float(.*)" "\\1\\2" LINK_FLAGS "${LINK_FLAGS}") +set_target_properties(${TARGET_EXE} PROPERTIES LINK_OPTIONS "${LINK_FLAGS}") + if(CMAKE_HOST_UNIX) add_custom_command(TARGET ${TARGET_EXE} POST_BUILD COMMAND ${TAGET_PROJECT_DIR}/mbl_afterbuild.sh ${TAGET_PROJECT_DIR}/GCC/output/bin ${TARGET_EXE} GCC \"\" diff --git a/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte/ebyte_callback.c b/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte/ebyte_callback.c index 85db472..d7510c0 100755 --- a/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte/ebyte_callback.c +++ b/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte/ebyte_callback.c @@ -134,7 +134,7 @@ void Ebyte_Port_ReceiveCallback( uint16_t state, uint8_t *buffer, uint8_t lengt if( ! PC_isConnected ) { - DEBUGPRINT("\r\n Receive Data:"); + EBYTE_LOG("\r\n Receive Data:"); Ebyte_BSP_UartTransmit ( buffer, length ); } diff --git a/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte/ebyte_port.c b/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte/ebyte_port.c index f3ac1d4..bac2911 100755 --- a/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte/ebyte_port.c +++ b/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte/ebyte_port.c @@ -23,6 +23,8 @@ /*= !!!配置目标硬件平台头文件 =======================================*/ #include "board.h" //E15-EVB02 评估板 +#include "drivers/CMT2310/3_Ebyte_WirelessModule_Drivers/E48xMx/radio_hal.h" +#include "systick.h" /*==================================================================*/ /* ! @@ -77,7 +79,7 @@ void Ebyte_Port_SpiCsIoControl( uint8e_t cmd ) void Ebyte_Port_DelayMs( uint16e_t time ) { /* !必须提供: 延时函数 */ - sys_ms_sleep(time); + delay_1ms(time); } @@ -90,7 +92,5 @@ void Ebyte_Port_DelayMs( uint16e_t time ) void Ebyte_Port_DelayUs( uint16e_t time ) { /* !必须提供: 延时函数 */ - sys_us_delay(time); + delay_1us(time); } - - diff --git a/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte_e48.h b/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte_e48.h index e9847d4..d6eddf1 100644 --- a/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte_e48.h +++ b/MBL/source_ns/drivers/CMT2310/0_Project/Uart_PingPong/ebyte_e48.h @@ -1,6 +1,8 @@ #ifndef __EBYTE_E48_H__ #define __EBYTE_E48_H__ +#include + int ebyte_main( void ); #endif /* __EBYTE_E48_H__ */ 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 e244093..2b791e0 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 @@ -67,8 +67,8 @@ int ebyte_main( void ) /* MCU 开全局中断 */ Ebyte_BSP_GlobalIntEnable(); - DEBUGPRINT( "Start PingPong.....\r\n" ); - DEBUGPRINT( "Please push button1 or button2.....\r\n" ); + EBYTE_LOG( "Start PingPong.....\r\n" ); + EBYTE_LOG( "Please push button1 or button2.....\r\n" ); while( 1 ) { /* 按键事件响应 */ @@ -80,7 +80,7 @@ int ebyte_main( void ) /* 任务:EBYTE驱动库必须的周期执行任务 客户无需修改 */ Ebyte_RF.StartPollTask(); - sys_ms_sleep(100); + delay_1ms(100); } } @@ -138,7 +138,7 @@ void Task_Transmit( void ) { pongLength = 5; }else{ - DEBUGPRINT( "\r\n Echo : pong \r\n" ); + EBYTE_LOG( "\r\n Echo : pong \r\n" ); pongLength = 4; } @@ -177,7 +177,7 @@ void Task_Button( void ) pingLength = 5; }else { - DEBUGPRINT( "\r\n Send Command : ping \r\n" ); + EBYTE_LOG( "\r\n Send Command : ping \r\n" ); pingLength = 4; } @@ -203,7 +203,7 @@ void Task_Button( void ) pingLength = 5; }else { - DEBUGPRINT( "\r\n Send Command : ping \r\n" ); + EBYTE_LOG( "\r\n Send Command : ping \r\n" ); pingLength = 4; } 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 236e595..4241325 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 @@ -235,10 +235,10 @@ void Ebyte_BSP_Init( void ) Ebyte_BSP_SPI_Init(); /* 定时器 初始化 */ - Ebyte_BSP_TIMER_Init(); +// Ebyte_BSP_TIMER_Init(); /* 按键事件队列 初始化 */ - Ebyte_BTN_FIFO_Init( &BSP_BTN_FIFO ); +// Ebyte_BTN_FIFO_Init( &BSP_BTN_FIFO ); } /* ! 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 5996f33..b2e50c8 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 @@ -22,9 +22,8 @@ #define __EBYTE_BOARD_H__ #include -//#include "stm8l15x_conf.h" -#include "gd32w51x.h" -#include "debug_print.h" +#include +#include #include "board_mini_printf.h" /* 引脚配置 LED */ diff --git a/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board_mini_printf.h b/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board_mini_printf.h index 5dc11b5..12f3154 100755 --- a/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board_mini_printf.h +++ b/MBL/source_ns/drivers/CMT2310/2_Ebyte_Board_Support/E15-EVB02/board_mini_printf.h @@ -3,4 +3,6 @@ void mprintf(char * Data, ...); +#define EBYTE_LOG printf + #endif // !__BOARD_PRINTF_H__ diff --git a/MBL/source_ns/drivers/CMT2310/3_Ebyte_WirelessModule_Drivers/E48xMx/ebyte_e48x.c b/MBL/source_ns/drivers/CMT2310/3_Ebyte_WirelessModule_Drivers/E48xMx/ebyte_e48x.c index 2384b57..f7d7999 100755 --- a/MBL/source_ns/drivers/CMT2310/3_Ebyte_WirelessModule_Drivers/E48xMx/ebyte_e48x.c +++ b/MBL/source_ns/drivers/CMT2310/3_Ebyte_WirelessModule_Drivers/E48xMx/ebyte_e48x.c @@ -37,17 +37,17 @@ void Ebyte_E48x_Init( void ) /* Step2 */ g_chip_id = lRadioChipVersion(); if(0x00231000 != (g_chip_id & 0x00FFFF00)) { - DEBUGPRINT("[%s|%u] Error, dismatch Chip-ID[%#x](!=0x231000).\r\n", __FUNCTION__, __LINE__, g_chip_id); + EBYTE_LOG("[%s|%u] Error, dismatch Chip-ID[%#x](!=0x231000).\r\n", __FUNCTION__, __LINE__, g_chip_id); return; } - DEBUGPRINT("[%s|%u] Info, Link Device:E48-XXXM20S.\r\n", __FUNCTION__, __LINE__); + EBYTE_LOG("[%s|%u] Info, Link Device:E48-XXXM20S.\r\n", __FUNCTION__, __LINE__); /* Step3 */ if (bRadioGetState() == CMT2310A_STATE_IS_READY) { - DEBUGPRINT("[%s|%u] Infor, CMT2310 already in State[READY], so skip initialization.\r\n", __FUNCTION__, __LINE__); + EBYTE_LOG("[%s|%u] Infor, CMT2310 already in State[READY], so skip initialization.\r\n", __FUNCTION__, __LINE__); return; } - DEBUGPRINT("[%s|%u] Info, goto initialize E48-XXXM20S.\r\n", __FUNCTION__, __LINE__); + EBYTE_LOG("[%s|%u] Info, goto initialize E48-XXXM20S.\r\n", __FUNCTION__, __LINE__); /* Step4 */ vRadioInit(); diff --git a/MBL/source_ns/drivers/CMT2310/3_Ebyte_WirelessModule_Drivers/E48xMx/radio.c b/MBL/source_ns/drivers/CMT2310/3_Ebyte_WirelessModule_Drivers/E48xMx/radio.c index d0c11a3..1aa38bb 100755 --- a/MBL/source_ns/drivers/CMT2310/3_Ebyte_WirelessModule_Drivers/E48xMx/radio.c +++ b/MBL/source_ns/drivers/CMT2310/3_Ebyte_WirelessModule_Drivers/E48xMx/radio.c @@ -63,6 +63,7 @@ const uint8_t cmt2310a_power[55][7] = { {0x21,0x16,0x00,0x47,0x00,0x00,0x01 }, /* cmt2310a_params20-N8.h */ {0x1D,0x16,0x00,0x47,0x00,0x00,0x01 } /* cmt2310a_params20-N9.h */ }; + /****************************** **Name: vRadioInit **Func: Radio config spi & reset @@ -399,16 +400,16 @@ void vRadioCheckLink(void) g_chip_id = lRadioChipVersion(); if(0x00231000==(g_chip_id&0x00FFFF00)) break; - DEBUGPRINT( "Link Error.....\r\n" ); + EBYTE_LOG( "Link Error.....\r\n" ); delay1ms(500); i++; if(i >= 20) while(1); } - DEBUGPRINT( "Link Device:E48-XXXM20S....\r\n" ); + EBYTE_LOG( "Link Device:E48-XXXM20S....\r\n" ); } void vRadioSetFreqChannel(uint8_t channel) { bRadioGoStandby(); bRadioWriteReg( CMT2310A_CTL_REG_03, channel); -} \ No newline at end of file +} diff --git a/MBL/source_ns/mbl_ns.c b/MBL/source_ns/mbl_ns.c index 82b9600..b379264 100644 --- a/MBL/source_ns/mbl_ns.c +++ b/MBL/source_ns/mbl_ns.c @@ -39,10 +39,13 @@ OF SUCH DAMAGE. #include "mbl_sys.h" #include "mbl_uart.h" #include "mbl_flash.h" +#include "ebyte_e48.h" +#include "rom_region.h" typedef void (*img_fptr_t) (void); int32_t mbl_err_process = ERR_PROCESS_ENDLESS_LOOP; int32_t mbl_trace_level = MBL_WARN; +struct rom_api_s_t *p_rom_api_s = (struct rom_api_s_t *)ROM_API_ARRAY_BASE; #if defined(__ARM_ARCH_8M_MAIN__) || defined(__ARM_ARCH_8M_BASE__) /* Macros to pick linker symbols */ @@ -95,12 +98,13 @@ static void jump_to_main_image(uint32_t msp, uint32_t reset) */ int main(void) { + int ret; struct image_header hdr; uint32_t boot_idx = 0, image_offset = 0, version; uint32_t arm_vector[2]; - int ret; #if defined(__ARM_ARCH_8M_MAIN__) || defined(__ARM_ARCH_8M_BASE__) uint32_t msp_stack_bottom = 0; + #if defined (__ICCARM__) msp_stack_bottom = (uint32_t)®ION_NAME(CSTACK, $$Base); #else @@ -119,6 +123,12 @@ int main(void) /* Initialize flash for reading system info */ flash_init(); + /* Init Systick */ + systick_config(); + + /* Init Systick */ + ebyte_main(); + /* Initialize system status if empty or validate system status */ ret = sys_status_check(); if (ret < 0) {