From 669ef1eb2bffd6c29211cb232bf223adc634476f Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Tue, 4 Apr 2023 14:41:54 +0800 Subject: [PATCH 01/15] =?UTF-8?q?1=E3=80=81feat=20add=20link-bootloader.ld?= =?UTF-8?q?s[start=20from=200x60000000]=20and=20link-application.lds[start?= =?UTF-8?q?=20from=200x60040000];=202=E3=80=81support=20BSP=5FUSING=5FOTA?= =?UTF-8?q?=20MCUBOOT=5FBOOTLOADER=20and=20MCUBOOT=5FAPPLICATION=20in=20xi?= =?UTF-8?q?datong-arm32/Kconfig;=203=E3=80=81support=20compile=20XiZi-xida?= =?UTF-8?q?tong-arm32-boot.bin=20when=20enable=20MCUBOOT=5FBOOTLOADER=20an?= =?UTF-8?q?d=20XiZi-xidatong-arm32-app.bin=20when=20enable=20MCUBOOT=5FAPP?= =?UTF-8?q?LICATION;=204=E3=80=81add=20QSPIFlash=20function=20for=20xidato?= =?UTF-8?q?ng-arm32=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ubiquitous/XiZi_IIoT/Makefile | 20 + .../XiZi_IIoT/arch/arm/cortex-m7/boot.S | 58 +- .../XiZi_IIoT/board/xidatong-arm32/Kconfig | 16 + .../XiZi_IIoT/board/xidatong-arm32/board.c | 26 +- .../XiZi_IIoT/board/xidatong-arm32/config.mk | 10 +- .../xidatong-arm32/include/clock_config.h | 47 + .../board/xidatong-arm32/link-application.lds | 264 ++++ .../board/xidatong-arm32/link-bootloader.lds | 280 ++++ .../XiZi_IIoT/board/xidatong-arm32/link.lds | 3 +- .../third_party_driver/common/Makefile | 4 + .../third_party_driver/common/clock_config.c | 82 +- .../third_party_driver/common/flash.c | 304 ++++ .../third_party_driver/common/fsl_clock.c | 388 ++++- .../third_party_driver/common/fsl_common.c | 6 +- .../third_party_driver/common/fsl_romapi.c | 161 ++ .../third_party_driver/common/mcuboot.c | 86 ++ .../third_party_driver/common/pin_mux.c | 1282 +--------------- .../third_party_driver/include/MIMXRT1052.h | 984 +++++++++++- .../include/MIMXRT1052_features.h | 19 +- .../third_party_driver/include/flash.h | 32 + .../third_party_driver/include/fsl_clock.h | 318 +++- .../third_party_driver/include/fsl_common.h | 46 +- .../third_party_driver/include/fsl_gpio.h | 4 +- .../third_party_driver/include/fsl_lpuart.h | 11 +- .../third_party_driver/include/fsl_romapi.h | 570 +++++++ .../third_party_driver/include/mcuboot.h | 27 + .../xidatong-arm32/xip/fsl_flexspi_nor_boot.c | 1349 ++++------------- .../xip/fsl_flexspi_nor_flash.c | 79 +- 28 files changed, 3886 insertions(+), 2590 deletions(-) create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-application.lds create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-bootloader.lds create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/fsl_romapi.c create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/mcuboot.c create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_romapi.h create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h diff --git a/Ubiquitous/XiZi_IIoT/Makefile b/Ubiquitous/XiZi_IIoT/Makefile index 26463828f..b235ec637 100755 --- a/Ubiquitous/XiZi_IIoT/Makefile +++ b/Ubiquitous/XiZi_IIoT/Makefile @@ -62,6 +62,10 @@ PART += COMPILE_KERNEL else ifeq ($(CONFIG_COMPILER_APP)_$(CONFIG_COMPILER_KERNEL),y_y) PART := COMPILE_APP COMPILE_KERNEL +else ifeq ($(CONFIG_MCUBOOT_BOOTLOADER), y) +PART := COMPILE_BOOTLOADER +else ifeq ($(CONFIG_MCUBOOT_APPLICATION), y) +PART := COMPILE_APPLICATION else PART := @@ -88,6 +92,22 @@ COMPILE_ALL: @$(MAKE) -C build TARGET=XiZi-$(BOARD).elf LINK_FLAGS=LFLAGS @rm build/Makefile build/make.obj +COMPILE_BOOTLOADER: + @for dir in $(SRC_DIR);do \ + $(MAKE) -C $$dir; \ + done + @cp link.mk build/Makefile + @$(MAKE) -C build COMPILE_TYPE="-boot" TARGET=XiZi-$(BOARD)-boot.elf LINK_FLAGS=LFLAGS + @rm build/Makefile build/make.obj + +COMPILE_APPLICATION: + @for dir in $(SRC_DIR);do \ + $(MAKE) -C $$dir; \ + done + @cp link.mk build/Makefile + @$(MAKE) -C build COMPILE_TYPE="-app" TARGET=XiZi-$(BOARD)-app.elf LINK_FLAGS=LFLAGS + @rm build/Makefile build/make.obj + COMPILE_MUSL: @for dir in $(MUSL_DIR);do \ $(MAKE) -C $$dir COMPILE_TYPE=$@ CONFIG_RESOURCES_LWIP=n; \ diff --git a/Ubiquitous/XiZi_IIoT/arch/arm/cortex-m7/boot.S b/Ubiquitous/XiZi_IIoT/arch/arm/cortex-m7/boot.S index 57083c7ea..d379a2b6a 100644 --- a/Ubiquitous/XiZi_IIoT/arch/arm/cortex-m7/boot.S +++ b/Ubiquitous/XiZi_IIoT/arch/arm/cortex-m7/boot.S @@ -49,6 +49,61 @@ Modification: .weak Reset_Handler .type Reset_Handler, %function Reset_Handler: +#ifdef __BOOTLOADER /* BOOT */ + cpsid i /* Mask interrupts */ + .equ VTOR, 0xE000ED08 + ldr r0, =VTOR + ldr r1, =__isr_vector + str r1, [r0] + ldr r2, [r1] + msr msp, r2 + + ldr r0,=SystemInit + blx r0 + +/* Loop to copy data from read only memory to RAM. The ranges + * of copy from/to are specified by following symbols evaluated in + * linker script. + * __bootloader_end: End of code section, i.e., begin of data sections to copy from. + * __data_start__/__data_end__: RAM address range that data should be + * __noncachedata_start__/__noncachedata_end__ : none cachable region + * copied to. Both must be aligned to 4 bytes boundary. */ + + ldr r1, =__etext + ldr r2, =__data_start__ + ldr r3, =__data_end__ + + /* Here are two copies of loop implemenations. First one favors code size + * and the second one favors performance. Default uses the first one. + * Change to "#if 0" to use the second one */ +.LoopCopy0: + cmp r2, r3 + ittt lt + ldrlt r0, [r1], #4 + strlt r0, [r2], #4 + blt .LoopCopy0 + + /* This part of work usually is done in C library startup code. Otherwise, + * define this macro to enable it in this startup. + * + * Loop to zero out BSS section, which uses following symbols + * in linker script: + * __bss_start__: start of BSS section. Must align to 4 + * __bss_end__: end of BSS section. Must align to 4 + */ + ldr r1, =__bss_start__ + ldr r2, =__bss_end__ + + movs r0, 0 +.LoopCopy1: + cmp r1, r2 + itt lt + strlt r0, [r1], #4 + blt .LoopCopy1 + + ldr r0,=BootLoaderJumpApp + blx r0 +#else /* APP */ cpsid i /* Mask interrupts */ .equ VTOR, 0xE000ED08 ldr r0, =VTOR @@ -122,7 +177,7 @@ Reset_Handler: blt .LC4 #endif /* __STARTUP_INITIALIZE_NONCACHEDATA */ -#ifdef __STARTUP_CLEAR_BSS +#if 1 /* This part of work usually is done in C library startup code. Otherwise, * define this macro to enable it in this startup. * @@ -144,5 +199,6 @@ Reset_Handler: ldr r0,=entry blx r0 +#endif /* MCUBOOT_BOOTLOADER */ .size Reset_Handler, . - Reset_Handler \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/Kconfig b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/Kconfig index faa887906..b84b61537 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/Kconfig +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/Kconfig @@ -40,6 +40,22 @@ menu "xidatong-arm32 feature" int "stack size for interrupt" default 4096 + config BSP_USING_OTA + bool "xidatong arm32 support OTA function" + default n + if BSP_USING_OTA + choice + prompt "compile bootloader bin or application bin." + default MCUBOOT_BOOTLOADER + + config MCUBOOT_BOOTLOADER + bool "config as bootloader." + + config MCUBOOT_APPLICATION + bool "config as application." + endchoice + endif + menu "config board peripheral" config MOUNT_SDCARD bool diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c index af87f9229..23600e8ed 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c @@ -64,6 +64,10 @@ Modification: #include #endif +#ifdef BSP_USING_OTA +#include +#endif + #ifdef BSP_USING_SEMC extern status_t BOARD_InitSEMC(void); #ifdef BSP_USING_EXTSRAM @@ -330,12 +334,12 @@ struct InitSequenceDesc _board_init[] = #endif #ifdef BSP_USING_SDIO - { "sdio", Imxrt1052HwSdioInit }, + { "sdio", Imxrt1052HwSdioInit }, #endif #ifdef BSP_USING_USB #ifdef BSP_USING_NXP_USBH - { "nxp hw usb", Imxrt1052HwUsbHostInit }, + { "nxp hw usb", Imxrt1052HwUsbHostInit }, #endif #endif @@ -344,7 +348,7 @@ struct InitSequenceDesc _board_init[] = #endif #ifdef BSP_USING_LCD - { "hw_lcd", Imxrt1052HwLcdInit }, + { "hw_lcd", Imxrt1052HwLcdInit }, #endif #ifdef BSP_USING_TOUCH @@ -358,7 +362,7 @@ struct InitSequenceDesc _board_init[] = #ifdef BSP_USING_WDT { "hw_wdt", Imxrt1052HwWdgInit }, #endif - { " NONE ",NONE }, + { " NONE ",NONE }, }; /** @@ -367,7 +371,7 @@ struct InitSequenceDesc _board_init[] = void InitBoardHardware() { int i = 0; - int ret = 0; + int ret = 0; BOARD_ConfigMPU(); BOARD_InitPins(); @@ -403,10 +407,12 @@ void InitBoardHardware() KPrintf("board initialization......\n"); for(i = 0; _board_init[i].fn != NONE; i++) { - ret = _board_init[i].fn(); - KPrintf("initialize %s %s\n",_board_init[i].fn_name, ret == 0 ? "success" : "failed"); - } + ret = _board_init[i].fn(); + KPrintf("initialize %s %s\n",_board_init[i].fn_name, ret == 0 ? "success" : "failed"); + } KPrintf("board init done.\n"); - KPrintf("start kernel...\n"); + KPrintf("start kernel...\n"); +#ifdef BSP_USING_OTA + FLASH_Init(); +#endif } - diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/config.mk b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/config.mk index e05bd2e19..4da08fe5c 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/config.mk +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/config.mk @@ -15,7 +15,11 @@ ifeq ($(CONFIG_RESOURCES_LWIP), y) export LINK_LWIP := $(KERNEL_ROOT)/resources/ethernet/LwIP/liblwip.a endif -ifeq ($(CONFIG_BSP_USING_USB),y) +ifeq ($(CONFIG_MCUBOOT_BOOTLOADER),y) +export LFLAGS += -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-xidatong-arm32-boot.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link-bootloader.lds +else ifeq ($(CONFIG_MCUBOOT_APPLICATION),y) +export LFLAGS += -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-xidatong-arm32-app.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link-application.lds +else ifeq ($(CONFIG_BSP_USING_USB),y) export LFLAGS += -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-xidatong-arm32.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link-usb.lds else export LFLAGS += -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-xidatong-arm32.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds @@ -28,5 +32,9 @@ export APPLFLAGS := -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections export DEFINES := -DHAVE_CCONFIG_H -DCPU_MIMXRT1052CVL5B -DSKIP_SYSCLK_INIT -DEVK_MCIMXRM -DFSL_SDK_ENABLE_DRIVER_CACHE_CONTROL=1 -DXIP_EXTERNAL_FLASH=1 -D__STARTUP_INITIALIZE_NONCACHEDATA -D__STARTUP_CLEAR_BSS +ifeq ($(CONFIG_MCUBOOT_BOOTLOADER),y) +export DEFINES += -D__BOOTLOADER +endif + export ARCH = arm export MCU = cortex-m7 diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/include/clock_config.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/include/clock_config.h index 96d9691c3..29570d854 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/include/clock_config.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/include/clock_config.h @@ -50,6 +50,53 @@ void BOARD_InitBootClocks(void); ******************************************************************************/ #define BOARD_BOOTCLOCKRUN_CORE_CLOCK 600000000U /*!< Core clock frequency: 600000000Hz */ +/* Clock outputs (values are in Hz): */ +#define BOARD_BOOTCLOCKRUN_AHB_CLK_ROOT 600000000UL +#define BOARD_BOOTCLOCKRUN_CAN_CLK_ROOT 40000000UL +#define BOARD_BOOTCLOCKRUN_CKIL_SYNC_CLK_ROOT 32768UL +#define BOARD_BOOTCLOCKRUN_CLKO1_CLK 0UL +#define BOARD_BOOTCLOCKRUN_CLKO2_CLK 0UL +#define BOARD_BOOTCLOCKRUN_CLK_1M 1000000UL +#define BOARD_BOOTCLOCKRUN_CLK_24M 24000000UL +#define BOARD_BOOTCLOCKRUN_CSI_CLK_ROOT 12000000UL +#define BOARD_BOOTCLOCKRUN_ENET1_TX_CLK 2400000UL +#define BOARD_BOOTCLOCKRUN_ENET_125M_CLK 2400000UL +#define BOARD_BOOTCLOCKRUN_ENET_25M_REF_CLK 1200000UL +#define BOARD_BOOTCLOCKRUN_FLEXIO1_CLK_ROOT 30000000UL +#define BOARD_BOOTCLOCKRUN_FLEXIO2_CLK_ROOT 30000000UL +#define BOARD_BOOTCLOCKRUN_FLEXSPI_CLK_ROOT 160000000UL +#define BOARD_BOOTCLOCKRUN_GPT1_IPG_CLK_HIGHFREQ 75000000UL +#define BOARD_BOOTCLOCKRUN_GPT2_IPG_CLK_HIGHFREQ 75000000UL +#define BOARD_BOOTCLOCKRUN_IPG_CLK_ROOT 150000000UL +#define BOARD_BOOTCLOCKRUN_LCDIF_CLK_ROOT 9642857UL +#define BOARD_BOOTCLOCKRUN_LPI2C_CLK_ROOT 60000000UL +#define BOARD_BOOTCLOCKRUN_LPSPI_CLK_ROOT 105600000UL +#define BOARD_BOOTCLOCKRUN_LVDS1_CLK 1200000000UL +#define BOARD_BOOTCLOCKRUN_MQS_MCLK 63529411UL +#define BOARD_BOOTCLOCKRUN_PERCLK_CLK_ROOT 75000000UL +#define BOARD_BOOTCLOCKRUN_PLL7_MAIN_CLK 24000000UL +#define BOARD_BOOTCLOCKRUN_SAI1_CLK_ROOT 63529411UL +#define BOARD_BOOTCLOCKRUN_SAI1_MCLK1 63529411UL +#define BOARD_BOOTCLOCKRUN_SAI1_MCLK2 63529411UL +#define BOARD_BOOTCLOCKRUN_SAI1_MCLK3 30000000UL +#define BOARD_BOOTCLOCKRUN_SAI2_CLK_ROOT 63529411UL +#define BOARD_BOOTCLOCKRUN_SAI2_MCLK1 63529411UL +#define BOARD_BOOTCLOCKRUN_SAI2_MCLK2 0UL +#define BOARD_BOOTCLOCKRUN_SAI2_MCLK3 30000000UL +#define BOARD_BOOTCLOCKRUN_SAI3_CLK_ROOT 63529411UL +#define BOARD_BOOTCLOCKRUN_SAI3_MCLK1 63529411UL +#define BOARD_BOOTCLOCKRUN_SAI3_MCLK2 0UL +#define BOARD_BOOTCLOCKRUN_SAI3_MCLK3 30000000UL +#define BOARD_BOOTCLOCKRUN_SEMC_CLK_ROOT 75000000UL +#define BOARD_BOOTCLOCKRUN_SPDIF0_CLK_ROOT 30000000UL +#define BOARD_BOOTCLOCKRUN_SPDIF0_EXTCLK_OUT 0UL +#define BOARD_BOOTCLOCKRUN_TRACE_CLK_ROOT 117333333UL +#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 80000000UL +#define BOARD_BOOTCLOCKRUN_USBPHY1_CLK 0UL +#define BOARD_BOOTCLOCKRUN_USBPHY2_CLK 0UL +#define BOARD_BOOTCLOCKRUN_USDHC1_CLK_ROOT 198000000UL +#define BOARD_BOOTCLOCKRUN_USDHC2_CLK_ROOT 198000000UL + /*! @brief Arm PLL set for BOARD_BootClockRUN configuration. */ extern const clock_arm_pll_config_t armPllConfig_BOARD_BootClockRUN; diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-application.lds b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-application.lds new file mode 100644 index 000000000..e42f2993e --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-application.lds @@ -0,0 +1,264 @@ +/* +** ################################################################### +** Processors: MIMXRT1052CVJ5B +** MIMXRT1052CVL5B +** MIMXRT1052DVJ6B +** MIMXRT1052DVL6B +** +** Compiler: GNU C Compiler +** Reference manual: IMXRT1050RM Rev.1, 03/2018 +** Version: rev. 1.0, 2018-09-21 +** Build: b180921 +** +** Abstract: +** Linker file for the GNU C Compiler +** +** Copyright 2016 Freescale Semiconductor, Inc. +** Copyright 2016-2018 NXP +** All rights reserved. +** +** SPDX-License-Identifier: BSD-3-Clause +** +** http: www.nxp.com +** mail: support@nxp.com +** +** ################################################################### +*/ + + +/** +* @file link.lds +* @brief xidatong-arm32 Linker script +* @version 1.0 +* @author AIIT XUOS Lab +* @date 2021-05-28 +*/ + +/************************************************* +File name: link.lds +Description: xidatong-arm32 Linker script +Others: take MIMXRT1052xxxxx_flexspi_nor.ld for references +History: +1. Date: 2021-05-28 +Author: AIIT XUOS Lab +Modification: +1. add shell cmd table and g_service_table +*************************************************/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +STACK_SIZE = 0x4000; + +/* Specify the memory areas */ +MEMORY +{ + m_interrupts (RX) : ORIGIN = 0x60040000, LENGTH = 0x00000400 + m_text (RX) : ORIGIN = 0x60040400, LENGTH = 0x000FFC00 + + m_data (RW) : ORIGIN = 0x20000000, LENGTH = 0x00020000 + m_data2 (RW) : ORIGIN = 0x20200000, LENGTH = 0x00060000 + + m_sdram (RW) : ORIGIN = 0x80000000, LENGTH = 0x01E00000 + m_nocache (RW) : ORIGIN = 0x81E00000, LENGTH = 0x00200000 +} + +/* Define output sections */ +SECTIONS +{ + /* The startup code goes first into internal RAM */ + .interrupts : + { + __VECTOR_TABLE = .; + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } > m_interrupts + + __VECTOR_RAM = __VECTOR_TABLE; + __RAM_VECTOR_TABLE_SIZE_BYTES = 0x0; + + /* The program code and other data goes into internal RAM */ + .text : + { + . = ALIGN(4); + *(EXCLUDE_FILE( + /* Exclude flash and frequently executed functions from XIP */ + *fsl_romapi.o + *flash.o + ) .text) /* .text sections (code) */ + *(EXCLUDE_FILE( + /* Exclude flash and frequently executed functions from XIP */ + *fsl_romapi.o + *flash.o + ) .text*) /* .text* sections (code) */ + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + KEEP (*(.init)) + KEEP (*(.fini)) + . = ALIGN(4); + + + /* section information for shell */ + . = ALIGN(4); + _shell_command_start = .; + KEEP (*(shellCommand)) + _shell_command_end = .; + . = ALIGN(4); + + __isrtbl_idx_start = .; + KEEP(*(.isrtbl.idx)) + __isrtbl_start = .; + KEEP(*(.isrtbl)) + __isrtbl_end = .; + . = ALIGN(4); + + PROVIDE(g_service_table_start = ABSOLUTE(.)); + KEEP(*(.g_service_table)) + PROVIDE(g_service_table_end = ABSOLUTE(.)); + } > m_text + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > m_text + + .ARM : + { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } > m_text + + .ctors : + { + __CTOR_LIST__ = .; + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + from the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + __CTOR_END__ = .; + } > m_text + + .dtors : + { + __DTOR_LIST__ = .; + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + __DTOR_END__ = .; + } > m_text + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } > m_text + + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } > m_text + + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } > m_text + + __etext = .; /* define a global symbol at end of code */ + __DATA_ROM = .; /* Symbol is used by startup for data initialization */ + + .data : AT(__DATA_ROM) + { + . = ALIGN(4); + __DATA_RAM = .; + __data_start__ = .; /* create a global symbol at data start */ + /* Explicit placement of flash and frequently executed functions in RAM */ + *fsl_romapi.o + *flash.o + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + KEEP(*(.jcr*)) + . = ALIGN(4); + PROVIDE(_sramfuncs = ABSOLUTE(.)); + KEEP(*(RamFunction)) + PROVIDE(_eramfuncs = ABSOLUTE(.)); + __data_end__ = .; /* define a global symbol at data end */ + } > m_data + + __NDATA_ROM = __DATA_ROM + (__data_end__ - __data_start__); + .ncache.init : AT(__NDATA_ROM) + { + __noncachedata_start__ = .; /* create a global symbol at ncache data start */ + *(NonCacheable.init) + . = ALIGN(4); + __noncachedata_init_end__ = .; /* create a global symbol at initialized ncache data end */ + } > m_nocache + . = __noncachedata_init_end__; + .ncache : + { + *(NonCacheable) + . = ALIGN(4); + __noncachedata_end__ = .; /* define a global symbol at ncache data end */ + } > m_nocache + + __DATA_END = __NDATA_ROM + (__noncachedata_init_end__ - __noncachedata_start__); + text_end = ORIGIN(m_text) + LENGTH(m_text); + ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data") + + /* Uninitialized data section */ + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + . = ALIGN(4); + __START_BSS = .; + __bss_start__ = .; + *(.bss) + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + __END_BSS = .; + } > m_data + + .stack : + { + . = ALIGN(8); + stack_start = .; + . += STACK_SIZE; + stack_end = .; + __StackTop = .; + heap_start = .; + } > m_data2 + + PROVIDE(heap_end = ORIGIN(m_data2) + LENGTH(m_data2)); + + .ARM.attributes 0 : { *(.ARM.attributes) } +} + diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-bootloader.lds b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-bootloader.lds new file mode 100644 index 000000000..fea1de877 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-bootloader.lds @@ -0,0 +1,280 @@ +/* +** ################################################################### +** Processors: MIMXRT1052CVJ5B +** MIMXRT1052CVL5B +** MIMXRT1052DVJ6B +** MIMXRT1052DVL6B +** +** Compiler: GNU C Compiler +** Reference manual: IMXRT1050RM Rev.1, 03/2018 +** Version: rev. 1.0, 2018-09-21 +** Build: b180921 +** +** Abstract: +** Linker file for the GNU C Compiler +** +** Copyright 2016 Freescale Semiconductor, Inc. +** Copyright 2016-2018 NXP +** All rights reserved. +** +** SPDX-License-Identifier: BSD-3-Clause +** +** http: www.nxp.com +** mail: support@nxp.com +** +** ################################################################### +*/ + + +/** +* @file link.lds +* @brief xidatong-arm32 Linker script +* @version 1.0 +* @author AIIT XUOS Lab +* @date 2021-05-28 +*/ + +/************************************************* +File name: link.lds +Description: xidatong-arm32 Linker script +Others: take MIMXRT1052xxxxx_flexspi_nor.ld for references +History: +1. Date: 2021-05-28 +Author: AIIT XUOS Lab +Modification: +1. add shell cmd table and g_service_table +*************************************************/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +STACK_SIZE = 0x8000; + +/* Specify the memory areas */ +MEMORY +{ + m_boot_data (RX) : ORIGIN = 0x60000000, LENGTH = 0x00001000 + m_image_vertor_table (RX) : ORIGIN = 0x60001000, LENGTH = 0x00001000 + + /*bootloader*/ + m_interrupts (RX) : ORIGIN = 0x60002000, LENGTH = 0x00000400 + m_text (RX) : ORIGIN = 0x60002400, LENGTH = 0x0003DC00 + + m_data (RW) : ORIGIN = 0x20000000, LENGTH = 0x00020000 + m_data2 (RW) : ORIGIN = 0x20200000, LENGTH = 0x00060000 + + m_sdram (RW) : ORIGIN = 0x80000000, LENGTH = 0x01E00000 + m_nocache (RW) : ORIGIN = 0x81E00000, LENGTH = 0x00200000 +} + +/* Define output sections */ +SECTIONS +{ + .boot_data : + { + KEEP(*(.boot_hdr.conf)) + } > m_boot_data + + .image_vertor_table : + { + KEEP(*(.boot_hdr.ivt)) + KEEP(*(.boot_hdr.boot_data)) + KEEP(*(.boot_hdr.dcd_data)) + } > m_image_vertor_table + + /* The startup code goes first into internal RAM */ + .interrupts : + { + __VECTOR_TABLE = .; + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } > m_interrupts + + __VECTOR_RAM = __VECTOR_TABLE; + __RAM_VECTOR_TABLE_SIZE_BYTES = 0x0; + + /* The program code and other data goes into internal RAM */ + .text : + { + . = ALIGN(4); + *(EXCLUDE_FILE( + /* Exclude flash and frequently executed functions from XIP */ + *fsl_romapi.o + *flash.o + ) .text) /* .text sections (code) */ + *(EXCLUDE_FILE( + /* Exclude flash and frequently executed functions from XIP */ + *fsl_romapi.o + *flash.o + ) .text*) /* .text* sections (code) */ + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + KEEP (*(.init)) + KEEP (*(.fini)) + . = ALIGN(4); + + + /* section information for shell */ + . = ALIGN(4); + _shell_command_start = .; + KEEP (*(shellCommand)) + _shell_command_end = .; + . = ALIGN(4); + + __isrtbl_idx_start = .; + KEEP(*(.isrtbl.idx)) + __isrtbl_start = .; + KEEP(*(.isrtbl)) + __isrtbl_end = .; + . = ALIGN(4); + + PROVIDE(g_service_table_start = ABSOLUTE(.)); + KEEP(*(.g_service_table)) + PROVIDE(g_service_table_end = ABSOLUTE(.)); + } > m_text + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > m_text + + .ARM : + { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } > m_text + + .ctors : + { + __CTOR_LIST__ = .; + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + from the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + __CTOR_END__ = .; + } > m_text + + .dtors : + { + __DTOR_LIST__ = .; + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + __DTOR_END__ = .; + } > m_text + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } > m_text + + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } > m_text + + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } > m_text + + __etext = .; /* define a global symbol at end of code */ + __DATA_ROM = .; /* Symbol is used by startup for data initialization */ + + .data : AT(__DATA_ROM) + { + . = ALIGN(4); + __DATA_RAM = .; + __data_start__ = .; /* create a global symbol at data start */ + /* Explicit placement of flash and frequently executed functions in RAM */ + *fsl_romapi.o + *flash.o + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + KEEP(*(.jcr*)) + . = ALIGN(4); + PROVIDE(_sramfuncs = ABSOLUTE(.)); + KEEP(*(RamFunction)) + PROVIDE(_eramfuncs = ABSOLUTE(.)); + __data_end__ = .; /* define a global symbol at data end */ + } > m_data + + __NDATA_ROM = __DATA_ROM + (__data_end__ - __data_start__); + .ncache.init : AT(__NDATA_ROM) + { + __noncachedata_start__ = .; /* create a global symbol at ncache data start */ + *(NonCacheable.init) + . = ALIGN(4); + __noncachedata_init_end__ = .; /* create a global symbol at initialized ncache data end */ + } > m_nocache + . = __noncachedata_init_end__; + .ncache : + { + *(NonCacheable) + . = ALIGN(4); + __noncachedata_end__ = .; /* define a global symbol at ncache data end */ + } > m_nocache + + __DATA_END = __NDATA_ROM + (__noncachedata_init_end__ - __noncachedata_start__); + text_end = ORIGIN(m_text) + LENGTH(m_text); + ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data") + + /* Uninitialized data section */ + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + . = ALIGN(4); + __START_BSS = .; + __bss_start__ = .; + *(.bss) + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + __END_BSS = .; + } > m_data + + .stack : + { + . = ALIGN(8); + stack_start = .; + . += STACK_SIZE; + stack_end = .; + __StackTop = .; + heap_start = .; + } > m_data + + PROVIDE(heap_end = ORIGIN(m_data) + LENGTH(m_data)); + + .ARM.attributes 0 : { *(.ARM.attributes) } +} + diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link.lds b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link.lds index 1940e5b81..0147853db 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link.lds +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link.lds @@ -260,5 +260,4 @@ SECTIONS PROVIDE(heap_end = ORIGIN(m_data2) + LENGTH(m_data2)); .ARM.attributes 0 : { *(.ARM.attributes) } -} - +} \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile index 7fda1f6bc..463b67808 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile @@ -4,4 +4,8 @@ ifeq ($(CONFIG_BSP_USING_SDIO),y) SRC_FILES += fsl_usdhc.c endif +ifeq ($(CONFIG_BSP_USING_OTA),y) + SRC_FILES += fsl_romapi.c flash.c mcuboot.c +endif + include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/clock_config.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/clock_config.c index 3e514b72e..b4c9a5fcd 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/clock_config.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/clock_config.c @@ -78,11 +78,11 @@ outputs: - {id: ENET_25M_REF_CLK.outFreq, value: 1.2 MHz} - {id: FLEXIO1_CLK_ROOT.outFreq, value: 30 MHz} - {id: FLEXIO2_CLK_ROOT.outFreq, value: 30 MHz} -- {id: FLEXSPI_CLK_ROOT.outFreq, value: 2880/11 MHz} +- {id: FLEXSPI_CLK_ROOT.outFreq, value: 160 MHz} - {id: GPT1_ipg_clk_highfreq.outFreq, value: 75 MHz} - {id: GPT2_ipg_clk_highfreq.outFreq, value: 75 MHz} - {id: IPG_CLK_ROOT.outFreq, value: 150 MHz} -- {id: LCDIF_CLK_ROOT.outFreq, value: 67.5/7 MHz} +- {id: LCDIF_CLK_ROOT.outFreq, value: 67.5 MHz} - {id: LPI2C_CLK_ROOT.outFreq, value: 60 MHz} - {id: LPSPI_CLK_ROOT.outFreq, value: 105.6 MHz} - {id: LVDS1_CLK.outFreq, value: 1.2 GHz} @@ -108,10 +108,8 @@ outputs: settings: - {id: CCM.AHB_PODF.scale, value: '1', locked: true} - {id: CCM.ARM_PODF.scale, value: '2', locked: true} -- {id: CCM.FLEXSPI_PODF.scale, value: '1', locked: true} -- {id: CCM.FLEXSPI_SEL.sel, value: CCM_ANALOG.PLL3_PFD0_CLK} -- {id: CCM.LCDIF_PODF.scale, value: '8', locked: true} -- {id: CCM.LCDIF_PRED.scale, value: '7', locked: true} +- {id: CCM.FLEXSPI_PODF.scale, value: '3', locked: true} +- {id: CCM.FLEXSPI_SEL.sel, value: CCM.PLL3_SW_CLK_SEL} - {id: CCM.LPSPI_PODF.scale, value: '5', locked: true} - {id: CCM.PERCLK_PODF.scale, value: '2', locked: true} - {id: CCM.SEMC_PODF.scale, value: '8'} @@ -148,23 +146,20 @@ sources: /******************************************************************************* * Variables for BOARD_BootClockRUN configuration ******************************************************************************/ -const clock_arm_pll_config_t armPllConfig_BOARD_BootClockRUN = - { - .loopDivider = 100, /* PLL loop divider, Fout = Fin * 50 */ - .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ - }; -const clock_sys_pll_config_t sysPllConfig_BOARD_BootClockRUN = - { - .loopDivider = 1, /* PLL loop divider, Fout = Fin * ( 20 + loopDivider*2 + numerator / denominator ) */ - .numerator = 0, /* 30 bit numerator of fractional loop divider */ - .denominator = 1, /* 30 bit denominator of fractional loop divider */ - .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ - }; -const clock_usb_pll_config_t usb1PllConfig_BOARD_BootClockRUN = - { - .loopDivider = 0, /* PLL loop divider, Fout = Fin * 20 */ - .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ - }; +const clock_arm_pll_config_t armPllConfig_BOARD_BootClockRUN = { + .loopDivider = 100, /* PLL loop divider, Fout = Fin * 50 */ + .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ +}; +const clock_sys_pll_config_t sysPllConfig_BOARD_BootClockRUN = { + .loopDivider = 1, /* PLL loop divider, Fout = Fin * ( 20 + loopDivider*2 + numerator / denominator ) */ + .numerator = 0, /* 30 bit numerator of fractional loop divider */ + .denominator = 1, /* 30 bit denominator of fractional loop divider */ + .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ +}; +const clock_usb_pll_config_t usb1PllConfig_BOARD_BootClockRUN = { + .loopDivider = 0, /* PLL loop divider, Fout = Fin * 20 */ + .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ +}; /******************************************************************************* * Code for BOARD_BootClockRUN configuration ******************************************************************************/ @@ -229,9 +224,10 @@ void BOARD_BootClockRUN(void) CLOCK_SetDiv(kCLOCK_Usdhc2Div, 1); /* Set Usdhc2 clock source. */ CLOCK_SetMux(kCLOCK_Usdhc2Mux, 0); - /* In SDK projects, SDRAM (configured by SEMC) will be initialized in either debug script or dcd. - * With this macro SKIP_SYSCLK_INIT, system pll (selected to be SEMC source clock in SDK projects) will be left unchanged. - * Note: If another clock source is selected for SEMC, user may want to avoid changing that clock as well.*/ +/* In SDK projects, SDRAM (configured by SEMC) will be initialized in either debug script or dcd. + * With this macro SKIP_SYSCLK_INIT, system pll (selected to be SEMC source clock in SDK projects) will be left + * unchanged. + * Note: If another clock source is selected for SEMC, user may want to avoid changing that clock as well.*/ #ifndef SKIP_SYSCLK_INIT /* Disable Semc clock gate. */ CLOCK_DisableClock(kCLOCK_Semc); @@ -242,16 +238,17 @@ void BOARD_BootClockRUN(void) /* Set Semc clock source. */ CLOCK_SetMux(kCLOCK_SemcMux, 0); #endif - /* In SDK projects, external flash (configured by FLEXSPI) will be initialized by dcd. - * With this macro XIP_EXTERNAL_FLASH, usb1 pll (selected to be FLEXSPI clock source in SDK projects) will be left unchanged. - * Note: If another clock source is selected for FLEXSPI, user may want to avoid changing that clock as well.*/ +/* In SDK projects, external flash (configured by FLEXSPI) will be initialized by dcd. + * With this macro XIP_EXTERNAL_FLASH, usb1 pll (selected to be FLEXSPI clock source in SDK projects) will be left + * unchanged. + * Note: If another clock source is selected for FLEXSPI, user may want to avoid changing that clock as well.*/ #if !(defined(XIP_EXTERNAL_FLASH) && (XIP_EXTERNAL_FLASH == 1)) /* Disable Flexspi clock gate. */ CLOCK_DisableClock(kCLOCK_FlexSpi); /* Set FLEXSPI_PODF. */ - CLOCK_SetDiv(kCLOCK_FlexspiDiv, 0); + CLOCK_SetDiv(kCLOCK_FlexspiDiv, 2); /* Set Flexspi clock source. */ - CLOCK_SetMux(kCLOCK_FlexspiMux, 3); + CLOCK_SetMux(kCLOCK_FlexspiMux, 1); #endif /* Disable CSI clock gate. */ CLOCK_DisableClock(kCLOCK_Csi); @@ -331,9 +328,9 @@ void BOARD_BootClockRUN(void) /* Disable LCDIF clock gate. */ CLOCK_DisableClock(kCLOCK_LcdPixel); /* Set LCDIF_PRED. */ - CLOCK_SetDiv(kCLOCK_LcdifPreDiv, 6); + CLOCK_SetDiv(kCLOCK_LcdifPreDiv, 1); /* Set LCDIF_CLK_PODF. */ - CLOCK_SetDiv(kCLOCK_LcdifDiv, 7); + CLOCK_SetDiv(kCLOCK_LcdifDiv, 3); /* Set Lcdif pre clock source. */ CLOCK_SetMux(kCLOCK_LcdifPreMux, 5); /* Disable SPDIF clock gate. */ @@ -365,8 +362,9 @@ void BOARD_BootClockRUN(void) /* Init ARM PLL. */ CLOCK_InitArmPll(&armPllConfig_BOARD_BootClockRUN); /* In SDK projects, SDRAM (configured by SEMC) will be initialized in either debug script or dcd. - * With this macro SKIP_SYSCLK_INIT, system pll (selected to be SEMC source clock in SDK projects) will be left unchanged. - * Note: If another clock source is selected for SEMC, user may want to avoid changing that clock as well.*/ + * With this macro SKIP_SYSCLK_INIT, system pll (selected to be SEMC source clock in SDK projects) will be left + * unchanged. Note: If another clock source is selected for SEMC, user may want to avoid changing that clock as + * well.*/ #ifndef SKIP_SYSCLK_INIT /* Init System PLL. */ CLOCK_InitSysPll(&sysPllConfig_BOARD_BootClockRUN); @@ -382,8 +380,9 @@ void BOARD_BootClockRUN(void) CCM_ANALOG->PLL_SYS &= ~CCM_ANALOG_PLL_SYS_PFD_OFFSET_EN_MASK; #endif /* In SDK projects, external flash (configured by FLEXSPI) will be initialized by dcd. - * With this macro XIP_EXTERNAL_FLASH, usb1 pll (selected to be FLEXSPI clock source in SDK projects) will be left unchanged. - * Note: If another clock source is selected for FLEXSPI, user may want to avoid changing that clock as well.*/ + * With this macro XIP_EXTERNAL_FLASH, usb1 pll (selected to be FLEXSPI clock source in SDK projects) will be left + * unchanged. Note: If another clock source is selected for FLEXSPI, user may want to avoid changing that clock as + * well.*/ #if !(defined(XIP_EXTERNAL_FLASH) && (XIP_EXTERNAL_FLASH == 1)) /* Init Usb1 PLL. */ CLOCK_InitUsb1Pll(&usb1PllConfig_BOARD_BootClockRUN); @@ -420,7 +419,8 @@ void BOARD_BootClockRUN(void) /* Bypass Enet PLL. */ CLOCK_SetPllBypass(CCM_ANALOG, kCLOCK_PllEnet, 1); /* Set Enet output divider. */ - CCM_ANALOG->PLL_ENET = (CCM_ANALOG->PLL_ENET & (~CCM_ANALOG_PLL_ENET_DIV_SELECT_MASK)) | CCM_ANALOG_PLL_ENET_DIV_SELECT(1); + CCM_ANALOG->PLL_ENET = + (CCM_ANALOG->PLL_ENET & (~CCM_ANALOG_PLL_ENET_DIV_SELECT_MASK)) | CCM_ANALOG_PLL_ENET_DIV_SELECT(1); /* Enable Enet output. */ CCM_ANALOG->PLL_ENET |= CCM_ANALOG_PLL_ENET_ENABLE_MASK; /* Enable Enet25M output. */ @@ -440,7 +440,8 @@ void BOARD_BootClockRUN(void) /* Set per clock source. */ CLOCK_SetMux(kCLOCK_PerclkMux, 0); /* Set lvds1 clock source. */ - CCM_ANALOG->MISC1 = (CCM_ANALOG->MISC1 & (~CCM_ANALOG_MISC1_LVDS1_CLK_SEL_MASK)) | CCM_ANALOG_MISC1_LVDS1_CLK_SEL(0); + CCM_ANALOG->MISC1 = + (CCM_ANALOG->MISC1 & (~CCM_ANALOG_MISC1_LVDS1_CLK_SEL_MASK)) | CCM_ANALOG_MISC1_LVDS1_CLK_SEL(0); /* Set clock out1 divider. */ CCM->CCOSR = (CCM->CCOSR & (~CCM_CCOSR_CLKO1_DIV_MASK)) | CCM_CCOSR_CLKO1_DIV(0); /* Set clock out1 source. */ @@ -466,7 +467,7 @@ void BOARD_BootClockRUN(void) /* Set SAI3 MCLK3 clock source. */ IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI3MClk3Sel, 0); /* Set MQS configuration. */ - IOMUXC_MQSConfig(IOMUXC_GPR,kIOMUXC_MqsPwmOverSampleRate32, 0); + IOMUXC_MQSConfig(IOMUXC_GPR, kIOMUXC_MqsPwmOverSampleRate32, 0); /* Set ENET Tx clock source. */ IOMUXC_EnableMode(IOMUXC_GPR, kIOMUXC_GPR_ENET1RefClkMode, false); /* Set GPT1 High frequency reference clock source. */ @@ -476,4 +477,3 @@ void BOARD_BootClockRUN(void) /* Set SystemCoreClock variable. */ SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK; } - diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c new file mode 100644 index 000000000..bd9df1124 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c @@ -0,0 +1,304 @@ +/* + * Copyright 2018-2020 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** +* @file flash.c +* @brief support flexspi norflash function +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-04-03 +*/ + +#include "flash.h" +#include "stdio.h" +#include "xs_base.h" + +/******************************************************************************* + * Definitions + ******************************************************************************/ + +/******************************************************************************* + * Prototypes + ******************************************************************************/ + +/******************************************************************************* + * Variables + ******************************************************************************/ +/*! @brief FLEXSPI NOR flash driver Structure in XIP config */ +extern flexspi_nor_config_t Qspiflash_config; +/*! @brief FLEXSPI NOR flash driver Structure in flash driver */ +static flexspi_nor_config_t norConfig; + +/******************************************************************************* + * Code + ******************************************************************************/ +/* Get FLEXSPI NOR Configuration Block */ +void FLEXSPI_NorFlash_GetConfig(flexspi_nor_config_t *config) +{ + /* Copy norflash config block from xip config */ + memcpy(config, &Qspiflash_config, sizeof(flexspi_nor_config_t)); +#ifndef HYPER_FLASH //QSPI Flash + /* Override some default config */ + config->memConfig.deviceType = kFLEXSPIDeviceType_SerialNOR; + config->memConfig.deviceModeType = kDeviceConfigCmdType_Generic; + config->memConfig.serialClkFreq = kFLEXSPISerialClk_30MHz; //Safe Serial Flash Frequencey + config->ipcmdSerialClkFreq = kFLEXSPISerialClk_30MHz; //Safe Clock frequency for IP command + config->memConfig.controllerMiscOption = FSL_ROM_FLEXSPI_BITMASK(kFLEXSPIMiscOffset_SafeConfigFreqEnable);//Always enable Safe configuration Frequency + + /* Read Status */ + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x05U, READ_SDR, FLEXSPI_1PAD, 0x1U); + + /* Write Enable */ + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x06U, STOP, FLEXSPI_1PAD, 0x0U); + + /* Page Program - quad mode */ + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM + 0U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x32U, RADDR_SDR, FLEXSPI_1PAD, 0x18U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM + 1U] = + FSL_ROM_FLEXSPI_LUT_SEQ(WRITE_SDR, FLEXSPI_4PAD, 0x04U, STOP, FLEXSPI_1PAD, 0x0U); + + /* Sector Erase */ + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xD7U, RADDR_SDR, FLEXSPI_1PAD, 0x18U); +#else + /* Override some default config */ + config->memConfig.deviceType = kFLEXSPIDeviceType_SerialNOR; + config->memConfig.deviceModeType = kDeviceConfigCmdType_Generic; + config->memConfig.lutCustomSeqEnable = true; + config->memConfig.busyOffset = 15U; + config->memConfig.busyBitPolarity = 1U; + config->ipcmdSerialClkFreq = kFLEXSPISerialClk_30MHz; //Safe Clock frequency for IP command + config->serialNorType = kSerialNorType_HyperBus; + // Read Status + // 0 + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x00U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS + 1U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xAAU); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS + 2U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x05U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS + 3U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x70U); + // 1 + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS + 4U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0xA0U, RADDR_DDR, FLEXSPI_8PAD, 0x18U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS + 5U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CADDR_DDR, FLEXSPI_8PAD, 0x10U, DUMMY_RWDS_DDR, FLEXSPI_8PAD, 0x0BU); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS + 6U] = + FSL_ROM_FLEXSPI_LUT_SEQ(READ_DDR, FLEXSPI_8PAD, 0x04U, STOP, FLEXSPI_1PAD, 0x00U); + + // Write Enable + // 0 + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x00U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE + 1U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xAAU); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE + 2U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x05U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE + 3U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xAAU); + // 1 + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE + 4U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x00U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE + 5U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x55U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE + 6U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x02U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE + 7U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x55U); + + // Page Program + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x00U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM + 1U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xAAU); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM + 2U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x05U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM + 3U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xA0U); + // 1 + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM + 4U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, RADDR_DDR, FLEXSPI_8PAD, 0x18U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM + 5U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CADDR_DDR, FLEXSPI_8PAD, 0x10U, WRITE_DDR, FLEXSPI_8PAD, 0x80U); + + // Erase Sector + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x00U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 1U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xAAU); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 2U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x05U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 3U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x80U); + // 1 + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 4U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x00U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 5U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xAAU); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 6U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x05U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 7U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xAAU); + // 2 + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 8U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x00U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 9U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x55U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 10U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x02U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 11U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x55U); + // 3 + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 12U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, RADDR_DDR, FLEXSPI_8PAD, 0x18U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 13U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CADDR_DDR, FLEXSPI_8PAD, 0x10U, CMD_DDR, FLEXSPI_8PAD, 0x00U); + config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 14U] = + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x30U, STOP, FLEXSPI_1PAD, 0x0U); + + // LUT customized sequence + config->memConfig.lutCustomSeq[NOR_CMD_INDEX_WRITEENABLE].seqNum = 2U; + config->memConfig.lutCustomSeq[NOR_CMD_INDEX_WRITEENABLE].seqId = NOR_CMD_LUT_SEQ_IDX_WRITEENABLE; + config->memConfig.lutCustomSeq[NOR_CMD_INDEX_READSTATUS].seqNum = 2U; + config->memConfig.lutCustomSeq[NOR_CMD_INDEX_READSTATUS].seqId = NOR_CMD_LUT_SEQ_IDX_READSTATUS; + config->memConfig.lutCustomSeq[NOR_CMD_INDEX_PAGEPROGRAM].seqNum = 2U; + config->memConfig.lutCustomSeq[NOR_CMD_INDEX_PAGEPROGRAM].seqId = NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM; + config->memConfig.lutCustomSeq[NOR_CMD_INDEX_ERASESECTOR].seqNum = 4U; + config->memConfig.lutCustomSeq[NOR_CMD_INDEX_ERASESECTOR].seqId = NOR_CMD_LUT_SEQ_IDX_ERASESECTOR; +#endif +} + + /** + * @brief 获得扇区大小 + * @note None + * @param None + * @retval Flash扇区尺寸 + */ +uint32_t FLASH_GetSectorSize(void) +{ +#ifndef HYPER_FLASH + return 4096;//QSPI Flash Sector Size +#else + return 256*1024UL;//Hyper Flash Sector Size +#endif +} + + /** + * @brief 获得最小编程长度 + * @note None + * @param None + * @retval 256 or 512 for QSPI Flash + */ +uint32_t FLASH_GetProgramCmd(void) +{ +#ifndef HYPER_FLASH + return 256;//QSPI Flash Page Program +#else + return 512;//Hyper Flash Page Program +#endif +} + /** + * @brief 初始化Flash + * @note None + * @param None + * @retval None + */ +void FLASH_Init(void) +{ + /* Clean up FLEXSPI NOR flash driver Structure */ + memset(&norConfig, 0U, sizeof(flexspi_nor_config_t)); + /* Setup FLEXSPI NOR Configuration Block */ + FLEXSPI_NorFlash_GetConfig(&norConfig); + /* Initializes the FLEXSPI module for the other FLEXSPI APIs */ + ROM_FLEXSPI_NorFlash_Init(0, &norConfig); + /* Reset the Flexspi's Cache */ + ROM_FLEXSPI_NorFlash_ClearCache(0); +} + /** + * @brief 反初始化Flash + * @note None + * @param None + * @retval None + */ +void FLASH_DeInit(void) +{ + /* Clear the FlexSPI LUT to avoid unexpected erase or program operion trigger */ + memset(&norConfig, 0U, sizeof(flexspi_nor_config_t)); + ROM_FLEXSPI_NorFlash_UpdateLut(0, NOR_CMD_LUT_SEQ_IDX_READSTATUS, norConfig.memConfig.lookupTable, sizeof(norConfig.memConfig.lookupTable)-(4*NOR_CMD_LUT_SEQ_IDX_READSTATUS)); + /* Reset the Flexspi's Cache */ + ROM_FLEXSPI_NorFlash_ClearCache(0); +} + + /** + * @brief 擦除Flash扇区 + * @note 该功能将删除一个Flash扇区的内容 + * @param addr: 擦除区域起始地址 + * @retval 返回操作结果 + */ +status_t FLASH_EraseSector(uint32_t addr) +{ + status_t status; + addr &= 0x0FFFFFFF; + + __disable_irq(); + status = ROM_FLEXSPI_NorFlash_Erase(0, &norConfig, addr, norConfig.sectorSize); + __enable_irq(); + + return status; +} + + /** + * @brief 写Flash一个页 + * @note 字节数小于等于一页 + * @param addr: 开始地址 + * @param buf : 写入数据起始指针 + * @param len : 字节数 + * @retval kStatus_Success:完成 + */ +status_t FLASH_WritePage(uint32_t addr, const uint8_t *buf, uint32_t len) +{ + status_t status; + addr &= 0x0FFFFFFF; + __disable_irq(); + norConfig.pageSize = len; + status = ROM_FLEXSPI_NorFlash_ProgramPage(0, &norConfig, addr, (const uint32_t *)buf); + __enable_irq(); + + return status; +} + /** + * @brief 读Flash内容 + * @param addr: 开始地址 + * @param buf : 读缓存指针 + * @param len : 字节数 + * @retval kStatus_Success:完成 + */ +status_t FLASH_Read(uint32_t addr, const uint8_t *buf, uint32_t len) +{ + status_t status; + flexspi_xfer_t flashXfer; + + addr &= 0x0FFFFFFF; + + flashXfer.operation = kFLEXSPIOperation_Read; + flashXfer.seqNum = 1; + flashXfer.seqId = NOR_CMD_LUT_SEQ_IDX_READ; + flashXfer.baseAddress = addr; + flashXfer.isParallelModeEnable = false; + flashXfer.rxBuffer = (uint32_t *)buf; + flashXfer.rxSize = len; + + __disable_irq(); + ROM_FLEXSPI_NorFlash_ClearCache(0); + status = ROM_FLEXSPI_NorFlash_CommandXfer(0, &flashXfer); + __enable_irq(); + + return status; +} \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/fsl_clock.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/fsl_clock.c index fae70f54a..b4a4ca2d5 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/fsl_clock.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/fsl_clock.c @@ -1,5 +1,5 @@ /* - * Copyright 2017 NXP + * Copyright 2017 - 2020 NXP * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -26,7 +26,7 @@ achieve better performance, it is depend on the IDE Floating point settings, if in IDE, clock_64b_t will switch to double type automatically. only support IAR and MDK here */ #if __FPU_USED -#if ((defined(__ICCARM__)) || (defined(__GNUC__))) +#if (defined(__ICCARM__)) #if (__ARMVFP__ >= __ARMFPV5__) && \ (__ARM_FP == 0xE) /*0xe implies support for half, single and double precision operations*/ @@ -35,6 +35,14 @@ typedef double clock_64b_t; typedef uint64_t clock_64b_t; #endif +#elif (defined(__GNUC__)) + +#if (__ARM_FP == 0xE) /*0xe implies support for half, single and double precision operations*/ +typedef double clock_64b_t; +#else +typedef uint64_t clock_64b_t; +#endif + #elif defined(__CC_ARM) || defined(__ARMCC_VERSION) #if defined __TARGET_FPU_FPV5_D16 @@ -71,6 +79,13 @@ volatile uint32_t g_rtcXtalFreq; */ static uint32_t CLOCK_GetPeriphClkFreq(void); +/*! + * @brief Get the frequency of PLL USB1 software clock. + * + * @return The frequency of PLL USB1 software clock. + */ +static uint32_t CLOCK_GetPllUsb1SWFreq(void); + /******************************************************************************* * Code ******************************************************************************/ @@ -80,7 +95,7 @@ static uint32_t CLOCK_GetPeriphClkFreq(void) uint32_t freq; /* Periph_clk2_clk ---> Periph_clk */ - if (CCM->CBCDR & CCM_CBCDR_PERIPH_CLK_SEL_MASK) + if ((CCM->CBCDR & CCM_CBCDR_PERIPH_CLK_SEL_MASK) != 0U) { switch (CCM->CBCMR & CCM_CBCMR_PERIPH_CLK2_SEL_MASK) { @@ -141,6 +156,30 @@ static uint32_t CLOCK_GetPeriphClkFreq(void) return freq; } +static uint32_t CLOCK_GetPllUsb1SWFreq(void) +{ + uint32_t freq; + + switch ((CCM->CCSR & CCM_CCSR_PLL3_SW_CLK_SEL_MASK) >> CCM_CCSR_PLL3_SW_CLK_SEL_SHIFT) + { + case 0: + { + freq = CLOCK_GetPllFreq(kCLOCK_PllUsb1); + break; + } + case 1: + { + freq = 24000000UL; + break; + } + default: + freq = 0UL; + break; + } + + return freq; +} + /*! * brief Initialize the external 24MHz clock. * @@ -161,11 +200,11 @@ void CLOCK_InitExternalClk(bool bypassXtalOsc) assert(!bypassXtalOsc); CCM_ANALOG->MISC0_CLR = CCM_ANALOG_MISC0_XTAL_24M_PWD_MASK; /* Power up */ - while ((XTALOSC24M->LOWPWR_CTRL & XTALOSC24M_LOWPWR_CTRL_XTALOSC_PWRUP_STAT_MASK) == 0) + while ((XTALOSC24M->LOWPWR_CTRL & XTALOSC24M_LOWPWR_CTRL_XTALOSC_PWRUP_STAT_MASK) == 0U) { } CCM_ANALOG->MISC0_SET = CCM_ANALOG_MISC0_OSC_XTALOK_EN_MASK; /* detect freq */ - while ((CCM_ANALOG->MISC0 & CCM_ANALOG_MISC0_OSC_XTALOK_MASK) == 0) + while ((CCM_ANALOG->MISC0 & CCM_ANALOG_MISC0_OSC_XTALOK_MASK) == 0UL) { } CCM_ANALOG->MISC0_CLR = CCM_ANALOG_MISC0_OSC_XTALOK_EN_MASK; @@ -194,9 +233,13 @@ void CLOCK_DeinitExternalClk(void) void CLOCK_SwitchOsc(clock_osc_t osc) { if (osc == kCLOCK_RcOsc) + { XTALOSC24M->LOWPWR_CTRL_SET = XTALOSC24M_LOWPWR_CTRL_SET_OSC_SEL_MASK; + } else + { XTALOSC24M->LOWPWR_CTRL_CLR = XTALOSC24M_LOWPWR_CTRL_CLR_OSC_SEL_MASK; + } } /*! @@ -235,10 +278,10 @@ uint32_t CLOCK_GetSemcFreq(void) uint32_t freq; /* SEMC alternative clock ---> SEMC Clock */ - if (CCM->CBCDR & CCM_CBCDR_SEMC_CLK_SEL_MASK) + if ((CCM->CBCDR & CCM_CBCDR_SEMC_CLK_SEL_MASK) != 0U) { /* PLL3 PFD1 ---> SEMC alternative clock ---> SEMC Clock */ - if (CCM->CBCDR & CCM_CBCDR_SEMC_ALT_CLK_SEL_MASK) + if ((CCM->CBCDR & CCM_CBCDR_SEMC_ALT_CLK_SEL_MASK) != 0U) { freq = CLOCK_GetUsb1PfdFreq(kCLOCK_Pfd1); } @@ -279,14 +322,14 @@ uint32_t CLOCK_GetPerClkFreq(void) uint32_t freq; /* Osc_clk ---> PER Clock*/ - if (CCM->CSCMR1 & CCM_CSCMR1_PERCLK_CLK_SEL_MASK) + if ((CCM->CSCMR1 & CCM_CSCMR1_PERCLK_CLK_SEL_MASK) != 0U) { freq = CLOCK_GetOscFreq(); } /* Periph_clk ---> AHB Clock ---> IPG Clock ---> PER Clock */ else { - freq = CLOCK_GetFreq(kCLOCK_IpgClk); + freq = CLOCK_GetIpgFreq(); } freq /= (((CCM->CSCMR1 & CCM_CSCMR1_PERCLK_PODF_MASK) >> CCM_CSCMR1_PERCLK_PODF_SHIFT) + 1U); @@ -350,6 +393,18 @@ uint32_t CLOCK_GetFreq(clock_name_t name) case kCLOCK_Usb1PllPfd3Clk: freq = CLOCK_GetUsb1PfdFreq(kCLOCK_Pfd3); break; + case kCLOCK_Usb1SwClk: + freq = CLOCK_GetPllUsb1SWFreq(); + break; + case kCLOCK_Usb1Sw120MClk: + freq = CLOCK_GetPllUsb1SWFreq() / 4UL; + break; + case kCLOCK_Usb1Sw60MClk: + freq = CLOCK_GetPllUsb1SWFreq() / 8UL; + break; + case kCLOCK_Usb1Sw80MClk: + freq = CLOCK_GetPllUsb1SWFreq() / 6UL; + break; case kCLOCK_Usb2PllClk: freq = CLOCK_GetPllFreq(kCLOCK_PllUsb2); break; @@ -388,6 +443,45 @@ uint32_t CLOCK_GetFreq(clock_name_t name) return freq; } +/*! + * brief Gets the frequency of selected clock root. + * + * param clockRoot The clock root used to get the frequency, please refer to @ref clock_root_t. + * return The frequency of selected clock root. + */ +uint32_t CLOCK_GetClockRootFreq(clock_root_t clockRoot) +{ + const clock_name_t clockRootSourceArray[][6] = CLOCK_ROOT_SOUCE; + const clock_mux_t clockRootMuxTupleArray[] = CLOCK_ROOT_MUX_TUPLE; + const clock_div_t clockRootDivTupleArray[][2] = CLOCK_ROOT_DIV_TUPLE; + uint32_t freq = 0UL; + clock_mux_t clockRootMuxTuple = clockRootMuxTupleArray[(uint8_t)clockRoot]; + clock_div_t clockRootPreDivTuple = clockRootDivTupleArray[(uint8_t)clockRoot][0]; + clock_div_t clockRootPostDivTuple = clockRootDivTupleArray[(uint8_t)clockRoot][1]; + uint32_t clockRootMuxValue = (CCM_TUPLE_REG(CCM, clockRootMuxTuple) & CCM_TUPLE_MASK(clockRootMuxTuple)) >> + CCM_TUPLE_SHIFT(clockRootMuxTuple); + clock_name_t clockSourceName; + + clockSourceName = clockRootSourceArray[(uint8_t)clockRoot][clockRootMuxValue]; + + assert(clockSourceName != kCLOCK_NoneName); + + freq = CLOCK_GetFreq(clockSourceName); + + if (clockRootPreDivTuple != kCLOCK_NonePreDiv) + { + freq /= ((CCM_TUPLE_REG(CCM, clockRootPreDivTuple) & CCM_TUPLE_MASK(clockRootPreDivTuple)) >> + CCM_TUPLE_SHIFT(clockRootPreDivTuple)) + + 1UL; + } + + freq /= ((CCM_TUPLE_REG(CCM, clockRootPostDivTuple) & CCM_TUPLE_MASK(clockRootPostDivTuple)) >> + CCM_TUPLE_SHIFT(clockRootPostDivTuple)) + + 1UL; + + return freq; +} + /*! brief Enable USB HS clock. * * This function only enables the access to USB HS prepheral, upper layer @@ -401,10 +495,12 @@ uint32_t CLOCK_GetFreq(clock_name_t name) */ bool CLOCK_EnableUsbhs0Clock(clock_usb_src_t src, uint32_t freq) { + uint32_t i; CCM->CCGR6 |= CCM_CCGR6_CG0_MASK; USB1->USBCMD |= USBHS_USBCMD_RST_MASK; - for (volatile uint32_t i = 0; i < 400000; - i++) /* Add a delay between RST and RS so make sure there is a DP pullup sequence*/ + + /* Add a delay between RST and RS so make sure there is a DP pullup sequence*/ + for (i = 0; i < 400000U; i++) { __ASM("nop"); } @@ -426,10 +522,12 @@ bool CLOCK_EnableUsbhs0Clock(clock_usb_src_t src, uint32_t freq) */ bool CLOCK_EnableUsbhs1Clock(clock_usb_src_t src, uint32_t freq) { + uint32_t i = 0; CCM->CCGR6 |= CCM_CCGR6_CG0_MASK; USB2->USBCMD |= USBHS_USBCMD_RST_MASK; - for (volatile uint32_t i = 0; i < 400000; - i++) /* Add a delay between RST and RS so make sure there is a DP pullup sequence*/ + + /* Add a delay between RST and RS so make sure there is a DP pullup sequence*/ + for (i = 0; i < 400000U; i++) { __ASM("nop"); } @@ -450,7 +548,7 @@ bool CLOCK_EnableUsbhs1Clock(clock_usb_src_t src, uint32_t freq) bool CLOCK_EnableUsbhs0PhyPllClock(clock_usb_phy_src_t src, uint32_t freq) { const clock_usb_pll_config_t g_ccmConfigUsbPll = {.loopDivider = 0U}; - if (CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_ENABLE_MASK) + if ((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_ENABLE_MASK) != 0U) { CCM_ANALOG->PLL_USB1 |= CCM_ANALOG_PLL_USB1_EN_USB_CLKS_MASK; } @@ -494,7 +592,7 @@ void CLOCK_InitArmPll(const clock_arm_pll_config_t *config) (CCM_ANALOG->PLL_ARM & (~(CCM_ANALOG_PLL_ARM_DIV_SELECT_MASK | CCM_ANALOG_PLL_ARM_POWERDOWN_MASK))) | CCM_ANALOG_PLL_ARM_ENABLE_MASK | CCM_ANALOG_PLL_ARM_DIV_SELECT(config->loopDivider); - while ((CCM_ANALOG->PLL_ARM & CCM_ANALOG_PLL_ARM_LOCK_MASK) == 0) + while ((CCM_ANALOG->PLL_ARM & CCM_ANALOG_PLL_ARM_LOCK_MASK) == 0UL) { } @@ -528,7 +626,7 @@ void CLOCK_InitSysPll(const clock_sys_pll_config_t *config) CCM_ANALOG_PLL_SYS_ENABLE_MASK | CCM_ANALOG_PLL_SYS_DIV_SELECT(config->loopDivider); /* Initialize the fractional mode */ - CCM_ANALOG->PLL_SYS_NUM = CCM_ANALOG_PLL_SYS_NUM_A(config->numerator); + CCM_ANALOG->PLL_SYS_NUM = CCM_ANALOG_PLL_SYS_NUM_A(config->numerator); CCM_ANALOG->PLL_SYS_DENOM = CCM_ANALOG_PLL_SYS_DENOM_B(config->denominator); /* Initialize the spread spectrum mode */ @@ -536,7 +634,7 @@ void CLOCK_InitSysPll(const clock_sys_pll_config_t *config) CCM_ANALOG_PLL_SYS_SS_ENABLE(config->ss_enable) | CCM_ANALOG_PLL_SYS_SS_STOP(config->ss_stop); - while ((CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_LOCK_MASK) == 0) + while ((CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_LOCK_MASK) == 0UL) { } @@ -569,7 +667,7 @@ void CLOCK_InitUsb1Pll(const clock_usb_pll_config_t *config) CCM_ANALOG_PLL_USB1_ENABLE_MASK | CCM_ANALOG_PLL_USB1_POWER_MASK | CCM_ANALOG_PLL_USB1_EN_USB_CLKS_MASK | CCM_ANALOG_PLL_USB1_DIV_SELECT(config->loopDivider); - while ((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_LOCK_MASK) == 0) + while ((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_LOCK_MASK) == 0UL) { } @@ -602,7 +700,7 @@ void CLOCK_InitUsb2Pll(const clock_usb_pll_config_t *config) CCM_ANALOG_PLL_USB2_ENABLE_MASK | CCM_ANALOG_PLL_USB2_POWER_MASK | CCM_ANALOG_PLL_USB2_EN_USB_CLKS_MASK | CCM_ANALOG_PLL_USB2_DIV_SELECT(config->loopDivider); - while ((CCM_ANALOG->PLL_USB2 & CCM_ANALOG_PLL_USB2_LOCK_MASK) == 0) + while ((CCM_ANALOG->PLL_USB2 & CCM_ANALOG_PLL_USB2_LOCK_MASK) == 0UL) { } @@ -634,7 +732,7 @@ void CLOCK_InitAudioPll(const clock_audio_pll_config_t *config) CCM_ANALOG->PLL_AUDIO = (CCM_ANALOG->PLL_AUDIO & (~CCM_ANALOG_PLL_AUDIO_BYPASS_CLK_SRC_MASK)) | CCM_ANALOG_PLL_AUDIO_BYPASS_MASK | CCM_ANALOG_PLL_AUDIO_BYPASS_CLK_SRC(config->src); - CCM_ANALOG->PLL_AUDIO_NUM = CCM_ANALOG_PLL_AUDIO_NUM_A(config->numerator); + CCM_ANALOG->PLL_AUDIO_NUM = CCM_ANALOG_PLL_AUDIO_NUM_A(config->numerator); CCM_ANALOG->PLL_AUDIO_DENOM = CCM_ANALOG_PLL_AUDIO_DENOM_B(config->denominator); /* @@ -689,7 +787,7 @@ void CLOCK_InitAudioPll(const clock_audio_pll_config_t *config) CCM_ANALOG->PLL_AUDIO = pllAudio; - while ((CCM_ANALOG->PLL_AUDIO & CCM_ANALOG_PLL_AUDIO_LOCK_MASK) == 0) + while ((CCM_ANALOG->PLL_AUDIO & CCM_ANALOG_PLL_AUDIO_LOCK_MASK) == 0UL) { } @@ -702,7 +800,7 @@ void CLOCK_InitAudioPll(const clock_audio_pll_config_t *config) */ void CLOCK_DeinitAudioPll(void) { - CCM_ANALOG->PLL_AUDIO = CCM_ANALOG_PLL_AUDIO_POWERDOWN_MASK; + CCM_ANALOG->PLL_AUDIO = (uint32_t)CCM_ANALOG_PLL_AUDIO_POWERDOWN_MASK; } /*! @@ -721,7 +819,7 @@ void CLOCK_InitVideoPll(const clock_video_pll_config_t *config) CCM_ANALOG->PLL_VIDEO = (CCM_ANALOG->PLL_VIDEO & (~CCM_ANALOG_PLL_VIDEO_BYPASS_CLK_SRC_MASK)) | CCM_ANALOG_PLL_VIDEO_BYPASS_MASK | CCM_ANALOG_PLL_VIDEO_BYPASS_CLK_SRC(config->src); - CCM_ANALOG->PLL_VIDEO_NUM = CCM_ANALOG_PLL_VIDEO_NUM_A(config->numerator); + CCM_ANALOG->PLL_VIDEO_NUM = CCM_ANALOG_PLL_VIDEO_NUM_A(config->numerator); CCM_ANALOG->PLL_VIDEO_DENOM = CCM_ANALOG_PLL_VIDEO_DENOM_B(config->denominator); /* @@ -775,7 +873,7 @@ void CLOCK_InitVideoPll(const clock_video_pll_config_t *config) CCM_ANALOG->PLL_VIDEO = pllVideo; - while ((CCM_ANALOG->PLL_VIDEO & CCM_ANALOG_PLL_VIDEO_LOCK_MASK) == 0) + while ((CCM_ANALOG->PLL_VIDEO & CCM_ANALOG_PLL_VIDEO_LOCK_MASK) == 0UL) { } @@ -820,7 +918,7 @@ void CLOCK_InitEnetPll(const clock_enet_pll_config_t *config) enet_pll; /* Wait for stable */ - while ((CCM_ANALOG->PLL_ENET & CCM_ANALOG_PLL_ENET_LOCK_MASK) == 0) + while ((CCM_ANALOG->PLL_ENET & CCM_ANALOG_PLL_ENET_LOCK_MASK) == 0UL) { } @@ -883,10 +981,10 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll) break; case kCLOCK_PllSys: /* PLL output frequency = Fref * (DIV_SELECT + NUM/DENOM). */ - freqTmp = ((clock_64b_t)freq * ((clock_64b_t)(CCM_ANALOG->PLL_SYS_NUM))) / - ((clock_64b_t)(CCM_ANALOG->PLL_SYS_DENOM)); + freqTmp = ((clock_64b_t)freq * ((clock_64b_t)(CCM_ANALOG->PLL_SYS_NUM))); + freqTmp /= ((clock_64b_t)(CCM_ANALOG->PLL_SYS_DENOM)); - if (CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_DIV_SELECT_MASK) + if ((CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_DIV_SELECT_MASK) != 0U) { freq *= 22U; } @@ -899,7 +997,7 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll) break; case kCLOCK_PllUsb1: - freq = (freq * ((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_DIV_SELECT_MASK) ? 22U : 20U)); + freq = (freq * (((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_DIV_SELECT_MASK) != 0UL) ? 22U : 20U)); break; case kCLOCK_PllAudio: @@ -907,8 +1005,8 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll) divSelect = (CCM_ANALOG->PLL_AUDIO & CCM_ANALOG_PLL_AUDIO_DIV_SELECT_MASK) >> CCM_ANALOG_PLL_AUDIO_DIV_SELECT_SHIFT; - freqTmp = ((clock_64b_t)freq * ((clock_64b_t)(CCM_ANALOG->PLL_AUDIO_NUM))) / - ((clock_64b_t)(CCM_ANALOG->PLL_AUDIO_DENOM)); + freqTmp = ((clock_64b_t)freq * ((clock_64b_t)(CCM_ANALOG->PLL_AUDIO_NUM))); + freqTmp /= ((clock_64b_t)(CCM_ANALOG->PLL_AUDIO_DENOM)); freq = freq * divSelect + (uint32_t)freqTmp; @@ -938,7 +1036,12 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll) freq = freq >> 1U; break; + case CCM_ANALOG_PLL_AUDIO_POST_DIV_SELECT(2U): + freq = freq >> 0U; + break; + default: + assert(false); break; } @@ -952,7 +1055,13 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll) freq >>= 1U; break; + case CCM_ANALOG_MISC2_AUDIO_DIV_MSB(0) | CCM_ANALOG_MISC2_AUDIO_DIV_LSB(0): + case CCM_ANALOG_MISC2_AUDIO_DIV_MSB(1) | CCM_ANALOG_MISC2_AUDIO_DIV_LSB(0): + freq >>= 0U; + break; + default: + assert(false); break; } break; @@ -962,9 +1071,8 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll) divSelect = (CCM_ANALOG->PLL_VIDEO & CCM_ANALOG_PLL_VIDEO_DIV_SELECT_MASK) >> CCM_ANALOG_PLL_VIDEO_DIV_SELECT_SHIFT; - freqTmp = ((clock_64b_t)freq * ((clock_64b_t)(CCM_ANALOG->PLL_VIDEO_NUM))) / - ((clock_64b_t)(CCM_ANALOG->PLL_VIDEO_DENOM)); - + freqTmp = ((clock_64b_t)freq * ((clock_64b_t)(CCM_ANALOG->PLL_VIDEO_NUM))); + freqTmp /= ((clock_64b_t)(CCM_ANALOG->PLL_VIDEO_DENOM)); freq = freq * divSelect + (uint32_t)freqTmp; /* VIDEO PLL output = PLL output frequency / POSTDIV. */ @@ -993,21 +1101,32 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll) freq = freq >> 1U; break; + case CCM_ANALOG_PLL_VIDEO_POST_DIV_SELECT(2U): + freq = freq >> 0U; + break; + default: + assert(false); break; } switch (CCM_ANALOG->MISC2 & CCM_ANALOG_MISC2_VIDEO_DIV_MASK) { - case CCM_ANALOG_MISC2_VIDEO_DIV(3): + case CCM_ANALOG_MISC2_VIDEO_DIV(3U): freq >>= 2U; break; - case CCM_ANALOG_MISC2_VIDEO_DIV(1): + case CCM_ANALOG_MISC2_VIDEO_DIV(1U): freq >>= 1U; break; + case CCM_ANALOG_MISC2_VIDEO_DIV(0U): + case CCM_ANALOG_MISC2_VIDEO_DIV(2U): + freq >>= 0U; + break; + default: + assert(false); break; } break; @@ -1023,7 +1142,7 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll) break; case kCLOCK_PllUsb2: - freq = (freq * ((CCM_ANALOG->PLL_USB2 & CCM_ANALOG_PLL_USB2_DIV_SELECT_MASK) ? 22U : 20U)); + freq = (freq * (((CCM_ANALOG->PLL_USB2 & CCM_ANALOG_PLL_USB2_DIV_SELECT_MASK) != 0U) ? 22U : 20U)); break; default: freq = 0U; @@ -1049,13 +1168,14 @@ void CLOCK_InitSysPfd(clock_pfd_t pfd, uint8_t pfdFrac) uint32_t pfd528; pfd528 = CCM_ANALOG->PFD_528 & - ~((CCM_ANALOG_PFD_528_PFD0_CLKGATE_MASK | CCM_ANALOG_PFD_528_PFD0_FRAC_MASK) << (8 * pfdIndex)); + ~(((uint32_t)((uint32_t)CCM_ANALOG_PFD_528_PFD0_CLKGATE_MASK | CCM_ANALOG_PFD_528_PFD0_FRAC_MASK) + << (8UL * pfdIndex))); /* Disable the clock output first. */ - CCM_ANALOG->PFD_528 = pfd528 | (CCM_ANALOG_PFD_528_PFD0_CLKGATE_MASK << (8 * pfdIndex)); + CCM_ANALOG->PFD_528 = pfd528 | ((uint32_t)CCM_ANALOG_PFD_528_PFD0_CLKGATE_MASK << (8UL * pfdIndex)); /* Set the new value and enable output. */ - CCM_ANALOG->PFD_528 = pfd528 | (CCM_ANALOG_PFD_528_PFD0_FRAC(pfdFrac) << (8 * pfdIndex)); + CCM_ANALOG->PFD_528 = pfd528 | (CCM_ANALOG_PFD_528_PFD0_FRAC(pfdFrac) << (8UL * pfdIndex)); } /*! @@ -1067,7 +1187,7 @@ void CLOCK_InitSysPfd(clock_pfd_t pfd, uint8_t pfdFrac) */ void CLOCK_DeinitSysPfd(clock_pfd_t pfd) { - CCM_ANALOG->PFD_528 |= CCM_ANALOG_PFD_528_PFD0_CLKGATE_MASK << (8 * pfd); + CCM_ANALOG->PFD_528 |= (uint32_t)CCM_ANALOG_PFD_528_PFD0_CLKGATE_MASK << (8U * (uint8_t)pfd); } /*! @@ -1086,13 +1206,14 @@ void CLOCK_InitUsb1Pfd(clock_pfd_t pfd, uint8_t pfdFrac) uint32_t pfd480; pfd480 = CCM_ANALOG->PFD_480 & - ~((CCM_ANALOG_PFD_480_PFD0_CLKGATE_MASK | CCM_ANALOG_PFD_480_PFD0_FRAC_MASK) << (8 * pfdIndex)); + ~(((uint32_t)((uint32_t)CCM_ANALOG_PFD_480_PFD0_CLKGATE_MASK | CCM_ANALOG_PFD_480_PFD0_FRAC_MASK) + << (8UL * pfdIndex))); /* Disable the clock output first. */ - CCM_ANALOG->PFD_480 = pfd480 | (CCM_ANALOG_PFD_480_PFD0_CLKGATE_MASK << (8 * pfdIndex)); + CCM_ANALOG->PFD_480 = pfd480 | ((uint32_t)CCM_ANALOG_PFD_480_PFD0_CLKGATE_MASK << (8UL * pfdIndex)); /* Set the new value and enable output. */ - CCM_ANALOG->PFD_480 = pfd480 | (CCM_ANALOG_PFD_480_PFD0_FRAC(pfdFrac) << (8 * pfdIndex)); + CCM_ANALOG->PFD_480 = pfd480 | (CCM_ANALOG_PFD_480_PFD0_FRAC(pfdFrac) << (8UL * pfdIndex)); } /*! @@ -1104,7 +1225,7 @@ void CLOCK_InitUsb1Pfd(clock_pfd_t pfd, uint8_t pfdFrac) */ void CLOCK_DeinitUsb1Pfd(clock_pfd_t pfd) { - CCM_ANALOG->PFD_480 |= CCM_ANALOG_PFD_480_PFD0_CLKGATE_MASK << (8 * pfd); + CCM_ANALOG->PFD_480 |= (uint32_t)CCM_ANALOG_PFD_480_PFD0_CLKGATE_MASK << (8UL * (uint8_t)pfd); } /*! @@ -1217,3 +1338,180 @@ void CLOCK_DisableUsbhs1PhyPllClock(void) CCM_ANALOG->PLL_USB2 &= ~CCM_ANALOG_PLL_USB2_EN_USB_CLKS_MASK; USBPHY2->CTRL |= USBPHY_CTRL_CLKGATE_MASK; /* Set to 1U to gate clocks */ } + +/*! + * brief Set the clock source and the divider of the clock output1. + * + * param selection The clock source to be output, please refer to clock_output1_selection_t. + * param divider The divider of the output clock signal, please refer to clock_output_divider_t. + */ +void CLOCK_SetClockOutput1(clock_output1_selection_t selection, clock_output_divider_t divider) +{ + uint32_t tmp32; + + tmp32 = CCM->CCOSR; + if (selection == kCLOCK_DisableClockOutput1) + { + tmp32 &= ~CCM_CCOSR_CLKO1_EN_MASK; + } + else + { + tmp32 |= CCM_CCOSR_CLKO1_EN_MASK; + tmp32 &= ~(CCM_CCOSR_CLKO1_SEL_MASK | CCM_CCOSR_CLKO1_DIV_MASK); + tmp32 |= CCM_CCOSR_CLKO1_SEL(selection) | CCM_CCOSR_CLKO1_DIV(divider); + } + CCM->CCOSR = tmp32; +} + +/*! + * brief Set the clock source and the divider of the clock output2. + * + * param selection The clock source to be output, please refer to clock_output2_selection_t. + * param divider The divider of the output clock signal, please refer to clock_output_divider_t. + */ +void CLOCK_SetClockOutput2(clock_output2_selection_t selection, clock_output_divider_t divider) +{ + uint32_t tmp32; + + tmp32 = CCM->CCOSR; + if (selection == kCLOCK_DisableClockOutput2) + { + tmp32 &= CCM_CCOSR_CLKO2_EN_MASK; + } + else + { + tmp32 |= CCM_CCOSR_CLKO2_EN_MASK; + tmp32 &= ~(CCM_CCOSR_CLKO2_SEL_MASK | CCM_CCOSR_CLKO2_DIV_MASK); + tmp32 |= CCM_CCOSR_CLKO2_SEL(selection) | CCM_CCOSR_CLKO2_DIV(divider); + } + + CCM->CCOSR = tmp32; +} + +/*! + * brief Get the frequency of clock output1 clock signal. + * + * return The frequency of clock output1 clock signal. + */ +uint32_t CLOCK_GetClockOutCLKO1Freq(void) +{ + uint32_t freq = 0U; + uint32_t tmp32; + + tmp32 = CCM->CCOSR; + + if ((tmp32 & CCM_CCOSR_CLKO1_EN_MASK) != 0UL) + { + switch ((tmp32 & CCM_CCOSR_CLKO1_SEL_MASK) >> CCM_CCOSR_CLKO1_SEL_SHIFT) + { + case (uint32_t)kCLOCK_OutputPllUsb1: + freq = CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 2U; + break; + case (uint32_t)kCLOCK_OutputPllSys: + freq = CLOCK_GetPllFreq(kCLOCK_PllSys) / 2U; + break; + case (uint32_t)kCLOCK_OutputPllVideo: + freq = CLOCK_GetPllFreq(kCLOCK_PllVideo) / 2U; + break; + case (uint32_t)kCLOCK_OutputSemcClk: + freq = CLOCK_GetSemcFreq(); + break; + case (uint32_t)kCLOCK_OutputLcdifPixClk: + freq = CLOCK_GetClockRootFreq(kCLOCK_LcdifClkRoot); + break; + case (uint32_t)kCLOCK_OutputAhbClk: + freq = CLOCK_GetAhbFreq(); + break; + case (uint32_t)kCLOCK_OutputIpgClk: + freq = CLOCK_GetIpgFreq(); + break; + case (uint32_t)kCLOCK_OutputPerClk: + freq = CLOCK_GetPerClkFreq(); + break; + case (uint32_t)kCLOCK_OutputCkilSyncClk: + freq = CLOCK_GetRtcFreq(); + break; + case (uint32_t)kCLOCK_OutputPll4MainClk: + freq = CLOCK_GetPllFreq(kCLOCK_PllAudio); + break; + default: + /* This branch should never be hit. */ + break; + } + + freq /= (((tmp32 & CCM_CCOSR_CLKO1_DIV_MASK) >> CCM_CCOSR_CLKO1_DIV_SHIFT) + 1U); + } + else + { + freq = 0UL; + } + + return freq; +} + +/*! + * brief Get the frequency of clock output2 clock signal. + * + * return The frequency of clock output2 clock signal. + */ +uint32_t CLOCK_GetClockOutClkO2Freq(void) +{ + uint32_t freq = 0U; + uint32_t tmp32; + + tmp32 = CCM->CCOSR; + + if ((tmp32 & CCM_CCOSR_CLKO2_EN_MASK) != 0UL) + { + switch ((tmp32 & CCM_CCOSR_CLKO2_SEL_MASK) >> CCM_CCOSR_CLKO2_SEL_SHIFT) + { + case (uint32_t)kCLOCK_OutputUsdhc1Clk: + freq = CLOCK_GetClockRootFreq(kCLOCK_Usdhc1ClkRoot); + break; + case (uint32_t)kCLOCK_OutputLpi2cClk: + freq = CLOCK_GetClockRootFreq(kCLOCK_Lpi2cClkRoot); + break; + case (uint32_t)kCLOCK_OutputCsiClk: + freq = CLOCK_GetClockRootFreq(kCLOCK_CsiClkRoot); + break; + case (uint32_t)kCLOCK_OutputOscClk: + freq = CLOCK_GetOscFreq(); + break; + case (uint32_t)kCLOCK_OutputUsdhc2Clk: + freq = CLOCK_GetClockRootFreq(kCLOCK_Usdhc2ClkRoot); + break; + case (uint32_t)kCLOCK_OutputSai1Clk: + freq = CLOCK_GetClockRootFreq(kCLOCK_Sai1ClkRoot); + break; + case (uint32_t)kCLOCK_OutputSai2Clk: + freq = CLOCK_GetClockRootFreq(kCLOCK_Sai2ClkRoot); + break; + case (uint32_t)kCLOCK_OutputSai3Clk: + freq = CLOCK_GetClockRootFreq(kCLOCK_Sai3ClkRoot); + break; + case (uint32_t)kCLOCK_OutputCanClk: + freq = CLOCK_GetClockRootFreq(kCLOCK_CanClkRoot); + break; + case (uint32_t)kCLOCK_OutputFlexspiClk: + freq = CLOCK_GetClockRootFreq(kCLOCK_FlexspiClkRoot); + break; + case (uint32_t)kCLOCK_OutputUartClk: + freq = CLOCK_GetClockRootFreq(kCLOCK_UartClkRoot); + break; + case (uint32_t)kCLOCK_OutputSpdif0Clk: + freq = CLOCK_GetClockRootFreq(kCLOCK_SpdifClkRoot); + break; + default: + /* This branch should never be hit. */ + break; + } + + freq /= (((tmp32 & CCM_CCOSR_CLKO2_DIV_MASK) >> CCM_CCOSR_CLKO2_DIV_SHIFT) + 1U); + } + else + { + freq = 0UL; + } + + return freq; +} diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/fsl_common.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/fsl_common.c index e697d0e51..77c3a9039 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/fsl_common.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/fsl_common.c @@ -135,16 +135,16 @@ void *SDK_Malloc(size_t size, size_t alignbytes) p_align_addr = (void *)SDK_SIZEALIGN((uint32_t)p_addr + sizeof(mem_align_cb_t), alignbytes); - p_cb = (mem_align_cb_t *)((uint32_t)p_align_addr - 4); + p_cb = (mem_align_cb_t *)((uint32_t)p_align_addr - 4U); p_cb->identifier = SDK_MEM_MAGIC_NUMBER; - p_cb->offset = (uint32_t)p_align_addr - (uint32_t)p_addr; + p_cb->offset = (uint32_t)p_align_addr - (uint32_t)p_addr; return (void *)p_align_addr; } void SDK_Free(void *ptr) { - mem_align_cb_t *p_cb = (mem_align_cb_t *)((uint32_t)ptr - 4); + mem_align_cb_t *p_cb = (mem_align_cb_t *)((uint32_t)ptr - 4U); if (p_cb->identifier != SDK_MEM_MAGIC_NUMBER) { diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/fsl_romapi.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/fsl_romapi.c new file mode 100644 index 000000000..0ed07ce5c --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/fsl_romapi.c @@ -0,0 +1,161 @@ +/* + * Copyright 2017-2020 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +/** +* @file fsl_romapi.c +* @brief support flexspi norflash function +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-04-03 +*/ +#include "fsl_romapi.h" + +/******************************************************************************* + * Definitions + ******************************************************************************/ + +/******************************************************************************* + * Prototypes + ******************************************************************************/ + +/*! + * @brief Interface for the ROM FLEXSPI NOR flash driver. + */ +typedef struct +{ + uint32_t version; + status_t (*init)(uint32_t instance, flexspi_nor_config_t *config); + status_t (*program)(uint32_t instance, flexspi_nor_config_t *config, uint32_t dst_addr, const uint32_t *src); + status_t (*erase_all)(uint32_t instance, flexspi_nor_config_t *config); + status_t (*erase)(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t lengthInBytes); + uint32_t reserved1; + void (*clear_cache)(uint32_t instance); + status_t (*xfer)(uint32_t instance, flexspi_xfer_t *xfer); + status_t (*update_lut)(uint32_t instance, uint32_t seqIndex, const uint32_t *lutBase, uint32_t seqNumber); + uint32_t reserved2; +} flexspi_nor_driver_interface_t; + +/*! + * @brief Root of the bootloader api tree. + * + * An instance of this struct resides in read-only memory in the bootloader. It + * provides a user application access to APIs exported by the bootloader. + * + * @note The order of existing fields must not be changed. + */ +typedef struct +{ + void (*runBootloader)(void *arg); /*!< Function to start the bootloader executing */ + const uint32_t version; /*!< Bootloader version number */ + const uint8_t *copyright; /*!< Bootloader Copyright */ + const uint32_t reserved0; + flexspi_nor_driver_interface_t *flexSpiNorDriver; /*!< FLEXSPI NOR flash api */ +} bootloader_api_entry_t; + +/******************************************************************************* + * Variables + ******************************************************************************/ + +#define g_bootloaderTree ((bootloader_api_entry_t *)*(uint32_t *)0x0020001cU) + +#define api_flexspi_nor_erase_sector \ + ((status_t(*)(uint32_t instance, flexspi_nor_config_t * config, uint32_t address))0x002106E7U) +/******************************************************************************* + * Codes + ******************************************************************************/ + +/******************************************************************************* + * ROM FLEXSPI NOR driver + ******************************************************************************/ + +/*! + * @brief Initialize Serial NOR flash via FLEXSPI. + * + * @param instance storge the instance of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + */ +status_t ROM_FLEXSPI_NorFlash_Init(uint32_t instance, flexspi_nor_config_t *config) +{ + return g_bootloaderTree->flexSpiNorDriver->init(instance, config); +} + +/*! + * @brief Program data to Serial NOR via FLEXSPI. + * + * @param instance storge the instance of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param dstAddr A pointer to the desired flash memory to be programmed. + * @param src A pointer to the source buffer of data that is to be programmed + * into the NOR flash. + */ +status_t ROM_FLEXSPI_NorFlash_ProgramPage(uint32_t instance, + flexspi_nor_config_t *config, + uint32_t dstAddr, + const uint32_t *src) +{ + return g_bootloaderTree->flexSpiNorDriver->program(instance, config, dstAddr, src); +} + +/*! + * @brief Erase Flash Region specified by address and length. + * + * @param instance storge the index of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param start The start address of the desired NOR flash memory to be erased. + * @param length The length, given in bytes to be erased. + */ +status_t ROM_FLEXSPI_NorFlash_Erase(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length) +{ + return g_bootloaderTree->flexSpiNorDriver->erase(instance, config, start, length); +} + +#if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_SECTOR) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_SECTOR +/*! + * @brief Erase one sector specified by address. + * + * @param instance storge the index of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param start The start address of the desired NOR flash memory to be erased. + */ +status_t ROM_FLEXSPI_NorFlash_EraseSector(uint32_t instance, flexspi_nor_config_t *config, uint32_t start) +{ + return api_flexspi_nor_erase_sector(instance, config, start); +} +#endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_SECTOR */ + +#if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_ALL) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_ALL +/*! @brief Erase all the Serial NOR flash connected on FLEXSPI. */ +status_t ROM_FLEXSPI_NorFlash_EraseAll(uint32_t instance, flexspi_nor_config_t *config) +{ + return g_bootloaderTree->flexSpiNorDriver->erase_all(instance, config); +} +#endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_ALL */ + +#if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_CMD_XFER) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_CMD_XFER +/*! @brief FLEXSPI command */ +status_t ROM_FLEXSPI_NorFlash_CommandXfer(uint32_t instance, flexspi_xfer_t *xfer) +{ + return g_bootloaderTree->flexSpiNorDriver->xfer(instance, xfer); +} +#endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_CMD_XFER */ + +#if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_UPDATE_LUT) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_UPDATE_LUT +/*! @brief Configure FLEXSPI Lookup table. */ +status_t ROM_FLEXSPI_NorFlash_UpdateLut(uint32_t instance, + uint32_t seqIndex, + const uint32_t *lutBase, + uint32_t seqNumber) +{ + return g_bootloaderTree->flexSpiNorDriver->update_lut(instance, seqIndex, lutBase, seqNumber); +} +#endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_UPDATE_LUT */ + +/*! @brief Software reset for the FLEXSPI logic. */ +void ROM_FLEXSPI_NorFlash_ClearCache(uint32_t instance) +{ + g_bootloaderTree->flexSpiNorDriver->clear_cache(instance); +} + 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 new file mode 100644 index 000000000..c489da8c6 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/mcuboot.c @@ -0,0 +1,86 @@ +/* + * Copyright 2018-2020 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** +* @file mucboot.c +* @brief support bootloader function +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-04-03 +*/ + +#include "flash.h" +#include "stdint.h" +#include "mcuboot.h" + +#ifdef MCUBOOT_BOOTLOADER +static void JumpToApp(void) +{ + asm volatile("LDR R0, = 0x60040000"); + asm volatile("LDR R0, [R0]"); + asm volatile("MOV SP, R0"); + + asm volatile("LDR R0, = 0x60040000+4"); + asm volatile("LDR R0, [R0]"); + asm volatile("BX R0"); +} + +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 SerialPutC(uint8_t c) +{ + LPUART_WriteByte(LPUART1, c); + while(!(kLPUART_TxDataRegEmptyFlag & LPUART_GetStatusFlags(LPUART1))) + { + } +} + +static void SerialPutString(uint8_t *s) +{ + while (*s != '\0') { + SerialPutC(*s); + s++; + } +} + +void BootLoaderJumpApp(void) +{ + BOARD_ConfigMPU(); + BOARD_InitPins(); + BOARD_BootClockRUN(); + + UartConfig(); + + SerialPutString("BOOTLOADER START AND JUMP TO APP[0x60040000]\n"); + SCB->VTOR = (uint32_t)0x60040000; + JumpToApp(); +} +#endif \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/pin_mux.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/pin_mux.c index de911ee2c..0aa7d67f6 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/pin_mux.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/pin_mux.c @@ -47,652 +47,6 @@ void BOARD_InitBootPins(void) { BOARD_InitPins(); } -void SDHCPinmuxConfig(void) -{ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B1_14_USDHC1_VSELECT, /* GPIO_B1_14 is configured as USDHC1_VSELECT */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_SD_B0_00_USDHC1_CMD, /* GPIO_SD_B0_00 is configured as USDHC1_CMD */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_SD_B0_01_USDHC1_CLK, /* GPIO_SD_B0_01 is configured as USDHC1_CLK */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_SD_B0_02_USDHC1_DATA0, /* GPIO_SD_B0_02 is configured as USDHC1_DATA0 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_SD_B0_03_USDHC1_DATA1, /* GPIO_SD_B0_03 is configured as USDHC1_DATA1 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_SD_B0_04_USDHC1_DATA2, /* GPIO_SD_B0_04 is configured as USDHC1_DATA2 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_SD_B0_05_USDHC1_DATA3, /* GPIO_SD_B0_05 is configured as USDHC1_DATA3 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B1_14_USDHC1_VSELECT, /* GPIO_B1_14 PAD functional properties : */ - 0x0170A1u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/4 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 47K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_SD_B0_00_USDHC1_CMD, /* GPIO_SD_B0_00 PAD functional properties : */ - 0x017089u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0(150 Ohm @ 3.3V, 260 Ohm@1.8V) - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 47K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_SD_B0_01_USDHC1_CLK, /* GPIO_SD_B0_01 PAD functional properties : */ - 0x014089u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0(150 Ohm @ 3.3V, 260 Ohm@1.8V) - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Disabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 47K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_SD_B0_02_USDHC1_DATA0, /* GPIO_SD_B0_02 PAD functional properties : */ - 0x017089u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0(150 Ohm @ 3.3V, 260 Ohm@1.8V) - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 47K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_SD_B0_03_USDHC1_DATA1, /* GPIO_SD_B0_03 PAD functional properties : */ - 0x017089u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0(150 Ohm @ 3.3V, 260 Ohm@1.8V) - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 47K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_SD_B0_04_USDHC1_DATA2, /* GPIO_SD_B0_04 PAD functional properties : */ - 0x017089u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0(150 Ohm @ 3.3V, 260 Ohm@1.8V) - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 47K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_SD_B0_05_USDHC1_DATA3, /* GPIO_SD_B0_05 PAD functional properties : */ - 0x017089u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0(150 Ohm @ 3.3V, 260 Ohm@1.8V) - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 47K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ -} - -void SemcPinmuxConfig(void) -{ - - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_00_SEMC_DATA00, /* GPIO_EMC_00 is configured as SEMC_DATA00 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_01_SEMC_DATA01, /* GPIO_EMC_01 is configured as SEMC_DATA01 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_02_SEMC_DATA02, /* GPIO_EMC_02 is configured as SEMC_DATA02 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_03_SEMC_DATA03, /* GPIO_EMC_03 is configured as SEMC_DATA03 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_04_SEMC_DATA04, /* GPIO_EMC_04 is configured as SEMC_DATA04 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_05_SEMC_DATA05, /* GPIO_EMC_05 is configured as SEMC_DATA05 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_06_SEMC_DATA06, /* GPIO_EMC_06 is configured as SEMC_DATA06 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_07_SEMC_DATA07, /* GPIO_EMC_07 is configured as SEMC_DATA07 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_08_SEMC_DM00, /* GPIO_EMC_08 is configured as SEMC_DM00 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_09_SEMC_ADDR00, /* GPIO_EMC_09 is configured as SEMC_ADDR00 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_10_SEMC_ADDR01, /* GPIO_EMC_10 is configured as SEMC_ADDR01 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_11_SEMC_ADDR02, /* GPIO_EMC_11 is configured as SEMC_ADDR02 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_12_SEMC_ADDR03, /* GPIO_EMC_12 is configured as SEMC_ADDR03 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_13_SEMC_ADDR04, /* GPIO_EMC_13 is configured as SEMC_ADDR04 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_14_SEMC_ADDR05, /* GPIO_EMC_14 is configured as SEMC_ADDR05 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_15_SEMC_ADDR06, /* GPIO_EMC_15 is configured as SEMC_ADDR06 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_16_SEMC_ADDR07, /* GPIO_EMC_16 is configured as SEMC_ADDR07 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_17_SEMC_ADDR08, /* GPIO_EMC_17 is configured as SEMC_ADDR08 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_18_SEMC_ADDR09, /* GPIO_EMC_18 is configured as SEMC_ADDR09 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_19_SEMC_ADDR11, /* GPIO_EMC_19 is configured as SEMC_ADDR11 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_20_SEMC_ADDR12, /* GPIO_EMC_20 is configured as SEMC_ADDR12 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_21_SEMC_BA0, /* GPIO_EMC_21 is configured as SEMC_BA0 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_22_SEMC_BA1, /* GPIO_EMC_22 is configured as SEMC_BA1 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_23_SEMC_ADDR10, /* GPIO_EMC_23 is configured as SEMC_ADDR10 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_24_SEMC_CAS, /* GPIO_EMC_24 is configured as SEMC_CAS */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_25_SEMC_RAS, /* GPIO_EMC_25 is configured as SEMC_RAS */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_26_SEMC_CLK, /* GPIO_EMC_26 is configured as SEMC_CLK */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_27_SEMC_CKE, /* GPIO_EMC_27 is configured as SEMC_CKE */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_28_SEMC_WE, /* GPIO_EMC_28 is configured as SEMC_WE */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_29_SEMC_CS0, /* GPIO_EMC_29 is configured as SEMC_CS0 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_30_SEMC_DATA08, /* GPIO_EMC_30 is configured as SEMC_DATA08 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_31_SEMC_DATA09, /* GPIO_EMC_31 is configured as SEMC_DATA09 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_32_SEMC_DATA10, /* GPIO_EMC_32 is configured as SEMC_DATA10 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_33_SEMC_DATA11, /* GPIO_EMC_33 is configured as SEMC_DATA11 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_34_SEMC_DATA12, /* GPIO_EMC_34 is configured as SEMC_DATA12 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_35_SEMC_DATA13, /* GPIO_EMC_35 is configured as SEMC_DATA13 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_36_SEMC_DATA14, /* GPIO_EMC_36 is configured as SEMC_DATA14 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_37_SEMC_DATA15, /* GPIO_EMC_37 is configured as SEMC_DATA15 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_38_SEMC_DM01, /* GPIO_EMC_38 is configured as SEMC_DM01 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_39_SEMC_DQS, /* GPIO_EMC_39 is configured as SEMC_DQS */ - 1U); /* Software Input On Field: Force input path of pad GPIO_EMC_39 */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_40_SEMC_RDY, /* GPIO_EMC_40 is configured as SEMC_RDY */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_41_SEMC_CSX00, /* GPIO_EMC_41 is configured as SEMC_CSX00 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_00_SEMC_DATA00, /* GPIO_EMC_00 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_01_SEMC_DATA01, /* GPIO_EMC_01 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_02_SEMC_DATA02, /* GPIO_EMC_02 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_03_SEMC_DATA03, /* GPIO_EMC_03 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_04_SEMC_DATA04, /* GPIO_EMC_04 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_05_SEMC_DATA05, /* GPIO_EMC_05 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_06_SEMC_DATA06, /* GPIO_EMC_06 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_07_SEMC_DATA07, /* GPIO_EMC_07 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_08_SEMC_DM00, /* GPIO_EMC_08 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_09_SEMC_ADDR00, /* GPIO_EMC_09 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_10_SEMC_ADDR01, /* GPIO_EMC_10 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_11_SEMC_ADDR02, /* GPIO_EMC_11 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_12_SEMC_ADDR03, /* GPIO_EMC_12 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_13_SEMC_ADDR04, /* GPIO_EMC_13 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_14_SEMC_ADDR05, /* GPIO_EMC_14 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_15_SEMC_ADDR06, /* GPIO_EMC_15 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_16_SEMC_ADDR07, /* GPIO_EMC_16 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_17_SEMC_ADDR08, /* GPIO_EMC_17 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_18_SEMC_ADDR09, /* GPIO_EMC_18 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_19_SEMC_ADDR11, /* GPIO_EMC_19 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_20_SEMC_ADDR12, /* GPIO_EMC_20 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_21_SEMC_BA0, /* GPIO_EMC_21 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_22_SEMC_BA1, /* GPIO_EMC_22 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_23_SEMC_ADDR10, /* GPIO_EMC_23 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_24_SEMC_CAS, /* GPIO_EMC_24 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_25_SEMC_RAS, /* GPIO_EMC_25 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_26_SEMC_CLK, /* GPIO_EMC_26 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_27_SEMC_CKE, /* GPIO_EMC_27 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_28_SEMC_WE, /* GPIO_EMC_28 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_29_SEMC_CS0, /* GPIO_EMC_29 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_30_SEMC_DATA08, /* GPIO_EMC_30 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_31_SEMC_DATA09, /* GPIO_EMC_31 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_32_SEMC_DATA10, /* GPIO_EMC_32 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_33_SEMC_DATA11, /* GPIO_EMC_33 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_34_SEMC_DATA12, /* GPIO_EMC_34 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_35_SEMC_DATA13, /* GPIO_EMC_35 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_36_SEMC_DATA14, /* GPIO_EMC_36 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_37_SEMC_DATA15, /* GPIO_EMC_37 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_38_SEMC_DM01, /* GPIO_EMC_38 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_39_SEMC_DQS, /* GPIO_EMC_39 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_40_SEMC_RDY, /* GPIO_EMC_40 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_41_SEMC_CSX00, /* GPIO_EMC_41 PAD functional properties : */ - 0x0110F9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/7 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Enabled */ -} /* * TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* BOARD_InitPins: @@ -702,313 +56,51 @@ BOARD_InitPins: pull_keeper_select: Keeper, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_100, drive_strength: R0_6, slew_rate: Slow} - {pin_num: K14, peripheral: LPUART1, signal: TX, pin_signal: GPIO_AD_B0_12, software_input_on: Disable, hysteresis_enable: Disable, pull_up_down_config: Pull_Down_100K_Ohm, pull_keeper_select: Keeper, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_100, drive_strength: R0_6, slew_rate: Slow} - - {pin_num: A7, peripheral: ENET, signal: enet_mdc, pin_signal: GPIO_EMC_40, software_input_on: Disable, hysteresis_enable: Disable, pull_up_down_config: Pull_Up_100K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_200, drive_strength: R0_5, slew_rate: Fast} - - {pin_num: C7, peripheral: ENET, signal: enet_mdio, pin_signal: GPIO_EMC_41, software_input_on: Disable, hysteresis_enable: Disable, pull_up_down_config: Pull_Up_100K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Enable, speed: MHZ_50, drive_strength: R0_5, slew_rate: Fast} - - {pin_num: B13, peripheral: ENET, signal: enet_ref_clk, pin_signal: GPIO_B1_10, software_input_on: Enable, hysteresis_enable: Disable, pull_up_down_config: Pull_Down_100K_Ohm, - pull_keeper_select: Keeper, pull_keeper_enable: Disable, open_drain: Disable, speed: MHZ_50, drive_strength: R0_6, slew_rate: Fast} - - {pin_num: E12, peripheral: ENET, signal: 'enet_rx_data, 0', pin_signal: GPIO_B1_04, software_input_on: Disable, hysteresis_enable: Disable, pull_up_down_config: Pull_Up_100K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_200, drive_strength: R0_5, slew_rate: Fast} - - {pin_num: D12, peripheral: ENET, signal: 'enet_rx_data, 1', pin_signal: GPIO_B1_05, software_input_on: Disable, hysteresis_enable: Disable, pull_up_down_config: Pull_Up_100K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_200, drive_strength: R0_5, slew_rate: Fast} - - {pin_num: C12, peripheral: ENET, signal: enet_rx_en, pin_signal: GPIO_B1_06, software_input_on: Disable, hysteresis_enable: Disable, pull_up_down_config: Pull_Up_100K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_200, drive_strength: R0_5, slew_rate: Fast} - - {pin_num: C13, peripheral: ENET, signal: enet_rx_er, pin_signal: GPIO_B1_11, software_input_on: Disable, hysteresis_enable: Disable, pull_up_down_config: Pull_Up_100K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_200, drive_strength: R0_5, slew_rate: Fast} - - {pin_num: B12, peripheral: ENET, signal: 'enet_tx_data, 0', pin_signal: GPIO_B1_07, software_input_on: Disable, hysteresis_enable: Disable, pull_up_down_config: Pull_Up_100K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_200, drive_strength: R0_5, slew_rate: Fast} - - {pin_num: A12, peripheral: ENET, signal: 'enet_tx_data, 1', pin_signal: GPIO_B1_08, software_input_on: Disable, hysteresis_enable: Disable, pull_up_down_config: Pull_Up_100K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_200, drive_strength: R0_5, slew_rate: Fast} - - {pin_num: A13, peripheral: ENET, signal: enet_tx_en, pin_signal: GPIO_B1_09, software_input_on: Disable, hysteresis_enable: Disable, pull_up_down_config: Pull_Up_100K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_200, drive_strength: R0_5, slew_rate: Fast} - - {pin_num: F14, peripheral: GPIO1, signal: 'gpio_io, 09', pin_signal: GPIO_AD_B0_09, software_input_on: Disable, hysteresis_enable: Disable, pull_up_down_config: Pull_Up_100K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_100, drive_strength: R0_5, slew_rate: Fast} - - {pin_num: G13, peripheral: GPIO1, signal: 'gpio_io, 10', pin_signal: GPIO_AD_B0_10, software_input_on: Disable, hysteresis_enable: Disable, pull_up_down_config: Pull_Up_100K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_100, drive_strength: R0_5, slew_rate: Fast} - - {pin_num: J3, peripheral: USDHC1, signal: usdhc_clk, pin_signal: GPIO_SD_B0_01, software_input_on: Disable, hysteresis_enable: Enable, pull_up_down_config: Pull_Up_47K_Ohm, - pull_keeper_select: Keeper, pull_keeper_enable: Disable, open_drain: Disable, speed: MHZ_100, drive_strength: R0, slew_rate: Fast} - - {pin_num: J4, peripheral: USDHC1, signal: usdhc_cmd, pin_signal: GPIO_SD_B0_00, software_input_on: Disable, hysteresis_enable: Enable, pull_up_down_config: Pull_Up_47K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_100, drive_strength: R0, slew_rate: Fast} - - {pin_num: J1, peripheral: USDHC1, signal: 'usdhc_data, 0', pin_signal: GPIO_SD_B0_02, software_input_on: Disable, hysteresis_enable: Enable, pull_up_down_config: Pull_Up_47K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_100, drive_strength: R0, slew_rate: Fast} - - {pin_num: K1, peripheral: USDHC1, signal: 'usdhc_data, 1', pin_signal: GPIO_SD_B0_03, software_input_on: Disable, hysteresis_enable: Enable, pull_up_down_config: Pull_Up_47K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_100, drive_strength: R0, slew_rate: Fast} - - {pin_num: H2, peripheral: USDHC1, signal: 'usdhc_data, 2', pin_signal: GPIO_SD_B0_04, software_input_on: Disable, hysteresis_enable: Enable, pull_up_down_config: Pull_Up_47K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_100, drive_strength: R0, slew_rate: Fast} - - {pin_num: J2, peripheral: USDHC1, signal: 'usdhc_data, 3', pin_signal: GPIO_SD_B0_05, software_input_on: Disable, hysteresis_enable: Enable, pull_up_down_config: Pull_Up_47K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_100, drive_strength: R0, slew_rate: Fast} - - {pin_num: C14, peripheral: USDHC1, signal: usdhc_vselect, pin_signal: GPIO_B1_14, software_input_on: Disable, hysteresis_enable: Enable, pull_up_down_config: Pull_Up_47K_Ohm, - pull_keeper_select: Pull, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_100, drive_strength: R0_4, slew_rate: Fast} + - {pin_num: F14, peripheral: GPIO1, signal: 'gpio_io, 09', pin_signal: GPIO_AD_B0_09, software_input_on: Disable, hysteresis_enable: Disable, pull_up_down_config: Pull_Down_100K_Ohm, + pull_keeper_select: Keeper, pull_keeper_enable: Enable, open_drain: Disable, speed: MHZ_100, drive_strength: R0_6, slew_rate: Slow} * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS *********** */ -void Lcd_InitPins(void) -{ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_00_LCD_CLK, /* GPIO_B0_00 is configured as LCD_CLK */ + +/* FUNCTION ************************************************************************************************************ + * + * Function Name : BOARD_InitPins + * Description : Configures pin routing and optionally pin electrical features. + * + * END ****************************************************************************************************************/ +void BOARD_InitPins(void) { + CLOCK_EnableClock(kCLOCK_Iomuxc); /* iomuxc clock (iomuxc_clk_enable): 0x03u */ + + IOMUXC_SetPinMux( + IOMUXC_GPIO_AD_B0_09_GPIO1_IO09, /* GPIO_AD_B0_09 is configured as GPIO1_IO09 */ 0U); /* Software Input On Field: Input Path is determined by functionality */ IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_01_LCD_ENABLE, /* GPIO_B0_01 is configured as LCD_ENABLE */ + IOMUXC_GPIO_AD_B0_12_LPUART1_TX, /* GPIO_AD_B0_12 is configured as LPUART1_TX */ 0U); /* Software Input On Field: Input Path is determined by functionality */ IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_02_LCD_HSYNC, /* GPIO_B0_02 is configured as LCD_HSYNC */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_03_LCD_VSYNC, /* GPIO_B0_03 is configured as LCD_VSYNC */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_04_LCD_DATA00, /* GPIO_B0_04 is configured as LCD_DATA00 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_05_LCD_DATA01, /* GPIO_B0_05 is configured as LCD_DATA01 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_06_LCD_DATA02, /* GPIO_B0_06 is configured as LCD_DATA02 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_07_LCD_DATA03, /* GPIO_B0_07 is configured as LCD_DATA03 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_08_LCD_DATA04, /* GPIO_B0_08 is configured as LCD_DATA04 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_09_LCD_DATA05, /* GPIO_B0_09 is configured as LCD_DATA05 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_10_LCD_DATA06, /* GPIO_B0_10 is configured as LCD_DATA06 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_11_LCD_DATA07, /* GPIO_B0_11 is configured as LCD_DATA07 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_12_LCD_DATA08, /* GPIO_B0_12 is configured as LCD_DATA08 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_13_LCD_DATA09, /* GPIO_B0_13 is configured as LCD_DATA09 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_14_LCD_DATA10, /* GPIO_B0_14 is configured as LCD_DATA10 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B0_15_LCD_DATA11, /* GPIO_B0_15 is configured as LCD_DATA11 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B1_00_LCD_DATA12, /* GPIO_B1_00 is configured as LCD_DATA12 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B1_01_LCD_DATA13, /* GPIO_B1_01 is configured as LCD_DATA13 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B1_02_LCD_DATA14, /* GPIO_B1_02 is configured as LCD_DATA14 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B1_03_LCD_DATA15, /* GPIO_B1_03 is configured as LCD_DATA15 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B1_15_GPIO2_IO31, /* GPIO_B1_15 is configured as GPIO2_IO31 */ + IOMUXC_GPIO_AD_B0_13_LPUART1_RX, /* GPIO_AD_B0_13 is configured as LPUART1_RX */ 0U); /* Software Input On Field: Input Path is determined by functionality */ IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_00_LCD_CLK, /* GPIO_B0_00 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + IOMUXC_GPIO_AD_B0_09_GPIO1_IO09, /* GPIO_AD_B0_09 PAD functional properties : */ + 0x10B0u); /* Slew Rate Field: Slow Slew Rate Drive Strength Field: R0/6 Speed Field: medium(100MHz) Open Drain Enable Field: Open Drain Disabled Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ + Pull / Keep Select Field: Keeper + Pull Up / Down Config. Field: 100K Ohm Pull Down + Hyst. Enable Field: Hysteresis Disabled */ IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_01_LCD_ENABLE, /* GPIO_B0_01 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate + IOMUXC_GPIO_AD_B0_12_LPUART1_TX, /* GPIO_AD_B0_12 PAD functional properties : */ + 0x10B0u); /* Slew Rate Field: Slow Slew Rate Drive Strength Field: R0/6 Speed Field: medium(100MHz) Open Drain Enable Field: Open Drain Disabled Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ + Pull / Keep Select Field: Keeper + Pull Up / Down Config. Field: 100K Ohm Pull Down + Hyst. Enable Field: Hysteresis Disabled */ IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_02_LCD_HSYNC, /* GPIO_B0_02 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_03_LCD_VSYNC, /* GPIO_B0_03 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_04_LCD_DATA00, /* GPIO_B0_04 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_05_LCD_DATA01, /* GPIO_B0_05 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_06_LCD_DATA02, /* GPIO_B0_06 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_07_LCD_DATA03, /* GPIO_B0_07 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_08_LCD_DATA04, /* GPIO_B0_08 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_09_LCD_DATA05, /* GPIO_B0_09 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_10_LCD_DATA06, /* GPIO_B0_10 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_11_LCD_DATA07, /* GPIO_B0_11 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_12_LCD_DATA08, /* GPIO_B0_12 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_13_LCD_DATA09, /* GPIO_B0_13 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_14_LCD_DATA10, /* GPIO_B0_14 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B0_15_LCD_DATA11, /* GPIO_B0_15 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B1_00_LCD_DATA12, /* GPIO_B1_00 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B1_01_LCD_DATA13, /* GPIO_B1_01 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B1_02_LCD_DATA14, /* GPIO_B1_02 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B1_03_LCD_DATA15, /* GPIO_B1_03 PAD functional properties : */ - 0x01B0B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Enabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B1_15_GPIO2_IO31, /* GPIO_B1_15 PAD functional properties : */ + IOMUXC_GPIO_AD_B0_13_LPUART1_RX, /* GPIO_AD_B0_13 PAD functional properties : */ 0x10B0u); /* Slew Rate Field: Slow Slew Rate Drive Strength Field: R0/6 Speed Field: medium(100MHz) @@ -1019,326 +111,6 @@ void Lcd_InitPins(void) Hyst. Enable Field: Hysteresis Disabled */ } -void BOARD_InitI2C1Pins(void) { - CLOCK_EnableClock(kCLOCK_Iomuxc); /* iomuxc clock (iomuxc_clk_enable): 0x03u */ - - IOMUXC_SetPinMux( - IOMUXC_GPIO_AD_B1_00_LPI2C1_SCL, /* GPIO_AD_B1_00 is configured as LPI2C1_SCL */ - 1U); /* Software Input On Field: Force input path of pad GPIO_AD_B1_00 */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_AD_B1_01_LPI2C1_SDA, /* GPIO_AD_B1_01 is configured as LPI2C1_SDA */ - 1U); /* Software Input On Field: Force input path of pad GPIO_AD_B1_01 */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_AD_B1_00_LPI2C1_SCL, /* GPIO_AD_B1_00 PAD functional properties : */ - 0xD8B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Enabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 22K Ohm Pull Up - Hyst. Enable Field: Hysteresis Disabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_AD_B1_01_LPI2C1_SDA, /* GPIO_AD_B1_01 PAD functional properties : */ - 0xD8B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Enabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 22K Ohm Pull Up - Hyst. Enable Field: Hysteresis Disabled */ -} - -void BOARD_InitUartPins(void) -{ -#ifdef BSP_USING_LPUART1 - IOMUXC_SetPinMux( - IOMUXC_GPIO_AD_B0_12_LPUART1_TX, /* GPIO_AD_B0_12 is configured as LPUART1_TX */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_AD_B0_13_LPUART1_RX, /* GPIO_AD_B0_13 is configured as LPUART1_RX */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_AD_B0_12_LPUART1_TX, /* GPIO_AD_B0_12 PAD functional properties : */ - 0x10B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Disabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_AD_B0_13_LPUART1_RX, /* GPIO_AD_B0_13 PAD functional properties : */ - 0x10B0u); /* Slew Rate Field: Slow Slew Rate - Drive Strength Field: R0/6 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Disabled */ -#endif -#ifdef BSP_USING_LPUART2 - IOMUXC_SetPinMux( - IOMUXC_GPIO_AD_B1_02_LPUART2_TX, - 0U); - IOMUXC_SetPinMux( - IOMUXC_GPIO_AD_B1_03_LPUART2_RX, - 0U); - IOMUXC_SetPinConfig( - IOMUXC_GPIO_AD_B1_02_LPUART2_TX, - 0x10B0u); - IOMUXC_SetPinConfig( - IOMUXC_GPIO_AD_B1_03_LPUART2_RX, - 0x10B0u); -#endif - -#ifdef BSP_USING_LPUART3 - IOMUXC_SetPinMux( - IOMUXC_GPIO_AD_B1_06_LPUART3_TX, - 0U); - IOMUXC_SetPinMux( - IOMUXC_GPIO_AD_B1_07_LPUART3_RX, - 0U); - IOMUXC_SetPinConfig( - IOMUXC_GPIO_AD_B1_06_LPUART3_TX, - 0x10B0u); - IOMUXC_SetPinConfig( - IOMUXC_GPIO_AD_B1_07_LPUART3_RX, - 0x10B0u); -#endif - - -#ifdef BSP_USING_LPUART4 - IOMUXC_SetPinMux( - IOMUXC_GPIO_SD_B1_00_LPUART4_TX, - 0U); - IOMUXC_SetPinMux( - IOMUXC_GPIO_SD_B1_01_LPUART4_RX, - 0U); - IOMUXC_SetPinConfig( - IOMUXC_GPIO_SD_B1_00_LPUART4_TX, - 0x10B0u); - IOMUXC_SetPinConfig( - IOMUXC_GPIO_SD_B1_01_LPUART4_RX, - 0x10B0u); -#endif - -#ifdef BSP_USING_LPUART8 - IOMUXC_SetPinMux( - IOMUXC_GPIO_AD_B1_10_LPUART8_TX, - 0U); - IOMUXC_SetPinMux( - IOMUXC_GPIO_AD_B1_11_LPUART8_RX, - 0U); - IOMUXC_SetPinConfig( - IOMUXC_GPIO_AD_B1_10_LPUART8_TX, - 0x10B0u); - IOMUXC_SetPinConfig( - IOMUXC_GPIO_AD_B1_11_LPUART8_RX, - 0x10B0u); -#endif -} - -/* FUNCTION ************************************************************************************************************ - * - * Function Name : BOARD_InitPins - * Description : Configures pin routing and optionally pin electrical features. - * - * END ****************************************************************************************************************/ -void BOARD_InitPins(void) -{ - CLOCK_EnableClock(kCLOCK_Iomuxc); /* iomuxc clock (iomuxc_clk_enable): 0x03u */ - /* Software Input On Field: Input Path is determined by functionality */ - SemcPinmuxConfig(); - -#ifdef BSP_USING_LPUART - BOARD_InitUartPins(); -#endif - -#ifdef BSP_USING_LCD - Lcd_InitPins(); -#endif - -#ifdef BSP_USING_I2C - BOARD_InitI2C1Pins(); -#endif - - IOMUXC_SetPinMux( - IOMUXC_GPIO_AD_B0_03_GPIO1_IO03, /* GPIO_AD_B0_09 is configured as GPIO1_IO09 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_AD_B0_10_GPIO1_IO10, /* GPIO_AD_B0_10 is configured as GPIO1_IO10 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - - IOMUXC_SetPinMux( - IOMUXC_GPIO_AD_B0_12_LPUART1_TX, /* GPIO_AD_B0_12 is configured as LPUART1_TX */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_AD_B0_13_LPUART1_RX, /* GPIO_AD_B0_13 is configured as LPUART1_RX */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - -#ifdef BSP_USING_SDIO - SDHCPinmuxConfig(); -#endif - - IOMUXC_SetPinMux( - IOMUXC_GPIO_B1_04_ENET_RX_DATA00, /* GPIO_B1_04 is configured as ENET_RX_DATA00 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B1_05_ENET_RX_DATA01, /* GPIO_B1_05 is configured as ENET_RX_DATA01 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B1_06_ENET_RX_EN, /* GPIO_B1_06 is configured as ENET_RX_EN */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B1_07_ENET_TX_DATA00, /* GPIO_B1_07 is configured as ENET_TX_DATA00 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B1_08_ENET_TX_DATA01, /* GPIO_B1_08 is configured as ENET_TX_DATA01 */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B1_09_ENET_TX_EN, /* GPIO_B1_09 is configured as ENET_TX_EN */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B1_10_ENET_REF_CLK, /* GPIO_B1_10 is configured as ENET_REF_CLK */ - 1U); /* Software Input On Field: Force input path of pad GPIO_B1_10 */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_B1_11_ENET_RX_ER, /* GPIO_B1_11 is configured as ENET_RX_ER */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_40_ENET_MDC, /* GPIO_EMC_40 is configured as ENET_MDC */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - IOMUXC_SetPinMux( - IOMUXC_GPIO_EMC_41_ENET_MDIO, /* GPIO_EMC_41 is configured as ENET_MDIO */ - 0U); /* Software Input On Field: Input Path is determined by functionality */ - - IOMUXC_SetPinConfig( - IOMUXC_GPIO_AD_B0_03_GPIO1_IO03, /* GPIO_AD_B0_09 PAD functional properties : */ - 0xB0A9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/5 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Disabled */ - - IOMUXC_SetPinConfig( - IOMUXC_GPIO_AD_B0_10_GPIO1_IO10, /* GPIO_AD_B0_10 PAD functional properties : */ - 0xB0A9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/5 - Speed Field: medium(100MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Disabled */ - - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B1_04_ENET_RX_DATA00, /* GPIO_B1_04 PAD functional properties : */ - 0xB0E9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/5 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Disabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B1_05_ENET_RX_DATA01, /* GPIO_B1_05 PAD functional properties : */ - 0xB0E9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/5 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Disabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B1_06_ENET_RX_EN, /* GPIO_B1_06 PAD functional properties : */ - 0xB0E9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/5 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Disabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B1_07_ENET_TX_DATA00, /* GPIO_B1_07 PAD functional properties : */ - 0xB0E9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/5 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Disabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B1_08_ENET_TX_DATA01, /* GPIO_B1_08 PAD functional properties : */ - 0xB0E9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/5 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Disabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B1_09_ENET_TX_EN, /* GPIO_B1_09 PAD functional properties : */ - 0xB0E9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/5 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Disabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B1_10_ENET_REF_CLK, /* GPIO_B1_10 PAD functional properties : */ - 0x31u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/6 - Speed Field: low(50MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Disabled - Pull / Keep Select Field: Keeper - Pull Up / Down Config. Field: 100K Ohm Pull Down - Hyst. Enable Field: Hysteresis Disabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_B1_11_ENET_RX_ER, /* GPIO_B1_11 PAD functional properties : */ - 0xB0E9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/5 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Disabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_40_ENET_MDC, /* GPIO_EMC_40 PAD functional properties : */ - 0xB0E9u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/5 - Speed Field: max(200MHz) - Open Drain Enable Field: Open Drain Disabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Disabled */ - IOMUXC_SetPinConfig( - IOMUXC_GPIO_EMC_41_ENET_MDIO, /* GPIO_EMC_41 PAD functional properties : */ - 0xB829u); /* Slew Rate Field: Fast Slew Rate - Drive Strength Field: R0/5 - Speed Field: low(50MHz) - Open Drain Enable Field: Open Drain Enabled - Pull / Keep Enable Field: Pull/Keeper Enabled - Pull / Keep Select Field: Pull - Pull Up / Down Config. Field: 100K Ohm Pull Up - Hyst. Enable Field: Hysteresis Disabled */ -} - /*********************************************************************************************************************** * EOF **********************************************************************************************************************/ diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/MIMXRT1052.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/MIMXRT1052.h index 552c36a16..a6607cd7e 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/MIMXRT1052.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/MIMXRT1052.h @@ -58,7 +58,7 @@ * compatible) */ #define MCU_MEM_MAP_VERSION 0x0100U /** Memory map minor version */ -#define MCU_MEM_MAP_VERSION_MINOR 0x0002U +#define MCU_MEM_MAP_VERSION_MINOR 0x0003U /* ---------------------------------------------------------------------------- @@ -9543,73 +9543,96 @@ typedef struct { /** DCP - Register Layout Typedef */ typedef struct { __IO uint32_t CTRL; /**< DCP control register 0, offset: 0x0 */ - uint8_t RESERVED_0[12]; + __IO uint32_t CTRL_SET; /**< DCP control register 0, offset: 0x4 */ + __IO uint32_t CTRL_CLR; /**< DCP control register 0, offset: 0x8 */ + __IO uint32_t CTRL_TOG; /**< DCP control register 0, offset: 0xC */ __IO uint32_t STAT; /**< DCP status register, offset: 0x10 */ - uint8_t RESERVED_1[12]; + __IO uint32_t STAT_SET; /**< DCP status register, offset: 0x14 */ + __IO uint32_t STAT_CLR; /**< DCP status register, offset: 0x18 */ + __IO uint32_t STAT_TOG; /**< DCP status register, offset: 0x1C */ __IO uint32_t CHANNELCTRL; /**< DCP channel control register, offset: 0x20 */ - uint8_t RESERVED_2[12]; + __IO uint32_t CHANNELCTRL_SET; /**< DCP channel control register, offset: 0x24 */ + __IO uint32_t CHANNELCTRL_CLR; /**< DCP channel control register, offset: 0x28 */ + __IO uint32_t CHANNELCTRL_TOG; /**< DCP channel control register, offset: 0x2C */ __IO uint32_t CAPABILITY0; /**< DCP capability 0 register, offset: 0x30 */ - uint8_t RESERVED_3[12]; + uint8_t RESERVED_0[12]; __I uint32_t CAPABILITY1; /**< DCP capability 1 register, offset: 0x40 */ - uint8_t RESERVED_4[12]; + uint8_t RESERVED_1[12]; __IO uint32_t CONTEXT; /**< DCP context buffer pointer, offset: 0x50 */ - uint8_t RESERVED_5[12]; + uint8_t RESERVED_2[12]; __IO uint32_t KEY; /**< DCP key index, offset: 0x60 */ - uint8_t RESERVED_6[12]; + uint8_t RESERVED_3[12]; __IO uint32_t KEYDATA; /**< DCP key data, offset: 0x70 */ - uint8_t RESERVED_7[12]; + uint8_t RESERVED_4[12]; __I uint32_t PACKET0; /**< DCP work packet 0 status register, offset: 0x80 */ - uint8_t RESERVED_8[12]; + uint8_t RESERVED_5[12]; __I uint32_t PACKET1; /**< DCP work packet 1 status register, offset: 0x90 */ - uint8_t RESERVED_9[12]; + uint8_t RESERVED_6[12]; __I uint32_t PACKET2; /**< DCP work packet 2 status register, offset: 0xA0 */ - uint8_t RESERVED_10[12]; + uint8_t RESERVED_7[12]; __I uint32_t PACKET3; /**< DCP work packet 3 status register, offset: 0xB0 */ - uint8_t RESERVED_11[12]; + uint8_t RESERVED_8[12]; __I uint32_t PACKET4; /**< DCP work packet 4 status register, offset: 0xC0 */ - uint8_t RESERVED_12[12]; + uint8_t RESERVED_9[12]; __I uint32_t PACKET5; /**< DCP work packet 5 status register, offset: 0xD0 */ - uint8_t RESERVED_13[12]; + uint8_t RESERVED_10[12]; __I uint32_t PACKET6; /**< DCP work packet 6 status register, offset: 0xE0 */ - uint8_t RESERVED_14[28]; + uint8_t RESERVED_11[28]; __IO uint32_t CH0CMDPTR; /**< DCP channel 0 command pointer address register, offset: 0x100 */ - uint8_t RESERVED_15[12]; + uint8_t RESERVED_12[12]; __IO uint32_t CH0SEMA; /**< DCP channel 0 semaphore register, offset: 0x110 */ - uint8_t RESERVED_16[12]; + uint8_t RESERVED_13[12]; __IO uint32_t CH0STAT; /**< DCP channel 0 status register, offset: 0x120 */ - uint8_t RESERVED_17[12]; + __IO uint32_t CH0STAT_SET; /**< DCP channel 0 status register, offset: 0x124 */ + __IO uint32_t CH0STAT_CLR; /**< DCP channel 0 status register, offset: 0x128 */ + __IO uint32_t CH0STAT_TOG; /**< DCP channel 0 status register, offset: 0x12C */ __IO uint32_t CH0OPTS; /**< DCP channel 0 options register, offset: 0x130 */ - uint8_t RESERVED_18[12]; + __IO uint32_t CH0OPTS_SET; /**< DCP channel 0 options register, offset: 0x134 */ + __IO uint32_t CH0OPTS_CLR; /**< DCP channel 0 options register, offset: 0x138 */ + __IO uint32_t CH0OPTS_TOG; /**< DCP channel 0 options register, offset: 0x13C */ __IO uint32_t CH1CMDPTR; /**< DCP channel 1 command pointer address register, offset: 0x140 */ - uint8_t RESERVED_19[12]; + uint8_t RESERVED_14[12]; __IO uint32_t CH1SEMA; /**< DCP channel 1 semaphore register, offset: 0x150 */ - uint8_t RESERVED_20[12]; + uint8_t RESERVED_15[12]; __IO uint32_t CH1STAT; /**< DCP channel 1 status register, offset: 0x160 */ - uint8_t RESERVED_21[12]; + __IO uint32_t CH1STAT_SET; /**< DCP channel 1 status register, offset: 0x164 */ + __IO uint32_t CH1STAT_CLR; /**< DCP channel 1 status register, offset: 0x168 */ + __IO uint32_t CH1STAT_TOG; /**< DCP channel 1 status register, offset: 0x16C */ __IO uint32_t CH1OPTS; /**< DCP channel 1 options register, offset: 0x170 */ - uint8_t RESERVED_22[12]; + __IO uint32_t CH1OPTS_SET; /**< DCP channel 1 options register, offset: 0x174 */ + __IO uint32_t CH1OPTS_CLR; /**< DCP channel 1 options register, offset: 0x178 */ + __IO uint32_t CH1OPTS_TOG; /**< DCP channel 1 options register, offset: 0x17C */ __IO uint32_t CH2CMDPTR; /**< DCP channel 2 command pointer address register, offset: 0x180 */ - uint8_t RESERVED_23[12]; + uint8_t RESERVED_16[12]; __IO uint32_t CH2SEMA; /**< DCP channel 2 semaphore register, offset: 0x190 */ - uint8_t RESERVED_24[12]; + uint8_t RESERVED_17[12]; __IO uint32_t CH2STAT; /**< DCP channel 2 status register, offset: 0x1A0 */ - uint8_t RESERVED_25[12]; + __IO uint32_t CH2STAT_SET; /**< DCP channel 2 status register, offset: 0x1A4 */ + __IO uint32_t CH2STAT_CLR; /**< DCP channel 2 status register, offset: 0x1A8 */ + __IO uint32_t CH2STAT_TOG; /**< DCP channel 2 status register, offset: 0x1AC */ __IO uint32_t CH2OPTS; /**< DCP channel 2 options register, offset: 0x1B0 */ - uint8_t RESERVED_26[12]; + __IO uint32_t CH2OPTS_SET; /**< DCP channel 2 options register, offset: 0x1B4 */ + __IO uint32_t CH2OPTS_CLR; /**< DCP channel 2 options register, offset: 0x1B8 */ + __IO uint32_t CH2OPTS_TOG; /**< DCP channel 2 options register, offset: 0x1BC */ __IO uint32_t CH3CMDPTR; /**< DCP channel 3 command pointer address register, offset: 0x1C0 */ - uint8_t RESERVED_27[12]; + uint8_t RESERVED_18[12]; __IO uint32_t CH3SEMA; /**< DCP channel 3 semaphore register, offset: 0x1D0 */ - uint8_t RESERVED_28[12]; + uint8_t RESERVED_19[12]; __IO uint32_t CH3STAT; /**< DCP channel 3 status register, offset: 0x1E0 */ - uint8_t RESERVED_29[12]; + __IO uint32_t CH3STAT_SET; /**< DCP channel 3 status register, offset: 0x1E4 */ + __IO uint32_t CH3STAT_CLR; /**< DCP channel 3 status register, offset: 0x1E8 */ + __IO uint32_t CH3STAT_TOG; /**< DCP channel 3 status register, offset: 0x1EC */ __IO uint32_t CH3OPTS; /**< DCP channel 3 options register, offset: 0x1F0 */ - uint8_t RESERVED_30[524]; + __IO uint32_t CH3OPTS_SET; /**< DCP channel 3 options register, offset: 0x1F4 */ + __IO uint32_t CH3OPTS_CLR; /**< DCP channel 3 options register, offset: 0x1F8 */ + __IO uint32_t CH3OPTS_TOG; /**< DCP channel 3 options register, offset: 0x1FC */ + uint8_t RESERVED_20[512]; __IO uint32_t DBGSELECT; /**< DCP debug select register, offset: 0x400 */ - uint8_t RESERVED_31[12]; + uint8_t RESERVED_21[12]; __I uint32_t DBGDATA; /**< DCP debug data register, offset: 0x410 */ - uint8_t RESERVED_32[12]; + uint8_t RESERVED_22[12]; __IO uint32_t PAGETABLE; /**< DCP page table register, offset: 0x420 */ - uint8_t RESERVED_33[12]; + uint8_t RESERVED_23[12]; __I uint32_t VERSION; /**< DCP version register, offset: 0x430 */ } DCP_Type; @@ -9667,6 +9690,141 @@ typedef struct { #define DCP_CTRL_SFTRST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_SFTRST_SHIFT)) & DCP_CTRL_SFTRST_MASK) /*! @} */ +/*! @name CTRL_SET - DCP control register 0 */ +/*! @{ */ +#define DCP_CTRL_SET_CHANNEL_INTERRUPT_ENABLE_MASK (0xFFU) +#define DCP_CTRL_SET_CHANNEL_INTERRUPT_ENABLE_SHIFT (0U) +/*! CHANNEL_INTERRUPT_ENABLE + * 0b00000001..CH0 + * 0b00000010..CH1 + * 0b00000100..CH2 + * 0b00001000..CH3 + */ +#define DCP_CTRL_SET_CHANNEL_INTERRUPT_ENABLE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_SET_CHANNEL_INTERRUPT_ENABLE_SHIFT)) & DCP_CTRL_SET_CHANNEL_INTERRUPT_ENABLE_MASK) +#define DCP_CTRL_SET_RSVD_CSC_INTERRUPT_ENABLE_MASK (0x100U) +#define DCP_CTRL_SET_RSVD_CSC_INTERRUPT_ENABLE_SHIFT (8U) +#define DCP_CTRL_SET_RSVD_CSC_INTERRUPT_ENABLE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_SET_RSVD_CSC_INTERRUPT_ENABLE_SHIFT)) & DCP_CTRL_SET_RSVD_CSC_INTERRUPT_ENABLE_MASK) +#define DCP_CTRL_SET_ENABLE_CONTEXT_SWITCHING_MASK (0x200000U) +#define DCP_CTRL_SET_ENABLE_CONTEXT_SWITCHING_SHIFT (21U) +#define DCP_CTRL_SET_ENABLE_CONTEXT_SWITCHING(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_SET_ENABLE_CONTEXT_SWITCHING_SHIFT)) & DCP_CTRL_SET_ENABLE_CONTEXT_SWITCHING_MASK) +#define DCP_CTRL_SET_ENABLE_CONTEXT_CACHING_MASK (0x400000U) +#define DCP_CTRL_SET_ENABLE_CONTEXT_CACHING_SHIFT (22U) +#define DCP_CTRL_SET_ENABLE_CONTEXT_CACHING(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_SET_ENABLE_CONTEXT_CACHING_SHIFT)) & DCP_CTRL_SET_ENABLE_CONTEXT_CACHING_MASK) +#define DCP_CTRL_SET_GATHER_RESIDUAL_WRITES_MASK (0x800000U) +#define DCP_CTRL_SET_GATHER_RESIDUAL_WRITES_SHIFT (23U) +#define DCP_CTRL_SET_GATHER_RESIDUAL_WRITES(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_SET_GATHER_RESIDUAL_WRITES_SHIFT)) & DCP_CTRL_SET_GATHER_RESIDUAL_WRITES_MASK) +#define DCP_CTRL_SET_PRESENT_SHA_MASK (0x10000000U) +#define DCP_CTRL_SET_PRESENT_SHA_SHIFT (28U) +/*! PRESENT_SHA + * 0b1..Present + * 0b0..Absent + */ +#define DCP_CTRL_SET_PRESENT_SHA(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_SET_PRESENT_SHA_SHIFT)) & DCP_CTRL_SET_PRESENT_SHA_MASK) +#define DCP_CTRL_SET_PRESENT_CRYPTO_MASK (0x20000000U) +#define DCP_CTRL_SET_PRESENT_CRYPTO_SHIFT (29U) +/*! PRESENT_CRYPTO + * 0b1..Present + * 0b0..Absent + */ +#define DCP_CTRL_SET_PRESENT_CRYPTO(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_SET_PRESENT_CRYPTO_SHIFT)) & DCP_CTRL_SET_PRESENT_CRYPTO_MASK) +#define DCP_CTRL_SET_CLKGATE_MASK (0x40000000U) +#define DCP_CTRL_SET_CLKGATE_SHIFT (30U) +#define DCP_CTRL_SET_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_SET_CLKGATE_SHIFT)) & DCP_CTRL_SET_CLKGATE_MASK) +#define DCP_CTRL_SET_SFTRST_MASK (0x80000000U) +#define DCP_CTRL_SET_SFTRST_SHIFT (31U) +#define DCP_CTRL_SET_SFTRST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_SET_SFTRST_SHIFT)) & DCP_CTRL_SET_SFTRST_MASK) +/*! @} */ + +/*! @name CTRL_CLR - DCP control register 0 */ +/*! @{ */ +#define DCP_CTRL_CLR_CHANNEL_INTERRUPT_ENABLE_MASK (0xFFU) +#define DCP_CTRL_CLR_CHANNEL_INTERRUPT_ENABLE_SHIFT (0U) +/*! CHANNEL_INTERRUPT_ENABLE + * 0b00000001..CH0 + * 0b00000010..CH1 + * 0b00000100..CH2 + * 0b00001000..CH3 + */ +#define DCP_CTRL_CLR_CHANNEL_INTERRUPT_ENABLE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_CLR_CHANNEL_INTERRUPT_ENABLE_SHIFT)) & DCP_CTRL_CLR_CHANNEL_INTERRUPT_ENABLE_MASK) +#define DCP_CTRL_CLR_RSVD_CSC_INTERRUPT_ENABLE_MASK (0x100U) +#define DCP_CTRL_CLR_RSVD_CSC_INTERRUPT_ENABLE_SHIFT (8U) +#define DCP_CTRL_CLR_RSVD_CSC_INTERRUPT_ENABLE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_CLR_RSVD_CSC_INTERRUPT_ENABLE_SHIFT)) & DCP_CTRL_CLR_RSVD_CSC_INTERRUPT_ENABLE_MASK) +#define DCP_CTRL_CLR_ENABLE_CONTEXT_SWITCHING_MASK (0x200000U) +#define DCP_CTRL_CLR_ENABLE_CONTEXT_SWITCHING_SHIFT (21U) +#define DCP_CTRL_CLR_ENABLE_CONTEXT_SWITCHING(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_CLR_ENABLE_CONTEXT_SWITCHING_SHIFT)) & DCP_CTRL_CLR_ENABLE_CONTEXT_SWITCHING_MASK) +#define DCP_CTRL_CLR_ENABLE_CONTEXT_CACHING_MASK (0x400000U) +#define DCP_CTRL_CLR_ENABLE_CONTEXT_CACHING_SHIFT (22U) +#define DCP_CTRL_CLR_ENABLE_CONTEXT_CACHING(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_CLR_ENABLE_CONTEXT_CACHING_SHIFT)) & DCP_CTRL_CLR_ENABLE_CONTEXT_CACHING_MASK) +#define DCP_CTRL_CLR_GATHER_RESIDUAL_WRITES_MASK (0x800000U) +#define DCP_CTRL_CLR_GATHER_RESIDUAL_WRITES_SHIFT (23U) +#define DCP_CTRL_CLR_GATHER_RESIDUAL_WRITES(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_CLR_GATHER_RESIDUAL_WRITES_SHIFT)) & DCP_CTRL_CLR_GATHER_RESIDUAL_WRITES_MASK) +#define DCP_CTRL_CLR_PRESENT_SHA_MASK (0x10000000U) +#define DCP_CTRL_CLR_PRESENT_SHA_SHIFT (28U) +/*! PRESENT_SHA + * 0b1..Present + * 0b0..Absent + */ +#define DCP_CTRL_CLR_PRESENT_SHA(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_CLR_PRESENT_SHA_SHIFT)) & DCP_CTRL_CLR_PRESENT_SHA_MASK) +#define DCP_CTRL_CLR_PRESENT_CRYPTO_MASK (0x20000000U) +#define DCP_CTRL_CLR_PRESENT_CRYPTO_SHIFT (29U) +/*! PRESENT_CRYPTO + * 0b1..Present + * 0b0..Absent + */ +#define DCP_CTRL_CLR_PRESENT_CRYPTO(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_CLR_PRESENT_CRYPTO_SHIFT)) & DCP_CTRL_CLR_PRESENT_CRYPTO_MASK) +#define DCP_CTRL_CLR_CLKGATE_MASK (0x40000000U) +#define DCP_CTRL_CLR_CLKGATE_SHIFT (30U) +#define DCP_CTRL_CLR_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_CLR_CLKGATE_SHIFT)) & DCP_CTRL_CLR_CLKGATE_MASK) +#define DCP_CTRL_CLR_SFTRST_MASK (0x80000000U) +#define DCP_CTRL_CLR_SFTRST_SHIFT (31U) +#define DCP_CTRL_CLR_SFTRST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_CLR_SFTRST_SHIFT)) & DCP_CTRL_CLR_SFTRST_MASK) +/*! @} */ + +/*! @name CTRL_TOG - DCP control register 0 */ +/*! @{ */ +#define DCP_CTRL_TOG_CHANNEL_INTERRUPT_ENABLE_MASK (0xFFU) +#define DCP_CTRL_TOG_CHANNEL_INTERRUPT_ENABLE_SHIFT (0U) +/*! CHANNEL_INTERRUPT_ENABLE + * 0b00000001..CH0 + * 0b00000010..CH1 + * 0b00000100..CH2 + * 0b00001000..CH3 + */ +#define DCP_CTRL_TOG_CHANNEL_INTERRUPT_ENABLE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_TOG_CHANNEL_INTERRUPT_ENABLE_SHIFT)) & DCP_CTRL_TOG_CHANNEL_INTERRUPT_ENABLE_MASK) +#define DCP_CTRL_TOG_RSVD_CSC_INTERRUPT_ENABLE_MASK (0x100U) +#define DCP_CTRL_TOG_RSVD_CSC_INTERRUPT_ENABLE_SHIFT (8U) +#define DCP_CTRL_TOG_RSVD_CSC_INTERRUPT_ENABLE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_TOG_RSVD_CSC_INTERRUPT_ENABLE_SHIFT)) & DCP_CTRL_TOG_RSVD_CSC_INTERRUPT_ENABLE_MASK) +#define DCP_CTRL_TOG_ENABLE_CONTEXT_SWITCHING_MASK (0x200000U) +#define DCP_CTRL_TOG_ENABLE_CONTEXT_SWITCHING_SHIFT (21U) +#define DCP_CTRL_TOG_ENABLE_CONTEXT_SWITCHING(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_TOG_ENABLE_CONTEXT_SWITCHING_SHIFT)) & DCP_CTRL_TOG_ENABLE_CONTEXT_SWITCHING_MASK) +#define DCP_CTRL_TOG_ENABLE_CONTEXT_CACHING_MASK (0x400000U) +#define DCP_CTRL_TOG_ENABLE_CONTEXT_CACHING_SHIFT (22U) +#define DCP_CTRL_TOG_ENABLE_CONTEXT_CACHING(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_TOG_ENABLE_CONTEXT_CACHING_SHIFT)) & DCP_CTRL_TOG_ENABLE_CONTEXT_CACHING_MASK) +#define DCP_CTRL_TOG_GATHER_RESIDUAL_WRITES_MASK (0x800000U) +#define DCP_CTRL_TOG_GATHER_RESIDUAL_WRITES_SHIFT (23U) +#define DCP_CTRL_TOG_GATHER_RESIDUAL_WRITES(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_TOG_GATHER_RESIDUAL_WRITES_SHIFT)) & DCP_CTRL_TOG_GATHER_RESIDUAL_WRITES_MASK) +#define DCP_CTRL_TOG_PRESENT_SHA_MASK (0x10000000U) +#define DCP_CTRL_TOG_PRESENT_SHA_SHIFT (28U) +/*! PRESENT_SHA + * 0b1..Present + * 0b0..Absent + */ +#define DCP_CTRL_TOG_PRESENT_SHA(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_TOG_PRESENT_SHA_SHIFT)) & DCP_CTRL_TOG_PRESENT_SHA_MASK) +#define DCP_CTRL_TOG_PRESENT_CRYPTO_MASK (0x20000000U) +#define DCP_CTRL_TOG_PRESENT_CRYPTO_SHIFT (29U) +/*! PRESENT_CRYPTO + * 0b1..Present + * 0b0..Absent + */ +#define DCP_CTRL_TOG_PRESENT_CRYPTO(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_TOG_PRESENT_CRYPTO_SHIFT)) & DCP_CTRL_TOG_PRESENT_CRYPTO_MASK) +#define DCP_CTRL_TOG_CLKGATE_MASK (0x40000000U) +#define DCP_CTRL_TOG_CLKGATE_SHIFT (30U) +#define DCP_CTRL_TOG_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_TOG_CLKGATE_SHIFT)) & DCP_CTRL_TOG_CLKGATE_MASK) +#define DCP_CTRL_TOG_SFTRST_MASK (0x80000000U) +#define DCP_CTRL_TOG_SFTRST_SHIFT (31U) +#define DCP_CTRL_TOG_SFTRST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CTRL_TOG_SFTRST_SHIFT)) & DCP_CTRL_TOG_SFTRST_MASK) +/*! @} */ + /*! @name STAT - DCP status register */ /*! @{ */ #define DCP_STAT_IRQ_MASK (0xFU) @@ -9699,6 +9857,102 @@ typedef struct { #define DCP_STAT_OTP_KEY_READY(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_OTP_KEY_READY_SHIFT)) & DCP_STAT_OTP_KEY_READY_MASK) /*! @} */ +/*! @name STAT_SET - DCP status register */ +/*! @{ */ +#define DCP_STAT_SET_IRQ_MASK (0xFU) +#define DCP_STAT_SET_IRQ_SHIFT (0U) +#define DCP_STAT_SET_IRQ(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_SET_IRQ_SHIFT)) & DCP_STAT_SET_IRQ_MASK) +#define DCP_STAT_SET_RSVD_IRQ_MASK (0x100U) +#define DCP_STAT_SET_RSVD_IRQ_SHIFT (8U) +#define DCP_STAT_SET_RSVD_IRQ(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_SET_RSVD_IRQ_SHIFT)) & DCP_STAT_SET_RSVD_IRQ_MASK) +#define DCP_STAT_SET_READY_CHANNELS_MASK (0xFF0000U) +#define DCP_STAT_SET_READY_CHANNELS_SHIFT (16U) +/*! READY_CHANNELS + * 0b00000001..CH0 + * 0b00000010..CH1 + * 0b00000100..CH2 + * 0b00001000..CH3 + */ +#define DCP_STAT_SET_READY_CHANNELS(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_SET_READY_CHANNELS_SHIFT)) & DCP_STAT_SET_READY_CHANNELS_MASK) +#define DCP_STAT_SET_CUR_CHANNEL_MASK (0xF000000U) +#define DCP_STAT_SET_CUR_CHANNEL_SHIFT (24U) +/*! CUR_CHANNEL + * 0b0000..None + * 0b0001..CH0 + * 0b0010..CH1 + * 0b0011..CH2 + * 0b0100..CH3 + */ +#define DCP_STAT_SET_CUR_CHANNEL(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_SET_CUR_CHANNEL_SHIFT)) & DCP_STAT_SET_CUR_CHANNEL_MASK) +#define DCP_STAT_SET_OTP_KEY_READY_MASK (0x10000000U) +#define DCP_STAT_SET_OTP_KEY_READY_SHIFT (28U) +#define DCP_STAT_SET_OTP_KEY_READY(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_SET_OTP_KEY_READY_SHIFT)) & DCP_STAT_SET_OTP_KEY_READY_MASK) +/*! @} */ + +/*! @name STAT_CLR - DCP status register */ +/*! @{ */ +#define DCP_STAT_CLR_IRQ_MASK (0xFU) +#define DCP_STAT_CLR_IRQ_SHIFT (0U) +#define DCP_STAT_CLR_IRQ(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_CLR_IRQ_SHIFT)) & DCP_STAT_CLR_IRQ_MASK) +#define DCP_STAT_CLR_RSVD_IRQ_MASK (0x100U) +#define DCP_STAT_CLR_RSVD_IRQ_SHIFT (8U) +#define DCP_STAT_CLR_RSVD_IRQ(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_CLR_RSVD_IRQ_SHIFT)) & DCP_STAT_CLR_RSVD_IRQ_MASK) +#define DCP_STAT_CLR_READY_CHANNELS_MASK (0xFF0000U) +#define DCP_STAT_CLR_READY_CHANNELS_SHIFT (16U) +/*! READY_CHANNELS + * 0b00000001..CH0 + * 0b00000010..CH1 + * 0b00000100..CH2 + * 0b00001000..CH3 + */ +#define DCP_STAT_CLR_READY_CHANNELS(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_CLR_READY_CHANNELS_SHIFT)) & DCP_STAT_CLR_READY_CHANNELS_MASK) +#define DCP_STAT_CLR_CUR_CHANNEL_MASK (0xF000000U) +#define DCP_STAT_CLR_CUR_CHANNEL_SHIFT (24U) +/*! CUR_CHANNEL + * 0b0000..None + * 0b0001..CH0 + * 0b0010..CH1 + * 0b0011..CH2 + * 0b0100..CH3 + */ +#define DCP_STAT_CLR_CUR_CHANNEL(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_CLR_CUR_CHANNEL_SHIFT)) & DCP_STAT_CLR_CUR_CHANNEL_MASK) +#define DCP_STAT_CLR_OTP_KEY_READY_MASK (0x10000000U) +#define DCP_STAT_CLR_OTP_KEY_READY_SHIFT (28U) +#define DCP_STAT_CLR_OTP_KEY_READY(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_CLR_OTP_KEY_READY_SHIFT)) & DCP_STAT_CLR_OTP_KEY_READY_MASK) +/*! @} */ + +/*! @name STAT_TOG - DCP status register */ +/*! @{ */ +#define DCP_STAT_TOG_IRQ_MASK (0xFU) +#define DCP_STAT_TOG_IRQ_SHIFT (0U) +#define DCP_STAT_TOG_IRQ(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_TOG_IRQ_SHIFT)) & DCP_STAT_TOG_IRQ_MASK) +#define DCP_STAT_TOG_RSVD_IRQ_MASK (0x100U) +#define DCP_STAT_TOG_RSVD_IRQ_SHIFT (8U) +#define DCP_STAT_TOG_RSVD_IRQ(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_TOG_RSVD_IRQ_SHIFT)) & DCP_STAT_TOG_RSVD_IRQ_MASK) +#define DCP_STAT_TOG_READY_CHANNELS_MASK (0xFF0000U) +#define DCP_STAT_TOG_READY_CHANNELS_SHIFT (16U) +/*! READY_CHANNELS + * 0b00000001..CH0 + * 0b00000010..CH1 + * 0b00000100..CH2 + * 0b00001000..CH3 + */ +#define DCP_STAT_TOG_READY_CHANNELS(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_TOG_READY_CHANNELS_SHIFT)) & DCP_STAT_TOG_READY_CHANNELS_MASK) +#define DCP_STAT_TOG_CUR_CHANNEL_MASK (0xF000000U) +#define DCP_STAT_TOG_CUR_CHANNEL_SHIFT (24U) +/*! CUR_CHANNEL + * 0b0000..None + * 0b0001..CH0 + * 0b0010..CH1 + * 0b0011..CH2 + * 0b0100..CH3 + */ +#define DCP_STAT_TOG_CUR_CHANNEL(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_TOG_CUR_CHANNEL_SHIFT)) & DCP_STAT_TOG_CUR_CHANNEL_MASK) +#define DCP_STAT_TOG_OTP_KEY_READY_MASK (0x10000000U) +#define DCP_STAT_TOG_OTP_KEY_READY_SHIFT (28U) +#define DCP_STAT_TOG_OTP_KEY_READY(x) (((uint32_t)(((uint32_t)(x)) << DCP_STAT_TOG_OTP_KEY_READY_SHIFT)) & DCP_STAT_TOG_OTP_KEY_READY_MASK) +/*! @} */ + /*! @name CHANNELCTRL - DCP channel control register */ /*! @{ */ #define DCP_CHANNELCTRL_ENABLE_CHANNEL_MASK (0xFFU) @@ -9727,6 +9981,90 @@ typedef struct { #define DCP_CHANNELCTRL_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CHANNELCTRL_RSVD_SHIFT)) & DCP_CHANNELCTRL_RSVD_MASK) /*! @} */ +/*! @name CHANNELCTRL_SET - DCP channel control register */ +/*! @{ */ +#define DCP_CHANNELCTRL_SET_ENABLE_CHANNEL_MASK (0xFFU) +#define DCP_CHANNELCTRL_SET_ENABLE_CHANNEL_SHIFT (0U) +/*! ENABLE_CHANNEL + * 0b00000001..CH0 + * 0b00000010..CH1 + * 0b00000100..CH2 + * 0b00001000..CH3 + */ +#define DCP_CHANNELCTRL_SET_ENABLE_CHANNEL(x) (((uint32_t)(((uint32_t)(x)) << DCP_CHANNELCTRL_SET_ENABLE_CHANNEL_SHIFT)) & DCP_CHANNELCTRL_SET_ENABLE_CHANNEL_MASK) +#define DCP_CHANNELCTRL_SET_HIGH_PRIORITY_CHANNEL_MASK (0xFF00U) +#define DCP_CHANNELCTRL_SET_HIGH_PRIORITY_CHANNEL_SHIFT (8U) +/*! HIGH_PRIORITY_CHANNEL + * 0b00000001..CH0 + * 0b00000010..CH1 + * 0b00000100..CH2 + * 0b00001000..CH3 + */ +#define DCP_CHANNELCTRL_SET_HIGH_PRIORITY_CHANNEL(x) (((uint32_t)(((uint32_t)(x)) << DCP_CHANNELCTRL_SET_HIGH_PRIORITY_CHANNEL_SHIFT)) & DCP_CHANNELCTRL_SET_HIGH_PRIORITY_CHANNEL_MASK) +#define DCP_CHANNELCTRL_SET_CH0_IRQ_MERGED_MASK (0x10000U) +#define DCP_CHANNELCTRL_SET_CH0_IRQ_MERGED_SHIFT (16U) +#define DCP_CHANNELCTRL_SET_CH0_IRQ_MERGED(x) (((uint32_t)(((uint32_t)(x)) << DCP_CHANNELCTRL_SET_CH0_IRQ_MERGED_SHIFT)) & DCP_CHANNELCTRL_SET_CH0_IRQ_MERGED_MASK) +#define DCP_CHANNELCTRL_SET_RSVD_MASK (0xFFFE0000U) +#define DCP_CHANNELCTRL_SET_RSVD_SHIFT (17U) +#define DCP_CHANNELCTRL_SET_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CHANNELCTRL_SET_RSVD_SHIFT)) & DCP_CHANNELCTRL_SET_RSVD_MASK) +/*! @} */ + +/*! @name CHANNELCTRL_CLR - DCP channel control register */ +/*! @{ */ +#define DCP_CHANNELCTRL_CLR_ENABLE_CHANNEL_MASK (0xFFU) +#define DCP_CHANNELCTRL_CLR_ENABLE_CHANNEL_SHIFT (0U) +/*! ENABLE_CHANNEL + * 0b00000001..CH0 + * 0b00000010..CH1 + * 0b00000100..CH2 + * 0b00001000..CH3 + */ +#define DCP_CHANNELCTRL_CLR_ENABLE_CHANNEL(x) (((uint32_t)(((uint32_t)(x)) << DCP_CHANNELCTRL_CLR_ENABLE_CHANNEL_SHIFT)) & DCP_CHANNELCTRL_CLR_ENABLE_CHANNEL_MASK) +#define DCP_CHANNELCTRL_CLR_HIGH_PRIORITY_CHANNEL_MASK (0xFF00U) +#define DCP_CHANNELCTRL_CLR_HIGH_PRIORITY_CHANNEL_SHIFT (8U) +/*! HIGH_PRIORITY_CHANNEL + * 0b00000001..CH0 + * 0b00000010..CH1 + * 0b00000100..CH2 + * 0b00001000..CH3 + */ +#define DCP_CHANNELCTRL_CLR_HIGH_PRIORITY_CHANNEL(x) (((uint32_t)(((uint32_t)(x)) << DCP_CHANNELCTRL_CLR_HIGH_PRIORITY_CHANNEL_SHIFT)) & DCP_CHANNELCTRL_CLR_HIGH_PRIORITY_CHANNEL_MASK) +#define DCP_CHANNELCTRL_CLR_CH0_IRQ_MERGED_MASK (0x10000U) +#define DCP_CHANNELCTRL_CLR_CH0_IRQ_MERGED_SHIFT (16U) +#define DCP_CHANNELCTRL_CLR_CH0_IRQ_MERGED(x) (((uint32_t)(((uint32_t)(x)) << DCP_CHANNELCTRL_CLR_CH0_IRQ_MERGED_SHIFT)) & DCP_CHANNELCTRL_CLR_CH0_IRQ_MERGED_MASK) +#define DCP_CHANNELCTRL_CLR_RSVD_MASK (0xFFFE0000U) +#define DCP_CHANNELCTRL_CLR_RSVD_SHIFT (17U) +#define DCP_CHANNELCTRL_CLR_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CHANNELCTRL_CLR_RSVD_SHIFT)) & DCP_CHANNELCTRL_CLR_RSVD_MASK) +/*! @} */ + +/*! @name CHANNELCTRL_TOG - DCP channel control register */ +/*! @{ */ +#define DCP_CHANNELCTRL_TOG_ENABLE_CHANNEL_MASK (0xFFU) +#define DCP_CHANNELCTRL_TOG_ENABLE_CHANNEL_SHIFT (0U) +/*! ENABLE_CHANNEL + * 0b00000001..CH0 + * 0b00000010..CH1 + * 0b00000100..CH2 + * 0b00001000..CH3 + */ +#define DCP_CHANNELCTRL_TOG_ENABLE_CHANNEL(x) (((uint32_t)(((uint32_t)(x)) << DCP_CHANNELCTRL_TOG_ENABLE_CHANNEL_SHIFT)) & DCP_CHANNELCTRL_TOG_ENABLE_CHANNEL_MASK) +#define DCP_CHANNELCTRL_TOG_HIGH_PRIORITY_CHANNEL_MASK (0xFF00U) +#define DCP_CHANNELCTRL_TOG_HIGH_PRIORITY_CHANNEL_SHIFT (8U) +/*! HIGH_PRIORITY_CHANNEL + * 0b00000001..CH0 + * 0b00000010..CH1 + * 0b00000100..CH2 + * 0b00001000..CH3 + */ +#define DCP_CHANNELCTRL_TOG_HIGH_PRIORITY_CHANNEL(x) (((uint32_t)(((uint32_t)(x)) << DCP_CHANNELCTRL_TOG_HIGH_PRIORITY_CHANNEL_SHIFT)) & DCP_CHANNELCTRL_TOG_HIGH_PRIORITY_CHANNEL_MASK) +#define DCP_CHANNELCTRL_TOG_CH0_IRQ_MERGED_MASK (0x10000U) +#define DCP_CHANNELCTRL_TOG_CH0_IRQ_MERGED_SHIFT (16U) +#define DCP_CHANNELCTRL_TOG_CH0_IRQ_MERGED(x) (((uint32_t)(((uint32_t)(x)) << DCP_CHANNELCTRL_TOG_CH0_IRQ_MERGED_SHIFT)) & DCP_CHANNELCTRL_TOG_CH0_IRQ_MERGED_MASK) +#define DCP_CHANNELCTRL_TOG_RSVD_MASK (0xFFFE0000U) +#define DCP_CHANNELCTRL_TOG_RSVD_SHIFT (17U) +#define DCP_CHANNELCTRL_TOG_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CHANNELCTRL_TOG_RSVD_SHIFT)) & DCP_CHANNELCTRL_TOG_RSVD_MASK) +/*! @} */ + /*! @name CAPABILITY0 - DCP capability 0 register */ /*! @{ */ #define DCP_CAPABILITY0_NUM_KEYS_MASK (0xFFU) @@ -10016,6 +10354,120 @@ typedef struct { #define DCP_CH0STAT_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_TAG_SHIFT)) & DCP_CH0STAT_TAG_MASK) /*! @} */ +/*! @name CH0STAT_SET - DCP channel 0 status register */ +/*! @{ */ +#define DCP_CH0STAT_SET_RSVD_COMPLETE_MASK (0x1U) +#define DCP_CH0STAT_SET_RSVD_COMPLETE_SHIFT (0U) +#define DCP_CH0STAT_SET_RSVD_COMPLETE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_SET_RSVD_COMPLETE_SHIFT)) & DCP_CH0STAT_SET_RSVD_COMPLETE_MASK) +#define DCP_CH0STAT_SET_HASH_MISMATCH_MASK (0x2U) +#define DCP_CH0STAT_SET_HASH_MISMATCH_SHIFT (1U) +#define DCP_CH0STAT_SET_HASH_MISMATCH(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_SET_HASH_MISMATCH_SHIFT)) & DCP_CH0STAT_SET_HASH_MISMATCH_MASK) +#define DCP_CH0STAT_SET_ERROR_SETUP_MASK (0x4U) +#define DCP_CH0STAT_SET_ERROR_SETUP_SHIFT (2U) +#define DCP_CH0STAT_SET_ERROR_SETUP(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_SET_ERROR_SETUP_SHIFT)) & DCP_CH0STAT_SET_ERROR_SETUP_MASK) +#define DCP_CH0STAT_SET_ERROR_PACKET_MASK (0x8U) +#define DCP_CH0STAT_SET_ERROR_PACKET_SHIFT (3U) +#define DCP_CH0STAT_SET_ERROR_PACKET(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_SET_ERROR_PACKET_SHIFT)) & DCP_CH0STAT_SET_ERROR_PACKET_MASK) +#define DCP_CH0STAT_SET_ERROR_SRC_MASK (0x10U) +#define DCP_CH0STAT_SET_ERROR_SRC_SHIFT (4U) +#define DCP_CH0STAT_SET_ERROR_SRC(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_SET_ERROR_SRC_SHIFT)) & DCP_CH0STAT_SET_ERROR_SRC_MASK) +#define DCP_CH0STAT_SET_ERROR_DST_MASK (0x20U) +#define DCP_CH0STAT_SET_ERROR_DST_SHIFT (5U) +#define DCP_CH0STAT_SET_ERROR_DST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_SET_ERROR_DST_SHIFT)) & DCP_CH0STAT_SET_ERROR_DST_MASK) +#define DCP_CH0STAT_SET_ERROR_PAGEFAULT_MASK (0x40U) +#define DCP_CH0STAT_SET_ERROR_PAGEFAULT_SHIFT (6U) +#define DCP_CH0STAT_SET_ERROR_PAGEFAULT(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_SET_ERROR_PAGEFAULT_SHIFT)) & DCP_CH0STAT_SET_ERROR_PAGEFAULT_MASK) +#define DCP_CH0STAT_SET_ERROR_CODE_MASK (0xFF0000U) +#define DCP_CH0STAT_SET_ERROR_CODE_SHIFT (16U) +/*! ERROR_CODE + * 0b00000001..Error signalled because the next pointer is 0x00000000 + * 0b00000010..Error signalled because the semaphore is non-zero and neither chain bit is set + * 0b00000011..Error signalled because an error is reported reading/writing the context buffer + * 0b00000100..Error signalled because an error is reported reading/writing the payload + * 0b00000101..Error signalled because the control packet specifies an invalid mode select (for instance, blit + hash) + */ +#define DCP_CH0STAT_SET_ERROR_CODE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_SET_ERROR_CODE_SHIFT)) & DCP_CH0STAT_SET_ERROR_CODE_MASK) +#define DCP_CH0STAT_SET_TAG_MASK (0xFF000000U) +#define DCP_CH0STAT_SET_TAG_SHIFT (24U) +#define DCP_CH0STAT_SET_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_SET_TAG_SHIFT)) & DCP_CH0STAT_SET_TAG_MASK) +/*! @} */ + +/*! @name CH0STAT_CLR - DCP channel 0 status register */ +/*! @{ */ +#define DCP_CH0STAT_CLR_RSVD_COMPLETE_MASK (0x1U) +#define DCP_CH0STAT_CLR_RSVD_COMPLETE_SHIFT (0U) +#define DCP_CH0STAT_CLR_RSVD_COMPLETE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_CLR_RSVD_COMPLETE_SHIFT)) & DCP_CH0STAT_CLR_RSVD_COMPLETE_MASK) +#define DCP_CH0STAT_CLR_HASH_MISMATCH_MASK (0x2U) +#define DCP_CH0STAT_CLR_HASH_MISMATCH_SHIFT (1U) +#define DCP_CH0STAT_CLR_HASH_MISMATCH(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_CLR_HASH_MISMATCH_SHIFT)) & DCP_CH0STAT_CLR_HASH_MISMATCH_MASK) +#define DCP_CH0STAT_CLR_ERROR_SETUP_MASK (0x4U) +#define DCP_CH0STAT_CLR_ERROR_SETUP_SHIFT (2U) +#define DCP_CH0STAT_CLR_ERROR_SETUP(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_CLR_ERROR_SETUP_SHIFT)) & DCP_CH0STAT_CLR_ERROR_SETUP_MASK) +#define DCP_CH0STAT_CLR_ERROR_PACKET_MASK (0x8U) +#define DCP_CH0STAT_CLR_ERROR_PACKET_SHIFT (3U) +#define DCP_CH0STAT_CLR_ERROR_PACKET(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_CLR_ERROR_PACKET_SHIFT)) & DCP_CH0STAT_CLR_ERROR_PACKET_MASK) +#define DCP_CH0STAT_CLR_ERROR_SRC_MASK (0x10U) +#define DCP_CH0STAT_CLR_ERROR_SRC_SHIFT (4U) +#define DCP_CH0STAT_CLR_ERROR_SRC(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_CLR_ERROR_SRC_SHIFT)) & DCP_CH0STAT_CLR_ERROR_SRC_MASK) +#define DCP_CH0STAT_CLR_ERROR_DST_MASK (0x20U) +#define DCP_CH0STAT_CLR_ERROR_DST_SHIFT (5U) +#define DCP_CH0STAT_CLR_ERROR_DST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_CLR_ERROR_DST_SHIFT)) & DCP_CH0STAT_CLR_ERROR_DST_MASK) +#define DCP_CH0STAT_CLR_ERROR_PAGEFAULT_MASK (0x40U) +#define DCP_CH0STAT_CLR_ERROR_PAGEFAULT_SHIFT (6U) +#define DCP_CH0STAT_CLR_ERROR_PAGEFAULT(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_CLR_ERROR_PAGEFAULT_SHIFT)) & DCP_CH0STAT_CLR_ERROR_PAGEFAULT_MASK) +#define DCP_CH0STAT_CLR_ERROR_CODE_MASK (0xFF0000U) +#define DCP_CH0STAT_CLR_ERROR_CODE_SHIFT (16U) +/*! ERROR_CODE + * 0b00000001..Error signalled because the next pointer is 0x00000000 + * 0b00000010..Error signalled because the semaphore is non-zero and neither chain bit is set + * 0b00000011..Error signalled because an error is reported reading/writing the context buffer + * 0b00000100..Error signalled because an error is reported reading/writing the payload + * 0b00000101..Error signalled because the control packet specifies an invalid mode select (for instance, blit + hash) + */ +#define DCP_CH0STAT_CLR_ERROR_CODE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_CLR_ERROR_CODE_SHIFT)) & DCP_CH0STAT_CLR_ERROR_CODE_MASK) +#define DCP_CH0STAT_CLR_TAG_MASK (0xFF000000U) +#define DCP_CH0STAT_CLR_TAG_SHIFT (24U) +#define DCP_CH0STAT_CLR_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_CLR_TAG_SHIFT)) & DCP_CH0STAT_CLR_TAG_MASK) +/*! @} */ + +/*! @name CH0STAT_TOG - DCP channel 0 status register */ +/*! @{ */ +#define DCP_CH0STAT_TOG_RSVD_COMPLETE_MASK (0x1U) +#define DCP_CH0STAT_TOG_RSVD_COMPLETE_SHIFT (0U) +#define DCP_CH0STAT_TOG_RSVD_COMPLETE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_TOG_RSVD_COMPLETE_SHIFT)) & DCP_CH0STAT_TOG_RSVD_COMPLETE_MASK) +#define DCP_CH0STAT_TOG_HASH_MISMATCH_MASK (0x2U) +#define DCP_CH0STAT_TOG_HASH_MISMATCH_SHIFT (1U) +#define DCP_CH0STAT_TOG_HASH_MISMATCH(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_TOG_HASH_MISMATCH_SHIFT)) & DCP_CH0STAT_TOG_HASH_MISMATCH_MASK) +#define DCP_CH0STAT_TOG_ERROR_SETUP_MASK (0x4U) +#define DCP_CH0STAT_TOG_ERROR_SETUP_SHIFT (2U) +#define DCP_CH0STAT_TOG_ERROR_SETUP(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_TOG_ERROR_SETUP_SHIFT)) & DCP_CH0STAT_TOG_ERROR_SETUP_MASK) +#define DCP_CH0STAT_TOG_ERROR_PACKET_MASK (0x8U) +#define DCP_CH0STAT_TOG_ERROR_PACKET_SHIFT (3U) +#define DCP_CH0STAT_TOG_ERROR_PACKET(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_TOG_ERROR_PACKET_SHIFT)) & DCP_CH0STAT_TOG_ERROR_PACKET_MASK) +#define DCP_CH0STAT_TOG_ERROR_SRC_MASK (0x10U) +#define DCP_CH0STAT_TOG_ERROR_SRC_SHIFT (4U) +#define DCP_CH0STAT_TOG_ERROR_SRC(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_TOG_ERROR_SRC_SHIFT)) & DCP_CH0STAT_TOG_ERROR_SRC_MASK) +#define DCP_CH0STAT_TOG_ERROR_DST_MASK (0x20U) +#define DCP_CH0STAT_TOG_ERROR_DST_SHIFT (5U) +#define DCP_CH0STAT_TOG_ERROR_DST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_TOG_ERROR_DST_SHIFT)) & DCP_CH0STAT_TOG_ERROR_DST_MASK) +#define DCP_CH0STAT_TOG_ERROR_PAGEFAULT_MASK (0x40U) +#define DCP_CH0STAT_TOG_ERROR_PAGEFAULT_SHIFT (6U) +#define DCP_CH0STAT_TOG_ERROR_PAGEFAULT(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_TOG_ERROR_PAGEFAULT_SHIFT)) & DCP_CH0STAT_TOG_ERROR_PAGEFAULT_MASK) +#define DCP_CH0STAT_TOG_ERROR_CODE_MASK (0xFF0000U) +#define DCP_CH0STAT_TOG_ERROR_CODE_SHIFT (16U) +/*! ERROR_CODE + * 0b00000001..Error signalled because the next pointer is 0x00000000 + * 0b00000010..Error signalled because the semaphore is non-zero and neither chain bit is set + * 0b00000011..Error signalled because an error is reported reading/writing the context buffer + * 0b00000100..Error signalled because an error is reported reading/writing the payload + * 0b00000101..Error signalled because the control packet specifies an invalid mode select (for instance, blit + hash) + */ +#define DCP_CH0STAT_TOG_ERROR_CODE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_TOG_ERROR_CODE_SHIFT)) & DCP_CH0STAT_TOG_ERROR_CODE_MASK) +#define DCP_CH0STAT_TOG_TAG_MASK (0xFF000000U) +#define DCP_CH0STAT_TOG_TAG_SHIFT (24U) +#define DCP_CH0STAT_TOG_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0STAT_TOG_TAG_SHIFT)) & DCP_CH0STAT_TOG_TAG_MASK) +/*! @} */ + /*! @name CH0OPTS - DCP channel 0 options register */ /*! @{ */ #define DCP_CH0OPTS_RECOVERY_TIMER_MASK (0xFFFFU) @@ -10026,6 +10478,36 @@ typedef struct { #define DCP_CH0OPTS_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0OPTS_RSVD_SHIFT)) & DCP_CH0OPTS_RSVD_MASK) /*! @} */ +/*! @name CH0OPTS_SET - DCP channel 0 options register */ +/*! @{ */ +#define DCP_CH0OPTS_SET_RECOVERY_TIMER_MASK (0xFFFFU) +#define DCP_CH0OPTS_SET_RECOVERY_TIMER_SHIFT (0U) +#define DCP_CH0OPTS_SET_RECOVERY_TIMER(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0OPTS_SET_RECOVERY_TIMER_SHIFT)) & DCP_CH0OPTS_SET_RECOVERY_TIMER_MASK) +#define DCP_CH0OPTS_SET_RSVD_MASK (0xFFFF0000U) +#define DCP_CH0OPTS_SET_RSVD_SHIFT (16U) +#define DCP_CH0OPTS_SET_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0OPTS_SET_RSVD_SHIFT)) & DCP_CH0OPTS_SET_RSVD_MASK) +/*! @} */ + +/*! @name CH0OPTS_CLR - DCP channel 0 options register */ +/*! @{ */ +#define DCP_CH0OPTS_CLR_RECOVERY_TIMER_MASK (0xFFFFU) +#define DCP_CH0OPTS_CLR_RECOVERY_TIMER_SHIFT (0U) +#define DCP_CH0OPTS_CLR_RECOVERY_TIMER(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0OPTS_CLR_RECOVERY_TIMER_SHIFT)) & DCP_CH0OPTS_CLR_RECOVERY_TIMER_MASK) +#define DCP_CH0OPTS_CLR_RSVD_MASK (0xFFFF0000U) +#define DCP_CH0OPTS_CLR_RSVD_SHIFT (16U) +#define DCP_CH0OPTS_CLR_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0OPTS_CLR_RSVD_SHIFT)) & DCP_CH0OPTS_CLR_RSVD_MASK) +/*! @} */ + +/*! @name CH0OPTS_TOG - DCP channel 0 options register */ +/*! @{ */ +#define DCP_CH0OPTS_TOG_RECOVERY_TIMER_MASK (0xFFFFU) +#define DCP_CH0OPTS_TOG_RECOVERY_TIMER_SHIFT (0U) +#define DCP_CH0OPTS_TOG_RECOVERY_TIMER(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0OPTS_TOG_RECOVERY_TIMER_SHIFT)) & DCP_CH0OPTS_TOG_RECOVERY_TIMER_MASK) +#define DCP_CH0OPTS_TOG_RSVD_MASK (0xFFFF0000U) +#define DCP_CH0OPTS_TOG_RSVD_SHIFT (16U) +#define DCP_CH0OPTS_TOG_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH0OPTS_TOG_RSVD_SHIFT)) & DCP_CH0OPTS_TOG_RSVD_MASK) +/*! @} */ + /*! @name CH1CMDPTR - DCP channel 1 command pointer address register */ /*! @{ */ #define DCP_CH1CMDPTR_ADDR_MASK (0xFFFFFFFFU) @@ -10081,6 +10563,120 @@ typedef struct { #define DCP_CH1STAT_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_TAG_SHIFT)) & DCP_CH1STAT_TAG_MASK) /*! @} */ +/*! @name CH1STAT_SET - DCP channel 1 status register */ +/*! @{ */ +#define DCP_CH1STAT_SET_RSVD_COMPLETE_MASK (0x1U) +#define DCP_CH1STAT_SET_RSVD_COMPLETE_SHIFT (0U) +#define DCP_CH1STAT_SET_RSVD_COMPLETE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_SET_RSVD_COMPLETE_SHIFT)) & DCP_CH1STAT_SET_RSVD_COMPLETE_MASK) +#define DCP_CH1STAT_SET_HASH_MISMATCH_MASK (0x2U) +#define DCP_CH1STAT_SET_HASH_MISMATCH_SHIFT (1U) +#define DCP_CH1STAT_SET_HASH_MISMATCH(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_SET_HASH_MISMATCH_SHIFT)) & DCP_CH1STAT_SET_HASH_MISMATCH_MASK) +#define DCP_CH1STAT_SET_ERROR_SETUP_MASK (0x4U) +#define DCP_CH1STAT_SET_ERROR_SETUP_SHIFT (2U) +#define DCP_CH1STAT_SET_ERROR_SETUP(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_SET_ERROR_SETUP_SHIFT)) & DCP_CH1STAT_SET_ERROR_SETUP_MASK) +#define DCP_CH1STAT_SET_ERROR_PACKET_MASK (0x8U) +#define DCP_CH1STAT_SET_ERROR_PACKET_SHIFT (3U) +#define DCP_CH1STAT_SET_ERROR_PACKET(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_SET_ERROR_PACKET_SHIFT)) & DCP_CH1STAT_SET_ERROR_PACKET_MASK) +#define DCP_CH1STAT_SET_ERROR_SRC_MASK (0x10U) +#define DCP_CH1STAT_SET_ERROR_SRC_SHIFT (4U) +#define DCP_CH1STAT_SET_ERROR_SRC(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_SET_ERROR_SRC_SHIFT)) & DCP_CH1STAT_SET_ERROR_SRC_MASK) +#define DCP_CH1STAT_SET_ERROR_DST_MASK (0x20U) +#define DCP_CH1STAT_SET_ERROR_DST_SHIFT (5U) +#define DCP_CH1STAT_SET_ERROR_DST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_SET_ERROR_DST_SHIFT)) & DCP_CH1STAT_SET_ERROR_DST_MASK) +#define DCP_CH1STAT_SET_ERROR_PAGEFAULT_MASK (0x40U) +#define DCP_CH1STAT_SET_ERROR_PAGEFAULT_SHIFT (6U) +#define DCP_CH1STAT_SET_ERROR_PAGEFAULT(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_SET_ERROR_PAGEFAULT_SHIFT)) & DCP_CH1STAT_SET_ERROR_PAGEFAULT_MASK) +#define DCP_CH1STAT_SET_ERROR_CODE_MASK (0xFF0000U) +#define DCP_CH1STAT_SET_ERROR_CODE_SHIFT (16U) +/*! ERROR_CODE + * 0b00000001..Error is signalled because the next pointer is 0x00000000. + * 0b00000010..Error is signalled because the semaphore is of a non-zero value and neither of the chain bits is set. + * 0b00000011..Error is signalled because an error was reported when reading/writing the context buffer. + * 0b00000100..Error is signalled because an error was reported when reading/writing the payload. + * 0b00000101..Error is signalled because the control packet specifies an invalid mode select (for example, blit + hash). + */ +#define DCP_CH1STAT_SET_ERROR_CODE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_SET_ERROR_CODE_SHIFT)) & DCP_CH1STAT_SET_ERROR_CODE_MASK) +#define DCP_CH1STAT_SET_TAG_MASK (0xFF000000U) +#define DCP_CH1STAT_SET_TAG_SHIFT (24U) +#define DCP_CH1STAT_SET_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_SET_TAG_SHIFT)) & DCP_CH1STAT_SET_TAG_MASK) +/*! @} */ + +/*! @name CH1STAT_CLR - DCP channel 1 status register */ +/*! @{ */ +#define DCP_CH1STAT_CLR_RSVD_COMPLETE_MASK (0x1U) +#define DCP_CH1STAT_CLR_RSVD_COMPLETE_SHIFT (0U) +#define DCP_CH1STAT_CLR_RSVD_COMPLETE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_CLR_RSVD_COMPLETE_SHIFT)) & DCP_CH1STAT_CLR_RSVD_COMPLETE_MASK) +#define DCP_CH1STAT_CLR_HASH_MISMATCH_MASK (0x2U) +#define DCP_CH1STAT_CLR_HASH_MISMATCH_SHIFT (1U) +#define DCP_CH1STAT_CLR_HASH_MISMATCH(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_CLR_HASH_MISMATCH_SHIFT)) & DCP_CH1STAT_CLR_HASH_MISMATCH_MASK) +#define DCP_CH1STAT_CLR_ERROR_SETUP_MASK (0x4U) +#define DCP_CH1STAT_CLR_ERROR_SETUP_SHIFT (2U) +#define DCP_CH1STAT_CLR_ERROR_SETUP(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_CLR_ERROR_SETUP_SHIFT)) & DCP_CH1STAT_CLR_ERROR_SETUP_MASK) +#define DCP_CH1STAT_CLR_ERROR_PACKET_MASK (0x8U) +#define DCP_CH1STAT_CLR_ERROR_PACKET_SHIFT (3U) +#define DCP_CH1STAT_CLR_ERROR_PACKET(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_CLR_ERROR_PACKET_SHIFT)) & DCP_CH1STAT_CLR_ERROR_PACKET_MASK) +#define DCP_CH1STAT_CLR_ERROR_SRC_MASK (0x10U) +#define DCP_CH1STAT_CLR_ERROR_SRC_SHIFT (4U) +#define DCP_CH1STAT_CLR_ERROR_SRC(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_CLR_ERROR_SRC_SHIFT)) & DCP_CH1STAT_CLR_ERROR_SRC_MASK) +#define DCP_CH1STAT_CLR_ERROR_DST_MASK (0x20U) +#define DCP_CH1STAT_CLR_ERROR_DST_SHIFT (5U) +#define DCP_CH1STAT_CLR_ERROR_DST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_CLR_ERROR_DST_SHIFT)) & DCP_CH1STAT_CLR_ERROR_DST_MASK) +#define DCP_CH1STAT_CLR_ERROR_PAGEFAULT_MASK (0x40U) +#define DCP_CH1STAT_CLR_ERROR_PAGEFAULT_SHIFT (6U) +#define DCP_CH1STAT_CLR_ERROR_PAGEFAULT(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_CLR_ERROR_PAGEFAULT_SHIFT)) & DCP_CH1STAT_CLR_ERROR_PAGEFAULT_MASK) +#define DCP_CH1STAT_CLR_ERROR_CODE_MASK (0xFF0000U) +#define DCP_CH1STAT_CLR_ERROR_CODE_SHIFT (16U) +/*! ERROR_CODE + * 0b00000001..Error is signalled because the next pointer is 0x00000000. + * 0b00000010..Error is signalled because the semaphore is of a non-zero value and neither of the chain bits is set. + * 0b00000011..Error is signalled because an error was reported when reading/writing the context buffer. + * 0b00000100..Error is signalled because an error was reported when reading/writing the payload. + * 0b00000101..Error is signalled because the control packet specifies an invalid mode select (for example, blit + hash). + */ +#define DCP_CH1STAT_CLR_ERROR_CODE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_CLR_ERROR_CODE_SHIFT)) & DCP_CH1STAT_CLR_ERROR_CODE_MASK) +#define DCP_CH1STAT_CLR_TAG_MASK (0xFF000000U) +#define DCP_CH1STAT_CLR_TAG_SHIFT (24U) +#define DCP_CH1STAT_CLR_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_CLR_TAG_SHIFT)) & DCP_CH1STAT_CLR_TAG_MASK) +/*! @} */ + +/*! @name CH1STAT_TOG - DCP channel 1 status register */ +/*! @{ */ +#define DCP_CH1STAT_TOG_RSVD_COMPLETE_MASK (0x1U) +#define DCP_CH1STAT_TOG_RSVD_COMPLETE_SHIFT (0U) +#define DCP_CH1STAT_TOG_RSVD_COMPLETE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_TOG_RSVD_COMPLETE_SHIFT)) & DCP_CH1STAT_TOG_RSVD_COMPLETE_MASK) +#define DCP_CH1STAT_TOG_HASH_MISMATCH_MASK (0x2U) +#define DCP_CH1STAT_TOG_HASH_MISMATCH_SHIFT (1U) +#define DCP_CH1STAT_TOG_HASH_MISMATCH(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_TOG_HASH_MISMATCH_SHIFT)) & DCP_CH1STAT_TOG_HASH_MISMATCH_MASK) +#define DCP_CH1STAT_TOG_ERROR_SETUP_MASK (0x4U) +#define DCP_CH1STAT_TOG_ERROR_SETUP_SHIFT (2U) +#define DCP_CH1STAT_TOG_ERROR_SETUP(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_TOG_ERROR_SETUP_SHIFT)) & DCP_CH1STAT_TOG_ERROR_SETUP_MASK) +#define DCP_CH1STAT_TOG_ERROR_PACKET_MASK (0x8U) +#define DCP_CH1STAT_TOG_ERROR_PACKET_SHIFT (3U) +#define DCP_CH1STAT_TOG_ERROR_PACKET(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_TOG_ERROR_PACKET_SHIFT)) & DCP_CH1STAT_TOG_ERROR_PACKET_MASK) +#define DCP_CH1STAT_TOG_ERROR_SRC_MASK (0x10U) +#define DCP_CH1STAT_TOG_ERROR_SRC_SHIFT (4U) +#define DCP_CH1STAT_TOG_ERROR_SRC(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_TOG_ERROR_SRC_SHIFT)) & DCP_CH1STAT_TOG_ERROR_SRC_MASK) +#define DCP_CH1STAT_TOG_ERROR_DST_MASK (0x20U) +#define DCP_CH1STAT_TOG_ERROR_DST_SHIFT (5U) +#define DCP_CH1STAT_TOG_ERROR_DST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_TOG_ERROR_DST_SHIFT)) & DCP_CH1STAT_TOG_ERROR_DST_MASK) +#define DCP_CH1STAT_TOG_ERROR_PAGEFAULT_MASK (0x40U) +#define DCP_CH1STAT_TOG_ERROR_PAGEFAULT_SHIFT (6U) +#define DCP_CH1STAT_TOG_ERROR_PAGEFAULT(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_TOG_ERROR_PAGEFAULT_SHIFT)) & DCP_CH1STAT_TOG_ERROR_PAGEFAULT_MASK) +#define DCP_CH1STAT_TOG_ERROR_CODE_MASK (0xFF0000U) +#define DCP_CH1STAT_TOG_ERROR_CODE_SHIFT (16U) +/*! ERROR_CODE + * 0b00000001..Error is signalled because the next pointer is 0x00000000. + * 0b00000010..Error is signalled because the semaphore is of a non-zero value and neither of the chain bits is set. + * 0b00000011..Error is signalled because an error was reported when reading/writing the context buffer. + * 0b00000100..Error is signalled because an error was reported when reading/writing the payload. + * 0b00000101..Error is signalled because the control packet specifies an invalid mode select (for example, blit + hash). + */ +#define DCP_CH1STAT_TOG_ERROR_CODE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_TOG_ERROR_CODE_SHIFT)) & DCP_CH1STAT_TOG_ERROR_CODE_MASK) +#define DCP_CH1STAT_TOG_TAG_MASK (0xFF000000U) +#define DCP_CH1STAT_TOG_TAG_SHIFT (24U) +#define DCP_CH1STAT_TOG_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1STAT_TOG_TAG_SHIFT)) & DCP_CH1STAT_TOG_TAG_MASK) +/*! @} */ + /*! @name CH1OPTS - DCP channel 1 options register */ /*! @{ */ #define DCP_CH1OPTS_RECOVERY_TIMER_MASK (0xFFFFU) @@ -10091,6 +10687,36 @@ typedef struct { #define DCP_CH1OPTS_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1OPTS_RSVD_SHIFT)) & DCP_CH1OPTS_RSVD_MASK) /*! @} */ +/*! @name CH1OPTS_SET - DCP channel 1 options register */ +/*! @{ */ +#define DCP_CH1OPTS_SET_RECOVERY_TIMER_MASK (0xFFFFU) +#define DCP_CH1OPTS_SET_RECOVERY_TIMER_SHIFT (0U) +#define DCP_CH1OPTS_SET_RECOVERY_TIMER(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1OPTS_SET_RECOVERY_TIMER_SHIFT)) & DCP_CH1OPTS_SET_RECOVERY_TIMER_MASK) +#define DCP_CH1OPTS_SET_RSVD_MASK (0xFFFF0000U) +#define DCP_CH1OPTS_SET_RSVD_SHIFT (16U) +#define DCP_CH1OPTS_SET_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1OPTS_SET_RSVD_SHIFT)) & DCP_CH1OPTS_SET_RSVD_MASK) +/*! @} */ + +/*! @name CH1OPTS_CLR - DCP channel 1 options register */ +/*! @{ */ +#define DCP_CH1OPTS_CLR_RECOVERY_TIMER_MASK (0xFFFFU) +#define DCP_CH1OPTS_CLR_RECOVERY_TIMER_SHIFT (0U) +#define DCP_CH1OPTS_CLR_RECOVERY_TIMER(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1OPTS_CLR_RECOVERY_TIMER_SHIFT)) & DCP_CH1OPTS_CLR_RECOVERY_TIMER_MASK) +#define DCP_CH1OPTS_CLR_RSVD_MASK (0xFFFF0000U) +#define DCP_CH1OPTS_CLR_RSVD_SHIFT (16U) +#define DCP_CH1OPTS_CLR_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1OPTS_CLR_RSVD_SHIFT)) & DCP_CH1OPTS_CLR_RSVD_MASK) +/*! @} */ + +/*! @name CH1OPTS_TOG - DCP channel 1 options register */ +/*! @{ */ +#define DCP_CH1OPTS_TOG_RECOVERY_TIMER_MASK (0xFFFFU) +#define DCP_CH1OPTS_TOG_RECOVERY_TIMER_SHIFT (0U) +#define DCP_CH1OPTS_TOG_RECOVERY_TIMER(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1OPTS_TOG_RECOVERY_TIMER_SHIFT)) & DCP_CH1OPTS_TOG_RECOVERY_TIMER_MASK) +#define DCP_CH1OPTS_TOG_RSVD_MASK (0xFFFF0000U) +#define DCP_CH1OPTS_TOG_RSVD_SHIFT (16U) +#define DCP_CH1OPTS_TOG_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH1OPTS_TOG_RSVD_SHIFT)) & DCP_CH1OPTS_TOG_RSVD_MASK) +/*! @} */ + /*! @name CH2CMDPTR - DCP channel 2 command pointer address register */ /*! @{ */ #define DCP_CH2CMDPTR_ADDR_MASK (0xFFFFFFFFU) @@ -10146,6 +10772,120 @@ typedef struct { #define DCP_CH2STAT_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_TAG_SHIFT)) & DCP_CH2STAT_TAG_MASK) /*! @} */ +/*! @name CH2STAT_SET - DCP channel 2 status register */ +/*! @{ */ +#define DCP_CH2STAT_SET_RSVD_COMPLETE_MASK (0x1U) +#define DCP_CH2STAT_SET_RSVD_COMPLETE_SHIFT (0U) +#define DCP_CH2STAT_SET_RSVD_COMPLETE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_SET_RSVD_COMPLETE_SHIFT)) & DCP_CH2STAT_SET_RSVD_COMPLETE_MASK) +#define DCP_CH2STAT_SET_HASH_MISMATCH_MASK (0x2U) +#define DCP_CH2STAT_SET_HASH_MISMATCH_SHIFT (1U) +#define DCP_CH2STAT_SET_HASH_MISMATCH(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_SET_HASH_MISMATCH_SHIFT)) & DCP_CH2STAT_SET_HASH_MISMATCH_MASK) +#define DCP_CH2STAT_SET_ERROR_SETUP_MASK (0x4U) +#define DCP_CH2STAT_SET_ERROR_SETUP_SHIFT (2U) +#define DCP_CH2STAT_SET_ERROR_SETUP(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_SET_ERROR_SETUP_SHIFT)) & DCP_CH2STAT_SET_ERROR_SETUP_MASK) +#define DCP_CH2STAT_SET_ERROR_PACKET_MASK (0x8U) +#define DCP_CH2STAT_SET_ERROR_PACKET_SHIFT (3U) +#define DCP_CH2STAT_SET_ERROR_PACKET(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_SET_ERROR_PACKET_SHIFT)) & DCP_CH2STAT_SET_ERROR_PACKET_MASK) +#define DCP_CH2STAT_SET_ERROR_SRC_MASK (0x10U) +#define DCP_CH2STAT_SET_ERROR_SRC_SHIFT (4U) +#define DCP_CH2STAT_SET_ERROR_SRC(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_SET_ERROR_SRC_SHIFT)) & DCP_CH2STAT_SET_ERROR_SRC_MASK) +#define DCP_CH2STAT_SET_ERROR_DST_MASK (0x20U) +#define DCP_CH2STAT_SET_ERROR_DST_SHIFT (5U) +#define DCP_CH2STAT_SET_ERROR_DST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_SET_ERROR_DST_SHIFT)) & DCP_CH2STAT_SET_ERROR_DST_MASK) +#define DCP_CH2STAT_SET_ERROR_PAGEFAULT_MASK (0x40U) +#define DCP_CH2STAT_SET_ERROR_PAGEFAULT_SHIFT (6U) +#define DCP_CH2STAT_SET_ERROR_PAGEFAULT(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_SET_ERROR_PAGEFAULT_SHIFT)) & DCP_CH2STAT_SET_ERROR_PAGEFAULT_MASK) +#define DCP_CH2STAT_SET_ERROR_CODE_MASK (0xFF0000U) +#define DCP_CH2STAT_SET_ERROR_CODE_SHIFT (16U) +/*! ERROR_CODE + * 0b00000001..Error is signalled because the next pointer is 0x00000000. + * 0b00000010..Error is signalled because the semaphore is of a non-zero value and neither of the chain bits is set. + * 0b00000011..Error is signalled because an error was reported while reading/writing the context buffer. + * 0b00000100..Error is signalled because an error was reported while reading/writing the payload. + * 0b00000101..Error is signalled because the control packet specifies an invalid mode select (for instance, blit + hash). + */ +#define DCP_CH2STAT_SET_ERROR_CODE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_SET_ERROR_CODE_SHIFT)) & DCP_CH2STAT_SET_ERROR_CODE_MASK) +#define DCP_CH2STAT_SET_TAG_MASK (0xFF000000U) +#define DCP_CH2STAT_SET_TAG_SHIFT (24U) +#define DCP_CH2STAT_SET_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_SET_TAG_SHIFT)) & DCP_CH2STAT_SET_TAG_MASK) +/*! @} */ + +/*! @name CH2STAT_CLR - DCP channel 2 status register */ +/*! @{ */ +#define DCP_CH2STAT_CLR_RSVD_COMPLETE_MASK (0x1U) +#define DCP_CH2STAT_CLR_RSVD_COMPLETE_SHIFT (0U) +#define DCP_CH2STAT_CLR_RSVD_COMPLETE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_CLR_RSVD_COMPLETE_SHIFT)) & DCP_CH2STAT_CLR_RSVD_COMPLETE_MASK) +#define DCP_CH2STAT_CLR_HASH_MISMATCH_MASK (0x2U) +#define DCP_CH2STAT_CLR_HASH_MISMATCH_SHIFT (1U) +#define DCP_CH2STAT_CLR_HASH_MISMATCH(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_CLR_HASH_MISMATCH_SHIFT)) & DCP_CH2STAT_CLR_HASH_MISMATCH_MASK) +#define DCP_CH2STAT_CLR_ERROR_SETUP_MASK (0x4U) +#define DCP_CH2STAT_CLR_ERROR_SETUP_SHIFT (2U) +#define DCP_CH2STAT_CLR_ERROR_SETUP(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_CLR_ERROR_SETUP_SHIFT)) & DCP_CH2STAT_CLR_ERROR_SETUP_MASK) +#define DCP_CH2STAT_CLR_ERROR_PACKET_MASK (0x8U) +#define DCP_CH2STAT_CLR_ERROR_PACKET_SHIFT (3U) +#define DCP_CH2STAT_CLR_ERROR_PACKET(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_CLR_ERROR_PACKET_SHIFT)) & DCP_CH2STAT_CLR_ERROR_PACKET_MASK) +#define DCP_CH2STAT_CLR_ERROR_SRC_MASK (0x10U) +#define DCP_CH2STAT_CLR_ERROR_SRC_SHIFT (4U) +#define DCP_CH2STAT_CLR_ERROR_SRC(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_CLR_ERROR_SRC_SHIFT)) & DCP_CH2STAT_CLR_ERROR_SRC_MASK) +#define DCP_CH2STAT_CLR_ERROR_DST_MASK (0x20U) +#define DCP_CH2STAT_CLR_ERROR_DST_SHIFT (5U) +#define DCP_CH2STAT_CLR_ERROR_DST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_CLR_ERROR_DST_SHIFT)) & DCP_CH2STAT_CLR_ERROR_DST_MASK) +#define DCP_CH2STAT_CLR_ERROR_PAGEFAULT_MASK (0x40U) +#define DCP_CH2STAT_CLR_ERROR_PAGEFAULT_SHIFT (6U) +#define DCP_CH2STAT_CLR_ERROR_PAGEFAULT(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_CLR_ERROR_PAGEFAULT_SHIFT)) & DCP_CH2STAT_CLR_ERROR_PAGEFAULT_MASK) +#define DCP_CH2STAT_CLR_ERROR_CODE_MASK (0xFF0000U) +#define DCP_CH2STAT_CLR_ERROR_CODE_SHIFT (16U) +/*! ERROR_CODE + * 0b00000001..Error is signalled because the next pointer is 0x00000000. + * 0b00000010..Error is signalled because the semaphore is of a non-zero value and neither of the chain bits is set. + * 0b00000011..Error is signalled because an error was reported while reading/writing the context buffer. + * 0b00000100..Error is signalled because an error was reported while reading/writing the payload. + * 0b00000101..Error is signalled because the control packet specifies an invalid mode select (for instance, blit + hash). + */ +#define DCP_CH2STAT_CLR_ERROR_CODE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_CLR_ERROR_CODE_SHIFT)) & DCP_CH2STAT_CLR_ERROR_CODE_MASK) +#define DCP_CH2STAT_CLR_TAG_MASK (0xFF000000U) +#define DCP_CH2STAT_CLR_TAG_SHIFT (24U) +#define DCP_CH2STAT_CLR_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_CLR_TAG_SHIFT)) & DCP_CH2STAT_CLR_TAG_MASK) +/*! @} */ + +/*! @name CH2STAT_TOG - DCP channel 2 status register */ +/*! @{ */ +#define DCP_CH2STAT_TOG_RSVD_COMPLETE_MASK (0x1U) +#define DCP_CH2STAT_TOG_RSVD_COMPLETE_SHIFT (0U) +#define DCP_CH2STAT_TOG_RSVD_COMPLETE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_TOG_RSVD_COMPLETE_SHIFT)) & DCP_CH2STAT_TOG_RSVD_COMPLETE_MASK) +#define DCP_CH2STAT_TOG_HASH_MISMATCH_MASK (0x2U) +#define DCP_CH2STAT_TOG_HASH_MISMATCH_SHIFT (1U) +#define DCP_CH2STAT_TOG_HASH_MISMATCH(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_TOG_HASH_MISMATCH_SHIFT)) & DCP_CH2STAT_TOG_HASH_MISMATCH_MASK) +#define DCP_CH2STAT_TOG_ERROR_SETUP_MASK (0x4U) +#define DCP_CH2STAT_TOG_ERROR_SETUP_SHIFT (2U) +#define DCP_CH2STAT_TOG_ERROR_SETUP(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_TOG_ERROR_SETUP_SHIFT)) & DCP_CH2STAT_TOG_ERROR_SETUP_MASK) +#define DCP_CH2STAT_TOG_ERROR_PACKET_MASK (0x8U) +#define DCP_CH2STAT_TOG_ERROR_PACKET_SHIFT (3U) +#define DCP_CH2STAT_TOG_ERROR_PACKET(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_TOG_ERROR_PACKET_SHIFT)) & DCP_CH2STAT_TOG_ERROR_PACKET_MASK) +#define DCP_CH2STAT_TOG_ERROR_SRC_MASK (0x10U) +#define DCP_CH2STAT_TOG_ERROR_SRC_SHIFT (4U) +#define DCP_CH2STAT_TOG_ERROR_SRC(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_TOG_ERROR_SRC_SHIFT)) & DCP_CH2STAT_TOG_ERROR_SRC_MASK) +#define DCP_CH2STAT_TOG_ERROR_DST_MASK (0x20U) +#define DCP_CH2STAT_TOG_ERROR_DST_SHIFT (5U) +#define DCP_CH2STAT_TOG_ERROR_DST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_TOG_ERROR_DST_SHIFT)) & DCP_CH2STAT_TOG_ERROR_DST_MASK) +#define DCP_CH2STAT_TOG_ERROR_PAGEFAULT_MASK (0x40U) +#define DCP_CH2STAT_TOG_ERROR_PAGEFAULT_SHIFT (6U) +#define DCP_CH2STAT_TOG_ERROR_PAGEFAULT(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_TOG_ERROR_PAGEFAULT_SHIFT)) & DCP_CH2STAT_TOG_ERROR_PAGEFAULT_MASK) +#define DCP_CH2STAT_TOG_ERROR_CODE_MASK (0xFF0000U) +#define DCP_CH2STAT_TOG_ERROR_CODE_SHIFT (16U) +/*! ERROR_CODE + * 0b00000001..Error is signalled because the next pointer is 0x00000000. + * 0b00000010..Error is signalled because the semaphore is of a non-zero value and neither of the chain bits is set. + * 0b00000011..Error is signalled because an error was reported while reading/writing the context buffer. + * 0b00000100..Error is signalled because an error was reported while reading/writing the payload. + * 0b00000101..Error is signalled because the control packet specifies an invalid mode select (for instance, blit + hash). + */ +#define DCP_CH2STAT_TOG_ERROR_CODE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_TOG_ERROR_CODE_SHIFT)) & DCP_CH2STAT_TOG_ERROR_CODE_MASK) +#define DCP_CH2STAT_TOG_TAG_MASK (0xFF000000U) +#define DCP_CH2STAT_TOG_TAG_SHIFT (24U) +#define DCP_CH2STAT_TOG_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2STAT_TOG_TAG_SHIFT)) & DCP_CH2STAT_TOG_TAG_MASK) +/*! @} */ + /*! @name CH2OPTS - DCP channel 2 options register */ /*! @{ */ #define DCP_CH2OPTS_RECOVERY_TIMER_MASK (0xFFFFU) @@ -10156,6 +10896,36 @@ typedef struct { #define DCP_CH2OPTS_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2OPTS_RSVD_SHIFT)) & DCP_CH2OPTS_RSVD_MASK) /*! @} */ +/*! @name CH2OPTS_SET - DCP channel 2 options register */ +/*! @{ */ +#define DCP_CH2OPTS_SET_RECOVERY_TIMER_MASK (0xFFFFU) +#define DCP_CH2OPTS_SET_RECOVERY_TIMER_SHIFT (0U) +#define DCP_CH2OPTS_SET_RECOVERY_TIMER(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2OPTS_SET_RECOVERY_TIMER_SHIFT)) & DCP_CH2OPTS_SET_RECOVERY_TIMER_MASK) +#define DCP_CH2OPTS_SET_RSVD_MASK (0xFFFF0000U) +#define DCP_CH2OPTS_SET_RSVD_SHIFT (16U) +#define DCP_CH2OPTS_SET_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2OPTS_SET_RSVD_SHIFT)) & DCP_CH2OPTS_SET_RSVD_MASK) +/*! @} */ + +/*! @name CH2OPTS_CLR - DCP channel 2 options register */ +/*! @{ */ +#define DCP_CH2OPTS_CLR_RECOVERY_TIMER_MASK (0xFFFFU) +#define DCP_CH2OPTS_CLR_RECOVERY_TIMER_SHIFT (0U) +#define DCP_CH2OPTS_CLR_RECOVERY_TIMER(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2OPTS_CLR_RECOVERY_TIMER_SHIFT)) & DCP_CH2OPTS_CLR_RECOVERY_TIMER_MASK) +#define DCP_CH2OPTS_CLR_RSVD_MASK (0xFFFF0000U) +#define DCP_CH2OPTS_CLR_RSVD_SHIFT (16U) +#define DCP_CH2OPTS_CLR_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2OPTS_CLR_RSVD_SHIFT)) & DCP_CH2OPTS_CLR_RSVD_MASK) +/*! @} */ + +/*! @name CH2OPTS_TOG - DCP channel 2 options register */ +/*! @{ */ +#define DCP_CH2OPTS_TOG_RECOVERY_TIMER_MASK (0xFFFFU) +#define DCP_CH2OPTS_TOG_RECOVERY_TIMER_SHIFT (0U) +#define DCP_CH2OPTS_TOG_RECOVERY_TIMER(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2OPTS_TOG_RECOVERY_TIMER_SHIFT)) & DCP_CH2OPTS_TOG_RECOVERY_TIMER_MASK) +#define DCP_CH2OPTS_TOG_RSVD_MASK (0xFFFF0000U) +#define DCP_CH2OPTS_TOG_RSVD_SHIFT (16U) +#define DCP_CH2OPTS_TOG_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH2OPTS_TOG_RSVD_SHIFT)) & DCP_CH2OPTS_TOG_RSVD_MASK) +/*! @} */ + /*! @name CH3CMDPTR - DCP channel 3 command pointer address register */ /*! @{ */ #define DCP_CH3CMDPTR_ADDR_MASK (0xFFFFFFFFU) @@ -10211,6 +10981,120 @@ typedef struct { #define DCP_CH3STAT_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_TAG_SHIFT)) & DCP_CH3STAT_TAG_MASK) /*! @} */ +/*! @name CH3STAT_SET - DCP channel 3 status register */ +/*! @{ */ +#define DCP_CH3STAT_SET_RSVD_COMPLETE_MASK (0x1U) +#define DCP_CH3STAT_SET_RSVD_COMPLETE_SHIFT (0U) +#define DCP_CH3STAT_SET_RSVD_COMPLETE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_SET_RSVD_COMPLETE_SHIFT)) & DCP_CH3STAT_SET_RSVD_COMPLETE_MASK) +#define DCP_CH3STAT_SET_HASH_MISMATCH_MASK (0x2U) +#define DCP_CH3STAT_SET_HASH_MISMATCH_SHIFT (1U) +#define DCP_CH3STAT_SET_HASH_MISMATCH(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_SET_HASH_MISMATCH_SHIFT)) & DCP_CH3STAT_SET_HASH_MISMATCH_MASK) +#define DCP_CH3STAT_SET_ERROR_SETUP_MASK (0x4U) +#define DCP_CH3STAT_SET_ERROR_SETUP_SHIFT (2U) +#define DCP_CH3STAT_SET_ERROR_SETUP(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_SET_ERROR_SETUP_SHIFT)) & DCP_CH3STAT_SET_ERROR_SETUP_MASK) +#define DCP_CH3STAT_SET_ERROR_PACKET_MASK (0x8U) +#define DCP_CH3STAT_SET_ERROR_PACKET_SHIFT (3U) +#define DCP_CH3STAT_SET_ERROR_PACKET(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_SET_ERROR_PACKET_SHIFT)) & DCP_CH3STAT_SET_ERROR_PACKET_MASK) +#define DCP_CH3STAT_SET_ERROR_SRC_MASK (0x10U) +#define DCP_CH3STAT_SET_ERROR_SRC_SHIFT (4U) +#define DCP_CH3STAT_SET_ERROR_SRC(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_SET_ERROR_SRC_SHIFT)) & DCP_CH3STAT_SET_ERROR_SRC_MASK) +#define DCP_CH3STAT_SET_ERROR_DST_MASK (0x20U) +#define DCP_CH3STAT_SET_ERROR_DST_SHIFT (5U) +#define DCP_CH3STAT_SET_ERROR_DST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_SET_ERROR_DST_SHIFT)) & DCP_CH3STAT_SET_ERROR_DST_MASK) +#define DCP_CH3STAT_SET_ERROR_PAGEFAULT_MASK (0x40U) +#define DCP_CH3STAT_SET_ERROR_PAGEFAULT_SHIFT (6U) +#define DCP_CH3STAT_SET_ERROR_PAGEFAULT(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_SET_ERROR_PAGEFAULT_SHIFT)) & DCP_CH3STAT_SET_ERROR_PAGEFAULT_MASK) +#define DCP_CH3STAT_SET_ERROR_CODE_MASK (0xFF0000U) +#define DCP_CH3STAT_SET_ERROR_CODE_SHIFT (16U) +/*! ERROR_CODE + * 0b00000001..Error is signalled because the next pointer is 0x00000000. + * 0b00000010..Error is signalled because the semaphore is of a non-zero value and neither of the chain bits is set. + * 0b00000011..Error is signalled because an error was reported while reading/writing the context buffer. + * 0b00000100..Error is signalled because an error was reported while reading/writing the payload. + * 0b00000101..Error is signalled because the control packet specifies an invalid mode select (for example, blit + hash). + */ +#define DCP_CH3STAT_SET_ERROR_CODE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_SET_ERROR_CODE_SHIFT)) & DCP_CH3STAT_SET_ERROR_CODE_MASK) +#define DCP_CH3STAT_SET_TAG_MASK (0xFF000000U) +#define DCP_CH3STAT_SET_TAG_SHIFT (24U) +#define DCP_CH3STAT_SET_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_SET_TAG_SHIFT)) & DCP_CH3STAT_SET_TAG_MASK) +/*! @} */ + +/*! @name CH3STAT_CLR - DCP channel 3 status register */ +/*! @{ */ +#define DCP_CH3STAT_CLR_RSVD_COMPLETE_MASK (0x1U) +#define DCP_CH3STAT_CLR_RSVD_COMPLETE_SHIFT (0U) +#define DCP_CH3STAT_CLR_RSVD_COMPLETE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_CLR_RSVD_COMPLETE_SHIFT)) & DCP_CH3STAT_CLR_RSVD_COMPLETE_MASK) +#define DCP_CH3STAT_CLR_HASH_MISMATCH_MASK (0x2U) +#define DCP_CH3STAT_CLR_HASH_MISMATCH_SHIFT (1U) +#define DCP_CH3STAT_CLR_HASH_MISMATCH(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_CLR_HASH_MISMATCH_SHIFT)) & DCP_CH3STAT_CLR_HASH_MISMATCH_MASK) +#define DCP_CH3STAT_CLR_ERROR_SETUP_MASK (0x4U) +#define DCP_CH3STAT_CLR_ERROR_SETUP_SHIFT (2U) +#define DCP_CH3STAT_CLR_ERROR_SETUP(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_CLR_ERROR_SETUP_SHIFT)) & DCP_CH3STAT_CLR_ERROR_SETUP_MASK) +#define DCP_CH3STAT_CLR_ERROR_PACKET_MASK (0x8U) +#define DCP_CH3STAT_CLR_ERROR_PACKET_SHIFT (3U) +#define DCP_CH3STAT_CLR_ERROR_PACKET(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_CLR_ERROR_PACKET_SHIFT)) & DCP_CH3STAT_CLR_ERROR_PACKET_MASK) +#define DCP_CH3STAT_CLR_ERROR_SRC_MASK (0x10U) +#define DCP_CH3STAT_CLR_ERROR_SRC_SHIFT (4U) +#define DCP_CH3STAT_CLR_ERROR_SRC(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_CLR_ERROR_SRC_SHIFT)) & DCP_CH3STAT_CLR_ERROR_SRC_MASK) +#define DCP_CH3STAT_CLR_ERROR_DST_MASK (0x20U) +#define DCP_CH3STAT_CLR_ERROR_DST_SHIFT (5U) +#define DCP_CH3STAT_CLR_ERROR_DST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_CLR_ERROR_DST_SHIFT)) & DCP_CH3STAT_CLR_ERROR_DST_MASK) +#define DCP_CH3STAT_CLR_ERROR_PAGEFAULT_MASK (0x40U) +#define DCP_CH3STAT_CLR_ERROR_PAGEFAULT_SHIFT (6U) +#define DCP_CH3STAT_CLR_ERROR_PAGEFAULT(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_CLR_ERROR_PAGEFAULT_SHIFT)) & DCP_CH3STAT_CLR_ERROR_PAGEFAULT_MASK) +#define DCP_CH3STAT_CLR_ERROR_CODE_MASK (0xFF0000U) +#define DCP_CH3STAT_CLR_ERROR_CODE_SHIFT (16U) +/*! ERROR_CODE + * 0b00000001..Error is signalled because the next pointer is 0x00000000. + * 0b00000010..Error is signalled because the semaphore is of a non-zero value and neither of the chain bits is set. + * 0b00000011..Error is signalled because an error was reported while reading/writing the context buffer. + * 0b00000100..Error is signalled because an error was reported while reading/writing the payload. + * 0b00000101..Error is signalled because the control packet specifies an invalid mode select (for example, blit + hash). + */ +#define DCP_CH3STAT_CLR_ERROR_CODE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_CLR_ERROR_CODE_SHIFT)) & DCP_CH3STAT_CLR_ERROR_CODE_MASK) +#define DCP_CH3STAT_CLR_TAG_MASK (0xFF000000U) +#define DCP_CH3STAT_CLR_TAG_SHIFT (24U) +#define DCP_CH3STAT_CLR_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_CLR_TAG_SHIFT)) & DCP_CH3STAT_CLR_TAG_MASK) +/*! @} */ + +/*! @name CH3STAT_TOG - DCP channel 3 status register */ +/*! @{ */ +#define DCP_CH3STAT_TOG_RSVD_COMPLETE_MASK (0x1U) +#define DCP_CH3STAT_TOG_RSVD_COMPLETE_SHIFT (0U) +#define DCP_CH3STAT_TOG_RSVD_COMPLETE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_TOG_RSVD_COMPLETE_SHIFT)) & DCP_CH3STAT_TOG_RSVD_COMPLETE_MASK) +#define DCP_CH3STAT_TOG_HASH_MISMATCH_MASK (0x2U) +#define DCP_CH3STAT_TOG_HASH_MISMATCH_SHIFT (1U) +#define DCP_CH3STAT_TOG_HASH_MISMATCH(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_TOG_HASH_MISMATCH_SHIFT)) & DCP_CH3STAT_TOG_HASH_MISMATCH_MASK) +#define DCP_CH3STAT_TOG_ERROR_SETUP_MASK (0x4U) +#define DCP_CH3STAT_TOG_ERROR_SETUP_SHIFT (2U) +#define DCP_CH3STAT_TOG_ERROR_SETUP(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_TOG_ERROR_SETUP_SHIFT)) & DCP_CH3STAT_TOG_ERROR_SETUP_MASK) +#define DCP_CH3STAT_TOG_ERROR_PACKET_MASK (0x8U) +#define DCP_CH3STAT_TOG_ERROR_PACKET_SHIFT (3U) +#define DCP_CH3STAT_TOG_ERROR_PACKET(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_TOG_ERROR_PACKET_SHIFT)) & DCP_CH3STAT_TOG_ERROR_PACKET_MASK) +#define DCP_CH3STAT_TOG_ERROR_SRC_MASK (0x10U) +#define DCP_CH3STAT_TOG_ERROR_SRC_SHIFT (4U) +#define DCP_CH3STAT_TOG_ERROR_SRC(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_TOG_ERROR_SRC_SHIFT)) & DCP_CH3STAT_TOG_ERROR_SRC_MASK) +#define DCP_CH3STAT_TOG_ERROR_DST_MASK (0x20U) +#define DCP_CH3STAT_TOG_ERROR_DST_SHIFT (5U) +#define DCP_CH3STAT_TOG_ERROR_DST(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_TOG_ERROR_DST_SHIFT)) & DCP_CH3STAT_TOG_ERROR_DST_MASK) +#define DCP_CH3STAT_TOG_ERROR_PAGEFAULT_MASK (0x40U) +#define DCP_CH3STAT_TOG_ERROR_PAGEFAULT_SHIFT (6U) +#define DCP_CH3STAT_TOG_ERROR_PAGEFAULT(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_TOG_ERROR_PAGEFAULT_SHIFT)) & DCP_CH3STAT_TOG_ERROR_PAGEFAULT_MASK) +#define DCP_CH3STAT_TOG_ERROR_CODE_MASK (0xFF0000U) +#define DCP_CH3STAT_TOG_ERROR_CODE_SHIFT (16U) +/*! ERROR_CODE + * 0b00000001..Error is signalled because the next pointer is 0x00000000. + * 0b00000010..Error is signalled because the semaphore is of a non-zero value and neither of the chain bits is set. + * 0b00000011..Error is signalled because an error was reported while reading/writing the context buffer. + * 0b00000100..Error is signalled because an error was reported while reading/writing the payload. + * 0b00000101..Error is signalled because the control packet specifies an invalid mode select (for example, blit + hash). + */ +#define DCP_CH3STAT_TOG_ERROR_CODE(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_TOG_ERROR_CODE_SHIFT)) & DCP_CH3STAT_TOG_ERROR_CODE_MASK) +#define DCP_CH3STAT_TOG_TAG_MASK (0xFF000000U) +#define DCP_CH3STAT_TOG_TAG_SHIFT (24U) +#define DCP_CH3STAT_TOG_TAG(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3STAT_TOG_TAG_SHIFT)) & DCP_CH3STAT_TOG_TAG_MASK) +/*! @} */ + /*! @name CH3OPTS - DCP channel 3 options register */ /*! @{ */ #define DCP_CH3OPTS_RECOVERY_TIMER_MASK (0xFFFFU) @@ -10221,6 +11105,36 @@ typedef struct { #define DCP_CH3OPTS_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3OPTS_RSVD_SHIFT)) & DCP_CH3OPTS_RSVD_MASK) /*! @} */ +/*! @name CH3OPTS_SET - DCP channel 3 options register */ +/*! @{ */ +#define DCP_CH3OPTS_SET_RECOVERY_TIMER_MASK (0xFFFFU) +#define DCP_CH3OPTS_SET_RECOVERY_TIMER_SHIFT (0U) +#define DCP_CH3OPTS_SET_RECOVERY_TIMER(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3OPTS_SET_RECOVERY_TIMER_SHIFT)) & DCP_CH3OPTS_SET_RECOVERY_TIMER_MASK) +#define DCP_CH3OPTS_SET_RSVD_MASK (0xFFFF0000U) +#define DCP_CH3OPTS_SET_RSVD_SHIFT (16U) +#define DCP_CH3OPTS_SET_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3OPTS_SET_RSVD_SHIFT)) & DCP_CH3OPTS_SET_RSVD_MASK) +/*! @} */ + +/*! @name CH3OPTS_CLR - DCP channel 3 options register */ +/*! @{ */ +#define DCP_CH3OPTS_CLR_RECOVERY_TIMER_MASK (0xFFFFU) +#define DCP_CH3OPTS_CLR_RECOVERY_TIMER_SHIFT (0U) +#define DCP_CH3OPTS_CLR_RECOVERY_TIMER(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3OPTS_CLR_RECOVERY_TIMER_SHIFT)) & DCP_CH3OPTS_CLR_RECOVERY_TIMER_MASK) +#define DCP_CH3OPTS_CLR_RSVD_MASK (0xFFFF0000U) +#define DCP_CH3OPTS_CLR_RSVD_SHIFT (16U) +#define DCP_CH3OPTS_CLR_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3OPTS_CLR_RSVD_SHIFT)) & DCP_CH3OPTS_CLR_RSVD_MASK) +/*! @} */ + +/*! @name CH3OPTS_TOG - DCP channel 3 options register */ +/*! @{ */ +#define DCP_CH3OPTS_TOG_RECOVERY_TIMER_MASK (0xFFFFU) +#define DCP_CH3OPTS_TOG_RECOVERY_TIMER_SHIFT (0U) +#define DCP_CH3OPTS_TOG_RECOVERY_TIMER(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3OPTS_TOG_RECOVERY_TIMER_SHIFT)) & DCP_CH3OPTS_TOG_RECOVERY_TIMER_MASK) +#define DCP_CH3OPTS_TOG_RSVD_MASK (0xFFFF0000U) +#define DCP_CH3OPTS_TOG_RSVD_SHIFT (16U) +#define DCP_CH3OPTS_TOG_RSVD(x) (((uint32_t)(((uint32_t)(x)) << DCP_CH3OPTS_TOG_RSVD_SHIFT)) & DCP_CH3OPTS_TOG_RSVD_MASK) +/*! @} */ + /*! @name DBGSELECT - DCP debug select register */ /*! @{ */ #define DCP_DBGSELECT_INDEX_MASK (0xFFU) diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/MIMXRT1052_features.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/MIMXRT1052_features.h index f78522df6..8d785dd81 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/MIMXRT1052_features.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/MIMXRT1052_features.h @@ -223,6 +223,12 @@ #define FSL_FEATURE_EDMA_HAS_ERROR_IRQ (1) /* @brief Number of DMA channels with asynchronous request capability (register EARS). (Valid only for eDMA modules.) */ #define FSL_FEATURE_EDMA_ASYNCHRO_REQUEST_CHANNEL_COUNT (32) +/* @brief Channel IRQ entry shared offset. */ +#define FSL_FEATURE_EDMA_MODULE_CHANNEL_IRQ_ENTRY_SHARED_OFFSET (16) +/* @brief If 8 bytes transfer supported. */ +#define FSL_FEATURE_EDMA_SUPPORT_8_BYTES_TRANSFER (1) +/* @brief If 16 bytes transfer supported. */ +#define FSL_FEATURE_EDMA_SUPPORT_16_BYTES_TRANSFER (0) /* DMAMUX module features */ @@ -279,6 +285,8 @@ #define FSL_FEATURE_FLEXIO_VERID_RESET_VALUE (0x1010001) /* @brief Reset value of the FLEXIO_PARAM register */ #define FSL_FEATURE_FLEXIO_PARAM_RESET_VALUE (0x2200404) +/* @brief Flexio DMA request base channel */ +#define FSL_FEATURE_FLEXIO_DMA_REQUEST_BASE_CHANNEL (0) /* FLEXRAM module features */ @@ -489,7 +497,10 @@ /* @brief Receive/transmit FIFO size in item count (register bit fields TCSR[FRDE], TCSR[FRIE], TCSR[FRF], TCR1[TFW], RCSR[FRDE], RCSR[FRIE], RCSR[FRF], RCR1[RFW], registers TFRn, RFRn). */ #define FSL_FEATURE_SAI_FIFO_COUNT (32) /* @brief Receive/transmit channel number (register bit fields TCR3[TCE], RCR3[RCE], registers TDRn and RDRn). */ -#define FSL_FEATURE_SAI_CHANNEL_COUNT (4) +#define FSL_FEATURE_SAI_CHANNEL_COUNTn(x) \ + (((x) == SAI1) ? (4) : \ + (((x) == SAI2) ? (1) : \ + (((x) == SAI3) ? (1) : (-1)))) /* @brief Maximum words per frame (register bit fields TCR3[WDFL], TCR4[FRSZ], TMR[TWM], RCR3[WDFL], RCR4[FRSZ], RMR[RWM]). */ #define FSL_FEATURE_SAI_MAX_WORDS_PER_FRAME (32) /* @brief Has support of combining multiple data channel FIFOs into single channel FIFO (register bit fields TCR3[CFR], TCR4[FCOMB], TFR0[WCP], TFR1[WCP], RCR3[CFR], RCR4[FCOMB], RFR0[RCP], RFR1[RCP]). */ @@ -514,6 +525,10 @@ #define FSL_FEATURE_SAI_HAS_MDR (0) /* @brief Has support the BCLK bypass mode when BCLK = MCLK. */ #define FSL_FEATURE_SAI_HAS_BCLK_BYPASS (0) +/* @brief Has DIV bit fields of MCR register (register bit fields MCR[DIV]. */ +#define FSL_FEATURE_SAI_HAS_MCR_MCLK_POST_DIV (0) +/* @brief Support Channel Mode (register bit fields TCR4[CHMOD]). */ +#define FSL_FEATURE_SAI_HAS_CHANNEL_MODE (1) /* SEMC module features */ @@ -623,5 +638,7 @@ /* @brief DMA_CH_MUX_REQ_95. */ #define FSL_FEATURE_XBARA_OUTPUT_DMA_CH_MUX_REQ_95 (1) +#define FSL_FEATURE_XBARA_INTERRUPT_COUNT (4) + #endif /* _MIMXRT1052_FEATURES_H_ */ diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h new file mode 100644 index 000000000..47b33596d --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h @@ -0,0 +1,32 @@ +/* + * Copyright 2018-2020 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** +* @file flash.h +* @brief support flexspi norflash function +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-04-03 +*/ + +#ifndef __FLASH_H__ +#define __FLASH_H__ + +#include +#include "fsl_romapi.h" + +void FLASH_Init(void); +void FLASH_DeInit(void); +uint32_t FLASH_GetSectorSize(void); +status_t FLASH_WritePage(uint32_t addr, const uint8_t *buf, uint32_t len); +status_t FLASH_EraseSector(uint32_t addr); +status_t FLASH_Read(uint32_t addr, const uint8_t *buf, uint32_t len); +uint32_t FLASH_Test(uint32_t startAddr, uint32_t len); +uint32_t FLASH_GetProgramCmd(void); + +#endif + diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_clock.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_clock.h index 3dfefede9..33962234d 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_clock.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_clock.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2019 NXP + * Copyright 2017 - 2020, NXP * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -47,8 +47,8 @@ /*! @name Driver version */ /*@{*/ -/*! @brief CLOCK driver version 2.2.0. */ -#define FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 2, 0)) +/*! @brief CLOCK driver version 2.4.0. */ +#define FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 4, 0)) /* Definition for delay API in clock driver, users can redefine it to the real application. */ #ifndef SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY @@ -56,8 +56,8 @@ #endif /* analog pll definition */ -#define CCM_ANALOG_PLL_BYPASS_SHIFT (16U) -#define CCM_ANALOG_PLL_BYPASS_CLK_SRC_MASK (0xC000U) +#define CCM_ANALOG_PLL_BYPASS_SHIFT (16U) +#define CCM_ANALOG_PLL_BYPASS_CLK_SRC_MASK (0xC000U) #define CCM_ANALOG_PLL_BYPASS_CLK_SRC_SHIFT (14U) /*@}*/ @@ -65,48 +65,56 @@ /*! * @brief CCM registers offset. */ -#define CCSR_OFFSET 0x0C -#define CBCDR_OFFSET 0x14 -#define CBCMR_OFFSET 0x18 +#define CCSR_OFFSET 0x0C +#define CBCDR_OFFSET 0x14 +#define CBCMR_OFFSET 0x18 #define CSCMR1_OFFSET 0x1C #define CSCMR2_OFFSET 0x20 #define CSCDR1_OFFSET 0x24 -#define CDCDR_OFFSET 0x30 +#define CDCDR_OFFSET 0x30 #define CSCDR2_OFFSET 0x38 #define CSCDR3_OFFSET 0x3C -#define CACRR_OFFSET 0x10 +#define CACRR_OFFSET 0x10 #define CS1CDR_OFFSET 0x28 #define CS2CDR_OFFSET 0x2C /*! * @brief CCM Analog registers offset. */ -#define PLL_ARM_OFFSET 0x00 -#define PLL_SYS_OFFSET 0x30 -#define PLL_USB1_OFFSET 0x10 +#define PLL_ARM_OFFSET 0x00 +#define PLL_SYS_OFFSET 0x30 +#define PLL_USB1_OFFSET 0x10 #define PLL_AUDIO_OFFSET 0x70 #define PLL_VIDEO_OFFSET 0xA0 -#define PLL_ENET_OFFSET 0xE0 -#define PLL_USB2_OFFSET 0x20 +#define PLL_ENET_OFFSET 0xE0 +#define PLL_USB2_OFFSET 0x20 #define CCM_TUPLE(reg, shift, mask, busyShift) \ - (int)((reg & 0xFFU) | ((shift) << 8U) | ((((mask) >> (shift)) & 0x1FFFU) << 13U) | ((busyShift) << 26U)) -#define CCM_TUPLE_REG(base, tuple) (*((volatile uint32_t *)(((uint32_t)(base)) + ((tuple)&0xFFU)))) -#define CCM_TUPLE_SHIFT(tuple) (((tuple) >> 8U) & 0x1FU) -#define CCM_TUPLE_MASK(tuple) ((uint32_t)((((tuple) >> 13U) & 0x1FFFU) << ((((tuple) >> 8U) & 0x1FU)))) -#define CCM_TUPLE_BUSY_SHIFT(tuple) (((tuple) >> 26U) & 0x3FU) + (int)(((reg)&0xFFU) | ((shift) << 8U) | ((((mask) >> (shift)) & 0x1FFFU) << 13U) | ((busyShift) << 26U)) +#define CCM_TUPLE_REG(base, tuple) (*((volatile uint32_t *)(((uint32_t)(base)) + ((uint32_t)(tuple)&0xFFU)))) +#define CCM_TUPLE_SHIFT(tuple) ((((uint32_t)tuple) >> 8U) & 0x1FU) +#define CCM_TUPLE_MASK(tuple) \ + ((uint32_t)((((uint32_t)(tuple) >> 13U) & 0x1FFFU) << (((((uint32_t)tuple) >> 8U) & 0x1FU)))) +#define CCM_TUPLE_BUSY_SHIFT(tuple) ((((uint32_t)tuple) >> 26U) & 0x3FU) #define CCM_NO_BUSY_WAIT (0x20U) /*! * @brief CCM ANALOG tuple macros to map corresponding registers and bit fields. */ -#define CCM_ANALOG_TUPLE(reg, shift) (((reg & 0xFFFU) << 16U) | (shift)) +#define CCM_ANALOG_TUPLE(reg, shift) ((((reg)&0xFFFU) << 16U) | (shift)) #define CCM_ANALOG_TUPLE_SHIFT(tuple) (((uint32_t)tuple) & 0x1FU) #define CCM_ANALOG_TUPLE_REG_OFF(base, tuple, off) \ - (*((volatile uint32_t *)((uint32_t)base + (((uint32_t)tuple >> 16U) & 0xFFFU) + off))) + (*((volatile uint32_t *)((uint32_t)(base) + (((uint32_t)(tuple) >> 16U) & 0xFFFU) + (off)))) #define CCM_ANALOG_TUPLE_REG(base, tuple) CCM_ANALOG_TUPLE_REG_OFF(base, tuple, 0U) +/* Definition for ERRATA 50235 check */ +#if (defined(FSL_FEATURE_CCM_HAS_ERRATA_50235) && FSL_FEATURE_CCM_HAS_ERRATA_50235) +#define CAN_CLOCK_CHECK_NO_AFFECTS \ + ((CCM_CSCMR2_CAN_CLK_SEL(2U) != (CCM->CSCMR2 & CCM_CSCMR2_CAN_CLK_SEL_MASK)) || \ + (CCM_CCGR5_CG12(0) != (CCM->CCGR5 & CCM_CCGR5_CG12_MASK))) +#endif /* FSL_FEATURE_CCM_HAS_ERRATA_50235 */ + /*! * @brief clock1PN frequency. */ @@ -118,8 +126,8 @@ * function CLOCK_SetXtalFreq to set the value in to clock driver. For example, * if XTAL is 24MHz, * @code - * CLOCK_InitExternalClk(false); // Setup the 24M OSC/SYSOSC - * CLOCK_SetXtalFreq(240000000); // Set the XTAL value to clock driver. + * CLOCK_InitExternalClk(false); + * CLOCK_SetXtalFreq(240000000); * @endcode */ extern volatile uint32_t g_xtalFreq; @@ -132,7 +140,7 @@ extern volatile uint32_t g_xtalFreq; extern volatile uint32_t g_rtcXtalFreq; /* For compatible with other platforms */ -#define CLOCK_SetXtal0Freq CLOCK_SetXtalFreq +#define CLOCK_SetXtal0Freq CLOCK_SetXtalFreq #define CLOCK_SetXtal32Freq CLOCK_SetRtcXtalFreq /*! @brief Clock ip name array for ADC. */ @@ -400,6 +408,65 @@ extern volatile uint32_t g_rtcXtalFreq; kCLOCK_IpInvalid, kCLOCK_IpInvalid, kCLOCK_Xbar2, kCLOCK_Xbar3 \ } +#define CLOCK_SOURCE_NONE (0xFFU) + +#define CLOCK_ROOT_SOUCE \ + { \ + {kCLOCK_SysPllPfd2Clk, kCLOCK_SysPllPfd0Clk, kCLOCK_NoneName, \ + kCLOCK_NoneName, kCLOCK_NoneName, kCLOCK_NoneName}, /* USDHC1 Clock Root. */ \ + {kCLOCK_SysPllPfd2Clk, kCLOCK_SysPllPfd0Clk, kCLOCK_NoneName, \ + kCLOCK_NoneName, kCLOCK_NoneName, kCLOCK_NoneName}, /* USDHC2 Clock Root. */ \ + {kCLOCK_SemcClk, kCLOCK_Usb1SwClk, kCLOCK_SysPllPfd2Clk, \ + kCLOCK_Usb1PllPfd0Clk, kCLOCK_NoneName, kCLOCK_NoneName}, /* FLEXSPI Clock Root. */ \ + {kCLOCK_OscClk, kCLOCK_SysPllPfd2Clk, kCLOCK_Usb1Sw120MClk, \ + kCLOCK_Usb1PllPfd1Clk, kCLOCK_NoneName, kCLOCK_NoneName}, /* CSI Clock Root. */ \ + {kCLOCK_Usb1PllPfd1Clk, kCLOCK_Usb1PllPfd0Clk, kCLOCK_SysPllClk, \ + kCLOCK_SysPllPfd2Clk, kCLOCK_NoneName, kCLOCK_NoneName}, /* LPSPI Clock Root. */ \ + {kCLOCK_SysPllClk, kCLOCK_SysPllPfd2Clk, kCLOCK_SysPllPfd0Clk, \ + kCLOCK_SysPllPfd1Clk, kCLOCK_NoneName, kCLOCK_NoneName}, /* TRACE Clock Root */ \ + {kCLOCK_Usb1PllPfd2Clk, kCLOCK_VideoPllClk, kCLOCK_AudioPllClk, \ + kCLOCK_NoneName, kCLOCK_NoneName, kCLOCK_NoneName}, /* SAI1 Clock Root */ \ + {kCLOCK_Usb1PllPfd2Clk, kCLOCK_VideoPllClk, kCLOCK_AudioPllClk, \ + kCLOCK_NoneName, kCLOCK_NoneName, kCLOCK_NoneName}, /* SAI2 Clock Root */ \ + {kCLOCK_Usb1PllPfd2Clk, kCLOCK_VideoPllClk, kCLOCK_AudioPllClk, \ + kCLOCK_NoneName, kCLOCK_NoneName, kCLOCK_NoneName}, /* SAI3 Clock Root */ \ + {kCLOCK_Usb1Sw60MClk, kCLOCK_OscClk, kCLOCK_NoneName, \ + kCLOCK_NoneName, kCLOCK_NoneName, kCLOCK_NoneName}, /* LPI2C Clock Root */ \ + {kCLOCK_Usb1Sw60MClk, kCLOCK_OscClk, kCLOCK_Usb1Sw80MClk, \ + kCLOCK_NoneName, kCLOCK_NoneName, kCLOCK_NoneName}, /* CAN Clock Root. */ \ + {kCLOCK_Usb1Sw80MClk, kCLOCK_OscClk, kCLOCK_NoneName, \ + kCLOCK_NoneName, kCLOCK_NoneName, kCLOCK_NoneName}, /* UART Clock Root */ \ + {kCLOCK_SysPllClk, kCLOCK_Usb1PllPfd3Clk, kCLOCK_VideoPllClk, \ + kCLOCK_SysPllPfd0Clk, kCLOCK_SysPllPfd1Clk, kCLOCK_Usb1PllPfd1Clk}, /* LCDIF Clock Root */ \ + {kCLOCK_AudioPllClk, kCLOCK_Usb1PllPfd2Clk, kCLOCK_VideoPllClk, \ + kCLOCK_Usb1SwClk, kCLOCK_NoneName, kCLOCK_NoneName}, /* SPDIF0 Clock Root */ \ + {kCLOCK_AudioPllClk, kCLOCK_Usb1PllPfd2Clk, kCLOCK_VideoPllClk, \ + kCLOCK_Usb1SwClk, kCLOCK_NoneName, kCLOCK_NoneName}, /* FLEXIO1 Clock Root */ \ + {kCLOCK_AudioPllClk, kCLOCK_Usb1PllPfd2Clk, kCLOCK_VideoPllClk, \ + kCLOCK_Usb1PllClk, kCLOCK_NoneName, kCLOCK_NoneName}, /* FLEXIO2 Clock ROOT */ \ + } + +#define CLOCK_ROOT_MUX_TUPLE \ + { \ + kCLOCK_Usdhc1Mux, kCLOCK_Usdhc2Mux, kCLOCK_FlexspiMux, kCLOCK_CsiMux, kCLOCK_LpspiMux, kCLOCK_TraceMux, \ + kCLOCK_Sai1Mux, kCLOCK_Sai2Mux, kCLOCK_Sai3Mux, kCLOCK_Lpi2cMux, kCLOCK_CanMux, kCLOCK_UartMux, \ + kCLOCK_LcdifPreMux, kCLOCK_SpdifMux, kCLOCK_Flexio1Mux, kCLOCK_Flexio2Mux, \ + } + +#define CLOCK_ROOT_NONE_PRE_DIV 0UL + +#define CLOCK_ROOT_DIV_TUPLE \ + { \ + {kCLOCK_NonePreDiv, kCLOCK_Usdhc1Div}, {kCLOCK_NonePreDiv, kCLOCK_Usdhc2Div}, \ + {kCLOCK_NonePreDiv, kCLOCK_FlexspiDiv}, {kCLOCK_NonePreDiv, kCLOCK_CsiDiv}, \ + {kCLOCK_NonePreDiv, kCLOCK_LpspiDiv}, {kCLOCK_NonePreDiv, kCLOCK_TraceDiv}, \ + {kCLOCK_Sai1PreDiv, kCLOCK_Sai1Div}, {kCLOCK_Sai2PreDiv, kCLOCK_Sai2Div}, \ + {kCLOCK_Sai3PreDiv, kCLOCK_Sai3Div}, {kCLOCK_NonePreDiv, kCLOCK_Lpi2cDiv}, \ + {kCLOCK_NonePreDiv, kCLOCK_CanDiv}, {kCLOCK_NonePreDiv, kCLOCK_UartDiv}, \ + {kCLOCK_LcdifPreDiv, kCLOCK_LcdifDiv}, {kCLOCK_Spdif0PreDiv, kCLOCK_Spdif0Div}, \ + {kCLOCK_Flexio1PreDiv, kCLOCK_Flexio1Div}, {kCLOCK_Flexio2PreDiv, kCLOCK_Flexio2Div}, \ + } + /*! @brief Clock name used to get clock frequency. */ typedef enum _clock_name { @@ -414,11 +481,15 @@ typedef enum _clock_name kCLOCK_ArmPllClk = 0x7U, /*!< ARMPLLCLK. */ - kCLOCK_Usb1PllClk = 0x8U, /*!< USB1PLLCLK. */ - kCLOCK_Usb1PllPfd0Clk = 0x9U, /*!< USB1PLLPDF0CLK. */ - kCLOCK_Usb1PllPfd1Clk = 0xAU, /*!< USB1PLLPFD1CLK. */ - kCLOCK_Usb1PllPfd2Clk = 0xBU, /*!< USB1PLLPFD2CLK. */ - kCLOCK_Usb1PllPfd3Clk = 0xCU, /*!< USB1PLLPFD3CLK. */ + kCLOCK_Usb1PllClk = 0x8U, /*!< USB1PLLCLK. */ + kCLOCK_Usb1PllPfd0Clk = 0x9U, /*!< USB1PLLPDF0CLK. */ + kCLOCK_Usb1PllPfd1Clk = 0xAU, /*!< USB1PLLPFD1CLK. */ + kCLOCK_Usb1PllPfd2Clk = 0xBU, /*!< USB1PLLPFD2CLK. */ + kCLOCK_Usb1PllPfd3Clk = 0xCU, /*!< USB1PLLPFD3CLK. */ + kCLOCK_Usb1SwClk = 0x17U, /*!< USB1PLLSWCLK */ + kCLOCK_Usb1Sw120MClk = 0x18U, /*!< USB1PLLSw120MCLK */ + kCLOCK_Usb1Sw60MClk = 0x19U, /*!< USB1PLLSw60MCLK */ + kCLOCK_Usb1Sw80MClk = 0x1AU, /*!< USB1PLLSw80MCLK */ kCLOCK_Usb2PllClk = 0xDU, /*!< USB2PLLCLK. */ @@ -431,11 +502,12 @@ typedef enum _clock_name kCLOCK_EnetPll0Clk = 0x13U, /*!< Enet PLLCLK ref_enetpll0. */ kCLOCK_EnetPll1Clk = 0x14U, /*!< Enet PLLCLK ref_enetpll1. */ - kCLOCK_AudioPllClk = 0x15U, /*!< Audio PLLCLK. */ - kCLOCK_VideoPllClk = 0x16U, /*!< Video PLLCLK. */ + kCLOCK_AudioPllClk = 0x15U, /*!< Audio PLLCLK. */ + kCLOCK_VideoPllClk = 0x16U, /*!< Video PLLCLK. */ + kCLOCK_NoneName = CLOCK_SOURCE_NONE, /*!< None Clock Name. */ } clock_name_t; -#define kCLOCK_CoreSysClk kCLOCK_CpuClk /*!< For compatible with other platforms without CCM. */ +#define kCLOCK_CoreSysClk kCLOCK_CpuClk /*!< For compatible with other platforms without CCM. */ #define CLOCK_GetCoreSysClkFreq CLOCK_GetCpuClkFreq /*!< For compatible with other platforms without CCM. */ /*! @@ -835,6 +907,8 @@ typedef enum _clock_div kCLOCK_CsiDiv = CCM_TUPLE( CSCDR3_OFFSET, CCM_CSCDR3_CSI_PODF_SHIFT, CCM_CSCDR3_CSI_PODF_MASK, CCM_NO_BUSY_WAIT), /*!< csi div name */ + + kCLOCK_NonePreDiv = CLOCK_ROOT_NONE_PRE_DIV, /*!< None Pre div. */ } clock_div_t; /*! @brief USB clock source definition. */ @@ -952,6 +1026,83 @@ typedef enum _clock_pfd kCLOCK_Pfd3 = 3U, /*!< PLL PFD3 */ } clock_pfd_t; +/*! + * @brief The enumerater of clock output1's clock source, such as USB1 PLL, SYS PLL and so on. + */ +typedef enum _clock_output1_selection +{ + kCLOCK_OutputPllUsb1 = 0U, /*!< Selects USB1 PLL clock(Divided by 2) output. */ + kCLOCK_OutputPllSys = 1U, /*!< Selects SYS PLL clock(Divided by 2) output. */ + kCLOCK_OutputPllVideo = 3U, /*!< Selects Video PLL clock(Divided by 2) output. */ + kCLOCK_OutputSemcClk = 5U, /*!< Selects semc clock root output. */ + kCLOCK_OutputLcdifPixClk = 0xAU, /*!< Selects Lcdif pix clock root output. */ + kCLOCK_OutputAhbClk = 0xBU, /*!< Selects AHB clock root output. */ + kCLOCK_OutputIpgClk = 0xCU, /*!< Selects IPG clock root output. */ + kCLOCK_OutputPerClk = 0xDU, /*!< Selects PERCLK clock root output. */ + kCLOCK_OutputCkilSyncClk = 0xEU, /*!< Selects Ckil clock root output. */ + kCLOCK_OutputPll4MainClk = 0xFU, /*!< Selects PLL4 main clock output. */ + kCLOCK_DisableClockOutput1 = 0x10U, /*!< Disables CLKO1. */ +} clock_output1_selection_t; + +/*! + * @brief The enumerater of clock output2's clock source, such as USDHC1 clock root, LPI2C clock root and so on. + * + */ +typedef enum _clock_output2_selection +{ + kCLOCK_OutputUsdhc1Clk = 3U, /*!< Selects USDHC1 clock root output. */ + kCLOCK_OutputLpi2cClk = 6U, /*!< Selects LPI2C clock root output. */ + kCLOCK_OutputCsiClk = 0xBU, /*!< Selects CSI clock root output. */ + kCLOCK_OutputOscClk = 0xEU, /*!< Selects OSC output. */ + kCLOCK_OutputUsdhc2Clk = 0x11U, /*!< Selects USDHC2 clock root output. */ + kCLOCK_OutputSai1Clk = 0x12U, /*!< Selects SAI1 clock root output. */ + kCLOCK_OutputSai2Clk = 0x13U, /*!< Selects SAI2 clock root output. */ + kCLOCK_OutputSai3Clk = 0x14U, /*!< Selects SAI3 clock root output. */ + kCLOCK_OutputCanClk = 0x17U, /*!< Selects CAN clock root output. */ + kCLOCK_OutputFlexspiClk = 0x1BU, /*!< Selects FLEXSPI clock root output. */ + kCLOCK_OutputUartClk = 0x1CU, /*!< Selects UART clock root output. */ + kCLOCK_OutputSpdif0Clk = 0x1DU, /*!< Selects SPDIF0 clock root output. */ + kCLOCK_DisableClockOutput2 = 0x1FU, /*!< Disables CLKO2. */ +} clock_output2_selection_t; + +/*! + * @brief The enumerator of clock output's divider. + */ +typedef enum _clock_output_divider +{ + kCLOCK_DivideBy1 = 0U, /*!< Output clock divided by 1. */ + kCLOCK_DivideBy2, /*!< Output clock divided by 2. */ + kCLOCK_DivideBy3, /*!< Output clock divided by 3. */ + kCLOCK_DivideBy4, /*!< Output clock divided by 4. */ + kCLOCK_DivideBy5, /*!< Output clock divided by 5. */ + kCLOCK_DivideBy6, /*!< Output clock divided by 6. */ + kCLOCK_DivideBy7, /*!< Output clock divided by 7. */ + kCLOCK_DivideBy8, /*!< Output clock divided by 8. */ +} clock_output_divider_t; + +/*! + * @brief The enumerator of clock root. + */ +typedef enum _clock_root +{ + kCLOCK_Usdhc1ClkRoot = 0U, /*!< USDHC1 clock root. */ + kCLOCK_Usdhc2ClkRoot, /*!< USDHC2 clock root. */ + kCLOCK_FlexspiClkRoot, /*!< FLEXSPI clock root. */ + kCLOCK_CsiClkRoot, /*!< CSI clock root. */ + kCLOCK_LpspiClkRoot, /*!< LPSPI clock root. */ + kCLOCK_TraceClkRoot, /*!< Trace clock root. */ + kCLOCK_Sai1ClkRoot, /*!< SAI1 clock root. */ + kCLOCK_Sai2ClkRoot, /*!< SAI2 clock root. */ + kCLOCK_Sai3ClkRoot, /*!< SAI3 clock root. */ + kCLOCK_Lpi2cClkRoot, /*!< LPI2C clock root. */ + kCLOCK_CanClkRoot, /*!< CAN clock root. */ + kCLOCK_UartClkRoot, /*!< UART clock root. */ + kCLOCK_LcdifClkRoot, /*!< LCD clock root. */ + kCLOCK_SpdifClkRoot, /*!< SPDIF clock root. */ + kCLOCK_Flexio1ClkRoot, /*!< FLEXIO1 clock root. */ + kCLOCK_Flexio2ClkRoot, /*!< FLEXIO2 clock root. */ +} clock_root_t; + /******************************************************************************* * API ******************************************************************************/ @@ -970,7 +1121,7 @@ static inline void CLOCK_SetMux(clock_mux_t mux, uint32_t value) { uint32_t busyShift; - busyShift = CCM_TUPLE_BUSY_SHIFT(mux); + busyShift = (uint32_t)CCM_TUPLE_BUSY_SHIFT(mux); CCM_TUPLE_REG(CCM, mux) = (CCM_TUPLE_REG(CCM, mux) & (~CCM_TUPLE_MASK(mux))) | (((uint32_t)((value) << CCM_TUPLE_SHIFT(mux))) & CCM_TUPLE_MASK(mux)); @@ -980,7 +1131,7 @@ static inline void CLOCK_SetMux(clock_mux_t mux, uint32_t value) if (CCM_NO_BUSY_WAIT != busyShift) { /* Wait until CCM internal handshake finish. */ - while (CCM->CDHIPR & (1U << busyShift)) + while ((CCM->CDHIPR & ((1UL << busyShift))) != 0UL) { } } @@ -994,7 +1145,7 @@ static inline void CLOCK_SetMux(clock_mux_t mux, uint32_t value) */ static inline uint32_t CLOCK_GetMux(clock_mux_t mux) { - return (CCM_TUPLE_REG(CCM, mux) & CCM_TUPLE_MASK(mux)) >> CCM_TUPLE_SHIFT(mux); + return (((uint32_t)(CCM_TUPLE_REG(CCM, mux) & CCM_TUPLE_MASK(mux))) >> CCM_TUPLE_SHIFT(mux)); } /*! @@ -1017,7 +1168,7 @@ static inline void CLOCK_SetDiv(clock_div_t divider, uint32_t value) if (CCM_NO_BUSY_WAIT != busyShift) { /* Wait until CCM internal handshake finish. */ - while (CCM->CDHIPR & (1U << busyShift)) + while ((CCM->CDHIPR & ((uint32_t)(1UL << busyShift))) != 0UL) { } } @@ -1030,7 +1181,7 @@ static inline void CLOCK_SetDiv(clock_div_t divider, uint32_t value) */ static inline uint32_t CLOCK_GetDiv(clock_div_t divider) { - return ((CCM_TUPLE_REG(CCM, divider) & CCM_TUPLE_MASK(divider)) >> CCM_TUPLE_SHIFT(divider)); + return ((uint32_t)(CCM_TUPLE_REG(CCM, divider) & CCM_TUPLE_MASK(divider)) >> CCM_TUPLE_SHIFT(divider)); } /*! @@ -1045,10 +1196,10 @@ static inline void CLOCK_ControlGate(clock_ip_name_t name, clock_gate_value_t va uint32_t shift = ((uint32_t)name) & 0x1FU; volatile uint32_t *reg; - assert(index <= 6); + assert(index <= 6UL); - reg = ((volatile uint32_t *)&CCM->CCGR0) + index; - *reg = ((*reg) & ~(3U << shift)) | (((uint32_t)value) << shift); + reg = (volatile uint32_t *)(&(((volatile uint32_t *)&CCM->CCGR0)[index])); + *reg = ((*reg) & ~((uint32_t)(3UL << shift))) | (((uint32_t)value) << shift); } /*! @@ -1087,13 +1238,11 @@ static inline void CLOCK_SetMode(clock_mode_t mode) * This function will return the external XTAL OSC frequency if it is selected as the source of OSC, * otherwise internal 24MHz RC OSC frequency will be returned. * - * @param osc OSC type to get frequency. - * * @return Clock frequency; If the clock is invalid, returns 0. */ static inline uint32_t CLOCK_GetOscFreq(void) { - return (XTALOSC24M->LOWPWR_CTRL & XTALOSC24M_LOWPWR_CTRL_OSC_SEL_MASK) ? 24000000UL : g_xtalFreq; + return ((XTALOSC24M->LOWPWR_CTRL & XTALOSC24M_LOWPWR_CTRL_OSC_SEL_MASK) != 0UL) ? 24000000UL : g_xtalFreq; } /*! @@ -1130,7 +1279,7 @@ uint32_t CLOCK_GetPerClkFreq(void); * This function checks the current clock configurations and then calculates * the clock frequency for a specific clock name defined in clock_name_t. * - * @param clockName Clock names defined in clock_name_t + * @param name Clock names defined in clock_name_t * @return Clock frequency value in hertz */ uint32_t CLOCK_GetFreq(clock_name_t name); @@ -1145,6 +1294,14 @@ static inline uint32_t CLOCK_GetCpuClkFreq(void) return CLOCK_GetFreq(kCLOCK_CpuClk); } +/*! + * @brief Gets the frequency of selected clock root. + * + * @param clockRoot The clock root used to get the frequency, please refer to @ref clock_root_t. + * @return The frequency of selected clock root. + */ +uint32_t CLOCK_GetClockRootFreq(clock_root_t clockRoot); + /*! * @name OSC operations * @{ @@ -1157,7 +1314,7 @@ static inline uint32_t CLOCK_GetCpuClkFreq(void) * 1. Use external crystal oscillator. * 2. Bypass the external crystal oscillator, using input source clock directly. * - * After this function, please call @ref CLOCK_SetXtal0Freq to inform clock driver + * After this function, please call CLOCK_SetXtal0Freq to inform clock driver * the external clock frequency. * * @param bypassXtalOsc Pass in true to bypass the external crystal oscillator. @@ -1171,7 +1328,7 @@ void CLOCK_InitExternalClk(bool bypassXtalOsc); * * This function disables the external 24MHz clock. * - * After this function, please call @ref CLOCK_SetXtal0Freq to set external clock + * After this function, please call CLOCK_SetXtal0Freq to set external clock * frequency to 0. */ void CLOCK_DeinitExternalClk(void); @@ -1229,7 +1386,7 @@ void CLOCK_DeinitRcOsc24M(void); /*! @brief Enable USB HS clock. * * This function only enables the access to USB HS prepheral, upper layer - * should first call the @ref CLOCK_EnableUsbhs0PhyPllClock to enable the PHY + * should first call the CLOCK_EnableUsbhs0PhyPllClock to enable the PHY * clock to use USB HS. * * @param src USB HS does not care about the clock source, here must be @ref kCLOCK_UsbSrcUnused. @@ -1242,7 +1399,7 @@ bool CLOCK_EnableUsbhs0Clock(clock_usb_src_t src, uint32_t freq); /*! @brief Enable USB HS clock. * * This function only enables the access to USB HS prepheral, upper layer - * should first call the @ref CLOCK_EnableUsbhs0PhyPllClock to enable the PHY + * should first call the CLOCK_EnableUsbhs0PhyPllClock to enable the PHY * clock to use USB HS. * * @param src USB HS does not care about the clock source, here must be @ref kCLOCK_UsbSrcUnused. @@ -1252,12 +1409,6 @@ bool CLOCK_EnableUsbhs0Clock(clock_usb_src_t src, uint32_t freq); */ bool CLOCK_EnableUsbhs1Clock(clock_usb_src_t src, uint32_t freq); -/*! @brief Disable USB HS PHY PLL clock. - * - * This function disables USB HS PHY PLL clock. - */ -void CLOCK_DisableUsbhs1PhyPllClock(void); - /* @} */ /*! @@ -1277,11 +1428,11 @@ static inline void CLOCK_SetPllBypass(CCM_ANALOG_Type *base, clock_pll_t pll, bo { if (bypass) { - CCM_ANALOG_TUPLE_REG_OFF(base, pll, 4U) = 1U << CCM_ANALOG_PLL_BYPASS_SHIFT; + CCM_ANALOG_TUPLE_REG_OFF(base, pll, 4U) = 1UL << CCM_ANALOG_PLL_BYPASS_SHIFT; } else { - CCM_ANALOG_TUPLE_REG_OFF(base, pll, 8U) = 1U << CCM_ANALOG_PLL_BYPASS_SHIFT; + CCM_ANALOG_TUPLE_REG_OFF(base, pll, 8U) = 1UL << CCM_ANALOG_PLL_BYPASS_SHIFT; } } @@ -1296,7 +1447,7 @@ static inline void CLOCK_SetPllBypass(CCM_ANALOG_Type *base, clock_pll_t pll, bo */ static inline bool CLOCK_IsPllBypassed(CCM_ANALOG_Type *base, clock_pll_t pll) { - return (bool)(CCM_ANALOG_TUPLE_REG(base, pll) & (1U << CCM_ANALOG_PLL_BYPASS_SHIFT)); + return (bool)(CCM_ANALOG_TUPLE_REG(base, pll) & (1UL << CCM_ANALOG_PLL_BYPASS_SHIFT)); } /*! @@ -1310,7 +1461,7 @@ static inline bool CLOCK_IsPllBypassed(CCM_ANALOG_Type *base, clock_pll_t pll) */ static inline bool CLOCK_IsPllEnabled(CCM_ANALOG_Type *base, clock_pll_t pll) { - return (bool)(CCM_ANALOG_TUPLE_REG(base, pll) & (1U << CCM_ANALOG_TUPLE_SHIFT(pll))); + return ((CCM_ANALOG_TUPLE_REG(base, pll) & (1UL << CCM_ANALOG_TUPLE_SHIFT(pll))) != 0U); } /*! @@ -1337,7 +1488,7 @@ static inline void CLOCK_SetPllBypassRefClkSrc(CCM_ANALOG_Type *base, clock_pll_ static inline uint32_t CLOCK_GetPllBypassRefClk(CCM_ANALOG_Type *base, clock_pll_t pll) { return (((CCM_ANALOG_TUPLE_REG(base, pll) & CCM_ANALOG_PLL_BYPASS_CLK_SRC_MASK) >> - CCM_ANALOG_PLL_BYPASS_CLK_SRC_SHIFT) == kCLOCK_PllClkSrc24M) ? + CCM_ANALOG_PLL_BYPASS_CLK_SRC_SHIFT) == (uint32_t)kCLOCK_PllClkSrc24M) ? CLOCK_GetOscFreq() : CLKPN_FREQ; } @@ -1547,18 +1698,45 @@ bool CLOCK_EnableUsbhs1PhyPllClock(clock_usb_phy_src_t src, uint32_t freq); */ void CLOCK_DisableUsbhs1PhyPllClock(void); -/*! - * @brief Use DWT to delay at least for some time. - * Please note that, this API will calculate the microsecond period with the maximum - * supported CPU frequency, so this API will only delay for at least the given microseconds, if precise - * delay count was needed, please implement a new timer count to achieve this function. - * - * @param delay_us Delay time in unit of microsecond. - */ -void SDK_DelayAtLeastUs(uint32_t delay_us); - /* @} */ +/*! + * @name Clock Output Inferfaces + * @{ + */ + +/*! + * @brief Set the clock source and the divider of the clock output1. + * + * @param selection The clock source to be output, please refer to @ref clock_output1_selection_t. + * @param divider The divider of the output clock signal, please refer to @ref clock_output_divider_t. + */ +void CLOCK_SetClockOutput1(clock_output1_selection_t selection, clock_output_divider_t divider); + +/*! + * @brief Set the clock source and the divider of the clock output2. + * + * @param selection The clock source to be output, please refer to @ref clock_output2_selection_t. + * @param divider The divider of the output clock signal, please refer to @ref clock_output_divider_t. + */ +void CLOCK_SetClockOutput2(clock_output2_selection_t selection, clock_output_divider_t divider); + +/*! + * @brief Get the frequency of clock output1 clock signal. + * + * @return The frequency of clock output1 clock signal. + */ +uint32_t CLOCK_GetClockOutCLKO1Freq(void); + +/*! + * @brief Get the frequency of clock output2 clock signal. + * + * @return The frequency of clock output2 clock signal. + */ +uint32_t CLOCK_GetClockOutClkO2Freq(void); + +/*! @} */ + #if defined(__cplusplus) } #endif /* __cplusplus */ diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_common.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_common.h index 6d07932ef..43ebe30d2 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_common.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_common.h @@ -47,7 +47,7 @@ /*! @name Driver version */ /*@{*/ /*! @brief common driver version 2.0.1. */ -#define FSL_COMMON_DRIVER_VERSION (MAKE_VERSION(2, 0, 1)) +#define FSL_COMMON_DRIVER_VERSION (MAKE_VERSION(2, 1, 0)) /*@}*/ /* Debug console type definition. */ @@ -131,6 +131,7 @@ enum _status_groups kStatusGroup_LPC_MINISPI = 76, /*!< Group number for LPC_MINISPI status codes. */ kStatusGroup_HASHCRYPT = 77, /*!< Group number for Hashcrypt status codes */ kStatusGroup_LPC_SPI_SSP = 78, /*!< Group number for LPC_SPI_SSP status codes. */ + kStatusGroup_I3C = 79, /*!< Group number for I3C status codes */ kStatusGroup_LPC_I2C_1 = 97, /*!< Group number for LPC_I2C_1 status codes. */ kStatusGroup_NOTIFIER = 98, /*!< Group number for NOTIFIER status codes. */ kStatusGroup_DebugConsole = 99, /*!< Group number for debug console status codes. */ @@ -157,6 +158,9 @@ enum _status_groups kStatusGroup_OSA = 143, /*!< Group number for OSA status codes. */ kStatusGroup_COMMON_TASK = 144, /*!< Group number for Common task status codes. */ kStatusGroup_MSG = 145, /*!< Group number for messaging status codes. */ + kStatusGroup_SDK_OCOTP = 146, /*!< Group number for OCOTP status codes. */ + kStatusGroup_SDK_FLEXSPINOR = 147, /*!< Group number for FLEXSPINOR status codes.*/ + kStatusGroup_CODEC = 148, /*!< Group number for codec status codes. */ }; /*! @brief Generic status return codes. */ @@ -174,20 +178,6 @@ enum _generic_status /*! @brief Type used for all status and error return values. */ typedef int32_t status_t; -/* - * The fsl_clock.h is included here because it needs MAKE_VERSION/MAKE_STATUS/status_t - * defined in previous of this file. - */ -#include "fsl_clock.h" - -/* - * Chip level peripheral reset API, for MCUs that implement peripheral reset control external to a peripheral - */ -#if ((defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0)) || \ - (defined(FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT) && (FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT > 0))) -#include "fsl_reset.h" -#endif - /* * Macro guard for whether to use default weak IRQ implementation in drivers */ @@ -198,11 +188,11 @@ typedef int32_t status_t; /*! @name Min/max macros */ /* @{ */ #if !defined(MIN) -#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif #if !defined(MAX) -#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif /* @} */ @@ -394,6 +384,21 @@ _Pragma("diag_suppress=Pm120") #error Toolchain not supported. #endif /* defined(__ICCARM__) */ /* @} */ + +/* + * The fsl_clock.h is included here because it needs MAKE_VERSION/MAKE_STATUS/status_t + * defined in previous of this file. + */ +#include "fsl_clock.h" + +/* + * Chip level peripheral reset API, for MCUs that implement peripheral reset control external to a peripheral + */ +#if ((defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0)) || \ + (defined(FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT) && (FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT > 0))) +#include "fsl_reset.h" +#endif + /******************************************************************************* * API ******************************************************************************/ @@ -489,6 +494,9 @@ _Pragma("diag_suppress=Pm120") */ static inline uint32_t DisableGlobalIRQ(void) { +#if defined (__XCC__) + return 0; +#else #if defined(CPSR_I_Msk) uint32_t cpsr = __get_CPSR() & CPSR_I_Msk; @@ -501,6 +509,7 @@ _Pragma("diag_suppress=Pm120") __disable_irq(); return regPrimask; +#endif #endif } @@ -516,10 +525,13 @@ _Pragma("diag_suppress=Pm120") */ static inline void EnableGlobalIRQ(uint32_t primask) { +#if defined (__XCC__) +#else #if defined(CPSR_I_Msk) __set_CPSR((__get_CPSR() & ~CPSR_I_Msk) | primask); #else __set_PRIMASK(primask); +#endif #endif } diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_gpio.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_gpio.h index 94cff8273..366e0779a 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_gpio.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_gpio.h @@ -30,8 +30,8 @@ /*! @name Driver version */ /*@{*/ -/*! @brief GPIO driver version 2.0.1. */ -#define FSL_GPIO_DRIVER_VERSION (MAKE_VERSION(2, 0, 1)) +/*! @brief GPIO driver version 2.0.2. */ +#define FSL_GPIO_DRIVER_VERSION (MAKE_VERSION(2, 0, 2)) /*@}*/ /*! @brief GPIO direction definition. */ diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_lpuart.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_lpuart.h index acc471346..f73e14919 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_lpuart.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_lpuart.h @@ -30,8 +30,8 @@ /*! @name Driver version */ /*@{*/ -/*! @brief LPUART driver version 2.2.6. */ -#define FSL_LPUART_DRIVER_VERSION (MAKE_VERSION(2, 2, 6)) +/*! @brief LPUART driver version 2.2.7. */ +#define FSL_LPUART_DRIVER_VERSION (MAKE_VERSION(2, 2, 7)) /*@}*/ /*! @brief Error codes for the LPUART driver. */ @@ -166,9 +166,8 @@ enum _lpuart_flags (LPUART_STAT_FE_MASK), /*!< Frame error flag, sets if logic 0 was detected where stop bit expected */ kLPUART_ParityErrorFlag = (LPUART_STAT_PF_MASK), /*!< If parity enabled, sets upon parity error detection */ #if defined(FSL_FEATURE_LPUART_HAS_LIN_BREAK_DETECT) && FSL_FEATURE_LPUART_HAS_LIN_BREAK_DETECT - kLPUART_LinBreakFlag = - (int)(LPUART_STAT_LBKDIF_MASK), /*!< LIN break detect interrupt flag, sets when LIN break char - detected and LIN circuit enabled */ + kLPUART_LinBreakFlag = (int)(LPUART_STAT_LBKDIF_MASK), /*!< LIN break detect interrupt flag, sets when LIN break + char detected and LIN circuit enabled */ #endif kLPUART_RxActiveEdgeFlag = (LPUART_STAT_RXEDGIF_MASK), /*!< Receive pin active edge interrupt flag, sets when active edge detected */ @@ -624,7 +623,7 @@ static inline uint8_t LPUART_ReadByte(LPUART_Type *base) return base->DATA; } #else - return base->DATA; + return (uint8_t)(base->DATA); #endif } diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_romapi.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_romapi.h new file mode 100644 index 000000000..d906d8ce6 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/fsl_romapi.h @@ -0,0 +1,570 @@ +/* + * Copyright 2017-2020 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** +* @file fsl_romapi.h +* @brief support flexspi norflash function +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-04-03 +*/ + +#ifndef _FSL_ROMAPI_H_ +#define _FSL_ROMAPI_H_ + +#include "fsl_common.h" + +/*! + * @addtogroup romapi + * @{ + */ + +/*! @brief ROMAPI version 1.1.1. */ +#define FSL_ROM_ROMAPI_VERSION (MAKE_VERSION(1U, 1U, 1U)) +/*! @brief ROM FLEXSPI NOR driver version 1.4.0. */ +#define FSL_ROM_FLEXSPINOR_DRIVER_VERSION (MAKE_VERSION(1U, 4U, 0U)) + +/*! + * @name Common ROMAPI fearures info defines + * @{ + */ +/* @brief ROM has FLEXSPI NOR API. */ +#define FSL_ROM_HAS_FLEXSPINOR_API (1) +/* @brief ROM has run bootloader API. */ +#define FSL_ROM_HAS_RUNBOOTLOADER_API (0) +/* @brief ROM has FLEXSPI NOR get config API. */ +#define FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_GET_CONFIG (0) +/* @brief ROM has flash init API. */ +#define FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_FLASH_INIT (1) +/* @brief ROM has erase API. */ +#define FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE (1) +/* @brief ROM has erase sector API. */ +#define FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_SECTOR (1) +/* @brief ROM has erase block API. */ +#define FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_BLOCK (0) +/* @brief ROM has erase all API. */ +#define FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_ALL (1) +/* @brief ROM has page program API. */ +#define FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_PAGE_PROGRAM (1) +/* @brief ROM has update lut API. */ +#define FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_UPDATE_LUT (1) +/* @brief ROM has FLEXSPI command API. */ +#define FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_CMD_XFER (1) + +/*@}*/ + +#define kROM_StatusGroup_FLEXSPI 60U /*!< ROM FLEXSPI status group number.*/ +#define kROM_StatusGroup_FLEXSPINOR 200U /*!< ROM FLEXSPI NOR status group number.*/ + +#define FSL_ROM_FLEXSPI_LUT_SEQ(cmd0, pad0, op0, cmd1, pad1, op1) \ + (FLEXSPI_LUT_OPERAND0(op0) | FLEXSPI_LUT_NUM_PADS0(pad0) | FLEXSPI_LUT_OPCODE0(cmd0) | FLEXSPI_LUT_OPERAND1(op1) | \ + FLEXSPI_LUT_NUM_PADS1(pad1) | FLEXSPI_LUT_OPCODE1(cmd1)) + +/*! @brief Generate bit mask */ +#define FSL_ROM_FLEXSPI_BITMASK(bit_offset) (1U << (bit_offset)) + +/*! @brief FLEXSPI memory config block related defintions */ +#define FLEXSPI_CFG_BLK_TAG (0x42464346UL) /*!< ascii "FCFB" Big Endian */ +#define FLEXSPI_CFG_BLK_VERSION (0x56010400UL) /*!< V1.4.0 */ + +#define CMD_SDR 0x01U +#define CMD_DDR 0x21U +#define RADDR_SDR 0x02U +#define RADDR_DDR 0x22U +#define CADDR_SDR 0x03U +#define CADDR_DDR 0x23U +#define MODE1_SDR 0x04U +#define MODE1_DDR 0x24U +#define MODE2_SDR 0x05U +#define MODE2_DDR 0x25U +#define MODE4_SDR 0x06U +#define MODE4_DDR 0x26U +#define MODE8_SDR 0x07U +#define MODE8_DDR 0x27U +#define WRITE_SDR 0x08U +#define WRITE_DDR 0x28U +#define READ_SDR 0x09U +#define READ_DDR 0x29U +#define LEARN_SDR 0x0AU +#define LEARN_DDR 0x2AU +#define DATSZ_SDR 0x0BU +#define DATSZ_DDR 0x2BU +#define DUMMY_SDR 0x0CU +#define DUMMY_DDR 0x2CU +#define DUMMY_RWDS_SDR 0x0DU +#define DUMMY_RWDS_DDR 0x2DU +#define JMP_ON_CS 0x1FU +#define STOP 0U + +#define FLEXSPI_1PAD 0U +#define FLEXSPI_2PAD 1U +#define FLEXSPI_4PAD 2U +#define FLEXSPI_8PAD 3U + +/* Lookup table related defintions */ +#define NOR_CMD_INDEX_READ 0U +#define NOR_CMD_INDEX_READSTATUS 1U +#define NOR_CMD_INDEX_WRITEENABLE 2U +#define NOR_CMD_INDEX_ERASESECTOR 3U +#define NOR_CMD_INDEX_PAGEPROGRAM 4U +#define NOR_CMD_INDEX_CHIPERASE 5U +#define NOR_CMD_INDEX_DUMMY 6U +#define NOR_CMD_INDEX_ERASEBLOCK 7U + +/*! + * NOR LUT sequence index used for default LUT assignment + * NOTE: + * The will take effect if the lut sequences are not customized. + */ +#define NOR_CMD_LUT_SEQ_IDX_READ 0U /*!< READ LUT sequence id in lookupTable stored in config block */ +#define NOR_CMD_LUT_SEQ_IDX_READSTATUS 1U /*!< Read Status LUT sequence id in lookupTable stored in config block */ +#define NOR_CMD_LUT_SEQ_IDX_READSTATUS_XPI \ + 2U /*!< Read status DPI/QPI/OPI sequence id in lookupTable stored in config block */ +#define NOR_CMD_LUT_SEQ_IDX_WRITEENABLE 3U /*!< Write Enable sequence id in lookupTable stored in config block */ +#define NOR_CMD_LUT_SEQ_IDX_WRITEENABLE_XPI \ + 4U /*!< Write Enable DPI/QPI/OPI sequence id in lookupTable stored in config block */ +#define NOR_CMD_LUT_SEQ_IDX_ERASESECTOR 5U /*!< Erase Sector sequence id in lookupTable stored in config block */ +#define NOR_CMD_LUT_SEQ_IDX_ERASEBLOCK 8U /*!< Erase Block sequence id in lookupTable stored in config block */ +#define NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM 9U /*!< Program sequence id in lookupTable stored in config block */ +#define NOR_CMD_LUT_SEQ_IDX_CHIPERASE 11U /*!< Chip Erase sequence in lookupTable id stored in config block */ +#define NOR_CMD_LUT_SEQ_IDX_READ_SFDP 13U /*!< Read SFDP sequence in lookupTable id stored in config block */ +#define NOR_CMD_LUT_SEQ_IDX_RESTORE_NOCMD \ + 14U /*!< Restore 0-4-4/0-8-8 mode sequence id in lookupTable stored in config block */ +#define NOR_CMD_LUT_SEQ_IDX_EXIT_NOCMD \ + 15U /*!< Exit 0-4-4/0-8-8 mode sequence id in lookupTable stored in config blobk */ + +/*! + * @name Support for init FLEXSPI NOR configuration + * @{ + */ +/*! @brief Flash Pad Definitions */ +enum +{ + kSerialFlash_1Pad = 1U, + kSerialFlash_2Pads = 2U, + kSerialFlash_4Pads = 4U, + kSerialFlash_8Pads = 8U, +}; + +/*! @brief FLEXSPI clock configuration type */ +enum +{ + kFLEXSPIClk_SDR, /*!< Clock configure for SDR mode */ + kFLEXSPIClk_DDR, /*!< Clock configurat for DDR mode */ +}; + +/*! @brief FLEXSPI Read Sample Clock Source definition */ +enum _flexspi_read_sample_clk +{ + kFLEXSPIReadSampleClk_LoopbackInternally = 0U, + kFLEXSPIReadSampleClk_LoopbackFromDqsPad = 1U, + kFLEXSPIReadSampleClk_LoopbackFromSckPad = 2U, + kFLEXSPIReadSampleClk_ExternalInputFromDqsPad = 3U, +}; + +/*! @brief Flash Type Definition */ +enum +{ + kFLEXSPIDeviceType_SerialNOR = 1U, /*!< Flash device is Serial NOR */ +}; + +/*! @brief Flash Configuration Command Type */ +enum +{ + kDeviceConfigCmdType_Generic, /*!< Generic command, for example: configure dummy cycles, drive strength, etc */ + kDeviceConfigCmdType_QuadEnable, /*!< Quad Enable command */ + kDeviceConfigCmdType_Spi2Xpi, /*!< Switch from SPI to DPI/QPI/OPI mode */ + kDeviceConfigCmdType_Xpi2Spi, /*!< Switch from DPI/QPI/OPI to SPI mode */ + kDeviceConfigCmdType_Spi2NoCmd, /*!< Switch to 0-4-4/0-8-8 mode */ + kDeviceConfigCmdType_Reset, /*!< Reset device command */ +}; + +/*! @brief Defintions for FLEXSPI Serial Clock Frequency */ +enum _flexspi_serial_clk_freq +{ + kFLEXSPISerialClk_NoChange = 0U, + kFLEXSPISerialClk_30MHz = 1U, + kFLEXSPISerialClk_50MHz = 2U, + kFLEXSPISerialClk_60MHz = 3U, + kFLEXSPISerialClk_75MHz = 4U, + kFLEXSPISerialClk_80MHz = 5U, + kFLEXSPISerialClk_100MHz = 6U, + kFLEXSPISerialClk_133MHz = 7U, + kFLEXSPISerialClk_166MHz = 8U, + kFLEXSPISerialClk_200MHz = 9U, +}; + +/*! @brief Misc feature bit definitions */ +enum +{ + kFLEXSPIMiscOffset_DiffClkEnable = 0U, /*!< Bit for Differential clock enable */ + kFLEXSPIMiscOffset_Ck2Enable = 1U, /*!< Bit for CK2 enable */ + kFLEXSPIMiscOffset_ParallelEnable = 2U, /*!< Bit for Parallel mode enable */ + kFLEXSPIMiscOffset_WordAddressableEnable = 3U, /*!< Bit for Word Addressable enable */ + kFLEXSPIMiscOffset_SafeConfigFreqEnable = 4U, /*!< Bit for Safe Configuration Frequency enable */ + kFLEXSPIMiscOffset_PadSettingOverrideEnable = 5U, /*!< Bit for Pad setting override enable */ + kFLEXSPIMiscOffset_DdrModeEnable = 6U, /*!< Bit for DDR clock confiuration indication. */ + kFLEXSPIMiscOffset_UseValidTimeForAllFreq = 7U, /*!< Bit for DLLCR settings under all modes */ +}; + +enum +{ + kSerialNorType_StandardSPI, /*!< Device that support Standard SPI and Extended SPI mode */ + kSerialNorType_HyperBus, /*!< Device that supports HyperBus only */ + kSerialNorType_XPI, /*!< Device that works under DPI, QPI or OPI mode */ + kSerialNorType_NoCmd, /*!< Device that works under No command mode (XIP mode/Performance Enhance + mode/continous read mode) */ +}; + +/*@}*/ + +/*! + * @name FLEXSPI NOR Configuration + * @{ + */ + +/*! @brief FLEXSPI LUT Sequence structure */ +typedef struct _flexspi_lut_seq +{ + uint8_t seqNum; /*!< Sequence Number, valid number: 1-16 */ + uint8_t seqId; /*!< Sequence Index, valid number: 0-15 */ + uint16_t reserved; +} flexspi_lut_seq_t; + +typedef struct +{ + uint8_t time_100ps; /*!< Data valid time, in terms of 100ps */ + uint8_t delay_cells; /*!< Data valid time, in terms of delay cells */ +} flexspi_dll_time_t; + +/*! @brief FLEXSPI Memory Configuration Block */ +typedef struct _flexspi_mem_config +{ + uint32_t tag; /*!< [0x000-0x003] Tag, fixed value 0x42464346UL */ + uint32_t version; /*!< [0x004-0x007] Version,[31:24] -'V', [23:16] - Major, [15:8] - Minor, [7:0] - bugfix */ + uint32_t reserved0; /*!< [0x008-0x00b] Reserved for future use */ + uint8_t readSampleClkSrc; /*!< [0x00c-0x00c] Read Sample Clock Source, valid value: 0/1/3 */ + uint8_t csHoldTime; /*!< [0x00d-0x00d] Data hold time, default value: 3 */ + uint8_t csSetupTime; /*!< [0x00e-0x00e] Date setup time, default value: 3 */ + uint8_t columnAddressWidth; /*!< [0x00f-0x00f] Column Address with, for HyperBus protocol, it is fixed to 3, For + Serial NAND, need to refer to datasheet */ + uint8_t deviceModeCfgEnable; /*!< [0x010-0x010] Device Mode Configure enable flag, 1 - Enable, 0 - Disable */ + uint8_t deviceModeType; /*!< [0x011-0x011] Specify the configuration command type:Quad Enable, DPI/QPI/OPI switch, + Generic configuration, etc. */ + uint16_t waitTimeCfgCommands; /*!< [0x012-0x013] Wait time for all configuration commands, unit: 100us, Used for + DPI/QPI/OPI switch or reset command */ + flexspi_lut_seq_t deviceModeSeq; /*!< [0x014-0x017] Device mode sequence info, [7:0] - LUT sequence id, [15:8] - LUt + sequence number, [31:16] Reserved */ + uint32_t deviceModeArg; /*!< [0x018-0x01b] Argument/Parameter for device configuration */ + uint8_t configCmdEnable; /*!< [0x01c-0x01c] Configure command Enable Flag, 1 - Enable, 0 - Disable */ + uint8_t configModeType[3]; /*!< [0x01d-0x01f] Configure Mode Type, similar as deviceModeTpe */ + flexspi_lut_seq_t + configCmdSeqs[3]; /*!< [0x020-0x02b] Sequence info for Device Configuration command, similar as deviceModeSeq */ + uint32_t reserved1; /*!< [0x02c-0x02f] Reserved for future use */ + uint32_t configCmdArgs[3]; /*!< [0x030-0x03b] Arguments/Parameters for device Configuration commands */ + uint32_t reserved2; /*!< [0x03c-0x03f] Reserved for future use */ + uint32_t controllerMiscOption; /*!< [0x040-0x043] Controller Misc Options, see Misc feature bit definitions for more + details */ + uint8_t deviceType; /*!< [0x044-0x044] Device Type: See Flash Type Definition for more details */ + uint8_t sflashPadType; /*!< [0x045-0x045] Serial Flash Pad Type: 1 - Single, 2 - Dual, 4 - Quad, 8 - Octal */ + uint8_t serialClkFreq; /*!< [0x046-0x046] Serial Flash Frequencey, device specific definitions, See System Boot + Chapter for more details */ + uint8_t + lutCustomSeqEnable; /*!< [0x047-0x047] LUT customization Enable, it is required if the program/erase cannot + be done using 1 LUT sequence, currently, only applicable to HyperFLASH */ + uint32_t reserved3[2]; /*!< [0x048-0x04f] Reserved for future use */ + uint32_t sflashA1Size; /*!< [0x050-0x053] Size of Flash connected to A1 */ + uint32_t sflashA2Size; /*!< [0x054-0x057] Size of Flash connected to A2 */ + uint32_t sflashB1Size; /*!< [0x058-0x05b] Size of Flash connected to B1 */ + uint32_t sflashB2Size; /*!< [0x05c-0x05f] Size of Flash connected to B2 */ + uint32_t csPadSettingOverride; /*!< [0x060-0x063] CS pad setting override value */ + uint32_t sclkPadSettingOverride; /*!< [0x064-0x067] SCK pad setting override value */ + uint32_t dataPadSettingOverride; /*!< [0x068-0x06b] data pad setting override value */ + uint32_t dqsPadSettingOverride; /*!< [0x06c-0x06f] DQS pad setting override value */ + uint32_t timeoutInMs; /*!< [0x070-0x073] Timeout threshold for read status command */ + uint32_t commandInterval; /*!< [0x074-0x077] CS deselect interval between two commands */ + flexspi_dll_time_t dataValidTime[2]; /*!< [0x078-0x07b] CLK edge to data valid time for PORT A and PORT B */ + uint16_t busyOffset; /*!< [0x07c-0x07d] Busy offset, valid value: 0-31 */ + uint16_t busyBitPolarity; /*!< [0x07e-0x07f] Busy flag polarity, 0 - busy flag is 1 when flash device is busy, 1 - + busy flag is 0 when flash device is busy */ + uint32_t lookupTable[64]; /*!< [0x080-0x17f] Lookup table holds Flash command sequences */ + flexspi_lut_seq_t lutCustomSeq[12]; /*!< [0x180-0x1af] Customizable LUT Sequences */ + uint32_t reserved4[4]; /*!< [0x1b0-0x1bf] Reserved for future use */ +} flexspi_mem_config_t; + +/*! @brief Serial NOR configuration block */ +typedef struct _flexspi_nor_config +{ + flexspi_mem_config_t memConfig; /*!< Common memory configuration info via FLEXSPI */ + uint32_t pageSize; /*!< Page size of Serial NOR */ + uint32_t sectorSize; /*!< Sector size of Serial NOR */ + uint8_t ipcmdSerialClkFreq; /*!< Clock frequency for IP command */ + uint8_t isUniformBlockSize; /*!< Sector/Block size is the same */ + uint8_t isDataOrderSwapped; /*!< Data order (D0, D1, D2, D3) is swapped (D1,D0, D3, D2) */ + uint8_t reserved0[1]; /*!< Reserved for future use */ + uint8_t serialNorType; /*!< Serial NOR Flash type: 0/1/2/3 */ + uint8_t needExitNoCmdMode; /*!< Need to exit NoCmd mode before other IP command */ + uint8_t halfClkForNonReadCmd; /*!< Half the Serial Clock for non-read command: true/false */ + uint8_t needRestoreNoCmdMode; /*!< Need to Restore NoCmd mode after IP commmand execution */ + uint32_t blockSize; /*!< Block size */ + uint32_t reserve2[11]; /*!< Reserved for future use */ +} flexspi_nor_config_t; + +/*@}*/ + +/*! @brief Manufacturer ID */ +enum +{ + kSerialFlash_ISSI_ManufacturerID = 0x9DU, /*!< Manufacturer ID of the ISSI serial flash */ + kSerialFlash_Adesto_ManufacturerID = 0x1F, /*!< Manufacturer ID of the Adesto Technologies serial flash*/ + kSerialFlash_Winbond_ManufacturerID = 0xEFU, /*!< Manufacturer ID of the Winbond serial flash */ + kSerialFlash_Cypress_ManufacturerID = 0x01U, /*!< Manufacturer ID for Cypress */ +}; + +/*! @brief ROM FLEXSPI NOR flash status */ +enum _flexspi_nor_status +{ + kStatus_ROM_FLEXSPI_SequenceExecutionTimeout = + MAKE_STATUS(kROM_StatusGroup_FLEXSPI, 0), /*!< Status for Sequence Execution timeout */ + kStatus_ROM_FLEXSPI_InvalidSequence = MAKE_STATUS(kROM_StatusGroup_FLEXSPI, 1), /*!< Status for Invalid Sequence */ + kStatus_ROM_FLEXSPI_DeviceTimeout = MAKE_STATUS(kROM_StatusGroup_FLEXSPI, 2), /*!< Status for Device timeout */ + kStatus_FLEXSPINOR_DTRRead_DummyProbeFailed = + MAKE_STATUS(kROM_StatusGroup_FLEXSPINOR, 10), /*!< Status for DDR Read dummy probe failure */ + kStatus_ROM_FLEXSPINOR_SFDP_NotFound = + MAKE_STATUS(kROM_StatusGroup_FLEXSPINOR, 7), /*!< Status for SFDP read failure */ + kStatus_ROM_FLEXSPINOR_Flash_NotFound = + MAKE_STATUS(kROM_StatusGroup_FLEXSPINOR, 9), /*!< Status for Flash detection failure */ +}; + +typedef enum _flexspi_operation +{ + kFLEXSPIOperation_Command, /*!< FLEXSPI operation: Only command, both TX and RX buffer are ignored. */ + kFLEXSPIOperation_Config, /*!< FLEXSPI operation: Configure device mode, the TX FIFO size is fixed in LUT. */ + kFLEXSPIOperation_Write, /*!< FLEXSPI operation: Write, only TX buffer is effective */ + kFLEXSPIOperation_Read, /*!< FLEXSPI operation: Read, only Rx Buffer is effective. */ + kFLEXSPIOperation_End = kFLEXSPIOperation_Read, +} flexspi_operation_t; + +/*! @brief FLEXSPI Transfer Context */ +typedef struct _flexspi_xfer +{ + flexspi_operation_t operation; /*!< FLEXSPI operation */ + uint32_t baseAddress; /*!< FLEXSPI operation base address */ + uint32_t seqId; /*!< Sequence Id */ + uint32_t seqNum; /*!< Sequence Number */ + bool isParallelModeEnable; /*!< Is a parallel transfer */ + uint32_t *txBuffer; /*!< Tx buffer */ + uint32_t txSize; /*!< Tx size in bytes */ + uint32_t *rxBuffer; /*!< Rx buffer */ + uint32_t rxSize; /*!< Rx size in bytes */ +} flexspi_xfer_t; + +#ifdef __cplusplus +extern "C" { +#endif + + +/*! + * @name Initialization + * @{ + */ + +/*! + * @brief Initialize Serial NOR flash via FLEXSPI + * + * This function checks and initializes the FLEXSPI module for the other FLEXSPI APIs. + * + * @param instance storge the instance of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * + * @retval kStatus_Success Api was executed succesfuly. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + * @retval kStatus_ROM_FLEXSPI_DeviceTimeout the device timeout + */ +status_t ROM_FLEXSPI_NorFlash_Init(uint32_t instance, flexspi_nor_config_t *config); + +/*@}*/ + +/*! + * @name Programming + * @{ + */ +/*! + * @brief Program data to Serial NOR flash via FLEXSPI. + * + * This function programs the NOR flash memory with the dest address for a given + * flash area as determined by the dst address and the length. + * + * @param instance storge the instance of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param dstAddr A pointer to the desired flash memory to be programmed. + * NOTE: + * It is recommended that use page aligned access; + * If the dstAddr is not aligned to page,the driver automatically + * aligns address down with the page address. + * @param src A pointer to the source buffer of data that is to be programmed + * into the NOR flash. + * + * @retval kStatus_Success Api was executed succesfuly. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + * @retval kStatus_ROM_FLEXSPI_DeviceTimeout the device timeout + */ +status_t ROM_FLEXSPI_NorFlash_ProgramPage(uint32_t instance, + flexspi_nor_config_t *config, + uint32_t dstAddr, + const uint32_t *src); + +/*@}*/ + +/*! + * @name Erasing + * @{ + */ +#if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_SECTOR) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_SECTOR +/*! + * @brief Erase one sector specified by address + * + * This function erases one of NOR flash sectors based on the desired address. + * + * @param instance storge the index of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param address The start address of the desired NOR flash memory to be erased. + * NOTE: + * It is recommended that use sector-aligned access nor device; + * If dstAddr is not aligned with the sector,The driver automatically + * aligns address down with the sector address. + * + * @retval kStatus_Success Api was executed succesfuly. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + * @retval kStatus_ROM_FLEXSPI_DeviceTimeout the device timeout + */ +status_t ROM_FLEXSPI_NorFlash_EraseSector(uint32_t instance, flexspi_nor_config_t *config, uint32_t address); +#endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_SECTOR */ + +#if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_ALL) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_ALL +/*! + * @brief Erase all the Serial NOR flash connected on FLEXSPI. + * + * @param instance storge the instance of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * + * @retval kStatus_Success Api was executed succesfuly. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + * @retval kStatus_ROM_FLEXSPI_DeviceTimeout the device timeout + */ +status_t ROM_FLEXSPI_NorFlash_EraseAll(uint32_t instance, flexspi_nor_config_t *config); +#endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_ALL */ + +/*! + * @brief Erase Flash Region specified by address and length + * + * This function erases the appropriate number of flash sectors based on the + * desired start address and length. + * + * @param instance storge the index of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param start The start address of the desired NOR flash memory to be erased. + * NOTE: + * It is recommended that use sector-aligned access NOR flash; + * If dstAddr is not aligned with the sector,the driver automatically + * aligns address down with the sector address. + * @param length The length, given in bytes to be erased. + * NOTE: + * It is recommended that use sector-aligned access NOR flash; + * If length is not aligned with the sector,the driver automatically + * aligns up with the sector. + * @retval kStatus_Success Api was executed succesfuly. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + * @retval kStatus_ROM_FLEXSPI_DeviceTimeout the device timeout + */ +status_t ROM_FLEXSPI_NorFlash_Erase(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length); + +/*@}*/ + +/*! + * @name Command + * @{ + */ + +#if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_CMD_XFER) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_CMD_XFER +/*! + * @brief FLEXSPI command + * + * This function is used to perform the command write sequence to the NOR flash. + * + * @param instance storge the index of FLEXSPI. + * @param xfer A pointer to the storage FLEXSPI Transfer Context. + * + * @retval kStatus_Success Api was executed succesfuly. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + */ +status_t ROM_FLEXSPI_NorFlash_CommandXfer(uint32_t instance, flexspi_xfer_t *xfer); +#endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_CMD_XFER */ +/*@}*/ + +/*! + * @name UpdateLut + * @{ + */ +#if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_UPDATE_LUT) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_UPDATE_LUT +/*! + * @brief Configure FLEXSPI Lookup table + * + * @param instance storge the index of FLEXSPI. + * @param seqIndex storge the sequence Id. + * @param lutBase A pointer to the look-up-table for command sequences. + * @param seqNumber storge sequence number. + * + * @retval kStatus_Success Api was executed succesfuly. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + */ +status_t ROM_FLEXSPI_NorFlash_UpdateLut(uint32_t instance, + uint32_t seqIndex, + const uint32_t *lutBase, + uint32_t seqNumber); +#endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_UPDATE_LUT */ + +/*@}*/ + +/*! + * @name ClearCache + * @{ + */ + +/*! + * @brief Software reset for the FLEXSPI logic. + * + * This function sets the software reset flags for both AHB and buffer domain and + * resets both AHB buffer and also IP FIFOs. + * + * @param instance storge the index of FLEXSPI. + */ +void ROM_FLEXSPI_NorFlash_ClearCache(uint32_t instance); + +/*@}*/ + +#ifdef __cplusplus +} +#endif + +/*! @}*/ + +#endif /* _FSL_ROMAPI_H_ */ diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h new file mode 100644 index 000000000..967559fa7 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h @@ -0,0 +1,27 @@ +/* + * Copyright 2018-2020 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** +* @file mcuboot.h +* @brief support bootloader function +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-04-03 +*/ + +#ifndef __MCUBOOT_H__ +#define __MCUBOOT_H__ + +#include "fsl_common.h" +#include "board.h" +#include "pin_mux.h" +#include "fsl_iomuxc.h" +#include "fsl_gpio.h" +#include "fsl_lpuart.h" + +#endif + diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/xip/fsl_flexspi_nor_boot.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/xip/fsl_flexspi_nor_boot.c index 503d56845..caac1f272 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/xip/fsl_flexspi_nor_boot.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/xip/fsl_flexspi_nor_boot.c @@ -73,1077 +73,282 @@ const BOOT_DATA_T boot_data = { #pragma location=".boot_hdr.dcd_data" #endif -const uint8_t dcd_sdram[1072] = { - /*0000*/ 0xD2, - 0x04, - 0x30, +const uint8_t dcd_sdram[] = { + /* HEADER */ + /* Tag */ + 0xD2, + /* Image Length */ + 0x04, 0x30, + /* Version */ 0x41, - 0xCC, - 0x03, - 0xAC, - 0x04, - 0x40, - 0x0F, - 0xC0, - 0x68, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - /*0010*/ 0x40, - 0x0F, - 0xC0, - 0x6C, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0x40, - 0x0F, - 0xC0, - 0x70, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - /*0020*/ 0x40, - 0x0F, - 0xC0, - 0x74, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0x40, - 0x0F, - 0xC0, - 0x78, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - /*0030*/ 0x40, - 0x0F, - 0xC0, - 0x7C, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - 0x40, - 0x0F, - 0xC0, - 0x80, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - /*0040*/ 0x40, - 0x0D, - 0x80, - 0x30, - 0x00, - 0x00, - 0x20, - 0x01, - 0x40, - 0x0D, - 0x81, - 0x00, - 0x00, - 0x1D, - 0x00, - 0x00, - /*0050*/ 0x40, - 0x0F, - 0xC0, - 0x14, - 0x00, - 0x01, - 0x0D, - 0x40, - 0x40, - 0x1F, - 0x80, - 0x14, - 0x00, - 0x00, - 0x00, - 0x00, - /*0060*/ 0x40, - 0x1F, - 0x80, - 0x18, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x1C, - 0x00, - 0x00, - 0x00, - 0x00, - /*0070*/ 0x40, - 0x1F, - 0x80, - 0x20, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x24, - 0x00, - 0x00, - 0x00, - 0x00, - /*0080*/ 0x40, - 0x1F, - 0x80, - 0x28, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x2C, - 0x00, - 0x00, - 0x00, - 0x00, - /*0090*/ 0x40, - 0x1F, - 0x80, - 0x30, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x34, - 0x00, - 0x00, - 0x00, - 0x00, - /*00a0*/ 0x40, - 0x1F, - 0x80, - 0x38, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x3C, - 0x00, - 0x00, - 0x00, - 0x00, - /*00b0*/ 0x40, - 0x1F, - 0x80, - 0x40, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x44, - 0x00, - 0x00, - 0x00, - 0x00, - /*00c0*/ 0x40, - 0x1F, - 0x80, - 0x48, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x4C, - 0x00, - 0x00, - 0x00, - 0x00, - /*00d0*/ 0x40, - 0x1F, - 0x80, - 0x50, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x54, - 0x00, - 0x00, - 0x00, - 0x00, - /*00e0*/ 0x40, - 0x1F, - 0x80, - 0x58, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x5C, - 0x00, - 0x00, - 0x00, - 0x00, - /*00f0*/ 0x40, - 0x1F, - 0x80, - 0x60, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x64, - 0x00, - 0x00, - 0x00, - 0x00, - /*0100*/ 0x40, - 0x1F, - 0x80, - 0x68, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x6C, - 0x00, - 0x00, - 0x00, - 0x00, - /*0110*/ 0x40, - 0x1F, - 0x80, - 0x70, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x74, - 0x00, - 0x00, - 0x00, - 0x00, - /*0120*/ 0x40, - 0x1F, - 0x80, - 0x78, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x7C, - 0x00, - 0x00, - 0x00, - 0x00, - /*0130*/ 0x40, - 0x1F, - 0x80, - 0x80, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x84, - 0x00, - 0x00, - 0x00, - 0x00, - /*0140*/ 0x40, - 0x1F, - 0x80, - 0x88, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x8C, - 0x00, - 0x00, - 0x00, - 0x00, - /*0150*/ 0x40, - 0x1F, - 0x80, - 0x90, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x94, - 0x00, - 0x00, - 0x00, - 0x00, - /*0160*/ 0x40, - 0x1F, - 0x80, - 0x98, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0x9C, - 0x00, - 0x00, - 0x00, - 0x00, - /*0170*/ 0x40, - 0x1F, - 0x80, - 0xA0, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0xA4, - 0x00, - 0x00, - 0x00, - 0x00, - /*0180*/ 0x40, - 0x1F, - 0x80, - 0xA8, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x80, - 0xAC, - 0x00, - 0x00, - 0x00, - 0x00, - /*0190*/ 0x40, - 0x1F, - 0x80, - 0xB0, - 0x00, - 0x00, - 0x00, - 0x10, - 0x40, - 0x1F, - 0x80, - 0xB4, - 0x00, - 0x00, - 0x00, - 0x00, - /*01a0*/ 0x40, - 0x1F, - 0x80, - 0xB8, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0x1F, - 0x82, - 0x04, - 0x00, - 0x01, - 0x10, - 0xF9, - /*01b0*/ 0x40, - 0x1F, - 0x82, - 0x08, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x0C, - 0x00, - 0x01, - 0x10, - 0xF9, - /*01c0*/ 0x40, - 0x1F, - 0x82, - 0x10, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x14, - 0x00, - 0x01, - 0x10, - 0xF9, - /*01d0*/ 0x40, - 0x1F, - 0x82, - 0x18, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x1C, - 0x00, - 0x01, - 0x10, - 0xF9, - /*01e0*/ 0x40, - 0x1F, - 0x82, - 0x20, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x24, - 0x00, - 0x01, - 0x10, - 0xF9, - /*01f0*/ 0x40, - 0x1F, - 0x82, - 0x28, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x2C, - 0x00, - 0x01, - 0x10, - 0xF9, - /*0200*/ 0x40, - 0x1F, - 0x82, - 0x30, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x34, - 0x00, - 0x01, - 0x10, - 0xF9, - /*0210*/ 0x40, - 0x1F, - 0x82, - 0x38, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x3C, - 0x00, - 0x01, - 0x10, - 0xF9, - /*0220*/ 0x40, - 0x1F, - 0x82, - 0x40, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x44, - 0x00, - 0x01, - 0x10, - 0xF9, - /*0230*/ 0x40, - 0x1F, - 0x82, - 0x48, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x4C, - 0x00, - 0x01, - 0x10, - 0xF9, - /*0240*/ 0x40, - 0x1F, - 0x82, - 0x50, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x54, - 0x00, - 0x01, - 0x10, - 0xF9, - /*0250*/ 0x40, - 0x1F, - 0x82, - 0x58, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x5C, - 0x00, - 0x01, - 0x10, - 0xF9, - /*0260*/ 0x40, - 0x1F, - 0x82, - 0x60, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x64, - 0x00, - 0x01, - 0x10, - 0xF9, - /*0270*/ 0x40, - 0x1F, - 0x82, - 0x68, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x6C, - 0x00, - 0x01, - 0x10, - 0xF9, - /*0280*/ 0x40, - 0x1F, - 0x82, - 0x70, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x74, - 0x00, - 0x01, - 0x10, - 0xF9, - /*0290*/ 0x40, - 0x1F, - 0x82, - 0x78, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x7C, - 0x00, - 0x01, - 0x10, - 0xF9, - /*02a0*/ 0x40, - 0x1F, - 0x82, - 0x80, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x84, - 0x00, - 0x01, - 0x10, - 0xF9, - /*02b0*/ 0x40, - 0x1F, - 0x82, - 0x88, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x8C, - 0x00, - 0x01, - 0x10, - 0xF9, - /*02c0*/ 0x40, - 0x1F, - 0x82, - 0x90, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x94, - 0x00, - 0x01, - 0x10, - 0xF9, - /*02d0*/ 0x40, - 0x1F, - 0x82, - 0x98, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0x9C, - 0x00, - 0x01, - 0x10, - 0xF9, - /*02e0*/ 0x40, - 0x1F, - 0x82, - 0xA0, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x1F, - 0x82, - 0xA4, - 0x00, - 0x01, - 0x10, - 0xF9, - /*02f0*/ 0x40, - 0x1F, - 0x82, - 0xA8, - 0x00, - 0x01, - 0x10, - 0xF9, - 0x40, - 0x2F, - 0x00, - 0x00, - 0x10, - 0x00, - 0x00, - 0x04, - /*0300*/ 0x40, - 0x2F, - 0x00, - 0x08, - 0x00, - 0x03, - 0x05, - 0x24, - 0x40, - 0x2F, - 0x00, - 0x0C, - 0x06, - 0x03, - 0x05, - 0x24, - /*0310*/ 0x40, - 0x2F, - 0x00, - 0x10, - 0x80, - 0x00, - 0x00, - 0x1B, - 0x40, - 0x2F, - 0x00, - 0x14, - 0x82, - 0x00, - 0x00, - 0x1B, - /*0320*/ 0x40, - 0x2F, - 0x00, - 0x18, - 0x84, - 0x00, - 0x00, - 0x1B, - 0x40, - 0x2F, - 0x00, - 0x1C, - 0x86, - 0x00, - 0x00, - 0x1B, - /*0330*/ 0x40, - 0x2F, - 0x00, - 0x20, - 0x90, - 0x00, - 0x00, - 0x21, - 0x40, - 0x2F, - 0x00, - 0x24, - 0xA0, - 0x00, - 0x00, - 0x19, - /*0340*/ 0x40, - 0x2F, - 0x00, - 0x28, - 0xA8, - 0x00, - 0x00, - 0x17, - 0x40, - 0x2F, - 0x00, - 0x2C, - 0xA9, - 0x00, - 0x00, - 0x1B, - /*0350*/ 0x40, - 0x2F, - 0x00, - 0x30, - 0x00, - 0x00, - 0x00, - 0x21, - 0x40, - 0x2F, - 0x00, - 0x04, - 0x00, - 0x00, - 0x79, - 0xA8, - /*0360*/ 0x40, - 0x2F, - 0x00, - 0x40, - 0x00, - 0x00, - 0x0F, - 0x31, - 0x40, - 0x2F, - 0x00, - 0x44, - 0x00, - 0x65, - 0x29, - 0x22, - /*0370*/ 0x40, - 0x2F, - 0x00, - 0x48, - 0x00, - 0x01, - 0x09, - 0x20, - 0x40, - 0x2F, - 0x00, - 0x4C, - 0x50, - 0x21, - 0x0A, - 0x08, - /*0380*/ 0x40, - 0x2F, - 0x00, - 0x80, - 0x00, - 0x00, - 0x00, - 0x21, - 0x40, - 0x2F, - 0x00, - 0x84, - 0x00, - 0x88, - 0x88, - 0x88, - /*0390*/ 0x40, - 0x2F, - 0x00, - 0x94, - 0x00, - 0x00, - 0x00, - 0x02, - 0x40, - 0x2F, - 0x00, - 0x98, - 0x00, - 0x00, - 0x00, - 0x00, - /*03a0*/ 0x40, - 0x2F, - 0x00, - 0x90, - 0x80, - 0x00, - 0x00, - 0x00, - 0x40, - 0x2F, - 0x00, - 0x9C, - 0xA5, - 0x5A, - 0x00, - 0x0F, - /*03b0*/ 0xCF, - 0x00, - 0x0C, - 0x1C, - 0x40, - 0x2F, - 0x00, - 0x3C, - 0x00, - 0x00, - 0x00, - 0x01, - 0xCC, - 0x00, - 0x14, - 0x04, - /*03c0*/ 0x40, - 0x2F, - 0x00, - 0x90, - 0x80, - 0x00, - 0x00, - 0x00, - 0x40, - 0x2F, - 0x00, - 0x9C, - 0xA5, - 0x5A, - 0x00, - 0x0C, - /*03d0*/ 0xCF, - 0x00, - 0x0C, - 0x1C, - 0x40, - 0x2F, - 0x00, - 0x3C, - 0x00, - 0x00, - 0x00, - 0x01, - 0xCC, - 0x00, - 0x14, - 0x04, - /*03e0*/ 0x40, - 0x2F, - 0x00, - 0x90, - 0x80, - 0x00, - 0x00, - 0x00, - 0x40, - 0x2F, - 0x00, - 0x9C, - 0xA5, - 0x5A, - 0x00, - 0x0C, - /*03f0*/ 0xCF, - 0x00, - 0x0C, - 0x1C, - 0x40, - 0x2F, - 0x00, - 0x3C, - 0x00, - 0x00, - 0x00, - 0x01, - 0xCC, - 0x00, - 0x1C, - 0x04, - /*0400*/ 0x40, - 0x2F, - 0x00, - 0xA0, - 0x00, - 0x00, - 0x00, - 0x33, - 0x40, - 0x2F, - 0x00, - 0x90, - 0x80, - 0x00, - 0x00, - 0x00, - /*0410*/ 0x40, - 0x2F, - 0x00, - 0x9C, - 0xA5, - 0x5A, - 0x00, - 0x0A, - 0xCF, - 0x00, - 0x0C, - 0x1C, - 0x40, - 0x2F, - 0x00, - 0x3C, - /*0420*/ 0x00, - 0x00, - 0x00, - 0x01, - 0xCC, - 0x00, - 0x0C, - 0x04, - 0x40, - 0x2F, - 0x00, - 0x4C, - 0x50, - 0x07, - 0x0A, - 0x09, + + /* COMMANDS */ + + /* group: 'Imported Commands' */ + /* #1.1-117, command header bytes for merged 'Write - value' command */ + 0xCC, 0x03, 0xAC, 0x04, + /* #1.1, command: write_value, address: CCM_CCGR0, value: 0xFFFFFFFF, size: 4 */ + 0x40, 0x0F, 0xC0, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, + /* #1.2, command: write_value, address: CCM_CCGR1, value: 0xFFFFFFFF, size: 4 */ + 0x40, 0x0F, 0xC0, 0x6C, 0xFF, 0xFF, 0xFF, 0xFF, + /* #1.3, command: write_value, address: CCM_CCGR2, value: 0xFFFFFFFF, size: 4 */ + 0x40, 0x0F, 0xC0, 0x70, 0xFF, 0xFF, 0xFF, 0xFF, + /* #1.4, command: write_value, address: CCM_CCGR3, value: 0xFFFFFFFF, size: 4 */ + 0x40, 0x0F, 0xC0, 0x74, 0xFF, 0xFF, 0xFF, 0xFF, + /* #1.5, command: write_value, address: CCM_CCGR4, value: 0xFFFFFFFF, size: 4 */ + 0x40, 0x0F, 0xC0, 0x78, 0xFF, 0xFF, 0xFF, 0xFF, + /* #1.6, command: write_value, address: CCM_CCGR5, value: 0xFFFFFFFF, size: 4 */ + 0x40, 0x0F, 0xC0, 0x7C, 0xFF, 0xFF, 0xFF, 0xFF, + /* #1.7, command: write_value, address: CCM_CCGR6, value: 0xFFFFFFFF, size: 4 */ + 0x40, 0x0F, 0xC0, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, + /* #1.8, command: write_value, address: CCM_ANALOG_PLL_SYS, value: 0x2001, size: 4 */ + 0x40, 0x0D, 0x80, 0x30, 0x00, 0x00, 0x20, 0x01, + /* #1.9, command: write_value, address: CCM_ANALOG_PFD_528, value: 0x1D0000, size: 4 */ + 0x40, 0x0D, 0x81, 0x00, 0x00, 0x1D, 0x00, 0x00, + /* #1.10, command: write_value, address: CCM_CBCDR, value: 0x10D40, size: 4 */ + 0x40, 0x0F, 0xC0, 0x14, 0x00, 0x01, 0x0D, 0x40, + /* #1.11, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_00, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x14, 0x00, 0x00, 0x00, 0x00, + /* #1.12, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_01, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x18, 0x00, 0x00, 0x00, 0x00, + /* #1.13, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_02, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x1C, 0x00, 0x00, 0x00, 0x00, + /* #1.14, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_03, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x20, 0x00, 0x00, 0x00, 0x00, + /* #1.15, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_04, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x24, 0x00, 0x00, 0x00, 0x00, + /* #1.16, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_05, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x28, 0x00, 0x00, 0x00, 0x00, + /* #1.17, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_06, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x2C, 0x00, 0x00, 0x00, 0x00, + /* #1.18, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_07, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x30, 0x00, 0x00, 0x00, 0x00, + /* #1.19, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_08, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, + /* #1.20, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_09, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x38, 0x00, 0x00, 0x00, 0x00, + /* #1.21, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_10, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x3C, 0x00, 0x00, 0x00, 0x00, + /* #1.22, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_11, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x40, 0x00, 0x00, 0x00, 0x00, + /* #1.23, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_12, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x44, 0x00, 0x00, 0x00, 0x00, + /* #1.24, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_13, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x48, 0x00, 0x00, 0x00, 0x00, + /* #1.25, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_14, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x4C, 0x00, 0x00, 0x00, 0x00, + /* #1.26, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_15, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, + /* #1.27, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_16, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x54, 0x00, 0x00, 0x00, 0x00, + /* #1.28, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_17, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x58, 0x00, 0x00, 0x00, 0x00, + /* #1.29, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_18, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x5C, 0x00, 0x00, 0x00, 0x00, + /* #1.30, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_19, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x60, 0x00, 0x00, 0x00, 0x00, + /* #1.31, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_20, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x64, 0x00, 0x00, 0x00, 0x00, + /* #1.32, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_21, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x68, 0x00, 0x00, 0x00, 0x00, + /* #1.33, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_22, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x6C, 0x00, 0x00, 0x00, 0x00, + /* #1.34, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_23, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x70, 0x00, 0x00, 0x00, 0x00, + /* #1.35, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_24, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x74, 0x00, 0x00, 0x00, 0x00, + /* #1.36, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_25, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x78, 0x00, 0x00, 0x00, 0x00, + /* #1.37, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_26, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x7C, 0x00, 0x00, 0x00, 0x00, + /* #1.38, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_27, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, + /* #1.39, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_28, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x84, 0x00, 0x00, 0x00, 0x00, + /* #1.40, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_29, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x88, 0x00, 0x00, 0x00, 0x00, + /* #1.41, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_30, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x8C, 0x00, 0x00, 0x00, 0x00, + /* #1.42, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_31, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x90, 0x00, 0x00, 0x00, 0x00, + /* #1.43, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_32, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x94, 0x00, 0x00, 0x00, 0x00, + /* #1.44, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_33, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x98, 0x00, 0x00, 0x00, 0x00, + /* #1.45, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_34, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0x9C, 0x00, 0x00, 0x00, 0x00, + /* #1.46, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_35, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0xA0, 0x00, 0x00, 0x00, 0x00, + /* #1.47, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_36, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0xA4, 0x00, 0x00, 0x00, 0x00, + /* #1.48, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_37, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0xA8, 0x00, 0x00, 0x00, 0x00, + /* #1.49, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_38, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0xAC, 0x00, 0x00, 0x00, 0x00, + /* #1.50, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_39, value: 0x10, size: 4 */ + 0x40, 0x1F, 0x80, 0xB0, 0x00, 0x00, 0x00, 0x10, + /* #1.51, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_40, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0xB4, 0x00, 0x00, 0x00, 0x00, + /* #1.52, command: write_value, address: IOMUXC_SW_MUX_CTL_PAD_GPIO_EMC_41, value: 0x00, size: 4 */ + 0x40, 0x1F, 0x80, 0xB8, 0x00, 0x00, 0x00, 0x00, + /* #1.53, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_00, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x04, 0x00, 0x01, 0x10, 0xF9, + /* #1.54, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_01, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x08, 0x00, 0x01, 0x10, 0xF9, + /* #1.55, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_02, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x0C, 0x00, 0x01, 0x10, 0xF9, + /* #1.56, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_03, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x10, 0x00, 0x01, 0x10, 0xF9, + /* #1.57, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_04, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x14, 0x00, 0x01, 0x10, 0xF9, + /* #1.58, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_05, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x18, 0x00, 0x01, 0x10, 0xF9, + /* #1.59, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_06, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x1C, 0x00, 0x01, 0x10, 0xF9, + /* #1.60, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_07, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x20, 0x00, 0x01, 0x10, 0xF9, + /* #1.61, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_08, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x24, 0x00, 0x01, 0x10, 0xF9, + /* #1.62, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_09, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x28, 0x00, 0x01, 0x10, 0xF9, + /* #1.63, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_10, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x2C, 0x00, 0x01, 0x10, 0xF9, + /* #1.64, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_11, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x30, 0x00, 0x01, 0x10, 0xF9, + /* #1.65, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_12, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x34, 0x00, 0x01, 0x10, 0xF9, + /* #1.66, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_13, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x38, 0x00, 0x01, 0x10, 0xF9, + /* #1.67, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_14, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x3C, 0x00, 0x01, 0x10, 0xF9, + /* #1.68, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_15, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x40, 0x00, 0x01, 0x10, 0xF9, + /* #1.69, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_16, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x44, 0x00, 0x01, 0x10, 0xF9, + /* #1.70, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_17, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x48, 0x00, 0x01, 0x10, 0xF9, + /* #1.71, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_18, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x4C, 0x00, 0x01, 0x10, 0xF9, + /* #1.72, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_19, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x50, 0x00, 0x01, 0x10, 0xF9, + /* #1.73, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_20, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x54, 0x00, 0x01, 0x10, 0xF9, + /* #1.74, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_21, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x58, 0x00, 0x01, 0x10, 0xF9, + /* #1.75, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_22, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x5C, 0x00, 0x01, 0x10, 0xF9, + /* #1.76, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_23, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x60, 0x00, 0x01, 0x10, 0xF9, + /* #1.77, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_24, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x64, 0x00, 0x01, 0x10, 0xF9, + /* #1.78, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_25, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x68, 0x00, 0x01, 0x10, 0xF9, + /* #1.79, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_26, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x6C, 0x00, 0x01, 0x10, 0xF9, + /* #1.80, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_27, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x70, 0x00, 0x01, 0x10, 0xF9, + /* #1.81, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_28, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x74, 0x00, 0x01, 0x10, 0xF9, + /* #1.82, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_29, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x78, 0x00, 0x01, 0x10, 0xF9, + /* #1.83, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_30, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x7C, 0x00, 0x01, 0x10, 0xF9, + /* #1.84, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_31, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x80, 0x00, 0x01, 0x10, 0xF9, + /* #1.85, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_32, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x84, 0x00, 0x01, 0x10, 0xF9, + /* #1.86, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_33, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x88, 0x00, 0x01, 0x10, 0xF9, + /* #1.87, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_34, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x8C, 0x00, 0x01, 0x10, 0xF9, + /* #1.88, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_35, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x90, 0x00, 0x01, 0x10, 0xF9, + /* #1.89, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_36, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x94, 0x00, 0x01, 0x10, 0xF9, + /* #1.90, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_37, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x98, 0x00, 0x01, 0x10, 0xF9, + /* #1.91, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_38, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0x9C, 0x00, 0x01, 0x10, 0xF9, + /* #1.92, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_39, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0xA0, 0x00, 0x01, 0x10, 0xF9, + /* #1.93, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_40, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0xA4, 0x00, 0x01, 0x10, 0xF9, + /* #1.94, command: write_value, address: IOMUXC_SW_PAD_CTL_PAD_GPIO_EMC_41, value: 0x110F9, size: 4 */ + 0x40, 0x1F, 0x82, 0xA8, 0x00, 0x01, 0x10, 0xF9, + /* #1.95, command: write_value, address: SEMC_MCR, value: 0x10000004, size: 4 */ + 0x40, 0x2F, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04, + /* #1.96, command: write_value, address: SEMC_BMCR0, value: 0x30524, size: 4 */ + 0x40, 0x2F, 0x00, 0x08, 0x00, 0x03, 0x05, 0x24, + /* #1.97, command: write_value, address: SEMC_BMCR1, value: 0x6030524, size: 4 */ + 0x40, 0x2F, 0x00, 0x0C, 0x06, 0x03, 0x05, 0x24, + /* #1.98, command: write_value, address: SEMC_BR0, value: 0x8000001B, size: 4 */ + 0x40, 0x2F, 0x00, 0x10, 0x80, 0x00, 0x00, 0x1B, + /* #1.99, command: write_value, address: SEMC_BR1, value: 0x8200001B, size: 4 */ + 0x40, 0x2F, 0x00, 0x14, 0x82, 0x00, 0x00, 0x1B, + /* #1.100, command: write_value, address: SEMC_BR2, value: 0x8400001B, size: 4 */ + 0x40, 0x2F, 0x00, 0x18, 0x84, 0x00, 0x00, 0x1B, + /* #1.101, command: write_value, address: SEMC_BR3, value: 0x8600001B, size: 4 */ + 0x40, 0x2F, 0x00, 0x1C, 0x86, 0x00, 0x00, 0x1B, + /* #1.102, command: write_value, address: SEMC_BR4, value: 0x90000021, size: 4 */ + 0x40, 0x2F, 0x00, 0x20, 0x90, 0x00, 0x00, 0x21, + /* #1.103, command: write_value, address: SEMC_BR5, value: 0xA0000019, size: 4 */ + 0x40, 0x2F, 0x00, 0x24, 0xA0, 0x00, 0x00, 0x19, + /* #1.104, command: write_value, address: SEMC_BR6, value: 0xA8000017, size: 4 */ + 0x40, 0x2F, 0x00, 0x28, 0xA8, 0x00, 0x00, 0x17, + /* #1.105, command: write_value, address: SEMC_BR7, value: 0xA900001B, size: 4 */ + 0x40, 0x2F, 0x00, 0x2C, 0xA9, 0x00, 0x00, 0x1B, + /* #1.106, command: write_value, address: SEMC_BR8, value: 0x21, size: 4 */ + 0x40, 0x2F, 0x00, 0x30, 0x00, 0x00, 0x00, 0x21, + /* #1.107, command: write_value, address: SEMC_IOCR, value: 0x79A8, size: 4 */ + 0x40, 0x2F, 0x00, 0x04, 0x00, 0x00, 0x79, 0xA8, + /* #1.108, command: write_value, address: SEMC_SDRAMCR0, value: 0xF31, size: 4 */ + 0x40, 0x2F, 0x00, 0x40, 0x00, 0x00, 0x0F, 0x31, + /* #1.109, command: write_value, address: SEMC_SDRAMCR1, value: 0x652922, size: 4 */ + 0x40, 0x2F, 0x00, 0x44, 0x00, 0x65, 0x29, 0x22, + /* #1.110, command: write_value, address: SEMC_SDRAMCR2, value: 0x10920, size: 4 */ + 0x40, 0x2F, 0x00, 0x48, 0x00, 0x01, 0x09, 0x20, + /* #1.111, command: write_value, address: SEMC_SDRAMCR3, value: 0x50210A08, size: 4 */ + 0x40, 0x2F, 0x00, 0x4C, 0x50, 0x21, 0x0A, 0x08, + /* #1.112, command: write_value, address: SEMC_DBICR0, value: 0x21, size: 4 */ + 0x40, 0x2F, 0x00, 0x80, 0x00, 0x00, 0x00, 0x21, + /* #1.113, command: write_value, address: SEMC_DBICR1, value: 0x888888, size: 4 */ + 0x40, 0x2F, 0x00, 0x84, 0x00, 0x88, 0x88, 0x88, + /* #1.114, command: write_value, address: SEMC_IPCR1, value: 0x02, size: 4 */ + 0x40, 0x2F, 0x00, 0x94, 0x00, 0x00, 0x00, 0x02, + /* #1.115, command: write_value, address: SEMC_IPCR2, value: 0x00, size: 4 */ + 0x40, 0x2F, 0x00, 0x98, 0x00, 0x00, 0x00, 0x00, + /* #1.116, command: write_value, address: SEMC_IPCR0, value: 0x80000000, size: 4 */ + 0x40, 0x2F, 0x00, 0x90, 0x80, 0x00, 0x00, 0x00, + /* #1.117, command: write_value, address: SEMC_IPCMD, value: 0xA55A000F, size: 4 */ + 0x40, 0x2F, 0x00, 0x9C, 0xA5, 0x5A, 0x00, 0x0F, + /* #2, command: check_any_bit_set, address: SEMC_INTR, value: 0x01, size: 4 */ + 0xCF, 0x00, 0x0C, 0x1C, 0x40, 0x2F, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x01, + /* #3.1-2, command header bytes for merged 'Write - value' command */ + 0xCC, 0x00, 0x14, 0x04, + /* #3.1, command: write_value, address: SEMC_IPCR0, value: 0x80000000, size: 4 */ + 0x40, 0x2F, 0x00, 0x90, 0x80, 0x00, 0x00, 0x00, + /* #3.2, command: write_value, address: SEMC_IPCMD, value: 0xA55A000C, size: 4 */ + 0x40, 0x2F, 0x00, 0x9C, 0xA5, 0x5A, 0x00, 0x0C, + /* #4, command: check_any_bit_set, address: SEMC_INTR, value: 0x01, size: 4 */ + 0xCF, 0x00, 0x0C, 0x1C, 0x40, 0x2F, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x01, + /* #5.1-2, command header bytes for merged 'Write - value' command */ + 0xCC, 0x00, 0x14, 0x04, + /* #5.1, command: write_value, address: SEMC_IPCR0, value: 0x80000000, size: 4 */ + 0x40, 0x2F, 0x00, 0x90, 0x80, 0x00, 0x00, 0x00, + /* #5.2, command: write_value, address: SEMC_IPCMD, value: 0xA55A000C, size: 4 */ + 0x40, 0x2F, 0x00, 0x9C, 0xA5, 0x5A, 0x00, 0x0C, + /* #6, command: check_any_bit_set, address: SEMC_INTR, value: 0x01, size: 4 */ + 0xCF, 0x00, 0x0C, 0x1C, 0x40, 0x2F, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x01, + /* #7.1-3, command header bytes for merged 'Write - value' command */ + 0xCC, 0x00, 0x1C, 0x04, + /* #7.1, command: write_value, address: SEMC_IPTXDAT, value: 0x33, size: 4 */ + 0x40, 0x2F, 0x00, 0xA0, 0x00, 0x00, 0x00, 0x33, + /* #7.2, command: write_value, address: SEMC_IPCR0, value: 0x80000000, size: 4 */ + 0x40, 0x2F, 0x00, 0x90, 0x80, 0x00, 0x00, 0x00, + /* #7.3, command: write_value, address: SEMC_IPCMD, value: 0xA55A000A, size: 4 */ + 0x40, 0x2F, 0x00, 0x9C, 0xA5, 0x5A, 0x00, 0x0A, + /* #8, command: check_any_bit_set, address: SEMC_INTR, value: 0x01, size: 4 */ + 0xCF, 0x00, 0x0C, 0x1C, 0x40, 0x2F, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x01, + /* #9, command: write_value, address: SEMC_SDRAMCR3, value: 0x50210A09, size: 4 */ + 0xCC, 0x00, 0x0C, 0x04, 0x40, 0x2F, 0x00, 0x4C, 0x50, 0x21, 0x0A, 0x09 }; diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/xip/fsl_flexspi_nor_flash.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/xip/fsl_flexspi_nor_flash.c index c5cc52dbc..a69ad5ede 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/xip/fsl_flexspi_nor_flash.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/xip/fsl_flexspi_nor_flash.c @@ -46,43 +46,64 @@ #pragma location=".boot_hdr.conf" #endif -const flexspi_nor_config_t Qspiflash_config = +#if defined(HYPERFLASH_BOOT) +const flexspi_nor_config_t hyperflash_config = { .memConfig = { .tag = FLEXSPI_CFG_BLK_TAG, .version = FLEXSPI_CFG_BLK_VERSION, - .readSampleClkSrc = kFlexSPIReadSampleClk_LoopbackInternally, + .readSampleClkSrc = kFlexSPIReadSampleClk_ExternalInputFromDqsPad, .csHoldTime = 3u, .csSetupTime = 3u, - .deviceModeCfgEnable = true, - .deviceModeType = 1,//Quad Enable command - .deviceModeSeq.seqNum = 1, - .deviceModeSeq.seqId = 4, - .deviceModeArg = 0x000200,//Set QE - .deviceType = kFlexSpiDeviceType_SerialNOR, - .sflashPadType = kSerialFlash_4Pads, - .serialClkFreq = kFlexSpiSerialClk_60MHz,//80MHz for Winbond, 100MHz for GD, 133MHz for ISSI - .sflashA1Size = 16u * 1024u * 1024u,//4MBytes + .columnAddressWidth = 3u, + + .controllerMiscOption = (1u << kFlexSpiMiscOffset_DdrModeEnable) | + (1u << kFlexSpiMiscOffset_WordAddressableEnable) | + (1u << kFlexSpiMiscOffset_SafeConfigFreqEnable) | + (1u << kFlexSpiMiscOffset_DiffClkEnable), + .sflashPadType = kSerialFlash_8Pads, + .serialClkFreq = kFlexSpiSerialClk_133MHz, + .sflashA1Size = 64u * 1024u * 1024u, .dataValidTime = {16u, 16u}, .lookupTable = - { -// //Fast Read Sequence -// [0] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x0B, RADDR_SDR, FLEXSPI_1PAD, 0x18), -// [1] = FLEXSPI_LUT_SEQ(DUMMY_SDR, FLEXSPI_1PAD, 0x08, READ_SDR, FLEXSPI_1PAD, 0x08), -// [2] = FLEXSPI_LUT_SEQ(JMP_ON_CS, 0, 0, 0, 0, 0), - //Quad Input/output read sequence - [0] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xEB, RADDR_SDR, FLEXSPI_4PAD, 0x18), - [1] = FLEXSPI_LUT_SEQ(DUMMY_SDR, FLEXSPI_4PAD, 0x06, READ_SDR, FLEXSPI_4PAD, 0x04), - [2] = FLEXSPI_LUT_SEQ(0, 0, 0, 0, 0, 0), - //Read Status - [1*4] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x05, READ_SDR, FLEXSPI_1PAD, 0x04), - //Write Enable - [3*4] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x06, STOP, 0, 0), - //Write status - [4*4] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x01, WRITE_SDR, FLEXSPI_1PAD, 0x2), - }, + { + + FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0xA0, RADDR_DDR, FLEXSPI_8PAD, 0x18), + FLEXSPI_LUT_SEQ(CADDR_DDR, FLEXSPI_8PAD, 0x10, DUMMY_DDR, FLEXSPI_8PAD, 0x06), + FLEXSPI_LUT_SEQ(READ_DDR, FLEXSPI_8PAD, 0x04, STOP, FLEXSPI_1PAD, 0x0), + }, }, - .pageSize = 256u, - .sectorSize = 4u * 1024u, + .pageSize = 512u, + .sectorSize = 256u * 1024u, + .blockSize = 256u * 1024u, + .isUniformBlockSize = true, }; + +#else +const flexspi_nor_config_t Qspiflash_config = +{ + .memConfig = + { + .tag = FLEXSPI_CFG_BLK_TAG, + .version = FLEXSPI_CFG_BLK_VERSION, + .readSampleClkSrc = kFlexSPIReadSampleClk_LoopbackFromDqsPad, + .csHoldTime = 3u, + .csSetupTime = 3u, + .sflashPadType = kSerialFlash_4Pads, + .serialClkFreq = kFlexSpiSerialClk_100MHz, + .sflashA1Size = 8u * 1024u * 1024u, + .lookupTable = + { + // Read LUTs + FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xEB, RADDR_SDR, FLEXSPI_4PAD, 0x18), + FLEXSPI_LUT_SEQ(DUMMY_SDR, FLEXSPI_4PAD, 0x06, READ_SDR, FLEXSPI_4PAD, 0x04), + }, + }, + .pageSize = 256u, + .sectorSize = 4u * 1024u, + .blockSize = 64u * 1024u, + .isUniformBlockSize = false, +}; + +#endif From d61579306376ff56ed08404916ce3a8e4cf3edcb Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Tue, 11 Apr 2023 11:10:00 +0800 Subject: [PATCH 02/15] =?UTF-8?q?1=E3=80=81Modifying=20Flash=20Partitions:?= =?UTF-8?q?=20=20=20=20Bootloader:0x60000000-0x6007FFFF=20512K=20=20=20=20?= =?UTF-8?q?APP:0x60100000-0x601FFFFF=201024K=20=20=20=20Backup:0x60300000-?= =?UTF-8?q?0x603FFFFF=201024K=20=20=20=20Download:0x60500000-0x605FFFFF=20?= =?UTF-8?q?1024K=20=20=20=20OTAFlag:0x60700000-0x6071FFFF=20128K=202?= =?UTF-8?q?=E3=80=81add=20four=20flash=20function:flash=5Ferase,flash=5Fwr?= =?UTF-8?q?ite,flash=5Fread=20and=20flash=5Fcopy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scripts/flash-mcuboot-app.ld | 2 +- .../board/xidatong-arm32/link-application.lds | 4 +- .../board/xidatong-arm32/link-bootloader.lds | 2 +- .../third_party_driver/common/flash.c | 140 +++++++++++++++++- .../third_party_driver/common/mcuboot.c | 8 +- .../third_party_driver/include/flash.h | 4 + 6 files changed, 148 insertions(+), 12 deletions(-) diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/scripts/flash-mcuboot-app.ld b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/scripts/flash-mcuboot-app.ld index 399e84745..e6bfa3be6 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/scripts/flash-mcuboot-app.ld +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/aiit_board/xidatong-arm32/scripts/flash-mcuboot-app.ld @@ -22,7 +22,7 @@ MEMORY { - flash (rx) : ORIGIN = 0x60040000, LENGTH = 0x00100000 + flash (rx) : ORIGIN = 0x60100000, LENGTH = 0x00100000 sram (rwx) : ORIGIN = 0x20200000, LENGTH = 0x00080000 itcm (rwx) : ORIGIN = 0x00000000, LENGTH = 0x00020000 dtcm (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000 diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-application.lds b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-application.lds index e42f2993e..6769453e6 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-application.lds +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-application.lds @@ -53,8 +53,8 @@ STACK_SIZE = 0x4000; /* Specify the memory areas */ MEMORY { - m_interrupts (RX) : ORIGIN = 0x60040000, LENGTH = 0x00000400 - m_text (RX) : ORIGIN = 0x60040400, LENGTH = 0x000FFC00 + m_interrupts (RX) : ORIGIN = 0x60100000, LENGTH = 0x00000400 + m_text (RX) : ORIGIN = 0x60100400, LENGTH = 0x000FFC00 m_data (RW) : ORIGIN = 0x20000000, LENGTH = 0x00020000 m_data2 (RW) : ORIGIN = 0x20200000, LENGTH = 0x00060000 diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-bootloader.lds b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-bootloader.lds index fea1de877..4ce000519 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-bootloader.lds +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/link-bootloader.lds @@ -58,7 +58,7 @@ MEMORY /*bootloader*/ m_interrupts (RX) : ORIGIN = 0x60002000, LENGTH = 0x00000400 - m_text (RX) : ORIGIN = 0x60002400, LENGTH = 0x0003DC00 + m_text (RX) : ORIGIN = 0x60002400, LENGTH = 0x0007DC00 m_data (RW) : ORIGIN = 0x20000000, LENGTH = 0x00020000 m_data2 (RW) : ORIGIN = 0x20200000, LENGTH = 0x00060000 diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c index bd9df1124..bf9278cb6 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c @@ -13,18 +13,20 @@ * @date 2023-04-03 */ +#include +#include #include "flash.h" -#include "stdio.h" -#include "xs_base.h" /******************************************************************************* * Definitions ******************************************************************************/ - +#define APP_FLASH_SIZE 0x100000 //Application package size is limited to 1M +#define FLASH_PAGE_SIZE 256 //每次写入256个字节 /******************************************************************************* * Prototypes ******************************************************************************/ - + +uint8_t buffer[FLASH_PAGE_SIZE]; //256 bytes buffer cache /******************************************************************************* * Variables ******************************************************************************/ @@ -301,4 +303,134 @@ status_t FLASH_Read(uint32_t addr, const uint8_t *buf, uint32_t len) __enable_irq(); return status; +} + + /** + * @brief 擦除flash指定地址指定长度的空间 + * @param start_addr: 开始地址 + * @param byte_cnt : 要擦除的字节数 + * @retval kStatus_Success:擦除成功 + */ +status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt) +{ + uint32_t addr; + status_t status; + + addr = start_addr; + while(addr < (byte_cnt + start_addr)) + { + status = FLASH_EraseSector(addr); + if(status != kStatus_Success) + { + return status; + } + addr += FLASH_GetSectorSize(); + } + return status; +} + + /** + * @brief 在flash指定地址写入指定长度的数据 + * @param start_addr: 开始地址 + * @param buf : 数据buffer + * @param byte_cnt : 要写入的字节数 + * @retval kStatus_Success:写入成功 + */ +status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt) +{ + return FLASH_WritePage(start_addr, buf, byte_cnt); +} + + /** + * @brief 在flash指定开始读取一定长度的数据到缓存中 + * @param start_addr: 开始地址 + * @param buf : 数据buffer + * @param byte_cnt : 要读取的字节数 + * @retval kStatus_Success:读取成功 + */ +status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len) +{ + /* For FlexSPI Memory ReadBack, use IP Command instead of AXI command for security */ + if((addr >= 0x60000000) && (addr < 0x70000000)) + { + return FLASH_Read(addr, buf, len); + } + + else + { + void* result = memcpy(buf, (void*)addr, len); + if(result == NULL) + { + return (status_t)kStatus_Fail; + } + else + { + return (status_t)kStatus_Success; + } + + } +} + + /** + * @brief 实现两块连续flash地址空间之间的数据拷贝 + * @param srcAddr: 源flash的起始地址 + * @param dstAddr : 目标flash的起始地址 + * @param imageSize : 要拷贝的flash空间大小,单位为字节 + * @retval kStatus_Success:拷贝成功 + */ +status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize) +{ + uint32_t PageNum, Remain, i; + status_t status; + + if((srcAddr == dstAddr) || imageSize > (APP_FLASH_SIZE + 1)) + { + return (status_t)kStatus_Fail; + } + + status = flash_erase(dstAddr,imageSize); + if(status != kStatus_Success) + { + KPrintf("Erase flash 0x%08x failure !\r\n",dstAddr); + return status; + } + + PageNum = imageSize/FLASH_PAGE_SIZE; + Remain = imageSize%FLASH_PAGE_SIZE; + + for(i=0;iVTOR = (uint32_t)0x60040000; + SerialPutString("BOOTLOADER START AND JUMP TO APP[0x60100000]\n"); + SCB->VTOR = (uint32_t)0x60100000; JumpToApp(); } #endif \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h index 47b33596d..46b96f58f 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h @@ -27,6 +27,10 @@ status_t FLASH_EraseSector(uint32_t addr); status_t FLASH_Read(uint32_t addr, const uint8_t *buf, uint32_t len); uint32_t FLASH_Test(uint32_t startAddr, uint32_t len); uint32_t FLASH_GetProgramCmd(void); +status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt); +status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt); +status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len); +status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize); #endif From 85105cb65d6f2d458f45db86356cb2881aa6fc13 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Wed, 12 Apr 2023 19:59:35 +0800 Subject: [PATCH 03/15] Upgrading binary packages by iap on xidatong-arm32 --- .../third_party_driver/common/Makefile | 3 + .../third_party_driver/common/common.c | 275 ++++++++++++ .../third_party_driver/common/flash.c | 196 ++++++++- .../third_party_driver/common/mcuboot.c | 90 ++-- .../third_party_driver/common/ymodem.c | 391 ++++++++++++++++++ .../third_party_driver/include/common.h | 47 +++ .../third_party_driver/include/flash.h | 22 +- .../third_party_driver/include/ymodem.h | 58 +++ 8 files changed, 1042 insertions(+), 40 deletions(-) create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/common.c create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/ymodem.c create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/common.h create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/ymodem.h diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile index 463b67808..e27bfd216 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile @@ -6,6 +6,9 @@ endif ifeq ($(CONFIG_BSP_USING_OTA),y) SRC_FILES += fsl_romapi.c flash.c mcuboot.c + ifeq ($(CONFIG_MCUBOOT_BOOTLOADER),y) + SRC_FILES += common.c ymodem.c + endif endif include $(KERNEL_ROOT)/compiler.mk 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 new file mode 100644 index 000000000..133fd7c69 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/common.c @@ -0,0 +1,275 @@ + +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file: common.c +* @brief: file common.c +* @version: 1.0 +* @author: AIIT XUOS Lab +* @date: 2023/3/24 +*/ + + +#include "common.h" + +/** + * @brief Convert an Integer to a string + * @param str: The string + * @param intnum: The intger to be converted + * @retval None + */ +void Int2Str(uint8_t* str, int32_t intnum) +{ + uint32_t i, Div = 1000000000, j = 0, Status = 0; + + for (i = 0; i < 10; i++) + { + str[j++] = (intnum / Div) + 48; + + intnum = intnum % Div; + Div /= 10; + if ((str[j-1] == '0') & (Status == 0)) + { + j = 0; + } + else + { + Status++; + } + } +} + +/** + * @brief Convert a string to an integer + * @param inputstr: The string to be converted + * @param intnum: The intger value + * @retval 1: Correct + * 0: Error + */ +uint32_t Str2Int(uint8_t *inputstr, int32_t *intnum) +{ + uint32_t i = 0, res = 0; + uint32_t val = 0; + + if (inputstr[0] == '0' && (inputstr[1] == 'x' || inputstr[1] == 'X')) + { + if (inputstr[2] == '\0') + { + return 0; + } + for (i = 2; i < 11; i++) + { + if (inputstr[i] == '\0') + { + *intnum = val; + /* return 1; */ + res = 1; + break; + } + if (ISVALIDHEX(inputstr[i])) + { + val = (val << 4) + CONVERTHEX(inputstr[i]); + } + else + { + /* return 0, Invalid input */ + res = 0; + break; + } + } + /* over 8 digit hex --invalid */ + if (i >= 11) + { + res = 0; + } + } + else /* max 10-digit decimal input */ + { + for (i = 0;i < 11;i++) + { + if (inputstr[i] == '\0') + { + *intnum = val; + /* return 1 */ + res = 1; + break; + } + else if ((inputstr[i] == 'k' || inputstr[i] == 'K') && (i > 0)) + { + val = val << 10; + *intnum = val; + res = 1; + break; + } + else if ((inputstr[i] == 'm' || inputstr[i] == 'M') && (i > 0)) + { + val = val << 20; + *intnum = val; + res = 1; + break; + } + else if (ISVALIDDEC(inputstr[i])) + { + val = val * 10 + CONVERTDEC(inputstr[i]); + } + else + { + /* return 0, Invalid input */ + res = 0; + break; + } + } + /* Over 10 digit decimal --invalid */ + if (i >= 11) + { + res = 0; + } + } + + return res; +} + +/** + * @brief Get an integer from the HyperTerminal + * @param num: The inetger + * @retval 1: Correct + * 0: Error + */ +uint32_t GetIntegerInput(int32_t * num) +{ + uint8_t inputstr[16]; + + while (1) + { + GetInputString(inputstr); + if (inputstr[0] == '\0') continue; + if ((inputstr[0] == 'a' || inputstr[0] == 'A') && inputstr[1] == '\0') + { + Serial_PutString("User Cancelled \r\n"); + return 0; + } + + if (Str2Int(inputstr, num) == 0) + { + Serial_PutString("Error, Input again: \r\n"); + } + else + { + return 1; + } + } +} + +/** + * @brief Test to see if a key has been pressed on the HyperTerminal + * @param key: The key pressed + * @retval 1: Correct + * 0: Error + */ +uint32_t SerialKeyPressed(uint8_t *key) +{ + if ((kLPUART_RxDataRegFullFlag)&LPUART_GetStatusFlags(LPUART1)) + { + *key = LPUART_ReadByte(LPUART1); + return 1; + } + else + { + return 0; + } +} + +/** + * @brief Get a key from the HyperTerminal + * @param None + * @retval The Key Pressed + */ +uint8_t GetKey(void) +{ + uint8_t key = 0; + + /* Waiting for user input */ + while (1) + { + if (SerialKeyPressed((uint8_t*)&key)) break; + } + return key; + +} + +/** + * @brief Print a character on the HyperTerminal + * @param c: The character to be printed + * @retval None + */ +void SerialPutChar(uint8_t c) +{ + LPUART_WriteByte(LPUART1,c); + while(!(kLPUART_TxDataRegEmptyFlag & LPUART_GetStatusFlags(LPUART1))) + { + } +} + +/** + * @brief Print a string on the HyperTerminal + * @param s: The string to be printed + * @retval None + */ +void Serial_PutString(uint8_t *s) +{ + while (*s != '\0') + { + SerialPutChar(*s); + s++; + } +} + +/** + * @brief Get Input string from the HyperTerminal + * @param buffP: The input string + * @retval None + */ +void GetInputString (uint8_t * buffP) +{ + uint32_t bytes_read = 0; + uint8_t c = 0; + do + { + c = GetKey(); + if (c == '\r') + break; + if (c == '\b') /* Backspace */ + { + if (bytes_read > 0) + { + Serial_PutString("\b \b"); + bytes_read --; + } + continue; + } + if (bytes_read >= CMD_STRING_SIZE ) + { + Serial_PutString("Command string size overflow\r\n"); + bytes_read = 0; + continue; + } + if (c >= 0x20 && c <= 0x7E) + { + buffP[bytes_read++] = c; + SerialPutChar(c); + } + } + while (1); + Serial_PutString(("\n\r")); + buffP[bytes_read] = '\0'; +} diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c index bf9278cb6..69f97ddf2 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c @@ -25,7 +25,7 @@ /******************************************************************************* * Prototypes ******************************************************************************/ - +uint8_t NorFlash_BUFFER[4096]; //4K buffer cache uint8_t buffer[FLASH_PAGE_SIZE]; //256 bytes buffer cache /******************************************************************************* * Variables @@ -264,13 +264,13 @@ status_t FLASH_EraseSector(uint32_t addr) * @param len : 字节数 * @retval kStatus_Success:完成 */ -status_t FLASH_WritePage(uint32_t addr, const uint8_t *buf, uint32_t len) +status_t FLASH_WritePage(uint32_t addr, const uint32_t *buf, uint32_t len) { status_t status; addr &= 0x0FFFFFFF; __disable_irq(); norConfig.pageSize = len; - status = ROM_FLEXSPI_NorFlash_ProgramPage(0, &norConfig, addr, (const uint32_t *)buf); + status = ROM_FLEXSPI_NorFlash_ProgramPage(0, &norConfig, addr, buf); __enable_irq(); return status; @@ -282,7 +282,7 @@ status_t FLASH_WritePage(uint32_t addr, const uint8_t *buf, uint32_t len) * @param len : 字节数 * @retval kStatus_Success:完成 */ -status_t FLASH_Read(uint32_t addr, const uint8_t *buf, uint32_t len) +status_t FLASH_Read(uint32_t addr, uint32_t *buf, uint32_t len) { status_t status; flexspi_xfer_t flashXfer; @@ -294,7 +294,7 @@ status_t FLASH_Read(uint32_t addr, const uint8_t *buf, uint32_t len) flashXfer.seqId = NOR_CMD_LUT_SEQ_IDX_READ; flashXfer.baseAddress = addr; flashXfer.isParallelModeEnable = false; - flashXfer.rxBuffer = (uint32_t *)buf; + flashXfer.rxBuffer = buf; flashXfer.rxSize = len; __disable_irq(); @@ -338,7 +338,7 @@ status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt) */ status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt) { - return FLASH_WritePage(start_addr, buf, byte_cnt); + return FLASH_WritePage(start_addr, (void *)buf, byte_cnt); } /** @@ -353,7 +353,7 @@ status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len) /* For FlexSPI Memory ReadBack, use IP Command instead of AXI command for security */ if((addr >= 0x60000000) && (addr < 0x70000000)) { - return FLASH_Read(addr, buf, len); + return FLASH_Read(addr, (void *)buf, len); } else @@ -433,4 +433,184 @@ status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize) } return (status_t)kStatus_Success; -} \ No newline at end of file +} + +status_t NOR_FLASH_Erase(uint32_t app_base_addr,uint32_t imageSize) +{ + uint16_t i; + uint32_t sectorNum = (imageSize%4096 != 0)? (imageSize/4096 + 1):(imageSize/4096); + + for(i=0;ipageRemain + { + pBuffer += pageRemain; + WriteAddr += pageRemain; + + NumByteToWrite -= pageRemain;//减去已经写入了的字节数 + if(NumByteToWrite > 256) + { + pageRemain = 256;//一次可以写入256个字节 + } + else + { + pageRemain = NumByteToWrite;//不够256个字节了 + } + } + } +} + +void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite) +{ + uint32_t secPos; + uint16_t secOff; + uint16_t secRemain; + uint16_t i; + uint8_t *NorFlash_BUF = 0; + + NorFlash_BUF = NorFlash_BUFFER;//RAM缓冲区4K + + WriteAddr &= 0x0FFFFFFF; + + secPos = WriteAddr/SECTOR_SIZE;//扇区地址 + secOff = WriteAddr%SECTOR_SIZE;//在扇区内的偏移 + secRemain = SECTOR_SIZE - secOff;//扇区剩余空间大小 + + if(NumByteToWrite <= secRemain) + { + secRemain = NumByteToWrite;//不大于4096个字节 + } + while(1) + { + FLASH_Read(FLASH_BASE + secPos*SECTOR_SIZE, (void *)NorFlash_BUF, SECTOR_SIZE);//读出整个扇区的内容 + for(i=0;i 4096) + { + secRemain = 4096;//下一个扇区还是写不完 + } + else + { + secRemain = NumByteToWrite;//下一个扇区可以写完了 + } + } + } +} + +#ifndef USE_HIGHT_SPEED_TRANS +uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength) +{ + uint32_t WriteAddr; + WriteAddr = *FlashAddress; + NorFlash_Write(Data,WriteAddr,DataLength); + *FlashAddress += DataLength; + return 0; +} +#else +uint8_t packetNum = 0; +uint32_t dataLen = 0; +uint32_t WriteAddr; +uint8_t dataBuff[5*1024]; +uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength,uint8_t doneFlag) +{ + if(!doneFlag) + { + memcpy(&dataBuff[dataLen],Data,DataLength); + dataLen += DataLength; + packetNum ++; + if(1 == packetNum) + { + WriteAddr = *FlashAddress; + } + + if(dataLen>=4096) + { + NorFlash_Write(dataBuff,WriteAddr,dataLen); + packetNum = 0; + dataLen = 0; + } + *FlashAddress += DataLength; + } + else + { + NorFlash_Write(dataBuff,WriteAddr,dataLen); + packetNum = 0; + dataLen = 0; + } + return (0); +} +#endif \ No newline at end of file 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 19e5ef712..617781a53 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 @@ -12,22 +12,16 @@ * @author AIIT XUOS Lab * @date 2023-04-03 */ - + +#include +#include #include "flash.h" -#include "stdint.h" #include "mcuboot.h" +#include "ymodem.h" +#include "common.h" #ifdef MCUBOOT_BOOTLOADER -static void JumpToApp(void) -{ - asm volatile("LDR R0, = 0x60100000"); - asm volatile("LDR R0, [R0]"); - asm volatile("MOV SP, R0"); - - asm volatile("LDR R0, = 0x60100000+4"); - asm volatile("LDR R0, [R0]"); - asm volatile("BX R0"); -} +extern void ImxrtMsDelay(uint32 ms); static uint32_t UartSrcFreq(void) { @@ -55,32 +49,72 @@ static void UartConfig(void) LPUART_Init(LPUART1, &config, UartSrcFreq()); } -static void SerialPutC(uint8_t c) +static void jump_to_application(void) { - LPUART_WriteByte(LPUART1, c); - while(!(kLPUART_TxDataRegEmptyFlag & LPUART_GetStatusFlags(LPUART1))) - { - } -} + SCB->VTOR = (uint32_t)0x60100000; -static void SerialPutString(uint8_t *s) -{ - while (*s != '\0') { - SerialPutC(*s); - s++; - } + asm volatile("LDR R0, = 0x60100000"); + asm volatile("LDR R0, [R0]"); + asm volatile("MOV SP, R0"); + + asm volatile("LDR R0, = 0x60100000+4"); + asm volatile("LDR R0, [R0]"); + asm volatile("BX R0"); } void BootLoaderJumpApp(void) { + uint8_t ch1, ch2; + uint32_t ret; + uint32_t timeout = 500; + BOARD_ConfigMPU(); BOARD_InitPins(); BOARD_BootClockRUN(); - UartConfig(); + SysTick_Config(SystemCoreClock / TICK_PER_SECOND); + + Serial_PutString("Please press 'space' key into menu in 5s !!!\r\n"); - SerialPutString("BOOTLOADER START AND JUMP TO APP[0x60100000]\n"); - SCB->VTOR = (uint32_t)0x60100000; - JumpToApp(); + while(timeout) + { + ret = (SerialKeyPressed((uint8_t*)&ch1)); + if(ret) break; + timeout--; + ImxrtMsDelay(10); + } + + while(1) + { + if((ret)&&(ch1 == 0x20)) + { + Serial_PutString("\r\nPlease slecet:"); + Serial_PutString("\r\n 1:run app"); + Serial_PutString("\r\n 2:update app"); + Serial_PutString("\r\n 3:reboot \r\n"); + + ch2 = GetKey(); + switch(ch2) + { + case 0x31: + jump_to_application(); + break; + case 0x32: + FLASH_Init(); + SerialDownload(); + FLASH_DeInit(); + break; + case 0x33: + __set_FAULTMASK(1); + NVIC_SystemReset(); + default: + break; + } + } + else + { + jump_to_application(); + } + } } #endif \ No newline at end of file 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 new file mode 100644 index 000000000..fff3ef2be --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/ymodem.c @@ -0,0 +1,391 @@ + +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file: ymodem.c +* @brief: file ymodem.c +* @version: 1.0 +* @author: AIIT XUOS Lab +* @date: 2023/3/24 +*/ + + +#include "common.h" +#include "ymodem.h" +#include "string.h" +#include "flash.h" + +#define BL_APP_VECTOR_TABLE_ADDRESS 0x60100000 + +uint8_t tab_1024[1024] ={0}; +uint8_t FileName[FILE_NAME_LENGTH]; + + +/** + * @brief Receive byte from sender + * @param c: Character + * @param timeout: Timeout + * @retval 0: Byte received + * -1: Timeout + */ +static int32_t Receive_Byte (uint8_t *c, uint32_t timeout) +{ + while (timeout-- > 0) + { + if (SerialKeyPressed(c) == 1) + { + return 0; + } + } + return -1; +} + +/** + * @brief Send a byte + * @param c: Character + * @retval 0: Byte sent + */ +static uint32_t Send_Byte (uint8_t c) +{ + SerialPutChar(c); + return 0; +} + +/** + * @brief Update CRC16 for input byte + * @param CRC input value + * @param input byte + * @retval Updated CRC value + */ +uint16_t UpdateCRC16(uint16_t crcIn, uint8_t byte) +{ + uint32_t crc = crcIn; + uint32_t in = byte|0x100; + + do + { + crc <<= 1; + in <<= 1; + + if(in&0x100) + { + ++crc; + } + + if(crc&0x10000) + { + crc ^= 0x1021; + } + } while(!(in&0x10000)); + + return (crc&0xffffu); +} + +/** + * @brief Cal CRC16 for YModem Packet + * @param data + * @param length + * @retval CRC value + */ +uint16_t Cal_CRC16(const uint8_t* data, uint32_t size) +{ + uint32_t crc = 0; + const uint8_t* dataEnd = data+size; + + while(data0: packet length + * @retval 0: normally return + * -1: timeout or packet error + * 1: abort by user + */ +static int32_t Receive_Packet (uint8_t *data, int32_t *length, uint32_t timeout) +{ + uint16_t i, packet_size, computedcrc; + uint8_t c; + *length = 0; + if (Receive_Byte(&c, timeout) != 0) + { + return -1; + } + switch (c) + { + case SOH: + packet_size = PACKET_SIZE; + break; + case STX: + packet_size = PACKET_1K_SIZE; + break; + case EOT: + return 0; + case CA: + if ((Receive_Byte(&c, timeout) == 0) && (c == CA)) + { + *length = -1; + return 0; + } + else + { + return -1; + } + case ABORT1: + case ABORT2: + return 1; + default: + return -1; + } + *data = c; + for (i = 1; i < (packet_size + PACKET_OVERHEAD); i ++) + { + if (Receive_Byte(data + i, timeout) != 0) + { + return -1; + } + } + if (data[PACKET_SEQNO_INDEX] != ((data[PACKET_SEQNO_COMP_INDEX] ^ 0xff) & 0xff)) + { + return -1; + } + + /* Compute the CRC */ + computedcrc = Cal_CRC16(&data[PACKET_HEADER], (uint32_t)packet_size); + /* Check that received CRC match the already computed CRC value + data[packet_size+3]<<8) | data[packet_size+4] contains the received CRC + computedcrc contains the computed CRC value */ + if (computedcrc != (uint16_t)((data[packet_size+3]<<8) | data[packet_size+4])) + { + /* CRC error */ + return -1; + } + + *length = packet_size; + return 0; +} + +/** + * @brief Receive a file using the ymodem protocol + * @param buf: Address of the first byte + * @retval The size of the file + */ +int32_t Ymodem_Receive (uint8_t *buf) +{ + uint8_t packet_data[PACKET_1K_SIZE + PACKET_OVERHEAD], file_size[FILE_SIZE_LENGTH], *file_ptr, *buf_ptr; + int32_t i, packet_length, session_done, file_done, packets_received, errors, session_begin, size = 0; + uint32_t flashdestination; + + /* Initialize flashdestination variable */ + flashdestination = BL_APP_VECTOR_TABLE_ADDRESS; + + for (session_done = 0, errors = 0, session_begin = 0; ;) + { + for (packets_received = 0, file_done = 0, buf_ptr = buf; ;) + { + switch (Receive_Packet(packet_data, &packet_length, NAK_TIMEOUT)) + { + case 0: + errors = 0; + switch (packet_length) + { + /* Abort by sender */ + case - 1: + Send_Byte(ACK); + return 0; + /* End of transmission */ + case 0: + Send_Byte(ACK); + file_done = 1; + break; + /* Normal packet */ + default: + if ((packet_data[PACKET_SEQNO_INDEX] & 0xff) != (packets_received & 0xff)) + { + Send_Byte(NAK); + } + else + { + if (packets_received == 0) + { + /* Filename packet */ + if (packet_data[PACKET_HEADER] != 0) + { + /* Filename packet has valid data */ + for (i = 0, file_ptr = packet_data + PACKET_HEADER; (*file_ptr != 0) && (i < FILE_NAME_LENGTH);) + { + FileName[i++] = *file_ptr++; + } + FileName[i++] = '\0'; + for (i = 0, file_ptr ++; (*file_ptr != ' ') && (i < (FILE_SIZE_LENGTH - 1));) + { + file_size[i++] = *file_ptr++; + } + file_size[i++] = '\0'; + Str2Int(file_size, &size); + + /* Test the size of the image to be sent */ + /* Image size is greater than Flash size */ + if (size > (USER_FLASH_SIZE + 1)) + { + /* End session */ + Send_Byte(CA); + Send_Byte(CA); + return -1; + } + /* erase user application area */ + + NOR_FLASH_Erase(BL_APP_VECTOR_TABLE_ADDRESS,size); + Send_Byte(ACK); + Send_Byte(CRC16); + } + /* Filename packet is empty, end session */ + else + { + Send_Byte(ACK); + file_done = 1; + session_done = 1; + break; + } + } + /* Data packet */ + else + { + memcpy(buf_ptr, packet_data + PACKET_HEADER, packet_length); + + /* Write received data in Flash */ +#ifndef USE_HIGHT_SPEED_TRANS + if (NOR_FLASH_Write(&flashdestination, buf, (uint16_t) packet_length) == 0) +#else + if (NOR_FLASH_Write(&flashdestination, buf, (uint16_t) packet_length,0) == 0) +#endif + { + Send_Byte(ACK); + } + else /* An error occurred while writing to Flash memory */ + { + /* End session */ + Send_Byte(CA); + Send_Byte(CA); + return -2; + } + } + packets_received ++; + session_begin = 1; + } + } + break; + case 1: + Send_Byte(CA); + Send_Byte(CA); + return -3; + default: + if (session_begin > 0) + { + errors ++; + } + if (errors > MAX_ERRORS) + { + Send_Byte(CA); + Send_Byte(CA); + return 0; + } + Send_Byte(CRC16); + break; + } + if (file_done != 0) + { + break; + } + } + if (session_done != 0) + { + break; + } + } +#ifdef USE_HIGHT_SPEED_TRANS + NOR_FLASH_Write(&flashdestination, buf, (uint16_t) packet_length,1); +#endif + return (int32_t)size; +} + +/** + * @brief Download a file via serial port + * @param None + * @retval None + */ +void SerialDownload(void) +{ + uint8_t Number[10] = {0}; + int32_t Size = 0; + + Serial_PutString("Waiting for the file to be sent ... (press 'a' to abort)\n\r"); + Size = Ymodem_Receive(&tab_1024[0]); + if (Size > 0) + { + Serial_PutString("\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: "); + Serial_PutString(FileName); + Int2Str(Number, Size); + Serial_PutString("\n\r Size: "); + Serial_PutString(Number); + Serial_PutString(" Bytes\r\n"); + Serial_PutString("-------------------\n"); + } + else if (Size == -1) + { + Serial_PutString("\n\n\rThe image size is higher than the allowed space memory!\n\r"); + } + else if (Size == -2) + { + Serial_PutString("\n\n\rVerification failed!\n\r"); + } + else if (Size == -3) + { + Serial_PutString("\r\n\nAborted by user.\n\r"); + } + else + { + Serial_PutString("\n\rFailed to receive the file!\n\r"); + } +} 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 new file mode 100644 index 000000000..f645ac52f --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/common.h @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file: common.h +* @brief: file common.h +* @version: 1.0 +* @author: AIIT XUOS Lab +* @date: 2023/3/24 +*/ + +#ifndef _COMMON_H +#define _COMMON_H + +#include "fsl_common.h" +#include "fsl_lpuart.h" + +#define CMD_STRING_SIZE 128 +#define IS_AF(c) ((c >= 'A') && (c <= 'F')) +#define IS_af(c) ((c >= 'a') && (c <= 'f')) +#define IS_09(c) ((c >= '0') && (c <= '9')) +#define ISVALIDHEX(c) IS_AF(c) || IS_af(c) || IS_09(c) +#define ISVALIDDEC(c) IS_09(c) +#define CONVERTDEC(c) (c - '0') + +#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 Int2Str(uint8_t* str,int32_t intnum); +uint32_t Str2Int(uint8_t *inputstr,int32_t *intnum); +uint32_t GetIntegerInput(int32_t * num); +uint32_t SerialKeyPressed(uint8_t *key); +uint8_t GetKey(void); +void SerialPutChar(uint8_t c); +void Serial_PutString(uint8_t *s); +void GetInputString(uint8_t * buffP); + +#endif diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h index 46b96f58f..190854ac4 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h @@ -19,18 +19,32 @@ #include #include "fsl_romapi.h" +#define USE_HIGHT_SPEED_TRANS 1 +#define FLASH_BASE 0x60000000 +#define SECTOR_SIZE 0x1000 +#define FLASH_PAGE_SIZE 256 + void FLASH_Init(void); void FLASH_DeInit(void); uint32_t FLASH_GetSectorSize(void); -status_t FLASH_WritePage(uint32_t addr, const uint8_t *buf, uint32_t len); +status_t FLASH_WritePage(uint32_t addr, const uint32_t *buf, uint32_t len); status_t FLASH_EraseSector(uint32_t addr); -status_t FLASH_Read(uint32_t addr, const uint8_t *buf, uint32_t len); -uint32_t FLASH_Test(uint32_t startAddr, uint32_t len); -uint32_t FLASH_GetProgramCmd(void); +status_t FLASH_Read(uint32_t addr, uint32_t *buf, uint32_t len); status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt); status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt); status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len); status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize); +status_t NOR_FLASH_Erase(uint32_t app_base_addr,uint32_t imageSize); +status_t NOR_FLASH_Erase(uint32_t app_base_addr,uint32_t imageSize); +void NorFlash_Write_PageProgram(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite); +void NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite); +void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite); +#ifndef USE_HIGHT_SPEED_TRANS +uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength); +#else +uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength,uint8_t doneFlag); +#endif + #endif 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 new file mode 100644 index 000000000..c2eac308c --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/ymodem.h @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file: ymodem.h +* @brief: file ymodem.h +* @version: 1.0 +* @author: AIIT XUOS Lab +* @date: 2023/3/24 +*/ + + +#ifndef _YMODEM_H_ +#define _YMODEM_H_ + +#include + +#define BL_APP_VECTOR_TABLE_ADDRESS 0x60100000 //Application start address +#define USER_FLASH_SIZE 0x100000 //Application package size is limited to 1M +#define PACKET_SEQNO_INDEX (1) +#define PACKET_SEQNO_COMP_INDEX (2) + +#define PACKET_HEADER (3) +#define PACKET_TRAILER (2) +#define PACKET_OVERHEAD (PACKET_HEADER + PACKET_TRAILER) +#define PACKET_SIZE (128) +#define PACKET_1K_SIZE (1024) + +#define FILE_NAME_LENGTH (256) +#define FILE_SIZE_LENGTH (16) + +#define SOH (0x01) /* start of 128-byte data packet */ +#define STX (0x02) /* start of 1024-byte data packet */ +#define EOT (0x04) /* end of transmission */ +#define ACK (0x06) /* acknowledge */ +#define NAK (0x15) /* negative acknowledge */ +#define CA (0x18) /* two of these in succession aborts transfer */ +#define CRC16 (0x43) /* 'C' == 0x43, request 16-bit CRC */ + +#define ABORT1 (0x41) /* 'A' == 0x41, abort by user */ +#define ABORT2 (0x61) /* 'a' == 0x61, abort by user */ + +#define NAK_TIMEOUT (0x100000) +#define MAX_ERRORS (5) + +void SerialDownload(void); +int32_t Ymodem_Receive (uint8_t *); + +#endif From 198fabf970f6a8c41f739ad6cd5800bb0153fac4 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Mon, 17 Apr 2023 15:08:10 +0800 Subject: [PATCH 04/15] fix xidatong-arm32 NorFlash init bug --- .../XiZi_IIoT/board/xidatong-arm32/board.c | 2 + .../third_party_driver/common/flash.c | 751 ++++++++++++------ .../third_party_driver/include/flash.h | 45 +- 3 files changed, 538 insertions(+), 260 deletions(-) diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c index 23600e8ed..6fea57bb5 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c @@ -414,5 +414,7 @@ void InitBoardHardware() KPrintf("start kernel...\n"); #ifdef BSP_USING_OTA FLASH_Init(); + //Flash operation + FLASH_DeInit(); #endif } diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c index 69f97ddf2..b8965c6d7 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c @@ -6,7 +6,7 @@ */ /** -* @file flash.c +* @file fsl_flash.c * @brief support flexspi norflash function * @version 2.0 * @author AIIT XUOS Lab @@ -16,173 +16,437 @@ #include #include #include "flash.h" +#include "MIMXRT1052.h" -/******************************************************************************* - * Definitions - ******************************************************************************/ -#define APP_FLASH_SIZE 0x100000 //Application package size is limited to 1M -#define FLASH_PAGE_SIZE 256 //每次写入256个字节 -/******************************************************************************* - * Prototypes - ******************************************************************************/ uint8_t NorFlash_BUFFER[4096]; //4K buffer cache uint8_t buffer[FLASH_PAGE_SIZE]; //256 bytes buffer cache /******************************************************************************* - * Variables + * Prototypes ******************************************************************************/ -/*! @brief FLEXSPI NOR flash driver Structure in XIP config */ -extern flexspi_nor_config_t Qspiflash_config; -/*! @brief FLEXSPI NOR flash driver Structure in flash driver */ -static flexspi_nor_config_t norConfig; +static status_t Flexspi_Nor_Wait_Busy(uint32_t instance, uint32_t baseAddr); +static status_t Flexspi_Nor_Write_Enable(uint32_t instance, uint32_t baseAddr); +static void flexspi_clock_config(uint32_t instance, uint32_t freq, uint32_t sampleClkMode); +static void flexspi_clock_gate_enable(uint32_t instance); +static void flexspi_clock_gate_disable(uint32_t instance); +static status_t flexspi_get_clock(uint32_t instance, flexspi_clock_type_t type, uint32_t *freq); +static status_t flexspi_get_ticks(uint32_t *ticks, uint32_t intervalNs, uint32_t freq, uint32_t unit); +static status_t flexspi_configure_dll(uint32_t instance, flexspi_mem_config_t *config); +static status_t flexspi_config_mcr1(uint32_t instance, flexspi_mem_config_t *config); -/******************************************************************************* - * Code - ******************************************************************************/ -/* Get FLEXSPI NOR Configuration Block */ -void FLEXSPI_NorFlash_GetConfig(flexspi_nor_config_t *config) +static const lookuptable_t FlashLookupTable={ +.ReadStatus_Seq= { - /* Copy norflash config block from xip config */ - memcpy(config, &Qspiflash_config, sizeof(flexspi_nor_config_t)); -#ifndef HYPER_FLASH //QSPI Flash - /* Override some default config */ - config->memConfig.deviceType = kFLEXSPIDeviceType_SerialNOR; - config->memConfig.deviceModeType = kDeviceConfigCmdType_Generic; - config->memConfig.serialClkFreq = kFLEXSPISerialClk_30MHz; //Safe Serial Flash Frequencey - config->ipcmdSerialClkFreq = kFLEXSPISerialClk_30MHz; //Safe Clock frequency for IP command - config->memConfig.controllerMiscOption = FSL_ROM_FLEXSPI_BITMASK(kFLEXSPIMiscOffset_SafeConfigFreqEnable);//Always enable Safe configuration Frequency + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x05, READ_SDR, FLEXSPI_1PAD, 0x04), +}, +/* Write Enable */ +.WriteEnable_Seq= +{ + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x06, STOP, FLEXSPI_1PAD, 0x00), +}, +/* Erase Sector */ +.EraseSector_Seq= +{ + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x20, RADDR_SDR, FLEXSPI_1PAD, 0x18), +}, +/* Page Program */ +.PageProgram_Seq= +{ + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x32, RADDR_SDR, FLEXSPI_1PAD, 0x18), + FSL_ROM_FLEXSPI_LUT_SEQ(WRITE_SDR, FLEXSPI_4PAD, 0x00, 0x00, 0x00, 0x00), +}, +}; - /* Read Status */ - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x05U, READ_SDR, FLEXSPI_1PAD, 0x1U); - /* Write Enable */ - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x06U, STOP, FLEXSPI_1PAD, 0x0U); +static status_t Flexspi_Nor_Wait_Busy(uint32_t instance, uint32_t baseAddr) +{ + status_t status = kStatus_InvalidArgument; + flexspi_xfer_t flashXfer; + uint32_t statusDataBuffer; + uint32_t busyMask; + uint32_t busyPolarity; + bool isBusy = false; + + flashXfer.operation = kFLEXSPIOperation_Read; + flashXfer.seqNum = 1; + busyMask = 1; + busyPolarity = 0; + flashXfer.seqId = NOR_CMD_LUT_SEQ_IDX_READSTATUS; + flashXfer.isParallelModeEnable = false; + flashXfer.baseAddress = baseAddr; + flashXfer.rxBuffer = &statusDataBuffer; + flashXfer.rxSize = sizeof(statusDataBuffer); + do + { + status = ROM_FLEXSPI_NorFlash_CommandXfer(instance, &flashXfer); + // Busy bit is 0 if polarity is 1 + if(busyPolarity) + { + isBusy = (~statusDataBuffer) & busyMask; + } + else + { + isBusy = statusDataBuffer & busyMask; + } + }while (isBusy); - /* Page Program - quad mode */ - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM + 0U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x32U, RADDR_SDR, FLEXSPI_1PAD, 0x18U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM + 1U] = - FSL_ROM_FLEXSPI_LUT_SEQ(WRITE_SDR, FLEXSPI_4PAD, 0x04U, STOP, FLEXSPI_1PAD, 0x0U); - - /* Sector Erase */ - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xD7U, RADDR_SDR, FLEXSPI_1PAD, 0x18U); -#else - /* Override some default config */ - config->memConfig.deviceType = kFLEXSPIDeviceType_SerialNOR; - config->memConfig.deviceModeType = kDeviceConfigCmdType_Generic; - config->memConfig.lutCustomSeqEnable = true; - config->memConfig.busyOffset = 15U; - config->memConfig.busyBitPolarity = 1U; - config->ipcmdSerialClkFreq = kFLEXSPISerialClk_30MHz; //Safe Clock frequency for IP command - config->serialNorType = kSerialNorType_HyperBus; - // Read Status - // 0 - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x00U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS + 1U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xAAU); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS + 2U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x05U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS + 3U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x70U); - // 1 - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS + 4U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0xA0U, RADDR_DDR, FLEXSPI_8PAD, 0x18U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS + 5U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CADDR_DDR, FLEXSPI_8PAD, 0x10U, DUMMY_RWDS_DDR, FLEXSPI_8PAD, 0x0BU); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_READSTATUS + 6U] = - FSL_ROM_FLEXSPI_LUT_SEQ(READ_DDR, FLEXSPI_8PAD, 0x04U, STOP, FLEXSPI_1PAD, 0x00U); - - // Write Enable - // 0 - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x00U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE + 1U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xAAU); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE + 2U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x05U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE + 3U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xAAU); - // 1 - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE + 4U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x00U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE + 5U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x55U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE + 6U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x02U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_WRITEENABLE + 7U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x55U); - - // Page Program - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x00U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM + 1U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xAAU); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM + 2U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x05U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM + 3U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xA0U); - // 1 - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM + 4U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, RADDR_DDR, FLEXSPI_8PAD, 0x18U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM + 5U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CADDR_DDR, FLEXSPI_8PAD, 0x10U, WRITE_DDR, FLEXSPI_8PAD, 0x80U); - - // Erase Sector - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x00U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 1U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xAAU); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 2U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x05U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 3U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x80U); - // 1 - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 4U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x00U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 5U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xAAU); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 6U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x05U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 7U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0xAAU); - // 2 - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 8U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x00U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 9U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x55U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 10U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x02U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 11U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, CMD_DDR, FLEXSPI_8PAD, 0x55U); - // 3 - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 12U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x00U, RADDR_DDR, FLEXSPI_8PAD, 0x18U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 13U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CADDR_DDR, FLEXSPI_8PAD, 0x10U, CMD_DDR, FLEXSPI_8PAD, 0x00U); - config->memConfig.lookupTable[4U * NOR_CMD_LUT_SEQ_IDX_ERASESECTOR + 14U] = - FSL_ROM_FLEXSPI_LUT_SEQ(CMD_DDR, FLEXSPI_8PAD, 0x30U, STOP, FLEXSPI_1PAD, 0x0U); - - // LUT customized sequence - config->memConfig.lutCustomSeq[NOR_CMD_INDEX_WRITEENABLE].seqNum = 2U; - config->memConfig.lutCustomSeq[NOR_CMD_INDEX_WRITEENABLE].seqId = NOR_CMD_LUT_SEQ_IDX_WRITEENABLE; - config->memConfig.lutCustomSeq[NOR_CMD_INDEX_READSTATUS].seqNum = 2U; - config->memConfig.lutCustomSeq[NOR_CMD_INDEX_READSTATUS].seqId = NOR_CMD_LUT_SEQ_IDX_READSTATUS; - config->memConfig.lutCustomSeq[NOR_CMD_INDEX_PAGEPROGRAM].seqNum = 2U; - config->memConfig.lutCustomSeq[NOR_CMD_INDEX_PAGEPROGRAM].seqId = NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM; - config->memConfig.lutCustomSeq[NOR_CMD_INDEX_ERASESECTOR].seqNum = 4U; - config->memConfig.lutCustomSeq[NOR_CMD_INDEX_ERASESECTOR].seqId = NOR_CMD_LUT_SEQ_IDX_ERASESECTOR; -#endif + return status; } - /** - * @brief 获得扇区大小 - * @note None - * @param None - * @retval Flash扇区尺寸 - */ + +static status_t Flexspi_Nor_Write_Enable(uint32_t instance, uint32_t baseAddr) +{ + status_t status = kStatus_InvalidArgument; + flexspi_xfer_t flashXfer; + + flashXfer.operation = kFLEXSPIOperation_Command; + flashXfer.seqNum = 1; + flashXfer.seqId = NOR_CMD_LUT_SEQ_IDX_WRITEENABLE; + flashXfer.isParallelModeEnable = false; + flashXfer.baseAddress = baseAddr; + + status = ROM_FLEXSPI_NorFlash_CommandXfer(instance, &flashXfer); + + return status; +} + + +static void flexspi_clock_config(uint32_t instance, uint32_t freq, uint32_t sampleClkMode) +{ + uint32_t pfd480 = 0; + uint32_t cscmr1 = 0; + uint32_t frac = 0; + uint32_t podf = 0; + + typedef struct _flexspi_clock_param + { + uint8_t frac; + uint8_t podf; + } flexspi_clock_param_t; + + const flexspi_clock_param_t k_sdr_clock_config[kFLEXSPISerialClk_200MHz + 1] = { + //Reserved, 30MHz 50MHz 60MHz 75MHz 80MHz 100MHz 133MHz 166MHz 200MHz + {0, 0}, {34, 8}, {22, 8}, {24, 6}, {30, 4}, {18, 6}, {14, 6}, {17, 4}, {26, 2}, {22, 2} + }; + const flexspi_clock_param_t k_ddr_clock_config[kFLEXSPISerialClk_200MHz + 1] = { + //Reserved, 30MHz 50MHz 60MHz 75MHz 80MHz 100MHz 133MHz 166MHz 200MHz + {0, 0}, {24, 6}, {22, 4}, {12, 6}, {30, 2}, {18, 3}, {22, 2}, {33, 1}, {26, 1}, {22, 1} + }; + + do + { + if((sampleClkMode != kFLEXSPIClk_SDR) && (sampleClkMode != kFLEXSPIClk_DDR)) + { + break; + } + + pfd480 = CCM_ANALOG->PFD_480 & (~CCM_ANALOG_PFD_480_PFD0_FRAC_MASK); + cscmr1 = CCM->CSCMR1 & (~CCM_CSCMR1_FLEXSPI_PODF_MASK); + + const flexspi_clock_param_t *flexspi_config_array = NULL; + if(sampleClkMode == kFLEXSPIClk_SDR) + { + flexspi_config_array = &k_sdr_clock_config[0]; + } + else + { + flexspi_config_array = &k_ddr_clock_config[0]; + } + + if(freq >= kFLEXSPISerialClk_30MHz) + { + if(freq > kFLEXSPISerialClk_200MHz) + { + freq = kFLEXSPISerialClk_30MHz; + } + + frac = flexspi_config_array[freq].frac; + podf = flexspi_config_array[freq].podf; + + pfd480 |= CCM_ANALOG_PFD_480_PFD0_FRAC(frac); + cscmr1 |= CCM_CSCMR1_FLEXSPI_PODF(podf - 1); + + FLEXSPI->MCR0 |= FLEXSPI_MCR0_MDIS_MASK; + flexspi_clock_gate_disable(instance); + + if(pfd480 != CCM_ANALOG->PFD_480) + { + CCM_ANALOG->PFD_480 = pfd480; + } + if(cscmr1 != CCM->CSCMR1) + { + CCM->CSCMR1 = cscmr1; + } + flexspi_clock_gate_enable(instance); + FLEXSPI->MCR0 &= ~FLEXSPI_MCR0_MDIS_MASK; + } + else + { + //Do nothing + } + } while (0); +} + + +static void flexspi_clock_gate_enable(uint32_t instance) +{ + CCM->CCGR6 |= CCM_CCGR6_CG5_MASK; +} + + +static void flexspi_clock_gate_disable(uint32_t instance) +{ + CCM->CCGR6 &= (uint32_t)~CCM_CCGR6_CG5_MASK; +} + + +static status_t flexspi_get_clock(uint32_t instance, flexspi_clock_type_t type, uint32_t *freq) +{ + uint32_t clockFrequency = 0; + status_t status = kStatus_Success; + + uint32_t ahbBusDivider; + uint32_t seralRootClkDivider; + uint32_t arm_clock = SystemCoreClock; + + switch (type) + { + case kFlexSpiClock_CoreClock: + clockFrequency = SystemCoreClock; + break; + case kFlexSpiClock_AhbClock: + { + // Note: In I.MXRT_512, actual AHB clock is IPG_CLOCK_ROOT + ahbBusDivider = ((CCM->CBCDR & CCM_CBCDR_IPG_PODF_MASK) >> CCM_CBCDR_IPG_PODF_SHIFT) + 1; + clockFrequency = arm_clock / ahbBusDivider; + } + break; + case kFlexSpiClock_SerialRootClock: + { + uint32_t pfdFrac; + uint32_t pfdClk; + + // FLEXPI CLK SEL + uint32_t flexspi_clk_src = + (CCM->CSCMR1 & CCM_CSCMR1_FLEXSPI_CLK_SEL_MASK) >> CCM_CSCMR1_FLEXSPI_CLK_SEL_SHIFT; + + // PLL_480_PFD0 + pfdFrac = (CCM_ANALOG->PFD_480 & CCM_ANALOG_PFD_480_PFD0_FRAC_MASK) >> CCM_ANALOG_PFD_480_PFD0_FRAC_SHIFT; + pfdClk = (480000000UL) / pfdFrac * 18; + + seralRootClkDivider = ((CCM->CSCMR1 & CCM_CSCMR1_FLEXSPI_PODF_MASK) >> CCM_CSCMR1_FLEXSPI_PODF_SHIFT) + 1; + + clockFrequency = pfdClk / seralRootClkDivider; + } + break; + default: + status = kStatus_InvalidArgument; + break; + } + *freq = clockFrequency; + + return status; +} + + +static status_t flexspi_get_ticks(uint32_t *ticks, uint32_t intervalNs, uint32_t freq, uint32_t unit) +{ + status_t status = kStatus_InvalidArgument; + do + { + if((ticks == NULL) || (freq < 1) || (unit < 1)) + { + break; + } + + // Get clock cycle in terms of ns + int32_t calculatedTicks; + uint32_t cycleNs = FLEXSPI_FREQ_1GHz / freq; + + calculatedTicks = intervalNs / (cycleNs * unit); + while(calculatedTicks * cycleNs * unit < intervalNs) + { + calculatedTicks++; + } + + *ticks = calculatedTicks; + + status = kStatus_Success; + + } while (0); + + return status; +} + + +static status_t flexspi_configure_dll(uint32_t instance, flexspi_mem_config_t *config) +{ + status_t status = kStatus_InvalidArgument; + bool mdisConfigRequired; + + do + { + bool isUnifiedConfig = true; + uint32_t flexspiRootClk; + uint32_t flexspiDll[2]; + uint32_t dllValue; + uint32_t temp; + if(config->readSampleClkSrc > kFLEXSPIReadSampleClk_ExternalInputFromDqsPad) + { + break; + } + switch (config->readSampleClkSrc) + { + case kFLEXSPIReadSampleClk_LoopbackInternally: + case kFLEXSPIReadSampleClk_LoopbackFromDqsPad: + case kFLEXSPIReadSampleClk_LoopbackFromSckPad: + isUnifiedConfig = true; + break; + case kFLEXSPIReadSampleClk_ExternalInputFromDqsPad: + isUnifiedConfig = false; + break; + default: // Never reach here + break; + } + + if(isUnifiedConfig) + { + flexspiDll[0] = FLEXSPI_DLLCR_DEFAULT; // 1 fixed delay cells in DLL delay chain) + flexspiDll[1] = FLEXSPI_DLLCR_DEFAULT; // 1 fixed delay cells in DLL delay chain) + } + else + { + flexspi_get_clock(instance, kFlexSpiClock_SerialRootClock, &flexspiRootClk); + + bool useDLL = false; + + //See FlexSPI Chapter for more details + if((flexspiRootClk >= 100 * FREQ_1MHz) && + (!(config->controllerMiscOption & (1U << kFLEXSPIMiscOffset_UseValidTimeForAllFreq)))) + { + useDLL = true; + } + if(useDLL) + { + flexspiDll[0] = FLEXSPI_DLLCR_DLLEN(1) | FLEXSPI_DLLCR_SLVDLYTARGET(0x0F); + flexspiDll[1] = FLEXSPI_DLLCR_DLLEN(1) | FLEXSPI_DLLCR_SLVDLYTARGET(0x0F); + } + else + { + for(uint32_t i = 0; i < 2; i++) + { + uint32_t dataValidTimeH = config->dataValidTime[i].delay_cells; + uint32_t dataValidTimeL = config->dataValidTime[i].time_100ps; + if(dataValidTimeH < 1) + { + // Convert the data valid time to n ps. + temp = dataValidTimeL * 100ul; + if(temp < 1) + { + uint32_t maxFreq = (166UL * 1000 * 1000); + bool is_ddr_enabled = (config->controllerMiscOption & 1<< kFLEXSPIMiscOffset_DdrModeEnable)?true:false; + /* For SDR mode, the delay cell configuration must ensure that the delay time is greater + than Half cycle of max supported frequency*/ + if(!is_ddr_enabled) + { + dllValue = FLEXSPI_FREQ_1GHz / maxFreq / 2 * 1000 / kFlexSpiDelayCellUnit_Min + 1; + } + /* For SDR mode, the delay cell configuration must ensure that the delay time is greater + than 1/4 cycle of max supported frequency */ + else + { + dllValue = FLEXSPI_FREQ_1GHz / maxFreq / 4 * 1000 / kFlexSpiDelayCellUnit_Min + 1; + } + } + else + { + dllValue = temp / kFlexSpiDelayCellUnit_Min; + if(dllValue * kFlexSpiDelayCellUnit_Min < temp) + { + dllValue++; + } + } + } + else + { + dllValue = dataValidTimeH; + } + // Calculate maximum dll value; + temp = (FLEXSPI_DLLCR_OVRDVAL_MASK >> FLEXSPI_DLLCR_OVRDVAL_SHIFT); + if(dllValue > temp) + { + dllValue = temp; + } + flexspiDll[i] = FLEXSPI_DLLCR_OVRDEN(1) | FLEXSPI_DLLCR_OVRDVAL(dllValue); + } + } + } + + if(FLEXSPI->MCR0 & FLEXSPI_MCR0_MDIS_MASK) + { + mdisConfigRequired = false; + } + else + { + mdisConfigRequired = true; + } + + if(mdisConfigRequired) + { + FLEXSPI->MCR0 |= FLEXSPI_MCR0_MDIS_MASK; + } + + FLEXSPI->DLLCR[0] = flexspiDll[0]; + FLEXSPI->DLLCR[1] = flexspiDll[1]; + + if(mdisConfigRequired) + { + FLEXSPI->MCR0 &= (uint32_t)~FLEXSPI_MCR0_MDIS_MASK; + } + /* Wait at least 100 NOPs*/ + for(uint8_t delay = 100U; delay > 0U; delay--) + { + __NOP(); + } + status = kStatus_Success; + } while (0); + + return status; +} + + +static status_t flexspi_config_mcr1(uint32_t instance, flexspi_mem_config_t *config) +{ + uint32_t seqWaitTicks = 0xFFFFu; + uint32_t ahbBusWaitTicks = 0xFFFFu; + uint32_t serialRootClockFreq; + uint32_t ahbBusClockFreq; + + if(config == NULL) + { + return kStatus_InvalidArgument; + } + + flexspi_get_clock(instance, kFlexSpiClock_SerialRootClock, &serialRootClockFreq); + flexspi_get_clock(instance, kFlexSpiClock_AhbClock, &ahbBusClockFreq); + flexspi_get_ticks(&seqWaitTicks, FLEXSPI_WAIT_TIMEOUT_NS, serialRootClockFreq, 1024); + flexspi_get_ticks(&ahbBusWaitTicks, FLEXSPI_WAIT_TIMEOUT_NS, ahbBusClockFreq, 1024); + + if(seqWaitTicks > 0xFFFF) + { + seqWaitTicks = 0xFFFF; + } + if(ahbBusWaitTicks > 0xFFFF) + { + ahbBusWaitTicks = 0xFFFF; + } + + // Configure MCR1 + FLEXSPI->MCR1 = FLEXSPI_MCR1_SEQWAIT(seqWaitTicks) | FLEXSPI_MCR1_AHBBUSWAIT(ahbBusWaitTicks); + + return kStatus_Success; +} + + uint32_t FLASH_GetSectorSize(void) { #ifndef HYPER_FLASH @@ -192,96 +456,92 @@ uint32_t FLASH_GetSectorSize(void) #endif } - /** - * @brief 获得最小编程长度 - * @note None - * @param None - * @retval 256 or 512 for QSPI Flash - */ + uint32_t FLASH_GetProgramCmd(void) { + uint32_t Program_Unit; #ifndef HYPER_FLASH - return 256;//QSPI Flash Page Program + Program_Unit = 256;//QSPI Flash Page Program #else - return 512;//Hyper Flash Page Program + Program_Unit = 512;//Hyper Flash Page Program #endif + + return Program_Unit; } - /** - * @brief 初始化Flash - * @note None - * @param None - * @retval None - */ + + void FLASH_Init(void) { - /* Clean up FLEXSPI NOR flash driver Structure */ - memset(&norConfig, 0U, sizeof(flexspi_nor_config_t)); - /* Setup FLEXSPI NOR Configuration Block */ - FLEXSPI_NorFlash_GetConfig(&norConfig); - /* Initializes the FLEXSPI module for the other FLEXSPI APIs */ - ROM_FLEXSPI_NorFlash_Init(0, &norConfig); - /* Reset the Flexspi's Cache */ + /* Update LUT Table for Status, Write Enable, Erase and Program */ + ROM_FLEXSPI_NorFlash_UpdateLut(0, NOR_CMD_LUT_SEQ_IDX_READSTATUS, (const uint32_t *)FlashLookupTable.ReadStatus_Seq, 10U); + /* Use 30MHz Flexspi clock for safe operation */ + flexspi_clock_config(0, kFLEXSPISerialClk_30MHz, kFLEXSPIClk_DDR); + extern flexspi_nor_config_t Qspiflash_config; + flexspi_config_mcr1(0, &Qspiflash_config.memConfig); + flexspi_configure_dll(0, &Qspiflash_config.memConfig); ROM_FLEXSPI_NorFlash_ClearCache(0); } - /** - * @brief 反初始化Flash - * @note None - * @param None - * @retval None - */ + + void FLASH_DeInit(void) { - /* Clear the FlexSPI LUT to avoid unexpected erase or program operion trigger */ - memset(&norConfig, 0U, sizeof(flexspi_nor_config_t)); - ROM_FLEXSPI_NorFlash_UpdateLut(0, NOR_CMD_LUT_SEQ_IDX_READSTATUS, norConfig.memConfig.lookupTable, sizeof(norConfig.memConfig.lookupTable)-(4*NOR_CMD_LUT_SEQ_IDX_READSTATUS)); - /* Reset the Flexspi's Cache */ + lookuptable_t clearlut; + memset(&clearlut, 0, sizeof(lookuptable_t)); + ROM_FLEXSPI_NorFlash_UpdateLut(0, NOR_CMD_LUT_SEQ_IDX_READSTATUS, (const uint32_t *)FlashLookupTable.ReadStatus_Seq, 10U); + /* Use 30MHz Flexspi clock for safe operation */ + flexspi_clock_config(0, kFLEXSPISerialClk_30MHz, kFLEXSPIClk_DDR); +} + + +uint8_t FLASH_EraseSector(uint32_t addr) +{ + status_t status; + flexspi_xfer_t flashXfer; + addr &= 0x0FFFFFFF; + + flashXfer.operation = kFLEXSPIOperation_Command; + flashXfer.seqNum = 1; + flashXfer.seqId = NOR_CMD_LUT_SEQ_IDX_ERASESECTOR; + flashXfer.baseAddress = addr; + flashXfer.isParallelModeEnable = false; + + __disable_irq(); + status = Flexspi_Nor_Write_Enable(0, addr); + status = ROM_FLEXSPI_NorFlash_CommandXfer(0, &flashXfer); + status = Flexspi_Nor_Wait_Busy(0, addr); ROM_FLEXSPI_NorFlash_ClearCache(0); -} - - /** - * @brief 擦除Flash扇区 - * @note 该功能将删除一个Flash扇区的内容 - * @param addr: 擦除区域起始地址 - * @retval 返回操作结果 - */ -status_t FLASH_EraseSector(uint32_t addr) -{ - status_t status; - addr &= 0x0FFFFFFF; - - __disable_irq(); - status = ROM_FLEXSPI_NorFlash_Erase(0, &norConfig, addr, norConfig.sectorSize); __enable_irq(); return status; } - /** - * @brief 写Flash一个页 - * @note 字节数小于等于一页 - * @param addr: 开始地址 - * @param buf : 写入数据起始指针 - * @param len : 字节数 - * @retval kStatus_Success:完成 - */ -status_t FLASH_WritePage(uint32_t addr, const uint32_t *buf, uint32_t len) + +uint8_t FLASH_WritePage(uint32_t addr, const uint32_t *buf, uint32_t len) { status_t status; + flexspi_xfer_t flashXfer; addr &= 0x0FFFFFFF; + + + flashXfer.operation = kFLEXSPIOperation_Write; + flashXfer.seqNum = 1; + flashXfer.seqId = NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM; + flashXfer.baseAddress = addr; + flashXfer.isParallelModeEnable = false; + flashXfer.txBuffer = (uint32_t *)buf; + flashXfer.txSize = len; + __disable_irq(); - norConfig.pageSize = len; - status = ROM_FLEXSPI_NorFlash_ProgramPage(0, &norConfig, addr, buf); + status = Flexspi_Nor_Write_Enable(0, addr); + status = ROM_FLEXSPI_NorFlash_CommandXfer(0, &flashXfer); + status = Flexspi_Nor_Wait_Busy(0, addr); + ROM_FLEXSPI_NorFlash_ClearCache(0); __enable_irq(); return status; } - /** - * @brief 读Flash内容 - * @param addr: 开始地址 - * @param buf : 读缓存指针 - * @param len : 字节数 - * @retval kStatus_Success:完成 - */ + + status_t FLASH_Read(uint32_t addr, uint32_t *buf, uint32_t len) { status_t status; @@ -305,12 +565,7 @@ status_t FLASH_Read(uint32_t addr, uint32_t *buf, uint32_t len) return status; } - /** - * @brief 擦除flash指定地址指定长度的空间 - * @param start_addr: 开始地址 - * @param byte_cnt : 要擦除的字节数 - * @retval kStatus_Success:擦除成功 - */ + status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt) { uint32_t addr; @@ -329,25 +584,12 @@ status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt) return status; } - /** - * @brief 在flash指定地址写入指定长度的数据 - * @param start_addr: 开始地址 - * @param buf : 数据buffer - * @param byte_cnt : 要写入的字节数 - * @retval kStatus_Success:写入成功 - */ status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt) { return FLASH_WritePage(start_addr, (void *)buf, byte_cnt); } - /** - * @brief 在flash指定开始读取一定长度的数据到缓存中 - * @param start_addr: 开始地址 - * @param buf : 数据buffer - * @param byte_cnt : 要读取的字节数 - * @retval kStatus_Success:读取成功 - */ + status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len) { /* For FlexSPI Memory ReadBack, use IP Command instead of AXI command for security */ @@ -371,13 +613,7 @@ status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len) } } - /** - * @brief 实现两块连续flash地址空间之间的数据拷贝 - * @param srcAddr: 源flash的起始地址 - * @param dstAddr : 目标flash的起始地址 - * @param imageSize : 要拷贝的flash空间大小,单位为字节 - * @retval kStatus_Success:拷贝成功 - */ + status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize) { uint32_t PageNum, Remain, i; @@ -435,10 +671,11 @@ status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize) return (status_t)kStatus_Success; } + status_t NOR_FLASH_Erase(uint32_t app_base_addr,uint32_t imageSize) { uint16_t i; - uint32_t sectorNum = (imageSize%4096 != 0)? (imageSize/4096 + 1):(imageSize/4096); + uint32_t sectorNum = (imageSize%SECTOR_SIZE != 0)? (imageSize/SECTOR_SIZE + 1):(imageSize/SECTOR_SIZE); for(i=0;i 4096) + if(NumByteToWrite > SECTOR_SIZE) { - secRemain = 4096;//下一个扇区还是写不完 + secRemain = SECTOR_SIZE;//下一个扇区还是写不完 } else { @@ -571,6 +811,7 @@ void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite) } } + #ifndef USE_HIGHT_SPEED_TRANS uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength) { @@ -597,7 +838,7 @@ uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLen WriteAddr = *FlashAddress; } - if(dataLen>=4096) + if(dataLen>=SECTOR_SIZE) { NorFlash_Write(dataBuff,WriteAddr,dataLen); packetNum = 0; @@ -613,4 +854,4 @@ uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLen } return (0); } -#endif \ No newline at end of file +#endif diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h index 190854ac4..a332ca55b 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h @@ -6,7 +6,7 @@ */ /** -* @file flash.h +* @file fsl_flash.h * @brief support flexspi norflash function * @version 2.0 * @author AIIT XUOS Lab @@ -23,23 +23,58 @@ #define FLASH_BASE 0x60000000 #define SECTOR_SIZE 0x1000 #define FLASH_PAGE_SIZE 256 +#define APP_FLASH_SIZE 0x100000 //Application package size is limited to 1M +#define FLEXSPI_WAIT_TIMEOUT_NS (500000000UL) //FlexSPI timeout value, 500ms +#define FLEXSPI_FREQ_1GHz (1000000000UL) +#define FREQ_1MHz (1000000UL) +#define FLEXSPI_DLLCR_DEFAULT (0x100UL) + +enum +{ + kFlexSpiDelayCellUnit_Min = 75, // 75ps + kFlexSpiDelayCellUnit_Max = 225, // 225ps +}; + +typedef enum +{ + kFlexSpiClock_CoreClock, //ARM Core Clock + kFlexSpiClock_AhbClock, //AHB clock + kFlexSpiClock_SerialRootClock, //Serial Root Clock + kFlexSpiClock_IpgClock, //IPG clock +} flexspi_clock_type_t; + +typedef struct LookUpTable +{ + uint32_t Read_Seq[4]; + uint32_t ReadStatus_Seq[8]; + uint32_t WriteEnable_Seq[8]; + uint32_t EraseSector_Seq[16]; + uint32_t PageProgram_Seq[8]; + uint32_t ChipErase_Seq[8]; + uint32_t ReadSfdp_Seq[4]; + uint32_t Restore_NoCmd_Seq[4]; + uint32_t Exit_NoCmd_Seq[4]; +}lookuptable_t; + + +uint32_t FLASH_GetSectorSize(void); +uint32_t FLASH_GetProgramCmd(void); void FLASH_Init(void); void FLASH_DeInit(void); -uint32_t FLASH_GetSectorSize(void); -status_t FLASH_WritePage(uint32_t addr, const uint32_t *buf, uint32_t len); -status_t FLASH_EraseSector(uint32_t addr); +uint8_t FLASH_EraseSector(uint32_t addr); +uint8_t FLASH_WritePage(uint32_t addr, const uint32_t *buf, uint32_t len); status_t FLASH_Read(uint32_t addr, uint32_t *buf, uint32_t len); status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt); status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt); status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len); status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize); -status_t NOR_FLASH_Erase(uint32_t app_base_addr,uint32_t imageSize); status_t NOR_FLASH_Erase(uint32_t app_base_addr,uint32_t imageSize); void NorFlash_Write_PageProgram(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite); void NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite); void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite); + #ifndef USE_HIGHT_SPEED_TRANS uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength); #else From bbb8dd75f8e907012b6aa87300273dd63ae41601 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Mon, 17 Apr 2023 18:36:47 +0800 Subject: [PATCH 05/15] Add four macro definitions: #define XIUOS_FLAH_ADDRESS 0x60100000 #define BAKUP_FLAH_ADDRESS 0x60300000 #define DOWN_FLAH_ADDRESS 0x60500000 #define FLAG_FLAH_ADDRESS 0x60700000 --- .../third_party_driver/common/Makefile | 5 +---- .../third_party_driver/common/mcuboot.c | 4 ++-- .../third_party_driver/common/ymodem.c | 16 +++++++--------- .../third_party_driver/include/flash.h | 5 +++++ .../third_party_driver/include/ymodem.h | 5 ++--- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile index e27bfd216..7f0219b14 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile @@ -5,10 +5,7 @@ ifeq ($(CONFIG_BSP_USING_SDIO),y) endif ifeq ($(CONFIG_BSP_USING_OTA),y) - SRC_FILES += fsl_romapi.c flash.c mcuboot.c - ifeq ($(CONFIG_MCUBOOT_BOOTLOADER),y) - SRC_FILES += common.c ymodem.c - endif + SRC_FILES += fsl_romapi.c flash.c mcuboot.c common.c ymodem.c endif include $(KERNEL_ROOT)/compiler.mk 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 617781a53..e978fd304 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 @@ -51,7 +51,7 @@ static void UartConfig(void) static void jump_to_application(void) { - SCB->VTOR = (uint32_t)0x60100000; + SCB->VTOR = (uint32_t)XIUOS_FLAH_ADDRESS; asm volatile("LDR R0, = 0x60100000"); asm volatile("LDR R0, [R0]"); @@ -101,7 +101,7 @@ void BootLoaderJumpApp(void) break; case 0x32: FLASH_Init(); - SerialDownload(); + SerialDownload(XIUOS_FLAH_ADDRESS); FLASH_DeInit(); break; case 0x33: 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 fff3ef2be..f8eb0a907 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,13 +19,11 @@ * @date: 2023/3/24 */ - #include "common.h" #include "ymodem.h" #include "string.h" #include "flash.h" -#define BL_APP_VECTOR_TABLE_ADDRESS 0x60100000 uint8_t tab_1024[1024] ={0}; uint8_t FileName[FILE_NAME_LENGTH]; @@ -208,17 +206,17 @@ static int32_t Receive_Packet (uint8_t *data, int32_t *length, uint32_t timeout) /** * @brief Receive a file using the ymodem protocol - * @param buf: Address of the first byte + * @param buf: Address of the first byte,addr:download flash start address * @retval The size of the file */ -int32_t Ymodem_Receive (uint8_t *buf) +int32_t Ymodem_Receive (uint8_t *buf, const uint32_t addr) { uint8_t packet_data[PACKET_1K_SIZE + PACKET_OVERHEAD], file_size[FILE_SIZE_LENGTH], *file_ptr, *buf_ptr; int32_t i, packet_length, session_done, file_done, packets_received, errors, session_begin, size = 0; uint32_t flashdestination; /* Initialize flashdestination variable */ - flashdestination = BL_APP_VECTOR_TABLE_ADDRESS; + flashdestination = addr; for (session_done = 0, errors = 0, session_begin = 0; ;) { @@ -276,7 +274,7 @@ int32_t Ymodem_Receive (uint8_t *buf) } /* erase user application area */ - NOR_FLASH_Erase(BL_APP_VECTOR_TABLE_ADDRESS,size); + NOR_FLASH_Erase(addr,size); Send_Byte(ACK); Send_Byte(CRC16); } @@ -352,16 +350,16 @@ int32_t Ymodem_Receive (uint8_t *buf) /** * @brief Download a file via serial port - * @param None + * @param flash start addr * @retval None */ -void SerialDownload(void) +void SerialDownload(const uint32_t addr) { uint8_t Number[10] = {0}; int32_t Size = 0; Serial_PutString("Waiting for the file to be sent ... (press 'a' to abort)\n\r"); - Size = Ymodem_Receive(&tab_1024[0]); + Size = Ymodem_Receive(&tab_1024[0], addr); if (Size > 0) { Serial_PutString("\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: "); diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h index a332ca55b..fd86d003d 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h @@ -30,6 +30,11 @@ #define FREQ_1MHz (1000000UL) #define FLEXSPI_DLLCR_DEFAULT (0x100UL) +#define XIUOS_FLAH_ADDRESS 0x60100000 +#define BAKUP_FLAH_ADDRESS 0x60300000 +#define DOWN_FLAH_ADDRESS 0x60500000 +#define FLAG_FLAH_ADDRESS 0x60700000 + enum { kFlexSpiDelayCellUnit_Min = 75, // 75ps 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 c2eac308c..08ff4fd1a 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 @@ -24,7 +24,6 @@ #include -#define BL_APP_VECTOR_TABLE_ADDRESS 0x60100000 //Application start address #define USER_FLASH_SIZE 0x100000 //Application package size is limited to 1M #define PACKET_SEQNO_INDEX (1) #define PACKET_SEQNO_COMP_INDEX (2) @@ -52,7 +51,7 @@ #define NAK_TIMEOUT (0x100000) #define MAX_ERRORS (5) -void SerialDownload(void); -int32_t Ymodem_Receive (uint8_t *); +void SerialDownload(const uint32_t addr); +int32_t Ymodem_Receive (uint8_t *buf, const uint32_t addr); #endif 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 06/15] 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) From 8bc7546828353b1609f20e610c02d0819085d0e5 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Wed, 19 Apr 2023 15:36:39 +0800 Subject: [PATCH 07/15] support ota function for xidatong-arm32 --- .../XiZi_IIoT/board/xidatong-arm32/board.c | 32 ++- .../board/xidatong-arm32/include/board.h | 2 +- .../third_party_driver/common/Makefile | 2 +- .../third_party_driver/common/flash.c | 2 +- .../third_party_driver/common/imxrt_ota.c | 214 ++++++++++++++++++ .../third_party_driver/common/mcuboot.c | 9 +- .../third_party_driver/common/ymodem.c | 4 +- .../third_party_driver/include/imxrt_ota.h | 52 +++++ .../third_party_driver/include/mcuboot.h | 2 + .../third_party_driver/include/ymodem.h | 2 +- 10 files changed, 304 insertions(+), 17 deletions(-) create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c create mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c index 6fea57bb5..e754866df 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c @@ -65,7 +65,7 @@ Modification: #endif #ifdef BSP_USING_OTA -#include +#include #endif #ifdef BSP_USING_SEMC @@ -365,6 +365,31 @@ struct InitSequenceDesc _board_init[] = { " NONE ",NONE }, }; + +#ifdef BSP_USING_OTA +static void OtaCmd(void) +{ + int32_t Size; + + FLASH_Init(); + UartConfig(); + UpdateOTAStatus(OTA_STATUS_DOWNLOADING); + Size = SerialDownload(DOWN_FLAH_ADDRESS); + UpdateOTAStatus(OTA_STATUS_DOWNLOADED); + if(Size > 0) + { + UpdateOTAFlag(Size, 0x11223344, OTA_STATUS_READY, "OTA Test!","No error!"); + } + FLASH_DeInit(); + + __set_FAULTMASK(1); + NVIC_SystemReset(); +} + +SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),ota, OtaCmd, ota function); + +#endif + /** * This function will initial imxrt1050 board. */ @@ -412,9 +437,4 @@ void InitBoardHardware() } KPrintf("board init done.\n"); KPrintf("start kernel...\n"); -#ifdef BSP_USING_OTA - FLASH_Init(); - //Flash operation - FLASH_DeInit(); -#endif } diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/include/board.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/include/board.h index c96c9805f..e0ed54d25 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/include/board.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/include/board.h @@ -33,7 +33,7 @@ Modification: #include "fsl_clock.h" #include "fsl_enet.h" #include "clock_config.h" -// #include +#include #include extern int heap_start; diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile index 7f0219b14..7c6193cfd 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile @@ -5,7 +5,7 @@ ifeq ($(CONFIG_BSP_USING_SDIO),y) endif ifeq ($(CONFIG_BSP_USING_OTA),y) - SRC_FILES += fsl_romapi.c flash.c mcuboot.c common.c ymodem.c + SRC_FILES += fsl_romapi.c flash.c mcuboot.c common.c ymodem.c imxrt_ota.c endif include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c index b8965c6d7..e7dca44fd 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c @@ -593,7 +593,7 @@ status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt) status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len) { /* For FlexSPI Memory ReadBack, use IP Command instead of AXI command for security */ - if((addr >= 0x60000000) && (addr < 0x70000000)) + if((addr >= 0x60000000) && (addr < 0x61000000)) { return FLASH_Read(addr, (void *)buf, len); } diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c new file mode 100644 index 000000000..ae6d5b690 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c @@ -0,0 +1,214 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file: imxrt_ota.c +* @brief: file imxrt_ota.c +* @version: 1.0 +* @author: AIIT XUOS Lab +* @date: 2023/3/24 +*/ +#include +#include +#include +#include "flash.h" +#include "common.h" +#include "imxrt_ota.h" + +static const uint32_t crc32tab[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + + +static uint32_t calculate_crc32(uint32_t addr, uint32_t len) +{ + uint32_t crc = 0xFFFFFFFF; + uint8_t byte = 0xFF; + + for(uint32_t i = 0; i < len; i++) + { + byte = *((volatile uint8_t *)(addr + i)); + crc = crc32tab[(crc ^ byte) & 0xff] ^ (crc >> 8); + } + return crc^0xFFFFFFFF; +} + +void UpdateOTAStatus(ota_status_t status) +{ + ota_info_t ota_info; + + //从Flash中读取OTA信息 + memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + ota_info.status = status; + flash_erase(FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + flash_write(FLAG_FLAH_ADDRESS,(void *)&ota_info,sizeof(ota_info_t)); +} + +void UpdateOTAFlag(uint32_t app_size, uint32_t version, uint32_t status, uint8_t* description, uint8_t* error_message) +{ + ota_info_t ota_info; // 定义OTA信息结构体 + + // 从Flash中读取OTA信息 + memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + ota_info.app_size = app_size; + ota_info.crc = calculate_crc32(DOWN_FLAH_ADDRESS, app_size); + ota_info.version = version; + strncpy(ota_info.description, description,sizeof(ota_info.description)); + ota_info.status = status; + strncpy(ota_info.error_message, error_message,sizeof(ota_info.error_message)); + + flash_erase(FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + flash_write(FLAG_FLAH_ADDRESS,(void *)&ota_info,sizeof(ota_info_t)); +} + +void UpdateApplication(void) +{ + status_t status; + ota_info_t ota_info; // 定义OTA信息结构体 + + // 从Flash中读取OTA信息 + memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + + // 如果OTA升级状态为准备状态,可以进行升级 + if(ota_info.status == OTA_STATUS_READY) + { + Serial_PutString("\r\n------Start to update the app!------\r\n"); + // 校验固件CRC + if(calculate_crc32(DOWN_FLAH_ADDRESS, ota_info.app_size) == ota_info.crc) + { + // 如果CRC校验通过,开始升级,逐字节搬移 + UpdateOTAStatus(OTA_STATUS_UPDATING); + status = flash_copy(XIUOS_FLAH_ADDRESS,BAKUP_FLAH_ADDRESS,ota_info.app_size); + if(status != kStatus_Success) + { + Serial_PutString("------Backup app failed!------\r\n"); + goto finish; + } + status = flash_copy(DOWN_FLAH_ADDRESS,XIUOS_FLAH_ADDRESS,ota_info.app_size); + if(status != kStatus_Success) + { + Serial_PutString("------Firmware partition copy failed!------\r\n"); + goto finish; + } + + // 校验搬移后的固件CRC + if(calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.app_size) == ota_info.crc) + { + ota_info.status = OTA_STATUS_IDLE; // 将OTA升级状态设置为IDLE + memset(ota_info.error_message,0,sizeof(ota_info.error_message)); // 清空错误信息 + + // 将更新后的OTA信息写入Flash中 + flash_erase(FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + flash_write(FLAG_FLAH_ADDRESS,(void *)&ota_info,sizeof(ota_info_t)); + Serial_PutString("\r\n------Update completed!------\r\n"); + goto finish; + } + else + { + // 如果搬移后的固件CRC校验失败,升级失败 + ota_info.status = OTA_STATUS_ERROR; // 将OTA升级状态设置为ERROR + memset(ota_info.error_message,0,sizeof(ota_info.error_message)); + snprintf((char *)ota_info.error_message, sizeof(ota_info.error_message), "APP Firmware CRC check failed!"); // 记录错误信息 + + // 将更新后的OTA信息写入Flash中 + flash_erase(FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + flash_write(FLAG_FLAH_ADDRESS,(void *)&ota_info,sizeof(ota_info_t)); + Serial_PutString("\r\n------APP Firmware CRC check failed!------\r\n"); + goto finish; + } + } + else + { + // 如果CRC校验失败,升级失败 + ota_info.status = OTA_STATUS_ERROR; // 将OTA升级状态设置为ERROR + memset(ota_info.error_message,0,sizeof(ota_info.error_message)); + snprintf((char *)ota_info.error_message, sizeof(ota_info.error_message), "Download Firmware CRC check failed"); // 记录错误信息 + + // 将更新后的OTA信息写入Flash中 + flash_erase(FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + flash_write(FLAG_FLAH_ADDRESS,(void *)&ota_info,sizeof(ota_info_t)); + Serial_PutString("\r\n------Download Firmware CRC check failed!------\r\n"); + goto finish; + } + } + else + { + Serial_PutString("\r\n------No need to update the app!------\r\n"); + goto finish; + } +finish: + // 跳转到应用程序 + jump_to_application(); +} 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 2326782d2..c1113d6a0 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 @@ -15,15 +15,13 @@ #include #include -#include "flash.h" -#include "mcuboot.h" -#include "ymodem.h" +#include "imxrt_ota.h" #include "common.h" #ifdef MCUBOOT_BOOTLOADER extern void ImxrtMsDelay(uint32 ms); -static void jump_to_application(void) +void jump_to_application(void) { SCB->VTOR = (uint32_t)XIUOS_FLAH_ADDRESS; @@ -36,7 +34,6 @@ static void jump_to_application(void) asm volatile("BX R0"); } - void BootLoaderJumpApp(void) { uint8_t ch1, ch2; @@ -76,7 +73,7 @@ void BootLoaderJumpApp(void) break; case 0x32: FLASH_Init(); - SerialDownload(XIUOS_FLAH_ADDRESS); + UpdateApplication(); FLASH_DeInit(); break; case 0x33: 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 1d1b5bc05..f894864d9 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 @@ -351,7 +351,7 @@ int32_t Ymodem_Receive (uint8_t *buf, const uint32_t addr) * @param flash start addr * @retval None */ -void SerialDownload(const uint32_t addr) +int32_t SerialDownload(const uint32_t addr) { uint8_t Number[10] = {0}; int32_t Size = 0; @@ -384,4 +384,6 @@ void SerialDownload(const uint32_t addr) { Serial_PutString("\n\rFailed to receive the file!\n\r"); } + + return Size; } diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h new file mode 100644 index 000000000..de01ab168 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file: imxrt_ota.h +* @brief: file imxrt_ota.h +* @version: 1.0 +* @author: AIIT XUOS Lab +* @date: 2023/3/24 +*/ + +#ifndef __IMXRT_OTA__H__ +#define __IMXRT_OTA__H__ + +#include +#include "mcuboot.h" +#include "flash.h" +#include "ymodem.h" + +typedef enum { + OTA_STATUS_IDLE = 0, // 绌洪棽鐘舵侊紝娌℃湁杩涜OTA鍗囩骇 + OTA_STATUS_READY, // 鍑嗗鐘舵侊紝鍙互杩涜OTA鍗囩骇 + OTA_STATUS_DOWNLOADING, // 姝e湪涓嬭浇鍥轰欢 + OTA_STATUS_DOWNLOADED, // 鍥轰欢涓嬭浇瀹屾垚锛屽彲浠ヨ繘琛屽崌绾 + OTA_STATUS_UPDATING, // 姝e湪杩涜OTA鍗囩骇 + OTA_STATUS_ERROR, // 鍑虹幇閿欒锛屽崌绾уけ璐 +} ota_status_t; + +typedef struct { + uint32_t app_size; // 搴旂敤绋嬪簭澶у皬 + uint32_t crc; // 搴旂敤绋嬪簭CRC鏍¢獙鍊 + uint32_t version; // 搴旂敤绋嬪簭鐗堟湰鍙 + uint32_t status; // 鍗囩骇鐘舵 + uint8_t description[64]; // 搴旂敤绋嬪簭鍗囩骇璇存槑锛屾渶澶64涓瓧绗 + uint8_t error_message[64]; // 閿欒淇℃伅锛屾渶澶64涓瓧绗 +} ota_info_t; + + +void UpdateOTAStatus(ota_status_t status); +void UpdateOTAFlag(uint32_t app_size, uint32_t version, uint32_t status, uint8_t* description, uint8_t* error_message); +void UpdateApplication(void); + +#endif diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h index 967559fa7..f3fa1806b 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h @@ -23,5 +23,7 @@ #include "fsl_gpio.h" #include "fsl_lpuart.h" +void jump_to_application(void); + #endif 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 7ffd0710f..c08c1221f 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 @@ -52,7 +52,7 @@ #define NAK_TIMEOUT (0x100000) #define MAX_ERRORS (5) -void SerialDownload(const uint32_t addr); +int32_t SerialDownload(const uint32_t addr); int32_t Ymodem_Receive (uint8_t *buf, const uint32_t addr); #endif From 6074b2b1478398cf954cdd02d15b1be80a240877 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Fri, 21 Apr 2023 10:15:15 +0800 Subject: [PATCH 08/15] Add function comments for flash related functions --- .../third_party_driver/common/flash.c | 219 ++++++++++++++-- .../third_party_driver/common/imxrt_ota.c | 34 +++ .../third_party_driver/common/ymodem.c | 234 +++++++++--------- .../third_party_driver/include/ymodem.h | 3 +- 4 files changed, 361 insertions(+), 129 deletions(-) diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c index e7dca44fd..7091142e8 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c @@ -18,7 +18,7 @@ #include "flash.h" #include "MIMXRT1052.h" -uint8_t NorFlash_BUFFER[4096]; //4K buffer cache +uint8_t NorFlash_BUFFER[4096]; //4K buffer cache uint8_t buffer[FLASH_PAGE_SIZE]; //256 bytes buffer cache /******************************************************************************* * Prototypes @@ -26,8 +26,8 @@ uint8_t buffer[FLASH_PAGE_SIZE]; //256 bytes buffer cache static status_t Flexspi_Nor_Wait_Busy(uint32_t instance, uint32_t baseAddr); static status_t Flexspi_Nor_Write_Enable(uint32_t instance, uint32_t baseAddr); static void flexspi_clock_config(uint32_t instance, uint32_t freq, uint32_t sampleClkMode); -static void flexspi_clock_gate_enable(uint32_t instance); -static void flexspi_clock_gate_disable(uint32_t instance); +static void flexspi_clock_gate_enable(void); +static void flexspi_clock_gate_disable(void); static status_t flexspi_get_clock(uint32_t instance, flexspi_clock_type_t type, uint32_t *freq); static status_t flexspi_get_ticks(uint32_t *ticks, uint32_t intervalNs, uint32_t freq, uint32_t unit); static status_t flexspi_configure_dll(uint32_t instance, flexspi_mem_config_t *config); @@ -57,6 +57,13 @@ static const lookuptable_t FlashLookupTable={ }; +/******************************************************************************* +* 函 数 名: Flexspi_Nor_Wait_Busy +* 功能描述: 等待FlexSPI NOR Flash忙碌状态结束 +* 形 参: instance:FlexSPI实例号 + baseAddr:开始读取的Flash地址(32bit) +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +*******************************************************************************/ static status_t Flexspi_Nor_Wait_Busy(uint32_t instance, uint32_t baseAddr) { status_t status = kStatus_InvalidArgument; @@ -93,6 +100,13 @@ static status_t Flexspi_Nor_Wait_Busy(uint32_t instance, uint32_t baseAddr) } +/******************************************************************************* +* 函 数 名: Flexspi_Nor_Write_Enable +* 功能描述: 使能 FlexSPI NOR Flash的写入操作 +* 形 参: instance:FlexSPI实例号 + baseAddr:开始读取的Flash地址(32bit) +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +*******************************************************************************/ static status_t Flexspi_Nor_Write_Enable(uint32_t instance, uint32_t baseAddr) { status_t status = kStatus_InvalidArgument; @@ -110,6 +124,14 @@ static status_t Flexspi_Nor_Write_Enable(uint32_t instance, uint32_t baseAddr) } +/******************************************************************************* +* 函 数 名: flexspi_clock_config +* 功能描述: 配置FlexSPI模块的时钟 +* 形 参: instance:FlexSPI实例号 + freq:表示所需的FlexSPI时钟频率 + sampleClkMode:指定FlexSPI时钟的采样时钟模式,可以选择SDR或DDR模式 +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +*******************************************************************************/ static void flexspi_clock_config(uint32_t instance, uint32_t freq, uint32_t sampleClkMode) { uint32_t pfd480 = 0; @@ -166,7 +188,7 @@ static void flexspi_clock_config(uint32_t instance, uint32_t freq, uint32_t samp cscmr1 |= CCM_CSCMR1_FLEXSPI_PODF(podf - 1); FLEXSPI->MCR0 |= FLEXSPI_MCR0_MDIS_MASK; - flexspi_clock_gate_disable(instance); + flexspi_clock_gate_disable(); if(pfd480 != CCM_ANALOG->PFD_480) { @@ -176,7 +198,7 @@ static void flexspi_clock_config(uint32_t instance, uint32_t freq, uint32_t samp { CCM->CSCMR1 = cscmr1; } - flexspi_clock_gate_enable(instance); + flexspi_clock_gate_enable(); FLEXSPI->MCR0 &= ~FLEXSPI_MCR0_MDIS_MASK; } else @@ -187,18 +209,38 @@ static void flexspi_clock_config(uint32_t instance, uint32_t freq, uint32_t samp } -static void flexspi_clock_gate_enable(uint32_t instance) +/******************************************************************************* +* 函 数 名: flexspi_clock_gate_enable +* 功能描述: 开启FlexSPI模块的时钟门控 +* 形 参: 无 +* 返 回 值: 无 +*******************************************************************************/ +static void flexspi_clock_gate_enable(void) { CCM->CCGR6 |= CCM_CCGR6_CG5_MASK; } -static void flexspi_clock_gate_disable(uint32_t instance) +/******************************************************************************* +* 函 数 名: flexspi_clock_gate_disable +* 功能描述: 关闭FlexSPI模块的时钟门控 +* 形 参: 无 +* 返 回 值: 无 +*******************************************************************************/ +static void flexspi_clock_gate_disable(void) { CCM->CCGR6 &= (uint32_t)~CCM_CCGR6_CG5_MASK; } +/******************************************************************************* +* 函 数 名: flexspi_get_clock +* 功能描述: 获取FlexSPI时钟频率 +* 形 参: instance:FlexSPI实例号 + type:所需时钟类型 + freq:用于存储获取到的时钟频率类型 +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +*******************************************************************************/ static status_t flexspi_get_clock(uint32_t instance, flexspi_clock_type_t type, uint32_t *freq) { uint32_t clockFrequency = 0; @@ -248,6 +290,15 @@ static status_t flexspi_get_clock(uint32_t instance, flexspi_clock_type_t type, } +/******************************************************************************* +* 函 数 名: flexspi_get_ticks +* 功能描述: 计算FlexSPI时钟周期数 +* 形 参: ticks:用于存储计算结果的指针,即所需的时钟周期数; + intervalNs:所需的时间间隔,以纳秒(ns)为单位; + freq:FlexSPI时钟频率,单位为MHz; + unit:时钟周期单位,即计算结果中每个时钟周期代表的时间长度,以ns为单位 +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +*******************************************************************************/ static status_t flexspi_get_ticks(uint32_t *ticks, uint32_t intervalNs, uint32_t freq, uint32_t unit) { status_t status = kStatus_InvalidArgument; @@ -278,6 +329,13 @@ static status_t flexspi_get_ticks(uint32_t *ticks, uint32_t intervalNs, uint32_t } +/******************************************************************************* +* 函 数 名: flexspi_configure_dll +* 功能描述: 用来配置FLEXSPI存储器的DLL(延迟锁存器) +* 形 参: instance:FLEXSPI实例号 + config:存储器配置信息,包括读取时钟源、数据有效时间等参数 +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +*******************************************************************************/ static status_t flexspi_configure_dll(uint32_t instance, flexspi_mem_config_t *config) { status_t status = kStatus_InvalidArgument; @@ -414,6 +472,13 @@ static status_t flexspi_configure_dll(uint32_t instance, flexspi_mem_config_t *c } +/******************************************************************************* +* 函 数 名: flexspi_config_mcr1 +* 功能描述: 配置FlexSPI模块的MCR1寄存器 +* 形 参: instance:FLEXSPI实例号 + onfig指向FlexSPI存储器配置结构体的指针 +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +*******************************************************************************/ static status_t flexspi_config_mcr1(uint32_t instance, flexspi_mem_config_t *config) { uint32_t seqWaitTicks = 0xFFFFu; @@ -447,6 +512,12 @@ static status_t flexspi_config_mcr1(uint32_t instance, flexspi_mem_config_t *con } +/******************************************************************************* +* 函 数 名: FLASH_GetSectorSize +* 功能描述: 获取扇区大小 +* 形 参: 无 +* 返 回 值: 返回扇区大小,HYPER FLASH为64K字节,NOR FLASH为4K字节 +*******************************************************************************/ uint32_t FLASH_GetSectorSize(void) { #ifndef HYPER_FLASH @@ -457,6 +528,12 @@ uint32_t FLASH_GetSectorSize(void) } +/******************************************************************************* +* 函 数 名: FLASH_GetProgramCmd +* 功能描述: 获取页大小 +* 形 参: 无 +* 返 回 值: 返回页大小,HYPER FLASH为512字节,NOR FLASH为256字节 +*******************************************************************************/ uint32_t FLASH_GetProgramCmd(void) { uint32_t Program_Unit; @@ -470,6 +547,12 @@ uint32_t FLASH_GetProgramCmd(void) } +/******************************************************************************* +* 函 数 名: FLASH_Init +* 功能描述: Flash接口初始化,需在进行Flash相关操作前进行调用 +* 形 参: 无 +* 返 回 值: 无 +*******************************************************************************/ void FLASH_Init(void) { /* Update LUT Table for Status, Write Enable, Erase and Program */ @@ -483,6 +566,12 @@ void FLASH_Init(void) } +/******************************************************************************* +* 函 数 名: FLASH_DeInit +* 功能描述: Flash接口反初始化,需在完成Flash相关操作后进行调用 +* 形 参: 无 +* 返 回 值: 无 +*******************************************************************************/ void FLASH_DeInit(void) { lookuptable_t clearlut; @@ -493,6 +582,13 @@ void FLASH_DeInit(void) } +/******************************************************************************* +* 函 数 名: FLASH_EraseSector +* 功能描述: 擦除一个Flash扇区 +* 形 参: addr:擦除区域起始地址 +* 返 回 值: None +* 注 释: 擦除一个扇区的最少时间:30ms~200/400ms +*******************************************************************************/ uint8_t FLASH_EraseSector(uint32_t addr) { status_t status; @@ -516,6 +612,15 @@ uint8_t FLASH_EraseSector(uint32_t addr) } +/******************************************************************************* +* 函 数 名: FLASH_WritePage +* 功能描述: 写Flash一个页 +* 形 参: addr:写入区域起始地址 + buf:数据存储区 + len:要写入的字节数(最大256) +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 注 释: 在指定地址开始写入最大256字节的数据 +*******************************************************************************/ uint8_t FLASH_WritePage(uint32_t addr, const uint32_t *buf, uint32_t len) { status_t status; @@ -542,6 +647,14 @@ uint8_t FLASH_WritePage(uint32_t addr, const uint32_t *buf, uint32_t len) } +/******************************************************************************* +* 函 数 名: FLASH_Read +* 功能描述: 读Flash内容 +* 形 参: addr:读取区域起始地址 + buf:数据存储区 + len:要读取的字节数 +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +*******************************************************************************/ status_t FLASH_Read(uint32_t addr, uint32_t *buf, uint32_t len) { status_t status; @@ -566,6 +679,14 @@ status_t FLASH_Read(uint32_t addr, uint32_t *buf, uint32_t len) } +/******************************************************************************* +* 函 数 名: flash_erase +* 功能描述: 擦除Flash指定长度的空间 +* 形 参: addr:擦除区域起始地址 + byte_cnt:要擦除的字节数,以4k字节为最小擦除单位 +* 返 回 值: None +* 注 释: 不满4k字节的,也需要擦除掉4k字节 +*******************************************************************************/ status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt) { uint32_t addr; @@ -584,12 +705,30 @@ status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt) return status; } + +/******************************************************************************* +* 函 数 名: flash_write +* 功能描述: 与FLASH_WritePage功能相同,写Flash一个页 +* 形 参: addr:写入区域起始地址 + buf:数据存储区 + len:要写入的字节数(最大256) +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 注 释: 在指定地址开始写入最大256字节的数据 +*******************************************************************************/ status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt) { return FLASH_WritePage(start_addr, (void *)buf, byte_cnt); } +/******************************************************************************* +* 函 数 名: flash_read +* 功能描述: 读Flash内容 +* 形 参: addr:读取区域起始地址 + buf:数据存储区 + len:要读取的字节数 +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +*******************************************************************************/ status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len) { /* For FlexSPI Memory ReadBack, use IP Command instead of AXI command for security */ @@ -614,12 +753,20 @@ status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len) } +/******************************************************************************* +* 函 数 名: flash_copy +* 功能描述: 实现flash数据在分区之间的拷贝 +* 形 参: srcAddr:源flash的起始地址 + dstAddr:目标flash的起始地址; + imageSize:要拷贝的flash空间大小,单位为字节 +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +*******************************************************************************/ status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize) { uint32_t PageNum, Remain, i; status_t status; - if((srcAddr == dstAddr) || imageSize > (APP_FLASH_SIZE + 1)) + if((srcAddr == dstAddr) || imageSize > APP_FLASH_SIZE) { return (status_t)kStatus_Fail; } @@ -672,6 +819,13 @@ status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize) } +/******************************************************************************* +* 函 数 名: NOR_FLASH_Erase +* 功能描述: 以扇区为擦除单位擦除Flash指定长度的空间,最终擦除的字节可能大于imageSize +* 形 参: addr:擦除区域起始地址 + imageSize:要擦除的字节数 +* 返 回 值: None +*******************************************************************************/ status_t NOR_FLASH_Erase(uint32_t app_base_addr,uint32_t imageSize) { uint16_t i; @@ -691,6 +845,15 @@ status_t NOR_FLASH_Erase(uint32_t app_base_addr,uint32_t imageSize) } +/******************************************************************************* +* 函 数 名: NorFlash_Write_PageProgram +* 功能描述: 写入Flash指定长度的数据 +* 形 参: pBuffer:数据存储区 + WriteAddr:写入区域起始地址 + NumByteToWrite:要写入的字节数(最大256) +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 注 释: 在指定地址开始写入最大256字节的数据 +*******************************************************************************/ void NorFlash_Write_PageProgram(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite) { uint8_t temp_data[256] = {0xff}; @@ -705,7 +868,17 @@ void NorFlash_Write_PageProgram(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t Num } -void NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite) +/******************************************************************************* +* 函 数 名: NorFlash_Write_NoCheck +* 功能描述: 无检验写入W25QXX从指定地址开始指定长度的数据 +* 形 参: pBuffer:数据存储区 + WriteAddr:开始写入的地址(24bit) + NumByteToWrite:要写入的字节数(最大65535) +* 返 回 值: 无 +* 注 释: 必须确保所写的地址范围内的数据全部为0XFF,否则在非0XFF处写入的数据将失败! + 具有自动换页功能,在指定地址开始写入指定长度的数据,但是要确保地址不越界! +*******************************************************************************/ +void NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite) { uint16_t pageRemain; @@ -742,6 +915,15 @@ void NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByte } +/******************************************************************************* +* 函 数 名: NorFlash_Write +* 功能描述: 写入W25QXX在指定地址开始写入指定长度的数据 +* 形 参: pBuffer:数据存储区 + WriteAddr:开始写入的地址(24bit) + NumByteToWrite:要写入的字节数(最大65535) +* 返 回 值: None +* 注 释: 该函数带擦除操作 +*******************************************************************************/ void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite) { uint32_t secPos; @@ -754,16 +936,16 @@ void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite) WriteAddr &= 0x0FFFFFFF; - secPos = WriteAddr/SECTOR_SIZE;//扇区地址 + secPos = WriteAddr/SECTOR_SIZE;//扇区地址 secOff = WriteAddr%SECTOR_SIZE;//在扇区内的偏移 secRemain = SECTOR_SIZE - secOff;//扇区剩余空间大小 if(NumByteToWrite <= secRemain) { - secRemain = NumByteToWrite;//不大于4096个字节 - } + secRemain = NumByteToWrite;//不大于4096个字节 + } while(1) - { + { FLASH_Read(FLASH_BASE + secPos*SECTOR_SIZE, (void *)NorFlash_BUF, SECTOR_SIZE);//读出整个扇区的内容 for(i=0;i 0) + while(timeout-- > 0) { - if (SerialKeyPressed(c) == 1) + if(SerialKeyPressed(c) == 1) { return 0; } @@ -46,23 +45,27 @@ static int32_t Receive_Byte (uint8_t *c, uint32_t timeout) return -1; } -/** - * @brief Send a byte - * @param c: Character - * @retval 0: Byte sent - */ -static uint32_t Send_Byte (uint8_t c) + +/******************************************************************************* +* 鍑 鏁 鍚: Send_Byte +* 鍔熻兘鎻忚堪: 鍙戦佷竴涓瓧鑺傜殑鏁版嵁 +* 褰 鍙: c:瑕佸彂閫佺殑鏁版嵁 +* 杩 鍥 鍊: 0 +*******************************************************************************/ +static uint32_t Send_Byte(uint8_t c) { SerialPutChar(c); return 0; } -/** - * @brief Update CRC16 for input byte - * @param CRC input value - * @param input byte - * @retval Updated CRC value - */ + +/******************************************************************************* +* 鍑 鏁 鍚: UpdateCRC16 +* 鍔熻兘鎻忚堪: 鏇存柊杈撳叆鏁版嵁鐨凜RC16鏍¢獙 +* 褰 鍙: crcIn:杈撳叆鐨16浣峜rc鏁版嵁 + byte:杈撳叆鐨8浣嶆暟鎹 +* 杩 鍥 鍊: 鏇存柊鍚庣殑crc鏁版嵁 +*******************************************************************************/ uint16_t UpdateCRC16(uint16_t crcIn, uint8_t byte) { uint32_t crc = crcIn; @@ -87,12 +90,14 @@ uint16_t UpdateCRC16(uint16_t crcIn, uint8_t byte) return (crc&0xffffu); } -/** - * @brief Cal CRC16 for YModem Packet - * @param data - * @param length - * @retval CRC value - */ + +/******************************************************************************* +* 鍑 鏁 鍚: Cal_CRC16 +* 鍔熻兘鎻忚堪: 璁$畻CRC16,鐢ㄤ簬YModem鐨勬暟鎹寘 +* 褰 鍙: data:鏁版嵁buffer + size:鏁版嵁闀垮害 +* 杩 鍥 鍊: 鐢熸垚鐨刢rc鏁版嵁 +*******************************************************************************/ uint16_t Cal_CRC16(const uint8_t* data, uint32_t size) { uint32_t crc = 0; @@ -108,12 +113,14 @@ uint16_t Cal_CRC16(const uint8_t* data, uint32_t size) return (crc&0xffffu); } -/** - * @brief Cal Check sum for YModem Packet - * @param data - * @param length - * @retval None - */ + +/******************************************************************************* +* 鍑 鏁 鍚: CalChecksum +* 鍔熻兘鎻忚堪: 璁$畻妫鏌Modem鏁版嵁鍖呯殑鎬诲拰 +* 褰 鍙: data:鏁版嵁buffer + size:鏁版嵁闀垮害 +* 杩 鍥 鍊: 璁$畻鍒扮殑鏁版嵁鍖呮诲拰 +*******************************************************************************/ uint8_t CalChecksum(const uint8_t* data, uint32_t size) { uint32_t sum = 0; @@ -127,24 +134,21 @@ uint8_t CalChecksum(const uint8_t* data, uint32_t size) return (sum&0xffu); } -/** - * @brief Receive a packet from sender - * @param data - * @param length - * @param timeout - * 0: end of transmission - * -1: abort by sender - * >0: packet length - * @retval 0: normally return - * -1: timeout or packet error - * 1: abort by user - */ -static int32_t Receive_Packet (uint8_t *data, int32_t *length, uint32_t timeout) + +/******************************************************************************* +* 鍑 鏁 鍚: Receive_Packet +* 鍔熻兘鎻忚堪: 浠庡彂閫佹柟鎺ユ敹鏁版嵁鍖 +* 褰 鍙: data:鏁版嵁buffer + length:瀛樺偍鏁版嵁闀垮害鐨勬寚閽 + timeout:瓒呮椂鏃堕棿 +* 杩 鍥 鍊: 0:姝e父杩斿洖,-1:鍙戦佽呬腑姝/瓒呮椂/鏁版嵁鍖呴敊璇,1:鐢ㄦ埛涓 +*******************************************************************************/ +static int32_t Receive_Packet(uint8_t *data, int32_t *length, uint32_t timeout) { uint16_t i, packet_size, computedcrc; uint8_t c; *length = 0; - if (Receive_Byte(&c, timeout) != 0) + if(Receive_Byte(&c, timeout) != 0) { return -1; } @@ -159,7 +163,7 @@ static int32_t Receive_Packet (uint8_t *data, int32_t *length, uint32_t timeout) case EOT: return 0; case CA: - if ((Receive_Byte(&c, timeout) == 0) && (c == CA)) + if((Receive_Byte(&c, timeout) == 0) && (c == CA)) { *length = -1; return 0; @@ -175,14 +179,14 @@ static int32_t Receive_Packet (uint8_t *data, int32_t *length, uint32_t timeout) return -1; } *data = c; - for (i = 1; i < (packet_size + PACKET_OVERHEAD); i ++) + for(i = 1; i < (packet_size + PACKET_OVERHEAD); i ++) { - if (Receive_Byte(data + i, timeout) != 0) + if(Receive_Byte(data + i, timeout) != 0) { return -1; } } - if (data[PACKET_SEQNO_INDEX] != ((data[PACKET_SEQNO_COMP_INDEX] ^ 0xff) & 0xff)) + if(data[PACKET_SEQNO_INDEX] != ((data[PACKET_SEQNO_COMP_INDEX] ^ 0xff) & 0xff)) { return -1; } @@ -192,7 +196,7 @@ static int32_t Receive_Packet (uint8_t *data, int32_t *length, uint32_t timeout) /* Check that received CRC match the already computed CRC value data[packet_size+3]<<8) | data[packet_size+4] contains the received CRC computedcrc contains the computed CRC value */ - if (computedcrc != (uint16_t)((data[packet_size+3]<<8) | data[packet_size+4])) + if(computedcrc != (uint16_t)((data[packet_size+3]<<8) | data[packet_size+4])) { /* CRC error */ return -1; @@ -202,12 +206,16 @@ static int32_t Receive_Packet (uint8_t *data, int32_t *length, uint32_t timeout) return 0; } -/** - * @brief Receive a file using the ymodem protocol - * @param buf: Address of the first byte,addr:download flash start address - * @retval The size of the file - */ -int32_t Ymodem_Receive (uint8_t *buf, const uint32_t addr) + +/******************************************************************************* +* 鍑 鏁 鍚: Ymodem_Receive +* 鍔熻兘鎻忚堪: 浣跨敤ymodem鍗忚鎺ユ敹鏂囦欢 +* 褰 鍙: buf:鏁版嵁buffer + addr:涓嬭浇flash璧峰鍦板潃 + timeout:瓒呮椂鏃堕棿 +* 杩 鍥 鍊: 鏂囦欢鐨勫ぇ灏 +*******************************************************************************/ +int32_t Ymodem_Receive(uint8_t *buf, const uint32_t addr) { uint8_t packet_data[PACKET_1K_SIZE + PACKET_OVERHEAD], file_size[FILE_SIZE_LENGTH], *file_ptr, *buf_ptr; int32_t i, packet_length, session_done, file_done, packets_received, errors, session_begin, size = 0; @@ -216,15 +224,15 @@ int32_t Ymodem_Receive (uint8_t *buf, const uint32_t addr) /* Initialize flashdestination variable */ flashdestination = addr; - for (session_done = 0, errors = 0, session_begin = 0; ;) + for(session_done = 0, errors = 0, session_begin = 0; ;) { - for (packets_received = 0, file_done = 0, buf_ptr = buf; ;) + for(packets_received = 0, file_done = 0, buf_ptr = buf; ;) { - switch (Receive_Packet(packet_data, &packet_length, NAK_TIMEOUT)) + switch(Receive_Packet(packet_data, &packet_length, NAK_TIMEOUT)) { case 0: errors = 0; - switch (packet_length) + switch(packet_length) { /* Abort by sender */ case - 1: @@ -237,24 +245,24 @@ int32_t Ymodem_Receive (uint8_t *buf, const uint32_t addr) break; /* Normal packet */ default: - if ((packet_data[PACKET_SEQNO_INDEX] & 0xff) != (packets_received & 0xff)) + if((packet_data[PACKET_SEQNO_INDEX] & 0xff) != (packets_received & 0xff)) { Send_Byte(NAK); } else { - if (packets_received == 0) + if(packets_received == 0) { /* Filename packet */ - if (packet_data[PACKET_HEADER] != 0) + if(packet_data[PACKET_HEADER] != 0) { /* Filename packet has valid data */ - for (i = 0, file_ptr = packet_data + PACKET_HEADER; (*file_ptr != 0) && (i < FILE_NAME_LENGTH);) + for(i = 0, file_ptr = packet_data + PACKET_HEADER; (*file_ptr != 0) && (i < FILE_NAME_LENGTH);) { FileName[i++] = *file_ptr++; } FileName[i++] = '\0'; - for (i = 0, file_ptr ++; (*file_ptr != ' ') && (i < (FILE_SIZE_LENGTH - 1));) + for(i = 0, file_ptr ++; (*file_ptr != ' ') && (i < (FILE_SIZE_LENGTH - 1));) { file_size[i++] = *file_ptr++; } @@ -263,7 +271,7 @@ int32_t Ymodem_Receive (uint8_t *buf, const uint32_t addr) /* Test the size of the image to be sent */ /* Image size is greater than Flash size */ - if (size > (USER_FLASH_SIZE + 1)) + if(size > APP_FLASH_SIZE) { /* End session */ Send_Byte(CA); @@ -292,9 +300,9 @@ int32_t Ymodem_Receive (uint8_t *buf, const uint32_t addr) /* Write received data in Flash */ #ifndef USE_HIGHT_SPEED_TRANS - if (NOR_FLASH_Write(&flashdestination, buf, (uint16_t) packet_length) == 0) + if(NOR_FLASH_Write(&flashdestination, buf, (uint16_t)packet_length) == 0) #else - if (NOR_FLASH_Write(&flashdestination, buf, (uint16_t) packet_length,0) == 0) + if(NOR_FLASH_Write(&flashdestination, buf, (uint16_t)packet_length, 0) == 0) #endif { Send_Byte(ACK); @@ -317,11 +325,11 @@ int32_t Ymodem_Receive (uint8_t *buf, const uint32_t addr) Send_Byte(CA); return -3; default: - if (session_begin > 0) + if(session_begin > 0) { errors ++; } - if (errors > MAX_ERRORS) + if(errors > MAX_ERRORS) { Send_Byte(CA); Send_Byte(CA); @@ -330,12 +338,12 @@ int32_t Ymodem_Receive (uint8_t *buf, const uint32_t addr) Send_Byte(CRC16); break; } - if (file_done != 0) + if(file_done != 0) { break; } } - if (session_done != 0) + if(session_done != 0) { break; } @@ -346,44 +354,46 @@ int32_t Ymodem_Receive (uint8_t *buf, const uint32_t addr) return (int32_t)size; } -/** - * @brief Download a file via serial port - * @param flash start addr - * @retval None - */ + +/******************************************************************************* +* 鍑 鏁 鍚: SerialDownload +* 鍔熻兘鎻忚堪: 閫氳繃涓插彛涓嬭浇鏂囦欢 +* 褰 鍙: addr:瀛樺偍鏂囦欢鐨刦lash璧峰鍦板潃 +* 杩 鍥 鍊: 鏂囦欢鐨勫ぇ灏 +*******************************************************************************/ int32_t SerialDownload(const uint32_t addr) { - uint8_t Number[10] = {0}; - int32_t Size = 0; + uint8_t Number[10] = {0}; + int32_t Size = 0; - Serial_PutString("Waiting for the file to be sent ... (press 'a' to abort)\n\r"); - Size = Ymodem_Receive(&tab_1024[0], addr); - if (Size > 0) - { - Serial_PutString("\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: "); - Serial_PutString(FileName); - Int2Str(Number, Size); - Serial_PutString("\n\r Size: "); - Serial_PutString(Number); - Serial_PutString(" Bytes\r\n"); - Serial_PutString("-------------------\n"); - } - else if (Size == -1) - { - Serial_PutString("\n\n\rThe image size is higher than the allowed space memory!\n\r"); - } - else if (Size == -2) - { - Serial_PutString("\n\n\rVerification failed!\n\r"); - } - else if (Size == -3) - { - Serial_PutString("\r\n\nAborted by user.\n\r"); - } - else - { - Serial_PutString("\n\rFailed to receive the file!\n\r"); - } + Serial_PutString("Waiting for the file to be sent ... (press 'a' to abort)\n\r"); + Size = Ymodem_Receive(&tab_1024[0], addr); + if(Size > 0) + { + Serial_PutString("\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: "); + Serial_PutString(FileName); + Int2Str(Number, Size); + Serial_PutString("\n\r Size: "); + Serial_PutString(Number); + Serial_PutString(" Bytes\r\n"); + Serial_PutString("-------------------\n"); + } + else if(Size == -1) + { + Serial_PutString("\n\n\rThe image size is higher than the allowed space memory!\n\r"); + } + else if(Size == -2) + { + Serial_PutString("\n\n\rVerification failed!\n\r"); + } + else if(Size == -3) + { + Serial_PutString("\r\n\nAborted by user.\n\r"); + } + else + { + Serial_PutString("\n\rFailed to receive the file!\n\r"); + } - return Size; + return Size; } 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 c08c1221f..3ff7a28e4 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 @@ -25,7 +25,6 @@ #include #include "common.h" -#define USER_FLASH_SIZE 0x100000 //Application package size is limited to 1M #define PACKET_SEQNO_INDEX (1) #define PACKET_SEQNO_COMP_INDEX (2) @@ -53,6 +52,6 @@ #define MAX_ERRORS (5) int32_t SerialDownload(const uint32_t addr); -int32_t Ymodem_Receive (uint8_t *buf, const uint32_t addr); +int32_t Ymodem_Receive(uint8_t *buf, const uint32_t addr); #endif From cfadebc3e843e128fdeb7c4ee2112835d1f31508 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Sun, 23 Apr 2023 16:33:22 +0800 Subject: [PATCH 09/15] Optimize OTA information structure and flash_write function --- .../XiZi_IIoT/board/xidatong-arm32/board.c | 36 +++++- .../third_party_driver/common/flash.c | 24 +++- .../third_party_driver/common/imxrt_ota.c | 121 ++++++------------ .../third_party_driver/include/imxrt_ota.h | 44 +++++-- 4 files changed, 118 insertions(+), 107 deletions(-) diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c index e754866df..fe5b35a75 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c @@ -369,17 +369,35 @@ struct InitSequenceDesc _board_init[] = #ifdef BSP_USING_OTA static void OtaCmd(void) { - int32_t Size; + int32_t size; + ota_info_t ota_info; FLASH_Init(); UartConfig(); - UpdateOTAStatus(OTA_STATUS_DOWNLOADING); - Size = SerialDownload(DOWN_FLAH_ADDRESS); - UpdateOTAStatus(OTA_STATUS_DOWNLOADED); - if(Size > 0) + + memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + ota_info.status = OTA_STATUS_DOWNLOADING; + UpdateOTAFlag(&ota_info); + size = SerialDownload(DOWN_FLAH_ADDRESS); + ota_info.status = OTA_STATUS_DOWNLOADED; + UpdateOTAFlag(&ota_info); + if(size > 0) { - UpdateOTAFlag(Size, 0x11223344, OTA_STATUS_READY, "OTA Test!","No error!"); + ota_info.down.size = size; + ota_info.down.crc32= calculate_crc32(DOWN_FLAH_ADDRESS, size); + ota_info.down.version = 0x11223344; + strncpy(ota_info.down.description, "OTA Test!",sizeof(ota_info.down.description)); + ota_info.status = OTA_STATUS_READY; + strncpy(ota_info.error_message, "Download the firmware to the download partition successfully!",sizeof(ota_info.error_message)); + UpdateOTAFlag(&ota_info); } + else + { + ota_info.status = OTA_STATUS_ERROR; + strncpy(ota_info.error_message, "Failed to download firmware to download partition!",sizeof(ota_info.error_message)); + UpdateOTAFlag(&ota_info); + } + FLASH_DeInit(); __set_FAULTMASK(1); @@ -437,4 +455,10 @@ void InitBoardHardware() } KPrintf("board init done.\n"); KPrintf("start kernel...\n"); + +#ifdef BSP_USING_OTA + FLASH_Init(); + //璺宠浆鎴愬姛灏嗗搴旇烦杞け璐ユ爣蹇楁竻闆 + FLASH_DeInit(); +#endif } diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c index 7091142e8..93938e5ed 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c @@ -684,7 +684,7 @@ status_t FLASH_Read(uint32_t addr, uint32_t *buf, uint32_t len) * 功能描述: 擦除Flash指定长度的空间 * 形 参: addr:擦除区域起始地址 byte_cnt:要擦除的字节数,以4k字节为最小擦除单位 -* 返 回 值: None +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 * 注 释: 不满4k字节的,也需要擦除掉4k字节 *******************************************************************************/ status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt) @@ -708,16 +708,30 @@ status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt) /******************************************************************************* * 函 数 名: flash_write -* 功能描述: 与FLASH_WritePage功能相同,写Flash一个页 +* 功能描述: 在指定的flash起始地址写入指定长度的数据 * 形 参: addr:写入区域起始地址 buf:数据存储区 - len:要写入的字节数(最大256) + byte_cnt:要写入的字节数 * 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 -* 注 释: 在指定地址开始写入最大256字节的数据 *******************************************************************************/ status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt) { - return FLASH_WritePage(start_addr, (void *)buf, byte_cnt); + uint32_t size; + status_t status; + while(byte_cnt > 0) + { + size = byte_cnt > FLASH_PAGE_SIZE ? FLASH_PAGE_SIZE : byte_cnt; + status = FLASH_WritePage(start_addr, (void *)buf, size); + if(status != kStatus_Success) + { + return status; + } + start_addr += size; + buf += size; + byte_cnt -= size; + } + + return kStatus_Success; } diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c index c6b8c368e..db68e98ef 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c @@ -100,7 +100,7 @@ static const uint32_t crc32tab[] = { len:表示需要计算CRC32的数据长度 * 返 回 值: 计算得到的CRC32值 *******************************************************************************/ -static uint32_t calculate_crc32(uint32_t addr, uint32_t len) +uint32_t calculate_crc32(uint32_t addr, uint32_t len) { uint32_t crc = 0xFFFFFFFF; uint8_t byte = 0xFF; @@ -114,52 +114,26 @@ static uint32_t calculate_crc32(uint32_t addr, uint32_t len) } -/******************************************************************************* -* 函 数 名: UpdateOTAStatus -* 功能描述: 更新OTA的状态信息 -* 形 参: status:将要更改的状态值 -* 返 回 值: 无 -*******************************************************************************/ -void UpdateOTAStatus(ota_status_t status) -{ - ota_info_t ota_info; - - //从Flash中读取OTA信息 - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - ota_info.status = status; - flash_erase(FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - flash_write(FLAG_FLAH_ADDRESS,(void *)&ota_info,sizeof(ota_info_t)); -} - - /******************************************************************************* * 函 数 名: UpdateOTAFlag * 功能描述: 更新OTA Flag区域的信息,版本完成下载后在app里进行调用 -* 形 参: app_size:新的固件的大小,单位字节 - version:新的固件的版本 - status:OTA的状态信息 - description:新版本的固件描述 - error_message:更新过程中存储的错误信息 -* 返 回 值: 无 +* 形 参: ptr:ota_info_t结构体指针,描述OTA升级相关信息 +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 *******************************************************************************/ -void UpdateOTAFlag(uint32_t app_size, uint32_t version, uint32_t status, uint8_t* description, uint8_t* error_message) +status_t UpdateOTAFlag(ota_info_t *ptr) { - ota_info_t ota_info; // 定义OTA信息结构体 + status_t status; - // 从Flash中读取OTA信息 - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - ota_info.app_size = app_size; - ota_info.crc = calculate_crc32(DOWN_FLAH_ADDRESS, app_size); - ota_info.version = version; - strncpy(ota_info.description, description,sizeof(ota_info.description)); - ota_info.status = status; - strncpy(ota_info.error_message, error_message,sizeof(ota_info.error_message)); + status = flash_erase(FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + if(status != kStatus_Success) + { + return status; + } + status = flash_write(FLAG_FLAH_ADDRESS,(void *)ptr,sizeof(ota_info_t)); - flash_erase(FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - flash_write(FLAG_FLAH_ADDRESS,(void *)&ota_info,sizeof(ota_info_t)); + return status; } - /******************************************************************************* * 函 数 名: UpdateApplication * 功能描述: 在bootloader里进行调用,根据Flash中Flag分区中的信息决定是否进行版本更新 @@ -179,61 +153,44 @@ void UpdateApplication(void) if(ota_info.status == OTA_STATUS_READY) { Serial_PutString("\r\n------Start to update the app!------\r\n"); - // 校验固件CRC - if(calculate_crc32(DOWN_FLAH_ADDRESS, ota_info.app_size) == ota_info.crc) + // 校验downlad分区固件CRC + if(calculate_crc32(DOWN_FLAH_ADDRESS, ota_info.down.size) == ota_info.down.crc32) { - // 如果CRC校验通过,开始升级,逐字节搬移 - UpdateOTAStatus(OTA_STATUS_UPDATING); - status = flash_copy(XIUOS_FLAH_ADDRESS,BAKUP_FLAH_ADDRESS,ota_info.app_size); - if(status != kStatus_Success) + ota_info.status = OTA_STATUS_UPDATING; + UpdateOTAFlag(&ota_info); + + // 拷贝download分区到XiUOS System分区 + status = flash_copy(DOWN_FLAH_ADDRESS, XIUOS_FLAH_ADDRESS, ota_info.down.size); + if((status == kStatus_Success) &&(calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.down.size) == ota_info.down.crc32)) { - Serial_PutString("------Backup app failed!------\r\n"); - goto finish; + Serial_PutString("\r\n------The download partition is copied successfully!------\r\n"); + + ota_info.os.size = ota_info.down.size; + ota_info.os.crc32 = ota_info.down.crc32; + ota_info.os.version = ota_info.down.version; + strncpy(ota_info.os.description, ota_info.down.description, sizeof(ota_info.down.description)); + ota_info.status == OTA_STATUS_IDLE; // 拷贝download分区到XiUOS System分区成功,将OTA升级状态设置为IDLE + UpdateOTAFlag(&ota_info); } - status = flash_copy(DOWN_FLAH_ADDRESS,XIUOS_FLAH_ADDRESS,ota_info.app_size); - if(status != kStatus_Success) + else { - Serial_PutString("------Firmware partition copy failed!------\r\n"); + Serial_PutString("\r\n------The download partition copy failed!------\r\n"); + ota_info.status = OTA_STATUS_ERROR; + strncpy(ota_info.error_message, "The download partition copy failed!",sizeof(ota_info.error_message)); + UpdateOTAFlag(&ota_info); goto finish; } - // 校验搬移后的固件CRC - if(calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.app_size) == ota_info.crc) - { - ota_info.status = OTA_STATUS_IDLE; // 将OTA升级状态设置为IDLE - memset(ota_info.error_message,0,sizeof(ota_info.error_message)); // 清空错误信息 - - // 将更新后的OTA信息写入Flash中 - flash_erase(FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - flash_write(FLAG_FLAH_ADDRESS,(void *)&ota_info,sizeof(ota_info_t)); - Serial_PutString("\r\n------Update completed!------\r\n"); - goto finish; - } - else - { - // 如果搬移后的固件CRC校验失败,升级失败 - ota_info.status = OTA_STATUS_ERROR; // 将OTA升级状态设置为ERROR - memset(ota_info.error_message,0,sizeof(ota_info.error_message)); - snprintf((char *)ota_info.error_message, sizeof(ota_info.error_message), "APP Firmware CRC check failed!"); // 记录错误信息 - - // 将更新后的OTA信息写入Flash中 - flash_erase(FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - flash_write(FLAG_FLAH_ADDRESS,(void *)&ota_info,sizeof(ota_info_t)); - Serial_PutString("\r\n------APP Firmware CRC check failed!------\r\n"); - goto finish; - } + Serial_PutString("\r\n------Update completed!------\r\n"); + goto finish; } else { - // 如果CRC校验失败,升级失败 - ota_info.status = OTA_STATUS_ERROR; // 将OTA升级状态设置为ERROR - memset(ota_info.error_message,0,sizeof(ota_info.error_message)); - snprintf((char *)ota_info.error_message, sizeof(ota_info.error_message), "Download Firmware CRC check failed"); // 记录错误信息 - - // 将更新后的OTA信息写入Flash中 - flash_erase(FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - flash_write(FLAG_FLAH_ADDRESS,(void *)&ota_info,sizeof(ota_info_t)); + // 如果download分区CRC校验失败,升级失败 Serial_PutString("\r\n------Download Firmware CRC check failed!------\r\n"); + ota_info.status = OTA_STATUS_ERROR; + strncpy(ota_info.error_message, "Download Firmware CRC check failed!",sizeof(ota_info.error_message)); + UpdateOTAFlag(&ota_info); goto finish; } } diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h index de01ab168..ddd4f41bf 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h @@ -26,27 +26,43 @@ #include "flash.h" #include "ymodem.h" + +/* OTA鍗囩骇杩囩▼涓殑鐘舵佹弿杩 */ typedef enum { - OTA_STATUS_IDLE = 0, // 绌洪棽鐘舵侊紝娌℃湁杩涜OTA鍗囩骇 - OTA_STATUS_READY, // 鍑嗗鐘舵侊紝鍙互杩涜OTA鍗囩骇 - OTA_STATUS_DOWNLOADING, // 姝e湪涓嬭浇鍥轰欢 - OTA_STATUS_DOWNLOADED, // 鍥轰欢涓嬭浇瀹屾垚锛屽彲浠ヨ繘琛屽崌绾 - OTA_STATUS_UPDATING, // 姝e湪杩涜OTA鍗囩骇 - OTA_STATUS_ERROR, // 鍑虹幇閿欒锛屽崌绾уけ璐 + OTA_STATUS_IDLE = 0, // 绌洪棽鐘舵侊紝娌℃湁杩涜OTA鍗囩骇 + OTA_STATUS_READY, // 鍑嗗鐘舵侊紝鍙互杩涜OTA鍗囩骇 + OTA_STATUS_DOWNLOADING, // 姝e湪涓嬭浇鍥轰欢 + OTA_STATUS_DOWNLOADED, // 鍥轰欢涓嬭浇瀹屾垚锛屽彲浠ヨ繘琛屽崌绾 + OTA_STATUS_UPDATING, // 姝e湪杩涜OTA鍗囩骇 + OTA_STATUS_ERROR, // 鍑虹幇閿欒锛屽崌绾уけ璐 } ota_status_t; + +/* Flash鍒嗗尯涓繚瀛樺浐浠剁殑灞炴ф弿杩 */ typedef struct { - uint32_t app_size; // 搴旂敤绋嬪簭澶у皬 - uint32_t crc; // 搴旂敤绋嬪簭CRC鏍¢獙鍊 - uint32_t version; // 搴旂敤绋嬪簭鐗堟湰鍙 - uint32_t status; // 鍗囩骇鐘舵 - uint8_t description[64]; // 搴旂敤绋嬪簭鍗囩骇璇存槑锛屾渶澶64涓瓧绗 - uint8_t error_message[64]; // 閿欒淇℃伅锛屾渶澶64涓瓧绗 + uint32_t size; // 搴旂敤绋嬪簭澶у皬,璁板綍鍒嗗尯鍥轰欢鐨勫ぇ灏 + uint32_t crc32; // 搴旂敤绋嬪簭CRC32鏍¢獙鍊,璁板綍鍒嗗尯鍥轰欢鐨刢rc32鍊 + uint32_t version; // 搴旂敤绋嬪簭鐗堟湰鍙,璁板綍鍒嗗尯鍥轰欢鐨勭増鏈彿 + uint32_t reserve; // 淇濈暀瀛楁 + uint8_t description[128]; // 鍥轰欢鐨勬弿杩颁俊鎭,鏈澶128涓瓧绗 +} firmware_t; + + +/* OTA鍗囩骇杩囩▼涓殑淇℃伅缁撴瀯浣 */ +typedef struct { + firmware_t os; // XiUOS System鍒嗗尯灞炴т俊鎭 + firmware_t bak; // Bakup鍒嗗尯灞炴т俊鎭 + firmware_t down; // Download鍒嗗尯灞炴т俊鎭 + uint32_t status; // 鍗囩骇鐘舵,鍙栧兼潵鑷簬ota_status_t绫诲瀷 + uint32_t initversion; // 鎭㈠鍑哄巶璁剧疆鐨勬爣蹇,0xFFFFFFFF浠h〃鏈儳鍐欒繃,鐑у啓杩囦互鍚庤缃负0x12345678 + uint32_t jumpfailed; // bootloaer璺宠浆澶辫触鐨勬爣蹇,bootloader閲岀疆0xabababab,璺宠浆鎴愬姛鍚庣疆0x00000000 + uint32_t reserve; // 淇濈暀瀛楁 + uint8_t error_message[128]; // 閿欒淇℃伅,鏈澶128涓瓧绗 } ota_info_t; -void UpdateOTAStatus(ota_status_t status); -void UpdateOTAFlag(uint32_t app_size, uint32_t version, uint32_t status, uint8_t* description, uint8_t* error_message); +uint32_t calculate_crc32(uint32_t addr, uint32_t len); +status_t UpdateOTAFlag(ota_info_t *ptr); void UpdateApplication(void); #endif From 3d16b694dd23cb265ec06ad5e10828af0bc2fa2a Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Mon, 24 Apr 2023 10:24:56 +0800 Subject: [PATCH 10/15] Use the serial port iap method to burn the initial firmware under the bootloader --- .../XiZi_IIoT/board/xidatong-arm32/board.c | 4 +-- .../third_party_driver/common/imxrt_ota.c | 29 ++++++++++++--- .../third_party_driver/common/mcuboot.c | 36 ++++++++++++++++++- .../third_party_driver/include/imxrt_ota.h | 14 ++++---- 4 files changed, 67 insertions(+), 16 deletions(-) diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c index fe5b35a75..69f663516 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c @@ -385,10 +385,10 @@ static void OtaCmd(void) { ota_info.down.size = size; ota_info.down.crc32= calculate_crc32(DOWN_FLAH_ADDRESS, size); - ota_info.down.version = 0x11223344; + ota_info.down.version = ota_info.os.version + 1; strncpy(ota_info.down.description, "OTA Test!",sizeof(ota_info.down.description)); ota_info.status = OTA_STATUS_READY; - strncpy(ota_info.error_message, "Download the firmware to the download partition successfully!",sizeof(ota_info.error_message)); + strncpy(ota_info.error_message, "No error message!",sizeof(ota_info.error_message)); UpdateOTAFlag(&ota_info); } else diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c index db68e98ef..872b1e66c 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c @@ -149,8 +149,8 @@ void UpdateApplication(void) // 从Flash中读取OTA信息 memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - // 如果OTA升级状态为准备状态,可以进行升级 - if(ota_info.status == OTA_STATUS_READY) + // 如果OTA升级状态为准备状态,且APP分区与download分区版本不同,才可以进行升级 + if((ota_info.status == OTA_STATUS_READY) && (ota_info.os.crc32 != ota_info.down.crc32)) { Serial_PutString("\r\n------Start to update the app!------\r\n"); // 校验downlad分区固件CRC @@ -159,7 +159,27 @@ void UpdateApplication(void) ota_info.status = OTA_STATUS_UPDATING; UpdateOTAFlag(&ota_info); - // 拷贝download分区到XiUOS System分区 + // 1.如果CRC校验通过,开始升级,逐字节拷贝Flash,先备份当前XiUOS System分区内容 + status = flash_copy(XIUOS_FLAH_ADDRESS, BAKUP_FLAH_ADDRESS, ota_info.os.size); + if((status == kStatus_Success) &&(calculate_crc32(BAKUP_FLAH_ADDRESS, ota_info.os.size) == ota_info.os.crc32)) + { + Serial_PutString("\r\n------Backup app success!------\r\n"); + ota_info.bak.size = ota_info.os.size; + ota_info.bak.crc32 = ota_info.os.crc32; + ota_info.bak.version = ota_info.os.version; + strncpy(ota_info.bak.description, ota_info.os.description, sizeof(ota_info.os.description)); + UpdateOTAFlag(&ota_info); + } + else + { + Serial_PutString("\r\n------Backup app failed!------\r\n"); + ota_info.status = OTA_STATUS_ERROR; + strncpy(ota_info.error_message, "Backup app failed!",sizeof(ota_info.error_message)); + UpdateOTAFlag(&ota_info); + goto finish; + } + + // 2.拷贝download分区到XiUOS System分区 status = flash_copy(DOWN_FLAH_ADDRESS, XIUOS_FLAH_ADDRESS, ota_info.down.size); if((status == kStatus_Success) &&(calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.down.size) == ota_info.down.crc32)) { @@ -200,6 +220,5 @@ void UpdateApplication(void) goto finish; } finish: - // 跳转到应用程序 - jump_to_application(); + return; } 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 c1113d6a0..7af9c9231 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 @@ -21,6 +21,25 @@ #ifdef MCUBOOT_BOOTLOADER extern void ImxrtMsDelay(uint32 ms); + +static void InitialVersion(void) +{ + int32_t size; + ota_info_t ota_info; + + memset(&ota_info, 0, sizeof(ota_info_t)); + size = SerialDownload(XIUOS_FLAH_ADDRESS); + if(size > 0) + { + ota_info.os.size = size; + ota_info.os.crc32 = calculate_crc32(XIUOS_FLAH_ADDRESS, size); + ota_info.os.version = 0x1; + strncpy(ota_info.os.description, "This is the initial firmware for the device!", sizeof(ota_info.os.description)); + UpdateOTAFlag(&ota_info); + } +} + + void jump_to_application(void) { SCB->VTOR = (uint32_t)XIUOS_FLAH_ADDRESS; @@ -34,10 +53,12 @@ void jump_to_application(void) asm volatile("BX R0"); } + void BootLoaderJumpApp(void) { uint8_t ch1, ch2; uint32_t ret; + ota_info_t ota_info; uint32_t timeout = 500; BOARD_ConfigMPU(); @@ -71,11 +92,24 @@ void BootLoaderJumpApp(void) case 0x31: jump_to_application(); break; + case 0x32: FLASH_Init(); - UpdateApplication(); + memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + /* 姝ゆ椂APP鍒嗗尯杩樻病鏈夋湁鏁堢殑鍥轰欢,闇瑕佸湪bootloader涓嬮氳繃iap鐑у啓鍑哄巶鍥轰欢 */ + if((ota_info.os.size > APP_FLASH_SIZE) || (calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.os.size) != ota_info.os.crc32)) + { + Serial_PutString("\r\nNeed to flash initial firmware!\r\n"); + InitialVersion(); + } + else + { + UpdateApplication(); + } FLASH_DeInit(); + jump_to_application(); break; + case 0x33: __set_FAULTMASK(1); NVIC_SystemReset(); diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h index ddd4f41bf..099aca3f0 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h @@ -26,15 +26,14 @@ #include "flash.h" #include "ymodem.h" - /* OTA鍗囩骇杩囩▼涓殑鐘舵佹弿杩 */ typedef enum { - OTA_STATUS_IDLE = 0, // 绌洪棽鐘舵侊紝娌℃湁杩涜OTA鍗囩骇 - OTA_STATUS_READY, // 鍑嗗鐘舵侊紝鍙互杩涜OTA鍗囩骇 + OTA_STATUS_IDLE = 0, // 绌洪棽鐘舵,娌℃湁杩涜OTA鍗囩骇 + OTA_STATUS_READY, // 鍑嗗鐘舵,鍙互杩涜OTA鍗囩骇 OTA_STATUS_DOWNLOADING, // 姝e湪涓嬭浇鍥轰欢 - OTA_STATUS_DOWNLOADED, // 鍥轰欢涓嬭浇瀹屾垚锛屽彲浠ヨ繘琛屽崌绾 + OTA_STATUS_DOWNLOADED, // 鍥轰欢涓嬭浇瀹屾垚 OTA_STATUS_UPDATING, // 姝e湪杩涜OTA鍗囩骇 - OTA_STATUS_ERROR, // 鍑虹幇閿欒锛屽崌绾уけ璐 + OTA_STATUS_ERROR, // 鍑虹幇閿欒,鍗囩骇澶辫触 } ota_status_t; @@ -54,9 +53,8 @@ typedef struct { firmware_t bak; // Bakup鍒嗗尯灞炴т俊鎭 firmware_t down; // Download鍒嗗尯灞炴т俊鎭 uint32_t status; // 鍗囩骇鐘舵,鍙栧兼潵鑷簬ota_status_t绫诲瀷 - uint32_t initversion; // 鎭㈠鍑哄巶璁剧疆鐨勬爣蹇,0xFFFFFFFF浠h〃鏈儳鍐欒繃,鐑у啓杩囦互鍚庤缃负0x12345678 - uint32_t jumpfailed; // bootloaer璺宠浆澶辫触鐨勬爣蹇,bootloader閲岀疆0xabababab,璺宠浆鎴愬姛鍚庣疆0x00000000 - uint32_t reserve; // 淇濈暀瀛楁 + uint32_t lastjumpflag; // bootloaer璺宠浆澶辫触鐨勬爣蹇,bootloader閲岀疆0xABABABAB,璺宠浆鎴愬姛鍚庡湪搴旂敤閲岀疆0x00000000 + uint32_t reserve[2]; // 淇濈暀瀛楁 uint8_t error_message[128]; // 閿欒淇℃伅,鏈澶128涓瓧绗 } ota_info_t; From 0ecb29c887a00970c861fb90891bfa6dbb4f4433 Mon Sep 17 00:00:00 2001 From: huang <1085210385@qq.com> Date: Thu, 4 May 2023 10:16:09 +0800 Subject: [PATCH 11/15] Add version rollback function for OTA --- .../XiZi_IIoT/board/xidatong-arm32/board.c | 4 + .../third_party_driver/common/flash.c | 330 +++++++++--------- .../third_party_driver/common/imxrt_ota.c | 44 +-- .../third_party_driver/common/mcuboot.c | 51 +++ .../third_party_driver/include/imxrt_ota.h | 1 + 5 files changed, 243 insertions(+), 187 deletions(-) diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c index 69f663516..9cb1b3af1 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c @@ -459,6 +459,10 @@ void InitBoardHardware() #ifdef BSP_USING_OTA FLASH_Init(); //璺宠浆鎴愬姛灏嗗搴旇烦杞け璐ユ爣蹇楁竻闆 + ota_info_t ota_info; + memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + ota_info.lastjumpflag=0x00000000; + UpdateOTAFlag(&ota_info); FLASH_DeInit(); #endif } diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c index 93938e5ed..dfb8965fe 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c @@ -58,11 +58,11 @@ static const lookuptable_t FlashLookupTable={ /******************************************************************************* -* 函 数 名: Flexspi_Nor_Wait_Busy -* 功能描述: 等待FlexSPI NOR Flash忙碌状态结束 -* 形 参: instance:FlexSPI实例号 - baseAddr:开始读取的Flash地址(32bit) -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 鍑 鏁 鍚: Flexspi_Nor_Wait_Busy +* 鍔熻兘鎻忚堪: 绛夊緟FlexSPI NOR Flash蹇欑鐘舵佺粨鏉 +* 褰 鍙: instance:FlexSPI瀹炰緥鍙 + baseAddr:寮濮嬭鍙栫殑Flash鍦板潃(32bit) +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 *******************************************************************************/ static status_t Flexspi_Nor_Wait_Busy(uint32_t instance, uint32_t baseAddr) { @@ -101,11 +101,11 @@ static status_t Flexspi_Nor_Wait_Busy(uint32_t instance, uint32_t baseAddr) /******************************************************************************* -* 函 数 名: Flexspi_Nor_Write_Enable -* 功能描述: 使能 FlexSPI NOR Flash的写入操作 -* 形 参: instance:FlexSPI实例号 - baseAddr:开始读取的Flash地址(32bit) -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 鍑 鏁 鍚: Flexspi_Nor_Write_Enable +* 鍔熻兘鎻忚堪: 浣胯兘 FlexSPI NOR Flash鐨勫啓鍏ユ搷浣 +* 褰 鍙: instance:FlexSPI瀹炰緥鍙 + baseAddr:寮濮嬭鍙栫殑Flash鍦板潃(32bit) +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 *******************************************************************************/ static status_t Flexspi_Nor_Write_Enable(uint32_t instance, uint32_t baseAddr) { @@ -125,12 +125,12 @@ static status_t Flexspi_Nor_Write_Enable(uint32_t instance, uint32_t baseAddr) /******************************************************************************* -* 函 数 名: flexspi_clock_config -* 功能描述: 配置FlexSPI模块的时钟 -* 形 参: instance:FlexSPI实例号 - freq:表示所需的FlexSPI时钟频率 - sampleClkMode:指定FlexSPI时钟的采样时钟模式,可以选择SDR或DDR模式 -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 鍑 鏁 鍚: flexspi_clock_config +* 鍔熻兘鎻忚堪: 閰嶇疆FlexSPI妯″潡鐨勬椂閽 +* 褰 鍙: instance:FlexSPI瀹炰緥鍙 + freq:琛ㄧず鎵闇鐨凢lexSPI鏃堕挓棰戠巼 + sampleClkMode:鎸囧畾FlexSPI鏃堕挓鐨勯噰鏍锋椂閽熸ā寮,鍙互閫夋嫨SDR鎴朌DR妯″紡 +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 *******************************************************************************/ static void flexspi_clock_config(uint32_t instance, uint32_t freq, uint32_t sampleClkMode) { @@ -210,10 +210,10 @@ static void flexspi_clock_config(uint32_t instance, uint32_t freq, uint32_t samp /******************************************************************************* -* 函 数 名: flexspi_clock_gate_enable -* 功能描述: 开启FlexSPI模块的时钟门控 -* 形 参: 无 -* 返 回 值: 无 +* 鍑 鏁 鍚: flexspi_clock_gate_enable +* 鍔熻兘鎻忚堪: 寮鍚疐lexSPI妯″潡鐨勬椂閽熼棬鎺 +* 褰 鍙: 鏃 +* 杩 鍥 鍊: 鏃 *******************************************************************************/ static void flexspi_clock_gate_enable(void) { @@ -222,10 +222,10 @@ static void flexspi_clock_gate_enable(void) /******************************************************************************* -* 函 数 名: flexspi_clock_gate_disable -* 功能描述: 关闭FlexSPI模块的时钟门控 -* 形 参: 无 -* 返 回 值: 无 +* 鍑 鏁 鍚: flexspi_clock_gate_disable +* 鍔熻兘鎻忚堪: 鍏抽棴FlexSPI妯″潡鐨勬椂閽熼棬鎺 +* 褰 鍙: 鏃 +* 杩 鍥 鍊: 鏃 *******************************************************************************/ static void flexspi_clock_gate_disable(void) { @@ -234,12 +234,12 @@ static void flexspi_clock_gate_disable(void) /******************************************************************************* -* 函 数 名: flexspi_get_clock -* 功能描述: 获取FlexSPI时钟频率 -* 形 参: instance:FlexSPI实例号 - type:所需时钟类型 - freq:用于存储获取到的时钟频率类型 -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 鍑 鏁 鍚: flexspi_get_clock +* 鍔熻兘鎻忚堪: 鑾峰彇FlexSPI鏃堕挓棰戠巼 +* 褰 鍙: instance:FlexSPI瀹炰緥鍙 + type:鎵闇鏃堕挓绫诲瀷 + freq:鐢ㄤ簬瀛樺偍鑾峰彇鍒扮殑鏃堕挓棰戠巼绫诲瀷 +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 *******************************************************************************/ static status_t flexspi_get_clock(uint32_t instance, flexspi_clock_type_t type, uint32_t *freq) { @@ -291,13 +291,13 @@ static status_t flexspi_get_clock(uint32_t instance, flexspi_clock_type_t type, /******************************************************************************* -* 函 数 名: flexspi_get_ticks -* 功能描述: 计算FlexSPI时钟周期数 -* 形 参: ticks:用于存储计算结果的指针,即所需的时钟周期数; - intervalNs:所需的时间间隔,以纳秒(ns)为单位; - freq:FlexSPI时钟频率,单位为MHz; - unit:时钟周期单位,即计算结果中每个时钟周期代表的时间长度,以ns为单位 -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 鍑 鏁 鍚: flexspi_get_ticks +* 鍔熻兘鎻忚堪: 璁$畻FlexSPI鏃堕挓鍛ㄦ湡鏁 +* 褰 鍙: ticks:鐢ㄤ簬瀛樺偍璁$畻缁撴灉鐨勬寚閽堬紝鍗虫墍闇鐨勬椂閽熷懆鏈熸暟锛 + intervalNs:鎵闇鐨勬椂闂撮棿闅旓紝浠ョ撼绉掞紙ns锛変负鍗曚綅锛 + freq:FlexSPI鏃堕挓棰戠巼锛屽崟浣嶄负MHz锛 + unit:鏃堕挓鍛ㄦ湡鍗曚綅,鍗宠绠楃粨鏋滀腑姣忎釜鏃堕挓鍛ㄦ湡浠h〃鐨勬椂闂撮暱搴,浠s涓哄崟浣 +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 *******************************************************************************/ static status_t flexspi_get_ticks(uint32_t *ticks, uint32_t intervalNs, uint32_t freq, uint32_t unit) { @@ -330,11 +330,11 @@ static status_t flexspi_get_ticks(uint32_t *ticks, uint32_t intervalNs, uint32_t /******************************************************************************* -* 函 数 名: flexspi_configure_dll -* 功能描述: 用来配置FLEXSPI存储器的DLL(延迟锁存器) -* 形 参: instance:FLEXSPI实例号 - config:存储器配置信息,包括读取时钟源、数据有效时间等参数 -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 鍑 鏁 鍚: flexspi_configure_dll +* 鍔熻兘鎻忚堪: 鐢ㄦ潵閰嶇疆FLEXSPI瀛樺偍鍣ㄧ殑DLL(寤惰繜閿佸瓨鍣) +* 褰 鍙: instance:FLEXSPI瀹炰緥鍙 + config:瀛樺偍鍣ㄩ厤缃俊鎭紝鍖呮嫭璇诲彇鏃堕挓婧愩佹暟鎹湁鏁堟椂闂寸瓑鍙傛暟 +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 *******************************************************************************/ static status_t flexspi_configure_dll(uint32_t instance, flexspi_mem_config_t *config) { @@ -473,11 +473,11 @@ static status_t flexspi_configure_dll(uint32_t instance, flexspi_mem_config_t *c /******************************************************************************* -* 函 数 名: flexspi_config_mcr1 -* 功能描述: 配置FlexSPI模块的MCR1寄存器 -* 形 参: instance:FLEXSPI实例号 - onfig指向FlexSPI存储器配置结构体的指针 -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 鍑 鏁 鍚: flexspi_config_mcr1 +* 鍔熻兘鎻忚堪: 閰嶇疆FlexSPI妯″潡鐨凪CR1瀵勫瓨鍣 +* 褰 鍙: instance:FLEXSPI瀹炰緥鍙 + onfig鎸囧悜FlexSPI瀛樺偍鍣ㄩ厤缃粨鏋勪綋鐨勬寚閽 +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 *******************************************************************************/ static status_t flexspi_config_mcr1(uint32_t instance, flexspi_mem_config_t *config) { @@ -513,10 +513,10 @@ static status_t flexspi_config_mcr1(uint32_t instance, flexspi_mem_config_t *con /******************************************************************************* -* 函 数 名: FLASH_GetSectorSize -* 功能描述: 获取扇区大小 -* 形 参: 无 -* 返 回 值: 返回扇区大小,HYPER FLASH为64K字节,NOR FLASH为4K字节 +* 鍑 鏁 鍚: FLASH_GetSectorSize +* 鍔熻兘鎻忚堪: 鑾峰彇鎵囧尯澶у皬 +* 褰 鍙: 鏃 +* 杩 鍥 鍊: 杩斿洖鎵囧尯澶у皬,HYPER FLASH涓64K瀛楄妭,NOR FLASH涓4K瀛楄妭 *******************************************************************************/ uint32_t FLASH_GetSectorSize(void) { @@ -529,10 +529,10 @@ uint32_t FLASH_GetSectorSize(void) /******************************************************************************* -* 函 数 名: FLASH_GetProgramCmd -* 功能描述: 获取页大小 -* 形 参: 无 -* 返 回 值: 返回页大小,HYPER FLASH为512字节,NOR FLASH为256字节 +* 鍑 鏁 鍚: FLASH_GetProgramCmd +* 鍔熻兘鎻忚堪: 鑾峰彇椤靛ぇ灏 +* 褰 鍙: 鏃 +* 杩 鍥 鍊: 杩斿洖椤靛ぇ灏,HYPER FLASH涓512瀛楄妭,NOR FLASH涓256瀛楄妭 *******************************************************************************/ uint32_t FLASH_GetProgramCmd(void) { @@ -548,10 +548,10 @@ uint32_t FLASH_GetProgramCmd(void) /******************************************************************************* -* 函 数 名: FLASH_Init -* 功能描述: Flash接口初始化,需在进行Flash相关操作前进行调用 -* 形 参: 无 -* 返 回 值: 无 +* 鍑 鏁 鍚: FLASH_Init +* 鍔熻兘鎻忚堪: Flash鎺ュ彛鍒濆鍖,闇鍦ㄨ繘琛孎lash鐩稿叧鎿嶄綔鍓嶈繘琛岃皟鐢 +* 褰 鍙: 鏃 +* 杩 鍥 鍊: 鏃 *******************************************************************************/ void FLASH_Init(void) { @@ -567,10 +567,10 @@ void FLASH_Init(void) /******************************************************************************* -* 函 数 名: FLASH_DeInit -* 功能描述: Flash接口反初始化,需在完成Flash相关操作后进行调用 -* 形 参: 无 -* 返 回 值: 无 +* 鍑 鏁 鍚: FLASH_DeInit +* 鍔熻兘鎻忚堪: Flash鎺ュ彛鍙嶅垵濮嬪寲锛岄渶鍦ㄥ畬鎴怓lash鐩稿叧鎿嶄綔鍚庤繘琛岃皟鐢 +* 褰 鍙: 鏃 +* 杩 鍥 鍊: 鏃 *******************************************************************************/ void FLASH_DeInit(void) { @@ -583,11 +583,11 @@ void FLASH_DeInit(void) /******************************************************************************* -* 函 数 名: FLASH_EraseSector -* 功能描述: 擦除一个Flash扇区 -* 形 参: addr:擦除区域起始地址 -* 返 回 值: None -* 注 释: 擦除一个扇区的最少时间:30ms~200/400ms +* 鍑 鏁 鍚: FLASH_EraseSector +* 鍔熻兘鎻忚堪: 鎿﹂櫎涓涓狥lash鎵囧尯 +* 褰 鍙: addr:鎿﹂櫎鍖哄煙璧峰鍦板潃 +* 杩 鍥 鍊: None +* 娉 閲: 鎿﹂櫎涓涓墖鍖虹殑鏈灏戞椂闂:30ms~200/400ms *******************************************************************************/ uint8_t FLASH_EraseSector(uint32_t addr) { @@ -613,13 +613,13 @@ uint8_t FLASH_EraseSector(uint32_t addr) /******************************************************************************* -* 函 数 名: FLASH_WritePage -* 功能描述: 写Flash一个页 -* 形 参: addr:写入区域起始地址 - buf:数据存储区 - len:要写入的字节数(最大256) -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 -* 注 释: 在指定地址开始写入最大256字节的数据 +* 鍑 鏁 鍚: FLASH_WritePage +* 鍔熻兘鎻忚堪: 鍐橣lash涓涓〉 +* 褰 鍙: addr:鍐欏叆鍖哄煙璧峰鍦板潃 + buf:鏁版嵁瀛樺偍鍖 + len:瑕佸啓鍏ョ殑瀛楄妭鏁(鏈澶256) +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 +* 娉 閲: 鍦ㄦ寚瀹氬湴鍧寮濮嬪啓鍏ユ渶澶256瀛楄妭鐨勬暟鎹 *******************************************************************************/ uint8_t FLASH_WritePage(uint32_t addr, const uint32_t *buf, uint32_t len) { @@ -648,12 +648,12 @@ uint8_t FLASH_WritePage(uint32_t addr, const uint32_t *buf, uint32_t len) /******************************************************************************* -* 函 数 名: FLASH_Read -* 功能描述: 读Flash内容 -* 形 参: addr:读取区域起始地址 - buf:数据存储区 - len:要读取的字节数 -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 鍑 鏁 鍚: FLASH_Read +* 鍔熻兘鎻忚堪: 璇籉lash鍐呭 +* 褰 鍙: addr:璇诲彇鍖哄煙璧峰鍦板潃 + buf:鏁版嵁瀛樺偍鍖 + len:瑕佽鍙栫殑瀛楄妭鏁 +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 *******************************************************************************/ status_t FLASH_Read(uint32_t addr, uint32_t *buf, uint32_t len) { @@ -680,12 +680,12 @@ status_t FLASH_Read(uint32_t addr, uint32_t *buf, uint32_t len) /******************************************************************************* -* 函 数 名: flash_erase -* 功能描述: 擦除Flash指定长度的空间 -* 形 参: addr:擦除区域起始地址 - byte_cnt:要擦除的字节数,以4k字节为最小擦除单位 -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 -* 注 释: 不满4k字节的,也需要擦除掉4k字节 +* 鍑 鏁 鍚: flash_erase +* 鍔熻兘鎻忚堪: 鎿﹂櫎Flash鎸囧畾闀垮害鐨勭┖闂 +* 褰 鍙: addr:鎿﹂櫎鍖哄煙璧峰鍦板潃 + byte_cnt:瑕佹摝闄ょ殑瀛楄妭鏁,浠4k瀛楄妭涓烘渶灏忔摝闄ゅ崟浣 +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 +* 娉 閲: 涓嶆弧4k瀛楄妭鐨勶紝涔熼渶瑕佹摝闄ゆ帀4k瀛楄妭 *******************************************************************************/ status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt) { @@ -707,12 +707,12 @@ status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt) /******************************************************************************* -* 函 数 名: flash_write -* 功能描述: 在指定的flash起始地址写入指定长度的数据 -* 形 参: addr:写入区域起始地址 - buf:数据存储区 - byte_cnt:要写入的字节数 -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 鍑 鏁 鍚: flash_write +* 鍔熻兘鎻忚堪: 鍦ㄦ寚瀹氱殑flash璧峰鍦板潃鍐欏叆鎸囧畾闀垮害鐨勬暟鎹 +* 褰 鍙: addr:鍐欏叆鍖哄煙璧峰鍦板潃 + buf:鏁版嵁瀛樺偍鍖 + byte_cnt:瑕佸啓鍏ョ殑瀛楄妭鏁 +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 *******************************************************************************/ status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt) { @@ -736,12 +736,12 @@ status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt) /******************************************************************************* -* 函 数 名: flash_read -* 功能描述: 读Flash内容 -* 形 参: addr:读取区域起始地址 - buf:数据存储区 - len:要读取的字节数 -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 鍑 鏁 鍚: flash_read +* 鍔熻兘鎻忚堪: 璇籉lash鍐呭 +* 褰 鍙: addr:璇诲彇鍖哄煙璧峰鍦板潃 + buf:鏁版嵁瀛樺偍鍖 + len:瑕佽鍙栫殑瀛楄妭鏁 +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 *******************************************************************************/ status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len) { @@ -768,12 +768,12 @@ status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len) /******************************************************************************* -* 函 数 名: flash_copy -* 功能描述: 实现flash数据在分区之间的拷贝 -* 形 参: srcAddr:源flash的起始地址 - dstAddr:目标flash的起始地址; - imageSize:要拷贝的flash空间大小,单位为字节 -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 鍑 鏁 鍚: flash_copy +* 鍔熻兘鎻忚堪: 瀹炵幇flash鏁版嵁鍦ㄥ垎鍖轰箣闂寸殑鎷疯礉 +* 褰 鍙: srcAddr:婧恌lash鐨勮捣濮嬪湴鍧 + dstAddr:鐩爣flash鐨勮捣濮嬪湴鍧; + imageSize:瑕佹嫹璐濈殑flash绌洪棿澶у皬,鍗曚綅涓哄瓧鑺 +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 *******************************************************************************/ status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize) { @@ -834,11 +834,11 @@ status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize) /******************************************************************************* -* 函 数 名: NOR_FLASH_Erase -* 功能描述: 以扇区为擦除单位擦除Flash指定长度的空间,最终擦除的字节可能大于imageSize -* 形 参: addr:擦除区域起始地址 - imageSize:要擦除的字节数 -* 返 回 值: None +* 鍑 鏁 鍚: NOR_FLASH_Erase +* 鍔熻兘鎻忚堪: 浠ユ墖鍖轰负鎿﹂櫎鍗曚綅鎿﹂櫎Flash鎸囧畾闀垮害鐨勭┖闂,鏈缁堟摝闄ょ殑瀛楄妭鍙兘澶т簬imageSize +* 褰 鍙: addr:鎿﹂櫎鍖哄煙璧峰鍦板潃 + imageSize:瑕佹摝闄ょ殑瀛楄妭鏁 +* 杩 鍥 鍊: None *******************************************************************************/ status_t NOR_FLASH_Erase(uint32_t app_base_addr,uint32_t imageSize) { @@ -860,13 +860,13 @@ status_t NOR_FLASH_Erase(uint32_t app_base_addr,uint32_t imageSize) /******************************************************************************* -* 函 数 名: NorFlash_Write_PageProgram -* 功能描述: 写入Flash指定长度的数据 -* 形 参: pBuffer:数据存储区 - WriteAddr:写入区域起始地址 - NumByteToWrite:要写入的字节数(最大256) -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 -* 注 释: 在指定地址开始写入最大256字节的数据 +* 鍑 鏁 鍚: NorFlash_Write_PageProgram +* 鍔熻兘鎻忚堪: 鍐欏叆Flash鎸囧畾闀垮害鐨勬暟鎹 +* 褰 鍙: pBuffer:鏁版嵁瀛樺偍鍖 + WriteAddr:鍐欏叆鍖哄煙璧峰鍦板潃 + NumByteToWrite:瑕佸啓鍏ョ殑瀛楄妭鏁(鏈澶256) +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 +* 娉 閲: 鍦ㄦ寚瀹氬湴鍧寮濮嬪啓鍏ユ渶澶256瀛楄妭鐨勬暟鎹 *******************************************************************************/ void NorFlash_Write_PageProgram(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite) { @@ -883,24 +883,24 @@ void NorFlash_Write_PageProgram(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t Num /******************************************************************************* -* 函 数 名: NorFlash_Write_NoCheck -* 功能描述: 无检验写入W25QXX从指定地址开始指定长度的数据 -* 形 参: pBuffer:数据存储区 - WriteAddr:开始写入的地址(24bit) - NumByteToWrite:要写入的字节数(最大65535) -* 返 回 值: 无 -* 注 释: 必须确保所写的地址范围内的数据全部为0XFF,否则在非0XFF处写入的数据将失败! - 具有自动换页功能,在指定地址开始写入指定长度的数据,但是要确保地址不越界! +* 鍑 鏁 鍚: NorFlash_Write_NoCheck +* 鍔熻兘鎻忚堪: 鏃犳楠屽啓鍏25QXX浠庢寚瀹氬湴鍧寮濮嬫寚瀹氶暱搴︾殑鏁版嵁 +* 褰 鍙: pBuffer:鏁版嵁瀛樺偍鍖 + WriteAddr:寮濮嬪啓鍏ョ殑鍦板潃(24bit) + NumByteToWrite:瑕佸啓鍏ョ殑瀛楄妭鏁(鏈澶65535) +* 杩 鍥 鍊: 鏃 +* 娉 閲: 蹇呴』纭繚鎵鍐欑殑鍦板潃鑼冨洿鍐呯殑鏁版嵁鍏ㄩ儴涓0XFF,鍚﹀垯鍦ㄩ潪0XFF澶勫啓鍏ョ殑鏁版嵁灏嗗け璐! + 鍏锋湁鑷姩鎹㈤〉鍔熻兘,鍦ㄦ寚瀹氬湴鍧寮濮嬪啓鍏ユ寚瀹氶暱搴︾殑鏁版嵁,浣嗘槸瑕佺‘淇濆湴鍧涓嶈秺鐣! *******************************************************************************/ void NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite) { uint16_t pageRemain; - pageRemain = 256 - WriteAddr%256;//单页剩余的字节数 + pageRemain = 256 - WriteAddr%256;//鍗曢〉鍓╀綑鐨勫瓧鑺傛暟 if(NumByteToWrite <= pageRemain) { - pageRemain = NumByteToWrite;//不大于256个字节 + pageRemain = NumByteToWrite;//涓嶅ぇ浜256涓瓧鑺 } while(1) @@ -908,21 +908,21 @@ void NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByte NorFlash_Write_PageProgram(pBuffer,WriteAddr,pageRemain); if(NumByteToWrite == pageRemain) { - break;//写入结束了 + break;//鍐欏叆缁撴潫浜 } else //NumByteToWrite>pageRemain { pBuffer += pageRemain; WriteAddr += pageRemain; - NumByteToWrite -= pageRemain;//减去已经写入了的字节数 + NumByteToWrite -= pageRemain;//鍑忓幓宸茬粡鍐欏叆浜嗙殑瀛楄妭鏁 if(NumByteToWrite > 256) { - pageRemain = 256;//一次可以写入256个字节 + pageRemain = 256;//涓娆″彲浠ュ啓鍏256涓瓧鑺 } else { - pageRemain = NumByteToWrite;//不够256个字节了 + pageRemain = NumByteToWrite;//涓嶅256涓瓧鑺備簡 } } } @@ -930,13 +930,13 @@ void NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByte /******************************************************************************* -* 函 数 名: NorFlash_Write -* 功能描述: 写入W25QXX在指定地址开始写入指定长度的数据 -* 形 参: pBuffer:数据存储区 - WriteAddr:开始写入的地址(24bit) - NumByteToWrite:要写入的字节数(最大65535) -* 返 回 值: None -* 注 释: 该函数带擦除操作 +* 鍑 鏁 鍚: NorFlash_Write +* 鍔熻兘鎻忚堪: 鍐欏叆W25QXX鍦ㄦ寚瀹氬湴鍧寮濮嬪啓鍏ユ寚瀹氶暱搴︾殑鏁版嵁 +* 褰 鍙: pBuffer:鏁版嵁瀛樺偍鍖 + WriteAddr:寮濮嬪啓鍏ョ殑鍦板潃(24bit) + NumByteToWrite:瑕佸啓鍏ョ殑瀛楄妭鏁(鏈澶65535) +* 杩 鍥 鍊: None +* 娉 閲: 璇ュ嚱鏁板甫鎿﹂櫎鎿嶄綔 *******************************************************************************/ void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite) { @@ -946,61 +946,61 @@ void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite) uint16_t i; uint8_t *NorFlash_BUF = 0; - NorFlash_BUF = NorFlash_BUFFER;//RAM缓冲区4K + NorFlash_BUF = NorFlash_BUFFER;//RAM缂撳啿鍖4K WriteAddr &= 0x0FFFFFFF; - secPos = WriteAddr/SECTOR_SIZE;//扇区地址 - secOff = WriteAddr%SECTOR_SIZE;//在扇区内的偏移 - secRemain = SECTOR_SIZE - secOff;//扇区剩余空间大小 + secPos = WriteAddr/SECTOR_SIZE;//鎵囧尯鍦板潃 + secOff = WriteAddr%SECTOR_SIZE;//鍦ㄦ墖鍖哄唴鐨勫亸绉 + secRemain = SECTOR_SIZE - secOff;//鎵囧尯鍓╀綑绌洪棿澶у皬 if(NumByteToWrite <= secRemain) { - secRemain = NumByteToWrite;//不大于4096个字节 + secRemain = NumByteToWrite;//涓嶅ぇ浜4096涓瓧鑺 } while(1) { - FLASH_Read(FLASH_BASE + secPos*SECTOR_SIZE, (void *)NorFlash_BUF, SECTOR_SIZE);//读出整个扇区的内容 - for(i=0;i SECTOR_SIZE) { - secRemain = SECTOR_SIZE;//下一个扇区还是写不完 + secRemain = SECTOR_SIZE;//涓嬩竴涓墖鍖鸿繕鏄啓涓嶅畬 } else { - secRemain = NumByteToWrite;//下一个扇区可以写完了 + secRemain = NumByteToWrite;//涓嬩竴涓墖鍖哄彲浠ュ啓瀹屼簡 } } } @@ -1008,12 +1008,12 @@ void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite) /******************************************************************************* -* 函 数 名: NOR_FLASH_Write -* 功能描述: 写入W25QXX在指定地址开始写入指定长度的数据 -* 形 参: FlashAddress:用于存储当前写入Flash地址的指针,写入过程中会移动 - Data:要写入数据存储区 - DataLength:要写入的字节数 -* 返 回 值: 0 +* 鍑 鏁 鍚: NOR_FLASH_Write +* 鍔熻兘鎻忚堪: 鍐欏叆W25QXX鍦ㄦ寚瀹氬湴鍧寮濮嬪啓鍏ユ寚瀹氶暱搴︾殑鏁版嵁 +* 褰 鍙: FlashAddress:鐢ㄤ簬瀛樺偍褰撳墠鍐欏叆Flash鍦板潃鐨勬寚閽堬紝鍐欏叆杩囩▼涓細绉诲姩 + Data:瑕佸啓鍏ユ暟鎹瓨鍌ㄥ尯 + DataLength:瑕佸啓鍏ョ殑瀛楄妭鏁 +* 杩 鍥 鍊: 0 *******************************************************************************/ #ifndef USE_HIGHT_SPEED_TRANS uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength) diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c index 872b1e66c..618515719 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c @@ -94,11 +94,11 @@ static const uint32_t crc32tab[] = { /******************************************************************************* -* 函 数 名: calculate_crc32 -* 功能描述: 计算给定Flash内存地址范围中数据的CRC32校验和 -* 形 参: addr:表示Flash地址的起始位置 - len:表示需要计算CRC32的数据长度 -* 返 回 值: 计算得到的CRC32值 +* 鍑 鏁 鍚: calculate_crc32 +* 鍔熻兘鎻忚堪: 璁$畻缁欏畾Flash鍐呭瓨鍦板潃鑼冨洿涓暟鎹殑CRC32鏍¢獙鍜 +* 褰 鍙: addr:琛ㄧずFlash鍦板潃鐨勮捣濮嬩綅缃 + len:琛ㄧず闇瑕佽绠桟RC32鐨勬暟鎹暱搴 +* 杩 鍥 鍊: 璁$畻寰楀埌鐨凜RC32鍊 *******************************************************************************/ uint32_t calculate_crc32(uint32_t addr, uint32_t len) { @@ -115,10 +115,10 @@ uint32_t calculate_crc32(uint32_t addr, uint32_t len) /******************************************************************************* -* 函 数 名: UpdateOTAFlag -* 功能描述: 更新OTA Flag区域的信息,版本完成下载后在app里进行调用 -* 形 参: ptr:ota_info_t结构体指针,描述OTA升级相关信息 -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 鍑 鏁 鍚: UpdateOTAFlag +* 鍔熻兘鎻忚堪: 鏇存柊OTA Flag鍖哄煙鐨勪俊鎭紝鐗堟湰瀹屾垚涓嬭浇鍚庡湪app閲岃繘琛岃皟鐢 +* 褰 鍙: ptr:ota_info_t缁撴瀯浣撴寚閽,鎻忚堪OTA鍗囩骇鐩稿叧淇℃伅 +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 *******************************************************************************/ status_t UpdateOTAFlag(ota_info_t *ptr) { @@ -135,31 +135,31 @@ status_t UpdateOTAFlag(ota_info_t *ptr) } /******************************************************************************* -* 函 数 名: UpdateApplication -* 功能描述: 在bootloader里进行调用,根据Flash中Flag分区中的信息决定是否进行版本更新 -* 形 参: 无 -* 返 回 值: 无 -* 注 释: 该函数调用后无论结果如何都将跳转到app分区 +* 鍑 鏁 鍚: UpdateApplication +* 鍔熻兘鎻忚堪: 鍦╞ootloader閲岃繘琛岃皟鐢,鏍规嵁Flash涓璅lag鍒嗗尯涓殑淇℃伅鍐冲畾鏄惁杩涜鐗堟湰鏇存柊 +* 褰 鍙: 鏃 +* 杩 鍥 鍊: 鏃 +* 娉 閲: 璇ュ嚱鏁拌皟鐢ㄥ悗鏃犺缁撴灉濡備綍閮藉皢璺宠浆鍒癮pp鍒嗗尯 *******************************************************************************/ void UpdateApplication(void) { status_t status; - ota_info_t ota_info; // 定义OTA信息结构体 + ota_info_t ota_info; // 瀹氫箟OTA淇℃伅缁撴瀯浣 - // 从Flash中读取OTA信息 + // 浠嶧lash涓鍙朞TA淇℃伅 memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - // 如果OTA升级状态为准备状态,且APP分区与download分区版本不同,才可以进行升级 + // 濡傛灉OTA鍗囩骇鐘舵佷负鍑嗗鐘舵侊紝涓擜PP鍒嗗尯涓巇ownload鍒嗗尯鐗堟湰涓嶅悓,鎵嶅彲浠ヨ繘琛屽崌绾 if((ota_info.status == OTA_STATUS_READY) && (ota_info.os.crc32 != ota_info.down.crc32)) { Serial_PutString("\r\n------Start to update the app!------\r\n"); - // 校验downlad分区固件CRC + // 鏍¢獙downlad鍒嗗尯鍥轰欢CRC if(calculate_crc32(DOWN_FLAH_ADDRESS, ota_info.down.size) == ota_info.down.crc32) { ota_info.status = OTA_STATUS_UPDATING; UpdateOTAFlag(&ota_info); - // 1.如果CRC校验通过,开始升级,逐字节拷贝Flash,先备份当前XiUOS System分区内容 + // 1.濡傛灉CRC鏍¢獙閫氳繃,寮濮嬪崌绾,閫愬瓧鑺傛嫹璐滷lash,鍏堝浠藉綋鍓峏iUOS System鍒嗗尯鍐呭 status = flash_copy(XIUOS_FLAH_ADDRESS, BAKUP_FLAH_ADDRESS, ota_info.os.size); if((status == kStatus_Success) &&(calculate_crc32(BAKUP_FLAH_ADDRESS, ota_info.os.size) == ota_info.os.crc32)) { @@ -179,7 +179,7 @@ void UpdateApplication(void) goto finish; } - // 2.拷贝download分区到XiUOS System分区 + // 2.鎷疯礉download鍒嗗尯鍒癤iUOS System鍒嗗尯 status = flash_copy(DOWN_FLAH_ADDRESS, XIUOS_FLAH_ADDRESS, ota_info.down.size); if((status == kStatus_Success) &&(calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.down.size) == ota_info.down.crc32)) { @@ -189,7 +189,7 @@ void UpdateApplication(void) ota_info.os.crc32 = ota_info.down.crc32; ota_info.os.version = ota_info.down.version; strncpy(ota_info.os.description, ota_info.down.description, sizeof(ota_info.down.description)); - ota_info.status == OTA_STATUS_IDLE; // 拷贝download分区到XiUOS System分区成功,将OTA升级状态设置为IDLE + ota_info.status == OTA_STATUS_IDLE; // 鎷疯礉download鍒嗗尯鍒癤iUOS System鍒嗗尯鎴愬姛,灏哋TA鍗囩骇鐘舵佽缃负IDLE UpdateOTAFlag(&ota_info); } else @@ -206,7 +206,7 @@ void UpdateApplication(void) } else { - // 如果download分区CRC校验失败,升级失败 + // 濡傛灉download鍒嗗尯CRC鏍¢獙澶辫触锛屽崌绾уけ璐 Serial_PutString("\r\n------Download Firmware CRC check failed!------\r\n"); ota_info.status = OTA_STATUS_ERROR; strncpy(ota_info.error_message, "Download Firmware CRC check failed!",sizeof(ota_info.error_message)); 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 7af9c9231..add7cfb5f 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 @@ -39,9 +39,53 @@ static void InitialVersion(void) } } +static void BackupVersion(void) +{ + status_t status; + ota_info_t ota_info; + memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + + ota_info.status = OTA_STATUS_BACKUP; + UpdateOTAFlag(&ota_info); + status = flash_copy(BAKUP_FLAH_ADDRESS, XIUOS_FLAH_ADDRESS, ota_info.bak.size); + if((status == kStatus_Success) &&(calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.bak.size) == ota_info.bak.crc32)) + { + Serial_PutString("\r\n------Backup app version success!------\r\n"); + ota_info.os.size = ota_info.bak.size; + ota_info.os.crc32 = ota_info.bak.crc32; + ota_info.os.version = ota_info.bak.version; + ota_info.lastjumpflag=0xABABABAB; + strncpy(ota_info.os.description, ota_info.bak.description, sizeof(ota_info.bak.description)); + UpdateOTAFlag(&ota_info); + } + else + { + Serial_PutString("\r\n------Backup app version failed!------\r\n"); + ota_info.status = OTA_STATUS_ERROR; + strncpy(ota_info.error_message, "Backup app version failed!",sizeof(ota_info.error_message)); + UpdateOTAFlag(&ota_info); + } +} void jump_to_application(void) { + ota_info_t ota_info; + FLASH_Init(); + memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + if (ota_info.lastjumpflag!=0x00000000) + { + Serial_PutString("\r\n------Bootloader false, begin backup!------\r\n"); + BackupVersion(); + + } + else + { + ota_info.lastjumpflag=0xABABABAB; + UpdateOTAFlag(&ota_info); + } + + FLASH_DeInit(); + SCB->VTOR = (uint32_t)XIUOS_FLAH_ADDRESS; asm volatile("LDR R0, = 0x60100000"); @@ -77,19 +121,25 @@ void BootLoaderJumpApp(void) ImxrtMsDelay(10); } + + while(1) { + if((ret)&&(ch1 == 0x20)) { Serial_PutString("\r\nPlease slecet:"); + Serial_PutString("\r\n 1:run app"); Serial_PutString("\r\n 2:update app"); Serial_PutString("\r\n 3:reboot \r\n"); + ch2 = GetKey(); switch(ch2) { case 0x31: + jump_to_application(); break; @@ -106,6 +156,7 @@ void BootLoaderJumpApp(void) { UpdateApplication(); } + FLASH_DeInit(); jump_to_application(); break; diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h index 099aca3f0..30d4c8de5 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h @@ -33,6 +33,7 @@ typedef enum { OTA_STATUS_DOWNLOADING, // 姝e湪涓嬭浇鍥轰欢 OTA_STATUS_DOWNLOADED, // 鍥轰欢涓嬭浇瀹屾垚 OTA_STATUS_UPDATING, // 姝e湪杩涜OTA鍗囩骇 + OTA_STATUS_BACKUP, // 姝e湪鐗堟湰鍥為 OTA_STATUS_ERROR, // 鍑虹幇閿欒,鍗囩骇澶辫触 } ota_status_t; From 4b40ae19dc6406f1f7e6c6d06f5dc7ad26413059 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Fri, 5 May 2023 17:07:30 +0800 Subject: [PATCH 12/15] =?UTF-8?q?1=E3=80=81Adapt=20ota-related=20interface?= =?UTF-8?q?s=20to=20the=20XiZi=5FIIoT/tool/bootloader=20directory=202?= =?UTF-8?q?=E3=80=81Add=20flash=20config=20by=20menuconfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ubiquitous/XiZi_IIoT/Kconfig | 2 + .../XiZi_IIoT/arch/arm/cortex-m7/boot.S | 2 +- .../XiZi_IIoT/board/xidatong-arm32/Kconfig | 16 - .../XiZi_IIoT/board/xidatong-arm32/board.c | 58 +-- .../third_party_driver/common/Makefile | 4 +- .../third_party_driver/common/flash.c | 9 +- .../third_party_driver/common/imxrt_ota.c | 224 --------- .../third_party_driver/common/mcuboot.c | 173 ++----- .../third_party_driver/common/ymodem.c | 2 +- .../third_party_driver/include/flash.h | 10 +- .../third_party_driver/include/mcuboot.h | 6 +- Ubiquitous/XiZi_IIoT/path_kernel.mk | 5 + Ubiquitous/XiZi_IIoT/tool/Kconfig | 5 + Ubiquitous/XiZi_IIoT/tool/Makefile | 4 + Ubiquitous/XiZi_IIoT/tool/bootloader/Kconfig | 48 ++ Ubiquitous/XiZi_IIoT/tool/bootloader/Makefile | 4 + .../XiZi_IIoT/tool/bootloader/flash/Makefile | 3 + .../tool/bootloader/flash/flash_ops.c | 0 .../tool/bootloader/flash/flash_ops.h | 47 ++ .../XiZi_IIoT/tool/bootloader/ota/Makefile | 3 + .../XiZi_IIoT/tool/bootloader/ota/ota.c | 444 ++++++++++++++++++ .../imxrt_ota.h => tool/bootloader/ota/ota.h} | 47 +- 22 files changed, 631 insertions(+), 485 deletions(-) delete mode 100644 Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/imxrt_ota.c create mode 100644 Ubiquitous/XiZi_IIoT/tool/Kconfig create mode 100644 Ubiquitous/XiZi_IIoT/tool/bootloader/flash/flash_ops.c create mode 100644 Ubiquitous/XiZi_IIoT/tool/bootloader/flash/flash_ops.h create mode 100644 Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c rename Ubiquitous/XiZi_IIoT/{board/xidatong-arm32/third_party_driver/include/imxrt_ota.h => tool/bootloader/ota/ota.h} (62%) diff --git a/Ubiquitous/XiZi_IIoT/Kconfig b/Ubiquitous/XiZi_IIoT/Kconfig index 2272a4f79..c2ce0865d 100644 --- a/Ubiquitous/XiZi_IIoT/Kconfig +++ b/Ubiquitous/XiZi_IIoT/Kconfig @@ -5,4 +5,6 @@ source "$KERNEL_DIR/lib/Kconfig" source "$KERNEL_DIR/fs/Kconfig" +source "$KERNEL_DIR/tool/Kconfig" + source "$KERNEL_DIR/../../APP_Framework/Kconfig" diff --git a/Ubiquitous/XiZi_IIoT/arch/arm/cortex-m7/boot.S b/Ubiquitous/XiZi_IIoT/arch/arm/cortex-m7/boot.S index d379a2b6a..2eb699f9c 100644 --- a/Ubiquitous/XiZi_IIoT/arch/arm/cortex-m7/boot.S +++ b/Ubiquitous/XiZi_IIoT/arch/arm/cortex-m7/boot.S @@ -101,7 +101,7 @@ Reset_Handler: strlt r0, [r1], #4 blt .LoopCopy1 - ldr r0,=BootLoaderJumpApp + ldr r0,=ota_entry blx r0 #else /* APP */ cpsid i /* Mask interrupts */ diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/Kconfig b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/Kconfig index b84b61537..faa887906 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/Kconfig +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/Kconfig @@ -40,22 +40,6 @@ menu "xidatong-arm32 feature" int "stack size for interrupt" default 4096 - config BSP_USING_OTA - bool "xidatong arm32 support OTA function" - default n - if BSP_USING_OTA - choice - prompt "compile bootloader bin or application bin." - default MCUBOOT_BOOTLOADER - - config MCUBOOT_BOOTLOADER - bool "config as bootloader." - - config MCUBOOT_APPLICATION - bool "config as application." - endchoice - endif - menu "config board peripheral" config MOUNT_SDCARD bool diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c index 9cb1b3af1..007d67690 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c @@ -64,8 +64,8 @@ Modification: #include #endif -#ifdef BSP_USING_OTA -#include +#ifdef TOOL_USING_OTA +#include #endif #ifdef BSP_USING_SEMC @@ -365,49 +365,6 @@ struct InitSequenceDesc _board_init[] = { " NONE ",NONE }, }; - -#ifdef BSP_USING_OTA -static void OtaCmd(void) -{ - int32_t size; - ota_info_t ota_info; - - FLASH_Init(); - UartConfig(); - - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - ota_info.status = OTA_STATUS_DOWNLOADING; - UpdateOTAFlag(&ota_info); - size = SerialDownload(DOWN_FLAH_ADDRESS); - ota_info.status = OTA_STATUS_DOWNLOADED; - UpdateOTAFlag(&ota_info); - if(size > 0) - { - ota_info.down.size = size; - ota_info.down.crc32= calculate_crc32(DOWN_FLAH_ADDRESS, size); - ota_info.down.version = ota_info.os.version + 1; - strncpy(ota_info.down.description, "OTA Test!",sizeof(ota_info.down.description)); - ota_info.status = OTA_STATUS_READY; - strncpy(ota_info.error_message, "No error message!",sizeof(ota_info.error_message)); - UpdateOTAFlag(&ota_info); - } - else - { - ota_info.status = OTA_STATUS_ERROR; - strncpy(ota_info.error_message, "Failed to download firmware to download partition!",sizeof(ota_info.error_message)); - UpdateOTAFlag(&ota_info); - } - - FLASH_DeInit(); - - __set_FAULTMASK(1); - NVIC_SystemReset(); -} - -SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),ota, OtaCmd, ota function); - -#endif - /** * This function will initial imxrt1050 board. */ @@ -456,13 +413,8 @@ void InitBoardHardware() KPrintf("board init done.\n"); KPrintf("start kernel...\n"); -#ifdef BSP_USING_OTA - FLASH_Init(); - //璺宠浆鎴愬姛灏嗗搴旇烦杞け璐ユ爣蹇楁竻闆 - ota_info_t ota_info; - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - ota_info.lastjumpflag=0x00000000; - UpdateOTAFlag(&ota_info); - FLASH_DeInit(); +#ifdef MCUBOOT_APPLICATION + /* Clear the lastjumpflag after the jump is successful.*/ + app_clear_jumpflag(); #endif } diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile index 7c6193cfd..811164369 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile @@ -4,8 +4,8 @@ ifeq ($(CONFIG_BSP_USING_SDIO),y) SRC_FILES += fsl_usdhc.c endif -ifeq ($(CONFIG_BSP_USING_OTA),y) - SRC_FILES += fsl_romapi.c flash.c mcuboot.c common.c ymodem.c imxrt_ota.c +ifeq ($(CONFIG_TOOL_USING_OTA),y) + SRC_FILES += fsl_romapi.c flash.c mcuboot.c common.c ymodem.c endif include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c index dfb8965fe..b10baee6b 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c @@ -14,7 +14,6 @@ */ #include -#include #include "flash.h" #include "MIMXRT1052.h" @@ -960,7 +959,7 @@ void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite) } while(1) { - FLASH_Read(FLASH_BASE + secPos*SECTOR_SIZE, (void *)NorFlash_BUF, SECTOR_SIZE);//璇诲嚭鏁翠釜鎵囧尯鐨勫唴瀹 + FLASH_Read(CHIP_FLAH_BASE + secPos*SECTOR_SIZE, (void *)NorFlash_BUF, SECTOR_SIZE);//璇诲嚭鏁翠釜鎵囧尯鐨勫唴瀹 for(i=0;i -#include -#include -#include "flash.h" -#include "common.h" -#include "imxrt_ota.h" - - -static const uint32_t crc32tab[] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, - 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, - 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, - 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, - 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, - 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, - 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, - 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, - 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, - 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, - 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, - 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, - 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, - 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, - 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, - 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, - 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, - 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, - 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, - 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, - 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, - 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, - 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, - 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, - 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, - 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, - 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, - 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, - 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, - 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, - 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, - 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, - 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, - 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, - 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, - 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, - 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, - 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, - 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, - 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, - 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, - 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, - 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d -}; - - -/******************************************************************************* -* 鍑 鏁 鍚: calculate_crc32 -* 鍔熻兘鎻忚堪: 璁$畻缁欏畾Flash鍐呭瓨鍦板潃鑼冨洿涓暟鎹殑CRC32鏍¢獙鍜 -* 褰 鍙: addr:琛ㄧずFlash鍦板潃鐨勮捣濮嬩綅缃 - len:琛ㄧず闇瑕佽绠桟RC32鐨勬暟鎹暱搴 -* 杩 鍥 鍊: 璁$畻寰楀埌鐨凜RC32鍊 -*******************************************************************************/ -uint32_t calculate_crc32(uint32_t addr, uint32_t len) -{ - uint32_t crc = 0xFFFFFFFF; - uint8_t byte = 0xFF; - - for(uint32_t i = 0; i < len; i++) - { - byte = *((volatile uint8_t *)(addr + i)); - crc = crc32tab[(crc ^ byte) & 0xff] ^ (crc >> 8); - } - return crc^0xFFFFFFFF; -} - - -/******************************************************************************* -* 鍑 鏁 鍚: UpdateOTAFlag -* 鍔熻兘鎻忚堪: 鏇存柊OTA Flag鍖哄煙鐨勪俊鎭紝鐗堟湰瀹屾垚涓嬭浇鍚庡湪app閲岃繘琛岃皟鐢 -* 褰 鍙: ptr:ota_info_t缁撴瀯浣撴寚閽,鎻忚堪OTA鍗囩骇鐩稿叧淇℃伅 -* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 -*******************************************************************************/ -status_t UpdateOTAFlag(ota_info_t *ptr) -{ - status_t status; - - status = flash_erase(FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - if(status != kStatus_Success) - { - return status; - } - status = flash_write(FLAG_FLAH_ADDRESS,(void *)ptr,sizeof(ota_info_t)); - - return status; -} - -/******************************************************************************* -* 鍑 鏁 鍚: UpdateApplication -* 鍔熻兘鎻忚堪: 鍦╞ootloader閲岃繘琛岃皟鐢,鏍规嵁Flash涓璅lag鍒嗗尯涓殑淇℃伅鍐冲畾鏄惁杩涜鐗堟湰鏇存柊 -* 褰 鍙: 鏃 -* 杩 鍥 鍊: 鏃 -* 娉 閲: 璇ュ嚱鏁拌皟鐢ㄥ悗鏃犺缁撴灉濡備綍閮藉皢璺宠浆鍒癮pp鍒嗗尯 -*******************************************************************************/ -void UpdateApplication(void) -{ - status_t status; - ota_info_t ota_info; // 瀹氫箟OTA淇℃伅缁撴瀯浣 - - // 浠嶧lash涓鍙朞TA淇℃伅 - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - - // 濡傛灉OTA鍗囩骇鐘舵佷负鍑嗗鐘舵侊紝涓擜PP鍒嗗尯涓巇ownload鍒嗗尯鐗堟湰涓嶅悓,鎵嶅彲浠ヨ繘琛屽崌绾 - if((ota_info.status == OTA_STATUS_READY) && (ota_info.os.crc32 != ota_info.down.crc32)) - { - Serial_PutString("\r\n------Start to update the app!------\r\n"); - // 鏍¢獙downlad鍒嗗尯鍥轰欢CRC - if(calculate_crc32(DOWN_FLAH_ADDRESS, ota_info.down.size) == ota_info.down.crc32) - { - ota_info.status = OTA_STATUS_UPDATING; - UpdateOTAFlag(&ota_info); - - // 1.濡傛灉CRC鏍¢獙閫氳繃,寮濮嬪崌绾,閫愬瓧鑺傛嫹璐滷lash,鍏堝浠藉綋鍓峏iUOS System鍒嗗尯鍐呭 - status = flash_copy(XIUOS_FLAH_ADDRESS, BAKUP_FLAH_ADDRESS, ota_info.os.size); - if((status == kStatus_Success) &&(calculate_crc32(BAKUP_FLAH_ADDRESS, ota_info.os.size) == ota_info.os.crc32)) - { - Serial_PutString("\r\n------Backup app success!------\r\n"); - ota_info.bak.size = ota_info.os.size; - ota_info.bak.crc32 = ota_info.os.crc32; - ota_info.bak.version = ota_info.os.version; - strncpy(ota_info.bak.description, ota_info.os.description, sizeof(ota_info.os.description)); - UpdateOTAFlag(&ota_info); - } - else - { - Serial_PutString("\r\n------Backup app failed!------\r\n"); - ota_info.status = OTA_STATUS_ERROR; - strncpy(ota_info.error_message, "Backup app failed!",sizeof(ota_info.error_message)); - UpdateOTAFlag(&ota_info); - goto finish; - } - - // 2.鎷疯礉download鍒嗗尯鍒癤iUOS System鍒嗗尯 - status = flash_copy(DOWN_FLAH_ADDRESS, XIUOS_FLAH_ADDRESS, ota_info.down.size); - if((status == kStatus_Success) &&(calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.down.size) == ota_info.down.crc32)) - { - Serial_PutString("\r\n------The download partition is copied successfully!------\r\n"); - - ota_info.os.size = ota_info.down.size; - ota_info.os.crc32 = ota_info.down.crc32; - ota_info.os.version = ota_info.down.version; - strncpy(ota_info.os.description, ota_info.down.description, sizeof(ota_info.down.description)); - ota_info.status == OTA_STATUS_IDLE; // 鎷疯礉download鍒嗗尯鍒癤iUOS System鍒嗗尯鎴愬姛,灏哋TA鍗囩骇鐘舵佽缃负IDLE - UpdateOTAFlag(&ota_info); - } - else - { - Serial_PutString("\r\n------The download partition copy failed!------\r\n"); - ota_info.status = OTA_STATUS_ERROR; - strncpy(ota_info.error_message, "The download partition copy failed!",sizeof(ota_info.error_message)); - UpdateOTAFlag(&ota_info); - goto finish; - } - - Serial_PutString("\r\n------Update completed!------\r\n"); - goto finish; - } - else - { - // 濡傛灉download鍒嗗尯CRC鏍¢獙澶辫触锛屽崌绾уけ璐 - Serial_PutString("\r\n------Download Firmware CRC check failed!------\r\n"); - ota_info.status = OTA_STATUS_ERROR; - strncpy(ota_info.error_message, "Download Firmware CRC check failed!",sizeof(ota_info.error_message)); - UpdateOTAFlag(&ota_info); - goto finish; - } - } - else - { - Serial_PutString("\r\n------No need to update the app!------\r\n"); - goto finish; - } -finish: - return; -} 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 add7cfb5f..e3890c505 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 @@ -15,163 +15,46 @@ #include #include -#include "imxrt_ota.h" #include "common.h" +#include "mcuboot.h" +#include "flash.h" -#ifdef MCUBOOT_BOOTLOADER -extern void ImxrtMsDelay(uint32 ms); +#ifdef TOOL_USING_OTA - -static void InitialVersion(void) +void mcuboot_bord_init(void) { - int32_t size; - ota_info_t ota_info; - - memset(&ota_info, 0, sizeof(ota_info_t)); - size = SerialDownload(XIUOS_FLAH_ADDRESS); - if(size > 0) - { - ota_info.os.size = size; - ota_info.os.crc32 = calculate_crc32(XIUOS_FLAH_ADDRESS, size); - ota_info.os.version = 0x1; - strncpy(ota_info.os.description, "This is the initial firmware for the device!", sizeof(ota_info.os.description)); - UpdateOTAFlag(&ota_info); - } -} - -static void BackupVersion(void) -{ - status_t status; - ota_info_t ota_info; - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - - ota_info.status = OTA_STATUS_BACKUP; - UpdateOTAFlag(&ota_info); - status = flash_copy(BAKUP_FLAH_ADDRESS, XIUOS_FLAH_ADDRESS, ota_info.bak.size); - if((status == kStatus_Success) &&(calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.bak.size) == ota_info.bak.crc32)) - { - Serial_PutString("\r\n------Backup app version success!------\r\n"); - ota_info.os.size = ota_info.bak.size; - ota_info.os.crc32 = ota_info.bak.crc32; - ota_info.os.version = ota_info.bak.version; - ota_info.lastjumpflag=0xABABABAB; - strncpy(ota_info.os.description, ota_info.bak.description, sizeof(ota_info.bak.description)); - UpdateOTAFlag(&ota_info); - } - else - { - Serial_PutString("\r\n------Backup app version failed!------\r\n"); - ota_info.status = OTA_STATUS_ERROR; - strncpy(ota_info.error_message, "Backup app version failed!",sizeof(ota_info.error_message)); - UpdateOTAFlag(&ota_info); - } -} - -void jump_to_application(void) -{ - ota_info_t ota_info; - FLASH_Init(); - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - if (ota_info.lastjumpflag!=0x00000000) - { - Serial_PutString("\r\n------Bootloader false, begin backup!------\r\n"); - BackupVersion(); - - } - else - { - ota_info.lastjumpflag=0xABABABAB; - UpdateOTAFlag(&ota_info); - } - - FLASH_DeInit(); - - SCB->VTOR = (uint32_t)XIUOS_FLAH_ADDRESS; - - asm volatile("LDR R0, = 0x60100000"); - asm volatile("LDR R0, [R0]"); - asm volatile("MOV SP, R0"); - - asm volatile("LDR R0, = 0x60100000+4"); - asm volatile("LDR R0, [R0]"); - asm volatile("BX R0"); -} - - -void BootLoaderJumpApp(void) -{ - uint8_t ch1, ch2; - uint32_t ret; - ota_info_t ota_info; - uint32_t timeout = 500; - BOARD_ConfigMPU(); BOARD_InitPins(); BOARD_BootClockRUN(); UartConfig(); SysTick_Config(SystemCoreClock / TICK_PER_SECOND); +} - Serial_PutString("Please press 'space' key into menu in 5s !!!\r\n"); +void mcuboot_reset(void) +{ + __set_FAULTMASK(1); + NVIC_SystemReset(); +} + +void mcuboot_jump(void) +{ + uint32_t addr = XIUOS_FLAH_ADDRESS; + + SCB->VTOR = addr; + asm volatile("LDR R0, %0" : : "m"(addr)); + asm volatile("LDR R0, [R0]"); + asm volatile("MOV SP, R0"); - while(timeout) - { - ret = (SerialKeyPressed((uint8_t*)&ch1)); - if(ret) break; - timeout--; - ImxrtMsDelay(10); - } + addr += 4; + asm volatile("LDR R0, %0" : : "m"(addr)); + asm volatile("LDR R0, [R0]"); + asm volatile("BX R0"); +} - +extern void ImxrtMsDelay(uint32 ms); - while(1) - { - - if((ret)&&(ch1 == 0x20)) - { - Serial_PutString("\r\nPlease slecet:"); - - Serial_PutString("\r\n 1:run app"); - Serial_PutString("\r\n 2:update app"); - Serial_PutString("\r\n 3:reboot \r\n"); - - - ch2 = GetKey(); - switch(ch2) - { - case 0x31: - - jump_to_application(); - break; - - case 0x32: - FLASH_Init(); - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - /* 姝ゆ椂APP鍒嗗尯杩樻病鏈夋湁鏁堢殑鍥轰欢,闇瑕佸湪bootloader涓嬮氳繃iap鐑у啓鍑哄巶鍥轰欢 */ - if((ota_info.os.size > APP_FLASH_SIZE) || (calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.os.size) != ota_info.os.crc32)) - { - Serial_PutString("\r\nNeed to flash initial firmware!\r\n"); - InitialVersion(); - } - else - { - UpdateApplication(); - } - - FLASH_DeInit(); - jump_to_application(); - break; - - case 0x33: - __set_FAULTMASK(1); - NVIC_SystemReset(); - default: - break; - } - } - else - { - jump_to_application(); - } - } +void mcuboot_delay(uint32_t ms) +{ + ImxrtMsDelay(ms); } #endif \ No newline at end of file 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 8c8fcbbcf..661f6e81c 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 @@ -17,7 +17,7 @@ * @author: AIIT XUOS Lab * @date: 2023/3/24 */ - +#include #include "ymodem.h" #include "string.h" #include "flash.h" diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h index fd86d003d..fd59738cb 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash.h @@ -6,7 +6,7 @@ */ /** -* @file fsl_flash.h +* @file flash.h * @brief support flexspi norflash function * @version 2.0 * @author AIIT XUOS Lab @@ -16,25 +16,19 @@ #ifndef __FLASH_H__ #define __FLASH_H__ +#include #include #include "fsl_romapi.h" #define USE_HIGHT_SPEED_TRANS 1 -#define FLASH_BASE 0x60000000 #define SECTOR_SIZE 0x1000 #define FLASH_PAGE_SIZE 256 -#define APP_FLASH_SIZE 0x100000 //Application package size is limited to 1M #define FLEXSPI_WAIT_TIMEOUT_NS (500000000UL) //FlexSPI timeout value, 500ms #define FLEXSPI_FREQ_1GHz (1000000000UL) #define FREQ_1MHz (1000000UL) #define FLEXSPI_DLLCR_DEFAULT (0x100UL) -#define XIUOS_FLAH_ADDRESS 0x60100000 -#define BAKUP_FLAH_ADDRESS 0x60300000 -#define DOWN_FLAH_ADDRESS 0x60500000 -#define FLAG_FLAH_ADDRESS 0x60700000 - enum { kFlexSpiDelayCellUnit_Min = 75, // 75ps diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h index f3fa1806b..f63aa1a8b 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h @@ -22,8 +22,12 @@ #include "fsl_iomuxc.h" #include "fsl_gpio.h" #include "fsl_lpuart.h" +#include "common.h" -void jump_to_application(void); +void mcuboot_bord_init(void); +void mcuboot_reset(void); +void mcuboot_jump(void); +void mcuboot_delay(uint32_t ms); #endif diff --git a/Ubiquitous/XiZi_IIoT/path_kernel.mk b/Ubiquitous/XiZi_IIoT/path_kernel.mk index e7e3c5557..6736938db 100755 --- a/Ubiquitous/XiZi_IIoT/path_kernel.mk +++ b/Ubiquitous/XiZi_IIoT/path_kernel.mk @@ -555,6 +555,11 @@ KERNELPATHS +=-I$(KERNEL_ROOT)/tool/shell/letter-shell \ -I$(KERNEL_ROOT)/tool/shell/letter-shell/file_ext # endif +ifeq ($(CONFIG_TOOL_USING_OTA), y) +KERNELPATHS +=-I$(KERNEL_ROOT)/tool/bootloader/flash \ + -I$(KERNEL_ROOT)/tool/bootloader/ota # +endif + ifeq ($(CONFIG_FS_LWEXT4),y) KERNELPATHS += -I$(KERNEL_ROOT)/fs/lwext4/lwext4_submodule/blockdev/xiuos # KERNELPATHS += -I$(KERNEL_ROOT)/fs/lwext4/lwext4_submodule/include # diff --git a/Ubiquitous/XiZi_IIoT/tool/Kconfig b/Ubiquitous/XiZi_IIoT/tool/Kconfig new file mode 100644 index 000000000..1989064ce --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/tool/Kconfig @@ -0,0 +1,5 @@ +menu "Tool feature" + + source "$KERNEL_DIR/tool/bootloader/Kconfig" + +endmenu diff --git a/Ubiquitous/XiZi_IIoT/tool/Makefile b/Ubiquitous/XiZi_IIoT/tool/Makefile index 998131f71..cd148dd4f 100644 --- a/Ubiquitous/XiZi_IIoT/tool/Makefile +++ b/Ubiquitous/XiZi_IIoT/tool/Makefile @@ -4,4 +4,8 @@ ifeq ($(CONFIG_TOOL_SHELL),y) SRC_DIR += shell endif +ifeq ($(CONFIG_TOOL_USING_OTA),y) + SRC_DIR += bootloader +endif + include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/Kconfig b/Ubiquitous/XiZi_IIoT/tool/bootloader/Kconfig index e69de29bb..f5213d718 100644 --- a/Ubiquitous/XiZi_IIoT/tool/bootloader/Kconfig +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/Kconfig @@ -0,0 +1,48 @@ +menu "OTA function" + + menuconfig TOOL_USING_OTA + bool "Enable support OTA function" + default n + + if TOOL_USING_OTA + choice + prompt "Compile bootloader bin or application bin." + default MCUBOOT_BOOTLOADER + + config MCUBOOT_BOOTLOADER + bool "Config as bootloader." + + config MCUBOOT_APPLICATION + bool "Config as application." + endchoice + + + menu "Flash area address and size configuration." + config CHIP_FLAH_BASE + hex "Flash base address of the chip." + default 0x60000000 + + config XIUOS_FLAH_ADDRESS + hex "Flash area address of the XiUOS system." + default 0x60100000 + + config BAKUP_FLAH_ADDRESS + hex "Flash area address of the backup firmware." + default 0x60300000 + + config DOWN_FLAH_ADDRESS + hex "Flash area address of the downloaded firmware." + default 0x60500000 + + config FLAG_FLAH_ADDRESS + hex "Flash area address of the OTA information." + default 0x60700000 + + config APP_FLASH_SIZE + hex "Application package size,the default size is limited to 1M." + default 0x00100000 + endmenu + + endif + +endmenu diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/Makefile b/Ubiquitous/XiZi_IIoT/tool/bootloader/Makefile index e69de29bb..3e0f3289d 100644 --- a/Ubiquitous/XiZi_IIoT/tool/bootloader/Makefile +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/Makefile @@ -0,0 +1,4 @@ +SRC_DIR := +SRC_DIR += flash ota + +include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/flash/Makefile b/Ubiquitous/XiZi_IIoT/tool/bootloader/flash/Makefile index e69de29bb..123d7c8b0 100644 --- a/Ubiquitous/XiZi_IIoT/tool/bootloader/flash/Makefile +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/flash/Makefile @@ -0,0 +1,3 @@ +SRC_FILES := flash_ops.c + +include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/flash/flash_ops.c b/Ubiquitous/XiZi_IIoT/tool/bootloader/flash/flash_ops.c new file mode 100644 index 000000000..e69de29bb diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/flash/flash_ops.h b/Ubiquitous/XiZi_IIoT/tool/bootloader/flash/flash_ops.h new file mode 100644 index 000000000..b0ff530f0 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/flash/flash_ops.h @@ -0,0 +1,47 @@ +/* + * Copyright 2018-2020 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** +* @file flash_ops.h +* @brief support flash function +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-04-03 +*/ +#ifndef __FLASH_OPS_H__ +#define __FLASH_OPS_H__ + + +#include + +typedef struct +{ + /* board init function*/ + void (*board_init)(void); + void (*serial_init)(void); + void (*print_string)(uint8_t *s); + + /* flash Driver operation */ + void (*flash_init)(void); + void (*flash_deinit)(void); + + /* flash operation */ + status_t (*op_flash_erase)(uint32_t start_addr, uint32_t byte_cnt); + status_t (*op_flash_write)(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt); + status_t (*op_flash_read)(uint32_t addr, uint8_t *buf, uint32_t len); + status_t (*op_flash_copy)(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize); + + /* Burn the initialization version */ + int32_t (*download_by_serial)(const uint32_t addr); + + /* system operation */ + void(*op_reset)(void); + void(*op_jump)(void); + void(*op_delay)(uint32_t ms); +}mcuboot_t; + +#endif \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/Makefile b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/Makefile index e69de29bb..47afc2d36 100644 --- a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/Makefile +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/Makefile @@ -0,0 +1,3 @@ +SRC_FILES := ota.c + +include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c new file mode 100644 index 000000000..31898cdb5 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c @@ -0,0 +1,444 @@ +/* + * Copyright 2018-2020 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** +* @file ota.c +* @brief file ota.c +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-04-03 +*/ +#include "shell.h" +#include "xsconfig.h" +#include "mcuboot.h" +#include "ymodem.h" +#include "ota.h" + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ +static uint32_t calculate_crc32(uint32_t addr, uint32_t len); +static void UpdateApplication(void); +static void InitialVersion(void); +static void BackupVersion(void); +static void BootLoaderJumpApp(void); +static status_t UpdateOTAFlag(ota_info_t *ptr); + +#ifdef MCUBOOT_APPLICATION +static void app_ota(void); +#endif + + +/**************************************************************************** + * Private Data + ****************************************************************************/ +static const mcuboot_t mcuboot = +{ + mcuboot_bord_init, + UartConfig, + Serial_PutString, + FLASH_Init, + FLASH_DeInit, + flash_erase, + flash_write, + flash_read, + flash_copy, + SerialDownload, + mcuboot_reset, + mcuboot_jump, + mcuboot_delay +}; + +static const uint32_t crc32tab[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + + +/******************************************************************************* +* 鍑 鏁 鍚: calculate_crc32 +* 鍔熻兘鎻忚堪: 璁$畻缁欏畾Flash鍐呭瓨鍦板潃鑼冨洿涓暟鎹殑CRC32鏍¢獙鍜 +* 褰 鍙: addr:琛ㄧずFlash鍦板潃鐨勮捣濮嬩綅缃 + len:琛ㄧず闇瑕佽绠桟RC32鐨勬暟鎹暱搴 +* 杩 鍥 鍊: 璁$畻寰楀埌鐨凜RC32鍊 +*******************************************************************************/ +static uint32_t calculate_crc32(uint32_t addr, uint32_t len) +{ + uint32_t crc = 0xFFFFFFFF; + uint8_t byte = 0xFF; + + for(uint32_t i = 0; i < len; i++) + { + byte = *((volatile uint8_t *)(addr + i)); + crc = crc32tab[(crc ^ byte) & 0xff] ^ (crc >> 8); + } + return crc^0xFFFFFFFF; +} + + +/******************************************************************************* +* 鍑 鏁 鍚: UpdateApplication +* 鍔熻兘鎻忚堪: 鍦╞ootloader閲岃繘琛岃皟鐢,鏍规嵁Flash涓璅lag鍒嗗尯涓殑淇℃伅鍐冲畾鏄惁杩涜鐗堟湰鏇存柊 +* 褰 鍙: 鏃 +* 杩 鍥 鍊: 鏃 +* 娉 閲: 璇ュ嚱鏁拌皟鐢ㄥ悗鏃犺缁撴灉濡備綍閮藉皢璺宠浆鍒癮pp鍒嗗尯 +*******************************************************************************/ +static void UpdateApplication(void) +{ + status_t status; + ota_info_t ota_info; // 瀹氫箟OTA淇℃伅缁撴瀯浣 + + // 浠嶧lash涓鍙朞TA淇℃伅 + memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + + // 濡傛灉OTA鍗囩骇鐘舵佷负鍑嗗鐘舵侊紝涓擜PP鍒嗗尯涓巇ownload鍒嗗尯鐗堟湰涓嶅悓,鎵嶅彲浠ヨ繘琛屽崌绾 + if((ota_info.status == OTA_STATUS_READY) && (ota_info.os.crc32 != ota_info.down.crc32)) + { + mcuboot.print_string("\r\n------Start to update the app!------\r\n"); + // 鏍¢獙downlad鍒嗗尯鍥轰欢CRC + if(calculate_crc32(DOWN_FLAH_ADDRESS, ota_info.down.size) == ota_info.down.crc32) + { + ota_info.status = OTA_STATUS_UPDATING; + UpdateOTAFlag(&ota_info); + + // 1.濡傛灉CRC鏍¢獙閫氳繃,寮濮嬪崌绾,閫愬瓧鑺傛嫹璐滷lash,鍏堝浠藉綋鍓峏iUOS System鍒嗗尯鍐呭 + status = mcuboot.op_flash_copy(XIUOS_FLAH_ADDRESS, BAKUP_FLAH_ADDRESS, ota_info.os.size); + if((status == kStatus_Success) &&(calculate_crc32(BAKUP_FLAH_ADDRESS, ota_info.os.size) == ota_info.os.crc32)) + { + mcuboot.print_string("\r\n------Backup app success!------\r\n"); + ota_info.bak.size = ota_info.os.size; + ota_info.bak.crc32 = ota_info.os.crc32; + ota_info.bak.version = ota_info.os.version; + strncpy(ota_info.bak.description, ota_info.os.description, sizeof(ota_info.os.description)); + UpdateOTAFlag(&ota_info);; + } + else + { + mcuboot.print_string("\r\n------Backup app failed!------\r\n"); + ota_info.status = OTA_STATUS_ERROR; + strncpy(ota_info.error_message, "Backup app failed!",sizeof(ota_info.error_message)); + UpdateOTAFlag(&ota_info);; + goto finish; + } + + // 2.鎷疯礉download鍒嗗尯鍒癤iUOS System鍒嗗尯 + status = mcuboot.op_flash_copy(DOWN_FLAH_ADDRESS, XIUOS_FLAH_ADDRESS, ota_info.down.size); + if((status == kStatus_Success) &&(calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.down.size) == ota_info.down.crc32)) + { + mcuboot.print_string("\r\n------The download partition is copied successfully!------\r\n"); + + ota_info.os.size = ota_info.down.size; + ota_info.os.crc32 = ota_info.down.crc32; + ota_info.os.version = ota_info.down.version; + strncpy(ota_info.os.description, ota_info.down.description, sizeof(ota_info.down.description)); + ota_info.status == OTA_STATUS_IDLE; // 鎷疯礉download鍒嗗尯鍒癤iUOS System鍒嗗尯鎴愬姛,灏哋TA鍗囩骇鐘舵佽缃负IDLE + UpdateOTAFlag(&ota_info);; + } + else + { + mcuboot.print_string("\r\n------The download partition copy failed!------\r\n"); + ota_info.status = OTA_STATUS_ERROR; + strncpy(ota_info.error_message, "The download partition copy failed!",sizeof(ota_info.error_message)); + UpdateOTAFlag(&ota_info);; + goto finish; + } + + mcuboot.print_string("\r\n------Update completed!------\r\n"); + goto finish; + } + else + { + // 濡傛灉download鍒嗗尯CRC鏍¢獙澶辫触锛屽崌绾уけ璐 + mcuboot.print_string("\r\n------Download Firmware CRC check failed!------\r\n"); + ota_info.status = OTA_STATUS_ERROR; + strncpy(ota_info.error_message, "Download Firmware CRC check failed!",sizeof(ota_info.error_message)); + UpdateOTAFlag(&ota_info);; + goto finish; + } + } + else + { + mcuboot.print_string("\r\n------No need to update the app!------\r\n"); + goto finish; + } +finish: + return; +} + + +/******************************************************************************* +* 鍑 鏁 鍚: InitialVersion +* 鍔熻兘鎻忚堪: 璇ュ嚱鏁板彲浠ョ儳鍐橝PP鍒嗗尯鐨勫垵濮嬪寲鐗堟湰,鍒濆鍖栫増鏈殑鐗堟湰鍙蜂负0x1 +* 褰 鍙: 鏃 +* 杩 鍥 鍊: 鏃 +*******************************************************************************/ +static void InitialVersion(void) +{ + int32_t size; + ota_info_t ota_info; + + memset(&ota_info, 0, sizeof(ota_info_t)); + size = mcuboot.download_by_serial(XIUOS_FLAH_ADDRESS); + if(size > 0) + { + ota_info.os.size = size; + ota_info.os.crc32 = calculate_crc32(XIUOS_FLAH_ADDRESS, size); + ota_info.os.version = 0x1; + strncpy(ota_info.os.description, "This is the initial firmware for the device!", sizeof(ota_info.os.description)); + UpdateOTAFlag(&ota_info); + } +} + +/******************************************************************************* +* 鍑 鏁 鍚: BackupVersion +* 鍔熻兘鎻忚堪: 鐗堟湰鍥為鍑芥暟,濡傛灉鍗囩骇鐨凙PP瀛樺湪bug瀵艰嚧鏃犳硶璺宠浆闇璋冪敤姝ゅ嚱鏁拌繘琛岀増鏈洖閫 +* 褰 鍙: 鏃 +* 杩 鍥 鍊: 鏃 +*******************************************************************************/ +static void BackupVersion(void) +{ + status_t status; + ota_info_t ota_info; + memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + + ota_info.status = OTA_STATUS_BACKUP; + UpdateOTAFlag(&ota_info); + status = mcuboot.op_flash_copy(BAKUP_FLAH_ADDRESS, XIUOS_FLAH_ADDRESS, ota_info.bak.size); + if((status == kStatus_Success) &&(calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.bak.size) == ota_info.bak.crc32)) + { + mcuboot.print_string("\r\n------Backup app version success!------\r\n"); + ota_info.os.size = ota_info.bak.size; + ota_info.os.crc32 = ota_info.bak.crc32; + ota_info.os.version = ota_info.bak.version; + ota_info.lastjumpflag = 0xABABABAB; + strncpy(ota_info.os.description, ota_info.bak.description, sizeof(ota_info.bak.description)); + UpdateOTAFlag(&ota_info); + } + else + { + mcuboot.print_string("\r\n------Backup app version failed!------\r\n"); + ota_info.status = OTA_STATUS_ERROR; + strncpy(ota_info.error_message, "Backup app version failed!",sizeof(ota_info.error_message)); + UpdateOTAFlag(&ota_info); + } +} + + +/******************************************************************************* +* 鍑 鏁 鍚: BootLoaderJumpApp +* 鍔熻兘鎻忚堪: 涓婃璺宠浆鑻ユ槸澶辫触鐨,鍏堜粠BAKUP鍒嗗尯杩涜鎭㈠锛岀劧鍚庡啀杩涜璺宠浆 +* 褰 鍙: 鏃 +* 杩 鍥 鍊: 鏃 +*******************************************************************************/ +static void BootLoaderJumpApp(void) +{ + ota_info_t ota_info; + mcuboot.flash_init(); + memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + if (ota_info.lastjumpflag != 0x00000000) + { + mcuboot.print_string("\r\n------Bootloader false, begin backup!------\r\n"); + BackupVersion(); + + } + else + { + ota_info.lastjumpflag = 0xABABABAB; + UpdateOTAFlag(&ota_info); + } + + mcuboot.flash_deinit(); + mcuboot.op_jump(); +} + + +/******************************************************************************* +* 鍑 鏁 鍚: UpdateOTAFlag +* 鍔熻兘鎻忚堪: 鏇存柊OTA Flag鍖哄煙鐨勪俊鎭紝鐗堟湰瀹屾垚涓嬭浇鍚庡湪app閲岃繘琛岃皟鐢 +* 褰 鍙: ptr:ota_info_t缁撴瀯浣撴寚閽,鎻忚堪OTA鍗囩骇鐩稿叧淇℃伅 +* 杩 鍥 鍊: 濡傛灉鍑芥暟鎵ц鎴愬姛锛岀姸鎬佸间负 kStatus_Success锛屽惁鍒欑姸鎬佸间负鍏朵粬閿欒鐮 +*******************************************************************************/ +static status_t UpdateOTAFlag(ota_info_t *ptr) +{ + status_t status; + + status = mcuboot.op_flash_erase(FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + if(status != kStatus_Success) + { + return status; + } + status = mcuboot.op_flash_write(FLAG_FLAH_ADDRESS,(void *)ptr,sizeof(ota_info_t)); + + return status; +} + +#ifdef MCUBOOT_APPLICATION +/******************************************************************************* +* 鍑 鏁 鍚: app_ota +* 鍔熻兘鎻忚堪: 鍦╝pp涓氳繃鍛戒护鏉ヨ繘琛宱ta鍗囩骇,璇ュ嚱鏁颁笌鍗囩骇鐨勫懡浠ゅ叧鑱 +* 褰 鍙: 鏃 +* 杩 鍥 鍊: 鏃 +*******************************************************************************/ +static void app_ota(void) +{ + int32_t size; + ota_info_t ota_info; + + mcuboot.flash_init(); + mcuboot.serial_init(); + + memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + ota_info.status = OTA_STATUS_DOWNLOADING; + UpdateOTAFlag(&ota_info); + size = mcuboot.download_by_serial(DOWN_FLAH_ADDRESS); + ota_info.status = OTA_STATUS_DOWNLOADED; + UpdateOTAFlag(&ota_info); + if(size > 0) + { + ota_info.down.size = size; + ota_info.down.crc32= calculate_crc32(DOWN_FLAH_ADDRESS, size); + ota_info.down.version = ota_info.os.version + 1; + strncpy(ota_info.down.description, "OTA Test!",sizeof(ota_info.down.description)); + ota_info.status = OTA_STATUS_READY; + strncpy(ota_info.error_message, "No error message!",sizeof(ota_info.error_message)); + UpdateOTAFlag(&ota_info); + } + else + { + ota_info.status = OTA_STATUS_ERROR; + strncpy(ota_info.error_message, "Failed to download firmware to download partition!",sizeof(ota_info.error_message)); + UpdateOTAFlag(&ota_info); + } + mcuboot.flash_deinit(); + mcuboot.op_reset(); +} +SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),ota, app_ota, ota function); + +/******************************************************************************* +* 鍑 鏁 鍚: app_clear_jumpflag +* 鍔熻兘鎻忚堪: 璺宠浆app鎴愬姛鍚,鍦╝pp涓皟鐢ㄥ皢lastjumpflag閲嶇疆涓0x00000000 +* 褰 鍙: 鏃 +* 杩 鍥 鍊: 鏃 +*******************************************************************************/ +void app_clear_jumpflag(void) +{ + mcuboot.flash_init(); + //璺宠浆鎴愬姛灏嗗搴旇烦杞け璐ユ爣蹇楁竻闆 + ota_info_t ota_info; + memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + ota_info.lastjumpflag = 0x00000000; + UpdateOTAFlag(&ota_info); + mcuboot.flash_deinit(); +} + +#endif + + +/******************************************************************************* +* 鍑 鏁 鍚: ota_entry +* 鍔熻兘鎻忚堪: bootloader鐨勫叆鍙e嚱鏁 +* 褰 鍙: 鏃 +* 杩 鍥 鍊: 鏃 +*******************************************************************************/ +void ota_entry(void) +{ + uint8_t ch1, ch2; + uint32_t ret; + ota_info_t ota_info; + uint32_t timeout = 1000; + + mcuboot.board_init(); + + mcuboot.print_string("Please press 'space' key into menu in 10s !!!\r\n"); + + while(timeout) + { + ret = (SerialKeyPressed((uint8_t*)&ch1)); + if(ret) break; + timeout--; + mcuboot.op_delay(10); + } + + while(1) + { + + if((ret)&&(ch1 == 0x20)) + { + mcuboot.print_string("\r\nPlease slecet:"); + + mcuboot.print_string("\r\n 1:run app"); + mcuboot.print_string("\r\n 2:update app"); + mcuboot.print_string("\r\n 3:reboot \r\n"); + + + ch2 = GetKey(); + switch(ch2) + { + case 0x31: + BootLoaderJumpApp(); + break; + + case 0x32: + mcuboot.flash_init(); + memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + /* 姝ゆ椂APP鍒嗗尯杩樻病鏈夋湁鏁堢殑鍥轰欢,闇瑕佸湪bootloader涓嬮氳繃iap鐑у啓鍑哄巶鍥轰欢 */ + if((ota_info.os.size > APP_FLASH_SIZE) || (calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.os.size) != ota_info.os.crc32)) + { + mcuboot.print_string("\r\nNeed to flash initial firmware!\r\n"); + InitialVersion(); + } + else + { + UpdateApplication(); + } + + mcuboot.flash_deinit(); + BootLoaderJumpApp(); + break; + + case 0x33: + mcuboot.op_reset(); + default: + break; + } + } + else + { + BootLoaderJumpApp(); + } + } +} diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h similarity index 62% rename from Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h rename to Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h index 30d4c8de5..7662b1702 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/imxrt_ota.h +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h @@ -1,32 +1,22 @@ /* -* Copyright (c) 2020 AIIT XUOS Lab -* XiUOS is licensed under Mulan PSL v2. -* You can use this software according to the terms and conditions of the Mulan PSL v2. -* You may obtain a copy of Mulan PSL v2 at: -* http://license.coscl.org.cn/MulanPSL2 -* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, -* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, -* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. -* See the Mulan PSL v2 for more details. -*/ - + * Copyright 2018-2020 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + /** -* @file: imxrt_ota.h -* @brief: file imxrt_ota.h -* @version: 1.0 -* @author: AIIT XUOS Lab -* @date: 2023/3/24 +* @file ota.h +* @brief file ota.h +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-04-03 */ +#ifndef __OTA_DEF_H__ +#define __OTA_DEF_H__ -#ifndef __IMXRT_OTA__H__ -#define __IMXRT_OTA__H__ +#include "flash_ops.h" -#include -#include "mcuboot.h" -#include "flash.h" -#include "ymodem.h" - -/* OTA鍗囩骇杩囩▼涓殑鐘舵佹弿杩 */ typedef enum { OTA_STATUS_IDLE = 0, // 绌洪棽鐘舵,娌℃湁杩涜OTA鍗囩骇 OTA_STATUS_READY, // 鍑嗗鐘舵,鍙互杩涜OTA鍗囩骇 @@ -59,9 +49,8 @@ typedef struct { uint8_t error_message[128]; // 閿欒淇℃伅,鏈澶128涓瓧绗 } ota_info_t; - -uint32_t calculate_crc32(uint32_t addr, uint32_t len); -status_t UpdateOTAFlag(ota_info_t *ptr); -void UpdateApplication(void); - +#ifdef MCUBOOT_APPLICATION +void app_clear_jumpflag(void); +#endif +void ota_entry(void); #endif From 33abc16c67476c713b97adb1c9623cbe41912a6f Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Mon, 8 May 2023 13:59:41 +0800 Subject: [PATCH 13/15] revert "Add version rollback function for OTA" --- .../XiZi_IIoT/board/xidatong-arm32/board.c | 7 +++--- .../XiZi_IIoT/tool/bootloader/ota/ota.c | 24 +++++++++---------- .../XiZi_IIoT/tool/bootloader/ota/ota.h | 7 +++--- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c index 007d67690..4c2dc16a9 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c @@ -413,8 +413,9 @@ void InitBoardHardware() KPrintf("board init done.\n"); KPrintf("start kernel...\n"); -#ifdef MCUBOOT_APPLICATION - /* Clear the lastjumpflag after the jump is successful.*/ - app_clear_jumpflag(); +#ifdef TOOL_USING_OTA + FLASH_Init(); + //璺宠浆鎴愬姛灏嗗搴旇烦杞け璐ユ爣蹇楄缃 + FLASH_DeInit(); #endif } diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c index 31898cdb5..e4b5956ce 100644 --- a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c @@ -244,7 +244,6 @@ static void BackupVersion(void) ota_info.os.size = ota_info.bak.size; ota_info.os.crc32 = ota_info.bak.crc32; ota_info.os.version = ota_info.bak.version; - ota_info.lastjumpflag = 0xABABABAB; strncpy(ota_info.os.description, ota_info.bak.description, sizeof(ota_info.bak.description)); UpdateOTAFlag(&ota_info); } @@ -269,7 +268,8 @@ static void BootLoaderJumpApp(void) ota_info_t ota_info; mcuboot.flash_init(); memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - if (ota_info.lastjumpflag != 0x00000000) + + if(ota_info.lastjumpflag == JUMP_FAILED_FLAG) { mcuboot.print_string("\r\n------Bootloader false, begin backup!------\r\n"); BackupVersion(); @@ -277,10 +277,9 @@ static void BootLoaderJumpApp(void) } else { - ota_info.lastjumpflag = 0xABABABAB; + ota_info.lastjumpflag = JUMP_FAILED_FLAG; UpdateOTAFlag(&ota_info); } - mcuboot.flash_deinit(); mcuboot.op_jump(); } @@ -306,7 +305,7 @@ static status_t UpdateOTAFlag(ota_info_t *ptr) return status; } -#ifdef MCUBOOT_APPLICATION + /******************************************************************************* * 鍑 鏁 鍚: app_ota * 鍔熻兘鎻忚堪: 鍦╝pp涓氳繃鍛戒护鏉ヨ繘琛宱ta鍗囩骇,璇ュ嚱鏁颁笌鍗囩骇鐨勫懡浠ゅ叧鑱 @@ -348,25 +347,24 @@ static void app_ota(void) } SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),ota, app_ota, ota function); + /******************************************************************************* * 鍑 鏁 鍚: app_clear_jumpflag -* 鍔熻兘鎻忚堪: 璺宠浆app鎴愬姛鍚,鍦╝pp涓皟鐢ㄥ皢lastjumpflag閲嶇疆涓0x00000000 +* 鍔熻兘鎻忚堪: 璺宠浆app鎴愬姛鍚,鍦╝pp涓皟鐢ㄥ皢lastjumpflag閲嶇疆涓0XCDCDCDCD * 褰 鍙: 鏃 * 杩 鍥 鍊: 鏃 *******************************************************************************/ void app_clear_jumpflag(void) { mcuboot.flash_init(); - //璺宠浆鎴愬姛灏嗗搴旇烦杞け璐ユ爣蹇楁竻闆 + //璺宠浆鎴愬姛璁剧疆lastjumpflag涓篔UMP_SUCCESS_FLAG ota_info_t ota_info; memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - ota_info.lastjumpflag = 0x00000000; + ota_info.lastjumpflag = JUMP_SUCCESS_FLAG; UpdateOTAFlag(&ota_info); mcuboot.flash_deinit(); } -#endif - /******************************************************************************* * 鍑 鏁 鍚: ota_entry @@ -409,7 +407,7 @@ void ota_entry(void) switch(ch2) { case 0x31: - BootLoaderJumpApp(); + mcuboot.op_jump(); break; case 0x32: @@ -427,7 +425,7 @@ void ota_entry(void) } mcuboot.flash_deinit(); - BootLoaderJumpApp(); + mcuboot.op_jump(); break; case 0x33: @@ -438,7 +436,7 @@ void ota_entry(void) } else { - BootLoaderJumpApp(); + mcuboot.op_jump(); } } } diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h index 7662b1702..1eab71bdb 100644 --- a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h @@ -17,6 +17,9 @@ #include "flash_ops.h" +#define JUMP_FAILED_FLAG 0XABABABAB +#define JUMP_SUCCESS_FLAG 0XCDCDCDCD + typedef enum { OTA_STATUS_IDLE = 0, // 绌洪棽鐘舵,娌℃湁杩涜OTA鍗囩骇 OTA_STATUS_READY, // 鍑嗗鐘舵,鍙互杩涜OTA鍗囩骇 @@ -44,13 +47,11 @@ typedef struct { firmware_t bak; // Bakup鍒嗗尯灞炴т俊鎭 firmware_t down; // Download鍒嗗尯灞炴т俊鎭 uint32_t status; // 鍗囩骇鐘舵,鍙栧兼潵鑷簬ota_status_t绫诲瀷 - uint32_t lastjumpflag; // bootloaer璺宠浆澶辫触鐨勬爣蹇,bootloader閲岀疆0xABABABAB,璺宠浆鎴愬姛鍚庡湪搴旂敤閲岀疆0x00000000 + uint32_t lastjumpflag; // bootloaer璺宠浆澶辫触鐨勬爣蹇,bootloader閲岀疆0xABABABAB,璺宠浆鎴愬姛鍚庡湪搴旂敤閲岀疆0xCDCDCDCD uint32_t reserve[2]; // 淇濈暀瀛楁 uint8_t error_message[128]; // 閿欒淇℃伅,鏈澶128涓瓧绗 } ota_info_t; -#ifdef MCUBOOT_APPLICATION void app_clear_jumpflag(void); -#endif void ota_entry(void); #endif From 078f4babf10a3e600729a526896d2df743f643ce Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Mon, 8 May 2023 14:48:38 +0800 Subject: [PATCH 14/15] mover version rollback function for OTA to tool dir --- .../XiZi_IIoT/board/xidatong-arm32/board.c | 5 ++--- .../XiZi_IIoT/tool/bootloader/ota/ota.c | 21 +++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c index 4c2dc16a9..614c8264c 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c @@ -414,8 +414,7 @@ void InitBoardHardware() KPrintf("start kernel...\n"); #ifdef TOOL_USING_OTA - FLASH_Init(); - //璺宠浆鎴愬姛灏嗗搴旇烦杞け璐ユ爣蹇楄缃 - FLASH_DeInit(); + //璺宠浆鎴愬姛璁剧疆lastjumpflag涓篔UMP_SUCCESS_FLAG + app_clear_jumpflag(); #endif } diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c index e4b5956ce..4e0416e19 100644 --- a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c @@ -123,7 +123,7 @@ static void UpdateApplication(void) ota_info_t ota_info; // 瀹氫箟OTA淇℃伅缁撴瀯浣 // 浠嶧lash涓鍙朞TA淇℃伅 - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); // 濡傛灉OTA鍗囩骇鐘舵佷负鍑嗗鐘舵侊紝涓擜PP鍒嗗尯涓巇ownload鍒嗗尯鐗堟湰涓嶅悓,鎵嶅彲浠ヨ繘琛屽崌绾 if((ota_info.status == OTA_STATUS_READY) && (ota_info.os.crc32 != ota_info.down.crc32)) @@ -233,7 +233,7 @@ static void BackupVersion(void) { status_t status; ota_info_t ota_info; - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); ota_info.status = OTA_STATUS_BACKUP; UpdateOTAFlag(&ota_info); @@ -267,13 +267,12 @@ static void BootLoaderJumpApp(void) { ota_info_t ota_info; mcuboot.flash_init(); - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); if(ota_info.lastjumpflag == JUMP_FAILED_FLAG) { mcuboot.print_string("\r\n------Bootloader false, begin backup!------\r\n"); - BackupVersion(); - + BackupVersion(); } else { @@ -320,7 +319,7 @@ static void app_ota(void) mcuboot.flash_init(); mcuboot.serial_init(); - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); ota_info.status = OTA_STATUS_DOWNLOADING; UpdateOTAFlag(&ota_info); size = mcuboot.download_by_serial(DOWN_FLAH_ADDRESS); @@ -359,7 +358,7 @@ void app_clear_jumpflag(void) mcuboot.flash_init(); //璺宠浆鎴愬姛璁剧疆lastjumpflag涓篔UMP_SUCCESS_FLAG ota_info_t ota_info; - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); ota_info.lastjumpflag = JUMP_SUCCESS_FLAG; UpdateOTAFlag(&ota_info); mcuboot.flash_deinit(); @@ -407,12 +406,12 @@ void ota_entry(void) switch(ch2) { case 0x31: - mcuboot.op_jump(); + BootLoaderJumpApp(); break; case 0x32: mcuboot.flash_init(); - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); /* 姝ゆ椂APP鍒嗗尯杩樻病鏈夋湁鏁堢殑鍥轰欢,闇瑕佸湪bootloader涓嬮氳繃iap鐑у啓鍑哄巶鍥轰欢 */ if((ota_info.os.size > APP_FLASH_SIZE) || (calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.os.size) != ota_info.os.crc32)) { @@ -425,7 +424,7 @@ void ota_entry(void) } mcuboot.flash_deinit(); - mcuboot.op_jump(); + BootLoaderJumpApp(); break; case 0x33: @@ -436,7 +435,7 @@ void ota_entry(void) } else { - mcuboot.op_jump(); + BootLoaderJumpApp(); } } } From 2532ae43d4c9036af49255e8abc43e2025804525 Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Mon, 8 May 2023 13:59:41 +0800 Subject: [PATCH 15/15] move version rollback function for OTA to tool dir --- .../XiZi_IIoT/board/xidatong-arm32/board.c | 4 +-- .../XiZi_IIoT/tool/bootloader/ota/ota.c | 33 +++++++++---------- .../XiZi_IIoT/tool/bootloader/ota/ota.h | 7 ++-- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c index 007d67690..614c8264c 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/board.c @@ -413,8 +413,8 @@ void InitBoardHardware() KPrintf("board init done.\n"); KPrintf("start kernel...\n"); -#ifdef MCUBOOT_APPLICATION - /* Clear the lastjumpflag after the jump is successful.*/ +#ifdef TOOL_USING_OTA + //璺宠浆鎴愬姛璁剧疆lastjumpflag涓篔UMP_SUCCESS_FLAG app_clear_jumpflag(); #endif } diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c index 31898cdb5..4e0416e19 100644 --- a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c @@ -123,7 +123,7 @@ static void UpdateApplication(void) ota_info_t ota_info; // 瀹氫箟OTA淇℃伅缁撴瀯浣 // 浠嶧lash涓鍙朞TA淇℃伅 - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); // 濡傛灉OTA鍗囩骇鐘舵佷负鍑嗗鐘舵侊紝涓擜PP鍒嗗尯涓巇ownload鍒嗗尯鐗堟湰涓嶅悓,鎵嶅彲浠ヨ繘琛屽崌绾 if((ota_info.status == OTA_STATUS_READY) && (ota_info.os.crc32 != ota_info.down.crc32)) @@ -233,7 +233,7 @@ static void BackupVersion(void) { status_t status; ota_info_t ota_info; - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); ota_info.status = OTA_STATUS_BACKUP; UpdateOTAFlag(&ota_info); @@ -244,7 +244,6 @@ static void BackupVersion(void) ota_info.os.size = ota_info.bak.size; ota_info.os.crc32 = ota_info.bak.crc32; ota_info.os.version = ota_info.bak.version; - ota_info.lastjumpflag = 0xABABABAB; strncpy(ota_info.os.description, ota_info.bak.description, sizeof(ota_info.bak.description)); UpdateOTAFlag(&ota_info); } @@ -268,19 +267,18 @@ static void BootLoaderJumpApp(void) { ota_info_t ota_info; mcuboot.flash_init(); - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - if (ota_info.lastjumpflag != 0x00000000) + mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); + + if(ota_info.lastjumpflag == JUMP_FAILED_FLAG) { mcuboot.print_string("\r\n------Bootloader false, begin backup!------\r\n"); - BackupVersion(); - + BackupVersion(); } else { - ota_info.lastjumpflag = 0xABABABAB; + ota_info.lastjumpflag = JUMP_FAILED_FLAG; UpdateOTAFlag(&ota_info); } - mcuboot.flash_deinit(); mcuboot.op_jump(); } @@ -306,7 +304,7 @@ static status_t UpdateOTAFlag(ota_info_t *ptr) return status; } -#ifdef MCUBOOT_APPLICATION + /******************************************************************************* * 鍑 鏁 鍚: app_ota * 鍔熻兘鎻忚堪: 鍦╝pp涓氳繃鍛戒护鏉ヨ繘琛宱ta鍗囩骇,璇ュ嚱鏁颁笌鍗囩骇鐨勫懡浠ゅ叧鑱 @@ -321,7 +319,7 @@ static void app_ota(void) mcuboot.flash_init(); mcuboot.serial_init(); - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); ota_info.status = OTA_STATUS_DOWNLOADING; UpdateOTAFlag(&ota_info); size = mcuboot.download_by_serial(DOWN_FLAH_ADDRESS); @@ -348,25 +346,24 @@ static void app_ota(void) } SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),ota, app_ota, ota function); + /******************************************************************************* * 鍑 鏁 鍚: app_clear_jumpflag -* 鍔熻兘鎻忚堪: 璺宠浆app鎴愬姛鍚,鍦╝pp涓皟鐢ㄥ皢lastjumpflag閲嶇疆涓0x00000000 +* 鍔熻兘鎻忚堪: 璺宠浆app鎴愬姛鍚,鍦╝pp涓皟鐢ㄥ皢lastjumpflag閲嶇疆涓0XCDCDCDCD * 褰 鍙: 鏃 * 杩 鍥 鍊: 鏃 *******************************************************************************/ void app_clear_jumpflag(void) { mcuboot.flash_init(); - //璺宠浆鎴愬姛灏嗗搴旇烦杞け璐ユ爣蹇楁竻闆 + //璺宠浆鎴愬姛璁剧疆lastjumpflag涓篔UMP_SUCCESS_FLAG ota_info_t ota_info; - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); - ota_info.lastjumpflag = 0x00000000; + mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); + ota_info.lastjumpflag = JUMP_SUCCESS_FLAG; UpdateOTAFlag(&ota_info); mcuboot.flash_deinit(); } -#endif - /******************************************************************************* * 鍑 鏁 鍚: ota_entry @@ -414,7 +411,7 @@ void ota_entry(void) case 0x32: mcuboot.flash_init(); - memcpy(&ota_info, (const void *)FLAG_FLAH_ADDRESS,sizeof(ota_info_t)); + mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)&ota_info, sizeof(ota_info_t)); /* 姝ゆ椂APP鍒嗗尯杩樻病鏈夋湁鏁堢殑鍥轰欢,闇瑕佸湪bootloader涓嬮氳繃iap鐑у啓鍑哄巶鍥轰欢 */ if((ota_info.os.size > APP_FLASH_SIZE) || (calculate_crc32(XIUOS_FLAH_ADDRESS, ota_info.os.size) != ota_info.os.crc32)) { diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h index 7662b1702..1eab71bdb 100644 --- a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.h @@ -17,6 +17,9 @@ #include "flash_ops.h" +#define JUMP_FAILED_FLAG 0XABABABAB +#define JUMP_SUCCESS_FLAG 0XCDCDCDCD + typedef enum { OTA_STATUS_IDLE = 0, // 绌洪棽鐘舵,娌℃湁杩涜OTA鍗囩骇 OTA_STATUS_READY, // 鍑嗗鐘舵,鍙互杩涜OTA鍗囩骇 @@ -44,13 +47,11 @@ typedef struct { firmware_t bak; // Bakup鍒嗗尯灞炴т俊鎭 firmware_t down; // Download鍒嗗尯灞炴т俊鎭 uint32_t status; // 鍗囩骇鐘舵,鍙栧兼潵鑷簬ota_status_t绫诲瀷 - uint32_t lastjumpflag; // bootloaer璺宠浆澶辫触鐨勬爣蹇,bootloader閲岀疆0xABABABAB,璺宠浆鎴愬姛鍚庡湪搴旂敤閲岀疆0x00000000 + uint32_t lastjumpflag; // bootloaer璺宠浆澶辫触鐨勬爣蹇,bootloader閲岀疆0xABABABAB,璺宠浆鎴愬姛鍚庡湪搴旂敤閲岀疆0xCDCDCDCD uint32_t reserve[2]; // 淇濈暀瀛楁 uint8_t error_message[128]; // 閿欒淇℃伅,鏈澶128涓瓧绗 } ota_info_t; -#ifdef MCUBOOT_APPLICATION void app_clear_jumpflag(void); -#endif void ota_entry(void); #endif