mirror of
https://github.com/WeActStudio/ArduinoCore-AT32F4.git
synced 2026-05-21 09:22:01 +00:00
fixed bug
This commit is contained in:
@@ -55,7 +55,7 @@ extern "C" {
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define ABS(x) (((x)>0)?(x):-(x)) //abs(x) is define in stdlib.h
|
||||
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
//#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
#define radians(deg) ((deg)*DEG_TO_RAD)
|
||||
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
||||
#define sq(x) ((x)*(x))
|
||||
@@ -111,8 +111,8 @@ void yield(void);
|
||||
# include "WCharacter.h"
|
||||
# include "WString.h"
|
||||
# include "WMath.h"
|
||||
# include <libcore/Tone.h>
|
||||
# include <libcore/HardwareSerial.h>
|
||||
# include <Tone.h>
|
||||
# include <HardwareSerial.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
#define SPI_I2S_GET_FLAG(spix, SPI_I2S_FLAG) (spix->sts & SPI_I2S_FLAG)
|
||||
#define SPI_I2S_RXDATA(spix) (spix->dt)
|
||||
#define SPI_I2S_RXDATA_VOLATILE(spix) volatile uint16_t vn = SPI_I2S_RXDATA(spix)
|
||||
#define SPI_I2S_RXDATA_VOLATILE(spix) do{ volatile uint16_t vn = SPI_I2S_RXDATA(spix); vn = vn; } while(0)
|
||||
#define SPI_I2S_TXDATA(spix, data) (spix->dt = (data))
|
||||
#define SPI_I2S_WAIT_RX(spix) do{ while (!SPI_I2S_GET_FLAG(spix, SPI_I2S_RDBF_FLAG)); } while(0)
|
||||
#define SPI_I2S_WAIT_TX(spix) do{ while (!SPI_I2S_GET_FLAG(spix, SPI_I2S_TDBE_FLAG)); } while(0)
|
||||
@@ -23,7 +23,7 @@
|
||||
#ifndef __TONE_H
|
||||
#define __TONE_H
|
||||
|
||||
#include "timer.h"
|
||||
#include "libcore/timer.h"
|
||||
|
||||
#define TONE_DURATION_INFINITE 0xFFFFFFFFU
|
||||
|
||||
2
ArduinoCore-AT32F403A/tools/.flake8
Normal file
2
ArduinoCore-AT32F403A/tools/.flake8
Normal file
@@ -0,0 +1,2 @@
|
||||
[flake8]
|
||||
max-line-length = 95
|
||||
35
ArduinoCore-AT32F403A/tools/platformio/boards_remap.json
Normal file
35
ArduinoCore-AT32F403A/tools/platformio/boards_remap.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"adafruit_feather_f405": "FEATHER_F405",
|
||||
"blackpill_f103c8_128": "BLACKPILL_F103C8",
|
||||
"blackpill_f401ce": "BLACKPILL_F401CC",
|
||||
"coreboard_f401rc": "CoreBoard_F401RC",
|
||||
"disco_g031j6": "DISCO_G0316",
|
||||
"disco_l072cz_lrwan1": "B_L072Z_LRWAN1",
|
||||
"disco_l475vg_iot01a": "B_L475E_IOT01A",
|
||||
"disco_l4s5i_iot01a": "B_L4S5I_IOT01A",
|
||||
"electrosmith_daisy": "DAISY_SEED",
|
||||
"maple_mini_origin": "MAPLEMINI_F103CB",
|
||||
"microduino32_flash": "GENERIC_F103C8TX",
|
||||
"netduino2plus": "GENERIC_F405RGTX",
|
||||
"nucleo_wb55rg_p": "P_NUCLEO_WB55RG",
|
||||
"olimex_e407": "GENERIC_F407ZGTX",
|
||||
"olimex_f103": "GENERIC_F103R8TX",
|
||||
"olimex_h407": "GENERIC_F407ZGTX",
|
||||
"olimex_p405": "GENERIC_F405RGTX",
|
||||
"olimexino": "GENERIC_F103RBTX",
|
||||
"piconomix_px_her0": "PX_HER0",
|
||||
"rak811_tracker_32": "RAK811_TRACKERA",
|
||||
"robotdyn_blackpill_f303cc": "BLACKPILL_F303CC",
|
||||
"rumba32_f446ve": "RUMBA32",
|
||||
"sparky_v1": "SPARKY_F303CC",
|
||||
"steval_mksboxv1": "STEVAL_MKSBOX1V1",
|
||||
"stm32f4stamp": "GENERIC_F405RGTX",
|
||||
"thunder_pack": "THUNDERPACK_L072",
|
||||
"thunder_pack_f411": "THUNDERPACK_F411",
|
||||
"vccgnd_f103zet6": "VCCGND_F103ZET6_MINI",
|
||||
"waveshare_open103z": "GENERIC_F103ZEHX",
|
||||
"bw_swan_r5": "SWAN_R5",
|
||||
"disco_b_g431b_esc1": "B_G431B_ESC1",
|
||||
"disco_b_u585i_iot02a": "B_U585I_IOT02A",
|
||||
"nucleo_wl55jc": "NUCLEO_WL55JC1"
|
||||
}
|
||||
414
ArduinoCore-AT32F403A/tools/platformio/platformio-build.py
Normal file
414
ArduinoCore-AT32F403A/tools/platformio/platformio-build.py
Normal file
@@ -0,0 +1,414 @@
|
||||
# Copyright 2014-present PlatformIO <contact@platformio.org>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""
|
||||
Arduino
|
||||
|
||||
Arduino Wiring-based Framework allows writing cross-platform software to
|
||||
control devices attached to a wide range of Arduino boards to create all
|
||||
kinds of creative coding, interactive objects, spaces or physical experiences.
|
||||
|
||||
https://github.com/stm32duino/Arduino_Core_STM32
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from os.path import isfile, isdir, join
|
||||
|
||||
from SCons.Script import COMMAND_LINE_TARGETS, DefaultEnvironment
|
||||
|
||||
env = DefaultEnvironment()
|
||||
platform = env.PioPlatform()
|
||||
board_config = env.BoardConfig()
|
||||
|
||||
IS_WINDOWS = sys.platform.startswith("win")
|
||||
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoststm32")
|
||||
CMSIS_DIR = join(platform.get_package_dir("framework-cmsis"), "CMSIS")
|
||||
assert isdir(FRAMEWORK_DIR)
|
||||
assert isdir(CMSIS_DIR)
|
||||
|
||||
|
||||
mcu = board_config.get("build.mcu", "")
|
||||
mcu_type = mcu[:-2]
|
||||
variant = board_config.get(
|
||||
"build.variant", board_config.get("build.arduino.variant", "generic")
|
||||
)
|
||||
series = mcu_type[:7].upper() + "xx"
|
||||
variants_dir = (
|
||||
join("$PROJECT_DIR", board_config.get("build.variants_dir"))
|
||||
if board_config.get("build.variants_dir", "")
|
||||
else join(FRAMEWORK_DIR, "variants")
|
||||
)
|
||||
variant_dir = join(variants_dir, variant)
|
||||
inc_variant_dir = variant_dir
|
||||
if not IS_WINDOWS and not (
|
||||
set(["_idedata", "idedata"]) & set(COMMAND_LINE_TARGETS) and " " not in variant_dir
|
||||
):
|
||||
inc_variant_dir = variant_dir.replace("(", r"\(").replace(")", r"\)")
|
||||
|
||||
upload_protocol = env.subst("$UPLOAD_PROTOCOL")
|
||||
|
||||
|
||||
def process_standard_library_configuration(cpp_defines):
|
||||
if "PIO_FRAMEWORK_ARDUINO_STANDARD_LIB" in cpp_defines:
|
||||
env["LINKFLAGS"].remove("--specs=nano.specs")
|
||||
if "PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF" in cpp_defines:
|
||||
env.Append(LINKFLAGS=["-u_printf_float"])
|
||||
if "PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_SCANF" in cpp_defines:
|
||||
env.Append(LINKFLAGS=["-u_scanf_float"])
|
||||
|
||||
|
||||
def process_usart_configuration(cpp_defines):
|
||||
if "PIO_FRAMEWORK_ARDUINO_SERIAL_DISABLED" in cpp_defines:
|
||||
env["CPPDEFINES"].remove("HAL_UART_MODULE_ENABLED")
|
||||
|
||||
elif "PIO_FRAMEWORK_ARDUINO_SERIAL_WITHOUT_GENERIC" in cpp_defines:
|
||||
env.Append(CPPDEFINES=["HWSERIAL_NONE"])
|
||||
|
||||
|
||||
def process_usb_speed_configuration(cpp_defines):
|
||||
if "PIO_FRAMEWORK_ARDUINO_USB_HIGHSPEED" in cpp_defines:
|
||||
env.Append(CPPDEFINES=["USE_USB_HS"])
|
||||
|
||||
elif "PIO_FRAMEWORK_ARDUINO_USB_HIGHSPEED_FULLMODE" in cpp_defines:
|
||||
env.Append(CPPDEFINES=["USE_USB_HS", "USE_USB_HS_IN_FS"])
|
||||
|
||||
|
||||
def process_usb_configuration(cpp_defines):
|
||||
if "PIO_FRAMEWORK_ARDUINO_ENABLE_CDC" in cpp_defines:
|
||||
env.Append(CPPDEFINES=["USBD_USE_CDC"])
|
||||
|
||||
elif "PIO_FRAMEWORK_ARDUINO_ENABLE_CDC_WITHOUT_SERIAL" in cpp_defines:
|
||||
env.Append(CPPDEFINES=["USBD_USE_CDC", "DISABLE_GENERIC_SERIALUSB"])
|
||||
|
||||
elif "PIO_FRAMEWORK_ARDUINO_ENABLE_HID" in cpp_defines:
|
||||
env.Append(CPPDEFINES=["USBD_USE_HID_COMPOSITE"])
|
||||
|
||||
if any(
|
||||
d in cpp_defines
|
||||
for d in (
|
||||
"PIO_FRAMEWORK_ARDUINO_ENABLE_CDC",
|
||||
"PIO_FRAMEWORK_ARDUINO_ENABLE_CDC_WITHOUT_SERIAL",
|
||||
"PIO_FRAMEWORK_ARDUINO_ENABLE_HID",
|
||||
)
|
||||
):
|
||||
env.Append(
|
||||
CPPDEFINES=[
|
||||
"USBCON",
|
||||
("USB_VID", board_config.get("build.hwids", [[0, 0]])[0][0]),
|
||||
("USB_PID", board_config.get("build.hwids", [[0, 0]])[0][1]),
|
||||
]
|
||||
)
|
||||
|
||||
if any(f in env["CPPDEFINES"] for f in ("USBD_USE_CDC", "USBD_USE_HID_COMPOSITE")):
|
||||
env.Append(CPPDEFINES=["HAL_PCD_MODULE_ENABLED"])
|
||||
|
||||
|
||||
def get_arm_math_lib(cpu):
|
||||
if "m33" in cpu:
|
||||
return "arm_ARMv8MMLlfsp_math"
|
||||
elif "m4" in cpu:
|
||||
return "arm_cortexM4lf_math"
|
||||
elif "m7" in cpu:
|
||||
return "arm_cortexM7lfsp_math"
|
||||
|
||||
return "arm_cortex%sl_math" % cpu[7:9].upper()
|
||||
|
||||
|
||||
def configure_application_offset(mcu, upload_protocol):
|
||||
offset = 0
|
||||
|
||||
if upload_protocol == "hid":
|
||||
if mcu.startswith("stm32f1"):
|
||||
offset = 0x800
|
||||
elif mcu.startswith("stm32f4"):
|
||||
offset = 0x4000
|
||||
|
||||
env.Append(CPPDEFINES=["BL_HID"])
|
||||
|
||||
elif upload_protocol == "dfu":
|
||||
# STM32F103 series doesn't have embedded DFU over USB
|
||||
# stm32duino bootloader (v1, v2) is used instead
|
||||
if mcu.startswith("stm32f103"):
|
||||
if board_config.get("upload.boot_version", 2) == 1:
|
||||
offset = 0x5000
|
||||
else:
|
||||
offset = 0x2000
|
||||
env.Append(CPPDEFINES=["BL_LEGACY_LEAF"])
|
||||
|
||||
if offset != 0:
|
||||
env.Append(
|
||||
CPPDEFINES=[("VECT_TAB_OFFSET", "%s" % hex(offset))],
|
||||
)
|
||||
|
||||
# LD_FLASH_OFFSET is mandatory even if there is no offset
|
||||
env.Append(LINKFLAGS=["-Wl,--defsym=LD_FLASH_OFFSET=%s" % hex(offset)])
|
||||
|
||||
|
||||
def load_boards_remap():
|
||||
remap_file = join(FRAMEWORK_DIR, "tools", "platformio", "boards_remap.json")
|
||||
if not isfile(remap_file):
|
||||
print("Warning! Couldn't find board remap file!")
|
||||
return {}
|
||||
|
||||
with open(remap_file, "r") as fp:
|
||||
try:
|
||||
return json.load(fp)
|
||||
except:
|
||||
print("Warning! Failed to parse board remap file!")
|
||||
return {}
|
||||
|
||||
|
||||
def get_arduino_board_id(board_config, mcu):
|
||||
# User-specified value
|
||||
if board_config.get("build.arduino.board", ""):
|
||||
return board_config.get("build.arduino.board")
|
||||
|
||||
# Default boards
|
||||
boards_remap = load_boards_remap()
|
||||
board_id = env.subst("$BOARD")
|
||||
if board_id in boards_remap:
|
||||
return boards_remap[board_id]
|
||||
|
||||
# Fall back to default cases according to MCU value for generic boards
|
||||
if board_id.lower().startswith("generic"):
|
||||
board_id = "GENERIC_"
|
||||
mcu = mcu.upper()
|
||||
if len(mcu) > 12:
|
||||
board_id += mcu[5:12] + "X"
|
||||
else:
|
||||
if len(mcu) > 10:
|
||||
board_id += mcu[5:11] + "TX"
|
||||
else:
|
||||
board_id += mcu
|
||||
print(
|
||||
"Warning! Couldn't generate proper internal board id from the `%s` MCU "
|
||||
"field! At least 12 symbols are required!" % mcu
|
||||
)
|
||||
|
||||
print("Falling back to `%s`." % board_id)
|
||||
|
||||
return board_id.upper()
|
||||
|
||||
board_id = get_arduino_board_id(board_config, mcu)
|
||||
machine_flags = [
|
||||
"-mcpu=%s" % board_config.get("build.cpu"),
|
||||
"-mthumb",
|
||||
]
|
||||
|
||||
if (
|
||||
any(cpu in board_config.get("build.cpu") for cpu in ("cortex-m33", "cortex-m4", "cortex-m7"))
|
||||
and "stm32wl" not in mcu
|
||||
):
|
||||
machine_flags.extend(["-mfpu=fpv4-sp-d16", "-mfloat-abi=hard"])
|
||||
|
||||
env.Append(
|
||||
ASFLAGS=machine_flags,
|
||||
ASPPFLAGS=[
|
||||
"-x", "assembler-with-cpp",
|
||||
],
|
||||
CFLAGS=["-std=gnu11"],
|
||||
CXXFLAGS=[
|
||||
"-std=gnu++14",
|
||||
"-fno-threadsafe-statics",
|
||||
"-fno-rtti",
|
||||
"-fno-exceptions",
|
||||
"-fno-use-cxa-atexit",
|
||||
],
|
||||
CCFLAGS=machine_flags + [
|
||||
"-Os", # optimize for size
|
||||
"-ffunction-sections", # place each function in its own section
|
||||
"-fdata-sections",
|
||||
"-nostdlib",
|
||||
"--param", "max-inline-insns-single=500",
|
||||
],
|
||||
CPPDEFINES=[
|
||||
series,
|
||||
("ARDUINO", 10808),
|
||||
"ARDUINO_ARCH_STM32",
|
||||
"ARDUINO_%s" % board_id,
|
||||
("BOARD_NAME", '\\"%s\\"' % board_id),
|
||||
"HAL_UART_MODULE_ENABLED",
|
||||
"USE_FULL_LL_DRIVER",
|
||||
(
|
||||
"VARIANT_H",
|
||||
'\\"%s\\"'
|
||||
% board_config.get(
|
||||
"build.arduino.variant_h",
|
||||
"variant_%s.h"
|
||||
% ("generic" if board_id.lower().startswith("generic") else board_id),
|
||||
),
|
||||
),
|
||||
],
|
||||
CPPPATH=[
|
||||
join(FRAMEWORK_DIR, "cores", "arduino", "avr"),
|
||||
join(FRAMEWORK_DIR, "cores", "arduino", "stm32"),
|
||||
join(FRAMEWORK_DIR, "cores", "arduino", "stm32", "LL"),
|
||||
join(FRAMEWORK_DIR, "cores", "arduino", "stm32", "usb"),
|
||||
join(FRAMEWORK_DIR, "cores", "arduino", "stm32", "OpenAMP"),
|
||||
join(FRAMEWORK_DIR, "cores", "arduino", "stm32", "usb", "hid"),
|
||||
join(FRAMEWORK_DIR, "cores", "arduino", "stm32", "usb", "cdc"),
|
||||
join(FRAMEWORK_DIR, "system", "Drivers", series + "_HAL_Driver", "Inc"),
|
||||
join(FRAMEWORK_DIR, "system", "Drivers", series + "_HAL_Driver", "Src"),
|
||||
join(FRAMEWORK_DIR, "system", series),
|
||||
join(
|
||||
FRAMEWORK_DIR,
|
||||
"system",
|
||||
"Middlewares",
|
||||
"ST",
|
||||
"STM32_USB_Device_Library",
|
||||
"Core",
|
||||
"Inc",
|
||||
),
|
||||
join(
|
||||
FRAMEWORK_DIR,
|
||||
"system",
|
||||
"Middlewares",
|
||||
"ST",
|
||||
"STM32_USB_Device_Library",
|
||||
"Core",
|
||||
"Src",
|
||||
),
|
||||
join(FRAMEWORK_DIR, "system", "Middlewares", "OpenAMP"),
|
||||
join(
|
||||
FRAMEWORK_DIR,
|
||||
"system",
|
||||
"Middlewares",
|
||||
"OpenAMP",
|
||||
"open-amp",
|
||||
"lib",
|
||||
"include",
|
||||
),
|
||||
join(
|
||||
FRAMEWORK_DIR,
|
||||
"system",
|
||||
"Middlewares",
|
||||
"OpenAMP",
|
||||
"libmetal",
|
||||
"lib",
|
||||
"include",
|
||||
),
|
||||
join(FRAMEWORK_DIR, "system", "Middlewares", "OpenAMP", "virtual_driver"),
|
||||
join(CMSIS_DIR, "Core", "Include"),
|
||||
join(
|
||||
FRAMEWORK_DIR,
|
||||
"system",
|
||||
"Drivers",
|
||||
"CMSIS",
|
||||
"Device",
|
||||
"ST",
|
||||
series,
|
||||
"Include",
|
||||
),
|
||||
join(
|
||||
FRAMEWORK_DIR,
|
||||
"system",
|
||||
"Drivers",
|
||||
"CMSIS",
|
||||
"Device",
|
||||
"ST",
|
||||
series,
|
||||
"Source",
|
||||
"Templates",
|
||||
"gcc",
|
||||
),
|
||||
join(CMSIS_DIR, "DSP", "Include"),
|
||||
join(CMSIS_DIR, "DSP", "PrivateInclude"),
|
||||
join(FRAMEWORK_DIR, "cores", "arduino"),
|
||||
],
|
||||
LINKFLAGS=machine_flags + [
|
||||
"-Os",
|
||||
"--specs=nano.specs",
|
||||
"-Wl,--gc-sections,--relax",
|
||||
"-Wl,--check-sections",
|
||||
"-Wl,--entry=Reset_Handler",
|
||||
"-Wl,--unresolved-symbols=report-all",
|
||||
"-Wl,--warn-common",
|
||||
"-Wl,--defsym=LD_MAX_SIZE=%d" % board_config.get("upload.maximum_size"),
|
||||
"-Wl,--defsym=LD_MAX_DATA_SIZE=%d"
|
||||
% board_config.get("upload.maximum_ram_size"),
|
||||
],
|
||||
LIBS=[
|
||||
get_arm_math_lib(board_config.get("build.cpu")),
|
||||
"c",
|
||||
"m",
|
||||
"gcc",
|
||||
"stdc++",
|
||||
],
|
||||
LIBPATH=[join(CMSIS_DIR, "DSP", "Lib", "GCC")],
|
||||
)
|
||||
|
||||
env.ProcessFlags(board_config.get("build.framework_extra_flags.arduino", ""))
|
||||
|
||||
configure_application_offset(mcu, upload_protocol)
|
||||
|
||||
#
|
||||
# Linker requires preprocessing with correct RAM|ROM sizes
|
||||
#
|
||||
|
||||
if not board_config.get("build.ldscript", ""):
|
||||
env.Replace(LDSCRIPT_PATH=join(FRAMEWORK_DIR, "system", "ldscript.ld"))
|
||||
if not isfile(join(env.subst(variant_dir), "ldscript.ld")):
|
||||
print("Warning! Cannot find linker script for the current target!\n")
|
||||
env.Append(
|
||||
LINKFLAGS=[
|
||||
(
|
||||
"-Wl,--default-script",
|
||||
join(
|
||||
inc_variant_dir,
|
||||
board_config.get("build.arduino.ldscript", "ldscript.ld"),
|
||||
),
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
#
|
||||
# Process configuration flags
|
||||
#
|
||||
|
||||
cpp_defines = env.Flatten(env.get("CPPDEFINES", []))
|
||||
|
||||
process_standard_library_configuration(cpp_defines)
|
||||
process_usb_configuration(cpp_defines)
|
||||
process_usb_speed_configuration(cpp_defines)
|
||||
process_usart_configuration(cpp_defines)
|
||||
|
||||
env.Append(
|
||||
LIBSOURCE_DIRS=[
|
||||
join(FRAMEWORK_DIR, "libraries", "__cores__", "arduino"),
|
||||
join(FRAMEWORK_DIR, "libraries"),
|
||||
]
|
||||
)
|
||||
|
||||
#
|
||||
# Target: Build Core Library
|
||||
#
|
||||
|
||||
libs = []
|
||||
|
||||
if "build.variant" in board_config:
|
||||
env.Append(CPPPATH=[inc_variant_dir], LIBPATH=[inc_variant_dir])
|
||||
env.BuildSources(join("$BUILD_DIR", "FrameworkArduinoVariant"), variant_dir)
|
||||
|
||||
libs.append(
|
||||
env.BuildLibrary(
|
||||
join("$BUILD_DIR", "FrameworkArduino"), join(FRAMEWORK_DIR, "cores", "arduino")
|
||||
)
|
||||
)
|
||||
|
||||
env.BuildSources(
|
||||
join("$BUILD_DIR", "SrcWrapper"), join(FRAMEWORK_DIR, "libraries", "SrcWrapper")
|
||||
)
|
||||
|
||||
env.Prepend(LIBS=libs)
|
||||
Reference in New Issue
Block a user