From c8ca531b2d68e822ff08820aae5ffcb1e9ff95c7 Mon Sep 17 00:00:00 2001 From: zhangjin1996 <1561494530@qq.com> Date: Fri, 28 Mar 2025 18:04:55 +0800 Subject: [PATCH] info stack systick --- .../arch/arm/cortex-m7/stm32h750/boot.S | 191 ++++-------------- Ubiquitous/XiZi_IIoT/board/stm32h750/board.c | 4 +- Ubiquitous/XiZi_IIoT/board/stm32h750/board.h | 7 +- Ubiquitous/XiZi_IIoT/board/stm32h750/link.lds | 24 +-- .../stm32h750/third_party_driver/Makefile | 2 +- .../stm32h750/third_party_driver/sys/sys.c | 7 +- .../third_party_driver/usart/connect_uart.c | 38 ++-- 7 files changed, 74 insertions(+), 199 deletions(-) diff --git a/Ubiquitous/XiZi_IIoT/arch/arm/cortex-m7/stm32h750/boot.S b/Ubiquitous/XiZi_IIoT/arch/arm/cortex-m7/stm32h750/boot.S index 2eb699f9c..4a58570bf 100644 --- a/Ubiquitous/XiZi_IIoT/arch/arm/cortex-m7/stm32h750/boot.S +++ b/Ubiquitous/XiZi_IIoT/arch/arm/cortex-m7/stm32h750/boot.S @@ -41,164 +41,47 @@ Modification: .text .thumb -/* Reset Handler */ +.word _sidata +.word __data_start__ +.word __data_end__ +.word __bss_start__ +.word __bss_end__ - .thumb_func - .align 2 - .globl Reset_Handler - .weak Reset_Handler - .type Reset_Handler, %function + .section .text.Reset_Handler + .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 sp, =__StackTop + movs r1, #0 - ldr r0,=SystemInit - blx r0 +/* Copy the data segment initializers from flash to SRAM */ +DataInit: + ldr r0, =__data_start__ + ldr r3, =__data_end__ + adds r2, r0, r1 + cmp r2, r3 + bcs DataInitEnd + ldr r3, =_sidata + ldr r3, [r3, r1] + str r3, [r0, r1] + adds r1, r1, #4 + b DataInit -/* 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. */ +DataInitEnd: + ldr r2, =__bss_start__ - ldr r1, =__etext - ldr r2, =__data_start__ - ldr r3, =__data_end__ +/* Zero fill the bss segment. */ +BSSInit: + ldr r3, = __bss_end__ + cmp r2, r3 + bcs BSSInitEnd + movs r3, #0 + str r3, [r2], #4 + b BSSInit - /* 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 +BSSInitEnd: + bl SystemInit - /* 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,=ota_entry - blx r0 -#else /* APP */ - cpsid i /* Mask interrupts */ - .equ VTOR, 0xE000ED08 - ldr r0, =VTOR - ldr r1, =__isr_vector - str r1, [r0] - ldr r2, [r1] - msr msp, r2 -#ifndef __NO_SYSTEM_INIT - ldr r0,=SystemInit - blx r0 -#endif -/* 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. - * __etext: 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__ - -#if 1 -/* 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 */ -.LC0: - cmp r2, r3 - ittt lt - ldrlt r0, [r1], #4 - strlt r0, [r2], #4 - blt .LC0 -#else - subs r3, r2 - ble .LC1 -.LC0: - subs r3, #4 - ldr r0, [r1, r3] - str r0, [r2, r3] - bgt .LC0 -.LC1: -#endif -#ifdef __STARTUP_INITIALIZE_NONCACHEDATA - ldr r2, =__noncachedata_start__ - ldr r3, =__noncachedata_init_end__ -#if 1 -.LC2: - cmp r2, r3 - ittt lt - ldrlt r0, [r1], #4 - strlt r0, [r2], #4 - blt .LC2 -#else - subs r3, r2 - ble .LC3 -.LC2: - subs r3, #4 - ldr r0, [r1, r3] - str r0, [r2, r3] - bgt .LC2 -.LC3: -#endif -/* zero inited ncache section initialization */ - ldr r3, =__noncachedata_end__ - movs r0,0 -.LC4: - cmp r2,r3 - itt lt - strlt r0,[r2],#4 - blt .LC4 -#endif /* __STARTUP_INITIALIZE_NONCACHEDATA */ - -#if 1 -/* 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 -.LC5: - cmp r1, r2 - itt lt - strlt r0, [r1], #4 - blt .LC5 -#endif /* __STARTUP_CLEAR_BSS */ - - ldr r0,=entry - blx r0 -#endif /* MCUBOOT_BOOTLOADER */ - -.size Reset_Handler, . - Reset_Handler \ No newline at end of file + bl entry + bx lr +.size Reset_Handler, .-Reset_Handler \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/stm32h750/board.c b/Ubiquitous/XiZi_IIoT/board/stm32h750/board.c index 9658dc173..152f5cb4e 100644 --- a/Ubiquitous/XiZi_IIoT/board/stm32h750/board.c +++ b/Ubiquitous/XiZi_IIoT/board/stm32h750/board.c @@ -33,11 +33,11 @@ void InitBoardHardware() { - + sys_cache_enable(); HAL_Init(); sys_stm32_clock_init(192, 5, 2, 4); - delay_init(480); + //delay_init(480); InitHwUart(); InitBoardMemory((void*)HEAP_START, (void*)HEAP_END); diff --git a/Ubiquitous/XiZi_IIoT/board/stm32h750/board.h b/Ubiquitous/XiZi_IIoT/board/stm32h750/board.h index 1934d9b4c..a5fd919c7 100644 --- a/Ubiquitous/XiZi_IIoT/board/stm32h750/board.h +++ b/Ubiquitous/XiZi_IIoT/board/stm32h750/board.h @@ -24,11 +24,10 @@ void InitBoardHardware(); -extern void *__bss_end__; -extern void *_heap_end; -#define HEAP_START ((void *)&__bss_end__) -#define HEAP_END ((void *)&_heap_end) + +#define HEAP_START 0x24030000 +#define HEAP_END 0x24060000 diff --git a/Ubiquitous/XiZi_IIoT/board/stm32h750/link.lds b/Ubiquitous/XiZi_IIoT/board/stm32h750/link.lds index dee49baa0..3737b7330 100644 --- a/Ubiquitous/XiZi_IIoT/board/stm32h750/link.lds +++ b/Ubiquitous/XiZi_IIoT/board/stm32h750/link.lds @@ -11,7 +11,7 @@ MEMORY OUTPUT_ARCH(arm) ENTRY(Reset_Handler) -_system_stack_size = 0x200; +_system_stack_size = 0x10000; SECTIONS { @@ -42,9 +42,6 @@ SECTIONS __isrtbl_end = .; . = ALIGN(4); - PROVIDE(g_service_table_start = ABSOLUTE(.)); - KEEP(*(.g_service_table)) - PROVIDE(g_service_table_end = ABSOLUTE(.)); PROVIDE(_etext = ABSOLUTE(.)); @@ -78,11 +75,12 @@ SECTIONS __data_end__ = . ; } >sram - __bss_start__ = .; + .bss : { . = ALIGN(4); /* This is used by the startup in order to initialize the .bss secion */ + __bss_start__ = .; _sbss = .; *(.bss) @@ -92,16 +90,16 @@ SECTIONS . = ALIGN(4); /* This is used by the startup in order to initialize the .bss secion */ _ebss = . ; + __bss_end__ = .; + } > sram + .stack : + { + . = ALIGN(8); + /* cpu stack */ + . = . + _system_stack_size; + __StackTop = .; } > sram - __bss_end__ = .; _end = .; - .stack ORIGIN(sram) + LENGTH(sram) - _system_stack_size : - { - PROVIDE( _heap_end = . ); - . = _system_stack_size; - PROVIDE( __StackTop = . ); - } >sram - } diff --git a/Ubiquitous/XiZi_IIoT/board/stm32h750/third_party_driver/Makefile b/Ubiquitous/XiZi_IIoT/board/stm32h750/third_party_driver/Makefile index 60e98d59c..12af8c0e9 100644 --- a/Ubiquitous/XiZi_IIoT/board/stm32h750/third_party_driver/Makefile +++ b/Ubiquitous/XiZi_IIoT/board/stm32h750/third_party_driver/Makefile @@ -1,7 +1,7 @@ SRC_DIR := libraries ifeq ($(CONFIG_BSP_USING_UART),y) - SRC_DIR += usart sys delay + SRC_DIR += usart sys endif include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/board/stm32h750/third_party_driver/sys/sys.c b/Ubiquitous/XiZi_IIoT/board/stm32h750/third_party_driver/sys/sys.c index db835f6bc..079fce83a 100755 --- a/Ubiquitous/XiZi_IIoT/board/stm32h750/third_party_driver/sys/sys.c +++ b/Ubiquitous/XiZi_IIoT/board/stm32h750/third_party_driver/sys/sys.c @@ -31,7 +31,12 @@ RCC_PeriphCLKInitTypeDef rcc_periph_clk_init_struct = {0}; - +void sys_cache_enable(void) +{ + SCB_EnableICache(); /* ʹÄÜI-Cache */ + SCB_EnableDCache(); /* ʹÄÜD-Cache */ + SCB->CACR |= SCB_CACR_FORCEWT_Msk; /* ʹÄÜD-CacheÇ¿ÖÆÍ¸Ð´ */ +} /** diff --git a/Ubiquitous/XiZi_IIoT/board/stm32h750/third_party_driver/usart/connect_uart.c b/Ubiquitous/XiZi_IIoT/board/stm32h750/third_party_driver/usart/connect_uart.c index 2e757f4c6..996f6c20c 100644 --- a/Ubiquitous/XiZi_IIoT/board/stm32h750/third_party_driver/usart/connect_uart.c +++ b/Ubiquitous/XiZi_IIoT/board/stm32h750/third_party_driver/usart/connect_uart.c @@ -22,6 +22,7 @@ #include #include #include +#include static struct SerialBus serial_bus_1; static struct SerialDriver serial_driver_1; static struct SerialHardwareDevice serial_device_1; @@ -75,31 +76,19 @@ static void UartHandler(struct SerialBus *serial_bus, struct SerialDriver *seria { SerialSetIsr(serial_dev, SERIAL_EVENT_RX_IND); } - else - { - if (__HAL_UART_GET_FLAG(&(serial_hw_cfg->uart_handle), UART_FLAG_ORE) != RESET) - { - __HAL_UART_CLEAR_OREFLAG(&serial_hw_cfg->uart_handle); - } - if (__HAL_UART_GET_FLAG(&(serial_hw_cfg->uart_handle), UART_FLAG_NE) != RESET) - { - __HAL_UART_CLEAR_NEFLAG(&serial_hw_cfg->uart_handle); - } - if (__HAL_UART_GET_FLAG(&(serial_hw_cfg->uart_handle), UART_FLAG_FE) != RESET) - { - __HAL_UART_CLEAR_FEFLAG(&serial_hw_cfg->uart_handle); - } - if (__HAL_UART_GET_FLAG(&(serial_hw_cfg->uart_handle), UART_FLAG_PE) != RESET) - { - __HAL_UART_CLEAR_PEFLAG(&serial_hw_cfg->uart_handle); - } - } + HAL_UART_IRQHandler(&(serial_hw_cfg->uart_handle)); } void UartIsr1(int vector, void *param) { /* get serial bus 1 */ - UartHandler(&serial_bus_1, &serial_driver_1); + x_base lock = 0; + lock = DISABLE_INTERRUPT(); + + UartHandler(&serial_bus_1, &serial_driver_1); + + ENABLE_INTERRUPT(lock); + } DECLARE_HW_IRQ(USART1_IRQn, UartIsr1, NONE); @@ -240,11 +229,12 @@ static int SerialPutChar(struct SerialHardwareDevice *serial_dev, char c) { struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_dev->private_data; struct Stm32UartHwCfg *serial_hw_cfg = (struct Stm32UartHwCfg *)serial_cfg->hw_cfg.private_data; + /* Polling mode. */ + HAL_UART_Transmit(&(serial_hw_cfg->uart_handle), (uint8_t *)&c, 1, 100); + // UART_INSTANCE_CLEAR_FUNCTION(&(serial_hw_cfg->uart_handle), UART_FLAG_TC); - UART_INSTANCE_CLEAR_FUNCTION(&(serial_hw_cfg->uart_handle), UART_FLAG_TC); - - serial_hw_cfg->uart_handle.Instance->RDR = c; - while (__HAL_UART_GET_FLAG(&(serial_hw_cfg->uart_handle), UART_FLAG_TC) == RESET); + // serial_hw_cfg->uart_handle.Instance->TDR = c; + // while (__HAL_UART_GET_FLAG(&(serial_hw_cfg->uart_handle), UART_FLAG_TC) == RESET); return EOK; }