From 01f3b5e0838388f1c3e3bc82cf67f6c00d19b168 Mon Sep 17 00:00:00 2001 From: IOsetting Date: Thu, 12 Jan 2023 00:50:57 +0800 Subject: [PATCH] feat: ld file for 002 --- Libraries/BSP/Inc/py32f0xx_bsp_printf.h | 39 ++++- Libraries/LDScripts/py32f002x5.ld | 155 ++++++++++++++++++ .../Inc/py32f0xx_hal_dma.h | 3 +- .../Src/py32f0xx_hal_dma.c | 3 + Makefile | 2 +- 5 files changed, 197 insertions(+), 5 deletions(-) create mode 100644 Libraries/LDScripts/py32f002x5.ld diff --git a/Libraries/BSP/Inc/py32f0xx_bsp_printf.h b/Libraries/BSP/Inc/py32f0xx_bsp_printf.h index d9c2a3a..8e32499 100644 --- a/Libraries/BSP/Inc/py32f0xx_bsp_printf.h +++ b/Libraries/BSP/Inc/py32f0xx_bsp_printf.h @@ -24,6 +24,8 @@ extern "C" { //debug printf redirect config #define DEBUG_USART_BAUDRATE 115200 +#if (defined(PY32F003PRE)|| defined(PY32F030PRE) || defined(PY32F072PRE)) + #define DEBUG_USART USART2 #define DEBUG_USART_CLK_ENABLE() do { \ __IO uint32_t tmpreg = 0x00U; \ @@ -53,10 +55,41 @@ extern "C" { #define DEBUG_USART_IRQHandler USART2_IRQHandler #define DEBUG_USART_IRQ USART2_IRQn -#endif -/************************************************************/ -#ifdef HAL_UART_MODULE_ENABLED +#else + +#define DEBUG_USART USART1 +#define DEBUG_USART_CLK_ENABLE() do { \ + __IO uint32_t tmpreg = 0x00U; \ + SET_BIT(RCC->APBENR2, RCC_APBENR2_USART1EN);\ + /* Delay after an RCC peripheral clock enabling */ \ + tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_USART1EN);\ + UNUSED(tmpreg); \ + } while(0U) + +#define __GPIOA_CLK_ENABLE() do { \ + __IO uint32_t tmpreg = 0x00U; \ + SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\ + /* Delay after an RCC peripheral clock enabling */ \ + tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\ + UNUSED(tmpreg); \ + } while(0U) + +#define DEBUG_USART_RX_GPIO_PORT GPIOA +#define DEBUG_USART_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() +#define DEBUG_USART_RX_PIN GPIO_PIN_3 +#define DEBUG_USART_RX_AF GPIO_AF1_USART1 + +#define DEBUG_USART_TX_GPIO_PORT GPIOA +#define DEBUG_USART_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() +#define DEBUG_USART_TX_PIN GPIO_PIN_2 +#define DEBUG_USART_TX_AF GPIO_AF1_USART1 + +#define DEBUG_USART_IRQHandler USART1_IRQHandler +#define DEBUG_USART_IRQ USART1_IRQn + +#endif + extern UART_HandleTypeDef DebugUartHandle; #endif diff --git a/Libraries/LDScripts/py32f002x5.ld b/Libraries/LDScripts/py32f002x5.ld new file mode 100644 index 0000000..96e4fbd --- /dev/null +++ b/Libraries/LDScripts/py32f002x5.ld @@ -0,0 +1,155 @@ +/* +****************************************************************************** +** +** File : LinkerScript.ld +** +** Abstract : Linker script for PY32F003x6 series +** Set heap size, stack size and stack location according +** to application requirements. +** Set memory bank area and size if external memory is used. +** +** Distribution: The file is distributed “as is,” without any warranty +** of any kind. +** +***************************************************************************** +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of RAM */ +/* + Generate a link error if heap and stack don't fit into RAM. + These numbers affect the USED size of RAM +*/ +_Min_Heap_Size = 0x100; /* required amount of heap: 256 bytes */ +_Min_Stack_Size = 0x200; /* required amount of stack: 512 bytes */ + +/* Specify the memory areas */ +MEMORY +{ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 3K + FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 20K +} + +/* Define output sections */ +SECTIONS +{ + /* The startup code goes first into FLASH */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data goes into FLASH */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data goes into FLASH */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH + .ARM : { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } >FLASH + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >FLASH + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } >FLASH + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >FLASH + + /* used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections goes into RAM, load LMA copy after code */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + } >RAM AT> FLASH + + + /* Uninitialized data section */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss secion */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough RAM left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + /* Remove information from the standard libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} + + diff --git a/Libraries/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_dma.h b/Libraries/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_dma.h index 1fc6577..39457ff 100644 --- a/Libraries/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_dma.h +++ b/Libraries/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_dma.h @@ -45,6 +45,7 @@ extern "C" { * @{ */ +#if (defined(PY32F003PRE)|| defined(PY32F030PRE) || defined(PY32F072PRE)) /** * @brief DMA Configuration Structure definition */ @@ -471,7 +472,7 @@ uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma); #define IS_DMA_MAP_VALUE(VALUE) (VALUE < DMA_CHANNEL_MAP_END) - +#endif /** * @} */ diff --git a/Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_dma.c b/Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_dma.c index fd6944f..650999e 100644 --- a/Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_dma.c +++ b/Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_dma.c @@ -95,6 +95,7 @@ * @brief DMA HAL module driver * @{ */ +#if (defined(PY32F003PRE)|| defined(PY32F030PRE) || defined(PY32F072PRE)) #ifdef HAL_DMA_MODULE_ENABLED @@ -883,6 +884,8 @@ static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t */ #endif /* HAL_DMA_MODULE_ENABLED */ + +#endif /** * @} */ diff --git a/Makefile b/Makefile index 21e566a..0d2818f 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ PYOCD_DEVICE ?= py32f003x8 ##### Paths ############ -# Link descript file: py32f003x6.ld, py32f003x8.ld, py32f030x6.ld, py32f030x8.ld +# Link descript file: py32f002x5.ld, py32f003x6.ld, py32f003x8.ld, py32f030x6.ld, py32f030x8.ld LDSCRIPT = Libraries/LDScripts/py32f003x8.ld # Library build flags: PY32F002x5, PY32F002Ax5, PY32F003x4, PY32F003x6, PY32F003x8, PY32F030x3, PY32F030x4, PY32F030x6, PY32F030x7, PY32F030x8, PY32F072xB LIB_FLAGS = PY32F003x8