Przeglądaj źródła

Merge pull request #1 from fengmuyou/f3_cmsis

adapt stm32f3 cmsis for rtt
沐攸 8 miesięcy temu
rodzic
commit
72d0bd5d87
44 zmienionych plików z 220 dodań i 42 usunięć
  1. 47 0
      SConscript
  2. 1 1
      Source/Templates/arm/startup_stm32f301x8.s
  3. 1 1
      Source/Templates/arm/startup_stm32f302x8.s
  4. 1 1
      Source/Templates/arm/startup_stm32f302xc.s
  5. 1 1
      Source/Templates/arm/startup_stm32f302xe.s
  6. 1 1
      Source/Templates/arm/startup_stm32f303x8.s
  7. 1 1
      Source/Templates/arm/startup_stm32f303xc.s
  8. 1 1
      Source/Templates/arm/startup_stm32f303xe.s
  9. 1 1
      Source/Templates/arm/startup_stm32f318xx.s
  10. 1 1
      Source/Templates/arm/startup_stm32f328xx.s
  11. 1 1
      Source/Templates/arm/startup_stm32f334x8.s
  12. 1 1
      Source/Templates/arm/startup_stm32f358xx.s
  13. 1 1
      Source/Templates/arm/startup_stm32f373xc.s
  14. 1 1
      Source/Templates/arm/startup_stm32f378xx.s
  15. 1 1
      Source/Templates/arm/startup_stm32f398xx.s
  16. 1 1
      Source/Templates/gcc/startup_stm32f301x8.s
  17. 1 1
      Source/Templates/gcc/startup_stm32f302x8.s
  18. 1 1
      Source/Templates/gcc/startup_stm32f302xc.s
  19. 1 1
      Source/Templates/gcc/startup_stm32f302xe.s
  20. 1 1
      Source/Templates/gcc/startup_stm32f303x8.s
  21. 1 1
      Source/Templates/gcc/startup_stm32f303xc.s
  22. 1 1
      Source/Templates/gcc/startup_stm32f303xe.s
  23. 1 1
      Source/Templates/gcc/startup_stm32f318xx.s
  24. 1 1
      Source/Templates/gcc/startup_stm32f328xx.s
  25. 1 1
      Source/Templates/gcc/startup_stm32f334x8.s
  26. 1 1
      Source/Templates/gcc/startup_stm32f358xx.s
  27. 1 1
      Source/Templates/gcc/startup_stm32f373xc.s
  28. 1 1
      Source/Templates/gcc/startup_stm32f378xx.s
  29. 1 1
      Source/Templates/gcc/startup_stm32f398xx.s
  30. 1 1
      Source/Templates/iar/linker/stm32f301x8_flash.icf
  31. 1 1
      Source/Templates/iar/linker/stm32f302x8_flash.icf
  32. 1 1
      Source/Templates/iar/linker/stm32f302xc_flash.icf
  33. 1 1
      Source/Templates/iar/linker/stm32f302xe_flash.icf
  34. 1 1
      Source/Templates/iar/linker/stm32f303x8_flash.icf
  35. 1 1
      Source/Templates/iar/linker/stm32f303xc_flash.icf
  36. 1 1
      Source/Templates/iar/linker/stm32f303xe_flash.icf
  37. 1 1
      Source/Templates/iar/linker/stm32f318xx_flash.icf
  38. 1 1
      Source/Templates/iar/linker/stm32f328xx_flash.icf
  39. 1 1
      Source/Templates/iar/linker/stm32f334x8_flash.icf
  40. 1 1
      Source/Templates/iar/linker/stm32f358xx_flash.icf
  41. 1 1
      Source/Templates/iar/linker/stm32f373xc_flash.icf
  42. 1 1
      Source/Templates/iar/linker/stm32f378xx_flash.icf
  43. 1 1
      Source/Templates/iar/linker/stm32f398xx_flash.icf
  44. 131 0
      stm32_update.py

+ 47 - 0
SConscript

