diff --git a/.platformio/packages/framework-cmsis-at32f40/.github/ISSUE_TEMPLATE/bug_report.md b/.platformio/packages/framework-cmsis-at32f40/.github/ISSUE_TEMPLATE/bug_report.md index 7de3bed..a03bdb2 100644 --- a/.platformio/packages/framework-cmsis-at32f40/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.platformio/packages/framework-cmsis-at32f40/.github/ISSUE_TEMPLATE/bug_report.md @@ -9,10 +9,9 @@ assignees: '' **Caution** The Issues are strictly limited for the reporting of problem encountered with the software provided in this project. -For any other problem related to the STM32 product, the performance, the hardware characteristics and boards, the tools the environment in general, please post a topic in the [ST Community/STM32 MCUs forum](https://community.st.com/s/group/0F90X000000AXsASAW/stm32-mcus). **Describe the set-up** - * The board (either ST RPN reference or your custom board) + * The board * IDE or at least the compiler and its version **Describe the bug** diff --git a/.platformio/packages/framework-cmsis-at32f40/.github/ISSUE_TEMPLATE/other-issue.md b/.platformio/packages/framework-cmsis-at32f40/.github/ISSUE_TEMPLATE/other-issue.md index a424001..d9dc00e 100644 --- a/.platformio/packages/framework-cmsis-at32f40/.github/ISSUE_TEMPLATE/other-issue.md +++ b/.platformio/packages/framework-cmsis-at32f40/.github/ISSUE_TEMPLATE/other-issue.md @@ -9,10 +9,9 @@ assignees: '' **Caution** The Issues are strictly limited for the reporting of problem encountered with the software provided in this project. -For any other problem related to the STM32 product, the performance, the hardware characteristics and boards, the tools the environment in general, please post a topic in the [ST Community/STM32 MCUs forum](https://community.st.com/s/group/0F90X000000AXsASAW/stm32-mcus). **Describe the set-up** - * The board (either ST RPN reference or your custom board) + * The board * IDE or at least the compiler and its version **Additional context** diff --git a/.platformio/platforms/at32/boards/generic_f403a.json b/.platformio/platforms/at32/boards/generic_f403a.json index 9da6cdb..879763f 100644 --- a/.platformio/platforms/at32/boards/generic_f403a.json +++ b/.platformio/platforms/at32/boards/generic_f403a.json @@ -8,10 +8,6 @@ [ "0x2E3C", "0xDF11" - ], - [ - "0x1EAF", - "0x0004" ] ], "mcu": "at32f403acgt7", diff --git a/.platformio/platforms/at32/builder/frameworks/_bare.py b/.platformio/platforms/at32/builder/frameworks/_bare.py index b1daab8..b35a0af 100644 --- a/.platformio/platforms/at32/builder/frameworks/_bare.py +++ b/.platformio/platforms/at32/builder/frameworks/_bare.py @@ -33,7 +33,7 @@ env.Append( CXXFLAGS=[ "-fno-rtti", - "-fno-exceptions" + "-fno-exceptions", ], CPPDEFINES=[ @@ -43,12 +43,22 @@ env.Append( LINKFLAGS=[ "-Os", "-Wl,--gc-sections,--relax", - "-mthumb" + "-mthumb", ], LIBS=["c", "gcc", "m", "stdc++"] ) +#Floating point unit: hard (hardware) | softfp (software) +if ( + any(cpu in board_config.get("build.cpu") for cpu in ("cortex-m4")) +): + env.Append( + CFLAGS=["-mfpu=fpv4-sp-d16", "-mfloat-abi=hard"], + CCFLAGS=["-mfpu=fpv4-sp-d16", "-mfloat-abi=hard"], + LINKFLAGS=["-mfpu=fpv4-sp-d16", "-mfloat-abi=hard"], + ) + if "BOARD" in env: env.Append( CCFLAGS=[ diff --git a/.platformio/platforms/at32/builder/frameworks/cmsis.py b/.platformio/platforms/at32/builder/frameworks/cmsis.py index 6ec125e..5c22397 100644 --- a/.platformio/platforms/at32/builder/frameworks/cmsis.py +++ b/.platformio/platforms/at32/builder/frameworks/cmsis.py @@ -45,10 +45,9 @@ assert product_line, "Missing MCU or Product Line field" #env.SConscript("_bare.py") -build_script = "_bare.py" +#build_script = "_bare.py" build_script = join(env.PioPlatform().get_package_dir("framework-cmsis-" + mcu[0:7]), "tools", "platformio", "platformio-build.py") -env.SConscript(build_script) if not isfile(build_script): sys.stderr.write("Error: Missing PlatformIO build script %s!\n" % build_script) @@ -138,12 +137,9 @@ env.Append( # # Compile CMSIS sources # - sources_path = os.path.join(CMSIS_DEVICE_DIR, "Source", "Templates") prepare_startup_file(sources_path) - - env.BuildSources( os.path.join("$BUILD_DIR", "FrameworkCMSIS"), sources_path, src_filter=[ diff --git a/.platformio/platforms/at32/builder/main.py b/.platformio/platforms/at32/builder/main.py index efb5e6c..30b2483 100644 --- a/.platformio/platforms/at32/builder/main.py +++ b/.platformio/platforms/at32/builder/main.py @@ -191,6 +191,41 @@ elif upload_protocol.startswith("jlink"): ) upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")] +elif upload_protocol == "dfu": + hwids = board.get("build.hwids", [["0x0483", "0xDF11"]]) + vid = hwids[0][0] + pid = hwids[0][1] + + # default tool for all boards with embedded DFU bootloader over USB + _upload_tool = '"%s"' % join(platform.get_package_dir( + "tool-dfuutil") or "", "bin", "dfu-util") + _upload_flags = [ + "-d", ",".join(["%s:%s" % (hwid[0], hwid[1]) for hwid in hwids]), + "-a", "0", "-s", + "%s:leave" % board.get("upload.offset_address", "0x08000000"), "-D" + ] + + upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")] + + if "dfu-util" in _upload_tool: + # Add special DFU header to the binary image + env.AddPostAction( + join("$BUILD_DIR", "${PROGNAME}.bin"), + env.VerboseAction( + " ".join([ + '"%s"' % join(platform.get_package_dir("tool-dfuutil") or "", + "bin", "dfu-suffix"), + "-v %s" % vid, + "-p %s" % pid, + "-d 0xffff", "-a", "$TARGET" + ]), "Adding dfu suffix to ${PROGNAME}.bin")) + env.Replace( + UPLOADER=_upload_tool, + UPLOADERFLAGS=_upload_flags, + UPLOADCMD='$UPLOADER $UPLOADERFLAGS "${SOURCE.get_abspath()}"') + + upload_source = target_firm + elif upload_protocol == "serial": def __configure_upload_port(env): @@ -199,13 +234,13 @@ elif upload_protocol == "serial": env.Replace( __configure_upload_port=__configure_upload_port, UPLOADER=join( - '"%s"' % platform.get_package_dir("tool-stm32duino") or "", - "stm32flash", "stm32flash"), + '%s' % platform.get_dir() or "", + "tools", "stm32flash", "stm32flash"), UPLOADERFLAGS=[ "-g", board.get("upload.offset_address", "0x08000000"), "-b", env.subst("$UPLOAD_SPEED") or "115200", "-w" ], - UPLOADCMD='$UPLOADER $UPLOADERFLAGS "$SOURCE" "${__configure_upload_port(__env__)}"' + UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCE ${__configure_upload_port(__env__)}' ) upload_actions = [ diff --git a/.platformio/platforms/at32/examples/cmsis-blink/.vscode/c_cpp_properties.json b/.platformio/platforms/at32/examples/cmsis-blink/.vscode/c_cpp_properties.json index d09f9a9..274c1a1 100644 --- a/.platformio/platforms/at32/examples/cmsis-blink/.vscode/c_cpp_properties.json +++ b/.platformio/platforms/at32/examples/cmsis-blink/.vscode/c_cpp_properties.json @@ -10,7 +10,7 @@ "includePath": [ "C:/Users/Xliloz/.platformio/platforms/at32/examples/cmsis-blink/include", "C:/Users/Xliloz/.platformio/platforms/at32/examples/cmsis-blink/src", - "C:/Users/Xliloz/.platformio/packages/framework-cmsis-at32f40/Source", + "C:/Users/Xliloz/.platformio/platforms/at32/examples/cmsis-blink/lib/Delay", "C:/Users/Xliloz/.platformio/packages/framework-cmsis@2.50501.200527/CMSIS/Include", "C:/Users/Xliloz/.platformio/packages/framework-cmsis-at32f40/Include", "" @@ -20,7 +20,7 @@ "path": [ "C:/Users/Xliloz/.platformio/platforms/at32/examples/cmsis-blink/include", "C:/Users/Xliloz/.platformio/platforms/at32/examples/cmsis-blink/src", - "C:/Users/Xliloz/.platformio/packages/framework-cmsis-at32f40/Source", + "C:/Users/Xliloz/.platformio/platforms/at32/examples/cmsis-blink/lib/Delay", "C:/Users/Xliloz/.platformio/packages/framework-cmsis@2.50501.200527/CMSIS/Include", "C:/Users/Xliloz/.platformio/packages/framework-cmsis-at32f40/Include", "" @@ -29,15 +29,20 @@ "defines": [ "PLATFORMIO=50200", "AT32F403ACGT7", + "DFU_MODE", + "USER_VECT_TAB_ADDRESS", + "VECT_TAB_OFFSET=0x2000", "" ], "cStandard": "c11", "compilerPath": "C:/Users/Xliloz/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin/arm-none-eabi-gcc.exe", "compilerArgs": [ + "-mfpu=fpv4-sp-d16", + "-mfloat-abi=hard", "-mcpu=cortex-m4", "-mthumb", - "-mcpu=cortex-m4", - "-mthumb", + "-mfpu=fpv4-sp-d16", + "-mfloat-abi=hard", "" ] } diff --git a/.platformio/platforms/at32/examples/cmsis-blink/platformio.ini b/.platformio/platforms/at32/examples/cmsis-blink/platformio.ini index acd267e..0b983ea 100644 --- a/.platformio/platforms/at32/examples/cmsis-blink/platformio.ini +++ b/.platformio/platforms/at32/examples/cmsis-blink/platformio.ini @@ -11,7 +11,22 @@ platform = at32 framework = cmsis board = generic_f403a -upload_protocol = custom -upload_port = COM16 -upload_speed = 460800 ;115200 460800 921600 -upload_command = ${platformio.packages_dir}/framework-cmsis-at32f40/tools/stm32flash/stm32flash -g 0x8000000 -b $UPLOAD_SPEED -w $SOURCE $UPLOAD_PORT +monitor_speed = 115200 ;serial monitor baudrate + +;Use the following for serial upload via bootloader (PA9, PA10) +;upload_protocol = serial +;upload_speed = 115200 ;default: 115200 + +;Use the following for DFU upload via USB port +upload_protocol = dfu +build_flags = + -DDFU_MODE + -UVECT_TAB_OFFSET + -DUSER_VECT_TAB_ADDRESS + -DVECT_TAB_OFFSET=0x2000 ; override default vector tale to support ISR table for DFU mode + +;Use the following for custom uploader +;upload_protocol = custom +;upload_port = COM16 +;upload_speed = 115200 +;upload_command = ${platformio.packages_dir}/framework-cmsis-at32f40/tools/stm32flash/stm32flash -b $UPLOAD_SPEED -w $SOURCE -g 0x8000000 $UPLOAD_PORT \ No newline at end of file diff --git a/.platformio/platforms/at32/examples/cmsis-blink/src/main.c b/.platformio/platforms/at32/examples/cmsis-blink/src/main.c index edaa3db..167368a 100644 --- a/.platformio/platforms/at32/examples/cmsis-blink/src/main.c +++ b/.platformio/platforms/at32/examples/cmsis-blink/src/main.c @@ -1,6 +1,7 @@ /** Light on/off pin PC13, 100Hz frequency */ #include "at32f4xx.h" +#include "delay.h" #define LEDPORT (GPIOC) #define LED1 (13) @@ -9,24 +10,16 @@ #define GPIOMODER (GPIO_CTRLH_MDE13_0) -void ms_delay(int ms) -{ - while (ms-- > 0) { - volatile int x=8000; - while (x-- > 0) - __asm("nop"); - } -} - - //Alternates blue and green LEDs quickly int main(void) { + Delay_init(); + ENABLE_GPIO_CLOCK; // enable the clock to GPIO LEDPORT->_MODER |= GPIOMODER; // set pins to be general purpose output for (;;) { - ms_delay(5); + Delay_ms(200); LEDPORT->OPTDT ^= (1<