From a9deff5cd0c0d73048c02fb0ffe26850d3d774b9 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Tue, 18 Apr 2023 15:38:52 +0800 Subject: [PATCH] move UartConfig function to common.c --- .../third_party_driver/common/common.c | 26 ++++++++++++++++++ .../third_party_driver/common/mcuboot.c | 27 +------------------ .../third_party_driver/common/ymodem.c | 2 -- .../third_party_driver/include/common.h | 1 + .../third_party_driver/include/ymodem.h | 1 + 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/common.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/common.c index 133fd7c69..c85f9ba88 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/common.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/common.c @@ -22,6 +22,32 @@ #include "common.h" +static uint32_t UartSrcFreq(void) +{ + uint32_t freq; + + if (CLOCK_GetMux(kCLOCK_UartMux) == 0){ + freq = (CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6U) / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); + } else { + freq = CLOCK_GetOscFreq() / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); + } + + return freq; +} + + +void UartConfig(void) +{ + lpuart_config_t config; + LPUART_GetDefaultConfig(&config); + config.baudRate_Bps = 115200u; + config.enableTx = true; + config.enableRx = true; + + LPUART_Init(LPUART1, &config, UartSrcFreq()); +} + + /** * @brief Convert an Integer to a string * @param str: The string diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/mcuboot.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/mcuboot.c index e978fd304..2326782d2 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/mcuboot.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/mcuboot.c @@ -23,32 +23,6 @@ #ifdef MCUBOOT_BOOTLOADER extern void ImxrtMsDelay(uint32 ms); -static uint32_t UartSrcFreq(void) -{ - uint32_t freq; - - /* To make it simple, we assume default PLL and divider settings, and the only variable - from application is use PLL3 source or OSC source */ - if (CLOCK_GetMux(kCLOCK_UartMux) == 0) /* PLL3 div6 80M */ { - freq = (CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6U) / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); - } else { - freq = CLOCK_GetOscFreq() / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); - } - - return freq; -} - -static void UartConfig(void) -{ - lpuart_config_t config; - LPUART_GetDefaultConfig(&config); - config.baudRate_Bps = 115200u; - config.enableTx = true; - config.enableRx = true; - - LPUART_Init(LPUART1, &config, UartSrcFreq()); -} - static void jump_to_application(void) { SCB->VTOR = (uint32_t)XIUOS_FLAH_ADDRESS; @@ -62,6 +36,7 @@ static void jump_to_application(void) asm volatile("BX R0"); } + void BootLoaderJumpApp(void) { uint8_t ch1, ch2; diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/ymodem.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/ymodem.c index f8eb0a907..1d1b5bc05 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/ymodem.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/ymodem.c @@ -19,12 +19,10 @@ * @date: 2023/3/24 */ -#include "common.h" #include "ymodem.h" #include "string.h" #include "flash.h" - uint8_t tab_1024[1024] ={0}; uint8_t FileName[FILE_NAME_LENGTH]; diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/common.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/common.h index f645ac52f..af4e476a0 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/common.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/common.h @@ -35,6 +35,7 @@ #define CONVERTHEX_alpha(c) (IS_AF(c) ? (c - 'A'+10) : (c - 'a'+10)) #define CONVERTHEX(c) (IS_09(c) ? (c - '0') : CONVERTHEX_alpha(c)) +void UartConfig(void); void Int2Str(uint8_t* str,int32_t intnum); uint32_t Str2Int(uint8_t *inputstr,int32_t *intnum); uint32_t GetIntegerInput(int32_t * num); diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/ymodem.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/ymodem.h index 08ff4fd1a..7ffd0710f 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/ymodem.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/ymodem.h @@ -23,6 +23,7 @@ #define _YMODEM_H_ #include +#include "common.h" #define USER_FLASH_SIZE 0x100000 //Application package size is limited to 1M #define PACKET_SEQNO_INDEX (1)