@@ -0,0 +1,47 @@
+from building import *
+import os
+
+# Import environment variables
+Import('env')
+
+# Get the current working directory
+cwd = GetCurrentDir()
+
+# Initialize include paths and source files list
+path = [os.path.join(cwd, 'Include')]
+src = [os.path.join(cwd, 'Source', 'Templates', 'system_stm32f3xx.c')]
+
+# Map microcontroller units (MCUs) to their corresponding startup files
+mcu_startup_files = {
+    'STM32F301x8': 'startup_stm32f301x8.s',
+    'STM32F302x8': 'startup_stm32f302x8.s',
+    'STM32F302xC': 'startup_stm32f302xc.s',
+    'STM32F302xE': 'startup_stm32f302xe.s',
+    'STM32F303x8': 'startup_stm32f303x8.s',
+    'STM32F303xC': 'startup_stm32f303xc.s',
+    'STM32F303xE': 'startup_stm32f303xe.s',
+    'STM32F318xx': 'startup_stm32f318xx.s',
+    'STM32F328xx': 'startup_stm32f328xx.s',
+    'STM32F334x8': 'startup_stm32f334x8.s',
+    'STM32F358xx': 'startup_stm32f358xx.s',
+    'STM32F373xC': 'startup_stm32f373xc.s',
+    'STM32F378xx': 'startup_stm32f378xx.s',
+    'STM32F398xx': 'startup_stm32f398xx.s', 
+}
+
+# Check each defined MCU, match the platform and append the appropriate startup file
+for mcu, startup_file in mcu_startup_files.items():
+    if mcu in env.get('CPPDEFINES', []):
+        if rtconfig.PLATFORM in ['gcc', 'llvm-arm']:
+            src += [os.path.join(cwd, 'Source', 'Templates', 'gcc', startup_file)]
+        elif rtconfig.PLATFORM in ['armcc', 'armclang']:
+            src += [os.path.join(cwd, 'Source', 'Templates', 'arm', startup_file)]
+        elif rtconfig.PLATFORM in ['iccarm']:
+            src += [os.path.join(cwd, 'Source', 'Templates', 'iar', startup_file)]
+        break
+
+# Define the build group
+group = DefineGroup('STM32F3-CMSIS', src, depend=['PKG_USING_STM32F3_CMSIS_DRIVER'], CPPPATH=path)
+
+# Return the build group
+Return('group')

+ 1 - 1
Source/Templates/arm/startup_stm32f301x8.s

@@ -40,7 +40,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00000200
+Heap_Size       EQU     0x00000000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

+ 1 - 1
Source/Templates/arm/startup_stm32f302x8.s

@@ -40,7 +40,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00000200
+Heap_Size       EQU     0x00000000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

+ 1 - 1
Source/Templates/arm/startup_stm32f302xc.s

@@ -40,7 +40,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00000200
+Heap_Size       EQU     0x00000000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

+ 1 - 1
Source/Templates/arm/startup_stm32f302xe.s

@@ -40,7 +40,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00000200
+Heap_Size       EQU     0x00000000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

+ 1 - 1
Source/Templates/arm/startup_stm32f303x8.s

@@ -40,7 +40,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00000200
+Heap_Size       EQU     0x00000000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

+ 1 - 1
Source/Templates/arm/startup_stm32f303xc.s

@@ -40,7 +40,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00000200
+Heap_Size       EQU     0x00000000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

+ 1 - 1
Source/Templates/arm/startup_stm32f303xe.s

@@ -40,7 +40,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00000200
+Heap_Size       EQU     0x00000000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

+ 1 - 1
Source/Templates/arm/startup_stm32f318xx.s

@@ -40,7 +40,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00000200
+Heap_Size       EQU     0x00000000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

+ 1 - 1
Source/Templates/arm/startup_stm32f328xx.s

@@ -40,7 +40,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00000200
+Heap_Size       EQU     0x00000000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

+ 1 - 1
Source/Templates/arm/startup_stm32f334x8.s

@@ -40,7 +40,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00000200
+Heap_Size       EQU     0x00000000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

+ 1 - 1
Source/Templates/arm/startup_stm32f358xx.s

@@ -40,7 +40,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00000200
+Heap_Size       EQU     0x00000000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

+ 1 - 1
Source/Templates/arm/startup_stm32f373xc.s

@@ -40,7 +40,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00000200
+Heap_Size       EQU     0x00000000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

+ 1 - 1
Source/Templates/arm/startup_stm32f378xx.s

