Added DFU uploader, HW Float Unit

This commit is contained in:
Martin Loren
2021-11-27 07:47:21 +08:00
parent b080772374
commit 5e7178734d
10 changed files with 91 additions and 37 deletions

View File

@@ -8,10 +8,6 @@
[
"0x2E3C",
"0xDF11"
],
[
"0x1EAF",
"0x0004"
]
],
"mcu": "at32f403acgt7",

View File

@@ -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=[

View File

@@ -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=[

View File

@@ -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 = [

View File

@@ -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",
""
]
}

View File

@@ -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

View File

@@ -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<<LED1); // toggle diodes ODR
}

View File

@@ -66,6 +66,12 @@
"owner": "platformio",
"version": "^1.63208.0"
},
"tool-dfuutil": {
"type": "uploader",
"optional": true,
"owner": "platformio",
"version": "~1.9.190708"
},
"tool-cmake": {
"optional": true,
"owner": "platformio",