Skip to content

Commit

Permalink
Added DFU uploader, HW Float Unit
Browse files Browse the repository at this point in the history
  • Loading branch information
martinloren committed Nov 26, 2021
1 parent b080772 commit 5e71787
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
4 changes: 0 additions & 4 deletions .platformio/platforms/at32/boards/generic_f403a.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
[
"0x2E3C",
"0xDF11"
],
[
"0x1EAF",
"0x0004"
]
],
"mcu": "at32f403acgt7",
Expand Down
14 changes: 12 additions & 2 deletions .platformio/platforms/at32/builder/frameworks/_bare.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

CXXFLAGS=[
"-fno-rtti",
"-fno-exceptions"
"-fno-exceptions",
],

CPPDEFINES=[
Expand All @@ -43,12 +43,22 @@
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=[
Expand Down
6 changes: 1 addition & 5 deletions .platformio/platforms/at32/builder/frameworks/cmsis.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@


#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)
Expand Down Expand Up @@ -138,12 +137,9 @@ def prepare_startup_file(src_path):
#
# 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=[
Expand Down
41 changes: 38 additions & 3 deletions .platformio/platforms/at32/builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,41 @@ def _jlink_cmd_script(env, source):
)
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):
Expand All @@ -199,13 +234,13 @@ def __configure_upload_port(env):
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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
""
Expand All @@ -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",
""
Expand All @@ -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",
""
]
}
Expand Down
23 changes: 19 additions & 4 deletions .platformio/platforms/at32/examples/cmsis-blink/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 4 additions & 11 deletions .platformio/platforms/at32/examples/cmsis-blink/src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** Light on/off pin PC13, 100Hz frequency */

#include "at32f4xx.h"
#include "delay.h"

#define LEDPORT (GPIOC)
#define LED1 (13)
Expand All @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions .platformio/platforms/at32/platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5e71787

Please sign in to comment.