@@ -40,7 +40,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00000200
+Heap_Size       EQU     0x00000000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

+ 1 - 1
Source/Templates/arm/startup_stm32f398xx.s

@@ -40,7 +40,7 @@ __initial_sp
 ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
 ; </h>
 
-Heap_Size       EQU     0x00000200
+Heap_Size       EQU     0x00000000
 
                 AREA    HEAP, NOINIT, READWRITE, ALIGN=3
 __heap_base

+ 1 - 1
Source/Templates/gcc/startup_stm32f301x8.s

@@ -98,7 +98,7 @@ LoopFillZerobss:
 /* Call static constructors */
     bl __libc_init_array
 /* Call the application's entry point.*/
-	bl	main
+	bl	entry
 
 LoopForever:
     b LoopForever

+ 1 - 1
Source/Templates/gcc/startup_stm32f302x8.s

@@ -98,7 +98,7 @@ LoopFillZerobss:
 /* Call static constructors */
     bl __libc_init_array
 /* Call the application's entry point.*/
-	bl	main
+	bl	entry
 
 LoopForever:
     b LoopForever

+ 1 - 1
Source/Templates/gcc/startup_stm32f302xc.s

@@ -98,7 +98,7 @@ LoopFillZerobss:
 /* Call static constructors */
     bl __libc_init_array
 /* Call the application's entry point.*/
-	bl	main
+	bl	entry
 
 LoopForever:
     b LoopForever

+ 1 - 1
Source/Templates/gcc/startup_stm32f302xe.s

@@ -98,7 +98,7 @@ LoopFillZerobss:
 /* Call static constructors */
     bl __libc_init_array
 /* Call the application's entry point.*/
-	bl	main
+	bl	entry
 
 LoopForever:
     b LoopForever

+ 1 - 1
Source/Templates/gcc/startup_stm32f303x8.s

@@ -98,7 +98,7 @@ LoopFillZerobss:
 /* Call static constructors */
     bl __libc_init_array
 /* Call the application's entry point.*/
-	bl	main
+	bl	entry
 
 LoopForever:
     b LoopForever

+ 1 - 1
Source/Templates/gcc/startup_stm32f303xc.s

@@ -98,7 +98,7 @@ LoopFillZerobss:
 /* Call static constructors */
     bl __libc_init_array
 /* Call the application's entry point.*/
-	bl	main
+	bl	entry
 
 LoopForever:
     b LoopForever

+ 1 - 1
Source/Templates/gcc/startup_stm32f303xe.s

@@ -98,7 +98,7 @@ LoopFillZerobss:
 /* Call static constructors */
     bl __libc_init_array
 /* Call the application's entry point.*/
-	bl	main
+	bl	entry
 
 LoopForever:
     b LoopForever

+ 1 - 1
Source/Templates/gcc/startup_stm32f318xx.s

@@ -98,7 +98,7 @@ LoopFillZerobss:
 /* Call static constructors */
     bl __libc_init_array
 /* Call the application's entry point.*/
-	bl	main
+	bl	entry
 
 LoopForever:
     b LoopForever

+ 1 - 1
Source/Templates/gcc/startup_stm32f328xx.s

@@ -98,7 +98,7 @@ LoopFillZerobss:
 /* Call static constructors */
     bl __libc_init_array
 /* Call the application's entry point.*/
-	bl	main
+	bl	entry
 
 LoopForever:
     b LoopForever

+ 1 - 1
Source/Templates/gcc/startup_stm32f334x8.s

@@ -98,7 +98,7 @@ LoopFillZerobss:
 /* Call static constructors */
     bl __libc_init_array
 /* Call the application's entry point.*/
-	bl	main
+	bl	entry
 
 LoopForever:
     b LoopForever

+ 1 - 1
Source/Templates/gcc/startup_stm32f358xx.s

@@ -98,7 +98,7 @@ LoopFillZerobss:
 /* Call static constructors */
     bl __libc_init_array
 /* Call the application's entry point.*/
-	bl	main
+	bl	entry
 
 LoopForever:
     b LoopForever

+ 1 - 1
Source/Templates/gcc/startup_stm32f373xc.s

@@ -98,7 +98,7 @@ LoopFillZerobss:
 /* Call static constructors */
     bl __libc_init_array
 /* Call the application's entry point.*/
-	bl	main
+	bl	entry
 
 LoopForever:
     b LoopForever

+ 1 - 1
Source/Templates/gcc/startup_stm32f378xx.s

@@ -98,7 +98,7 @@ LoopFillZerobss:
 /* Call static constructors */
     bl __libc_init_array
 /* Call the application's entry point.*/
-	bl	main
+	bl	entry
 
 LoopForever:
     b LoopForever

+ 1 - 1
Source/Templates/gcc/startup_stm32f398xx.s

@@ -98,7 +98,7 @@ LoopFillZerobss:
 /* Call static constructors */
     bl __libc_init_array
 /* Call the application's entry point.*/
-	bl	main
+	bl	entry
 
 LoopForever:
     b LoopForever

+ 1 - 1
Source/Templates/iar/linker/stm32f301x8_flash.icf

@@ -10,7 +10,7 @@ define symbol __ICFEDIT_region_RAM_start__    = 0x20000000;
 define symbol __ICFEDIT_region_RAM_end__      = 0x20003FFF;
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x400;
-define symbol __ICFEDIT_size_heap__   = 0x200;
+define symbol __ICFEDIT_size_heap__   = 0x000;
 /**** End of ICF editor section. ###ICF###*/
 
 

+ 1 - 1
Source/Templates/iar/linker/stm32f302x8_flash.icf

@@ -10,7 +10,7 @@ define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
 define symbol __ICFEDIT_region_RAM_end__   = 0x20003FFF;
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x400;
-define symbol __ICFEDIT_size_heap__   = 0x200;
+define symbol __ICFEDIT_size_heap__   = 0x000;
 /**** End of ICF editor section. ###ICF###*/
 
 

+ 1 - 1
Source/Templates/iar/linker/stm32f302xc_flash.icf

@@ -10,7 +10,7 @@ define symbol __ICFEDIT_region_RAM_start__    = 0x20000000;
 define symbol __ICFEDIT_region_RAM_end__      = 0x20009FFF;
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x400;
-define symbol __ICFEDIT_size_heap__   = 0x200;
+define symbol __ICFEDIT_size_heap__   = 0x000;
 /**** End of ICF editor section. ###ICF###*/
 
 

+ 1 - 1
Source/Templates/iar/linker/stm32f302xe_flash.icf

@@ -10,7 +10,7 @@ define symbol __ICFEDIT_region_RAM_start__    = 0x20000000;
 define symbol __ICFEDIT_region_RAM_end__      = 0x2000FFFF;
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x400;
-define symbol __ICFEDIT_size_heap__   = 0x200;
+define symbol __ICFEDIT_size_heap__   = 0x000;
 /**** End of ICF editor section. ###ICF###*/
 
 

+ 1 - 1
Source/Templates/iar/linker/stm32f303x8_flash.icf

@@ -12,7 +12,7 @@ define symbol __ICFEDIT_region_CCMRAM_start__ = 0x10000000;
 define symbol __ICFEDIT_region_CCMRAM_end__   = 0x10000FFF;
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x400;
-define symbol __ICFEDIT_size_heap__   = 0x200;
+define symbol __ICFEDIT_size_heap__   = 0x000;
 /**** End of ICF editor section. ###ICF###*/
 
 

+ 1 - 1
Source/Templates/iar/linker/stm32f303xc_flash.icf

@@ -12,7 +12,7 @@ define symbol __ICFEDIT_region_CCMRAM_start__ = 0x10000000;
 define symbol __ICFEDIT_region_CCMRAM_end__   = 0x10001FFF;
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x400;
-define symbol __ICFEDIT_size_heap__   = 0x200;
+define symbol __ICFEDIT_size_heap__   = 0x000;
 /**** End of ICF editor section. ###ICF###*/
 
 

+ 1 - 1
Source/Templates/iar/linker/stm32f303xe_flash.icf

@@ -12,7 +12,7 @@ define symbol __ICFEDIT_region_CCMRAM_start__ = 0x10000000;
 define symbol __ICFEDIT_region_CCMRAM_end__   = 0x10003FFF;
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x400;
-define symbol __ICFEDIT_size_heap__   = 0x200;
+define symbol __ICFEDIT_size_heap__   = 0x000;
 /**** End of ICF editor section. ###ICF###*/
 
 

+ 1 - 1
Source/Templates/iar/linker/stm32f318xx_flash.icf

@@ -10,7 +10,7 @@ define symbol __ICFEDIT_region_RAM_start__    = 0x20000000;
 define symbol __ICFEDIT_region_RAM_end__      = 0x20003FFF;
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x400;
-define symbol __ICFEDIT_size_heap__   = 0x200;
+define symbol __ICFEDIT_size_heap__   = 0x000;
 /**** End of ICF editor section. ###ICF###*/
 
 

+ 1 - 1
Source/Templates/iar/linker/stm32f328xx_flash.icf

@@ -12,7 +12,7 @@ define symbol __ICFEDIT_region_CCMRAM_start__ = 0x10000000;
 define symbol __ICFEDIT_region_CCMRAM_end__   = 0x10000FFF;
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x400;
-define symbol __ICFEDIT_size_heap__   = 0x200;
+define symbol __ICFEDIT_size_heap__   = 0x000;
 /**** End of ICF editor section. ###ICF###*/
 
 

+ 1 - 1
Source/Templates/iar/linker/stm32f334x8_flash.icf

@@ -12,7 +12,7 @@ define symbol __ICFEDIT_region_CCMRAM_start__ = 0x10000000;
 define symbol __ICFEDIT_region_CCMRAM_end__   = 0x10000FFF;
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x400;
-define symbol __ICFEDIT_size_heap__   = 0x200;
+define symbol __ICFEDIT_size_heap__   = 0x000;
 /**** End of ICF editor section. ###ICF###*/
 
 

+ 1 - 1
Source/Templates/iar/linker/stm32f358xx_flash.icf

@@ -12,7 +12,7 @@ define symbol __ICFEDIT_region_CCMRAM_start__ = 0x10000000;
 define symbol __ICFEDIT_region_CCMRAM_end__   = 0x10001FFF;
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x400;
-define symbol __ICFEDIT_size_heap__   = 0x200;
+define symbol __ICFEDIT_size_heap__   = 0x000;
 /**** End of ICF editor section. ###ICF###*/
 
 

+ 1 - 1
Source/Templates/iar/linker/stm32f373xc_flash.icf

@@ -10,7 +10,7 @@ define symbol __ICFEDIT_region_RAM_start__    = 0x20000000;
 define symbol __ICFEDIT_region_RAM_end__      = 0x20007FFF;
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x400;
-define symbol __ICFEDIT_size_heap__   = 0x200;
+define symbol __ICFEDIT_size_heap__   = 0x000;
 /**** End of ICF editor section. ###ICF###*/
 
 

+ 1 - 1
Source/Templates/iar/linker/stm32f378xx_flash.icf

@@ -10,7 +10,7 @@ define symbol __ICFEDIT_region_RAM_start__    = 0x20000000;
 define symbol __ICFEDIT_region_RAM_end__      = 0x20007FFF;
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x400;
-define symbol __ICFEDIT_size_heap__   = 0x200;
+define symbol __ICFEDIT_size_heap__   = 0x000;
 /**** End of ICF editor section. ###ICF###*/
 
 

+ 1 - 1
Source/Templates/iar/linker/stm32f398xx_flash.icf

@@ -12,7 +12,7 @@ define symbol __ICFEDIT_region_CCMRAM_start__ = 0x10000000;
 define symbol __ICFEDIT_region_CCMRAM_end__   = 0x10003FFF;
 /*-Sizes-*/
 define symbol __ICFEDIT_size_cstack__ = 0x400;
-define symbol __ICFEDIT_size_heap__   = 0x200;
+define symbol __ICFEDIT_size_heap__   = 0x000;
 /**** End of ICF editor section. ###ICF###*/
 
 

+ 131 - 0
stm32_update.py

@@ -0,0 +1,131 @@
+# Copyright (c) 2006-2022, RT-Thread Development Team
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# Change Logs:
+# Date           Author       Notes
+# 2021-10-11     Meco Man     First version
+
+# This file is suggested to use under Linux environment.
+# > python stm32_update.py
+# update STM32 startup assembly language file:
+# 1.replace main to entry (GCC)
+# 2.reduce the heap size as 0x000 (Keil IAR)
+# 3.extend the GCC stack size as 0x400, which is the same as Keil and IAR startup files.
+
+import os
+import re
+
+# replace 'bl main' to 'bl entry'
+def stm32update_main2entry(path):
+    oldline = ''
+    newline = ''
+
+    for root, dirs, files in os.walk(path):
+        for file in files:
+            if os.path.splitext(file)[1] == '.s': # find .s files (Keil MDK)
+                file_path = os.path.join(root,file)
+                flag_need_replace = False
+                with open(file_path,'r+',) as f:
+                    while True:
+                        line = f.readline()
+                        if line == '':
+                            break
+                        elif ('bl' in line) and ('main' in line): # find 'bl main'
+                            oldline = line # bl main
+                            newline = line.replace('main', 'entry') # use 'entry' to replace 'main'
+                            flag_need_replace = True # mark that need to be replaced
+                            break
+
+                    if (flag_need_replace == True): # use 'entry' to replace 'main'
+                        f.seek(0)
+                        content = f.read()
+                        f.seek(0)
+                        f.truncate()
+                        newcontent = content.replace(oldline, newline)
+                        f.write(newcontent)
+
+#reduce the heap size as 0x000
+def stm32update_heap2zero(path):
+    oldline = ''
+    newline = ''
+    for root, dirs, files in os.walk(path):
+        for file in files:
+            file_path = os.path.join(root,file)
+            if os.path.splitext(file)[1] == '.s': # find .s files (Keil MDK)
+                with open(file_path,'r+',) as f:
+                    flag_need_replace = False
+                    while True:
+                        line = f.readline()
+                        if line == '':
+                            break
+
+                        re_result = re.match('\\s*Heap_Size\\s+EQU\\s+0[xX][0-9a-fA-F]+', line)
+                        if re_result != None:
+                            oldline = line
+                            newline = re.sub('0[xX][0-9a-fA-F]+','0x00000000', oldline)
+                            flag_need_replace = True
+                            break
+
+                    if flag_need_replace == True:
+                        f.seek(0)
+                        content = f.read()
+                        f.seek(0)
+                        f.truncate()
+                        newcontent = content.replace(oldline, newline)
+                        f.write(newcontent)
+
+            elif os.path.splitext(file)[1] == '.icf': # find .icf files (IAR)
+                with open(file_path,'r+',) as f:
+                    flag_need_replace = False
+                    while True:
+                        line = f.readline()
+                        if line == '':
+                            break
+
+                        re_result = re.match('\\s*define\\s+symbol\\s+__ICFEDIT_size_heap__\\s*=\\s*0[xX][0-9a-fA-F]+', line)
+                        if re_result != None:
+                            oldline = line
+                            newline = re.sub('0[xX][0-9a-fA-F]+','0x000', oldline)
+                            flag_need_replace = True
+                            break
+
+                    if flag_need_replace == True:
+                        f.seek(0)
+                        content = f.read()
+                        f.seek(0)
+                        f.truncate()
+                        newcontent = content.replace(oldline, newline)
+                        f.write(newcontent)
+
+            elif os.path.splitext(file)[1] == '.lds': # find .lds files (GCC)
+                with open(file_path,'r+',) as f:
+                    flag_need_replace = False
+                    while True:
+                        line = f.readline()
+                        if line == '':
+                            break
+
+                        re_result = re.match('\\s*_system_stack_size\\s*=\\s*0[xX][0-9a-fA-F]+', line)
+                        if re_result != None:
+                            oldline = line
+                            newline = re.sub('0[xX][0-9a-fA-F]+','0x400', oldline)
+                            flag_need_replace = True
+                            break
+
+                    if flag_need_replace == True:
+                        f.seek(0)
+                        content = f.read()
+                        f.seek(0)
+                        f.truncate()
+                        newcontent = content.replace(oldline, newline)
+                        f.write(newcontent)
+
+
+def stm32_update(path):
+    stm32update_main2entry(path)
+    stm32update_heap2zero(path)
+
+if __name__ == "__main__":
+    stm32_update(os.getcwd())
+    print("STM32 startup assembly language file update successfully!")