diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 2c82c7d4..9a88ae2b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -25,6 +25,7 @@ applications/sd-filesystem/** @skotopes @DrZlo13 applications/subghz/** @skotopes @DrZlo13 applications/template/** @skotopes @DrZlo13 applications/tests/** @skotopes @DrZlo13 +applications/updater/** @skotopes @DrZlo13 @hedger # Assets and asset generator assets/** @skotopes @DrZlo13 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d4a2e97e..9e5f3c72 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,7 +42,7 @@ jobs: run: | test -d artifacts && rm -rf artifacts || true mkdir artifacts - + - name: 'Generate suffix and folder name' id: names run: | @@ -52,13 +52,13 @@ jobs: fi BRANCH_OR_TAG=${REF#refs/*/} SHA=$(git rev-parse --short HEAD) - + if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then SUFFIX=${BRANCH_OR_TAG//\//_} else SUFFIX=${BRANCH_OR_TAG//\//_}-$(date +'%d%m%Y')-${SHA} fi - + echo "WORKFLOW_BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV echo "DIST_SUFFIX=${SUFFIX}" >> $GITHUB_ENV echo "::set-output name=artifacts-path::${BRANCH_OR_TAG}" @@ -86,7 +86,7 @@ jobs: set -e for TARGET in ${TARGETS} do - make TARGET=${TARGET} ${{ startsWith(github.ref, 'refs/tags') && 'DEBUG=0 COMPACT=1' || '' }} + make updater_package TARGET=${TARGET} ${{ startsWith(github.ref, 'refs/tags') && 'DEBUG=0 COMPACT=1' || '' }} done - name: 'Move upload files' @@ -100,6 +100,17 @@ jobs: mv dist/${TARGET}/* artifacts/ done + - name: 'Bundle self-update package' + if: ${{ !github.event.pull_request.head.repo.fork }} + run: | + set -e + for UPDATEBUNDLE in artifacts/*/ + do + BUNDLE_NAME=`echo $UPDATEBUNDLE | cut -d'/' -f2` + echo Packaging ${BUNDLE_NAME} + tar czpf artifacts/flipper-z-${BUNDLE_NAME}.tgz -C artifacts ${BUNDLE_NAME} + done + - name: 'Bundle resources' if: ${{ !github.event.pull_request.head.repo.fork }} run: | @@ -175,7 +186,7 @@ jobs: - name: 'Build docker image' uses: ./.github/actions/docker - + - name: 'Generate suffix and folder name' id: names run: | @@ -185,13 +196,13 @@ jobs: fi BRANCH_OR_TAG=${REF#refs/*/} SHA=$(git rev-parse --short HEAD) - + if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then SUFFIX=${BRANCH_OR_TAG//\//_} else SUFFIX=${BRANCH_OR_TAG//\//_}-$(date +'%d%m%Y')-${SHA} fi - + echo "WORKFLOW_BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV echo "DIST_SUFFIX=${SUFFIX}" >> $GITHUB_ENV diff --git a/.gitmodules b/.gitmodules index a16101ad..c4649fdc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,6 @@ [submodule "lib/FreeRTOS-Kernel"] path = lib/FreeRTOS-Kernel url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git +[submodule "lib/microtar"] + path = lib/microtar + url = https://github.com/amachronic/microtar.git diff --git a/Makefile b/Makefile index cd448e2e..02008033 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,16 @@ PROJECT_ROOT := $(abspath $(dir $(abspath $(firstword $(MAKEFILE_LIST))))) + +include $(PROJECT_ROOT)/make/git.mk + COPRO_DIR := $(PROJECT_ROOT)/lib/STM32CubeWB/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x PROJECT_SOURCE_DIRECTORIES := \ $(PROJECT_ROOT)/applications \ - $(PROJECT_ROOT)/bootloader/src \ - $(PROJECT_ROOT)/bootloader/targets \ $(PROJECT_ROOT)/core \ $(PROJECT_ROOT)/firmware/targets \ $(PROJECT_ROOT)/lib/app-template \ $(PROJECT_ROOT)/lib/app-scened-template \ $(PROJECT_ROOT)/lib/common-api \ - $(PROJECT_ROOT)/lib/cyfral \ $(PROJECT_ROOT)/lib/drivers \ $(PROJECT_ROOT)/lib/flipper_file \ $(PROJECT_ROOT)/lib/infrared \ @@ -34,18 +34,18 @@ endif include $(PROJECT_ROOT)/make/defaults.mk .PHONY: all -all: bootloader_all firmware_all - @$(PROJECT_ROOT)/scripts/dist.sh +all: firmware_all + @$(PROJECT_ROOT)/scripts/dist.py copy -t $(TARGET) -p firmware -s $(DIST_SUFFIX) .PHONY: whole -whole: flash_radio bootloader_flash firmware_flash +whole: flash_radio firmware_flash .PHONY: clean -clean: bootloader_clean firmware_clean +clean: firmware_clean updater_clean @rm -rf $(PROJECT_ROOT)/dist/$(TARGET) .PHONY: flash -flash: bootloader_flash firmware_flash +flash: firmware_flash .PHONY: debug debug: @@ -60,36 +60,38 @@ wipe: @$(PROJECT_ROOT)/scripts/flash.py wipe @$(PROJECT_ROOT)/scripts/ob.py set -.PHONY: bootloader_all -bootloader_all: - @$(MAKE) -C $(PROJECT_ROOT)/bootloader -j$(NPROCS) all - .PHONY: firmware_all firmware_all: @$(MAKE) -C $(PROJECT_ROOT)/firmware -j$(NPROCS) all -.PHONY: bootloader_clean -bootloader_clean: - @$(MAKE) -C $(PROJECT_ROOT)/bootloader -j$(NPROCS) clean - .PHONY: firmware_clean firmware_clean: @$(MAKE) -C $(PROJECT_ROOT)/firmware -j$(NPROCS) clean -.PHONY: bootloader_flash -bootloader_flash: -ifeq ($(FORCE), 1) - @rm $(PROJECT_ROOT)/bootloader/.obj/f*/flash || true -endif - @$(MAKE) -C $(PROJECT_ROOT)/bootloader -j$(NPROCS) flash - .PHONY: firmware_flash firmware_flash: ifeq ($(FORCE), 1) - @rm $(PROJECT_ROOT)/firmware/.obj/f*/flash || true + @rm $(PROJECT_ROOT)/firmware/.obj/f*-firmware/flash || true endif @$(MAKE) -C $(PROJECT_ROOT)/firmware -j$(NPROCS) flash + +.PHONY: updater +updater: + @$(MAKE) -C $(PROJECT_ROOT)/firmware -j$(NPROCS) RAM_EXEC=1 all + +.PHONY: updater_clean +updater_clean: + @$(MAKE) -C $(PROJECT_ROOT)/firmware -j$(NPROCS) RAM_EXEC=1 clean + +.PHONY: updater_debug +updater_debug: + @$(MAKE) -C $(PROJECT_ROOT)/firmware -j$(NPROCS) RAM_EXEC=1 debug + +.PHONY: updater_package +updater_package: firmware_all updater + @$(PROJECT_ROOT)/scripts/dist.py copy -t $(TARGET) -p firmware updater -s $(DIST_SUFFIX) --bundlever "$(VERSION_STRING)" + .PHONY: flash_radio flash_radio: @$(PROJECT_ROOT)/scripts/flash.py core2radio 0x080D7000 $(COPRO_DIR)/stm32wb5x_BLE_Stack_light_fw.bin @@ -100,7 +102,7 @@ flash_radio_fus: @echo @echo "================ DON'T DO IT ================" @echo "= Flashing FUS is going to erase secure enclave =" - @echo "= You will loose ability to use encrypted assets =" + @echo "= You will lose ability to use encrypted assets =" @echo "= type 'find / -exec rm -rf {} \;' =" @echo "= In case if you still want to continue =" @echo "================ JUST DON'T ================" diff --git a/ReadMe.md b/ReadMe.md index 940e6051..9a355eba 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -11,17 +11,16 @@ Our goal is to create nice and clean code with good documentation, to make it a [Get Latest Firmware from Update Server](https://update.flipperzero.one/) -Flipper Zero's firmware consists of three components: +Flipper Zero's firmware consists of two components: - Core2 firmware set - proprietary components by ST: FUS + radio stack. FUS is flashed at factory and you should never update it. -- Core1 Bootloader - controls basic hardware initialization and loads firmware. - Core1 Firmware - HAL + OS + Drivers + Applications. All 3 of them must be flashed in order described. ## With STLink -### Core1 Bootloader + Firmware +### Core1 Firmware Prerequisites: @@ -144,7 +143,6 @@ make whole - `applications` - Applications and services used in firmware - `assets` - Assets used by applications and services -- `bootloader` - Bootloader source code - `core` - Furi Core: os level primitives and helpers - `debug` - Debug tool: GDB-plugins, SVD-file and etc - `docker` - Docker image sources (used for firmware build automation) diff --git a/applications/ReadMe.md b/applications/ReadMe.md index 4c7066ee..2c78dfa2 100644 --- a/applications/ReadMe.md +++ b/applications/ReadMe.md @@ -34,6 +34,7 @@ - `system` - System settings, tools and API - `tests` - Unit tests and etc - `u2f` - U2F Application +- `updater` - Update service & application - `application.c` - Firmware application list source - `application.h` - Firmware application list header diff --git a/applications/about/about.c b/applications/about/about.c index 22b8a3a3..bda50a4b 100644 --- a/applications/about/about.c +++ b/applications/about/about.c @@ -116,9 +116,10 @@ static DialogMessageButton fw_version_screen(DialogsApp* dialogs, DialogMessage* } else { string_cat_printf( buffer, - "%s [%s]\n%s [%s]\n[%d] %s", + "%s [%s]\n%s%s [%s]\n[%d] %s", version_get_version(ver), version_get_builddate(ver), + version_get_dirty_flag(ver) ? "[!] " : "", version_get_githash(ver), version_get_gitbranchnum(ver), version_get_target(ver), @@ -135,36 +136,6 @@ static DialogMessageButton fw_version_screen(DialogsApp* dialogs, DialogMessage* return result; } -static DialogMessageButton bootloader_version_screen(DialogsApp* dialogs, DialogMessage* message) { - DialogMessageButton result; - string_t buffer; - string_init(buffer); - const Version* ver = furi_hal_version_get_bootloader_version(); - - if(!ver) { - string_cat_printf(buffer, "No info\n"); - } else { - string_cat_printf( - buffer, - "%s [%s]\n%s [%s]\n[%d] %s", - version_get_version(ver), - version_get_builddate(ver), - version_get_githash(ver), - version_get_gitbranchnum(ver), - version_get_target(ver), - version_get_gitbranch(ver)); - } - - dialog_message_set_header(message, "Boot Version info:", 0, 0, AlignLeft, AlignTop); - dialog_message_set_text(message, string_get_cstr(buffer), 0, 13, AlignLeft, AlignTop); - result = dialog_message_show(dialogs, message); - dialog_message_set_text(message, NULL, 0, 0, AlignLeft, AlignTop); - dialog_message_set_header(message, NULL, 0, 0, AlignLeft, AlignTop); - string_clear(buffer); - - return result; -} - const AboutDialogScreen about_screens[] = { product_screen, compliance_screen, @@ -172,8 +143,7 @@ const AboutDialogScreen about_screens[] = { icon1_screen, icon2_screen, hw_version_screen, - fw_version_screen, - bootloader_version_screen}; + fw_version_screen}; const size_t about_screens_count = sizeof(about_screens) / sizeof(AboutDialogScreen); diff --git a/applications/applications.c b/applications/applications.c index 24279d82..d5e7efd7 100644 --- a/applications/applications.c +++ b/applications/applications.c @@ -14,6 +14,7 @@ extern int32_t notification_srv(void* p); extern int32_t power_srv(void* p); extern int32_t storage_srv(void* p); extern int32_t desktop_srv(void* p); +extern int32_t updater_srv(void* p); // Apps extern int32_t accessor_app(void* p); @@ -58,6 +59,7 @@ extern void storage_on_system_start(); extern void subghz_on_system_start(); extern void power_on_system_start(); extern void unit_tests_on_system_start(); +extern void updater_on_system_start(); // Settings extern int32_t notification_settings_app(void* p); @@ -91,6 +93,9 @@ const FlipperApplication FLIPPER_SERVICES[] = { #endif #ifdef SRV_DESKTOP +#ifdef SRV_UPDATER +#error SRV_UPDATER and SRV_DESKTOP are mutually exclusive! +#endif {.app = desktop_srv, .name = "DesktopSrv", .stack_size = 2048, .icon = NULL}, #endif @@ -117,10 +122,28 @@ const FlipperApplication FLIPPER_SERVICES[] = { #ifdef SRV_STORAGE {.app = storage_srv, .name = "StorageSrv", .stack_size = 3072, .icon = NULL}, #endif + +#ifdef SRV_UPDATER +#ifdef SRV_DESKTOP +#error SRV_UPDATER and SRV_DESKTOP are mutually exclusive! +#endif + {.app = updater_srv, .name = "UpdaterSrv", .stack_size = 2048, .icon = NULL}, +#endif }; const size_t FLIPPER_SERVICES_COUNT = sizeof(FLIPPER_SERVICES) / sizeof(FlipperApplication); +const FlipperApplication FLIPPER_SYSTEM_APPS[] = { +#ifdef APP_UPDATER +#ifdef SRV_UPDATER +#error APP_UPDATER and SRV_UPDATER are mutually exclusive! +#endif + {.app = updater_srv, .name = "UpdaterApp", .stack_size = 2048, .icon = NULL}, +#endif +}; + +const size_t FLIPPER_SYSTEM_APPS_COUNT = sizeof(FLIPPER_SERVICES) / sizeof(FlipperApplication); + // Main menu APP const FlipperApplication FLIPPER_APPS[] = { @@ -199,6 +222,10 @@ const FlipperOnStartHook FLIPPER_ON_SYSTEM_START[] = { #ifdef APP_UNIT_TESTS unit_tests_on_system_start, #endif + +#ifdef APP_UPDATER + updater_on_system_start, +#endif }; const size_t FLIPPER_ON_SYSTEM_START_COUNT = @@ -326,4 +353,4 @@ const FlipperApplication FLIPPER_SETTINGS_APPS[] = { }; const size_t FLIPPER_SETTINGS_APPS_COUNT = - sizeof(FLIPPER_SETTINGS_APPS) / sizeof(FlipperApplication); + sizeof(FLIPPER_SETTINGS_APPS) / sizeof(FlipperApplication); \ No newline at end of file diff --git a/applications/applications.h b/applications/applications.h index 962eaa77..705dba28 100644 --- a/applications/applications.h +++ b/applications/applications.h @@ -42,6 +42,12 @@ extern const size_t FLIPPER_PLUGINS_COUNT; extern const FlipperApplication FLIPPER_DEBUG_APPS[]; extern const size_t FLIPPER_DEBUG_APPS_COUNT; +/* System apps + * Can only be spawned by loader by name + */ +extern const FlipperApplication FLIPPER_SYSTEM_APPS[]; +extern const size_t FLIPPER_SYSTEM_APPS_COUNT; + /* Seperate scene app holder * Spawned by loader */ @@ -55,4 +61,4 @@ extern const FlipperApplication FLIPPER_ARCHIVE; * Spawned by loader */ extern const FlipperApplication FLIPPER_SETTINGS_APPS[]; -extern const size_t FLIPPER_SETTINGS_APPS_COUNT; \ No newline at end of file +extern const size_t FLIPPER_SETTINGS_APPS_COUNT; diff --git a/applications/applications.mk b/applications/applications.mk index 954ec647..c6295fd8 100644 --- a/applications/applications.mk +++ b/applications/applications.mk @@ -5,6 +5,16 @@ CFLAGS += -I$(APP_DIR) C_SOURCES += $(shell find $(APP_DIR) -name "*.c") CPP_SOURCES += $(shell find $(APP_DIR) -name "*.cpp") +RAM_EXEC ?= 0 +ifeq ($(RAM_EXEC), 1) +APP_RELEASE = 0 +SRV_GUI = 1 +SRV_INPUT = 1 +SRV_NOTIFICATION = 1 +SRV_STORAGE = 1 +SRV_UPDATER = 1 +APP_UPDATER = 0 +endif APP_RELEASE ?= 1 ifeq ($(APP_RELEASE), 1) @@ -18,13 +28,13 @@ SRV_INPUT = 1 SRV_LOADER = 1 SRV_NOTIFICATION = 1 SRV_POWER = 1 -SRV_RPC = 1 +SRV_RPC = 1 SRV_STORAGE = 1 # Apps SRV_DESKTOP = 1 APP_ARCHIVE = 1 -APP_GPIO = 1 +APP_GPIO = 1 APP_IBUTTON = 1 APP_INFRARED = 1 APP_LF_RFID = 1 @@ -32,6 +42,7 @@ APP_NFC = 1 APP_SUBGHZ = 1 APP_ABOUT = 1 APP_PASSPORT = 1 +APP_UPDATER = 1 # Plugins APP_MUSIC_PLAYER = 1 @@ -223,6 +234,14 @@ CFLAGS += -DAPP_IBUTTON SRV_GUI = 1 endif +APP_UPDATER ?= 0 +ifeq ($(APP_UPDATER), 1) +CFLAGS += -DAPP_UPDATER +SRV_GUI = 1 +SRV_STORAGE = 1 +SRV_NOTIFICATION = 1 +SRV_INPUT = 1 +endif # Services # that will start with OS @@ -245,6 +264,14 @@ SRV_GUI = 1 endif +SRV_UPDATER ?= 0 +ifeq ($(SRV_UPDATER), 1) +CFLAGS += -DSRV_UPDATER +SRV_STORAGE = 1 +SRV_GUI = 1 +endif + + SRV_DOLPHIN ?= 0 ifeq ($(SRV_DOLPHIN), 1) CFLAGS += -DSRV_DOLPHIN diff --git a/applications/archive/helpers/archive_browser.h b/applications/archive/helpers/archive_browser.h index 968564cd..593a9be0 100644 --- a/applications/archive/helpers/archive_browser.h +++ b/applications/archive/helpers/archive_browser.h @@ -25,6 +25,7 @@ static const char* known_ext[] = { [ArchiveFileTypeInfrared] = ".ir", [ArchiveFileTypeBadUsb] = ".txt", [ArchiveFileTypeU2f] = "?", + [ArchiveFileTypeUpdateManifest] = ".fuf", [ArchiveFileTypeFolder] = "?", [ArchiveFileTypeUnknown] = "*", }; diff --git a/applications/archive/helpers/archive_files.h b/applications/archive/helpers/archive_files.h index e6f6eaa1..b65f96ae 100644 --- a/applications/archive/helpers/archive_files.h +++ b/applications/archive/helpers/archive_files.h @@ -10,6 +10,7 @@ typedef enum { ArchiveFileTypeInfrared, ArchiveFileTypeBadUsb, ArchiveFileTypeU2f, + ArchiveFileTypeUpdateManifest, ArchiveFileTypeFolder, ArchiveFileTypeUnknown, ArchiveFileTypeLoading, diff --git a/applications/archive/scenes/archive_scene_browser.c b/applications/archive/scenes/archive_scene_browser.c index 9410062d..92a49304 100644 --- a/applications/archive/scenes/archive_scene_browser.c +++ b/applications/archive/scenes/archive_scene_browser.c @@ -15,6 +15,7 @@ static const char* flipper_app_name[] = { [ArchiveFileTypeInfrared] = "Infrared", [ArchiveFileTypeBadUsb] = "Bad USB", [ArchiveFileTypeU2f] = "U2F", + [ArchiveFileTypeUpdateManifest] = "UpdaterApp", }; static void archive_run_in_app(ArchiveBrowserView* browser, ArchiveFile_t* selected) { diff --git a/applications/archive/views/archive_browser_view.c b/applications/archive/views/archive_browser_view.c index cd63c4d7..34588f33 100644 --- a/applications/archive/views/archive_browser_view.c +++ b/applications/archive/views/archive_browser_view.c @@ -12,7 +12,8 @@ static const char* ArchiveTabNames[] = { [ArchiveTabInfrared] = "Infrared", [ArchiveTabBadUsb] = "Bad USB", [ArchiveTabU2f] = "U2F", - [ArchiveTabBrowser] = "Browser"}; + [ArchiveTabBrowser] = "Browser", +}; static const Icon* ArchiveItemIcons[] = { [ArchiveFileTypeIButton] = &I_ibutt_10px, @@ -22,6 +23,7 @@ static const Icon* ArchiveItemIcons[] = { [ArchiveFileTypeInfrared] = &I_ir_10px, [ArchiveFileTypeBadUsb] = &I_badusb_10px, [ArchiveFileTypeU2f] = &I_u2f_10px, + [ArchiveFileTypeUpdateManifest] = &I_update_10px, [ArchiveFileTypeFolder] = &I_dir_10px, [ArchiveFileTypeUnknown] = &I_unknown_10px, [ArchiveFileTypeLoading] = &I_unknown_10px, // TODO loading icon @@ -374,4 +376,4 @@ void browser_free(ArchiveBrowserView* browser) { view_free(browser->view); free(browser); -} +} \ No newline at end of file diff --git a/applications/bt/bt_cli.c b/applications/bt/bt_cli.c index 50b5c225..2469e74e 100644 --- a/applications/bt/bt_cli.c +++ b/applications/bt/bt_cli.c @@ -244,5 +244,7 @@ void bt_on_system_start() { cli_add_command(cli, "bt", CliCommandFlagDefault, bt_cli, NULL); furi_record_close("bt"); furi_record_close("cli"); +#else + UNUSED(bt_cli); #endif -} +} \ No newline at end of file diff --git a/applications/cli/cli.c b/applications/cli/cli.c index 4b36521b..0453fb66 100644 --- a/applications/cli/cli.c +++ b/applications/cli/cli.c @@ -95,10 +95,11 @@ void cli_motd() { const Version* firmware_version = furi_hal_version_get_firmware_version(); if(firmware_version) { printf( - "Firmware version: %s %s (%s built on %s)\r\n", + "Firmware version: %s %s (%s%s built on %s)\r\n", version_get_gitbranch(firmware_version), version_get_version(firmware_version), version_get_githash(firmware_version), + version_get_dirty_flag(firmware_version) ? "-dirty" : "", version_get_builddate(firmware_version)); } } diff --git a/applications/cli/cli_commands.c b/applications/cli/cli_commands.c index 53595a08..58c13160 100644 --- a/applications/cli/cli_commands.c +++ b/applications/cli/cli_commands.c @@ -327,6 +327,7 @@ void cli_command_ps(Cli* cli, string_t args, void* context) { void cli_command_free(Cli* cli, string_t args, void* context) { printf("Free heap size: %d\r\n", memmgr_get_free_heap()); + printf("Total heap size: %d\r\n", memmgr_get_total_heap()); printf("Minimum heap size: %d\r\n", memmgr_get_minimum_free_heap()); printf("Maximum heap block: %d\r\n", memmgr_heap_get_max_free_block()); } diff --git a/applications/crypto/crypto_cli.c b/applications/crypto/crypto_cli.c index 60e32b2b..7cd9d5cc 100644 --- a/applications/crypto/crypto_cli.c +++ b/applications/crypto/crypto_cli.c @@ -276,7 +276,7 @@ void crypto_cli_store_key(Cli* cli, string_t args) { string_clear(key_type); } -void crypto_cli(Cli* cli, string_t args, void* context) { +static void crypto_cli(Cli* cli, string_t args, void* context) { string_t cmd; string_init(cmd); @@ -317,5 +317,7 @@ void crypto_on_system_start() { Cli* cli = furi_record_open("cli"); cli_add_command(cli, "crypto", CliCommandFlagDefault, crypto_cli, NULL); furi_record_close("cli"); +#else + UNUSED(crypto_cli); #endif } diff --git a/applications/desktop/views/desktop_view_debug.c b/applications/desktop/views/desktop_view_debug.c index 4cb8e8ea..0aed2adf 100644 --- a/applications/desktop/views/desktop_view_debug.c +++ b/applications/desktop/views/desktop_view_debug.c @@ -23,7 +23,7 @@ void desktop_debug_render(Canvas* canvas, void* model) { const Version* ver; char buffer[64]; - static const char* headers[] = {"FW Version info:", "Boot Version info:", "Dolphin info:"}; + static const char* headers[] = {"FW Version info:", "Dolphin info:"}; canvas_set_color(canvas, ColorBlack); canvas_set_font(canvas, FontPrimary); @@ -44,8 +44,7 @@ void desktop_debug_render(Canvas* canvas, void* model) { my_name ? my_name : "Unknown"); canvas_draw_str(canvas, 5, 19 + STATUS_BAR_Y_SHIFT, buffer); - ver = m->screen == DesktopViewStatsBoot ? furi_hal_version_get_bootloader_version() : - furi_hal_version_get_firmware_version(); + ver = furi_hal_version_get_firmware_version(); if(!ver) { canvas_draw_str(canvas, 5, 29 + STATUS_BAR_Y_SHIFT, "No info"); @@ -63,7 +62,8 @@ void desktop_debug_render(Canvas* canvas, void* model) { snprintf( buffer, sizeof(buffer), - "%s [%s]", + "%s%s [%s]", + version_get_dirty_flag(ver) ? "[!] " : "", version_get_githash(ver), version_get_gitbranchnum(ver)); canvas_draw_str(canvas, 5, 39 + STATUS_BAR_Y_SHIFT, buffer); diff --git a/applications/desktop/views/desktop_view_debug.h b/applications/desktop/views/desktop_view_debug.h index fecbb2aa..f6af16b2 100644 --- a/applications/desktop/views/desktop_view_debug.h +++ b/applications/desktop/views/desktop_view_debug.h @@ -11,7 +11,6 @@ typedef void (*DesktopDebugViewCallback)(DesktopEvent event, void* context); // Debug info typedef enum { DesktopViewStatsFw, - DesktopViewStatsBoot, DesktopViewStatsMeta, DesktopViewStatsTotalCount, } DesktopViewStatsScreens; diff --git a/applications/gui/elements.c b/applications/gui/elements.c index 4fbafbd5..289e4d8e 100644 --- a/applications/gui/elements.c +++ b/applications/gui/elements.c @@ -739,4 +739,4 @@ void elements_text_box( } } canvas_set_font(canvas, FontSecondary); -} +} \ No newline at end of file diff --git a/applications/ibutton/ibutton_cli.c b/applications/ibutton/ibutton_cli.c index 243ee36b..c50ec210 100644 --- a/applications/ibutton/ibutton_cli.c +++ b/applications/ibutton/ibutton_cli.c @@ -6,8 +6,8 @@ #include #include -void ibutton_cli(Cli* cli, string_t args, void* context); -void onewire_cli(Cli* cli, string_t args, void* context); +static void ibutton_cli(Cli* cli, string_t args, void* context); +static void onewire_cli(Cli* cli, string_t args, void* context); // app cli function void ibutton_on_system_start() { @@ -16,6 +16,9 @@ void ibutton_on_system_start() { cli_add_command(cli, "ikey", CliCommandFlagDefault, ibutton_cli, cli); cli_add_command(cli, "onewire", CliCommandFlagDefault, onewire_cli, cli); furi_record_close("cli"); +#else + UNUSED(ibutton_cli); + UNUSED(onewire_cli); #endif } @@ -236,7 +239,7 @@ void ibutton_cli_emulate(Cli* cli, string_t args) { ibutton_key_free(key); }; -void ibutton_cli(Cli* cli, string_t args, void* context) { +static void ibutton_cli(Cli* cli, string_t args, void* context) { string_t cmd; string_init(cmd); @@ -264,7 +267,7 @@ void onewire_cli_print_usage() { printf("onewire search\r\n"); }; -void onewire_cli_search(Cli* cli) { +static void onewire_cli_search(Cli* cli) { OneWireHost* onewire = onewire_host_alloc(); uint8_t address[8]; bool done = false; @@ -308,4 +311,4 @@ void onewire_cli(Cli* cli, string_t args, void* context) { } string_clear(cmd); -} +} \ No newline at end of file diff --git a/applications/infrared/cli/infrared_cli.cpp b/applications/infrared/cli/infrared_cli.cpp index 8cda0cd7..15de2d85 100644 --- a/applications/infrared/cli/infrared_cli.cpp +++ b/applications/infrared/cli/infrared_cli.cpp @@ -192,5 +192,7 @@ extern "C" void infrared_on_system_start() { Cli* cli = (Cli*)furi_record_open("cli"); cli_add_command(cli, "ir", CliCommandFlagDefault, infrared_cli_start_ir, NULL); furi_record_close("cli"); +#else + UNUSED(infrared_cli_start_ir); #endif } diff --git a/applications/infrared/infrared_app_remote_manager.cpp b/applications/infrared/infrared_app_remote_manager.cpp index b2637ccb..9fbef84f 100644 --- a/applications/infrared/infrared_app_remote_manager.cpp +++ b/applications/infrared/infrared_app_remote_manager.cpp @@ -13,7 +13,7 @@ #include #include "infrared_app.h" -static const std::string default_remote_name = "remote"; +static const char* default_remote_name = "remote"; std::string InfraredAppRemoteManager::make_full_name( const std::string& path, diff --git a/applications/input/input_cli.c b/applications/input/input_cli.c index c244ece5..eb510f6c 100644 --- a/applications/input/input_cli.c +++ b/applications/input/input_cli.c @@ -50,7 +50,7 @@ static void input_cli_send_print_usage() { printf("\t\t \t - one of 'press', 'release', 'short', 'long'\r\n"); } -void input_cli_send(Cli* cli, string_t args, Input* input) { +static void input_cli_send(Cli* cli, string_t args, Input* input) { InputEvent event; string_t key_str; string_init(key_str); diff --git a/applications/lfrfid/lfrfid_cli.cpp b/applications/lfrfid/lfrfid_cli.cpp index 18784876..235dd68f 100644 --- a/applications/lfrfid/lfrfid_cli.cpp +++ b/applications/lfrfid/lfrfid_cli.cpp @@ -7,7 +7,7 @@ #include "helpers/rfid_reader.h" #include "helpers/rfid_timer_emulator.h" -void lfrfid_cli(Cli* cli, string_t args, void* context); +static void lfrfid_cli(Cli* cli, string_t args, void* context); // app cli function extern "C" void lfrfid_on_system_start() { @@ -15,6 +15,8 @@ extern "C" void lfrfid_on_system_start() { Cli* cli = static_cast(furi_record_open("cli")); cli_add_command(cli, "rfid", CliCommandFlagDefault, lfrfid_cli, NULL); furi_record_close("cli"); +#else + UNUSED(lfrfid_cli); #endif } @@ -29,7 +31,7 @@ void lfrfid_cli_print_usage() { printf("\t are hex-formatted\r\n"); }; -bool lfrfid_cli_get_key_type(string_t data, LfrfidKeyType* type) { +static bool lfrfid_cli_get_key_type(string_t data, LfrfidKeyType* type) { bool result = false; if(string_cmp_str(data, "EM4100") == 0 || string_cmp_str(data, "EM-Marin") == 0) { @@ -46,7 +48,7 @@ bool lfrfid_cli_get_key_type(string_t data, LfrfidKeyType* type) { return result; } -void lfrfid_cli_read(Cli* cli, string_t args) { +static void lfrfid_cli_read(Cli* cli, string_t args) { RfidReader reader; string_t type_string; string_init(type_string); @@ -97,12 +99,12 @@ void lfrfid_cli_read(Cli* cli, string_t args) { string_clear(type_string); } -void lfrfid_cli_write(Cli* cli, string_t args) { +static void lfrfid_cli_write(Cli* cli, string_t args) { // TODO implement rfid write printf("Not implemented :(\r\n"); } -void lfrfid_cli_emulate(Cli* cli, string_t args) { +static void lfrfid_cli_emulate(Cli* cli, string_t args) { string_t data; string_init(data); RfidTimerEmulator emulator; @@ -144,7 +146,7 @@ void lfrfid_cli_emulate(Cli* cli, string_t args) { string_clear(data); } -void lfrfid_cli(Cli* cli, string_t args, void* context) { +static void lfrfid_cli(Cli* cli, string_t args, void* context) { string_t cmd; string_init(cmd); diff --git a/applications/loader/loader.c b/applications/loader/loader.c index d35fcf64..054562a2 100644 --- a/applications/loader/loader.c +++ b/applications/loader/loader.c @@ -65,33 +65,36 @@ static void loader_cli_print_usage() { printf("\topen \t - Open application by name\r\n"); } +static FlipperApplication const* loader_find_application_by_name_in_list( + const char* name, + const FlipperApplication* list, + const uint32_t n_apps) { + for(size_t i = 0; i < n_apps; i++) { + if(strcmp(name, list[i].name) == 0) { + return &list[i]; + } + } + return NULL; +} + const FlipperApplication* loader_find_application_by_name(const char* name) { const FlipperApplication* application = NULL; - - for(size_t i = 0; i < FLIPPER_APPS_COUNT; i++) { - if(strcmp(name, FLIPPER_APPS[i].name) == 0) { - application = &FLIPPER_APPS[i]; - } + application = loader_find_application_by_name_in_list(name, FLIPPER_APPS, FLIPPER_APPS_COUNT); + if(!application) { + application = + loader_find_application_by_name_in_list(name, FLIPPER_PLUGINS, FLIPPER_PLUGINS_COUNT); } - - for(size_t i = 0; i < FLIPPER_PLUGINS_COUNT; i++) { - if(strcmp(name, FLIPPER_PLUGINS[i].name) == 0) { - application = &FLIPPER_PLUGINS[i]; - } + if(!application) { + application = loader_find_application_by_name_in_list( + name, FLIPPER_SETTINGS_APPS, FLIPPER_SETTINGS_APPS_COUNT); } - - for(size_t i = 0; i < FLIPPER_SETTINGS_APPS_COUNT; i++) { - if(strcmp(name, FLIPPER_SETTINGS_APPS[i].name) == 0) { - application = &FLIPPER_SETTINGS_APPS[i]; - } + if(!application) { + application = loader_find_application_by_name_in_list( + name, FLIPPER_SYSTEM_APPS, FLIPPER_SYSTEM_APPS_COUNT); } - - if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { - for(size_t i = 0; i < FLIPPER_DEBUG_APPS_COUNT; i++) { - if(strcmp(name, FLIPPER_DEBUG_APPS[i].name) == 0) { - application = &FLIPPER_DEBUG_APPS[i]; - } - } + if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) && !application) { + application = loader_find_application_by_name_in_list( + name, FLIPPER_DEBUG_APPS, FLIPPER_DEBUG_APPS_COUNT); } return application; @@ -149,7 +152,7 @@ void loader_cli_list(Cli* cli, string_t args, Loader* instance) { } } -void loader_cli(Cli* cli, string_t args, void* _ctx) { +static void loader_cli(Cli* cli, string_t args, void* _ctx) { furi_assert(_ctx); Loader* instance = _ctx; @@ -290,6 +293,8 @@ static Loader* loader_alloc() { #ifdef SRV_CLI instance->cli = furi_record_open("cli"); cli_add_command(instance->cli, "loader", CliCommandFlagDefault, loader_cli, instance); +#else + UNUSED(loader_cli); #endif instance->loader_thread = osThreadGetId(); @@ -483,4 +488,4 @@ int32_t loader_srv(void* p) { FuriPubSub* loader_get_pubsub(Loader* instance) { return instance->pubsub; -} +} \ No newline at end of file diff --git a/applications/nfc/nfc_cli.c b/applications/nfc/nfc_cli.c index 0dd212a6..98024e7d 100755 --- a/applications/nfc/nfc_cli.c +++ b/applications/nfc/nfc_cli.c @@ -136,5 +136,7 @@ void nfc_on_system_start() { Cli* cli = furi_record_open("cli"); cli_add_command(cli, "nfc", CliCommandFlagDefault, nfc_cli, NULL); furi_record_close("cli"); +#else + UNUSED(nfc_cli); #endif } diff --git a/applications/power/power_cli.c b/applications/power/power_cli.c index 110318ac..09e75fa9 100644 --- a/applications/power/power_cli.c +++ b/applications/power/power_cli.c @@ -128,5 +128,7 @@ void power_on_system_start() { cli_add_command(cli, "power", CliCommandFlagParallelSafe, power_cli, NULL); furi_record_close("cli"); +#else + UNUSED(power_cli); #endif } diff --git a/applications/power/power_service/power_api.c b/applications/power/power_service/power_api.c index a92bfd00..28c23fcf 100644 --- a/applications/power/power_service/power_api.c +++ b/applications/power/power_service/power_api.c @@ -1,8 +1,7 @@ #include "power_i.h" #include -#include "furi_hal_power.h" -#include "furi_hal_bootloader.h" +#include void power_off(Power* power) { furi_hal_power_off(); @@ -15,9 +14,9 @@ void power_off(Power* power) { void power_reboot(PowerBootMode mode) { if(mode == PowerBootModeNormal) { - furi_hal_bootloader_set_mode(FuriHalBootloaderModeNormal); + furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); } else if(mode == PowerBootModeDfu) { - furi_hal_bootloader_set_mode(FuriHalBootloaderModeDFU); + furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeDfu); } furi_hal_power_reset(); } diff --git a/applications/rpc/rpc_gui.c b/applications/rpc/rpc_gui.c index 84051bff..b67035ac 100644 --- a/applications/rpc/rpc_gui.c +++ b/applications/rpc/rpc_gui.c @@ -69,30 +69,34 @@ static void rpc_system_gui_start_screen_stream_process(const PB_Main* request, v RpcSession* session = rpc_gui->session; furi_assert(session); - furi_assert(!rpc_gui->is_streaming); - rpc_send_and_release_empty(session, request->command_id, PB_CommandStatus_OK); + if(rpc_gui->is_streaming) { + rpc_send_and_release_empty( + session, request->command_id, PB_CommandStatus_ERROR_VIRTUAL_DISPLAY_ALREADY_STARTED); + } else { + rpc_send_and_release_empty(session, request->command_id, PB_CommandStatus_OK); - rpc_gui->is_streaming = true; - size_t framebuffer_size = gui_get_framebuffer_size(rpc_gui->gui); - // Reusable Frame - rpc_gui->transmit_frame = malloc(sizeof(PB_Main)); - rpc_gui->transmit_frame->which_content = PB_Main_gui_screen_frame_tag; - rpc_gui->transmit_frame->command_status = PB_CommandStatus_OK; - rpc_gui->transmit_frame->content.gui_screen_frame.data = - malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(framebuffer_size)); - rpc_gui->transmit_frame->content.gui_screen_frame.data->size = framebuffer_size; - // Transmission thread for async TX - rpc_gui->transmit_thread = furi_thread_alloc(); - furi_thread_set_name(rpc_gui->transmit_thread, "GuiRpcWorker"); - furi_thread_set_callback( - rpc_gui->transmit_thread, rpc_system_gui_screen_stream_frame_transmit_thread); - furi_thread_set_context(rpc_gui->transmit_thread, rpc_gui); - furi_thread_set_stack_size(rpc_gui->transmit_thread, 1024); - furi_thread_start(rpc_gui->transmit_thread); - // GUI framebuffer callback - gui_add_framebuffer_callback( - rpc_gui->gui, rpc_system_gui_screen_stream_frame_callback, context); + rpc_gui->is_streaming = true; + size_t framebuffer_size = gui_get_framebuffer_size(rpc_gui->gui); + // Reusable Frame + rpc_gui->transmit_frame = malloc(sizeof(PB_Main)); + rpc_gui->transmit_frame->which_content = PB_Main_gui_screen_frame_tag; + rpc_gui->transmit_frame->command_status = PB_CommandStatus_OK; + rpc_gui->transmit_frame->content.gui_screen_frame.data = + malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(framebuffer_size)); + rpc_gui->transmit_frame->content.gui_screen_frame.data->size = framebuffer_size; + // Transmission thread for async TX + rpc_gui->transmit_thread = furi_thread_alloc(); + furi_thread_set_name(rpc_gui->transmit_thread, "GuiRpcWorker"); + furi_thread_set_callback( + rpc_gui->transmit_thread, rpc_system_gui_screen_stream_frame_transmit_thread); + furi_thread_set_context(rpc_gui->transmit_thread, rpc_gui); + furi_thread_set_stack_size(rpc_gui->transmit_thread, 1024); + furi_thread_start(rpc_gui->transmit_thread); + // GUI framebuffer callback + gui_add_framebuffer_callback( + rpc_gui->gui, rpc_system_gui_screen_stream_frame_callback, context); + } } static void rpc_system_gui_stop_screen_stream_process(const PB_Main* request, void* context) { diff --git a/applications/rpc/rpc_storage.c b/applications/rpc/rpc_storage.c index b70ec4cc..e9c13ca3 100644 --- a/applications/rpc/rpc_storage.c +++ b/applications/rpc/rpc_storage.c @@ -10,10 +10,12 @@ #include "storage/storage.h" #include #include +#include #define RPC_TAG "RPC_STORAGE" #define MAX_NAME_LENGTH 255 -#define MAX_DATA_SIZE 512 + +static const size_t MAX_DATA_SIZE = 512; typedef enum { RpcStorageStateIdle = 0, @@ -185,7 +187,7 @@ static void rpc_system_storage_list_root(const PB_Main* request, void* context) }; furi_assert(COUNT_OF(hard_coded_dirs) < COUNT_OF(response.content.storage_list_response.file)); - for(int i = 0; i < COUNT_OF(hard_coded_dirs); ++i) { + for(uint32_t i = 0; i < COUNT_OF(hard_coded_dirs); ++i) { ++response.content.storage_list_response.file_count; response.content.storage_list_response.file[i].data = NULL; response.content.storage_list_response.file[i].size = 0; @@ -538,6 +540,53 @@ static void rpc_system_storage_rename_process(const PB_Main* request, void* cont rpc_send_and_release_empty(session, request->command_id, status); } +static void rpc_system_storage_backup_create_process(const PB_Main* request, void* context) { + furi_assert(request); + furi_assert(request->which_content == PB_Main_storage_backup_create_request_tag); + + RpcSession* session = (RpcSession*)context; + furi_assert(session); + + PB_Main* response = malloc(sizeof(PB_Main)); + response->command_id = request->command_id; + response->has_next = false; + + Storage* fs_api = furi_record_open("storage"); + + bool backup_ok = + lfs_backup_create(fs_api, request->content.storage_backup_create_request.archive_path); + response->command_status = backup_ok ? PB_CommandStatus_OK : PB_CommandStatus_ERROR; + + furi_record_close("storage"); + + rpc_send_and_release(session, response); + free(response); +} + +static void rpc_system_storage_backup_restore_process(const PB_Main* request, void* context) { + furi_assert(request); + furi_assert(request->which_content == PB_Main_storage_backup_restore_request_tag); + + RpcSession* session = (RpcSession*)context; + furi_assert(session); + + PB_Main* response = malloc(sizeof(PB_Main)); + response->command_id = request->command_id; + response->has_next = false; + response->command_status = PB_CommandStatus_OK; + + Storage* fs_api = furi_record_open("storage"); + + bool backup_ok = + lfs_backup_unpack(fs_api, request->content.storage_backup_restore_request.archive_path); + response->command_status = backup_ok ? PB_CommandStatus_OK : PB_CommandStatus_ERROR; + + furi_record_close("storage"); + + rpc_send_and_release(session, response); + free(response); +} + void* rpc_system_storage_alloc(RpcSession* session) { furi_assert(session); @@ -579,6 +628,12 @@ void* rpc_system_storage_alloc(RpcSession* session) { rpc_handler.message_handler = rpc_system_storage_rename_process; rpc_add_handler(session, PB_Main_storage_rename_request_tag, &rpc_handler); + rpc_handler.message_handler = rpc_system_storage_backup_create_process; + rpc_add_handler(session, PB_Main_storage_backup_create_request_tag, &rpc_handler); + + rpc_handler.message_handler = rpc_system_storage_backup_restore_process; + rpc_add_handler(session, PB_Main_storage_backup_restore_request_tag, &rpc_handler); + return rpc_storage; } diff --git a/applications/rpc/rpc_system.c b/applications/rpc/rpc_system.c index f3a8242a..6ea3b02e 100644 --- a/applications/rpc/rpc_system.c +++ b/applications/rpc/rpc_system.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "rpc_i.h" @@ -242,6 +243,28 @@ static void rpc_system_system_get_power_info_process(const PB_Main* request, voi free(response); } +#ifdef APP_UPDATER +static void rpc_system_system_update_request_process(const PB_Main* request, void* context) { + furi_assert(request); + furi_assert(request->which_content == PB_Main_system_update_request_tag); + + RpcSession* session = (RpcSession*)context; + furi_assert(session); + + bool update_prepare_result = + update_operation_prepare(request->content.system_update_request.update_folder) == + UpdatePrepareResultOK; + + PB_Main* response = malloc(sizeof(PB_Main)); + response->command_id = request->command_id; + response->has_next = false; + response->command_status = update_prepare_result ? PB_CommandStatus_OK : + PB_CommandStatus_ERROR_INVALID_PARAMETERS; + rpc_send_and_release(session, response); + free(response); +} +#endif + void* rpc_system_system_alloc(RpcSession* session) { RpcHandler rpc_handler = { .message_handler = NULL, @@ -276,5 +299,10 @@ void* rpc_system_system_alloc(RpcSession* session) { rpc_handler.message_handler = rpc_system_system_get_power_info_process; rpc_add_handler(session, PB_Main_system_power_info_request_tag, &rpc_handler); +#ifdef APP_UPDATER + rpc_handler.message_handler = rpc_system_system_update_request_process; + rpc_add_handler(session, PB_Main_system_update_request_tag, &rpc_handler); +#endif + return NULL; -} +} \ No newline at end of file diff --git a/applications/storage/storage.c b/applications/storage/storage.c index 4aa5f105..078a136c 100644 --- a/applications/storage/storage.c +++ b/applications/storage/storage.c @@ -40,7 +40,9 @@ Storage* storage_app_alloc() { storage_data_init(&app->storage[i]); } +#ifndef FURI_RAM_EXEC storage_int_init(&app->storage[ST_INT]); +#endif storage_ext_init(&app->storage[ST_EXT]); // sd icon gui diff --git a/applications/storage/storage.h b/applications/storage/storage.h index d5eb87d3..bb71447b 100644 --- a/applications/storage/storage.h +++ b/applications/storage/storage.h @@ -263,6 +263,22 @@ FS_Error storage_sd_info(Storage* api, SDInfo* info); */ FS_Error storage_sd_status(Storage* api); +/******************* Internal LFS Functions *******************/ + +/** Backs up internal storage to a tar archive + * @param api pointer to the api + * @param dstmane destination archive path + * @return FS_Error operation result + */ +FS_Error storage_int_backup(Storage* api, const char* dstname); + +/** Restores internal storage from a tar archive + * @param api pointer to the api + * @param dstmane archive path + * @return FS_Error operation result + */ +FS_Error storage_int_restore(Storage* api, const char* dstname); + /***************** Simplified Functions ******************/ /** @@ -309,4 +325,4 @@ void storage_get_next_filename( #ifdef __cplusplus } -#endif +#endif \ No newline at end of file diff --git a/applications/storage/storage_cli.c b/applications/storage/storage_cli.c index 07fa638f..17bffa97 100644 --- a/applications/storage/storage_cli.c +++ b/applications/storage/storage_cli.c @@ -521,7 +521,7 @@ void storage_cli(Cli* cli, string_t args, void* context) { string_clear(cmd); } -void storage_cli_factory_reset(Cli* cli, string_t args, void* context) { +static void storage_cli_factory_reset(Cli* cli, string_t args, void* context) { printf("All data will be lost. Are you sure (y/n)?\r\n"); char c = cli_getc(cli); if(c == 'y' || c == 'Y') { @@ -540,5 +540,7 @@ void storage_on_system_start() { cli_add_command( cli, "factory_reset", CliCommandFlagParallelSafe, storage_cli_factory_reset, NULL); furi_record_close("cli"); +#else + UNUSED(storage_cli_factory_reset); #endif } diff --git a/applications/storage/storage_internal_api.c b/applications/storage/storage_internal_api.c new file mode 100644 index 00000000..754ae0dd --- /dev/null +++ b/applications/storage/storage_internal_api.c @@ -0,0 +1,22 @@ +#include +#include +#include "storage.h" +#include + +#define INT_PATH "/int" + +FS_Error storage_int_backup(Storage* api, const char* dstname) { + TarArchive* archive = tar_archive_alloc(api); + bool success = tar_archive_open(archive, dstname, TAR_OPEN_MODE_WRITE) && + tar_archive_add_dir(archive, INT_PATH, "") && tar_archive_finalize(archive); + tar_archive_free(archive); + return success ? FSE_OK : FSE_INTERNAL; +} + +FS_Error storage_int_restore(Storage* api, const char* srcname) { + TarArchive* archive = tar_archive_alloc(api); + bool success = tar_archive_open(archive, srcname, TAR_OPEN_MODE_READ) && + tar_archive_unpack_to(archive, INT_PATH); + tar_archive_free(archive); + return success ? FSE_OK : FSE_INTERNAL; +} \ No newline at end of file diff --git a/applications/storage/storage_processing.c b/applications/storage/storage_processing.c index bb1ac9c3..6120a345 100644 --- a/applications/storage/storage_processing.c +++ b/applications/storage/storage_processing.c @@ -20,7 +20,11 @@ static StorageData* storage_get_storage_by_type(Storage* app, StorageType type) } static bool storage_type_is_not_valid(StorageType type) { +#ifdef FURI_RAM_EXEC + return type != ST_EXT; +#else return type >= ST_ERROR; +#endif } static StorageData* get_storage_by_file(File* file, StorageData* storages) { diff --git a/applications/storage/storages/storage_ext.c b/applications/storage/storages/storage_ext.c index 8a3d21ca..4ef9a8ea 100644 --- a/applications/storage/storages/storage_ext.c +++ b/applications/storage/storages/storage_ext.c @@ -54,10 +54,12 @@ static bool sd_mount_card(StorageData* storage, bool notify) { SDError status = f_mount(sd_data->fs, sd_data->path, 1); if(status == FR_OK || status == FR_NO_FILESYSTEM) { +#ifndef FURI_RAM_EXEC FATFS* fs; uint32_t free_clusters; status = f_getfree(sd_data->path, &free_clusters, &fs); +#endif if(status == FR_OK || status == FR_NO_FILESYSTEM) { result = true; @@ -110,6 +112,9 @@ FS_Error sd_unmount_card(StorageData* storage) { } FS_Error sd_format_card(StorageData* storage) { +#ifdef FURI_RAM_EXEC + return FSE_NOT_READY; +#else uint8_t* work_area; SDData* sd_data = storage->data; SDError error; @@ -135,11 +140,14 @@ FS_Error sd_format_card(StorageData* storage) { storage_data_unlock(storage); return storage_ext_parse_error(error); +#endif } FS_Error sd_card_info(StorageData* storage, SDInfo* sd_info) { +#ifndef FURI_RAM_EXEC uint32_t free_clusters, free_sectors, total_sectors; FATFS* fs; +#endif SDData* sd_data = storage->data; SDError error; @@ -150,20 +158,32 @@ FS_Error sd_card_info(StorageData* storage, SDInfo* sd_info) { storage_data_lock(storage); error = f_getlabel(sd_data->path, sd_info->label, NULL); if(error == FR_OK) { +#ifndef FURI_RAM_EXEC error = f_getfree(sd_data->path, &free_clusters, &fs); +#endif } storage_data_unlock(storage); if(error == FR_OK) { // calculate size +#ifndef FURI_RAM_EXEC total_sectors = (fs->n_fatent - 2) * fs->csize; free_sectors = free_clusters * fs->csize; +#endif uint16_t sector_size = _MAX_SS; #if _MAX_SS != _MIN_SS sector_size = fs->ssize; #endif +#ifdef FURI_RAM_EXEC + sd_info->fs_type = 0; + sd_info->kb_total = 0; + sd_info->kb_free = 0; + sd_info->cluster_size = 512; + sd_info->sector_size = sector_size; +#else + sd_info->fs_type = fs->fs_type; switch(fs->fs_type) { case FS_FAT12: sd_info->fs_type = FST_FAT12; @@ -177,7 +197,6 @@ FS_Error sd_card_info(StorageData* storage, SDInfo* sd_info) { case FS_EXFAT: sd_info->fs_type = FST_EXFAT; break; - default: sd_info->fs_type = FST_UNKNOWN; break; @@ -187,6 +206,7 @@ FS_Error sd_card_info(StorageData* storage, SDInfo* sd_info) { sd_info->kb_free = free_sectors / 1024 * sector_size; sd_info->cluster_size = fs->csize; sd_info->sector_size = sector_size; +#endif } return storage_ext_parse_error(error); @@ -328,12 +348,16 @@ static uint16_t static uint16_t storage_ext_file_write(void* ctx, File* file, const void* buff, uint16_t const bytes_to_write) { +#ifdef FURI_RAM_EXEC + return FSE_NOT_READY; +#else StorageData* storage = ctx; SDFile* file_data = storage_get_storage_file_data(file, storage); uint16_t bytes_written = 0; file->internal_error_id = f_write(file_data, buff, bytes_to_write, &bytes_written); file->error_id = storage_ext_parse_error(file->internal_error_id); return bytes_written; +#endif } static bool @@ -364,21 +388,29 @@ static uint64_t storage_ext_file_tell(void* ctx, File* file) { } static bool storage_ext_file_truncate(void* ctx, File* file) { +#ifdef FURI_RAM_EXEC + return FSE_NOT_READY; +#else StorageData* storage = ctx; SDFile* file_data = storage_get_storage_file_data(file, storage); file->internal_error_id = f_truncate(file_data); file->error_id = storage_ext_parse_error(file->internal_error_id); return (file->error_id == FSE_OK); +#endif } static bool storage_ext_file_sync(void* ctx, File* file) { +#ifdef FURI_RAM_EXEC + return FSE_NOT_READY; +#else StorageData* storage = ctx; SDFile* file_data = storage_get_storage_file_data(file, storage); file->internal_error_id = f_sync(file_data); file->error_id = storage_ext_parse_error(file->internal_error_id); return (file->error_id == FSE_OK); +#endif } static uint64_t storage_ext_file_size(void* ctx, File* file) { @@ -479,13 +511,21 @@ static FS_Error storage_ext_common_stat(void* ctx, const char* path, FileInfo* f } static FS_Error storage_ext_common_remove(void* ctx, const char* path) { +#ifdef FURI_RAM_EXEC + return FSE_NOT_READY; +#else SDError result = f_unlink(path); return storage_ext_parse_error(result); +#endif } static FS_Error storage_ext_common_mkdir(void* ctx, const char* path) { +#ifdef FURI_RAM_EXEC + return FSE_NOT_READY; +#else SDError result = f_mkdir(path); return storage_ext_parse_error(result); +#endif } static FS_Error storage_ext_common_fs_info( @@ -493,6 +533,9 @@ static FS_Error storage_ext_common_fs_info( const char* fs_path, uint64_t* total_space, uint64_t* free_space) { +#ifdef FURI_RAM_EXEC + return FSE_NOT_READY; +#else StorageData* storage = ctx; SDData* sd_data = storage->data; @@ -519,6 +562,7 @@ static FS_Error storage_ext_common_fs_info( } return storage_ext_parse_error(fresult); +#endif } /******************* Init Storage *******************/ @@ -566,4 +610,4 @@ void storage_ext_init(StorageData* storage) { // do not notify on first launch, notifications app is waiting for our thread to read settings storage_ext_tick_internal(storage, false); -} +} \ No newline at end of file diff --git a/applications/subghz/subghz_cli.c b/applications/subghz/subghz_cli.c index ad2f4031..143016a1 100644 --- a/applications/subghz/subghz_cli.c +++ b/applications/subghz/subghz_cli.c @@ -571,7 +571,7 @@ static void subghz_cli_command_chat(Cli* cli, string_t args) { printf("\r\nExit chat\r\n"); } -void subghz_cli_command(Cli* cli, string_t args, void* context) { +static void subghz_cli_command(Cli* cli, string_t args, void* context) { string_t cmd; string_init(cmd); @@ -630,5 +630,7 @@ void subghz_on_system_start() { cli_add_command(cli, "subghz", CliCommandFlagDefault, subghz_cli_command, NULL); furi_record_close("cli"); +#else + UNUSED(subghz_cli_command); #endif } diff --git a/applications/updater/cli/updater_cli.c b/applications/updater/cli/updater_cli.c new file mode 100644 index 00000000..aa08bc61 --- /dev/null +++ b/applications/updater/cli/updater_cli.c @@ -0,0 +1,134 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef void (*cmd_handler)(string_t args); +typedef struct { + const char* command; + const cmd_handler handler; +} CliSubcommand; + +static void updater_cli_install(string_t manifest_path) { + printf("Verifying update package at '%s'\r\n", string_get_cstr(manifest_path)); + + UpdatePrepareResult result = update_operation_prepare(string_get_cstr(manifest_path)); + if(result != UpdatePrepareResultOK) { + printf( + "Error: %s. Stopping update.\r\n", + update_operation_describe_preparation_result(result)); + return; + } + printf("OK.\r\nRestarting to apply update. BRB\r\n"); + osDelay(100); + furi_hal_power_reset(); +} + +static void updater_cli_backup(string_t args) { + printf("Backup /int to '%s'\r\n", string_get_cstr(args)); + Storage* storage = furi_record_open("storage"); + bool success = lfs_backup_create(storage, string_get_cstr(args)); + furi_record_close("storage"); + printf("Result: %s\r\n", success ? "OK" : "FAIL"); +} + +static void updater_cli_restore(string_t args) { + printf("Restore /int from '%s'\r\n", string_get_cstr(args)); + Storage* storage = furi_record_open("storage"); + bool success = lfs_backup_unpack(storage, string_get_cstr(args)); + furi_record_close("storage"); + printf("Result: %s\r\n", success ? "OK" : "FAIL"); +} + +static void updater_cli_help(string_t args) { + UNUSED(args); + printf("Commands:\r\n" + "\tinstall /ext/update/PACKAGE/update.fuf - verify & apply update package\r\n" + "\tbackup /ext/path/to/backup.tar - create internal storage backup\r\n" + "\trestore /ext/path/to/backup.tar - restore internal storage backup\r\n"); +} + +static const CliSubcommand update_cli_subcommands[] = { + {.command = "install", .handler = updater_cli_install}, + {.command = "backup", .handler = updater_cli_backup}, + {.command = "restore", .handler = updater_cli_restore}, + {.command = "help", .handler = updater_cli_help}, +}; + +static void updater_cli_ep(Cli* cli, string_t args, void* context) { + string_t subcommand; + string_init(subcommand); + if(!args_read_string_and_trim(args, subcommand) || string_empty_p(args)) { + updater_cli_help(args); + string_clear(subcommand); + return; + } + for(size_t idx = 0; idx < COUNT_OF(update_cli_subcommands); ++idx) { + const CliSubcommand* subcmd_def = &update_cli_subcommands[idx]; + if(string_cmp_str(subcommand, subcmd_def->command) == 0) { + string_clear(subcommand); + subcmd_def->handler(args); + return; + } + } + string_clear(subcommand); + updater_cli_help(args); +} + +static int32_t updater_spawner_thread_worker(void* arg) { + Loader* loader = furi_record_open("loader"); + loader_start(loader, "UpdaterApp", NULL); + furi_record_close("loader"); + return 0; +} + +static void updater_spawner_thread_cleanup(FuriThreadState state, void* context) { + FuriThread* thread = context; + if(state == FuriThreadStateStopped) { + furi_thread_free(thread); + } +} + +static void updater_start_app() { + FuriHalRtcBootMode mode = furi_hal_rtc_get_boot_mode(); + if((mode != FuriHalRtcBootModePreUpdate) && (mode != FuriHalRtcBootModePostUpdate)) { + return; + } + + /* We need to spawn a separate thread, because these callbacks are executed + * inside loader process, at startup. + * So, accessing its record would cause a deadlock + */ + FuriThread* thread = furi_thread_alloc(); + + furi_thread_set_name(thread, "UpdateAppSpawner"); + furi_thread_set_stack_size(thread, 768); + furi_thread_set_callback(thread, updater_spawner_thread_worker); + furi_thread_set_state_callback(thread, updater_spawner_thread_cleanup); + furi_thread_set_state_context(thread, thread); + furi_thread_start(thread); +} + +void updater_on_system_start() { +#ifdef SRV_CLI + Cli* cli = (Cli*)furi_record_open("cli"); + cli_add_command(cli, "update", CliCommandFlagDefault, updater_cli_ep, NULL); + furi_record_close("cli"); +#else + UNUSED(updater_cli_ep); +#endif +#ifndef FURI_RAM_EXEC + updater_start_app(); +#else + UNUSED(updater_start_app); +#endif +} diff --git a/applications/updater/scenes/updater_scene.c b/applications/updater/scenes/updater_scene.c new file mode 100644 index 00000000..afc5d08a --- /dev/null +++ b/applications/updater/scenes/updater_scene.c @@ -0,0 +1,30 @@ +#include "updater_scene.h" + +// Generate scene on_enter handlers array +#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter, +void (*const updater_on_enter_handlers[])(void*) = { +#include "updater_scene_config.h" +}; +#undef ADD_SCENE + +// Generate scene on_event handlers array +#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event, +bool (*const updater_on_event_handlers[])(void* context, SceneManagerEvent event) = { +#include "updater_scene_config.h" +}; +#undef ADD_SCENE + +// Generate scene on_exit handlers array +#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit, +void (*const updater_on_exit_handlers[])(void* context) = { +#include "updater_scene_config.h" +}; +#undef ADD_SCENE + +// Initialize scene handlers configuration structure +const SceneManagerHandlers updater_scene_handlers = { + .on_enter_handlers = updater_on_enter_handlers, + .on_event_handlers = updater_on_event_handlers, + .on_exit_handlers = updater_on_exit_handlers, + .scene_num = UpdaterSceneNum, +}; diff --git a/applications/updater/scenes/updater_scene.h b/applications/updater/scenes/updater_scene.h new file mode 100644 index 00000000..1c2dba27 --- /dev/null +++ b/applications/updater/scenes/updater_scene.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +// Generate scene id and total number +#define ADD_SCENE(prefix, name, id) UpdaterScene##id, +typedef enum { +#include "updater_scene_config.h" + UpdaterSceneNum, +} UpdaterScene; +#undef ADD_SCENE + +extern const SceneManagerHandlers updater_scene_handlers; + +// Generate scene on_enter handlers declaration +#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*); +#include "updater_scene_config.h" +#undef ADD_SCENE + +// Generate scene on_event handlers declaration +#define ADD_SCENE(prefix, name, id) \ + bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event); +#include "updater_scene_config.h" +#undef ADD_SCENE + +// Generate scene on_exit handlers declaration +#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context); +#include "updater_scene_config.h" +#undef ADD_SCENE diff --git a/applications/updater/scenes/updater_scene_config.h b/applications/updater/scenes/updater_scene_config.h new file mode 100644 index 00000000..d2441c59 --- /dev/null +++ b/applications/updater/scenes/updater_scene_config.h @@ -0,0 +1,5 @@ +ADD_SCENE(updater, main, Main) +#ifndef FURI_RAM_EXEC +ADD_SCENE(updater, loadcfg, LoadCfg) +ADD_SCENE(updater, error, Error) +#endif \ No newline at end of file diff --git a/applications/updater/scenes/updater_scene_error.c b/applications/updater/scenes/updater_scene_error.c new file mode 100644 index 00000000..362c471a --- /dev/null +++ b/applications/updater/scenes/updater_scene_error.c @@ -0,0 +1,65 @@ +#include "updater/updater_i.h" +#include "updater_scene.h" +#include + +void updater_scene_error_callback(GuiButtonType result, InputType type, void* context) { + furi_assert(context); + Updater* updater = context; + if(type != InputTypeShort) { + return; + } + + if(result == GuiButtonTypeLeft) { + view_dispatcher_send_custom_event( + updater->view_dispatcher, UpdaterCustomEventCancelUpdate); + } +} + +void updater_scene_error_on_enter(void* context) { + Updater* updater = (Updater*)context; + + widget_add_button_element( + updater->widget, GuiButtonTypeLeft, "Exit", updater_scene_error_callback, updater); + + widget_add_string_multiline_element( + updater->widget, 64, 13, AlignCenter, AlignCenter, FontPrimary, "Error"); + + widget_add_string_multiline_element( + updater->widget, + 64, + 33, + AlignCenter, + AlignCenter, + FontPrimary, + update_operation_describe_preparation_result(updater->preparation_result)); + + view_dispatcher_switch_to_view(updater->view_dispatcher, UpdaterViewWidget); +} + +bool updater_scene_error_on_event(void* context, SceneManagerEvent event) { + Updater* updater = (Updater*)context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeBack) { + view_dispatcher_stop(updater->view_dispatcher); + consumed = true; + } else if(event.type == SceneManagerEventTypeCustom) { + switch(event.event) { + case UpdaterCustomEventCancelUpdate: + view_dispatcher_stop(updater->view_dispatcher); + consumed = true; + break; + default: + break; + } + } + + return consumed; +} + +void updater_scene_error_on_exit(void* context) { + Updater* updater = (Updater*)context; + + widget_reset(updater->widget); + free(updater->pending_update); +} diff --git a/applications/updater/scenes/updater_scene_loadcfg.c b/applications/updater/scenes/updater_scene_loadcfg.c new file mode 100644 index 00000000..78423b07 --- /dev/null +++ b/applications/updater/scenes/updater_scene_loadcfg.c @@ -0,0 +1,105 @@ +#include "updater/updater_i.h" +#include "updater_scene.h" + +#include +#include + +void updater_scene_loadcfg_apply_callback(GuiButtonType result, InputType type, void* context) { + furi_assert(context); + Updater* updater = context; + if(type != InputTypeShort) { + return; + } + + if(result == GuiButtonTypeRight) { + view_dispatcher_send_custom_event(updater->view_dispatcher, UpdaterCustomEventStartUpdate); + } else if(result == GuiButtonTypeLeft) { + view_dispatcher_send_custom_event( + updater->view_dispatcher, UpdaterCustomEventCancelUpdate); + } +} + +void updater_scene_loadcfg_on_enter(void* context) { + Updater* updater = (Updater*)context; + UpdaterManifestProcessingState* pending_upd = updater->pending_update = + malloc(sizeof(UpdaterManifestProcessingState)); + pending_upd->manifest = update_manifest_alloc(); + + if(update_manifest_init(pending_upd->manifest, string_get_cstr(updater->startup_arg))) { + widget_add_string_element( + updater->widget, 64, 12, AlignCenter, AlignCenter, FontPrimary, "Update"); + + widget_add_string_multiline_element( + updater->widget, + 64, + 32, + AlignCenter, + AlignCenter, + FontSecondary, + string_get_cstr(pending_upd->manifest->version)); + + widget_add_button_element( + updater->widget, + GuiButtonTypeRight, + "Install", + updater_scene_loadcfg_apply_callback, + updater); + } else { + widget_add_string_element( + updater->widget, 64, 24, AlignCenter, AlignCenter, FontPrimary, "Invalid manifest"); + } + + widget_add_button_element( + updater->widget, + GuiButtonTypeLeft, + "Cancel", + updater_scene_loadcfg_apply_callback, + updater); + + view_dispatcher_switch_to_view(updater->view_dispatcher, UpdaterViewWidget); +} + +bool updater_scene_loadcfg_on_event(void* context, SceneManagerEvent event) { + Updater* updater = (Updater*)context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeBack) { + view_dispatcher_stop(updater->view_dispatcher); + consumed = true; + } else if(event.type == SceneManagerEventTypeCustom) { + switch(event.event) { + case UpdaterCustomEventStartUpdate: + updater->preparation_result = + update_operation_prepare(string_get_cstr(updater->startup_arg)); + if(updater->preparation_result == UpdatePrepareResultOK) { + furi_hal_power_reset(); + } else { +#ifndef FURI_RAM_EXEC + scene_manager_next_scene(updater->scene_manager, UpdaterSceneError); +#endif + } + consumed = true; + break; + case UpdaterCustomEventCancelUpdate: + view_dispatcher_stop(updater->view_dispatcher); + consumed = true; + break; + default: + break; + } + } + + return consumed; +} + +void updater_scene_loadcfg_on_exit(void* context) { + Updater* updater = (Updater*)context; + + if(updater->pending_update) { + update_manifest_free(updater->pending_update->manifest); + string_clear(updater->pending_update->message); + } + + widget_reset(updater->widget); + free(updater->pending_update); +} \ No newline at end of file diff --git a/applications/updater/scenes/updater_scene_main.c b/applications/updater/scenes/updater_scene_main.c new file mode 100644 index 00000000..d7b28a9d --- /dev/null +++ b/applications/updater/scenes/updater_scene_main.c @@ -0,0 +1,106 @@ +#include +#include +#include +#include + +#include "updater/updater_i.h" +#include "updater/views/updater_main.h" +#include "updater_scene.h" + +static void sd_mount_callback(const void* message, void* context) { + Updater* updater = context; + const StorageEvent* new_event = message; + + switch(new_event->type) { + case StorageEventTypeCardMount: + view_dispatcher_send_custom_event(updater->view_dispatcher, UpdaterCustomEventStartUpdate); + break; + case StorageEventTypeCardUnmount: + view_dispatcher_send_custom_event(updater->view_dispatcher, UpdaterCustomEventSdUnmounted); + break; + default: + break; + } +} + +void updater_scene_main_on_enter(void* context) { + Updater* updater = (Updater*)context; + UpdaterMainView* main_view = updater->main_view; + + FuriPubSubSubscription* sub = + furi_pubsub_subscribe(storage_get_pubsub(updater->storage), &sd_mount_callback, updater); + updater_main_set_storage_pubsub(main_view, sub); + + /* FIXME: there's a misbehavior in storage subsystem. If we produce heavy load on it before it + * fires an SD card event, it'll never do that until the load is lifted. Meanwhile SD card icon + * will be missing from UI, however, /ext will be fully operational. So, until it's fixed, this + * should remain commented out. */ + // If (somehow) we started after SD card is mounted, initiate update immediately + //if(storage_sd_status(updater->storage) == FSE_OK) { + // view_dispatcher_send_custom_event(updater->view_dispatcher, UpdaterCustomEventStartUpdate); + //} + + updater_main_set_view_dispatcher(main_view, updater->view_dispatcher); + view_dispatcher_switch_to_view(updater->view_dispatcher, UpdaterViewMain); +} + +static void updater_scene_restart_to_postupdate() { + furi_hal_rtc_set_boot_mode(FuriHalRtcBootModePostUpdate); + furi_hal_power_reset(); +} + +bool updater_scene_main_on_event(void* context, SceneManagerEvent event) { + Updater* updater = (Updater*)context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeTick) { + if(!update_task_is_running(updater->update_task)) { + if(updater->idle_ticks++ >= (UPDATE_DELAY_OPERATION_ERROR / UPDATER_APP_TICK)) { + updater_scene_restart_to_postupdate(); + } + } else { + updater->idle_ticks = 0; + } + } else if(event.type == SceneManagerEventTypeCustom) { + switch(event.event) { + case UpdaterCustomEventStartUpdate: + if(!update_task_is_running(updater->update_task) && + update_task_init(updater->update_task)) { + update_task_start(updater->update_task); + } + consumed = true; + break; + + case UpdaterCustomEventRetryUpdate: + if(!update_task_is_running(updater->update_task) && + (update_task_get_state(updater->update_task)->stage != UpdateTaskStageComplete)) + update_task_start(updater->update_task); + consumed = true; + break; + + case UpdaterCustomEventCancelUpdate: + if(!update_task_is_running(updater->update_task)) { + updater_scene_restart_to_postupdate(); + } + consumed = true; + break; + + case UpdaterCustomEventSdUnmounted: + // TODO: error out, stop worker (it's probably dead actually) + break; + default: + break; + } + } + + return consumed; +} + +void updater_scene_main_on_exit(void* context) { + Updater* updater = (Updater*)context; + + furi_pubsub_unsubscribe( + storage_get_pubsub(updater->storage), updater_main_get_storage_pubsub(updater->main_view)); + + scene_manager_set_scene_state(updater->scene_manager, UpdaterSceneMain, 0); +} \ No newline at end of file diff --git a/applications/updater/updater.c b/applications/updater/updater.c new file mode 100644 index 00000000..dbad239b --- /dev/null +++ b/applications/updater/updater.c @@ -0,0 +1,132 @@ +#include "scenes/updater_scene.h" +#include "updater_i.h" + +#include +#include +#include +#include +#include +#include + +static bool updater_custom_event_callback(void* context, uint32_t event) { + furi_assert(context); + Updater* updater = (Updater*)context; + return scene_manager_handle_custom_event(updater->scene_manager, event); +} + +static void updater_tick_event_callback(void* context) { + furi_assert(context); + Updater* app = context; + scene_manager_handle_tick_event(app->scene_manager); +} + +static bool updater_back_event_callback(void* context) { + furi_assert(context); + Updater* updater = (Updater*)context; + return scene_manager_handle_back_event(updater->scene_manager); +} + +static void status_update_cb( + const char* message, + const uint8_t progress, + const uint8_t idx_stage, + const uint8_t total_stages, + bool failed, + void* context) { + UpdaterMainView* main_view = context; + updater_main_model_set_state(main_view, message, progress, idx_stage, total_stages, failed); +} + +Updater* updater_alloc(const char* arg) { + Updater* updater = malloc(sizeof(Updater)); + if(arg) { + string_init_set_str(updater->startup_arg, arg); + string_replace_str(updater->startup_arg, "/any/", "/ext/"); + } else { + string_init(updater->startup_arg); + } + + updater->storage = furi_record_open("storage"); + + updater->gui = furi_record_open("gui"); + updater->view_dispatcher = view_dispatcher_alloc(); + updater->scene_manager = scene_manager_alloc(&updater_scene_handlers, updater); + + view_dispatcher_enable_queue(updater->view_dispatcher); + + view_dispatcher_set_event_callback_context(updater->view_dispatcher, updater); + view_dispatcher_set_custom_event_callback( + updater->view_dispatcher, updater_custom_event_callback); + view_dispatcher_set_navigation_event_callback( + updater->view_dispatcher, updater_back_event_callback); + view_dispatcher_set_tick_event_callback( + updater->view_dispatcher, updater_tick_event_callback, UPDATER_APP_TICK); + + view_dispatcher_attach_to_gui( + updater->view_dispatcher, + updater->gui, + arg ? ViewDispatcherTypeFullscreen : ViewDispatcherTypeWindow); + + updater->main_view = updater_main_alloc(); + view_dispatcher_add_view( + updater->view_dispatcher, UpdaterViewMain, updater_main_get_view(updater->main_view)); + +#ifndef FURI_RAM_EXEC + updater->widget = widget_alloc(); + view_dispatcher_add_view( + updater->view_dispatcher, UpdaterViewWidget, widget_get_view(updater->widget)); +#endif + +#ifdef FURI_RAM_EXEC + if(true) { +#else + if(!arg) { +#endif + updater->update_task = update_task_alloc(); + update_task_set_progress_cb(updater->update_task, status_update_cb, updater->main_view); + + scene_manager_next_scene(updater->scene_manager, UpdaterSceneMain); + } else { +#ifndef FURI_RAM_EXEC + scene_manager_next_scene(updater->scene_manager, UpdaterSceneLoadCfg); +#endif + } + + return updater; +} + +void updater_free(Updater* updater) { + furi_assert(updater); + + string_clear(updater->startup_arg); + if(updater->update_task) { + update_task_set_progress_cb(updater->update_task, NULL, NULL); + update_task_free(updater->update_task); + } + + view_dispatcher_remove_view(updater->view_dispatcher, UpdaterViewMain); + updater_main_free(updater->main_view); + +#ifndef FURI_RAM_EXEC + view_dispatcher_remove_view(updater->view_dispatcher, UpdaterViewWidget); + widget_free(updater->widget); +#endif + + view_dispatcher_free(updater->view_dispatcher); + scene_manager_free(updater->scene_manager); + + furi_record_close("gui"); + furi_record_close("storage"); + + free(updater); +} + +int32_t updater_srv(void* p) { + const char* cfgpath = p; + + Updater* updater = updater_alloc(cfgpath); + view_dispatcher_run(updater->view_dispatcher); + updater_free(updater); + + return 0; +} \ No newline at end of file diff --git a/applications/updater/updater_i.h b/applications/updater/updater_i.h new file mode 100644 index 00000000..d0e7c77c --- /dev/null +++ b/applications/updater/updater_i.h @@ -0,0 +1,65 @@ +#pragma once + +#include "views/updater_main.h" +#include "util/update_task.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define UPDATER_APP_TICK 500 + +typedef enum { + UpdaterViewMain, + UpdaterViewWidget, +} UpdaterViewEnum; + +typedef enum { + UpdaterCustomEventUnknown, + UpdaterCustomEventStartUpdate, + UpdaterCustomEventRetryUpdate, + UpdaterCustomEventCancelUpdate, + UpdaterCustomEventSdUnmounted, +} UpdaterCustomEvent; + +typedef struct UpdaterManifestProcessingState { + UpdateManifest* manifest; + string_t message; + bool ready_to_be_applied; +} UpdaterManifestProcessingState; + +typedef struct { + // GUI + Gui* gui; + SceneManager* scene_manager; + ViewDispatcher* view_dispatcher; + Storage* storage; + + UpdaterMainView* main_view; + + UpdaterManifestProcessingState* pending_update; + UpdatePrepareResult preparation_result; + + UpdateTask* update_task; + Widget* widget; + string_t startup_arg; + int32_t idle_ticks; +} Updater; + +Updater* updater_alloc(const char* arg); + +void updater_free(Updater* updater); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/applications/updater/util/update_task.c b/applications/updater/util/update_task.c new file mode 100644 index 00000000..8ca5aad2 --- /dev/null +++ b/applications/updater/util/update_task.c @@ -0,0 +1,226 @@ +#include "update_task.h" +#include "update_task_i.h" + +#include +#include +#include +#include +#include +#include +#include + +static const char* update_task_stage_descr[] = { + [UpdateTaskStageProgress] = "...", + [UpdateTaskStageReadManifest] = "Loading update manifest", + [UpdateTaskStageValidateDFUImage] = "Checking DFU file", + [UpdateTaskStageFlashWrite] = "Writing flash", + [UpdateTaskStageFlashValidate] = "Validating", + [UpdateTaskStageRadioWrite] = "Writing radio stack", + [UpdateTaskStageRadioCommit] = "Applying radio stack", + [UpdateTaskStageLfsBackup] = "Backing up LFS", + [UpdateTaskStageLfsRestore] = "Restoring LFS", + [UpdateTaskStageComplete] = "Complete", + [UpdateTaskStageError] = "Error", +}; + +static void update_task_set_status(UpdateTask* update_task, const char* status) { + if(!status) { + if(update_task->state.stage >= COUNT_OF(update_task_stage_descr)) { + status = "..."; + } else { + status = update_task_stage_descr[update_task->state.stage]; + } + } + string_set_str(update_task->state.status, status); +} + +void update_task_set_progress(UpdateTask* update_task, UpdateTaskStage stage, uint8_t progress) { + if(stage != UpdateTaskStageProgress) { + update_task->state.stage = stage; + update_task->state.current_stage_idx++; + update_task_set_status(update_task, NULL); + } + + if(progress > 100) { + progress = 100; + } + + update_task->state.progress = progress; + if(update_task->status_change_cb) { + (update_task->status_change_cb)( + string_get_cstr(update_task->state.status), + progress, + update_task->state.current_stage_idx, + update_task->state.total_stages, + update_task->state.stage == UpdateTaskStageError, + update_task->status_change_cb_state); + } +} + +static void update_task_close_file(UpdateTask* update_task) { + furi_assert(update_task); + if(!storage_file_is_open(update_task->file)) { + return; + } + + storage_file_close(update_task->file); +} + +static bool update_task_check_file_exists(UpdateTask* update_task, string_t filename) { + furi_assert(update_task); + string_t tmp_path; + string_init_set(tmp_path, update_task->update_path); + path_append(tmp_path, string_get_cstr(filename)); + bool exists = + (storage_common_stat(update_task->storage, string_get_cstr(tmp_path), NULL) == FSE_OK); + string_clear(tmp_path); + return exists; +} + +bool update_task_open_file(UpdateTask* update_task, string_t filename) { + furi_assert(update_task); + update_task_close_file(update_task); + + string_t tmp_path; + string_init_set(tmp_path, update_task->update_path); + path_append(tmp_path, string_get_cstr(filename)); + bool open_success = storage_file_open( + update_task->file, string_get_cstr(tmp_path), FSAM_READ, FSOM_OPEN_EXISTING); + string_clear(tmp_path); + return open_success; +} + +static void update_task_worker_thread_cb(FuriThreadState state, void* context) { + UpdateTask* update_task = context; + + if(state != FuriThreadStateStopped) { + return; + } + + int32_t op_result = furi_thread_get_return_code(update_task->thread); + if(op_result == UPDATE_TASK_NOERR) { + osDelay(UPDATE_DELAY_OPERATION_OK); + furi_hal_power_reset(); + } +} + +UpdateTask* update_task_alloc() { + UpdateTask* update_task = malloc(sizeof(UpdateTask)); + + update_task->state.stage = UpdateTaskStageProgress; + update_task->state.progress = 0; + string_init(update_task->state.status); + + update_task->manifest = update_manifest_alloc(); + update_task->storage = furi_record_open("storage"); + update_task->file = storage_file_alloc(update_task->storage); + update_task->status_change_cb = NULL; + + FuriThread* thread = update_task->thread = furi_thread_alloc(); + + furi_thread_set_name(thread, "UpdateWorker"); + furi_thread_set_stack_size(thread, 5120); + furi_thread_set_context(thread, update_task); + + furi_thread_set_state_callback(thread, update_task_worker_thread_cb); + furi_thread_set_state_context(thread, update_task); +#ifdef FURI_RAM_EXEC + UNUSED(update_task_worker_backup_restore); + furi_thread_set_callback(thread, update_task_worker_flash_writer); +#else + UNUSED(update_task_worker_flash_writer); + furi_thread_set_callback(thread, update_task_worker_backup_restore); +#endif + + return update_task; +} + +void update_task_free(UpdateTask* update_task) { + furi_assert(update_task); + + furi_thread_join(update_task->thread); + + furi_thread_free(update_task->thread); + update_task_close_file(update_task); + storage_file_free(update_task->file); + update_manifest_free(update_task->manifest); + + furi_record_close("storage"); + string_clear(update_task->update_path); + + free(update_task); +} + +bool update_task_init(UpdateTask* update_task) { + furi_assert(update_task); + string_init(update_task->update_path); + return true; +} + +bool update_task_parse_manifest(UpdateTask* update_task) { + furi_assert(update_task); + update_task_set_progress(update_task, UpdateTaskStageReadManifest, 0); + bool result = false; + string_t manifest_path; + string_init(manifest_path); + + do { + update_task_set_progress(update_task, UpdateTaskStageProgress, 10); + if(!update_operation_get_current_package_path( + update_task->storage, update_task->update_path)) { + break; + } + + path_concat( + string_get_cstr(update_task->update_path), + UPDATE_MANIFEST_DEFAULT_NAME, + manifest_path); + update_task_set_progress(update_task, UpdateTaskStageProgress, 30); + if(!update_manifest_init(update_task->manifest, string_get_cstr(manifest_path))) { + break; + } + + update_task_set_progress(update_task, UpdateTaskStageProgress, 50); + if(!string_empty_p(update_task->manifest->firmware_dfu_image) && + !update_task_check_file_exists(update_task, update_task->manifest->firmware_dfu_image)) { + break; + } + + update_task_set_progress(update_task, UpdateTaskStageProgress, 70); + if(!string_empty_p(update_task->manifest->radio_image) && + !update_task_check_file_exists(update_task, update_task->manifest->radio_image)) { + break; + } + + update_task_set_progress(update_task, UpdateTaskStageProgress, 100); + result = true; + } while(false); + + string_clear(manifest_path); + return result; +} + +void update_task_set_progress_cb(UpdateTask* update_task, updateProgressCb cb, void* state) { + update_task->status_change_cb = cb; + update_task->status_change_cb_state = state; +} + +bool update_task_start(UpdateTask* update_task) { + furi_assert(update_task); + return furi_thread_start(update_task->thread); +} + +bool update_task_is_running(UpdateTask* update_task) { + furi_assert(update_task); + return furi_thread_get_state(update_task->thread) == FuriThreadStateRunning; +} + +UpdateTaskState const* update_task_get_state(UpdateTask* update_task) { + furi_assert(update_task); + return &update_task->state; +} + +UpdateManifest const* update_task_get_manifest(UpdateTask* update_task) { + furi_assert(update_task); + return update_task->manifest; +} diff --git a/applications/updater/util/update_task.h b/applications/updater/util/update_task.h new file mode 100644 index 00000000..32dea989 --- /dev/null +++ b/applications/updater/util/update_task.h @@ -0,0 +1,66 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +#include +#include + +#define UPDATE_DELAY_OPERATION_OK 600 +#define UPDATE_DELAY_OPERATION_ERROR INT_MAX + +typedef enum { + UpdateTaskStageProgress, + UpdateTaskStageReadManifest, + UpdateTaskStageValidateDFUImage, + UpdateTaskStageFlashWrite, + UpdateTaskStageFlashValidate, + UpdateTaskStageRadioWrite, + UpdateTaskStageRadioCommit, + UpdateTaskStageLfsBackup, + UpdateTaskStageLfsRestore, + UpdateTaskStageComplete, + UpdateTaskStageError, +} UpdateTaskStage; + +typedef struct { + UpdateTaskStage stage; + uint8_t progress; + uint8_t current_stage_idx; + uint8_t total_stages; + string_t status; +} UpdateTaskState; + +typedef struct UpdateTask UpdateTask; + +typedef void (*updateProgressCb)( + const char* status, + const uint8_t stage_pct, + const uint8_t idx_stage, + const uint8_t total_stages, + bool failed, + void* state); + +UpdateTask* update_task_alloc(); + +void update_task_free(UpdateTask* update_task); + +bool update_task_init(UpdateTask* update_task); + +void update_task_set_progress_cb(UpdateTask* update_task, updateProgressCb cb, void* state); + +bool update_task_start(UpdateTask* update_task); + +bool update_task_is_running(UpdateTask* update_task); + +UpdateTaskState const* update_task_get_state(UpdateTask* update_task); + +UpdateManifest const* update_task_get_manifest(UpdateTask* update_task); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/applications/updater/util/update_task_i.h b/applications/updater/util/update_task_i.h new file mode 100644 index 00000000..fb6b4ac1 --- /dev/null +++ b/applications/updater/util/update_task_i.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#define UPDATE_TASK_NOERR 0 +#define UPDATE_TASK_FAILED -1 + +typedef struct UpdateTask { + UpdateTaskState state; + string_t update_path; + UpdateManifest* manifest; + FuriThread* thread; + Storage* storage; + File* file; + updateProgressCb status_change_cb; + void* status_change_cb_state; +} UpdateTask; + +void update_task_set_progress(UpdateTask* update_task, UpdateTaskStage stage, uint8_t progress); +bool update_task_parse_manifest(UpdateTask* update_task); +bool update_task_open_file(UpdateTask* update_task, string_t filename); + +int32_t update_task_worker_flash_writer(void* context); +int32_t update_task_worker_backup_restore(void* context); diff --git a/applications/updater/util/update_task_workers.c b/applications/updater/util/update_task_workers.c new file mode 100644 index 00000000..fb1e86be --- /dev/null +++ b/applications/updater/util/update_task_workers.c @@ -0,0 +1,148 @@ +#include "update_task.h" +#include "update_task_i.h" + +#include +#include +#include +#include +#include +#include +#include + +#define CHECK_RESULT(x) \ + if(!(x)) { \ + break; \ + } + +#define STM_DFU_VENDOR_ID 0x0483 +#define STM_DFU_PRODUCT_ID 0xDF11 +/* Written into DFU file by build pipeline */ +#define FLIPPER_ZERO_DFU_DEVICE_CODE 0xFFFF + +static const DfuValidationParams flipper_dfu_params = { + .device = FLIPPER_ZERO_DFU_DEVICE_CODE, + .product = STM_DFU_PRODUCT_ID, + .vendor = STM_DFU_VENDOR_ID, +}; + +static void update_task_dfu_progress(const uint8_t progress, void* context) { + UpdateTask* update_task = context; + update_task_set_progress(update_task, UpdateTaskStageProgress, progress); +} + +static bool page_task_compare_flash( + const uint8_t i_page, + const uint8_t* update_block, + uint16_t update_block_len) { + const size_t page_addr = furi_hal_flash_get_base() + furi_hal_flash_get_page_size() * i_page; + return (memcmp(update_block, (void*)page_addr, update_block_len) == 0); +} + +/* Verifies a flash operation address for fitting into writable memory + */ +static bool check_address_boundaries(const size_t address) { + const size_t min_allowed_address = furi_hal_flash_get_base(); + const size_t max_allowed_address = (size_t)furi_hal_flash_get_free_end_address(); + return ((address >= min_allowed_address) && (address < max_allowed_address)); +} + +int32_t update_task_worker_flash_writer(void* context) { + furi_assert(context); + UpdateTask* update_task = context; + bool success = false; + DfuUpdateTask page_task = { + .address_cb = &check_address_boundaries, + .progress_cb = &update_task_dfu_progress, + .task_cb = &furi_hal_flash_program_page, + .context = update_task, + }; + + update_task->state.current_stage_idx = 0; + update_task->state.total_stages = 4; + + do { + CHECK_RESULT(update_task_parse_manifest(update_task)); + + if(!string_empty_p(update_task->manifest->firmware_dfu_image)) { + update_task_set_progress(update_task, UpdateTaskStageValidateDFUImage, 0); + CHECK_RESULT( + update_task_open_file(update_task, update_task->manifest->firmware_dfu_image)); + CHECK_RESULT( + dfu_file_validate_crc(update_task->file, &update_task_dfu_progress, update_task)); + + const uint8_t valid_targets = + dfu_file_validate_headers(update_task->file, &flipper_dfu_params); + if(valid_targets == 0) { + break; + } + + update_task_set_progress(update_task, UpdateTaskStageFlashWrite, 0); + CHECK_RESULT(dfu_file_process_targets(&page_task, update_task->file, valid_targets)); + + page_task.task_cb = &page_task_compare_flash; + + update_task_set_progress(update_task, UpdateTaskStageFlashValidate, 0); + CHECK_RESULT(dfu_file_process_targets(&page_task, update_task->file, valid_targets)); + } + + update_task_set_progress(update_task, UpdateTaskStageComplete, 100); + + furi_hal_rtc_set_boot_mode(FuriHalRtcBootModePostUpdate); + + success = true; + } while(false); + + if(!success) { + update_task_set_progress(update_task, UpdateTaskStageError, update_task->state.progress); + } + + return success ? UPDATE_TASK_NOERR : UPDATE_TASK_FAILED; +} + +int32_t update_task_worker_backup_restore(void* context) { + furi_assert(context); + UpdateTask* update_task = context; + bool success = false; + + FuriHalRtcBootMode boot_mode = furi_hal_rtc_get_boot_mode(); + if((boot_mode != FuriHalRtcBootModePreUpdate) && (boot_mode != FuriHalRtcBootModePostUpdate)) { + // no idea how we got here. Clear to normal boot + furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); + return UPDATE_TASK_NOERR; + } + + update_task->state.current_stage_idx = 0; + update_task->state.total_stages = 1; + + if(!update_operation_get_current_package_path(update_task->storage, update_task->update_path)) { + return UPDATE_TASK_FAILED; + } + + string_t backup_file_path; + string_init(backup_file_path); + path_concat( + string_get_cstr(update_task->update_path), LFS_BACKUP_DEFAULT_FILENAME, backup_file_path); + + if(boot_mode == FuriHalRtcBootModePreUpdate) { + update_task_set_progress(update_task, UpdateTaskStageLfsBackup, 0); + furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); // to avoid bootloops + if((success = + lfs_backup_create(update_task->storage, string_get_cstr(backup_file_path)))) { + furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeUpdate); + } + } else if(boot_mode == FuriHalRtcBootModePostUpdate) { + update_task_set_progress(update_task, UpdateTaskStageLfsRestore, 0); + furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); + success = lfs_backup_unpack(update_task->storage, string_get_cstr(backup_file_path)); + } + + if(success) { + update_task_set_progress(update_task, UpdateTaskStageComplete, 100); + } else { + update_task_set_progress(update_task, UpdateTaskStageError, update_task->state.progress); + } + + string_clear(backup_file_path); + + return success ? UPDATE_TASK_NOERR : UPDATE_TASK_FAILED; +} diff --git a/applications/updater/views/updater_main.c b/applications/updater/views/updater_main.c new file mode 100644 index 00000000..8d9b3e95 --- /dev/null +++ b/applications/updater/views/updater_main.c @@ -0,0 +1,151 @@ +#include +#include +#include +#include +#include +#include + +#include "../updater_i.h" +#include "updater_main.h" + +struct UpdaterMainView { + View* view; + ViewDispatcher* view_dispatcher; + FuriPubSubSubscription* subscription; + void* context; +}; + +static const uint8_t PROGRESS_RENDER_STEP = 3; /* percent, to limit rendering rate */ + +typedef struct { + string_t status; + uint8_t progress, rendered_progress; + uint8_t idx_stage, total_stages; + bool failed; +} UpdaterProgressModel; + +void updater_main_model_set_state( + UpdaterMainView* main_view, + const char* message, + uint8_t progress, + uint8_t idx_stage, + uint8_t total_stages, + bool failed) { + with_view_model( + main_view->view, (UpdaterProgressModel * model) { + model->failed = failed; + model->idx_stage = idx_stage; + model->total_stages = total_stages; + model->progress = progress; + if(string_cmp_str(model->status, message)) { + string_set(model->status, message); + model->rendered_progress = progress; + return true; + } + if((model->rendered_progress > progress) || + ((progress - model->rendered_progress) > PROGRESS_RENDER_STEP)) { + model->rendered_progress = progress; + return true; + } + return false; + }); +} + +View* updater_main_get_view(UpdaterMainView* main_view) { + furi_assert(main_view); + return main_view->view; +} + +bool updater_main_input(InputEvent* event, void* context) { + furi_assert(event); + furi_assert(context); + + UpdaterMainView* main_view = context; + if(!main_view->view_dispatcher) { + return true; + } + + if(event->type != InputTypeShort) { + return true; + } + + if(event->key == InputKeyOk) { + view_dispatcher_send_custom_event( + main_view->view_dispatcher, UpdaterCustomEventRetryUpdate); + } else if(event->key == InputKeyBack) { + view_dispatcher_send_custom_event( + main_view->view_dispatcher, UpdaterCustomEventCancelUpdate); + } + + return true; +} + +static void updater_main_draw_callback(Canvas* canvas, void* _model) { + UpdaterProgressModel* model = _model; + + canvas_set_font(canvas, FontPrimary); + + uint16_t y_offset = model->failed ? 5 : 13; + string_t status_text; + if(!model->failed && (model->idx_stage != 0) && (model->idx_stage <= model->total_stages)) { + string_init_printf( + status_text, + "[%d/%d] %s", + model->idx_stage, + model->total_stages, + string_get_cstr(model->status)); + } else { + string_init_set(status_text, model->status); + } + canvas_draw_str_aligned( + canvas, 128 / 2, y_offset, AlignCenter, AlignTop, string_get_cstr(status_text)); + string_clear(status_text); + if(model->failed) { + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned( + canvas, 128 / 2, 20, AlignCenter, AlignTop, "[OK] to retry, [Back] to abort"); + } + elements_progress_bar(canvas, 14, 35, 100, (float)model->progress / 100); +} + +UpdaterMainView* updater_main_alloc() { + UpdaterMainView* main_view = malloc(sizeof(UpdaterMainView)); + + main_view->view = view_alloc(); + view_allocate_model(main_view->view, ViewModelTypeLocking, sizeof(UpdaterProgressModel)); + + with_view_model( + main_view->view, (UpdaterProgressModel * model) { + string_init_set(model->status, "Waiting for storage"); + return true; + }); + + view_set_context(main_view->view, main_view); + view_set_input_callback(main_view->view, updater_main_input); + view_set_draw_callback(main_view->view, updater_main_draw_callback); + + return main_view; +} + +void updater_main_free(UpdaterMainView* main_view) { + furi_assert(main_view); + with_view_model( + main_view->view, (UpdaterProgressModel * model) { + string_clear(model->status); + return false; + }); + view_free(main_view->view); + free(main_view); +} + +void updater_main_set_storage_pubsub(UpdaterMainView* main_view, FuriPubSubSubscription* sub) { + main_view->subscription = sub; +} + +FuriPubSubSubscription* updater_main_get_storage_pubsub(UpdaterMainView* main_view) { + return main_view->subscription; +} + +void updater_main_set_view_dispatcher(UpdaterMainView* main_view, ViewDispatcher* view_dispatcher) { + main_view->view_dispatcher = view_dispatcher; +} diff --git a/applications/updater/views/updater_main.h b/applications/updater/views/updater_main.h new file mode 100644 index 00000000..3c55a8c2 --- /dev/null +++ b/applications/updater/views/updater_main.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +typedef struct UpdaterMainView UpdaterMainView; +typedef struct FuriPubSubSubscription FuriPubSubSubscription; +typedef struct ViewDispatcher ViewDispatcher; +typedef void (*UpdaterMainInputCallback)(InputType type, void* context); + +View* updater_main_get_view(UpdaterMainView* main_view); + +UpdaterMainView* updater_main_alloc(); + +void updater_main_free(UpdaterMainView* main_view); + +void updater_main_model_set_state( + UpdaterMainView* main_view, + const char* message, + uint8_t progress, + uint8_t idx_stage, + uint8_t total_stages, + bool failed); + +void updater_main_set_storage_pubsub(UpdaterMainView* main_view, FuriPubSubSubscription* sub); + +FuriPubSubSubscription* updater_main_get_storage_pubsub(UpdaterMainView* main_view); + +void updater_main_set_view_dispatcher(UpdaterMainView* main_view, ViewDispatcher* view_dispatcher); \ No newline at end of file diff --git a/assets/assets.mk b/assets/assets.mk index cd5a9b2e..55783ec8 100644 --- a/assets/assets.mk +++ b/assets/assets.mk @@ -16,7 +16,7 @@ PROTOBUF_COMPILED_DIR := $(ASSETS_COMPILED_DIR) PROTOBUF_SOURCES := $(shell find $(PROTOBUF_SOURCE_DIR) -type f -iname '*.proto') PROTOBUF_FILENAMES := $(notdir $(addsuffix .pb.c,$(basename $(PROTOBUF_SOURCES)))) PROTOBUF := $(addprefix $(PROTOBUF_COMPILED_DIR)/,$(PROTOBUF_FILENAMES)) $(PROTOBUF_COMPILED_DIR)/protobuf_version.h -PROTOBUF_VERSION := $(shell git -C $(PROTOBUF_SOURCE_DIR) fetch --tags 2>/dev/null && git -C $(PROTOBUF_SOURCE_DIR) describe --tags --abbrev=0 2>/dev/null || echo 'unknown') +PROTOBUF_VERSION := $(shell git -C $(PROTOBUF_SOURCE_DIR) fetch --tags 2>/dev/null ; git -C $(PROTOBUF_SOURCE_DIR) describe --tags --abbrev=0 2>/dev/null || echo 'unknown') PROTOBUF_MAJOR_VERSION := $(word 1,$(subst ., ,$(PROTOBUF_VERSION))) PROTOBUF_MINOR_VERSION := $(word 2,$(subst ., ,$(PROTOBUF_VERSION))) $(if $(PROTOBUF_MAJOR_VERSION),,$(error "Protobuf major version is not specified, $$PROTOBUF_VERSION=$(PROTOBUF_VERSION), please perform git fetch in assets/protobuf directory")) diff --git a/assets/compiled/assets_icons.c b/assets/compiled/assets_icons.c index 03dda94a..8b17d078 100644 --- a/assets/compiled/assets_icons.c +++ b/assets/compiled/assets_icons.c @@ -64,6 +64,9 @@ const uint8_t* const _I_u2f_10px[] = {_I_u2f_10px_0}; const uint8_t _I_unknown_10px_0[] = {0x01,0x00,0x12,0x00,0xbc,0x40,0x39,0x90,0x0c,0x24,0x03,0x81,0x00,0xb0,0x40,0x26,0x00,0x12,0x00,0x08,0x14,0xc0,}; const uint8_t* const _I_unknown_10px[] = {_I_unknown_10px_0}; +const uint8_t _I_update_10px_0[] = {0x00,0xFE,0x01,0x01,0x02,0xFF,0x03,0x01,0x02,0x31,0x02,0x79,0x02,0xFD,0x02,0x31,0x02,0x31,0x02,0xFF,0x03,}; +const uint8_t* const _I_update_10px[] = {_I_update_10px_0}; + const uint8_t _I_BLE_Pairing_128x64_0[] = {0x01,0x00,0xb7,0x01,0x00,0x6c,0x38,0x1f,0xd0,0x10,0x76,0xe0,0x03,0xdd,0x40,0x07,0xf4,0x82,0x01,0x08,0x07,0xf4,0xc0,0x1f,0x91,0x08,0x07,0x00,0x1f,0xc0,0x0d,0x1e,0xe8,0x3f,0xc0,0x03,0x58,0x80,0xcf,0x11,0xd9,0xaf,0x85,0x77,0x01,0xf7,0x60,0xf8,0x45,0xff,0x05,0xed,0x9e,0x7c,0x09,0xdb,0xe0,0x2f,0x78,0x03,0x3c,0x8e,0xee,0x8a,0x43,0x81,0xfb,0x0c,0x66,0xe8,0xfc,0x59,0xba,0x6f,0x28,0x1b,0xfb,0xa3,0x80,0xfc,0xa0,0x1f,0xc6,0x86,0xbf,0xc3,0x78,0xce,0x04,0x19,0x26,0x77,0xfa,0x43,0xbe,0x12,0xa0,0x7e,0xf8,0x2a,0xa2,0x02,0xff,0x89,0x27,0x01,0xbf,0x99,0x38,0x8a,0xfc,0x0f,0x8e,0x07,0xfe,0x0e,0x94,0x2c,0x07,0xfc,0x7f,0x1f,0xf5,0x00,0xc3,0x00,0xe4,0x31,0x13,0xd1,0x00,0x0a,0xb8,0x19,0x25,0x91,0xc0,0x81,0xe2,0xb9,0x4d,0x5d,0x78,0x64,0x2e,0x84,0x80,0x61,0x07,0x02,0x3e,0x2a,0xa4,0xa2,0x00,0xf2,0x40,0x20,0xe3,0x21,0xa0,0x62,0x9f,0x60,0x05,0x02,0x3e,0x36,0x41,0x66,0x23,0x20,0x51,0xfc,0x40,0x68,0x0f,0x15,0x90,0x60,0x20,0x1b,0x09,0x89,0x70,0x46,0x42,0x07,0x14,0x99,0x41,0xe8,0x1f,0x18,0x0c,0x07,0xc1,0x19,0xff,0xc3,0xce,0x6b,0x54,0x8f,0xe0,0x3f,0x90,0x78,0x17,0x02,0x1a,0x70,0x39,0x01,0xa0,0xb1,0x53,0xb5,0x88,0xc7,0xe0,0x98,0x08,0x3a,0xd5,0xe8,0x97,0xd0,0x78,0xcf,0xe1,0x07,0xf1,0x0d,0x08,0x00,0x74,0x10,0x80,0x18,0xe8,0x97,0xc3,0xf2,0xff,0xc4,0x03,0xe3,0x04,0x8c,0x19,0xcc,0x00,0x35,0x0c,0x3c,0x03,0xf9,0x3f,0xb0,0x8f,0xc6,0x31,0x0e,0x0f,0x90,0x90,0xb5,0x45,0xc1,0xf8,0x4f,0xf0,0xde,0x18,0xcc,0x82,0x08,0x1f,0x22,0x20,0xd0,0x3a,0xab,0xd1,0xe0,0x5f,0xa1,0x1b,0x19,0x8d,0x02,0x04,0x9a,0x1d,0x04,0x28,0x26,0x36,0xa8,0x05,0xf0,0xe0,0x3f,0x04,0xf8,0xd0,0x30,0x55,0xfa,0xad,0x54,0x3e,0x35,0x09,0xab,0xac,0xbf,0x2b,0xf2,0x0a,0x0e,0xfb,0x55,0xaa,0x0f,0x94,0x68,0x04,0x30,0x6f,0xd3,0x7c,0xb0,0x15,0x0f,0xfd,0x7f,0xeb,0x05,0x4f,0x0b,0x60,0xa3,0x1f,0x28,0x0b,0xfc,0xbc,0x30,0x1f,0xf7,0xfe,0x54,0x2c,0x18,0x30,0x3c,0x6f,0x00,0xf2,0x1c,0x8c,0xf8,0x10,0x3c,0x00,0xf8,0xd5,0x5c,0x05,0xb8,0xb0,0xaa,0xdb,0x01,0x2b,0x31,0x0a,0xdc,0xa7,0x00,0xe6,0x00,0x0c,0x56,0x00,0x7e,0x10,0x00,0xcc,0x01,0xf0,0x1f,0x1b,0x40,0x2e,0x00,0x07,0x16,0x10,0x90,0x02,0xe5,0x90,0x06,0x29,0x00,0x2a,0xa9,0x00,0x2f,0x10,0x02,0xa5,0x10,0x02,0xf1,0x00,0x2a,0xa0,0x0d,0xc0,0x00,0xec,0x01,0xfd,0x60,0x17,0x6a,0xc0,0x60,0x40,0xfd,0xc0,0x30,0x04,0x01,0xb0,0xb0,0x7f,0x45,0x80,}; const uint8_t* const _I_BLE_Pairing_128x64[] = {_I_BLE_Pairing_128x64_0}; @@ -674,6 +677,7 @@ const Icon I_ir_10px = {.width=10,.height=10,.frame_count=1,.frame_rate=0,.frame const Icon I_sub1_10px = {.width=10,.height=10,.frame_count=1,.frame_rate=0,.frames=_I_sub1_10px}; const Icon I_u2f_10px = {.width=10,.height=10,.frame_count=1,.frame_rate=0,.frames=_I_u2f_10px}; const Icon I_unknown_10px = {.width=10,.height=10,.frame_count=1,.frame_rate=0,.frames=_I_unknown_10px}; +const Icon I_update_10px = {.width=10,.height=10,.frame_count=1,.frame_rate=0,.frames=_I_update_10px}; const Icon I_BLE_Pairing_128x64 = {.width=128,.height=64,.frame_count=1,.frame_rate=0,.frames=_I_BLE_Pairing_128x64}; const Icon I_Ble_connected_38x34 = {.width=38,.height=34,.frame_count=1,.frame_rate=0,.frames=_I_Ble_connected_38x34}; const Icon I_Ble_disconnected_24x34 = {.width=24,.height=34,.frame_count=1,.frame_rate=0,.frames=_I_Ble_disconnected_24x34}; diff --git a/assets/compiled/assets_icons.h b/assets/compiled/assets_icons.h index e80fdd2f..be1023f6 100644 --- a/assets/compiled/assets_icons.h +++ b/assets/compiled/assets_icons.h @@ -15,6 +15,7 @@ extern const Icon I_ir_10px; extern const Icon I_sub1_10px; extern const Icon I_u2f_10px; extern const Icon I_unknown_10px; +extern const Icon I_update_10px; extern const Icon I_BLE_Pairing_128x64; extern const Icon I_Ble_connected_38x34; extern const Icon I_Ble_disconnected_24x34; diff --git a/assets/icons/Archive/update_10px.png b/assets/icons/Archive/update_10px.png new file mode 100644 index 00000000..5a97651c Binary files /dev/null and b/assets/icons/Archive/update_10px.png differ diff --git a/bootloader/Makefile b/bootloader/Makefile deleted file mode 100644 index 08dcee83..00000000 --- a/bootloader/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -MAKEFILE_DIR := $(dir $(abspath $(firstword $(MAKEFILE_LIST)))) -PROJECT_ROOT := $(abspath $(MAKEFILE_DIR)/..) -PROJECT := bootloader - -include $(PROJECT_ROOT)/make/base.mk - -CFLAGS += -I$(PROJECT_ROOT) -Itargets/furi_hal_include -ASM_SOURCES += $(wildcard src/*.s) -C_SOURCES += $(wildcard src/*.c) -CPP_SOURCES += $(wildcard src/*.cpp) - -include $(PROJECT_ROOT)/make/defaults.mk -TARGET_DIR = targets/$(TARGET) -include $(TARGET_DIR)/target.mk - -LIB_DIR = $(PROJECT_ROOT)/lib - -# U8G2 display library -U8G2_DIR = $(LIB_DIR)/u8g2 -CFLAGS += -I$(U8G2_DIR) -C_SOURCES += $(U8G2_DIR)/u8g2_glue.c -C_SOURCES += $(U8G2_DIR)/u8g2_intersection.c -C_SOURCES += $(U8G2_DIR)/u8g2_setup.c -C_SOURCES += $(U8G2_DIR)/u8g2_d_memory.c -C_SOURCES += $(U8G2_DIR)/u8x8_cad.c -C_SOURCES += $(U8G2_DIR)/u8x8_byte.c -C_SOURCES += $(U8G2_DIR)/u8x8_gpio.c -C_SOURCES += $(U8G2_DIR)/u8x8_display.c -C_SOURCES += $(U8G2_DIR)/u8x8_setup.c -C_SOURCES += $(U8G2_DIR)/u8g2_hvline.c -C_SOURCES += $(U8G2_DIR)/u8g2_line.c -C_SOURCES += $(U8G2_DIR)/u8g2_ll_hvline.c -C_SOURCES += $(U8G2_DIR)/u8g2_circle.c -C_SOURCES += $(U8G2_DIR)/u8g2_box.c -C_SOURCES += $(U8G2_DIR)/u8g2_buffer.c -C_SOURCES += $(U8G2_DIR)/u8g2_font.c -C_SOURCES += $(U8G2_DIR)/u8g2_fonts.c -C_SOURCES += $(U8G2_DIR)/u8x8_8x8.c -C_SOURCES += $(U8G2_DIR)/u8g2_bitmap.c - - -include $(PROJECT_ROOT)/make/git.mk -include $(PROJECT_ROOT)/make/toolchain.mk -include $(PROJECT_ROOT)/make/rules.mk diff --git a/bootloader/ReadMe.md b/bootloader/ReadMe.md deleted file mode 100644 index 8a35cc5f..00000000 --- a/bootloader/ReadMe.md +++ /dev/null @@ -1,50 +0,0 @@ -# Flipper bootloader - -What it does? - -- [x] Hardware initialization -- [x] Boot process LED indicators -- [x] Firmware update -- [x] Errata crutches -- [ ] Recovery mode - -# Targets - -| Name | Bootloader | Firmware | Reset | DFU | -| | Address | Address | Combo | Combo | ------------------------------------------------------------------------------ -| f7 | 0x08000000 | 0x00008000 | L+Back | L+Back, hold L | - -Also there is a ST bootloader combo available on empty device: L+Ok+Back, release Back,Left. -Target independent code and headers in `src` and `target/include` folders. - -# Building - -## With dev docker image: - -`docker-compose exec dev make -C bootloader` - -## With toolchain installed in path: - -`make -C bootloader ` - -## Build Options - -- `DEBUG` - 0/1 - enable or disable debug build. Default is 1. -- `TARGET` - string - target to build. Default is `f4`. - -# Flashing - -Using SWD (STLink): - -`make -C bootloader flash` - -Or use DFU (USB): - -`make -C bootloader upload` - -# Debug - -Using SWD (STLink): - -`make -C bootloader debug` diff --git a/bootloader/src/main.c b/bootloader/src/main.c deleted file mode 100644 index 6f592eda..00000000 --- a/bootloader/src/main.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "target.h" - -int main() { - // Initialize hardware - target_init(); - // Check if dfu requested - if(target_is_dfu_requested()) { - target_switch2dfu(); - } - // Switch to OS - target_switch2os(); - // Never should get here - return 0; -} \ No newline at end of file diff --git a/bootloader/targets/f7/furi_hal/furi_hal.c b/bootloader/targets/f7/furi_hal/furi_hal.c deleted file mode 100644 index 33b0c8f1..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - -void furi_hal_init() { - furi_hal_i2c_init(); - furi_hal_light_init(); - furi_hal_spi_init(); - furi_hal_version_init(); -} - -void furi_hal_delay_ms(float milliseconds) { - LL_mDelay((uint32_t)milliseconds); -} - -void furi_hal_delay_us(float microseconds) { - microseconds = microseconds / 1000; - if(microseconds < 1) { - microseconds = 1; - } - LL_mDelay((uint32_t)microseconds); -} diff --git a/bootloader/targets/f7/furi_hal/furi_hal_gpio.c b/bootloader/targets/f7/furi_hal/furi_hal_gpio.c deleted file mode 100644 index f80f4c1e..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_gpio.c +++ /dev/null @@ -1,214 +0,0 @@ -#include -#include -#include - -#define GET_SYSCFG_EXTI_PORT(gpio) \ - (((gpio) == (GPIOA)) ? LL_SYSCFG_EXTI_PORTA : \ - ((gpio) == (GPIOB)) ? LL_SYSCFG_EXTI_PORTB : \ - ((gpio) == (GPIOC)) ? LL_SYSCFG_EXTI_PORTC : \ - ((gpio) == (GPIOD)) ? LL_SYSCFG_EXTI_PORTD : \ - ((gpio) == (GPIOE)) ? LL_SYSCFG_EXTI_PORTE : \ - LL_SYSCFG_EXTI_PORTH) - -#define GPIO_PIN_MAP(pin, prefix) \ - (((pin) == (LL_GPIO_PIN_0)) ? prefix##0 : \ - ((pin) == (LL_GPIO_PIN_1)) ? prefix##1 : \ - ((pin) == (LL_GPIO_PIN_2)) ? prefix##2 : \ - ((pin) == (LL_GPIO_PIN_3)) ? prefix##3 : \ - ((pin) == (LL_GPIO_PIN_4)) ? prefix##4 : \ - ((pin) == (LL_GPIO_PIN_5)) ? prefix##5 : \ - ((pin) == (LL_GPIO_PIN_6)) ? prefix##6 : \ - ((pin) == (LL_GPIO_PIN_7)) ? prefix##7 : \ - ((pin) == (LL_GPIO_PIN_8)) ? prefix##8 : \ - ((pin) == (LL_GPIO_PIN_9)) ? prefix##9 : \ - ((pin) == (LL_GPIO_PIN_10)) ? prefix##10 : \ - ((pin) == (LL_GPIO_PIN_11)) ? prefix##11 : \ - ((pin) == (LL_GPIO_PIN_12)) ? prefix##12 : \ - ((pin) == (LL_GPIO_PIN_13)) ? prefix##13 : \ - ((pin) == (LL_GPIO_PIN_14)) ? prefix##14 : \ - prefix##15) - -#define GET_SYSCFG_EXTI_LINE(pin) GPIO_PIN_MAP(pin, LL_SYSCFG_EXTI_LINE) -#define GET_EXTI_LINE(pin) GPIO_PIN_MAP(pin, LL_EXTI_LINE_) - -static volatile GpioInterrupt gpio_interrupt[GPIO_NUMBER]; - -static uint8_t furi_hal_gpio_get_pin_num(const GpioPin* gpio) { - uint8_t pin_num = 0; - for(pin_num = 0; pin_num < GPIO_NUMBER; pin_num++) { - if(gpio->pin & (1 << pin_num)) break; - } - return pin_num; -} - -void furi_hal_gpio_init_simple(const GpioPin* gpio, const GpioMode mode) { - furi_hal_gpio_init(gpio, mode, GpioPullNo, GpioSpeedLow); -} - -void furi_hal_gpio_init( - const GpioPin* gpio, - const GpioMode mode, - const GpioPull pull, - const GpioSpeed speed) { - // we cannot set alternate mode in this function - assert(mode != GpioModeAltFunctionPushPull); - assert(mode != GpioModeAltFunctionOpenDrain); - - furi_hal_gpio_init_ex(gpio, mode, pull, speed, GpioAltFnUnused); -} - -void furi_hal_gpio_init_ex( - const GpioPin* gpio, - const GpioMode mode, - const GpioPull pull, - const GpioSpeed speed, - const GpioAltFn alt_fn) { - uint32_t sys_exti_port = GET_SYSCFG_EXTI_PORT(gpio->port); - uint32_t sys_exti_line = GET_SYSCFG_EXTI_LINE(gpio->pin); - uint32_t exti_line = GET_EXTI_LINE(gpio->pin); - - // Configure gpio with interrupts disabled - __disable_irq(); - - // Set gpio speed - switch(speed) { - case GpioSpeedLow: - LL_GPIO_SetPinSpeed(gpio->port, gpio->pin, LL_GPIO_SPEED_FREQ_LOW); - break; - case GpioSpeedMedium: - LL_GPIO_SetPinSpeed(gpio->port, gpio->pin, LL_GPIO_SPEED_FREQ_MEDIUM); - break; - case GpioSpeedHigh: - LL_GPIO_SetPinSpeed(gpio->port, gpio->pin, LL_GPIO_SPEED_FREQ_HIGH); - break; - case GpioSpeedVeryHigh: - LL_GPIO_SetPinSpeed(gpio->port, gpio->pin, LL_GPIO_SPEED_FREQ_VERY_HIGH); - break; - } - - // Set gpio pull mode - switch(pull) { - case GpioPullNo: - LL_GPIO_SetPinPull(gpio->port, gpio->pin, LL_GPIO_PULL_NO); - break; - case GpioPullUp: - LL_GPIO_SetPinPull(gpio->port, gpio->pin, LL_GPIO_PULL_UP); - break; - case GpioPullDown: - LL_GPIO_SetPinPull(gpio->port, gpio->pin, LL_GPIO_PULL_DOWN); - break; - } - - // Set gpio mode - if(mode >= GpioModeInterruptRise) { - // Set pin in interrupt mode - LL_GPIO_SetPinMode(gpio->port, gpio->pin, LL_GPIO_MODE_INPUT); - LL_SYSCFG_SetEXTISource(sys_exti_port, sys_exti_line); - if(mode == GpioModeInterruptRise || mode == GpioModeInterruptRiseFall) { - LL_EXTI_EnableIT_0_31(exti_line); - LL_EXTI_EnableRisingTrig_0_31(exti_line); - } - if(mode == GpioModeInterruptFall || mode == GpioModeInterruptRiseFall) { - LL_EXTI_EnableIT_0_31(exti_line); - LL_EXTI_EnableFallingTrig_0_31(exti_line); - } - if(mode == GpioModeEventRise || mode == GpioModeEventRiseFall) { - LL_EXTI_EnableEvent_0_31(exti_line); - LL_EXTI_EnableRisingTrig_0_31(exti_line); - } - if(mode == GpioModeEventFall || mode == GpioModeEventRiseFall) { - LL_EXTI_EnableEvent_0_31(exti_line); - LL_EXTI_EnableFallingTrig_0_31(exti_line); - } - } else { - // Disable interrupts if set - if(LL_SYSCFG_GetEXTISource(sys_exti_line) == sys_exti_port && - LL_EXTI_IsEnabledIT_0_31(exti_line)) { - LL_EXTI_DisableIT_0_31(exti_line); - LL_EXTI_DisableRisingTrig_0_31(exti_line); - LL_EXTI_DisableFallingTrig_0_31(exti_line); - } - - // Prepare alternative part if any - if(mode == GpioModeAltFunctionPushPull || mode == GpioModeAltFunctionOpenDrain) { - // set alternate function - if(furi_hal_gpio_get_pin_num(gpio) < 8) { - LL_GPIO_SetAFPin_0_7(gpio->port, gpio->pin, alt_fn); - } else { - LL_GPIO_SetAFPin_8_15(gpio->port, gpio->pin, alt_fn); - } - } - - // Set not interrupt pin modes - switch(mode) { - case GpioModeInput: - LL_GPIO_SetPinMode(gpio->port, gpio->pin, LL_GPIO_MODE_INPUT); - break; - case GpioModeOutputPushPull: - LL_GPIO_SetPinOutputType(gpio->port, gpio->pin, LL_GPIO_OUTPUT_PUSHPULL); - LL_GPIO_SetPinMode(gpio->port, gpio->pin, LL_GPIO_MODE_OUTPUT); - break; - case GpioModeAltFunctionPushPull: - LL_GPIO_SetPinOutputType(gpio->port, gpio->pin, LL_GPIO_OUTPUT_PUSHPULL); - LL_GPIO_SetPinMode(gpio->port, gpio->pin, LL_GPIO_MODE_ALTERNATE); - break; - case GpioModeOutputOpenDrain: - LL_GPIO_SetPinOutputType(gpio->port, gpio->pin, LL_GPIO_OUTPUT_OPENDRAIN); - LL_GPIO_SetPinMode(gpio->port, gpio->pin, LL_GPIO_MODE_OUTPUT); - break; - case GpioModeAltFunctionOpenDrain: - LL_GPIO_SetPinOutputType(gpio->port, gpio->pin, LL_GPIO_OUTPUT_OPENDRAIN); - LL_GPIO_SetPinMode(gpio->port, gpio->pin, LL_GPIO_MODE_ALTERNATE); - break; - case GpioModeAnalog: - LL_GPIO_SetPinMode(gpio->port, gpio->pin, LL_GPIO_MODE_ANALOG); - break; - default: - break; - } - } - __enable_irq(); -} - -void furi_hal_gpio_add_int_callback(const GpioPin* gpio, GpioExtiCallback cb, void* ctx) { - assert(gpio); - assert(cb); - - __disable_irq(); - uint8_t pin_num = furi_hal_gpio_get_pin_num(gpio); - gpio_interrupt[pin_num].callback = cb; - gpio_interrupt[pin_num].context = ctx; - gpio_interrupt[pin_num].ready = true; - __enable_irq(); -} - -void furi_hal_gpio_enable_int_callback(const GpioPin* gpio) { - assert(gpio); - - __disable_irq(); - uint8_t pin_num = furi_hal_gpio_get_pin_num(gpio); - if(gpio_interrupt[pin_num].callback) { - gpio_interrupt[pin_num].ready = true; - } - __enable_irq(); -} - -void furi_hal_gpio_disable_int_callback(const GpioPin* gpio) { - assert(gpio); - - __disable_irq(); - uint8_t pin_num = furi_hal_gpio_get_pin_num(gpio); - gpio_interrupt[pin_num].ready = false; - __enable_irq(); -} - -void furi_hal_gpio_remove_int_callback(const GpioPin* gpio) { - assert(gpio); - - __disable_irq(); - uint8_t pin_num = furi_hal_gpio_get_pin_num(gpio); - gpio_interrupt[pin_num].callback = NULL; - gpio_interrupt[pin_num].context = NULL; - gpio_interrupt[pin_num].ready = false; - __enable_irq(); -} diff --git a/bootloader/targets/f7/furi_hal/furi_hal_gpio.h b/bootloader/targets/f7/furi_hal/furi_hal_gpio.h deleted file mode 100644 index f633e834..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_gpio.h +++ /dev/null @@ -1,264 +0,0 @@ -#pragma once -#include "stdbool.h" -#include "main.h" -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Number of gpio on one port - */ -#define GPIO_NUMBER (16U) - -/** - * Interrupt callback prototype - */ -typedef void (*GpioExtiCallback)(void* ctx); - -/** - * Gpio interrupt type - */ -typedef struct { - GpioExtiCallback callback; - void* context; - volatile bool ready; -} GpioInterrupt; - -/** - * Gpio modes - */ -typedef enum { - GpioModeInput, - GpioModeOutputPushPull, - GpioModeOutputOpenDrain, - GpioModeAltFunctionPushPull, - GpioModeAltFunctionOpenDrain, - GpioModeAnalog, - GpioModeInterruptRise, - GpioModeInterruptFall, - GpioModeInterruptRiseFall, - GpioModeEventRise, - GpioModeEventFall, - GpioModeEventRiseFall, -} GpioMode; - -/** - * Gpio pull modes - */ -typedef enum { - GpioPullNo, - GpioPullUp, - GpioPullDown, -} GpioPull; - -/** - * Gpio speed modes - */ -typedef enum { - GpioSpeedLow, - GpioSpeedMedium, - GpioSpeedHigh, - GpioSpeedVeryHigh, -} GpioSpeed; - -/** - * Gpio alternate functions - */ -typedef enum { - GpioAltFn0MCO = 0, /*!< MCO Alternate Function mapping */ - GpioAltFn0LSCO = 0, /*!< LSCO Alternate Function mapping */ - GpioAltFn0JTMS_SWDIO = 0, /*!< JTMS-SWDIO Alternate Function mapping */ - GpioAltFn0JTCK_SWCLK = 0, /*!< JTCK-SWCLK Alternate Function mapping */ - GpioAltFn0JTDI = 0, /*!< JTDI Alternate Function mapping */ - GpioAltFn0RTC_OUT = 0, /*!< RCT_OUT Alternate Function mapping */ - GpioAltFn0JTD_TRACE = 0, /*!< JTDO-TRACESWO Alternate Function mapping */ - GpioAltFn0NJTRST = 0, /*!< NJTRST Alternate Function mapping */ - GpioAltFn0RTC_REFIN = 0, /*!< RTC_REFIN Alternate Function mapping */ - GpioAltFn0TRACED0 = 0, /*!< TRACED0 Alternate Function mapping */ - GpioAltFn0TRACED1 = 0, /*!< TRACED1 Alternate Function mapping */ - GpioAltFn0TRACED2 = 0, /*!< TRACED2 Alternate Function mapping */ - GpioAltFn0TRACED3 = 0, /*!< TRACED3 Alternate Function mapping */ - GpioAltFn0TRIG_INOUT = 0, /*!< TRIG_INOUT Alternate Function mapping */ - GpioAltFn0TRACECK = 0, /*!< TRACECK Alternate Function mapping */ - GpioAltFn0SYS = 0, /*!< System Function mapping */ - - GpioAltFn1TIM1 = 1, /*!< TIM1 Alternate Function mapping */ - GpioAltFn1TIM2 = 1, /*!< TIM2 Alternate Function mapping */ - GpioAltFn1LPTIM1 = 1, /*!< LPTIM1 Alternate Function mapping */ - - GpioAltFn2TIM2 = 2, /*!< TIM2 Alternate Function mapping */ - GpioAltFn2TIM1 = 2, /*!< TIM1 Alternate Function mapping */ - - GpioAltFn3SAI1 = 3, /*!< SAI1_CK1 Alternate Function mapping */ - GpioAltFn3SPI2 = 3, /*!< SPI2 Alternate Function mapping */ - GpioAltFn3TIM1 = 3, /*!< TIM1 Alternate Function mapping */ - - GpioAltFn4I2C1 = 4, /*!< I2C1 Alternate Function mapping */ - GpioAltFn4I2C3 = 4, /*!< I2C3 Alternate Function mapping */ - - GpioAltFn5SPI1 = 5, /*!< SPI1 Alternate Function mapping */ - GpioAltFn5SPI2 = 5, /*!< SPI2 Alternate Function mapping */ - - GpioAltFn6MCO = 6, /*!< MCO Alternate Function mapping */ - GpioAltFn6LSCO = 6, /*!< LSCO Alternate Function mapping */ - GpioAltFn6RF_DTB0 = 6, /*!< RF_DTB0 Alternate Function mapping */ - GpioAltFn6RF_DTB1 = 6, /*!< RF_DTB1 Alternate Function mapping */ - GpioAltFn6RF_DTB2 = 6, /*!< RF_DTB2 Alternate Function mapping */ - GpioAltFn6RF_DTB3 = 6, /*!< RF_DTB3 Alternate Function mapping */ - GpioAltFn6RF_DTB4 = 6, /*!< RF_DTB4 Alternate Function mapping */ - GpioAltFn6RF_DTB5 = 6, /*!< RF_DTB5 Alternate Function mapping */ - GpioAltFn6RF_DTB6 = 6, /*!< RF_DTB6 Alternate Function mapping */ - GpioAltFn6RF_DTB7 = 6, /*!< RF_DTB7 Alternate Function mapping */ - GpioAltFn6RF_DTB8 = 6, /*!< RF_DTB8 Alternate Function mapping */ - GpioAltFn6RF_DTB9 = 6, /*!< RF_DTB9 Alternate Function mapping */ - GpioAltFn6RF_DTB10 = 6, /*!< RF_DTB10 Alternate Function mapping */ - GpioAltFn6RF_DTB11 = 6, /*!< RF_DTB11 Alternate Function mapping */ - GpioAltFn6RF_DTB12 = 6, /*!< RF_DTB12 Alternate Function mapping */ - GpioAltFn6RF_DTB13 = 6, /*!< RF_DTB13 Alternate Function mapping */ - GpioAltFn6RF_DTB14 = 6, /*!< RF_DTB14 Alternate Function mapping */ - GpioAltFn6RF_DTB15 = 6, /*!< RF_DTB15 Alternate Function mapping */ - GpioAltFn6RF_DTB16 = 6, /*!< RF_DTB16 Alternate Function mapping */ - GpioAltFn6RF_DTB17 = 6, /*!< RF_DTB17 Alternate Function mapping */ - GpioAltFn6RF_DTB18 = 6, /*!< RF_DTB18 Alternate Function mapping */ - GpioAltFn6RF_MISO = 6, /*!< RF_MISO Alternate Function mapping */ - GpioAltFn6RF_MOSI = 6, /*!< RF_MOSI Alternate Function mapping */ - GpioAltFn6RF_SCK = 6, /*!< RF_SCK Alternate Function mapping */ - GpioAltFn6RF_NSS = 6, /*!< RF_NSS Alternate Function mapping */ - - GpioAltFn7USART1 = 7, /*!< USART1 Alternate Function mapping */ - - GpioAltFn8LPUART1 = 8, /*!< LPUART1 Alternate Function mapping */ - GpioAltFn8IR = 8, /*!< IR Alternate Function mapping */ - - GpioAltFn9TSC = 9, /*!< TSC Alternate Function mapping */ - - GpioAltFn10QUADSPI = 10, /*!< QUADSPI Alternate Function mapping */ - GpioAltFn10USB = 10, /*!< USB Alternate Function mapping */ - - GpioAltFn11LCD = 11, /*!< LCD Alternate Function mapping */ - - GpioAltFn12COMP1 = 12, /*!< COMP1 Alternate Function mapping */ - GpioAltFn12COMP2 = 12, /*!< COMP2 Alternate Function mapping */ - GpioAltFn12TIM1 = 12, /*!< TIM1 Alternate Function mapping */ - - GpioAltFn13SAI1 = 13, /*!< SAI1 Alternate Function mapping */ - - GpioAltFn14TIM2 = 14, /*!< TIM2 Alternate Function mapping */ - GpioAltFn14TIM16 = 14, /*!< TIM16 Alternate Function mapping */ - GpioAltFn14TIM17 = 14, /*!< TIM17 Alternate Function mapping */ - GpioAltFn14LPTIM2 = 14, /*!< LPTIM2 Alternate Function mapping */ - - GpioAltFn15EVENTOUT = 15, /*!< EVENTOUT Alternate Function mapping */ - - GpioAltFnUnused = 16, /*!< just dummy value */ -} GpioAltFn; - -/** - * Gpio structure - */ -typedef struct { - GPIO_TypeDef* port; - uint16_t pin; -} GpioPin; - -/** - * GPIO initialization function, simple version - * @param gpio GpioPin - * @param mode GpioMode - */ -void furi_hal_gpio_init_simple(const GpioPin* gpio, const GpioMode mode); - -/** - * GPIO initialization function, normal version - * @param gpio GpioPin - * @param mode GpioMode - * @param pull GpioPull - * @param speed GpioSpeed - */ -void furi_hal_gpio_init( - const GpioPin* gpio, - const GpioMode mode, - const GpioPull pull, - const GpioSpeed speed); - -/** - * GPIO initialization function, extended version - * @param gpio GpioPin - * @param mode GpioMode - * @param pull GpioPull - * @param speed GpioSpeed - * @param alt_fn GpioAltFn - */ -void furi_hal_gpio_init_ex( - const GpioPin* gpio, - const GpioMode mode, - const GpioPull pull, - const GpioSpeed speed, - const GpioAltFn alt_fn); - -/** - * Add and enable interrupt - * @param gpio GpioPin - * @param cb GpioExtiCallback - * @param ctx context for callback - */ -void furi_hal_gpio_add_int_callback(const GpioPin* gpio, GpioExtiCallback cb, void* ctx); - -/** - * Enable interrupt - * @param gpio GpioPin - */ -void furi_hal_gpio_enable_int_callback(const GpioPin* gpio); - -/** - * Disable interrupt - * @param gpio GpioPin - */ -void furi_hal_gpio_disable_int_callback(const GpioPin* gpio); - -/** - * Remove interrupt - * @param gpio GpioPin - */ -void furi_hal_gpio_remove_int_callback(const GpioPin* gpio); - -/** - * GPIO write pin - * @param gpio GpioPin - * @param state true / false - */ -static inline void furi_hal_gpio_write(const GpioPin* gpio, const bool state) { - // writing to BSSR is an atomic operation - if(state == true) { - gpio->port->BSRR = gpio->pin; - } else { - gpio->port->BSRR = (uint32_t)gpio->pin << GPIO_NUMBER; - } -} - -/** - * GPIO read pin - * @param gpio GpioPin - * @return true / false - */ -static inline bool furi_hal_gpio_read(const GpioPin* gpio) { - if((gpio->port->IDR & gpio->pin) != 0x00U) { - return true; - } else { - return false; - } -} - -/** - * Get RFID IN level - * @return false = LOW, true = HIGH - */ -bool furi_hal_gpio_get_rfid_in_level(); - -#ifdef __cplusplus -} -#endif diff --git a/bootloader/targets/f7/furi_hal/furi_hal_i2c.c b/bootloader/targets/f7/furi_hal/furi_hal_i2c.c deleted file mode 100644 index 210f96d6..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_i2c.c +++ /dev/null @@ -1,205 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -void furi_hal_i2c_init() { - furi_hal_i2c_bus_power.callback(&furi_hal_i2c_bus_power, FuriHalI2cBusEventInit); -} - -void furi_hal_i2c_acquire(FuriHalI2cBusHandle* handle) { - handle->bus->callback(handle->bus, FuriHalI2cBusEventLock); - - assert(handle->bus->current_handle == NULL); - - handle->bus->current_handle = handle; - - handle->bus->callback(handle->bus, FuriHalI2cBusEventActivate); - - handle->callback(handle, FuriHalI2cBusHandleEventActivate); -} - -void furi_hal_i2c_release(FuriHalI2cBusHandle* handle) { - assert(handle->bus->current_handle == handle); - - handle->callback(handle, FuriHalI2cBusHandleEventDeactivate); - - handle->bus->callback(handle->bus, FuriHalI2cBusEventDeactivate); - - handle->bus->current_handle = NULL; - - handle->bus->callback(handle->bus, FuriHalI2cBusEventUnlock); -} - -bool furi_hal_i2c_tx( - FuriHalI2cBusHandle* handle, - uint8_t address, - const uint8_t* data, - uint8_t size, - uint32_t timeout) { - assert(handle->bus->current_handle == handle); - uint32_t time_left = timeout; - bool ret = true; - - while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) - ; - - LL_I2C_HandleTransfer( - handle->bus->i2c, - address, - LL_I2C_ADDRSLAVE_7BIT, - size, - LL_I2C_MODE_AUTOEND, - LL_I2C_GENERATE_START_WRITE); - - while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c) || size > 0) { - if(LL_I2C_IsActiveFlag_TXIS(handle->bus->i2c)) { - LL_I2C_TransmitData8(handle->bus->i2c, (*data)); - data++; - size--; - time_left = timeout; - } - - if(LL_SYSTICK_IsActiveCounterFlag()) { - if(--time_left == 0) { - ret = false; - break; - } - } - } - - LL_I2C_ClearFlag_STOP(handle->bus->i2c); - - return ret; -} - -bool furi_hal_i2c_rx( - FuriHalI2cBusHandle* handle, - uint8_t address, - uint8_t* data, - uint8_t size, - uint32_t timeout) { - assert(handle->bus->current_handle == handle); - uint32_t time_left = timeout; - bool ret = true; - - while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) - ; - - LL_I2C_HandleTransfer( - handle->bus->i2c, - address, - LL_I2C_ADDRSLAVE_7BIT, - size, - LL_I2C_MODE_AUTOEND, - LL_I2C_GENERATE_START_READ); - - while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c) || size > 0) { - if(LL_I2C_IsActiveFlag_RXNE(handle->bus->i2c)) { - *data = LL_I2C_ReceiveData8(handle->bus->i2c); - data++; - size--; - time_left = timeout; - } - - if(LL_SYSTICK_IsActiveCounterFlag()) { - if(--time_left == 0) { - ret = false; - break; - } - } - } - - LL_I2C_ClearFlag_STOP(handle->bus->i2c); - - return ret; -} - -bool furi_hal_i2c_trx( - FuriHalI2cBusHandle* handle, - uint8_t address, - const uint8_t* tx_data, - uint8_t tx_size, - uint8_t* rx_data, - uint8_t rx_size, - uint32_t timeout) { - if(furi_hal_i2c_tx(handle, address, tx_data, tx_size, timeout) && - furi_hal_i2c_rx(handle, address, rx_data, rx_size, timeout)) { - return true; - } else { - return false; - } -} - -bool furi_hal_i2c_read_reg_8( - FuriHalI2cBusHandle* handle, - uint8_t i2c_addr, - uint8_t reg_addr, - uint8_t* data, - uint32_t timeout) { - assert(handle); - - return furi_hal_i2c_trx(handle, i2c_addr, ®_addr, 1, data, 1, timeout); -} - -bool furi_hal_i2c_read_reg_16( - FuriHalI2cBusHandle* handle, - uint8_t i2c_addr, - uint8_t reg_addr, - uint16_t* data, - uint32_t timeout) { - assert(handle); - - uint8_t reg_data[2]; - bool ret = furi_hal_i2c_trx(handle, i2c_addr, ®_addr, 1, reg_data, 2, timeout); - *data = (reg_data[0] << 8) | (reg_data[1]); - - return ret; -} - -bool furi_hal_i2c_read_mem( - FuriHalI2cBusHandle* handle, - uint8_t i2c_addr, - uint8_t mem_addr, - uint8_t* data, - uint8_t len, - uint32_t timeout) { - assert(handle); - - return furi_hal_i2c_trx(handle, i2c_addr, &mem_addr, 1, data, len, timeout); -} - -bool furi_hal_i2c_write_reg_8( - FuriHalI2cBusHandle* handle, - uint8_t i2c_addr, - uint8_t reg_addr, - uint8_t data, - uint32_t timeout) { - assert(handle); - - uint8_t tx_data[2]; - tx_data[0] = reg_addr; - tx_data[1] = data; - - return furi_hal_i2c_tx(handle, i2c_addr, (const uint8_t*)&tx_data, 2, timeout); -} - -bool furi_hal_i2c_write_reg_16( - FuriHalI2cBusHandle* handle, - uint8_t i2c_addr, - uint8_t reg_addr, - uint16_t data, - uint32_t timeout) { - assert(handle); - - uint8_t tx_data[3]; - tx_data[0] = reg_addr; - tx_data[1] = (data >> 8) & 0xFF; - tx_data[2] = data & 0xFF; - - return furi_hal_i2c_tx(handle, i2c_addr, (const uint8_t*)&tx_data, 3, timeout); -} diff --git a/bootloader/targets/f7/furi_hal/furi_hal_i2c.h b/bootloader/targets/f7/furi_hal/furi_hal_i2c.h deleted file mode 100644 index c2ad1728..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_i2c.h +++ /dev/null @@ -1,195 +0,0 @@ -/** - * @file furi_hal_i2c.h - * I2C HAL API - */ - -#pragma once - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** Init I2C - */ -void furi_hal_i2c_init(); - -/** Acquire i2c bus handle - * - * @return Instance of FuriHalI2cBus - */ -void furi_hal_i2c_acquire(FuriHalI2cBusHandle* handle); - -/** Release i2c bus handle - * - * @param bus instance of FuriHalI2cBus aquired in `furi_hal_i2c_acquire` - */ -void furi_hal_i2c_release(FuriHalI2cBusHandle* handle); - -/** Perform I2C tx transfer - * - * @param handle pointer to FuriHalI2cBusHandle instance - * @param address I2C slave address - * @param data pointer to data buffer - * @param size size of data buffer - * @param timeout timeout in ticks - * - * @return true on successful transfer, false otherwise - */ -bool furi_hal_i2c_tx( - FuriHalI2cBusHandle* handle, - const uint8_t address, - const uint8_t* data, - const uint8_t size, - uint32_t timeout); - -/** Perform I2C rx transfer - * - * @param handle pointer to FuriHalI2cBusHandle instance - * @param address I2C slave address - * @param data pointer to data buffer - * @param size size of data buffer - * @param timeout timeout in ticks - * - * @return true on successful transfer, false otherwise - */ -bool furi_hal_i2c_rx( - FuriHalI2cBusHandle* handle, - const uint8_t address, - uint8_t* data, - const uint8_t size, - uint32_t timeout); - -/** Perform I2C tx and rx transfers - * - * @param handle pointer to FuriHalI2cBusHandle instance - * @param address I2C slave address - * @param tx_data pointer to tx data buffer - * @param tx_size size of tx data buffer - * @param rx_data pointer to rx data buffer - * @param rx_size size of rx data buffer - * @param timeout timeout in ticks - * - * @return true on successful transfer, false otherwise - */ -bool furi_hal_i2c_trx( - FuriHalI2cBusHandle* handle, - const uint8_t address, - const uint8_t* tx_data, - const uint8_t tx_size, - uint8_t* rx_data, - const uint8_t rx_size, - uint32_t timeout); - -/** Perform I2C device register read (8-bit) - * - * @param handle pointer to FuriHalI2cBusHandle instance - * @param i2c_addr I2C slave address - * @param reg_addr register address - * @param data pointer to register value - * @param timeout timeout in ticks - * - * @return true on successful transfer, false otherwise - */ -bool furi_hal_i2c_read_reg_8( - FuriHalI2cBusHandle* handle, - uint8_t i2c_addr, - uint8_t reg_addr, - uint8_t* data, - uint32_t timeout); - -/** Perform I2C device register read (16-bit) - * - * @param handle pointer to FuriHalI2cBusHandle instance - * @param i2c_addr I2C slave address - * @param reg_addr register address - * @param data pointer to register value - * @param timeout timeout in ticks - * - * @return true on successful transfer, false otherwise - */ -bool furi_hal_i2c_read_reg_16( - FuriHalI2cBusHandle* handle, - uint8_t i2c_addr, - uint8_t reg_addr, - uint16_t* data, - uint32_t timeout); - -/** Perform I2C device memory read - * - * @param handle pointer to FuriHalI2cBusHandle instance - * @param i2c_addr I2C slave address - * @param mem_addr memory start address - * @param data pointer to data buffer - * @param len size of data buffer - * @param timeout timeout in ticks - * - * @return true on successful transfer, false otherwise - */ -bool furi_hal_i2c_read_mem( - FuriHalI2cBusHandle* handle, - uint8_t i2c_addr, - uint8_t mem_addr, - uint8_t* data, - uint8_t len, - uint32_t timeout); - -/** Perform I2C device register write (8-bit) - * - * @param handle pointer to FuriHalI2cBusHandle instance - * @param i2c_addr I2C slave address - * @param reg_addr register address - * @param data register value - * @param timeout timeout in ticks - * - * @return true on successful transfer, false otherwise - */ -bool furi_hal_i2c_write_reg_8( - FuriHalI2cBusHandle* handle, - uint8_t i2c_addr, - uint8_t reg_addr, - uint8_t data, - uint32_t timeout); - -/** Perform I2C device register write (16-bit) - * - * @param handle pointer to FuriHalI2cBusHandle instance - * @param i2c_addr I2C slave address - * @param reg_addr register address - * @param data register value - * @param timeout timeout in ticks - * - * @return true on successful transfer, false otherwise - */ -bool furi_hal_i2c_write_reg_16( - FuriHalI2cBusHandle* handle, - uint8_t i2c_addr, - uint8_t reg_addr, - uint16_t data, - uint32_t timeout); - -/** Perform I2C device memory - * - * @param handle pointer to FuriHalI2cBusHandle instance - * @param i2c_addr I2C slave address - * @param mem_addr memory start address - * @param data pointer to data buffer - * @param len size of data buffer - * @param timeout timeout in ticks - * - * @return true on successful transfer, false otherwise - */ -bool furi_hal_i2c_write_mem( - FuriHalI2cBusHandle* handle, - uint8_t i2c_addr, - uint8_t mem_addr, - uint8_t* data, - uint8_t len, - uint32_t timeout); - -#ifdef __cplusplus -} -#endif diff --git a/bootloader/targets/f7/furi_hal/furi_hal_i2c_config.c b/bootloader/targets/f7/furi_hal/furi_hal_i2c_config.c deleted file mode 100644 index e693911a..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_i2c_config.c +++ /dev/null @@ -1,151 +0,0 @@ -#include "furi_hal_i2c_config.h" -#include -#include - -#include -#include - -/** Timing register value is computed with the STM32CubeMX Tool, - * Standard Mode @100kHz with I2CCLK = 64 MHz, - * rise time = 0ns, fall time = 0ns - */ -#define FURI_HAL_I2C_CONFIG_POWER_I2C_TIMINGS_100 0x10707DBC - -/** Timing register value is computed with the STM32CubeMX Tool, - * Fast Mode @400kHz with I2CCLK = 64 MHz, - * rise time = 0ns, fall time = 0ns - */ -#define FURI_HAL_I2C_CONFIG_POWER_I2C_TIMINGS_400 0x00602173 - -static void furi_hal_i2c_bus_power_event(FuriHalI2cBus* bus, FuriHalI2cBusEvent event) { - if(event == FuriHalI2cBusEventInit) { - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1); - LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_PCLK1); - LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C1); - bus->current_handle = NULL; - } else if(event == FuriHalI2cBusEventDeinit) { - } else if(event == FuriHalI2cBusEventLock) { - } else if(event == FuriHalI2cBusEventUnlock) { - } else if(event == FuriHalI2cBusEventActivate) { - LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C1); - } else if(event == FuriHalI2cBusEventDeactivate) { - LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C1); - } -} - -FuriHalI2cBus furi_hal_i2c_bus_power = { - .i2c = I2C1, - .current_handle = NULL, - .callback = furi_hal_i2c_bus_power_event, -}; - -static void furi_hal_i2c_bus_external_event(FuriHalI2cBus* bus, FuriHalI2cBusEvent event) { - if(event == FuriHalI2cBusEventActivate) { - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C3); - LL_RCC_SetI2CClockSource(LL_RCC_I2C3_CLKSOURCE_PCLK1); - LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C3); - } else if(event == FuriHalI2cBusEventDeactivate) { - LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C3); - } -} - -FuriHalI2cBus furi_hal_i2c_bus_external = { - .i2c = I2C3, - .current_handle = NULL, - .callback = furi_hal_i2c_bus_external_event, -}; - -void furi_hal_i2c_bus_handle_power_event( - FuriHalI2cBusHandle* handle, - FuriHalI2cBusHandleEvent event) { - if(event == FuriHalI2cBusHandleEventActivate) { - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - furi_hal_gpio_init_ex( - &gpio_i2c_power_sda, - GpioModeAltFunctionOpenDrain, - GpioPullNo, - GpioSpeedLow, - GpioAltFn4I2C1); - furi_hal_gpio_init_ex( - &gpio_i2c_power_scl, - GpioModeAltFunctionOpenDrain, - GpioPullNo, - GpioSpeedLow, - GpioAltFn4I2C1); - - LL_I2C_InitTypeDef I2C_InitStruct = {0}; - I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; - I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; - I2C_InitStruct.DigitalFilter = 0; - I2C_InitStruct.OwnAddress1 = 0; - I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK; - I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT; - if(furi_hal_version_get_hw_version() > 10) { - I2C_InitStruct.Timing = FURI_HAL_I2C_CONFIG_POWER_I2C_TIMINGS_400; - } else { - I2C_InitStruct.Timing = FURI_HAL_I2C_CONFIG_POWER_I2C_TIMINGS_100; - } - LL_I2C_Init(handle->bus->i2c, &I2C_InitStruct); - - LL_I2C_EnableAutoEndMode(handle->bus->i2c); - LL_I2C_SetOwnAddress2(handle->bus->i2c, 0, LL_I2C_OWNADDRESS2_NOMASK); - LL_I2C_DisableOwnAddress2(handle->bus->i2c); - LL_I2C_DisableGeneralCall(handle->bus->i2c); - LL_I2C_EnableClockStretching(handle->bus->i2c); - LL_I2C_Enable(handle->bus->i2c); - } else if(event == FuriHalI2cBusHandleEventDeactivate) { - LL_I2C_Disable(handle->bus->i2c); - furi_hal_gpio_write(&gpio_i2c_power_sda, 1); - furi_hal_gpio_write(&gpio_i2c_power_scl, 1); - furi_hal_gpio_init_ex( - &gpio_i2c_power_sda, GpioModeAnalog, GpioPullNo, GpioSpeedLow, GpioAltFnUnused); - furi_hal_gpio_init_ex( - &gpio_i2c_power_scl, GpioModeAnalog, GpioPullNo, GpioSpeedLow, GpioAltFnUnused); - } -} - -FuriHalI2cBusHandle furi_hal_i2c_handle_power = { - .bus = &furi_hal_i2c_bus_power, - .callback = furi_hal_i2c_bus_handle_power_event, -}; - -void furi_hal_i2c_bus_handle_external_event( - FuriHalI2cBusHandle* handle, - FuriHalI2cBusHandleEvent event) { - if(event == FuriHalI2cBusHandleEventActivate) { - furi_hal_gpio_init_ex( - &gpio_ext_pc0, GpioModeAltFunctionOpenDrain, GpioPullNo, GpioSpeedLow, GpioAltFn4I2C3); - furi_hal_gpio_init_ex( - &gpio_ext_pc1, GpioModeAltFunctionOpenDrain, GpioPullNo, GpioSpeedLow, GpioAltFn4I2C3); - - LL_I2C_InitTypeDef I2C_InitStruct = {0}; - I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; - I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; - I2C_InitStruct.DigitalFilter = 0; - I2C_InitStruct.OwnAddress1 = 0; - I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK; - I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT; - I2C_InitStruct.Timing = FURI_HAL_I2C_CONFIG_POWER_I2C_TIMINGS_100; - LL_I2C_Init(handle->bus->i2c, &I2C_InitStruct); - - LL_I2C_EnableAutoEndMode(handle->bus->i2c); - LL_I2C_SetOwnAddress2(handle->bus->i2c, 0, LL_I2C_OWNADDRESS2_NOMASK); - LL_I2C_DisableOwnAddress2(handle->bus->i2c); - LL_I2C_DisableGeneralCall(handle->bus->i2c); - LL_I2C_EnableClockStretching(handle->bus->i2c); - LL_I2C_Enable(handle->bus->i2c); - } else if(event == FuriHalI2cBusHandleEventDeactivate) { - LL_I2C_Disable(handle->bus->i2c); - furi_hal_gpio_write(&gpio_ext_pc0, 1); - furi_hal_gpio_write(&gpio_ext_pc1, 1); - furi_hal_gpio_init_ex( - &gpio_ext_pc0, GpioModeAnalog, GpioPullNo, GpioSpeedLow, GpioAltFnUnused); - furi_hal_gpio_init_ex( - &gpio_ext_pc1, GpioModeAnalog, GpioPullNo, GpioSpeedLow, GpioAltFnUnused); - } -} - -FuriHalI2cBusHandle furi_hal_i2c_handle_external = { - .bus = &furi_hal_i2c_bus_external, - .callback = furi_hal_i2c_bus_handle_external_event, -}; diff --git a/bootloader/targets/f7/furi_hal/furi_hal_i2c_config.h b/bootloader/targets/f7/furi_hal/furi_hal_i2c_config.h deleted file mode 100644 index 03c0f1ca..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_i2c_config.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** Internal(power) i2c bus, I2C1, under reset when not used */ -extern FuriHalI2cBus furi_hal_i2c_bus_power; - -/** External i2c bus, I2C3, under reset when not used */ -extern FuriHalI2cBus furi_hal_i2c_bus_external; - -/** Handle for internal(power) i2c bus - * Bus: furi_hal_i2c_bus_external - * Pins: PA9(SCL) / PA10(SDA), float on release - * Params: 400khz - */ -extern FuriHalI2cBusHandle furi_hal_i2c_handle_power; - -/** Handle for external i2c bus - * Bus: furi_hal_i2c_bus_external - * Pins: PC0(SCL) / PC1(SDA), float on release - * Params: 100khz - */ -extern FuriHalI2cBusHandle furi_hal_i2c_handle_external; - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/bootloader/targets/f7/furi_hal/furi_hal_i2c_types.h b/bootloader/targets/f7/furi_hal/furi_hal_i2c_types.h deleted file mode 100644 index 0f2b735e..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_i2c_types.h +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct FuriHalI2cBus FuriHalI2cBus; -typedef struct FuriHalI2cBusHandle FuriHalI2cBusHandle; - -/** FuriHal i2c bus states */ -typedef enum { - FuriHalI2cBusEventInit, /**< Bus initialization event, called on system start */ - FuriHalI2cBusEventDeinit, /**< Bus deinitialization event, called on system stop */ - FuriHalI2cBusEventLock, /**< Bus lock event, called before activation */ - FuriHalI2cBusEventUnlock, /**< Bus unlock event, called after deactivation */ - FuriHalI2cBusEventActivate, /**< Bus activation event, called before handle activation */ - FuriHalI2cBusEventDeactivate, /**< Bus deactivation event, called after handle deactivation */ -} FuriHalI2cBusEvent; - -/** FuriHal i2c bus event callback */ -typedef void (*FuriHalI2cBusEventCallback)(FuriHalI2cBus* bus, FuriHalI2cBusEvent event); - -/** FuriHal i2c bus */ -struct FuriHalI2cBus { - I2C_TypeDef* i2c; - FuriHalI2cBusHandle* current_handle; - FuriHalI2cBusEventCallback callback; -}; - -/** FuriHal i2c handle states */ -typedef enum { - FuriHalI2cBusHandleEventActivate, /**< Handle activate: connect gpio and apply bus config */ - FuriHalI2cBusHandleEventDeactivate, /**< Handle deactivate: disconnect gpio and reset bus config */ -} FuriHalI2cBusHandleEvent; - -/** FuriHal i2c handle event callback */ -typedef void (*FuriHalI2cBusHandleEventCallback)( - FuriHalI2cBusHandle* handle, - FuriHalI2cBusHandleEvent event); - -/** FuriHal i2c handle */ -struct FuriHalI2cBusHandle { - FuriHalI2cBus* bus; - FuriHalI2cBusHandleEventCallback callback; -}; - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/bootloader/targets/f7/furi_hal/furi_hal_light.c b/bootloader/targets/f7/furi_hal/furi_hal_light.c deleted file mode 100644 index 6aba7efb..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_light.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include - -#define LED_CURRENT_RED 50 -#define LED_CURRENT_GREEN 50 -#define LED_CURRENT_BLUE 50 -#define LED_CURRENT_WHITE 150 - -void furi_hal_light_init() { - furi_hal_i2c_acquire(&furi_hal_i2c_handle_power); - - lp5562_reset(&furi_hal_i2c_handle_power); - - lp5562_set_channel_current(&furi_hal_i2c_handle_power, LP5562ChannelRed, LED_CURRENT_RED); - lp5562_set_channel_current(&furi_hal_i2c_handle_power, LP5562ChannelGreen, LED_CURRENT_GREEN); - lp5562_set_channel_current(&furi_hal_i2c_handle_power, LP5562ChannelBlue, LED_CURRENT_BLUE); - lp5562_set_channel_current(&furi_hal_i2c_handle_power, LP5562ChannelWhite, LED_CURRENT_WHITE); - - lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelRed, 0x00); - lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelGreen, 0x00); - lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelBlue, 0x00); - lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelWhite, 0x00); - - lp5562_enable(&furi_hal_i2c_handle_power); - lp5562_configure(&furi_hal_i2c_handle_power); - - furi_hal_i2c_release(&furi_hal_i2c_handle_power); -} - -void furi_hal_light_set(Light light, uint8_t value) { - furi_hal_i2c_acquire(&furi_hal_i2c_handle_power); - switch(light) { - case LightRed: - lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelRed, value); - break; - case LightGreen: - lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelGreen, value); - break; - case LightBlue: - lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelBlue, value); - break; - case LightBacklight: - lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelWhite, value); - break; - default: - break; - } - furi_hal_i2c_release(&furi_hal_i2c_handle_power); -} \ No newline at end of file diff --git a/bootloader/targets/f7/furi_hal/furi_hal_light.h b/bootloader/targets/f7/furi_hal/furi_hal_light.h deleted file mode 100644 index c585ddf5..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_light.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -void furi_hal_light_init(); - -void furi_hal_light_set(Light light, uint8_t value); - -#ifdef __cplusplus -} -#endif diff --git a/bootloader/targets/f7/furi_hal/furi_hal_resources.c b/bootloader/targets/f7/furi_hal/furi_hal_resources.c deleted file mode 100644 index fd792aa6..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_resources.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "furi_hal_resources.h" - -const GpioPin vibro_gpio = {.port = VIBRO_GPIO_Port, .pin = VIBRO_Pin}; -const GpioPin ibutton_gpio = {.port = iBTN_GPIO_Port, .pin = iBTN_Pin}; - -const GpioPin gpio_cc1101_g0 = {.port = CC1101_G0_GPIO_Port, .pin = CC1101_G0_Pin}; -const GpioPin gpio_rf_sw_0 = {.port = RF_SW_0_GPIO_Port, .pin = RF_SW_0_Pin}; - -const GpioPin gpio_subghz_cs = {.port = CC1101_CS_GPIO_Port, .pin = CC1101_CS_Pin}; -const GpioPin gpio_display_cs = {.port = DISPLAY_CS_GPIO_Port, .pin = DISPLAY_CS_Pin}; -const GpioPin gpio_display_rst = {.port = DISPLAY_RST_GPIO_Port, .pin = DISPLAY_RST_Pin}; -const GpioPin gpio_display_di = {.port = DISPLAY_DI_GPIO_Port, .pin = DISPLAY_DI_Pin}; -const GpioPin gpio_sdcard_cs = {.port = SD_CS_GPIO_Port, .pin = SD_CS_Pin}; -const GpioPin gpio_nfc_cs = {.port = NFC_CS_GPIO_Port, .pin = NFC_CS_Pin}; - -const GpioPin gpio_spi_d_miso = {.port = SPI_D_MISO_GPIO_Port, .pin = SPI_D_MISO_Pin}; -const GpioPin gpio_spi_d_mosi = {.port = SPI_D_MOSI_GPIO_Port, .pin = SPI_D_MOSI_Pin}; -const GpioPin gpio_spi_d_sck = {.port = SPI_D_SCK_GPIO_Port, .pin = SPI_D_SCK_Pin}; -const GpioPin gpio_spi_r_miso = {.port = SPI_R_MISO_GPIO_Port, .pin = SPI_R_MISO_Pin}; -const GpioPin gpio_spi_r_mosi = {.port = SPI_R_MOSI_GPIO_Port, .pin = SPI_R_MOSI_Pin}; -const GpioPin gpio_spi_r_sck = {.port = SPI_R_SCK_GPIO_Port, .pin = SPI_R_SCK_Pin}; - -const GpioPin gpio_ext_pc0 = {.port = GPIOC, .pin = LL_GPIO_PIN_0}; -const GpioPin gpio_ext_pc1 = {.port = GPIOC, .pin = LL_GPIO_PIN_1}; -const GpioPin gpio_ext_pc3 = {.port = GPIOC, .pin = LL_GPIO_PIN_3}; -const GpioPin gpio_ext_pb2 = {.port = GPIOB, .pin = LL_GPIO_PIN_2}; -const GpioPin gpio_ext_pb3 = {.port = GPIOB, .pin = LL_GPIO_PIN_3}; -const GpioPin gpio_ext_pa4 = {.port = GPIOA, .pin = LL_GPIO_PIN_4}; -const GpioPin gpio_ext_pa6 = {.port = GPIOA, .pin = LL_GPIO_PIN_6}; -const GpioPin gpio_ext_pa7 = {.port = GPIOA, .pin = LL_GPIO_PIN_7}; - -const GpioPin gpio_rfid_pull = {.port = RFID_PULL_GPIO_Port, .pin = RFID_PULL_Pin}; -const GpioPin gpio_rfid_carrier_out = {.port = RFID_OUT_GPIO_Port, .pin = RFID_OUT_Pin}; -const GpioPin gpio_rfid_data_in = {.port = RFID_RF_IN_GPIO_Port, .pin = RFID_RF_IN_Pin}; - -const GpioPin gpio_infrared_rx = {.port = IR_RX_GPIO_Port, .pin = IR_RX_Pin}; -const GpioPin gpio_infrared_tx = {.port = IR_TX_GPIO_Port, .pin = IR_TX_Pin}; - -const GpioPin gpio_usart_tx = {.port = USART1_TX_Port, .pin = USART1_TX_Pin}; -const GpioPin gpio_usart_rx = {.port = USART1_RX_Port, .pin = USART1_RX_Pin}; - -const GpioPin gpio_i2c_power_sda = {.port = GPIOA, .pin = LL_GPIO_PIN_10}; -const GpioPin gpio_i2c_power_scl = {.port = GPIOA, .pin = LL_GPIO_PIN_9}; diff --git a/bootloader/targets/f7/furi_hal/furi_hal_resources.h b/bootloader/targets/f7/furi_hal/furi_hal_resources.h deleted file mode 100644 index 925bd5ac..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_resources.h +++ /dev/null @@ -1,73 +0,0 @@ -#pragma once - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Input Keys */ -typedef enum { - InputKeyUp, - InputKeyDown, - InputKeyRight, - InputKeyLeft, - InputKeyOk, - InputKeyBack, -} InputKey; - -/* Light */ -typedef enum { - LightRed, - LightGreen, - LightBlue, - LightBacklight, -} Light; - -extern const GpioPin vibro_gpio; -extern const GpioPin ibutton_gpio; - -extern const GpioPin gpio_cc1101_g0; -extern const GpioPin gpio_rf_sw_0; - -extern const GpioPin gpio_subghz_cs; -extern const GpioPin gpio_display_cs; -extern const GpioPin gpio_display_rst; -extern const GpioPin gpio_display_di; -extern const GpioPin gpio_sdcard_cs; -extern const GpioPin gpio_nfc_cs; - -extern const GpioPin gpio_spi_d_miso; -extern const GpioPin gpio_spi_d_mosi; -extern const GpioPin gpio_spi_d_sck; -extern const GpioPin gpio_spi_r_miso; -extern const GpioPin gpio_spi_r_mosi; -extern const GpioPin gpio_spi_r_sck; - -extern const GpioPin gpio_ext_pc0; -extern const GpioPin gpio_ext_pc1; -extern const GpioPin gpio_ext_pc3; -extern const GpioPin gpio_ext_pb2; -extern const GpioPin gpio_ext_pb3; -extern const GpioPin gpio_ext_pa4; -extern const GpioPin gpio_ext_pa6; -extern const GpioPin gpio_ext_pa7; - -extern const GpioPin gpio_rfid_pull; -extern const GpioPin gpio_rfid_carrier_out; -extern const GpioPin gpio_rfid_data_in; - -extern const GpioPin gpio_infrared_rx; -extern const GpioPin gpio_infrared_tx; - -extern const GpioPin gpio_usart_tx; -extern const GpioPin gpio_usart_rx; - -extern const GpioPin gpio_i2c_power_sda; -extern const GpioPin gpio_i2c_power_scl; - -#ifdef __cplusplus -} -#endif diff --git a/bootloader/targets/f7/furi_hal/furi_hal_spi.c b/bootloader/targets/f7/furi_hal/furi_hal_spi.c deleted file mode 100644 index 85f2f71b..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_spi.c +++ /dev/null @@ -1,151 +0,0 @@ -#include "furi_hal_spi.h" -#include "furi_hal_resources.h" - -#include -#include -#include - -#include -#include -#include - -void furi_hal_spi_init() { - furi_hal_spi_bus_init(&furi_hal_spi_bus_r); - furi_hal_spi_bus_init(&furi_hal_spi_bus_d); - - furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_subghz); - furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_nfc); - furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_display); - furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_sd_fast); - furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_sd_slow); -} - -void furi_hal_spi_bus_init(FuriHalSpiBus* bus) { - assert(bus); - bus->callback(bus, FuriHalSpiBusEventInit); -} - -void furi_hal_spi_bus_deinit(FuriHalSpiBus* bus) { - assert(bus); - bus->callback(bus, FuriHalSpiBusEventDeinit); -} - -void furi_hal_spi_bus_handle_init(FuriHalSpiBusHandle* handle) { - assert(handle); - handle->callback(handle, FuriHalSpiBusHandleEventInit); -} - -void furi_hal_spi_bus_handle_deinit(FuriHalSpiBusHandle* handle) { - assert(handle); - handle->callback(handle, FuriHalSpiBusHandleEventDeinit); -} - -void furi_hal_spi_acquire(FuriHalSpiBusHandle* handle) { - assert(handle); - - handle->bus->callback(handle->bus, FuriHalSpiBusEventLock); - handle->bus->callback(handle->bus, FuriHalSpiBusEventActivate); - - assert(handle->bus->current_handle == NULL); - - handle->bus->current_handle = handle; - handle->callback(handle, FuriHalSpiBusHandleEventActivate); -} - -void furi_hal_spi_release(FuriHalSpiBusHandle* handle) { - assert(handle); - assert(handle->bus->current_handle == handle); - - // Handle event and unset handle - handle->callback(handle, FuriHalSpiBusHandleEventDeactivate); - handle->bus->current_handle = NULL; - - // Bus events - handle->bus->callback(handle->bus, FuriHalSpiBusEventDeactivate); - handle->bus->callback(handle->bus, FuriHalSpiBusEventUnlock); -} - -static void furi_hal_spi_bus_end_txrx(FuriHalSpiBusHandle* handle, uint32_t timeout) { - while(LL_SPI_GetTxFIFOLevel(handle->bus->spi) != LL_SPI_TX_FIFO_EMPTY) - ; - while(LL_SPI_IsActiveFlag_BSY(handle->bus->spi)) - ; - while(LL_SPI_GetRxFIFOLevel(handle->bus->spi) != LL_SPI_RX_FIFO_EMPTY) { - LL_SPI_ReceiveData8(handle->bus->spi); - } -} - -bool furi_hal_spi_bus_rx( - FuriHalSpiBusHandle* handle, - uint8_t* buffer, - size_t size, - uint32_t timeout) { - assert(handle); - assert(handle->bus->current_handle == handle); - assert(buffer); - assert(size > 0); - - return furi_hal_spi_bus_trx(handle, buffer, buffer, size, timeout); -} - -bool furi_hal_spi_bus_tx( - FuriHalSpiBusHandle* handle, - uint8_t* buffer, - size_t size, - uint32_t timeout) { - assert(handle); - assert(handle->bus->current_handle == handle); - assert(buffer); - assert(size > 0); - bool ret = true; - - while(size > 0) { - if(LL_SPI_IsActiveFlag_TXE(handle->bus->spi)) { - LL_SPI_TransmitData8(handle->bus->spi, *buffer); - buffer++; - size--; - } - } - - furi_hal_spi_bus_end_txrx(handle, timeout); - LL_SPI_ClearFlag_OVR(handle->bus->spi); - - return ret; -} - -bool furi_hal_spi_bus_trx( - FuriHalSpiBusHandle* handle, - uint8_t* tx_buffer, - uint8_t* rx_buffer, - size_t size, - uint32_t timeout) { - assert(handle); - assert(handle->bus->current_handle == handle); - assert(tx_buffer); - assert(rx_buffer); - assert(size > 0); - - bool ret = true; - size_t tx_size = size; - bool tx_allowed = true; - - while(size > 0) { - if(tx_size > 0 && LL_SPI_IsActiveFlag_TXE(handle->bus->spi) && tx_allowed) { - LL_SPI_TransmitData8(handle->bus->spi, *tx_buffer); - tx_buffer++; - tx_size--; - tx_allowed = false; - } - - if(LL_SPI_IsActiveFlag_RXNE(handle->bus->spi)) { - *rx_buffer = LL_SPI_ReceiveData8(handle->bus->spi); - rx_buffer++; - size--; - tx_allowed = true; - } - } - - furi_hal_spi_bus_end_txrx(handle, timeout); - - return ret; -} diff --git a/bootloader/targets/f7/furi_hal/furi_hal_spi_config.c b/bootloader/targets/f7/furi_hal/furi_hal_spi_config.c deleted file mode 100644 index a7c745cd..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_spi_config.c +++ /dev/null @@ -1,290 +0,0 @@ -#include -#include - -/* SPI Presets */ - -const LL_SPI_InitTypeDef furi_hal_spi_preset_2edge_low_8m = { - .Mode = LL_SPI_MODE_MASTER, - .TransferDirection = LL_SPI_FULL_DUPLEX, - .DataWidth = LL_SPI_DATAWIDTH_8BIT, - .ClockPolarity = LL_SPI_POLARITY_LOW, - .ClockPhase = LL_SPI_PHASE_2EDGE, - .NSS = LL_SPI_NSS_SOFT, - .BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV8, - .BitOrder = LL_SPI_MSB_FIRST, - .CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE, - .CRCPoly = 7, -}; - -const LL_SPI_InitTypeDef furi_hal_spi_preset_1edge_low_8m = { - .Mode = LL_SPI_MODE_MASTER, - .TransferDirection = LL_SPI_FULL_DUPLEX, - .DataWidth = LL_SPI_DATAWIDTH_8BIT, - .ClockPolarity = LL_SPI_POLARITY_LOW, - .ClockPhase = LL_SPI_PHASE_1EDGE, - .NSS = LL_SPI_NSS_SOFT, - .BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV8, - .BitOrder = LL_SPI_MSB_FIRST, - .CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE, - .CRCPoly = 7, -}; - -const LL_SPI_InitTypeDef furi_hal_spi_preset_1edge_low_4m = { - .Mode = LL_SPI_MODE_MASTER, - .TransferDirection = LL_SPI_FULL_DUPLEX, - .DataWidth = LL_SPI_DATAWIDTH_8BIT, - .ClockPolarity = LL_SPI_POLARITY_LOW, - .ClockPhase = LL_SPI_PHASE_1EDGE, - .NSS = LL_SPI_NSS_SOFT, - .BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV16, - .BitOrder = LL_SPI_MSB_FIRST, - .CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE, - .CRCPoly = 7, -}; - -const LL_SPI_InitTypeDef furi_hal_spi_preset_1edge_low_16m = { - .Mode = LL_SPI_MODE_MASTER, - .TransferDirection = LL_SPI_FULL_DUPLEX, - .DataWidth = LL_SPI_DATAWIDTH_8BIT, - .ClockPolarity = LL_SPI_POLARITY_LOW, - .ClockPhase = LL_SPI_PHASE_1EDGE, - .NSS = LL_SPI_NSS_SOFT, - .BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2, - .BitOrder = LL_SPI_MSB_FIRST, - .CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE, - .CRCPoly = 7, -}; - -const LL_SPI_InitTypeDef furi_hal_spi_preset_1edge_low_2m = { - .Mode = LL_SPI_MODE_MASTER, - .TransferDirection = LL_SPI_FULL_DUPLEX, - .DataWidth = LL_SPI_DATAWIDTH_8BIT, - .ClockPolarity = LL_SPI_POLARITY_LOW, - .ClockPhase = LL_SPI_PHASE_1EDGE, - .NSS = LL_SPI_NSS_SOFT, - .BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV32, - .BitOrder = LL_SPI_MSB_FIRST, - .CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE, - .CRCPoly = 7, -}; - -/* SPI Buses */ - -static void furi_hal_spi_bus_r_event_callback(FuriHalSpiBus* bus, FuriHalSpiBusEvent event) { - if(event == FuriHalSpiBusEventInit) { - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1); - LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_SPI1); - bus->current_handle = NULL; - } else if(event == FuriHalSpiBusEventDeinit) { - } else if(event == FuriHalSpiBusEventLock) { - } else if(event == FuriHalSpiBusEventUnlock) { - } else if(event == FuriHalSpiBusEventActivate) { - LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_SPI1); - } else if(event == FuriHalSpiBusEventDeactivate) { - LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_SPI1); - } -} - -FuriHalSpiBus furi_hal_spi_bus_r = { - .spi = SPI1, - .callback = furi_hal_spi_bus_r_event_callback, -}; - -static void furi_hal_spi_bus_d_event_callback(FuriHalSpiBus* bus, FuriHalSpiBusEvent event) { - if(event == FuriHalSpiBusEventInit) { - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2); - LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_SPI2); - bus->current_handle = NULL; - } else if(event == FuriHalSpiBusEventDeinit) { - } else if(event == FuriHalSpiBusEventLock) { - } else if(event == FuriHalSpiBusEventUnlock) { - } else if(event == FuriHalSpiBusEventActivate) { - LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_SPI2); - } else if(event == FuriHalSpiBusEventDeactivate) { - LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_SPI2); - } -} - -FuriHalSpiBus furi_hal_spi_bus_d = { - .spi = SPI2, - .callback = furi_hal_spi_bus_d_event_callback, -}; - -/* SPI Bus Handles */ - -inline static void furi_hal_spi_bus_r_handle_event_callback( - FuriHalSpiBusHandle* handle, - FuriHalSpiBusHandleEvent event, - const LL_SPI_InitTypeDef* preset) { - if(event == FuriHalSpiBusHandleEventInit) { - furi_hal_gpio_write(handle->cs, true); - furi_hal_gpio_init(handle->cs, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh); - } else if(event == FuriHalSpiBusHandleEventDeinit) { - furi_hal_gpio_write(handle->cs, true); - furi_hal_gpio_init(handle->cs, GpioModeAnalog, GpioPullNo, GpioSpeedLow); - } else if(event == FuriHalSpiBusHandleEventActivate) { - LL_SPI_Init(handle->bus->spi, (LL_SPI_InitTypeDef*)preset); - LL_SPI_SetRxFIFOThreshold(handle->bus->spi, LL_SPI_RX_FIFO_TH_QUARTER); - LL_SPI_Enable(handle->bus->spi); - - furi_hal_gpio_init_ex( - handle->miso, - GpioModeAltFunctionPushPull, - GpioPullNo, - GpioSpeedVeryHigh, - GpioAltFn5SPI1); - furi_hal_gpio_init_ex( - handle->mosi, - GpioModeAltFunctionPushPull, - GpioPullNo, - GpioSpeedVeryHigh, - GpioAltFn5SPI1); - furi_hal_gpio_init_ex( - handle->sck, - GpioModeAltFunctionPushPull, - GpioPullNo, - GpioSpeedVeryHigh, - GpioAltFn5SPI1); - - furi_hal_gpio_write(handle->cs, false); - } else if(event == FuriHalSpiBusHandleEventDeactivate) { - furi_hal_gpio_write(handle->cs, true); - - furi_hal_gpio_init(handle->miso, GpioModeAnalog, GpioPullNo, GpioSpeedLow); - furi_hal_gpio_init(handle->mosi, GpioModeAnalog, GpioPullNo, GpioSpeedLow); - furi_hal_gpio_init(handle->sck, GpioModeAnalog, GpioPullNo, GpioSpeedLow); - - LL_SPI_Disable(handle->bus->spi); - } -} - -static void furi_hal_spi_bus_handle_subghz_event_callback( - FuriHalSpiBusHandle* handle, - FuriHalSpiBusHandleEvent event) { - furi_hal_spi_bus_r_handle_event_callback(handle, event, &furi_hal_spi_preset_1edge_low_8m); -} - -FuriHalSpiBusHandle furi_hal_spi_bus_handle_subghz = { - .bus = &furi_hal_spi_bus_r, - .callback = furi_hal_spi_bus_handle_subghz_event_callback, - .miso = &gpio_spi_r_miso, - .mosi = &gpio_spi_r_mosi, - .sck = &gpio_spi_r_sck, - .cs = &gpio_subghz_cs, -}; - -static void furi_hal_spi_bus_handle_nfc_event_callback( - FuriHalSpiBusHandle* handle, - FuriHalSpiBusHandleEvent event) { - furi_hal_spi_bus_r_handle_event_callback(handle, event, &furi_hal_spi_preset_2edge_low_8m); -} - -FuriHalSpiBusHandle furi_hal_spi_bus_handle_nfc = { - .bus = &furi_hal_spi_bus_r, - .callback = furi_hal_spi_bus_handle_nfc_event_callback, - .miso = &gpio_spi_r_miso, - .mosi = &gpio_spi_r_mosi, - .sck = &gpio_spi_r_sck, - .cs = &gpio_nfc_cs, -}; - -static void furi_hal_spi_bus_handle_external_event_callback( - FuriHalSpiBusHandle* handle, - FuriHalSpiBusHandleEvent event) { - furi_hal_spi_bus_r_handle_event_callback(handle, event, &furi_hal_spi_preset_1edge_low_2m); -} - -FuriHalSpiBusHandle furi_hal_spi_bus_handle_external = { - .bus = &furi_hal_spi_bus_r, - .callback = furi_hal_spi_bus_handle_external_event_callback, - .miso = &gpio_ext_pa6, - .mosi = &gpio_ext_pa7, - .sck = &gpio_ext_pb3, - .cs = &gpio_ext_pa4, -}; - -inline static void furi_hal_spi_bus_d_handle_event_callback( - FuriHalSpiBusHandle* handle, - FuriHalSpiBusHandleEvent event, - const LL_SPI_InitTypeDef* preset) { - if(event == FuriHalSpiBusHandleEventInit) { - furi_hal_gpio_write(handle->cs, true); - furi_hal_gpio_init(handle->cs, GpioModeOutputPushPull, GpioPullUp, GpioSpeedVeryHigh); - - furi_hal_gpio_init_ex( - handle->miso, - GpioModeAltFunctionPushPull, - GpioPullNo, - GpioSpeedVeryHigh, - GpioAltFn5SPI2); - furi_hal_gpio_init_ex( - handle->mosi, - GpioModeAltFunctionPushPull, - GpioPullNo, - GpioSpeedVeryHigh, - GpioAltFn5SPI2); - furi_hal_gpio_init_ex( - handle->sck, - GpioModeAltFunctionPushPull, - GpioPullNo, - GpioSpeedVeryHigh, - GpioAltFn5SPI2); - - } else if(event == FuriHalSpiBusHandleEventDeinit) { - furi_hal_gpio_write(handle->cs, true); - furi_hal_gpio_init(handle->cs, GpioModeAnalog, GpioPullUp, GpioSpeedLow); - } else if(event == FuriHalSpiBusHandleEventActivate) { - LL_SPI_Init(handle->bus->spi, (LL_SPI_InitTypeDef*)preset); - LL_SPI_SetRxFIFOThreshold(handle->bus->spi, LL_SPI_RX_FIFO_TH_QUARTER); - LL_SPI_Enable(handle->bus->spi); - furi_hal_gpio_write(handle->cs, false); - } else if(event == FuriHalSpiBusHandleEventDeactivate) { - furi_hal_gpio_write(handle->cs, true); - LL_SPI_Disable(handle->bus->spi); - } -} - -static void furi_hal_spi_bus_handle_display_event_callback( - FuriHalSpiBusHandle* handle, - FuriHalSpiBusHandleEvent event) { - furi_hal_spi_bus_d_handle_event_callback(handle, event, &furi_hal_spi_preset_1edge_low_4m); -} - -FuriHalSpiBusHandle furi_hal_spi_bus_handle_display = { - .bus = &furi_hal_spi_bus_d, - .callback = furi_hal_spi_bus_handle_display_event_callback, - .miso = &gpio_spi_d_miso, - .mosi = &gpio_spi_d_mosi, - .sck = &gpio_spi_d_sck, - .cs = &gpio_display_cs, -}; - -static void furi_hal_spi_bus_handle_sd_fast_event_callback( - FuriHalSpiBusHandle* handle, - FuriHalSpiBusHandleEvent event) { - furi_hal_spi_bus_d_handle_event_callback(handle, event, &furi_hal_spi_preset_1edge_low_16m); -} - -FuriHalSpiBusHandle furi_hal_spi_bus_handle_sd_fast = { - .bus = &furi_hal_spi_bus_d, - .callback = furi_hal_spi_bus_handle_sd_fast_event_callback, - .miso = &gpio_spi_d_miso, - .mosi = &gpio_spi_d_mosi, - .sck = &gpio_spi_d_sck, - .cs = &gpio_sdcard_cs, -}; - -static void furi_hal_spi_bus_handle_sd_slow_event_callback( - FuriHalSpiBusHandle* handle, - FuriHalSpiBusHandleEvent event) { - furi_hal_spi_bus_d_handle_event_callback(handle, event, &furi_hal_spi_preset_1edge_low_2m); -} - -FuriHalSpiBusHandle furi_hal_spi_bus_handle_sd_slow = { - .bus = &furi_hal_spi_bus_d, - .callback = furi_hal_spi_bus_handle_sd_slow_event_callback, - .miso = &gpio_spi_d_miso, - .mosi = &gpio_spi_d_mosi, - .sck = &gpio_spi_d_sck, - .cs = &gpio_sdcard_cs, -}; diff --git a/bootloader/targets/f7/furi_hal/furi_hal_spi_config.h b/bootloader/targets/f7/furi_hal/furi_hal_spi_config.h deleted file mode 100644 index 3e4296a0..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_spi_config.h +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** Preset for ST25R916 */ -extern const LL_SPI_InitTypeDef furi_hal_spi_preset_2edge_low_8m; - -/** Preset for CC1101 */ -extern const LL_SPI_InitTypeDef furi_hal_spi_preset_1edge_low_8m; - -/** Preset for ST7567 (Display) */ -extern const LL_SPI_InitTypeDef furi_hal_spi_preset_1edge_low_4m; - -/** Preset for SdCard in fast mode */ -extern const LL_SPI_InitTypeDef furi_hal_spi_preset_1edge_low_16m; - -/** Preset for SdCard in slow mode */ -extern const LL_SPI_InitTypeDef furi_hal_spi_preset_1edge_low_2m; - -/** Furi Hal Spi Bus R (Radio: CC1101, Nfc, External)*/ -extern FuriHalSpiBus furi_hal_spi_bus_r; - -/** Furi Hal Spi Bus D (Display, SdCard) */ -extern FuriHalSpiBus furi_hal_spi_bus_d; - -/** CC1101 on `furi_hal_spi_bus_r` */ -extern FuriHalSpiBusHandle furi_hal_spi_bus_handle_subghz; - -/** ST25R3916 on `furi_hal_spi_bus_r` */ -extern FuriHalSpiBusHandle furi_hal_spi_bus_handle_nfc; - -/** External on `furi_hal_spi_bus_r` - * Preset: `furi_hal_spi_preset_1edge_low_2m` - * - * miso: pa6 - * mosi: pa7 - * sck: pb3 - * cs: pa4 (software controlled) - * - * @warning not initialized by default, call `furi_hal_spi_bus_handle_init` to initialize - * Bus pins are floating on inactive state, CS high after initialization - * - */ -extern FuriHalSpiBusHandle furi_hal_spi_bus_handle_external; - -/** ST7567(Display) on `furi_hal_spi_bus_d` */ -extern FuriHalSpiBusHandle furi_hal_spi_bus_handle_display; - -/** SdCard in fast mode on `furi_hal_spi_bus_d` */ -extern FuriHalSpiBusHandle furi_hal_spi_bus_handle_sd_fast; - -/** SdCard in slow mode on `furi_hal_spi_bus_d` */ -extern FuriHalSpiBusHandle furi_hal_spi_bus_handle_sd_slow; - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/bootloader/targets/f7/furi_hal/furi_hal_spi_types.h b/bootloader/targets/f7/furi_hal/furi_hal_spi_types.h deleted file mode 100644 index 1fb1c02b..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_spi_types.h +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once - -#include -#include - -#include - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct FuriHalSpiBus FuriHalSpiBus; -typedef struct FuriHalSpiBusHandle FuriHalSpiBusHandle; - -/** FuriHal spi bus states */ -typedef enum { - FuriHalSpiBusEventInit, /**< Bus initialization event, called on system start */ - FuriHalSpiBusEventDeinit, /**< Bus deinitialization event, called on system stop */ - FuriHalSpiBusEventLock, /**< Bus lock event, called before activation */ - FuriHalSpiBusEventUnlock, /**< Bus unlock event, called after deactivation */ - FuriHalSpiBusEventActivate, /**< Bus activation event, called before handle activation */ - FuriHalSpiBusEventDeactivate, /**< Bus deactivation event, called after handle deactivation */ -} FuriHalSpiBusEvent; - -/** FuriHal spi bus event callback */ -typedef void (*FuriHalSpiBusEventCallback)(FuriHalSpiBus* bus, FuriHalSpiBusEvent event); - -/** FuriHal spi bus */ -struct FuriHalSpiBus { - SPI_TypeDef* spi; - FuriHalSpiBusEventCallback callback; - FuriHalSpiBusHandle* current_handle; -}; - -/** FuriHal spi handle states */ -typedef enum { - FuriHalSpiBusHandleEventInit, /**< Handle init, called on system start, initialize gpio for idle state */ - FuriHalSpiBusHandleEventDeinit, /**< Handle deinit, called on system stop, deinitialize gpio for default state */ - FuriHalSpiBusHandleEventActivate, /**< Handle activate: connect gpio and apply bus config */ - FuriHalSpiBusHandleEventDeactivate, /**< Handle deactivate: disconnect gpio and reset bus config */ -} FuriHalSpiBusHandleEvent; - -/** FuriHal spi handle event callback */ -typedef void (*FuriHalSpiBusHandleEventCallback)( - FuriHalSpiBusHandle* handle, - FuriHalSpiBusHandleEvent event); - -/** FuriHal spi handle */ -struct FuriHalSpiBusHandle { - FuriHalSpiBus* bus; - FuriHalSpiBusHandleEventCallback callback; - const GpioPin* miso; - const GpioPin* mosi; - const GpioPin* sck; - const GpioPin* cs; -}; - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/bootloader/targets/f7/furi_hal/furi_hal_version.c b/bootloader/targets/f7/furi_hal/furi_hal_version.c deleted file mode 100644 index 5e2bead9..00000000 --- a/bootloader/targets/f7/furi_hal/furi_hal_version.c +++ /dev/null @@ -1,268 +0,0 @@ -#include - -#include -#include -#include - -#include - -#define FURI_HAL_VERSION_OTP_HEADER_MAGIC 0xBABE -#define FURI_HAL_VERSION_OTP_ADDRESS OTP_AREA_BASE - -/** OTP V0 Structure: prototypes and early EVT */ -typedef struct { - uint8_t board_version; - uint8_t board_target; - uint8_t board_body; - uint8_t board_connect; - uint32_t header_timestamp; - char name[FURI_HAL_VERSION_NAME_LENGTH]; -} FuriHalVersionOTPv0; - -/** OTP V1 Structure: late EVT, DVT */ -typedef struct { - /* First 64 bits: header */ - uint16_t header_magic; - uint8_t header_version; - uint8_t header_reserved; - uint32_t header_timestamp; - - /* Second 64 bits: board info */ - uint8_t board_version; /** Board version */ - uint8_t board_target; /** Board target firmware */ - uint8_t board_body; /** Board body */ - uint8_t board_connect; /** Board interconnect */ - uint8_t board_color; /** Board color */ - uint8_t board_region; /** Board region */ - uint16_t board_reserved; /** Reserved for future use, 0x0000 */ - - /* Third 64 bits: Unique Device Name */ - char name[FURI_HAL_VERSION_NAME_LENGTH]; /** Unique Device Name */ -} FuriHalVersionOTPv1; - -/** OTP V2 Structure: DVT2, PVT, Production */ -typedef struct { - /* Early First 64 bits: header */ - uint16_t header_magic; - uint8_t header_version; - uint8_t header_reserved; - uint32_t header_timestamp; - - /* Early Second 64 bits: board info */ - uint8_t board_version; /** Board version */ - uint8_t board_target; /** Board target firmware */ - uint8_t board_body; /** Board body */ - uint8_t board_connect; /** Board interconnect */ - uint8_t board_display; /** Board display */ - uint8_t board_reserved2_0; /** Reserved for future use, 0x00 */ - uint16_t board_reserved2_1; /** Reserved for future use, 0x0000 */ - - /* Late Third 64 bits: device info */ - uint8_t board_color; /** Board color */ - uint8_t board_region; /** Board region */ - uint16_t board_reserved3_0; /** Reserved for future use, 0x0000 */ - uint32_t board_reserved3_1; /** Reserved for future use, 0x00000000 */ - - /* Late Fourth 64 bits: Unique Device Name */ - char name[FURI_HAL_VERSION_NAME_LENGTH]; /** Unique Device Name */ -} FuriHalVersionOTPv2; - -/** Represenation Model: */ -typedef struct { - uint32_t timestamp; - - uint8_t board_version; /** Board version */ - uint8_t board_target; /** Board target firmware */ - uint8_t board_body; /** Board body */ - uint8_t board_connect; /** Board interconnect */ - uint8_t board_color; /** Board color */ - uint8_t board_region; /** Board region */ - uint8_t board_display; /** Board display */ - - char name[FURI_HAL_VERSION_ARRAY_NAME_LENGTH]; /** \0 terminated name */ - char device_name[FURI_HAL_VERSION_DEVICE_NAME_LENGTH]; /** device name for special needs */ - uint8_t ble_mac[6]; -} FuriHalVersion; - -static FuriHalVersion furi_hal_version = {0}; - -static void furi_hal_version_set_name(const char* name) { - furi_hal_version.device_name[0] = 0; -} - -static void furi_hal_version_load_otp_default() { - furi_hal_version_set_name(NULL); -} - -static void furi_hal_version_load_otp_v0() { - const FuriHalVersionOTPv0* otp = (FuriHalVersionOTPv0*)FURI_HAL_VERSION_OTP_ADDRESS; - - furi_hal_version.timestamp = otp->header_timestamp; - furi_hal_version.board_version = otp->board_version; - furi_hal_version.board_target = otp->board_target; - furi_hal_version.board_body = otp->board_body; - furi_hal_version.board_connect = otp->board_connect; - - furi_hal_version_set_name(otp->name); -} - -static void furi_hal_version_load_otp_v1() { - const FuriHalVersionOTPv1* otp = (FuriHalVersionOTPv1*)FURI_HAL_VERSION_OTP_ADDRESS; - - furi_hal_version.timestamp = otp->header_timestamp; - furi_hal_version.board_version = otp->board_version; - furi_hal_version.board_target = otp->board_target; - furi_hal_version.board_body = otp->board_body; - furi_hal_version.board_connect = otp->board_connect; - furi_hal_version.board_color = otp->board_color; - furi_hal_version.board_region = otp->board_region; - - furi_hal_version_set_name(otp->name); -} - -static void furi_hal_version_load_otp_v2() { - const FuriHalVersionOTPv2* otp = (FuriHalVersionOTPv2*)FURI_HAL_VERSION_OTP_ADDRESS; - - // 1st block, programmed afer baking - furi_hal_version.timestamp = otp->header_timestamp; - - // 2nd block, programmed afer baking - furi_hal_version.board_version = otp->board_version; - furi_hal_version.board_target = otp->board_target; - furi_hal_version.board_body = otp->board_body; - furi_hal_version.board_connect = otp->board_connect; - furi_hal_version.board_display = otp->board_display; - - // 3rd and 4th blocks, programmed on FATP stage - if(otp->board_color != 0xFF) { - furi_hal_version.board_color = otp->board_color; - furi_hal_version.board_region = otp->board_region; - furi_hal_version_set_name(otp->name); - } else { - furi_hal_version.board_color = 0; - furi_hal_version.board_region = 0; - furi_hal_version_set_name(NULL); - } -} - -void furi_hal_version_init() { - switch(furi_hal_version_get_otp_version()) { - case FuriHalVersionOtpVersionUnknown: - furi_hal_version_load_otp_default(); - break; - case FuriHalVersionOtpVersionEmpty: - furi_hal_version_load_otp_default(); - break; - case FuriHalVersionOtpVersion0: - furi_hal_version_load_otp_v0(); - break; - case FuriHalVersionOtpVersion1: - furi_hal_version_load_otp_v1(); - break; - case FuriHalVersionOtpVersion2: - furi_hal_version_load_otp_v2(); - break; - default: - furi_hal_version_load_otp_default(); - } -} - -bool furi_hal_version_do_i_belong_here() { - return furi_hal_version_get_hw_target() == 7; -} - -const char* furi_hal_version_get_model_name() { - return "Flipper Zero"; -} - -const FuriHalVersionOtpVersion furi_hal_version_get_otp_version() { - if(*(uint64_t*)FURI_HAL_VERSION_OTP_ADDRESS == 0xFFFFFFFF) { - return FuriHalVersionOtpVersionEmpty; - } else { - if(((FuriHalVersionOTPv1*)FURI_HAL_VERSION_OTP_ADDRESS)->header_magic == - FURI_HAL_VERSION_OTP_HEADER_MAGIC) { - // Version 1+ - uint8_t version = ((FuriHalVersionOTPv1*)FURI_HAL_VERSION_OTP_ADDRESS)->header_version; - if(version >= FuriHalVersionOtpVersion1 && version <= FuriHalVersionOtpVersion2) { - return version; - } else { - return FuriHalVersionOtpVersionUnknown; - } - } else if(((FuriHalVersionOTPv0*)FURI_HAL_VERSION_OTP_ADDRESS)->board_version <= 10) { - // Version 0 - return FuriHalVersionOtpVersion0; - } else { - // Version Unknown - return FuriHalVersionOtpVersionUnknown; - } - } -} - -const uint8_t furi_hal_version_get_hw_version() { - return furi_hal_version.board_version; -} - -const uint8_t furi_hal_version_get_hw_target() { - return furi_hal_version.board_target; -} - -const uint8_t furi_hal_version_get_hw_body() { - return furi_hal_version.board_body; -} - -const FuriHalVersionColor furi_hal_version_get_hw_color() { - return furi_hal_version.board_color; -} - -const uint8_t furi_hal_version_get_hw_connect() { - return furi_hal_version.board_connect; -} - -const FuriHalVersionRegion furi_hal_version_get_hw_region() { - return furi_hal_version.board_region; -} - -const FuriHalVersionDisplay furi_hal_version_get_hw_display() { - return furi_hal_version.board_display; -} - -const uint32_t furi_hal_version_get_hw_timestamp() { - return furi_hal_version.timestamp; -} - -const char* furi_hal_version_get_name_ptr() { - return *furi_hal_version.name == 0x00 ? NULL : furi_hal_version.name; -} - -const char* furi_hal_version_get_device_name_ptr() { - return furi_hal_version.device_name + 1; -} - -const char* furi_hal_version_get_ble_local_device_name_ptr() { - return furi_hal_version.device_name; -} - -const uint8_t* furi_hal_version_get_ble_mac() { - return furi_hal_version.ble_mac; -} - -const struct Version* furi_hal_version_get_firmware_version(void) { - return version_get(); -} - -const struct Version* furi_hal_version_get_bootloader_version(void) { -#ifdef NO_BOOTLOADER - return 0; -#else - /* Backup register which points to structure in flash memory */ - return (const struct Version*)LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR1); -#endif -} - -size_t furi_hal_version_uid_size() { - return 64 / 8; -} - -const uint8_t* furi_hal_version_uid() { - return (const uint8_t*)UID64_BASE; -} diff --git a/bootloader/targets/f7/furi_hal/main.h b/bootloader/targets/f7/furi_hal/main.h deleted file mode 100644 index 6b1d644d..00000000 --- a/bootloader/targets/f7/furi_hal/main.h +++ /dev/null @@ -1,108 +0,0 @@ -#pragma once - -#include -#include -#include - -#define BUTTON_BACK_GPIO_Port GPIOC -#define BUTTON_BACK_Pin LL_GPIO_PIN_13 -#define BUTTON_DOWN_GPIO_Port GPIOC -#define BUTTON_DOWN_Pin LL_GPIO_PIN_6 -#define BUTTON_LEFT_GPIO_Port GPIOB -#define BUTTON_LEFT_Pin LL_GPIO_PIN_11 -#define BUTTON_OK_GPIO_Port GPIOH -#define BUTTON_OK_Pin LL_GPIO_PIN_3 -#define BUTTON_RIGHT_GPIO_Port GPIOB -#define BUTTON_RIGHT_Pin LL_GPIO_PIN_12 -#define BUTTON_UP_GPIO_Port GPIOB -#define BUTTON_UP_Pin LL_GPIO_PIN_10 - -#define CC1101_CS_GPIO_Port GPIOD -#define CC1101_CS_Pin LL_GPIO_PIN_0 -#define CC1101_G0_GPIO_Port GPIOA -#define CC1101_G0_Pin LL_GPIO_PIN_1 - -#define DISPLAY_CS_GPIO_Port GPIOC -#define DISPLAY_CS_Pin LL_GPIO_PIN_11 -#define DISPLAY_DI_GPIO_Port GPIOB -#define DISPLAY_DI_Pin LL_GPIO_PIN_1 -#define DISPLAY_RST_GPIO_Port GPIOB -#define DISPLAY_RST_Pin LL_GPIO_PIN_0 - -#define IR_RX_GPIO_Port GPIOA -#define IR_RX_Pin LL_GPIO_PIN_0 -#define IR_TX_GPIO_Port GPIOB -#define IR_TX_Pin LL_GPIO_PIN_9 - -#define NFC_CS_GPIO_Port GPIOE -#define NFC_CS_Pin LL_GPIO_PIN_4 - -#define PA4_GPIO_Port GPIOA -#define PA4_Pin LL_GPIO_PIN_4 -#define PA6_GPIO_Port GPIOA -#define PA6_Pin LL_GPIO_PIN_6 -#define PA7_GPIO_Port GPIOA -#define PA7_Pin LL_GPIO_PIN_7 -#define PB2_GPIO_Port GPIOB -#define PB2_Pin LL_GPIO_PIN_2 -#define PB3_GPIO_Port GPIOB -#define PB3_Pin LL_GPIO_PIN_3 -#define PC0_GPIO_Port GPIOC -#define PC0_Pin LL_GPIO_PIN_0 -#define PC1_GPIO_Port GPIOC -#define PC1_Pin LL_GPIO_PIN_1 -#define PC3_GPIO_Port GPIOC -#define PC3_Pin LL_GPIO_PIN_3 - -#define PERIPH_POWER_GPIO_Port GPIOA -#define PERIPH_POWER_Pin LL_GPIO_PIN_3 - -#define QUARTZ_32MHZ_IN_GPIO_Port GPIOC -#define QUARTZ_32MHZ_IN_Pin LL_GPIO_PIN_14 -#define QUARTZ_32MHZ_OUT_GPIO_Port GPIOC -#define QUARTZ_32MHZ_OUT_Pin LL_GPIO_PIN_15 - -#define RFID_OUT_GPIO_Port GPIOB -#define RFID_OUT_Pin LL_GPIO_PIN_13 -#define RFID_PULL_GPIO_Port GPIOA -#define RFID_PULL_Pin LL_GPIO_PIN_2 -#define RFID_RF_IN_GPIO_Port GPIOC -#define RFID_RF_IN_Pin LL_GPIO_PIN_5 -#define RFID_TUNE_GPIO_Port GPIOA -#define RFID_TUNE_Pin LL_GPIO_PIN_8 - -#define RF_SW_0_GPIO_Port GPIOC -#define RF_SW_0_Pin LL_GPIO_PIN_4 - -#define SD_CD_GPIO_Port GPIOC -#define SD_CD_Pin LL_GPIO_PIN_10 -#define SD_CS_GPIO_Port GPIOC -#define SD_CS_Pin LL_GPIO_PIN_12 - -#define SPEAKER_GPIO_Port GPIOB -#define SPEAKER_Pin LL_GPIO_PIN_8 - -#define VIBRO_GPIO_Port GPIOA -#define VIBRO_Pin LL_GPIO_PIN_15 - -#define iBTN_GPIO_Port GPIOB -#define iBTN_Pin LL_GPIO_PIN_14 - -#define USART1_TX_Pin LL_GPIO_PIN_6 -#define USART1_TX_Port GPIOB -#define USART1_RX_Pin LL_GPIO_PIN_7 -#define USART1_RX_Port GPIOB - -#define SPI_D_MISO_GPIO_Port GPIOC -#define SPI_D_MISO_Pin LL_GPIO_PIN_2 -#define SPI_D_MOSI_GPIO_Port GPIOB -#define SPI_D_MOSI_Pin LL_GPIO_PIN_15 -#define SPI_D_SCK_GPIO_Port GPIOD -#define SPI_D_SCK_Pin LL_GPIO_PIN_1 - -#define SPI_R_MISO_GPIO_Port GPIOB -#define SPI_R_MISO_Pin LL_GPIO_PIN_4 -#define SPI_R_MOSI_GPIO_Port GPIOB -#define SPI_R_MOSI_Pin LL_GPIO_PIN_5 -#define SPI_R_SCK_GPIO_Port GPIOA -#define SPI_R_SCK_Pin LL_GPIO_PIN_5 diff --git a/bootloader/targets/f7/stm32wb55xx_flash_cm4.ld b/bootloader/targets/f7/stm32wb55xx_flash_cm4.ld deleted file mode 100644 index 6d3a78a2..00000000 --- a/bootloader/targets/f7/stm32wb55xx_flash_cm4.ld +++ /dev/null @@ -1,187 +0,0 @@ -/** -***************************************************************************** -** -** File : stm32wb55xx_flash_cm4.ld -** -** Abstract : System Workbench Minimal System calls file -** -** For more information about which c-functions -** need which of these lowlevel functions -** please consult the Newlib libc-manual -** -** Environment : System Workbench for MCU -** -** Distribution: The file is distributed “as is,” without any warranty -** of any kind. -** -***************************************************************************** -** -**

© COPYRIGHT(c) 2019 Ac6

-** -** Redistribution and use in source and binary forms, with or without modification, -** are permitted provided that the following conditions are met: -** 1. Redistributions of source code must retain the above copyright notice, -** this list of conditions and the following disclaimer. -** 2. Redistributions in binary form must reproduce the above copyright notice, -** this list of conditions and the following disclaimer in the documentation -** and/or other materials provided with the distribution. -** 3. Neither the name of Ac6 nor the names of its contributors -** may be used to endorse or promote products derived from this software -** without specific prior written permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -** -***************************************************************************** -*/ - -/* Entry Point */ -ENTRY(Reset_Handler) - -/* Highest address of the user mode stack */ -_estack = 0x20030000; /* end of RAM */ -/* Generate a link error if heap and stack don't fit into RAM */ -_Min_Heap_Size = 0x200; /* required amount of heap */ -_Min_Stack_Size = 0x400; /* required amount of stack */ - -/* Specify the memory areas */ -MEMORY -{ -FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K -RAM1 (xrw) : ORIGIN = 0x20000008, LENGTH = 0x2FFF8 -RAM_SHARED (xrw) : ORIGIN = 0x20030000, LENGTH = 10K -} - -/* Define output sections */ -SECTIONS -{ - /* The startup code goes first into FLASH */ - .isr_vector : - { - . = ALIGN(4); - KEEP(*(.isr_vector)) /* Startup code */ - . = ALIGN(4); - } >FLASH - - /* The program code and other data goes into FLASH */ - .text : - { - . = ALIGN(4); - *(.text) /* .text sections (code) */ - *(.text*) /* .text* sections (code) */ - *(.glue_7) /* glue arm to thumb code */ - *(.glue_7t) /* glue thumb to arm code */ - *(.eh_frame) - - KEEP (*(.init)) - KEEP (*(.fini)) - - . = ALIGN(4); - _etext = .; /* define a global symbols at end of code */ - } >FLASH - - /* Constant data goes into FLASH */ - .rodata : - { - . = ALIGN(4); - *(.rodata) /* .rodata sections (constants, strings, etc.) */ - *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ - . = ALIGN(4); - } >FLASH - - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH - .ARM : { - __exidx_start = .; - *(.ARM.exidx*) - __exidx_end = .; - } >FLASH - - .preinit_array : - { - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP (*(.preinit_array*)) - PROVIDE_HIDDEN (__preinit_array_end = .); - } >FLASH - .init_array : - { - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array*)) - PROVIDE_HIDDEN (__init_array_end = .); - } >FLASH - .fini_array : - { - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP (*(SORT(.fini_array.*))) - KEEP (*(.fini_array*)) - PROVIDE_HIDDEN (__fini_array_end = .); - } >FLASH - - /* used by the startup to initialize data */ - _sidata = LOADADDR(.data); - - /* Initialized data sections goes into RAM, load LMA copy after code */ - .data : - { - . = ALIGN(4); - _sdata = .; /* create a global symbol at data start */ - *(.data) /* .data sections */ - *(.data*) /* .data* sections */ - - . = ALIGN(4); - _edata = .; /* define a global symbol at data end */ - } >RAM1 AT> FLASH - - - /* Uninitialized data section */ - . = ALIGN(4); - .bss : - { - /* This is used by the startup in order to initialize the .bss secion */ - _sbss = .; /* define a global symbol at bss start */ - __bss_start__ = _sbss; - *(.bss) - *(.bss*) - *(COMMON) - - . = ALIGN(4); - _ebss = .; /* define a global symbol at bss end */ - __bss_end__ = _ebss; - } >RAM1 - - /* User_heap_stack section, used to check that there is enough RAM left */ - ._user_heap_stack : - { - . = ALIGN(8); - PROVIDE ( end = . ); - PROVIDE ( _end = . ); - . = . + _Min_Heap_Size; - . = . + _Min_Stack_Size; - . = ALIGN(8); - } >RAM1 - - - - /* Remove information from the standard libraries */ - /DISCARD/ : - { - libc.a ( * ) - libm.a ( * ) - libgcc.a ( * ) - } - - .ARM.attributes 0 : { *(.ARM.attributes) } - MAPPING_TABLE (NOLOAD) : { *(MAPPING_TABLE) } >RAM_SHARED - MB_MEM1 (NOLOAD) : { *(MB_MEM1) } >RAM_SHARED - MB_MEM2 (NOLOAD) : { _sMB_MEM2 = . ; *(MB_MEM2) ; _eMB_MEM2 = . ; } >RAM_SHARED -} - - diff --git a/bootloader/targets/f7/target.c b/bootloader/targets/f7/target.c deleted file mode 100644 index 58eace9c..00000000 --- a/bootloader/targets/f7/target.c +++ /dev/null @@ -1,264 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -const uint8_t I_DFU_128x50[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x38, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0xC0, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8F, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x7F, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x75, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x0A, 0x00, 0x00, 0x0F, 0x60, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0x0F, 0x00, 0xC0, 0xE0, 0x4F, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x18, 0x00, 0x30, 0x1E, 0x90, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x18, 0x00, 0x8C, 0x01, 0xA0, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x81, 0xFF, 0x19, 0x00, 0x63, 0x00, 0xC0, 0xF0, 0x07, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x5E, 0x1F, 0x80, 0x18, 0x00, 0xE0, 0x0E, 0x18, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x18, 0xAF, 0x0F, 0x40, 0x06, 0x00, 0xF8, 0x01, 0x20, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x06, 0x57, 0x01, 0x20, 0x01, 0x00, 0x78, 0x00, 0x3E, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x81, 0xAF, 0x02, 0x90, 0x00, 0x00, 0x38, 0x80, 0x41, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x80, 0x57, 0x01, 0x48, 0x00, 0x00, 0x10, 0x60, 0x40, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x10, 0x80, 0xAB, 0x00, 0x24, 0x00, 0x00, 0x08, 0x10, 0x40, - 0x3F, 0x00, 0x00, 0x00, 0x00, 0x38, 0x0C, 0xC0, 0x57, 0x01, 0x12, 0x00, 0x00, 0x04, 0x08, 0x40, - 0xC0, 0x0F, 0x00, 0x00, 0xC0, 0x07, 0x03, 0xF0, 0xAB, 0x00, 0x0A, 0x00, 0x00, 0x02, 0x04, 0x40, - 0x00, 0xF0, 0x1F, 0x80, 0x3F, 0xC0, 0x00, 0xFC, 0x55, 0x01, 0x05, 0xE0, 0x00, 0x01, 0x04, 0x40, - 0x00, 0x00, 0xE0, 0x7F, 0x00, 0x30, 0x00, 0xFF, 0xAB, 0x00, 0x05, 0xE0, 0x80, 0x00, 0x02, 0x40, - 0x0F, 0x00, 0x00, 0x00, 0x80, 0x0F, 0xE0, 0xCF, 0x55, 0x81, 0x02, 0xF0, 0x40, 0x00, 0x02, 0x40, - 0xF0, 0x0F, 0x00, 0x00, 0x7F, 0x00, 0xFE, 0xC3, 0xAB, 0x80, 0x02, 0x78, 0x20, 0x00, 0x01, 0x40, - 0x00, 0xF0, 0xFF, 0xFF, 0x00, 0xF0, 0xFF, 0xC0, 0xD5, 0x81, 0x01, 0x7E, 0x10, 0x80, 0x00, 0x20, - 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x0F, 0xE0, 0xFA, 0x83, 0xC1, 0x3F, 0x08, 0x80, 0x00, 0x20, - 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x01, 0xD8, 0x07, 0x83, 0xF1, 0x1F, 0x04, 0x40, 0x00, 0x20, - 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x0F, 0x80, 0xC7, 0x01, 0x83, 0xF1, 0x0F, 0x00, 0x20, 0x00, 0x10, - 0xE0, 0xFF, 0xFF, 0xFF, 0x3F, 0xC0, 0x7F, 0x40, 0x80, 0x83, 0xE1, 0x01, 0x00, 0x20, 0x00, 0x18, - 0xFC, 0xFF, 0xFF, 0xFF, 0x03, 0x3F, 0x00, 0x20, 0xFC, 0x83, 0x01, 0x00, 0x00, 0x10, 0x00, 0x18, - 0xFF, 0xFF, 0xFF, 0x3F, 0xF0, 0x00, 0x00, 0x10, 0xD7, 0x01, 0x03, 0x00, 0x00, 0x08, 0x00, 0x1C, - 0xFF, 0xFF, 0x01, 0x00, 0x0F, 0x00, 0x00, 0x88, 0xAB, 0x02, 0xE3, 0x01, 0x00, 0x08, 0x00, 0x0C, - 0xFF, 0x07, 0x00, 0xE0, 0x00, 0x00, 0x00, 0xC4, 0x55, 0x05, 0x1E, 0x00, 0x00, 0x04, 0x00, 0x0E, - 0x7F, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0xA3, 0xAB, 0x02, 0x06, 0x00, 0x00, 0x02, 0x00, 0x0F, - 0x0F, 0x00, 0x80, 0x03, 0x00, 0x00, 0xC0, 0x10, 0x57, 0x05, 0x02, 0x00, 0x00, 0x01, 0x80, 0x07, - 0x03, 0x00, 0x70, 0x00, 0x00, 0x00, 0x30, 0x08, 0xAB, 0x0A, 0x02, 0x00, 0xC0, 0x00, 0xC0, 0x07, - 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x0C, 0x84, 0x57, 0x15, 0x01, 0x00, 0x30, 0x00, 0xE0, 0x07, - 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0xC3, 0xFF, 0x2A, 0x01, 0x00, 0x0C, 0x00, 0xF0, 0x0F, - 0x00, 0xC0, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0xE0, 0xFE, 0x55, 0x01, 0x82, 0x03, 0x00, 0xF8, 0x15, - 0x00, 0x30, 0x00, 0x00, 0x00, 0x1C, 0x30, 0x78, 0xFE, 0xAA, 0x01, 0x7C, 0x00, 0x00, 0xFC, 0x23, - 0x00, 0x0E, 0x00, 0x00, 0xC0, 0x03, 0x0C, 0x3C, 0x7F, 0x5D, 0x01, 0x00, 0x00, 0x00, 0xFF, 0x45, - 0xC0, 0x01, 0x00, 0x00, 0x3E, 0x00, 0x02, 0x8F, 0xBF, 0xAE, 0x03, 0x00, 0x00, 0xC0, 0xFF, 0x82, - 0x30, 0x00, 0x00, 0xC0, 0x01, 0x80, 0xC1, 0x43, 0xFE, 0x5D, 0x01, 0x00, 0x00, 0xF0, 0xFF, 0x05, - 0x0F, 0x00, 0x80, 0x3F, 0x00, 0x60, 0xF0, 0x31, 0xF6, 0xAE, 0x03, 0x00, 0x00, 0xFA, 0xAF, 0x02, - 0xFC, 0xFF, 0x7F, 0x00, 0x00, 0x18, 0x7C, 0x08, 0x23, 0xFF, 0x05, 0x00, 0x00, 0xFD, 0x55, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x1F, 0x84, 0x30, 0xFE, 0x0A, 0x00, 0x00, 0xAA, 0xAA, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x80, 0xF1, 0x07, 0x43, 0x18, 0xFF, 0x15, 0x00, 0x00, 0x54, 0x15, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 0x80, 0x20, 0x8C, 0xFF, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, -}; - -// Boot request enum -#define BOOT_REQUEST_TAINTED 0x00000000 -#define BOOT_REQUEST_CLEAN 0xDADEDADE -#define BOOT_REQUEST_DFU 0xDF00B000 -// Boot to DFU pin -#define BOOT_DFU_PORT GPIOB -#define BOOT_DFU_PIN LL_GPIO_PIN_11 -// USB pins -#define BOOT_USB_PORT GPIOA -#define BOOT_USB_DM_PIN LL_GPIO_PIN_11 -#define BOOT_USB_DP_PIN LL_GPIO_PIN_12 -#define BOOT_USB_PIN (BOOT_USB_DM_PIN | BOOT_USB_DP_PIN) - -#define RTC_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady()) - -void target_led_control(char* c) { - furi_hal_light_set(LightRed, 0x00); - furi_hal_light_set(LightGreen, 0x00); - furi_hal_light_set(LightBlue, 0x00); - do { - if(*c == 'R') { - furi_hal_light_set(LightRed, 0xFF); - } else if(*c == 'G') { - furi_hal_light_set(LightGreen, 0xFF); - } else if(*c == 'B') { - furi_hal_light_set(LightBlue, 0xFF); - } else if(*c == '.') { - LL_mDelay(125); - furi_hal_light_set(LightRed, 0x00); - furi_hal_light_set(LightGreen, 0x00); - furi_hal_light_set(LightBlue, 0x00); - LL_mDelay(125); - } else if(*c == '-') { - LL_mDelay(250); - furi_hal_light_set(LightRed, 0x00); - furi_hal_light_set(LightGreen, 0x00); - furi_hal_light_set(LightBlue, 0x00); - LL_mDelay(250); - } else if(*c == '|') { - furi_hal_light_set(LightRed, 0x00); - furi_hal_light_set(LightGreen, 0x00); - furi_hal_light_set(LightBlue, 0x00); - } - c++; - } while(*c != 0); -} - -void target_clock_init() { - LL_Init1msTick(4000000); - LL_SetSystemCoreClock(4000000); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOE); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOH); - - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1); - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2); -} - -void target_gpio_init() { - // USB D+ - LL_GPIO_SetPinMode(BOOT_USB_PORT, BOOT_USB_DP_PIN, LL_GPIO_MODE_OUTPUT); - LL_GPIO_SetPinSpeed(BOOT_USB_PORT, BOOT_USB_DP_PIN, LL_GPIO_SPEED_FREQ_VERY_HIGH); - LL_GPIO_SetPinOutputType(BOOT_USB_PORT, BOOT_USB_DP_PIN, LL_GPIO_OUTPUT_OPENDRAIN); - // USB D- - LL_GPIO_SetPinMode(BOOT_USB_PORT, BOOT_USB_DM_PIN, LL_GPIO_MODE_OUTPUT); - LL_GPIO_SetPinSpeed(BOOT_USB_PORT, BOOT_USB_DM_PIN, LL_GPIO_SPEED_FREQ_VERY_HIGH); - LL_GPIO_SetPinOutputType(BOOT_USB_PORT, BOOT_USB_DM_PIN, LL_GPIO_OUTPUT_OPENDRAIN); - // Button: back - LL_GPIO_SetPinMode(BOOT_DFU_PORT, BOOT_DFU_PIN, LL_GPIO_MODE_INPUT); - LL_GPIO_SetPinPull(BOOT_DFU_PORT, BOOT_DFU_PIN, LL_GPIO_PULL_UP); -} - -void target_rtc_init() { - // LSE and RTC - LL_PWR_EnableBkUpAccess(); - if(!RTC_CLOCK_IS_READY()) { - // Start LSI1 needed for CSS - LL_RCC_LSI1_Enable(); - // Try to start LSE normal way - LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_HIGH); - LL_RCC_LSE_Enable(); - uint32_t c = 0; - while(!RTC_CLOCK_IS_READY() && c < 200) { - LL_mDelay(10); - c++; - } - // Plan B: reset backup domain - if(!RTC_CLOCK_IS_READY()) { - target_led_control("-R.R.R."); - LL_RCC_ForceBackupDomainReset(); - LL_RCC_ReleaseBackupDomainReset(); - NVIC_SystemReset(); - } - // Set RTC domain clock to LSE - LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE); - // Enable LSE CSS - LL_RCC_LSE_EnableCSS(); - } - // Enable clocking - LL_RCC_EnableRTC(); - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTCAPB); -} - -void target_version_save(void) { - LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR1, (uint32_t)version_get()); -} - -void target_usb_wire_reset() { - LL_GPIO_ResetOutputPin(BOOT_USB_PORT, BOOT_USB_PIN); -} - -void target_display_init() { - // Prepare gpio - furi_hal_gpio_init_simple(&gpio_display_rst, GpioModeOutputPushPull); - furi_hal_gpio_init_simple(&gpio_display_di, GpioModeOutputPushPull); - // Initialize - u8g2_t fb; - u8g2_Setup_st756x_flipper(&fb, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32); - u8g2_InitDisplay(&fb); - // Create payload - u8g2_ClearBuffer(&fb); - u8g2_SetDrawColor(&fb, 0x01); - u8g2_DrawXBM(&fb, 0, 64 - 50, 128, 50, I_DFU_128x50); -#ifndef SLIM_BOOTLOADER - u8g2_SetFont(&fb, u8g2_font_helvB08_tf); - u8g2_DrawStr(&fb, 2, 8, "Update & Recovery Mode"); - u8g2_DrawStr(&fb, 2, 21, "DFU started"); -#endif - // Send buffer - u8g2_SetPowerSave(&fb, 0); - u8g2_SendBuffer(&fb); -} - -void target_init() { - target_clock_init(); - target_gpio_init(); - furi_hal_init(); - target_led_control("RGB"); - target_rtc_init(); - target_version_save(); - target_usb_wire_reset(); - - // Errata 2.2.9, Flash OPTVERR flag is always set after system reset - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); -} - -int target_is_dfu_requested() { - if(LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR0) == BOOT_REQUEST_TAINTED) { - // Default system state is tainted - // We must ensure that MCU is cleanly booted - LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_CLEAN); - NVIC_SystemReset(); - } else if(LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR0) == BOOT_REQUEST_DFU) { - return 1; - } - LL_mDelay(100); - if(!LL_GPIO_IsInputPinSet(BOOT_DFU_PORT, BOOT_DFU_PIN)) { - return 1; - } - - return 0; -} - -void target_switch(void* offset) { - asm volatile("ldr r3, [%0] \n" - "msr msp, r3 \n" - "ldr r3, [%1] \n" - "mov pc, r3 \n" - : - : "r"(offset), "r"(offset + 0x4) - : "r3"); -} - -void target_switch2dfu() { - target_led_control("B"); - furi_hal_light_set(LightBacklight, 0xFF); - target_display_init(); - // Mark system as tainted, it will be soon - LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_TAINTED); - // Remap memory to system bootloader - LL_SYSCFG_SetRemapMemory(LL_SYSCFG_REMAP_SYSTEMFLASH); - // Jump - target_switch(0x0); -} - -void target_switch2os() { - target_led_control("G"); - SCB->VTOR = OS_OFFSET; - target_switch((void*)(BOOT_ADDRESS + OS_OFFSET)); -} diff --git a/bootloader/targets/f7/target.mk b/bootloader/targets/f7/target.mk deleted file mode 100644 index 72677daf..00000000 --- a/bootloader/targets/f7/target.mk +++ /dev/null @@ -1,50 +0,0 @@ -TOOLCHAIN = arm - -BOOT_ADDRESS = 0x08000000 -FW_ADDRESS = 0x08008000 -OS_OFFSET = 0x00008000 -FLASH_ADDRESS = 0x08000000 - -OPENOCD_OPTS = -f interface/stlink.cfg -c "transport select hla_swd" -f ../debug/stm32wbx.cfg -c "init" -BOOT_CFLAGS = -DBOOT_ADDRESS=$(BOOT_ADDRESS) -DFW_ADDRESS=$(FW_ADDRESS) -DOS_OFFSET=$(OS_OFFSET) -MCU_FLAGS = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard - -CFLAGS += $(MCU_FLAGS) $(BOOT_CFLAGS) -DSTM32WB55xx -Wall -fdata-sections -ffunction-sections -LDFLAGS += $(MCU_FLAGS) -specs=nosys.specs -specs=nano.specs - -HARDWARE_TARGET = 7 - -CUBE_DIR = $(PROJECT_ROOT)/lib/STM32CubeWB - -# ST HAL -CFLAGS += -DUSE_FULL_LL_DRIVER -ASM_SOURCES += $(CUBE_DIR)/Drivers/CMSIS/Device/ST/STM32WBxx/Source/Templates/gcc/startup_stm32wb55xx_cm4.s -C_SOURCES += $(CUBE_DIR)/Drivers/CMSIS/Device/ST/STM32WBxx/Source/Templates/system_stm32wbxx.c -C_SOURCES += $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_utils.c -C_SOURCES += $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_gpio.c -C_SOURCES += $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_i2c.c -C_SOURCES += $(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_spi.c - -CFLAGS += -I$(CUBE_DIR)/Drivers/CMSIS/Include -CFLAGS += -I$(CUBE_DIR)/Drivers/CMSIS/Device/ST/STM32WBxx/Include -CFLAGS += -I$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Inc - -LDFLAGS += -T$(TARGET_DIR)/stm32wb55xx_flash_cm4.ld - -# Drivers -DRIVERS_DIR = $(PROJECT_ROOT)//lib/drivers -CFLAGS += -I$(DRIVERS_DIR) -C_SOURCES += $(DRIVERS_DIR)/lp5562.c - -# API-HAL -CFLAGS += -I$(TARGET_DIR)/furi_hal -C_SOURCES += $(wildcard $(TARGET_DIR)/furi_hal/*.c) - -# Version generation -C_SOURCES += $(PROJECT_ROOT)/lib/toolbox/version.c - -ASM_SOURCES += $(wildcard $(TARGET_DIR)/*.s) -C_SOURCES += $(wildcard $(TARGET_DIR)/*.c) -CPP_SOURCES += $(wildcard $(TARGET_DIR)/*.cpp) - -SVD_FILE = $(PROJECT_ROOT)/debug/STM32WB55_CM4.svd diff --git a/bootloader/targets/furi_hal_include/furi_hal.h b/bootloader/targets/furi_hal_include/furi_hal.h deleted file mode 100644 index 5d612566..00000000 --- a/bootloader/targets/furi_hal_include/furi_hal.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#define furi_assert(value) (void)(value) - -void furi_hal_init(); - -void furi_hal_delay_ms(float milliseconds); - -void furi_hal_delay_us(float microseconds); diff --git a/bootloader/targets/furi_hal_include/furi_hal_spi.h b/bootloader/targets/furi_hal_include/furi_hal_spi.h deleted file mode 100644 index be31727f..00000000 --- a/bootloader/targets/furi_hal_include/furi_hal_spi.h +++ /dev/null @@ -1,102 +0,0 @@ -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** Initialize SPI HAL */ -void furi_hal_spi_init(); - -/** Initialize SPI Bus - * - * @param handle pointer to FuriHalSpiBus instance - */ -void furi_hal_spi_bus_init(FuriHalSpiBus* bus); - -/** Deinitialize SPI Bus - * - * @param handle pointer to FuriHalSpiBus instance - */ -void furi_hal_spi_bus_deinit(FuriHalSpiBus* bus); - -/** Initialize SPI Bus Handle - * - * @param handle pointer to FuriHalSpiBusHandle instance - */ -void furi_hal_spi_bus_handle_init(FuriHalSpiBusHandle* handle); - -/** Deinitialize SPI Bus Handle - * - * @param handle pointer to FuriHalSpiBusHandle instance - */ -void furi_hal_spi_bus_handle_deinit(FuriHalSpiBusHandle* handle); - -/** Acquire SPI bus - * - * @warning blocking, calls `furi_crash` on programming error, CS transition is up to handler event routine - * - * @param handle pointer to FuriHalSpiBusHandle instance - */ -void furi_hal_spi_acquire(FuriHalSpiBusHandle* handle); - -/** Release SPI bus - * - * @warning calls `furi_crash` on programming error, CS transition is up to handler event routine - * - * @param handle pointer to FuriHalSpiBusHandle instance - */ -void furi_hal_spi_release(FuriHalSpiBusHandle* handle); - -/** SPI Receive - * - * @param handle pointer to FuriHalSpiBusHandle instance - * @param buffer receive buffer - * @param size transaction size (buffer size) - * @param timeout operation timeout in ms - * - * @return true on sucess - */ -bool furi_hal_spi_bus_rx( - FuriHalSpiBusHandle* handle, - uint8_t* buffer, - size_t size, - uint32_t timeout); - -/** SPI Transmit - * - * @param handle pointer to FuriHalSpiBusHandle instance - * @param buffer transmit buffer - * @param size transaction size (buffer size) - * @param timeout operation timeout in ms - * - * @return true on success - */ -bool furi_hal_spi_bus_tx( - FuriHalSpiBusHandle* handle, - uint8_t* buffer, - size_t size, - uint32_t timeout); - -/** SPI Transmit and Receive - * - * @param handle pointer to FuriHalSpiBusHandle instance - * @param tx_buffer pointer to tx buffer - * @param rx_buffer pointer to rx buffer - * @param size transaction size (buffer size) - * @param timeout operation timeout in ms - * - * @return true on success - */ -bool furi_hal_spi_bus_trx( - FuriHalSpiBusHandle* handle, - uint8_t* tx_buffer, - uint8_t* rx_buffer, - size_t size, - uint32_t timeout); - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/bootloader/targets/furi_hal_include/furi_hal_version.h b/bootloader/targets/furi_hal_include/furi_hal_version.h deleted file mode 100644 index 62f0147f..00000000 --- a/bootloader/targets/furi_hal_include/furi_hal_version.h +++ /dev/null @@ -1,173 +0,0 @@ -/** - * @file furi_hal_version.h - * Version HAL API - */ - -#pragma once - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define FURI_HAL_VERSION_NAME_LENGTH 8 -#define FURI_HAL_VERSION_ARRAY_NAME_LENGTH (FURI_HAL_VERSION_NAME_LENGTH + 1) -/** BLE symbol + "Flipper " + name */ -#define FURI_HAL_VERSION_DEVICE_NAME_LENGTH (1 + 8 + FURI_HAL_VERSION_ARRAY_NAME_LENGTH) - -/** OTP Versions enum */ -typedef enum { - FuriHalVersionOtpVersion0 = 0x00, - FuriHalVersionOtpVersion1 = 0x01, - FuriHalVersionOtpVersion2 = 0x02, - FuriHalVersionOtpVersionEmpty = 0xFFFFFFFE, - FuriHalVersionOtpVersionUnknown = 0xFFFFFFFF, -} FuriHalVersionOtpVersion; - -/** Device Colors */ -typedef enum { - FuriHalVersionColorUnknown = 0x00, - FuriHalVersionColorBlack = 0x01, - FuriHalVersionColorWhite = 0x02, -} FuriHalVersionColor; - -/** Device Regions */ -typedef enum { - FuriHalVersionRegionUnknown = 0x00, - FuriHalVersionRegionEuRu = 0x01, - FuriHalVersionRegionUsCaAu = 0x02, - FuriHalVersionRegionJp = 0x03, -} FuriHalVersionRegion; - -/** Device Display */ -typedef enum { - FuriHalVersionDisplayUnknown = 0x00, - FuriHalVersionDisplayErc = 0x01, - FuriHalVersionDisplayMgg = 0x02, -} FuriHalVersionDisplay; - -/** Init flipper version - */ -void furi_hal_version_init(); - -/** Check target firmware version - * - * @return true if target and real matches - */ -bool furi_hal_version_do_i_belong_here(); - -/** Get model name - * - * @return model name C-string - */ -const char* furi_hal_version_get_model_name(); - -/** Get OTP version - * - * @return OTP Version - */ -const FuriHalVersionOtpVersion furi_hal_version_get_otp_version(); - -/** Get hardware version - * - * @return Hardware Version - */ -const uint8_t furi_hal_version_get_hw_version(); - -/** Get hardware target - * - * @return Hardware Target - */ -const uint8_t furi_hal_version_get_hw_target(); - -/** Get hardware body - * - * @return Hardware Body - */ -const uint8_t furi_hal_version_get_hw_body(); - -/** Get hardware body color - * - * @return Hardware Color - */ -const FuriHalVersionColor furi_hal_version_get_hw_color(); - -/** Get hardware connect - * - * @return Hardware Interconnect - */ -const uint8_t furi_hal_version_get_hw_connect(); - -/** Get hardware region - * - * @return Hardware Region - */ -const FuriHalVersionRegion furi_hal_version_get_hw_region(); - -/** Get hardware display id - * - * @return Display id - */ -const FuriHalVersionDisplay furi_hal_version_get_hw_display(); - -/** Get hardware timestamp - * - * @return Hardware Manufacture timestamp - */ -const uint32_t furi_hal_version_get_hw_timestamp(); - -/** Get pointer to target name - * - * @return Hardware Name C-string - */ -const char* furi_hal_version_get_name_ptr(); - -/** Get pointer to target device name - * - * @return Hardware Device Name C-string - */ -const char* furi_hal_version_get_device_name_ptr(); - -/** Get pointer to target ble local device name - * - * @return Ble Device Name C-string - */ -const char* furi_hal_version_get_ble_local_device_name_ptr(); - -/** Get BLE MAC address - * - * @return pointer to BLE MAC address - */ -const uint8_t* furi_hal_version_get_ble_mac(); - -/** Get address of version structure of bootloader, stored in chip flash. - * - * @return Address of boot version structure. - */ -const struct Version* furi_hal_version_get_bootloader_version(); - -/** Get address of version structure of firmware. - * - * @return Address of firmware version structure. - */ -const struct Version* furi_hal_version_get_firmware_version(); - -/** Get platform UID size in bytes - * - * @return UID size in bytes - */ -size_t furi_hal_version_uid_size(); - -/** Get const pointer to UID - * - * @return pointer to UID - */ -const uint8_t* furi_hal_version_uid(); - -#ifdef __cplusplus -} -#endif diff --git a/bootloader/targets/furi_hal_include/target.h b/bootloader/targets/furi_hal_include/target.h deleted file mode 100644 index e16d4f78..00000000 --- a/bootloader/targets/furi_hal_include/target.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef TARGET_H -#define TARGET_H - -/** - * Initialize hardware -*/ -void target_init(); - -/** - * Check if dfu mode requested - * @return 1 if dfu mode requested, 0 if not - */ -int target_is_dfu_requested(); - -/** - * Switch to dfu mode - */ -void target_switch2dfu(); - -/** - * Switch to OS - */ -void target_switch2os(); - -#endif \ No newline at end of file diff --git a/core/flipper.c b/core/flipper.c index c7190b3b..c7d7c5a6 100755 --- a/core/flipper.c +++ b/core/flipper.c @@ -11,13 +11,14 @@ static void flipper_print_version(const char* target, const Version* version) { TAG, "\r\n\t%s version:\t%s\r\n" "\tBuild date:\t\t%s\r\n" - "\tGit Commit:\t\t%s (%s)\r\n" + "\tGit Commit:\t\t%s (%s)%s\r\n" "\tGit Branch:\t\t%s", target, version_get_version(version), version_get_builddate(version), version_get_githash(version), version_get_gitbranchnum(version), + version_get_dirty_flag(version) ? " (dirty)" : "", version_get_gitbranch(version)); } else { FURI_LOG_I(TAG, "No build info for %s", target); @@ -25,13 +26,7 @@ static void flipper_print_version(const char* target, const Version* version) { } void flipper_init() { - const Version* version; - - version = (const Version*)furi_hal_version_get_bootloader_version(); - flipper_print_version("Bootloader", version); - - version = (const Version*)furi_hal_version_get_firmware_version(); - flipper_print_version("Firmware", version); + flipper_print_version("Firmware", furi_hal_version_get_firmware_version()); FURI_LOG_I(TAG, "starting services"); diff --git a/core/furi.c b/core/furi.c index 09c5851d..edee1592 100644 --- a/core/furi.c +++ b/core/furi.c @@ -1,7 +1,13 @@ #include "furi.h" void furi_init() { + osKernelInitialize(); + furi_log_init(); furi_record_init(); furi_stdglue_init(); } + +void furi_run() { + osKernelStart(); +} diff --git a/core/furi.h b/core/furi.h index 1844ec9a..6a0d1b0a 100644 --- a/core/furi.h +++ b/core/furi.h @@ -27,6 +27,8 @@ extern "C" { void furi_init(); +void furi_run(); + #ifdef __cplusplus } #endif diff --git a/core/furi/check.c b/core/furi/check.c index fafddd91..5ea76614 100644 --- a/core/furi/check.c +++ b/core/furi/check.c @@ -21,20 +21,21 @@ void __furi_print_name() { } } -void __furi_halt() { +static FURI_NORETURN void __furi_halt() { asm volatile( #ifdef FURI_DEBUG "bkpt 0x00 \n" #endif - "loop: \n" + "loop%=: \n" "wfi \n" - "b loop \n" + "b loop%= \n" : : : "memory"); + __builtin_unreachable(); } -void furi_crash(const char* message) { +FURI_NORETURN void furi_crash(const char* message) { __disable_irq(); if(message == NULL) { @@ -54,9 +55,10 @@ void furi_crash(const char* message) { furi_hal_console_puts("\033[0m\r\n"); furi_hal_power_reset(); #endif + __builtin_unreachable(); } -void furi_halt(const char* message) { +FURI_NORETURN void furi_halt(const char* message) { __disable_irq(); if(message == NULL) { @@ -69,4 +71,4 @@ void furi_halt(const char* message) { furi_hal_console_puts("\r\nSystem halted. Bye-bye!\r\n"); furi_hal_console_puts("\033[0m\r\n"); __furi_halt(); -} +} \ No newline at end of file diff --git a/core/furi/check.h b/core/furi/check.h index b4b66815..adea4039 100644 --- a/core/furi/check.h +++ b/core/furi/check.h @@ -1,7 +1,10 @@ #pragma once - #ifdef __cplusplus extern "C" { +#define FURI_NORETURN [[noreturn]] +#else +#include +#define FURI_NORETURN noreturn #endif /** Check condition and crash if check failed */ @@ -15,10 +18,10 @@ extern "C" { #endif /** Crash system */ -void furi_crash(const char* message); +FURI_NORETURN void furi_crash(const char* message); /** Halt system */ -void furi_halt(const char* message); +FURI_NORETURN void furi_halt(const char* message); #ifdef __cplusplus } diff --git a/core/furi/common_defines.h b/core/furi/common_defines.h index 38e60315..9c4f7b18 100644 --- a/core/furi/common_defines.h +++ b/core/furi/common_defines.h @@ -101,18 +101,20 @@ extern "C" { #endif #ifndef FURI_IS_ISR -#define FURI_IS_ISR() \ - (FURI_IS_IRQ_MODE() || (FURI_IS_IRQ_MASKED() && (osKernelGetState() == osKernelRunning))) +#define FURI_IS_ISR() (FURI_IS_IRQ_MODE() || FURI_IS_IRQ_MASKED()) #endif #ifndef FURI_CRITICAL_ENTER -#define FURI_CRITICAL_ENTER() \ - uint32_t __isrm = 0; \ - bool __from_isr = FURI_IS_ISR(); \ - if(__from_isr) { \ - __isrm = taskENTER_CRITICAL_FROM_ISR(); \ - } else { \ - taskENTER_CRITICAL(); \ +#define FURI_CRITICAL_ENTER() \ + uint32_t __isrm = 0; \ + bool __from_isr = FURI_IS_ISR(); \ + bool __kernel_running = (osKernelGetState() == osKernelRunning); \ + if(__from_isr) { \ + __isrm = taskENTER_CRITICAL_FROM_ISR(); \ + } else if(__kernel_running) { \ + taskENTER_CRITICAL(); \ + } else { \ + __disable_irq(); \ } #endif @@ -120,8 +122,10 @@ extern "C" { #define FURI_CRITICAL_EXIT() \ if(__from_isr) { \ taskEXIT_CRITICAL_FROM_ISR(__isrm); \ - } else { \ + } else if(__kernel_running) { \ taskEXIT_CRITICAL(); \ + } else { \ + __enable_irq(); \ } #endif diff --git a/core/furi/memmgr.c b/core/furi/memmgr.c index f7a24a76..457520d9 100644 --- a/core/furi/memmgr.c +++ b/core/furi/memmgr.c @@ -4,6 +4,7 @@ extern void* pvPortMalloc(size_t xSize); extern void vPortFree(void* pv); extern size_t xPortGetFreeHeapSize(void); +extern size_t xPortGetTotalHeapSize(void); extern size_t xPortGetMinimumEverFreeHeapSize(void); void* malloc(size_t size) { @@ -50,6 +51,10 @@ size_t memmgr_get_free_heap(void) { return xPortGetFreeHeapSize(); } +size_t memmgr_get_total_heap(void) { + return xPortGetTotalHeapSize(); +} + size_t memmgr_get_minimum_free_heap(void) { return xPortGetMinimumEverFreeHeapSize(); } diff --git a/core/furi/memmgr.h b/core/furi/memmgr.h index b749c8e5..d7285fb2 100644 --- a/core/furi/memmgr.h +++ b/core/furi/memmgr.h @@ -23,6 +23,12 @@ extern "C" { */ size_t memmgr_get_free_heap(void); +/** Get total heap size + * + * @return total heap size in bytes + */ +size_t memmgr_get_total_heap(void); + /** Get heap watermark * * @return minimum heap in bytes diff --git a/core/furi/memmgr_heap.c b/core/furi/memmgr_heap.c index d40da870..9455371e 100644 --- a/core/furi/memmgr_heap.c +++ b/core/furi/memmgr_heap.c @@ -526,6 +526,11 @@ void vPortFree(void* pv) { } /*-----------------------------------------------------------*/ +size_t xPortGetTotalHeapSize(void) { + return (size_t)&__heap_end__ - (size_t)&__heap_start__; +} +/*-----------------------------------------------------------*/ + size_t xPortGetFreeHeapSize(void) { return xFreeBytesRemaining; } diff --git a/core/furi/record.h b/core/furi/record.h index 2d5f2c49..cb4bd199 100644 --- a/core/furi/record.h +++ b/core/furi/record.h @@ -49,7 +49,7 @@ bool furi_record_destroy(const char* name); * * @return pointer to the record * @note Thread safe. Open and close must be executed from the same - * thread. Suspends caller thread till record appear + * thread. Suspends caller thread till record is available */ void* furi_record_open(const char* name); diff --git a/core/furi/thread.c b/core/furi/thread.c index de86cbdc..ee86f62e 100644 --- a/core/furi/thread.c +++ b/core/furi/thread.c @@ -30,7 +30,7 @@ void furi_thread_set_state(FuriThread* thread, FuriThreadState state) { } } -void furi_thread_body(void* context) { +static void furi_thread_body(void* context) { furi_assert(context); FuriThread* thread = context; @@ -167,3 +167,9 @@ size_t furi_thread_get_heap_size(FuriThread* thread) { furi_assert(thread->heap_trace_enabled == true); return thread->heap_size; } + +int32_t furi_thread_get_return_code(FuriThread* thread) { + furi_assert(thread); + furi_assert(thread->state == FuriThreadStateStopped); + return thread->ret; +} diff --git a/core/furi/thread.h b/core/furi/thread.h index 50342517..ea1da27a 100644 --- a/core/furi/thread.h +++ b/core/furi/thread.h @@ -150,6 +150,14 @@ void furi_thread_disable_heap_trace(FuriThread* thread); */ size_t furi_thread_get_heap_size(FuriThread* thread); +/** Get thread return code + * + * @param thread FuriThread instance + * + * @return return code + */ +int32_t furi_thread_get_return_code(FuriThread* thread); + #ifdef __cplusplus } -#endif +#endif \ No newline at end of file diff --git a/firmware/Makefile b/firmware/Makefile index 3237ed59..efa185ca 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -1,6 +1,5 @@ MAKEFILE_DIR := $(dir $(abspath $(firstword $(MAKEFILE_LIST)))) PROJECT_ROOT := $(abspath $(MAKEFILE_DIR)/..) -PROJECT := firmware include $(PROJECT_ROOT)/make/base.mk include $(PROJECT_ROOT)/make/freertos-heap.mk @@ -17,6 +16,12 @@ include $(PROJECT_ROOT)/make/defaults.mk TARGET_DIR = targets/$(TARGET) include $(TARGET_DIR)/target.mk +ifeq ($(RAM_EXEC), 0) +PROJECT := firmware +else +PROJECT := updater +endif + include $(PROJECT_ROOT)/make/git.mk include $(PROJECT_ROOT)/make/toolchain.mk include $(PROJECT_ROOT)/make/rules.mk diff --git a/firmware/ReadMe.md b/firmware/ReadMe.md index 237adae9..f12f2e7b 100644 --- a/firmware/ReadMe.md +++ b/firmware/ReadMe.md @@ -1,6 +1,6 @@ # Flipper firmware -What it does? +What does it do? - [x] RTOS - [x] FuriHAL @@ -10,13 +10,13 @@ What it does? # Targets -| Name | Bootloader | Firmware | Reset | DFU | -| | Address | Address | Combo | Combo | ------------------------------------------------------------------------------ -| f7 | 0x08000000 | 0x00008000 | L+Back | L+Back, hold L | +| Name | Firmware | Reset | DFU | +| | Address | Combo | Combo | +--------------------------------------------------------------------------------- +| f7 | 0x08000000 | L+Back, release both | L+Back, release Back | -Also there is a ST bootloader combo available on empty device: L+Ok+Back, release Back,Left. -Target independent code and headers in `target/include` folders. +Also there is a "hardware" ST bootloader combo available even on a bricked or empty device: L+Ok+Back, release Back, Left. +Target independent code and headers in `target/include` folders. More details in `documentation/KeyCombo.md` # Building @@ -31,7 +31,9 @@ Target independent code and headers in `target/include` folders. ## Build Options - `DEBUG` - 0/1 - enable or disable debug build. Default is 1. +- `COMPACT` - 0/1 - enable or disable compiler optimizations. Significantly reduces binary size. Default is 0. - `TARGET` - string - target to build. Default is `f7`. +- `RAM_EXEC` - 0/1 - whether to build full firmware or RAM-based stage for firmware update. 0 is default, builds firmware. # Flashing diff --git a/firmware/targets/f7/Inc/FreeRTOSConfig.h b/firmware/targets/f7/Inc/FreeRTOSConfig.h index ee56922b..f0944cb7 100644 --- a/firmware/targets/f7/Inc/FreeRTOSConfig.h +++ b/firmware/targets/f7/Inc/FreeRTOSConfig.h @@ -30,7 +30,7 @@ extern uint32_t SystemCoreClock; #define configUSE_16_BIT_TICKS 0 #define configUSE_MUTEXES 1 #define configQUEUE_REGISTRY_SIZE 8 -#define configCHECK_FOR_STACK_OVERFLOW 1 +#define configCHECK_FOR_STACK_OVERFLOW 2 #define configUSE_RECURSIVE_MUTEXES 1 #define configUSE_COUNTING_SEMAPHORES 1 #define configENABLE_BACKWARD_COMPATIBILITY 0 @@ -124,11 +124,13 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ /* Normal assert() semantics without relying on the provision of an assert.h header file. */ +#ifdef DEBUG #include #define configASSERT(x) \ if((x) == 0) { \ furi_crash("FreeRTOS Assert"); \ } +#endif /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS standard names. */ diff --git a/firmware/targets/f7/Inc/alt_boot.h b/firmware/targets/f7/Inc/alt_boot.h new file mode 100644 index 00000000..91bf9bdf --- /dev/null +++ b/firmware/targets/f7/Inc/alt_boot.h @@ -0,0 +1,13 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +void flipper_boot_update_exec(); + +void flipper_boot_dfu_exec(); + +#ifdef __cplusplus +} +#endif diff --git a/firmware/targets/f7/Src/dfu.c b/firmware/targets/f7/Src/dfu.c new file mode 100644 index 00000000..889c3c1e --- /dev/null +++ b/firmware/targets/f7/Src/dfu.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include + +void flipper_boot_dfu_show_splash() { + // Initialize + furi_hal_compress_icon_init(); + + u8g2_t* fb = malloc(sizeof(u8g2_t)); + memset(fb, 0, sizeof(u8g2_t)); + u8g2_Setup_st756x_flipper(fb, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32); + u8g2_InitDisplay(fb); + u8g2_SetDrawColor(fb, 0x01); + uint8_t* splash_data = NULL; + furi_hal_compress_icon_decode(icon_get_data(&I_DFU_128x50), &splash_data); + u8g2_DrawXBM(fb, 0, 64 - 50, 128, 50, splash_data); + u8g2_SetFont(fb, u8g2_font_helvB08_tr); + u8g2_DrawStr(fb, 2, 8, "Update & Recovery Mode"); + u8g2_DrawStr(fb, 2, 21, "DFU started"); + u8g2_SetPowerSave(fb, 0); + u8g2_SendBuffer(fb); +} + +void flipper_boot_dfu_exec() { + // Show DFU splashscreen + flipper_boot_dfu_show_splash(); + + // Errata 2.2.9, Flash OPTVERR flag is always set after system reset + WRITE_REG(FLASH->SR, FLASH_SR_OPTVERR); + + // Cleanup before jumping to DFU + furi_hal_deinit_early(); + + // Remap memory to system bootloader + LL_SYSCFG_SetRemapMemory(LL_SYSCFG_REMAP_SYSTEMFLASH); + // Jump + furi_hal_switch(0x0); +} diff --git a/firmware/targets/f7/Src/main.c b/firmware/targets/f7/Src/main.c index 2dcaab92..2e3bf04f 100644 --- a/firmware/targets/f7/Src/main.c +++ b/firmware/targets/f7/Src/main.c @@ -1,29 +1,85 @@ #include #include #include +#include +#include #define TAG "Main" -int main(void) { - // Flipper critical FURI HAL - furi_hal_init_critical(); - +#ifdef FURI_RAM_EXEC +int main() { // Initialize FURI layer furi_init(); + // Flipper critical FURI HAL + furi_hal_init_early(); + // Flipper FURI HAL furi_hal_init(); - // CMSIS initialization - osKernelInitialize(); - FURI_LOG_I(TAG, "KERNEL OK"); - // Init flipper flipper_init(); - // Start kernel - osKernelStart(); + furi_run(); while(1) { } } +#else +int main() { + // Initialize FURI layer + furi_init(); + + // Flipper critical FURI HAL + furi_hal_init_early(); + furi_hal_light_sequence("RGB"); + + // Delay is for button sampling + furi_hal_delay_ms(100); + + FuriHalRtcBootMode boot_mode = furi_hal_rtc_get_boot_mode(); + if(boot_mode == FuriHalRtcBootModeDfu || !furi_hal_gpio_read(&gpio_button_left)) { + furi_hal_light_sequence("rgb WB"); + furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); + flipper_boot_dfu_exec(); + furi_hal_power_reset(); + } else if(boot_mode == FuriHalRtcBootModeUpdate) { + furi_hal_light_sequence("rgb BR"); + flipper_boot_update_exec(); + // if things go nice, we shouldn't reach this point. + // But if we do, abandon to avoid bootloops + furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); + furi_hal_power_reset(); + } else { + furi_hal_light_sequence("rgb G"); + + // Flipper FURI HAL + furi_hal_init(); + + // Init flipper + flipper_init(); + + furi_run(); + } + + while(1) { + } +} +#endif + +void Error_Handler(void) { + furi_crash("ErrorHandler"); +} + +#ifdef USE_FULL_ASSERT +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ +void assert_failed(uint8_t* file, uint32_t line) { + furi_crash("HAL assert failed"); +} +#endif /* USE_FULL_ASSERT */ diff --git a/firmware/targets/f7/Src/system_stm32wbxx.c b/firmware/targets/f7/Src/system_stm32wbxx.c index 9fc52ca7..77430fda 100644 --- a/firmware/targets/f7/Src/system_stm32wbxx.c +++ b/firmware/targets/f7/Src/system_stm32wbxx.c @@ -1,15 +1,15 @@ #include "stm32wbxx.h" -/*!< Uncomment the following line if you need to relocate your vector Table in - Internal SRAM. */ +/*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ + +#ifndef VECT_TAB_OFFSET #define VECT_TAB_OFFSET \ - OS_OFFSET /*!< Vector Table base offset field. - This value must be a multiple of 0x200. */ + 0x0 /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ +#endif #define VECT_TAB_BASE_ADDRESS \ - SRAM1_BASE /*!< Vector Table base offset field. - This value must be a multiple of 0x200. */ + SRAM1_BASE /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /* The SystemCoreClock variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() diff --git a/firmware/targets/f7/Src/update.c b/firmware/targets/f7/Src/update.c new file mode 100644 index 00000000..3e94fbec --- /dev/null +++ b/firmware/targets/f7/Src/update.c @@ -0,0 +1,196 @@ +#include +#include +#include +#include + +#include +#include + +#include +#include + +static FATFS* pfs = NULL; + +static const char FS_ROOT_PATH[] = "/"; + +#define CHECK_FRESULT(result) \ + { \ + if((result) != FR_OK) { \ + return false; \ + } \ + } + +static bool flipper_update_init() { + furi_hal_clock_init(); + furi_hal_rtc_init(); + furi_hal_interrupt_init(); + furi_hal_delay_init(); + + furi_hal_spi_init(); + furi_hal_crc_init(false); + + MX_FATFS_Init(); + if(!hal_sd_detect()) { + return false; + } + + if(BSP_SD_Init(true)) { + return false; + } + + pfs = malloc(sizeof(FATFS)); + CHECK_FRESULT(f_mount(pfs, FS_ROOT_PATH, 1)); + return true; +} + +static bool flipper_update_load_stage(const string_t work_dir, UpdateManifest* manifest) { + FIL file; + FILINFO stat; + + string_t loader_img_path; + string_init_set(loader_img_path, work_dir); + path_append(loader_img_path, string_get_cstr(manifest->staged_loader_file)); + + if((f_stat(string_get_cstr(loader_img_path), &stat) != FR_OK) || + (f_open(&file, string_get_cstr(loader_img_path), FA_OPEN_EXISTING | FA_READ) != FR_OK)) { + string_clear(loader_img_path); + return false; + } + string_clear(loader_img_path); + + void* img = malloc(stat.fsize); + uint32_t bytes_read = 0; + const uint16_t MAX_READ = 0xFFFF; + + furi_hal_crc_reset(); + uint32_t crc = 0; + do { + uint16_t size_read = 0; + if(f_read(&file, img + bytes_read, MAX_READ, &size_read) != FR_OK) { + break; + } + crc = furi_hal_crc_feed(img + bytes_read, size_read); + bytes_read += size_read; + } while(bytes_read == MAX_READ); + furi_hal_crc_reset(); + + do { + if((bytes_read != stat.fsize) || (crc != manifest->staged_loader_crc)) { + break; + } + + /* Point of no return. Literally + * + * NB: we MUST disable IRQ, otherwise handlers from flash + * will change global variables (like tick count) + * that are located in .data. And we move staged loader + * to the same memory region. So, IRQ handlers will mess up + * memmove'd .text section and ruin your day. + * We don't want that to happen. + */ + __disable_irq(); + + memmove((void*)(SRAM1_BASE), img, stat.fsize); + LL_SYSCFG_SetRemapMemory(LL_SYSCFG_REMAP_SRAM); + furi_hal_switch((void*)SRAM1_BASE); + return true; + + } while(false); + + free(img); + return false; +} + +static bool flipper_update_get_work_directory(string_t out_dir) { + const uint32_t update_index = furi_hal_rtc_get_register(FuriHalRtcRegisterUpdateFolderFSIndex); + if(update_index == 0) { + string_set(out_dir, UPDATE_DIR_DEFAULT_REL_PATH); + return true; + } + + DIR dir; + UINT entry_idx = 0; + FILINFO fno; + CHECK_FRESULT(f_opendir(&dir, UPDATE_DIR_DEFAULT_REL_PATH)); + string_set(out_dir, UPDATE_DIR_DEFAULT_REL_PATH); + + while(f_readdir(&dir, &fno) == FR_OK) { + entry_idx++; + if(fno.fname[0] == '\0') { + return false; + } + if(entry_idx == update_index) { + path_append(out_dir, fno.fname); + return true; + } + } + + string_reset(out_dir); + return false; +} + +static UpdateManifest* flipper_update_process_manifest(const string_t work_dir) { + FIL file; + FILINFO stat; + + string_t manifest_path; + string_init_set(manifest_path, work_dir); + path_append(manifest_path, UPDATE_MANIFEST_DEFAULT_NAME); + + CHECK_FRESULT(f_stat(string_get_cstr(manifest_path), &stat)); + CHECK_FRESULT(f_open(&file, string_get_cstr(manifest_path), FA_OPEN_EXISTING | FA_READ)); + + uint8_t* manifest_data = malloc(stat.fsize); + uint32_t bytes_read = 0; + const uint16_t MAX_READ = 0xFFFF; + + do { + uint16_t size_read = 0; + if(f_read(&file, manifest_data + bytes_read, MAX_READ, &size_read) != FR_OK) { + break; + } + bytes_read += size_read; + } while(bytes_read == MAX_READ); + + UpdateManifest* manifest = NULL; + do { + if(bytes_read != stat.fsize) { + break; + } + + manifest = update_manifest_alloc(); + if(!update_manifest_init_mem(manifest, manifest_data, bytes_read)) { + update_manifest_free(manifest); + manifest = NULL; + } + } while(false); + + string_clear(manifest_path); + free(manifest_data); + return manifest; +} + +void flipper_boot_update_exec() { + if(!flipper_update_init()) { + return; + } + + string_t work_dir; + string_init(work_dir); + do { + if(!flipper_update_get_work_directory(work_dir)) { + break; + } + + UpdateManifest* manifest = flipper_update_process_manifest(work_dir); + if(!manifest) { + break; + } + + if(!flipper_update_load_stage(work_dir, manifest)) { + update_manifest_free(manifest); + } + } while(false); + string_clear(work_dir); + free(pfs); +} diff --git a/firmware/targets/f7/cube/Inc/FreeRTOSConfig.h b/firmware/targets/f7/cube/Inc/FreeRTOSConfig.h deleted file mode 100644 index 47883e66..00000000 --- a/firmware/targets/f7/cube/Inc/FreeRTOSConfig.h +++ /dev/null @@ -1,193 +0,0 @@ -/* USER CODE BEGIN Header */ -/* - * FreeRTOS Kernel V10.3.1 - * Portion Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * Portion Copyright (C) 2019 StMicroelectronics, Inc. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://www.FreeRTOS.org - * http://aws.amazon.com/freertos - * - * 1 tab == 4 spaces! - */ -/* USER CODE END Header */ - -#ifndef FREERTOS_CONFIG_H -#define FREERTOS_CONFIG_H - -/*----------------------------------------------------------- - * Application specific definitions. - * - * These definitions should be adjusted for your particular hardware and - * application requirements. - * - * These parameters and more are described within the 'configuration' section of the - * FreeRTOS API documentation available on the FreeRTOS.org web site. - * - * See http://www.freertos.org/a00110.html - *----------------------------------------------------------*/ - -/* USER CODE BEGIN Includes */ -/* Section where include file can be added */ -/* USER CODE END Includes */ - -/* Ensure definitions are only used by the compiler, and not by the assembler. */ -#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) -#include -extern uint32_t SystemCoreClock; -void xPortSysTickHandler(void); -/* USER CODE BEGIN 0 */ -extern void configureTimerForRunTimeStats(void); -extern unsigned long getRunTimeCounterValue(void); -/* USER CODE END 0 */ -#endif -#ifndef CMSIS_device_header -#define CMSIS_device_header "stm32wbxx.h" -#endif /* CMSIS_device_header */ - -#define configENABLE_FPU 1 -#define configENABLE_MPU 0 - -#define configUSE_PREEMPTION 1 -#define configSUPPORT_STATIC_ALLOCATION 1 -#define configSUPPORT_DYNAMIC_ALLOCATION 1 -#define configUSE_IDLE_HOOK 1 -#define configUSE_TICK_HOOK 0 -#define configCPU_CLOCK_HZ (SystemCoreClock) -#define configTICK_RATE_HZ ((TickType_t)1000) -#define configMAX_PRIORITIES (56) -#define configMINIMAL_STACK_SIZE ((uint16_t)128) -#define configTOTAL_HEAP_SIZE ((size_t)40960) -#define configMAX_TASK_NAME_LEN (16) -#define configGENERATE_RUN_TIME_STATS 1 -#define configUSE_TRACE_FACILITY 1 -#define configUSE_16_BIT_TICKS 0 -#define configUSE_MUTEXES 1 -#define configQUEUE_REGISTRY_SIZE 8 -#define configCHECK_FOR_STACK_OVERFLOW 1 -#define configUSE_RECURSIVE_MUTEXES 1 -#define configUSE_COUNTING_SEMAPHORES 1 -#define configENABLE_BACKWARD_COMPATIBILITY 0 -#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 -#define configUSE_TICKLESS_IDLE 2 -#define configRECORD_STACK_HIGH_ADDRESS 1 -/* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */ -/* Defaults to size_t for backward compatibility, but can be changed - if lengths will always be less than the number of bytes in a size_t. */ -#define configMESSAGE_BUFFER_LENGTH_TYPE size_t -/* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */ - -/* Co-routine definitions. */ -#define configUSE_CO_ROUTINES 0 -#define configMAX_CO_ROUTINE_PRIORITIES (2) - -/* Software timer definitions. */ -#define configUSE_TIMERS 1 -#define configTIMER_TASK_PRIORITY (2) -#define configTIMER_QUEUE_LENGTH 10 -#define configTIMER_TASK_STACK_DEPTH 256 - -/* CMSIS-RTOS V2 flags */ -#define configUSE_OS2_THREAD_SUSPEND_RESUME 1 -#define configUSE_OS2_THREAD_ENUMERATE 1 -#define configUSE_OS2_EVENTFLAGS_FROM_ISR 1 -#define configUSE_OS2_THREAD_FLAGS 1 -#define configUSE_OS2_TIMER 1 -#define configUSE_OS2_MUTEX 1 - -/* Set the following definitions to 1 to include the API function, or zero -to exclude the API function. */ -#define INCLUDE_vTaskPrioritySet 1 -#define INCLUDE_uxTaskPriorityGet 1 -#define INCLUDE_vTaskDelete 1 -#define INCLUDE_vTaskCleanUpResources 1 -#define INCLUDE_vTaskSuspend 1 -#define INCLUDE_vTaskDelayUntil 1 -#define INCLUDE_vTaskDelay 1 -#define INCLUDE_xTaskGetSchedulerState 1 -#define INCLUDE_xTimerPendFunctionCall 1 -#define INCLUDE_xQueueGetMutexHolder 1 -#define INCLUDE_uxTaskGetStackHighWaterMark 1 -#define INCLUDE_xTaskGetCurrentTaskHandle 1 -#define INCLUDE_eTaskGetState 1 - -/* - * The CMSIS-RTOS V2 FreeRTOS wrapper is dependent on the heap implementation used - * by the application thus the correct define need to be enabled below - */ -#define USE_FreeRTOS_HEAP_4 - -/* Cortex-M specific definitions. */ -#ifdef __NVIC_PRIO_BITS -/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ -#define configPRIO_BITS __NVIC_PRIO_BITS -#else -#define configPRIO_BITS 4 -#endif - -/* The lowest interrupt priority that can be used in a call to a "set priority" -function. */ -#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15 - -/* The highest interrupt priority that can be used by any interrupt service -routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL -INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER -PRIORITY THAN THIS! (higher priorities are lower numeric values. */ -#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 - -/* Interrupt priorities used by the kernel port layer itself. These are generic -to all Cortex-M ports, and do not rely on any particular library functions. */ -#define configKERNEL_INTERRUPT_PRIORITY \ - (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) -/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! -See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ -#define configMAX_SYSCALL_INTERRUPT_PRIORITY \ - (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) - -/* Normal assert() semantics without relying on the provision of an assert.h -header file. */ -/* USER CODE BEGIN 1 */ -#define configASSERT(x) \ - if((x) == 0) { \ - taskDISABLE_INTERRUPTS(); \ - for(;;) \ - ; \ - } -/* USER CODE END 1 */ - -/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS -standard names. */ -#define vPortSVCHandler SVC_Handler -#define xPortPendSVHandler PendSV_Handler - -/* IMPORTANT: After 10.3.1 update, Systick_Handler comes from NVIC (if SYS timebase = systick), otherwise from cmsis_os2.c */ - -#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 1 - -/* USER CODE BEGIN 2 */ -/* Definitions needed when configGENERATE_RUN_TIME_STATS is on */ -#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS configureTimerForRunTimeStats -#define portGET_RUN_TIME_COUNTER_VALUE getRunTimeCounterValue -/* USER CODE END 2 */ - -/* USER CODE BEGIN Defines */ -/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */ -/* USER CODE END Defines */ - -#endif /* FREERTOS_CONFIG_H */ diff --git a/firmware/targets/f7/cube/Inc/adc.h b/firmware/targets/f7/cube/Inc/adc.h deleted file mode 100644 index 940f1d49..00000000 --- a/firmware/targets/f7/cube/Inc/adc.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - ****************************************************************************** - * @file adc.h - * @brief This file contains all the function prototypes for - * the adc.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __ADC_H__ -#define __ADC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern ADC_HandleTypeDef hadc1; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_ADC1_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __ADC_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/aes.h b/firmware/targets/f7/cube/Inc/aes.h deleted file mode 100644 index 93c548f7..00000000 --- a/firmware/targets/f7/cube/Inc/aes.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - ****************************************************************************** - * @file aes.h - * @brief This file contains all the function prototypes for - * the aes.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AES_H__ -#define __AES_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern CRYP_HandleTypeDef hcryp1; -extern CRYP_HandleTypeDef hcryp2; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_AES1_Init(void); -void MX_AES2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __AES_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/comp.h b/firmware/targets/f7/cube/Inc/comp.h deleted file mode 100644 index a0ebfd5b..00000000 --- a/firmware/targets/f7/cube/Inc/comp.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - ****************************************************************************** - * @file comp.h - * @brief This file contains all the function prototypes for - * the comp.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __COMP_H__ -#define __COMP_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern COMP_HandleTypeDef hcomp1; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_COMP1_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __COMP_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/crc.h b/firmware/targets/f7/cube/Inc/crc.h deleted file mode 100644 index 8f05b75c..00000000 --- a/firmware/targets/f7/cube/Inc/crc.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - ****************************************************************************** - * @file crc.h - * @brief This file contains all the function prototypes for - * the crc.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __CRC_H__ -#define __CRC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern CRC_HandleTypeDef hcrc; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_CRC_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CRC_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/gpio.h b/firmware/targets/f7/cube/Inc/gpio.h deleted file mode 100644 index b8813862..00000000 --- a/firmware/targets/f7/cube/Inc/gpio.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - ****************************************************************************** - * @file gpio.h - * @brief This file contains all the function prototypes for - * the gpio.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __GPIO_H__ -#define __GPIO_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_GPIO_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif -#endif /*__ GPIO_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/i2c.h b/firmware/targets/f7/cube/Inc/i2c.h deleted file mode 100644 index b4f04780..00000000 --- a/firmware/targets/f7/cube/Inc/i2c.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - ****************************************************************************** - * @file i2c.h - * @brief This file contains all the function prototypes for - * the i2c.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __I2C_H__ -#define __I2C_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_I2C1_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __I2C_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/main.h b/firmware/targets/f7/cube/Inc/main.h deleted file mode 100644 index 3d34eb81..00000000 --- a/firmware/targets/f7/cube/Inc/main.h +++ /dev/null @@ -1,175 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.h - * @brief : Header for main.c file. - * This file contains the common defines of the application. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __MAIN_H -#define __MAIN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "stm32wbxx_hal.h" - -#include "stm32wbxx_ll_i2c.h" -#include "stm32wbxx_ll_crs.h" -#include "stm32wbxx_ll_rcc.h" -#include "stm32wbxx_ll_bus.h" -#include "stm32wbxx_ll_system.h" -#include "stm32wbxx_ll_exti.h" -#include "stm32wbxx_ll_cortex.h" -#include "stm32wbxx_ll_utils.h" -#include "stm32wbxx_ll_pwr.h" -#include "stm32wbxx_ll_dma.h" -#include "stm32wbxx_ll_usart.h" -#include "stm32wbxx_ll_gpio.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Exported types ------------------------------------------------------------*/ -/* USER CODE BEGIN ET */ - -/* USER CODE END ET */ - -/* Exported constants --------------------------------------------------------*/ -/* USER CODE BEGIN EC */ - -/* USER CODE END EC */ - -/* Exported macro ------------------------------------------------------------*/ -/* USER CODE BEGIN EM */ - -/* USER CODE END EM */ - -/* Exported functions prototypes ---------------------------------------------*/ -void Error_Handler(void); - -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -/* Private defines -----------------------------------------------------------*/ -#define BUTTON_BACK_Pin GPIO_PIN_13 -#define BUTTON_BACK_GPIO_Port GPIOC -#define BUTTON_BACK_EXTI_IRQn EXTI15_10_IRQn -#define QUARTZ_32MHZ_IN_Pin GPIO_PIN_14 -#define QUARTZ_32MHZ_IN_GPIO_Port GPIOC -#define QUARTZ_32MHZ_OUT_Pin GPIO_PIN_15 -#define QUARTZ_32MHZ_OUT_GPIO_Port GPIOC -#define BUTTON_OK_Pin GPIO_PIN_3 -#define BUTTON_OK_GPIO_Port GPIOH -#define BUTTON_OK_EXTI_IRQn EXTI3_IRQn -#define SPEAKER_Pin GPIO_PIN_8 -#define SPEAKER_GPIO_Port GPIOB -#define IR_TX_Pin GPIO_PIN_9 -#define IR_TX_GPIO_Port GPIOB -#define PC0_Pin GPIO_PIN_0 -#define PC0_GPIO_Port GPIOC -#define PC1_Pin GPIO_PIN_1 -#define PC1_GPIO_Port GPIOC -#define SPI_D_MISO_Pin GPIO_PIN_2 -#define SPI_D_MISO_GPIO_Port GPIOC -#define PC3_Pin GPIO_PIN_3 -#define PC3_GPIO_Port GPIOC -#define IR_RX_Pin GPIO_PIN_0 -#define IR_RX_GPIO_Port GPIOA -#define CC1101_G0_Pin GPIO_PIN_1 -#define CC1101_G0_GPIO_Port GPIOA -#define RFID_PULL_Pin GPIO_PIN_2 -#define RFID_PULL_GPIO_Port GPIOA -#define PERIPH_POWER_Pin GPIO_PIN_3 -#define PERIPH_POWER_GPIO_Port GPIOA -#define PA4_Pin GPIO_PIN_4 -#define PA4_GPIO_Port GPIOA -#define SPI_R_SCK_Pin GPIO_PIN_5 -#define SPI_R_SCK_GPIO_Port GPIOA -#define PA6_Pin GPIO_PIN_6 -#define PA6_GPIO_Port GPIOA -#define PA7_Pin GPIO_PIN_7 -#define PA7_GPIO_Port GPIOA -#define VIBRO_Pin GPIO_PIN_8 -#define VIBRO_GPIO_Port GPIOA -#define I2C_SCL_Pin GPIO_PIN_9 -#define I2C_SCL_GPIO_Port GPIOA -#define RF_SW_0_Pin GPIO_PIN_4 -#define RF_SW_0_GPIO_Port GPIOC -#define RFID_RF_IN_Pin GPIO_PIN_5 -#define RFID_RF_IN_GPIO_Port GPIOC -#define PB2_Pin GPIO_PIN_2 -#define PB2_GPIO_Port GPIOB -#define BUTTON_UP_Pin GPIO_PIN_10 -#define BUTTON_UP_GPIO_Port GPIOB -#define BUTTON_UP_EXTI_IRQn EXTI15_10_IRQn -#define BUTTON_LEFT_Pin GPIO_PIN_11 -#define BUTTON_LEFT_GPIO_Port GPIOB -#define BUTTON_LEFT_EXTI_IRQn EXTI15_10_IRQn -#define DISPLAY_RST_Pin GPIO_PIN_0 -#define DISPLAY_RST_GPIO_Port GPIOB -#define DISPLAY_DI_Pin GPIO_PIN_1 -#define DISPLAY_DI_GPIO_Port GPIOB -#define NFC_CS_Pin GPIO_PIN_4 -#define NFC_CS_GPIO_Port GPIOE -#define BUTTON_RIGHT_Pin GPIO_PIN_12 -#define BUTTON_RIGHT_GPIO_Port GPIOB -#define BUTTON_RIGHT_EXTI_IRQn EXTI15_10_IRQn -#define RFID_OUT_Pin GPIO_PIN_13 -#define RFID_OUT_GPIO_Port GPIOB -#define iBTN_Pin GPIO_PIN_14 -#define iBTN_GPIO_Port GPIOB -#define SPI_D_MOSI_Pin GPIO_PIN_15 -#define SPI_D_MOSI_GPIO_Port GPIOB -#define BUTTON_DOWN_Pin GPIO_PIN_6 -#define BUTTON_DOWN_GPIO_Port GPIOC -#define I2C_SDA_Pin GPIO_PIN_10 -#define I2C_SDA_GPIO_Port GPIOA -#define RFID_CARRIER_Pin GPIO_PIN_15 -#define RFID_CARRIER_GPIO_Port GPIOA -#define SD_CD_Pin GPIO_PIN_10 -#define SD_CD_GPIO_Port GPIOC -#define DISPLAY_CS_Pin GPIO_PIN_11 -#define DISPLAY_CS_GPIO_Port GPIOC -#define SD_CS_Pin GPIO_PIN_12 -#define SD_CS_GPIO_Port GPIOC -#define CC1101_CS_Pin GPIO_PIN_0 -#define CC1101_CS_GPIO_Port GPIOD -#define SPI_D_SCK_Pin GPIO_PIN_1 -#define SPI_D_SCK_GPIO_Port GPIOD -#define PB3_Pin GPIO_PIN_3 -#define PB3_GPIO_Port GPIOB -#define SPI_R_MISO_Pin GPIO_PIN_4 -#define SPI_R_MISO_GPIO_Port GPIOB -#define SPI_R_MOSI_Pin GPIO_PIN_5 -#define SPI_R_MOSI_GPIO_Port GPIOB -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/pka.h b/firmware/targets/f7/cube/Inc/pka.h deleted file mode 100644 index 712a1487..00000000 --- a/firmware/targets/f7/cube/Inc/pka.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - ****************************************************************************** - * @file pka.h - * @brief This file contains all the function prototypes for - * the pka.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __PKA_H__ -#define __PKA_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern PKA_HandleTypeDef hpka; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_PKA_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __PKA_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/rf.h b/firmware/targets/f7/cube/Inc/rf.h deleted file mode 100644 index 8ccea6b5..00000000 --- a/firmware/targets/f7/cube/Inc/rf.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - ****************************************************************************** - * @file rf.h - * @brief This file contains all the function prototypes for - * the rf.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __RF_H__ -#define __RF_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_RF_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __RF_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/rng.h b/firmware/targets/f7/cube/Inc/rng.h deleted file mode 100644 index 82b61396..00000000 --- a/firmware/targets/f7/cube/Inc/rng.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - ****************************************************************************** - * @file rng.h - * @brief This file contains all the function prototypes for - * the rng.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __RNG_H__ -#define __RNG_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern RNG_HandleTypeDef hrng; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_RNG_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __RNG_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/rtc.h b/firmware/targets/f7/cube/Inc/rtc.h deleted file mode 100644 index 6dd24df4..00000000 --- a/firmware/targets/f7/cube/Inc/rtc.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - ****************************************************************************** - * @file rtc.h - * @brief This file contains all the function prototypes for - * the rtc.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __RTC_H__ -#define __RTC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern RTC_HandleTypeDef hrtc; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_RTC_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __RTC_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/spi.h b/firmware/targets/f7/cube/Inc/spi.h deleted file mode 100644 index 8647d5e7..00000000 --- a/firmware/targets/f7/cube/Inc/spi.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - ****************************************************************************** - * @file spi.h - * @brief This file contains all the function prototypes for - * the spi.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __SPI_H__ -#define __SPI_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern SPI_HandleTypeDef hspi1; -extern SPI_HandleTypeDef hspi2; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_SPI1_Init(void); -void MX_SPI2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __SPI_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/stm32_assert.h b/firmware/targets/f7/cube/Inc/stm32_assert.h deleted file mode 100644 index b9dad5de..00000000 --- a/firmware/targets/f7/cube/Inc/stm32_assert.h +++ /dev/null @@ -1,53 +0,0 @@ -/** - ****************************************************************************** - * @file stm32_assert.h - * @brief STM32 assert file. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32_ASSERT_H -#define __STM32_ASSERT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Includes ------------------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT -/** - * @brief The assert_param macro is used for function's parameters check. - * @param expr: If expr is false, it calls assert_failed function - * which reports the name of the source file and the source - * line number of the call that failed. - * If expr is true, it returns no value. - * @retval None - */ -#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t*)__FILE__, __LINE__)) -/* Exported functions ------------------------------------------------------- */ -void assert_failed(uint8_t* file, uint32_t line); -#else -#define assert_param(expr) ((void)0U) -#endif /* USE_FULL_ASSERT */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32_ASSERT_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/stm32wbxx_hal_conf.h b/firmware/targets/f7/cube/Inc/stm32wbxx_hal_conf.h deleted file mode 100644 index e151d81b..00000000 --- a/firmware/targets/f7/cube/Inc/stm32wbxx_hal_conf.h +++ /dev/null @@ -1,354 +0,0 @@ -/** - ****************************************************************************** - * @file stm32wbxx_hal_conf.h - * @author MCD Application Team - * @brief HAL configuration file. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32WBxx_HAL_CONF_H -#define __STM32WBxx_HAL_CONF_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ - -/* ########################## Module Selection ############################## */ -/** - * @brief This is the list of modules to be used in the HAL driver - */ -#define HAL_MODULE_ENABLED -#define HAL_ADC_MODULE_ENABLED -#define HAL_CRYP_MODULE_ENABLED -#define HAL_COMP_MODULE_ENABLED -#define HAL_CRC_MODULE_ENABLED -#define HAL_HSEM_MODULE_ENABLED -/*#define HAL_I2C_MODULE_ENABLED */ -/*#define HAL_IPCC_MODULE_ENABLED */ -/*#define HAL_IRDA_MODULE_ENABLED */ -/*#define HAL_IWDG_MODULE_ENABLED */ -/*#define HAL_LCD_MODULE_ENABLED */ -/*#define HAL_LPTIM_MODULE_ENABLED */ -#define HAL_PCD_MODULE_ENABLED -#define HAL_PKA_MODULE_ENABLED -/*#define HAL_QSPI_MODULE_ENABLED */ -#define HAL_RNG_MODULE_ENABLED -#define HAL_RTC_MODULE_ENABLED -/*#define HAL_SAI_MODULE_ENABLED */ -/*#define HAL_SMBUS_MODULE_ENABLED */ -/*#define HAL_SMARTCARD_MODULE_ENABLED */ -#define HAL_SPI_MODULE_ENABLED -#define HAL_TIM_MODULE_ENABLED -/*#define HAL_TSC_MODULE_ENABLED */ -/*#define HAL_UART_MODULE_ENABLED */ -/*#define HAL_USART_MODULE_ENABLED */ -/*#define HAL_WWDG_MODULE_ENABLED */ -#define HAL_EXTI_MODULE_ENABLED -#define HAL_CORTEX_MODULE_ENABLED -#define HAL_DMA_MODULE_ENABLED -#define HAL_FLASH_MODULE_ENABLED -#define HAL_GPIO_MODULE_ENABLED -#define HAL_PWR_MODULE_ENABLED -#define HAL_RCC_MODULE_ENABLED - -#define USE_HAL_ADC_REGISTER_CALLBACKS 0u -#define USE_HAL_COMP_REGISTER_CALLBACKS 0u -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0u -#define USE_HAL_I2C_REGISTER_CALLBACKS 0u -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0u -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0u -#define USE_HAL_PCD_REGISTER_CALLBACKS 0u -#define USE_HAL_PKA_REGISTER_CALLBACKS 0u -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0u -#define USE_HAL_RNG_REGISTER_CALLBACKS 0u -#define USE_HAL_RTC_REGISTER_CALLBACKS 0u -#define USE_HAL_SAI_REGISTER_CALLBACKS 0u -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0u -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0u -#define USE_HAL_SPI_REGISTER_CALLBACKS 0u -#define USE_HAL_TIM_REGISTER_CALLBACKS 0u -#define USE_HAL_TSC_REGISTER_CALLBACKS 0u -#define USE_HAL_UART_REGISTER_CALLBACKS 0u -#define USE_HAL_USART_REGISTER_CALLBACKS 0u -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0u - -/* ########################## Oscillator Values adaptation ####################*/ -/** - * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. - * This value is used by the RCC HAL module to compute the system frequency - * (when HSE is used as system clock source, directly or through the PLL). - */ -#if !defined(HSE_VALUE) -#define HSE_VALUE 32000000U /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ - -/** - * @brief Internal Multiple Speed oscillator (MSI) default value. - * This value is the default MSI range value after Reset. - */ -#if !defined(MSI_VALUE) -#define MSI_VALUE ((uint32_t)4000000) /*!< Value of the Internal oscillator in Hz*/ -#endif /* MSI_VALUE */ - -/** - * @brief Internal High Speed oscillator (HSI) value. - * This value is used by the RCC HAL module to compute the system frequency - * (when HSI is used as system clock source, directly or through the PLL). - */ -#if !defined(HSI_VALUE) -#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ - -/** - * @brief Internal Low Speed oscillator (LSI1) value. - */ -#if !defined(LSI1_VALUE) -#define LSI1_VALUE ((uint32_t)32000) /*!< LSI1 Typical Value in Hz*/ -#endif /* LSI1_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz - The real value may vary depending on the variations - in voltage and temperature.*/ -/** - * @brief Internal Low Speed oscillator (LSI2) value. - */ -#if !defined(LSI2_VALUE) -#define LSI2_VALUE ((uint32_t)32000) /*!< LSI2 Typical Value in Hz*/ -#endif /* LSI2_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz - The real value may vary depending on the variations - in voltage and temperature.*/ - -/** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE 32768U /*!< Value of the External oscillator in Hz*/ -#endif /* LSE_VALUE */ - -/** - * @brief Internal Multiple Speed oscillator (HSI48) default value. - * This value is the default HSI48 range value after Reset. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE ((uint32_t)48000000) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI48_VALUE */ - -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT 1000U /*!< Time out for LSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ - -/** - * @brief External clock source for SAI1 peripheral - * This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source - * frequency. - */ -#if !defined(EXTERNAL_SAI1_CLOCK_VALUE) -#define EXTERNAL_SAI1_CLOCK_VALUE \ - ((uint32_t)2097000) /*!< Value of the SAI1 External clock source in Hz*/ -#endif /* EXTERNAL_SAI1_CLOCK_VALUE */ - -/* Tip: To avoid modifying this file each time you need to use different HSE, - === you can define the HSE value in your toolchain compiler preprocessor. */ - -/* ########################### System Configuration ######################### */ -/** - * @brief This is the HAL system configuration section - */ - -#define VDD_VALUE 3300U /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY 15U /*!< tick interrupt priority */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 1U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U - -/* ########################## Assert Selection ############################## */ -/** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -/* #define USE_FULL_ASSERT 1U */ - -/* ################## SPI peripheral configuration ########################## */ - -/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver - * Activated: CRC code is present inside driver - * Deactivated: CRC code cleaned from driver - */ - -#define USE_SPI_CRC 0U - -/* Includes ------------------------------------------------------------------*/ -/** - * @brief Include module's header file - */ -#ifdef HAL_DMA_MODULE_ENABLED -#include "stm32wbxx_hal_dma.h" -#endif /* HAL_DMA_MODULE_ENABLED */ - -#ifdef HAL_ADC_MODULE_ENABLED -#include "stm32wbxx_hal_adc.h" -#endif /* HAL_ADC_MODULE_ENABLED */ - -#ifdef HAL_COMP_MODULE_ENABLED -#include "stm32wbxx_hal_comp.h" -#endif /* HAL_COMP_MODULE_ENABLED */ - -#ifdef HAL_CORTEX_MODULE_ENABLED -#include "stm32wbxx_hal_cortex.h" -#endif /* HAL_CORTEX_MODULE_ENABLED */ - -#ifdef HAL_CRC_MODULE_ENABLED -#include "stm32wbxx_hal_crc.h" -#endif /* HAL_CRC_MODULE_ENABLED */ - -#ifdef HAL_CRYP_MODULE_ENABLED -#include "stm32wbxx_hal_cryp.h" -#endif /* HAL_CRYP_MODULE_ENABLED */ - -#ifdef HAL_EXTI_MODULE_ENABLED -#include "stm32wbxx_hal_exti.h" -#endif /* HAL_EXTI_MODULE_ENABLED */ - -#ifdef HAL_FLASH_MODULE_ENABLED -#include "stm32wbxx_hal_flash.h" -#endif /* HAL_FLASH_MODULE_ENABLED */ - -#ifdef HAL_GPIO_MODULE_ENABLED -#include "stm32wbxx_hal_gpio.h" -#endif /* HAL_GPIO_MODULE_ENABLED */ - -#ifdef HAL_HSEM_MODULE_ENABLED -#include "stm32wbxx_hal_hsem.h" -#endif /* HAL_HSEM_MODULE_ENABLED */ - -#ifdef HAL_I2C_MODULE_ENABLED -#include "stm32wbxx_hal_i2c.h" -#endif /* HAL_I2C_MODULE_ENABLED */ - -#ifdef HAL_IPCC_MODULE_ENABLED -#include "stm32wbxx_hal_ipcc.h" -#endif /* HAL_IPCC_MODULE_ENABLED */ - -#ifdef HAL_IRDA_MODULE_ENABLED -#include "stm32wbxx_hal_irda.h" -#endif /* HAL_IRDA_MODULE_ENABLED */ - -#ifdef HAL_IWDG_MODULE_ENABLED -#include "stm32wbxx_hal_iwdg.h" -#endif /* HAL_IWDG_MODULE_ENABLED */ - -#ifdef HAL_LCD_MODULE_ENABLED -#include "stm32wbxx_hal_lcd.h" -#endif /* HAL_LCD_MODULE_ENABLED */ - -#ifdef HAL_LPTIM_MODULE_ENABLED -#include "stm32wbxx_hal_lptim.h" -#endif /* HAL_LPTIM_MODULE_ENABLED */ - -#ifdef HAL_PCD_MODULE_ENABLED -#include "stm32wbxx_hal_pcd.h" -#endif /* HAL_PCD_MODULE_ENABLED */ - -#ifdef HAL_PKA_MODULE_ENABLED -#include "stm32wbxx_hal_pka.h" -#endif /* HAL_PKA_MODULE_ENABLED */ - -#ifdef HAL_PWR_MODULE_ENABLED -#include "stm32wbxx_hal_pwr.h" -#endif /* HAL_PWR_MODULE_ENABLED */ - -#ifdef HAL_QSPI_MODULE_ENABLED -#include "stm32wbxx_hal_qspi.h" -#endif /* HAL_QSPI_MODULE_ENABLED */ - -#ifdef HAL_RCC_MODULE_ENABLED -#include "stm32wbxx_hal_rcc.h" -#endif /* HAL_RCC_MODULE_ENABLED */ - -#ifdef HAL_RNG_MODULE_ENABLED -#include "stm32wbxx_hal_rng.h" -#endif /* HAL_RNG_MODULE_ENABLED */ - -#ifdef HAL_RTC_MODULE_ENABLED -#include "stm32wbxx_hal_rtc.h" -#endif /* HAL_RTC_MODULE_ENABLED */ - -#ifdef HAL_SAI_MODULE_ENABLED -#include "stm32wbxx_hal_sai.h" -#endif /* HAL_SAI_MODULE_ENABLED */ - -#ifdef HAL_SMARTCARD_MODULE_ENABLED -#include "stm32wbxx_hal_smartcard.h" -#endif /* HAL_SMARTCARD_MODULE_ENABLED */ - -#ifdef HAL_SMBUS_MODULE_ENABLED -#include "stm32wbxx_hal_smbus.h" -#endif /* HAL_SMBUS_MODULE_ENABLED */ - -#ifdef HAL_SPI_MODULE_ENABLED -#include "stm32wbxx_hal_spi.h" -#endif /* HAL_SPI_MODULE_ENABLED */ - -#ifdef HAL_TIM_MODULE_ENABLED -#include "stm32wbxx_hal_tim.h" -#endif /* HAL_TIM_MODULE_ENABLED */ - -#ifdef HAL_TSC_MODULE_ENABLED -#include "stm32wbxx_hal_tsc.h" -#endif /* HAL_TSC_MODULE_ENABLED */ - -#ifdef HAL_UART_MODULE_ENABLED -#include "stm32wbxx_hal_uart.h" -#endif /* HAL_UART_MODULE_ENABLED */ - -#ifdef HAL_USART_MODULE_ENABLED -#include "stm32wbxx_hal_usart.h" -#endif /* HAL_USART_MODULE_ENABLED */ - -#ifdef HAL_WWDG_MODULE_ENABLED -#include "stm32wbxx_hal_wwdg.h" -#endif /* HAL_WWDG_MODULE_ENABLED */ - -/* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT -/** - * @brief The assert_param macro is used for function's parameters check. - * @param expr If expr is false, it calls assert_failed function - * which reports the name of the source file and the source - * line number of the call that failed. - * If expr is true, it returns no value. - * @retval None - */ -#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t*)__FILE__, __LINE__)) -/* Exported functions ------------------------------------------------------- */ -void assert_failed(uint8_t* file, uint32_t line); -#else -#define assert_param(expr) ((void)0U) -#endif /* USE_FULL_ASSERT */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32WBxx_HAL_CONF_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/stm32wbxx_it.h b/firmware/targets/f7/cube/Inc/stm32wbxx_it.h deleted file mode 100644 index 095a83ec..00000000 --- a/firmware/targets/f7/cube/Inc/stm32wbxx_it.h +++ /dev/null @@ -1,77 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32wbxx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32WBxx_IT_H -#define __STM32WBxx_IT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Exported types ------------------------------------------------------------*/ -/* USER CODE BEGIN ET */ - -/* USER CODE END ET */ - -/* Exported constants --------------------------------------------------------*/ -/* USER CODE BEGIN EC */ - -/* USER CODE END EC */ - -/* Exported macro ------------------------------------------------------------*/ -/* USER CODE BEGIN EM */ - -/* USER CODE END EM */ - -/* Exported functions prototypes ---------------------------------------------*/ -void NMI_Handler(void); -void HardFault_Handler(void); -void MemManage_Handler(void); -void BusFault_Handler(void); -void UsageFault_Handler(void); -void DebugMon_Handler(void); -void SysTick_Handler(void); -void TAMP_STAMP_LSECSS_IRQHandler(void); -void RCC_IRQHandler(void); -void EXTI3_IRQHandler(void); -void ADC1_IRQHandler(void); -void USB_LP_IRQHandler(void); -void COMP_IRQHandler(void); -void TIM1_TRG_COM_TIM17_IRQHandler(void); -void TIM2_IRQHandler(void); -void EXTI15_10_IRQHandler(void); -void HSEM_IRQHandler(void); -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32WBxx_IT_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/tim.h b/firmware/targets/f7/cube/Inc/tim.h deleted file mode 100644 index e0f65f10..00000000 --- a/firmware/targets/f7/cube/Inc/tim.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - ****************************************************************************** - * @file tim.h - * @brief This file contains all the function prototypes for - * the tim.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __TIM_H__ -#define __TIM_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern TIM_HandleTypeDef htim1; -extern TIM_HandleTypeDef htim2; -extern TIM_HandleTypeDef htim16; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_TIM1_Init(void); -void MX_TIM2_Init(void); -void MX_TIM16_Init(void); - -void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __TIM_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/usart.h b/firmware/targets/f7/cube/Inc/usart.h deleted file mode 100644 index 81412610..00000000 --- a/firmware/targets/f7/cube/Inc/usart.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - ****************************************************************************** - * @file usart.h - * @brief This file contains all the function prototypes for - * the usart.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USART_H__ -#define __USART_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_USART1_UART_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USART_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/usb_device.h b/firmware/targets/f7/cube/Inc/usb_device.h deleted file mode 100644 index b9a4bf43..00000000 --- a/firmware/targets/f7/cube/Inc/usb_device.h +++ /dev/null @@ -1,105 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usb_device.h - * @version : v3.0_Cube - * @brief : Header for usb_device.c file. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_DEVICE__H__ -#define __USB_DEVICE__H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "stm32wbxx.h" -#include "stm32wbxx_hal.h" -#include "usbd_def.h" - -/* USER CODE BEGIN INCLUDE */ - -/* USER CODE END INCLUDE */ - -/** @addtogroup USBD_OTG_DRIVER - * @{ - */ - -/** @defgroup USBD_DEVICE USBD_DEVICE - * @brief Device file for Usb otg low level driver. - * @{ - */ - -/** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables - * @brief Public variables. - * @{ - */ - -/* Private variables ---------------------------------------------------------*/ -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* - * -- Insert your variables declaration here -- - */ -/* USER CODE BEGIN VARIABLES */ - -/* USER CODE END VARIABLES */ -/** - * @} - */ - -/** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype - * @brief Declaration of public functions for Usb device. - * @{ - */ - -/** USB Device initialization function. */ -void MX_USB_Device_Init(void); - -/* - * -- Insert functions declaration here -- - */ -/* USER CODE BEGIN FD */ - -/* USER CODE END FD */ -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USB_DEVICE__H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/usbd_cdc_if.h b/firmware/targets/f7/cube/Inc/usbd_cdc_if.h deleted file mode 100644 index 7ddbe67a..00000000 --- a/firmware/targets/f7/cube/Inc/usbd_cdc_if.h +++ /dev/null @@ -1,133 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usbd_cdc_if.h - * @version : v3.0_Cube - * @brief : Header for usbd_cdc_if.c file. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_CDC_IF_H__ -#define __USBD_CDC_IF_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_cdc.h" - -/* USER CODE BEGIN INCLUDE */ - -/* USER CODE END INCLUDE */ - -/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @brief For Usb device. - * @{ - */ - -/** @defgroup USBD_CDC_IF USBD_CDC_IF - * @brief Usb VCP device module - * @{ - */ - -/** @defgroup USBD_CDC_IF_Exported_Defines USBD_CDC_IF_Exported_Defines - * @brief Defines. - * @{ - */ -/* Define size for the receive and transmit buffer over CDC */ -#define APP_RX_DATA_SIZE 512 -#define APP_TX_DATA_SIZE 512 -/* USER CODE BEGIN EXPORTED_DEFINES */ - -/* USER CODE END EXPORTED_DEFINES */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_IF_Exported_Types USBD_CDC_IF_Exported_Types - * @brief Types. - * @{ - */ - -/* USER CODE BEGIN EXPORTED_TYPES */ - -/* USER CODE END EXPORTED_TYPES */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_IF_Exported_Macros USBD_CDC_IF_Exported_Macros - * @brief Aliases. - * @{ - */ - -/* USER CODE BEGIN EXPORTED_MACRO */ - -/* USER CODE END EXPORTED_MACRO */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables - * @brief Public variables. - * @{ - */ - -/** CDC Interface callback. */ -extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS; - -/* USER CODE BEGIN EXPORTED_VARIABLES */ - -/* USER CODE END EXPORTED_VARIABLES */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype USBD_CDC_IF_Exported_FunctionsPrototype - * @brief Public functions declaration. - * @{ - */ - -uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len); - -/* USER CODE BEGIN EXPORTED_FUNCTIONS */ - -/* USER CODE END EXPORTED_FUNCTIONS */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_CDC_IF_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/usbd_conf.h b/firmware/targets/f7/cube/Inc/usbd_conf.h deleted file mode 100644 index 98306d6a..00000000 --- a/firmware/targets/f7/cube/Inc/usbd_conf.h +++ /dev/null @@ -1,179 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usbd_conf.h - * @version : v3.0_Cube - * @brief : Header for usbd_conf.c file. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_CONF__H__ -#define __USBD_CONF__H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include -#include -#include -#include "stm32wbxx.h" -#include "stm32wbxx_hal.h" - -/* USER CODE BEGIN INCLUDE */ - -/* USER CODE END INCLUDE */ - -/** @addtogroup USBD_OTG_DRIVER - * @brief Driver for Usb device. - * @{ - */ - -/** @defgroup USBD_CONF USBD_CONF - * @brief Configuration file for Usb otg low level driver. - * @{ - */ - -/** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables - * @brief Public variables. - * @{ - */ - -/* Private variables ---------------------------------------------------------*/ -/* USER CODE BEGIN PV */ -/* USER CODE END PV */ -/** - * @} - */ - -/** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines - * @brief Defines for configuration of the Usb device. - * @{ - */ - -/*---------- -----------*/ -#define USBD_MAX_NUM_INTERFACES 1U -/*---------- -----------*/ -#define USBD_MAX_NUM_CONFIGURATION 1U -/*---------- -----------*/ -#define USBD_MAX_STR_DESC_SIZ 512U -/*---------- -----------*/ -#define USBD_DEBUG_LEVEL 0U -/*---------- -----------*/ -#define USBD_LPM_ENABLED 1U -/*---------- -----------*/ -#define USBD_SELF_POWERED 1U - -/****************************************/ -/* #define for FS and HS identification */ -#define DEVICE_FS 0 - -/** - * @} - */ - -/** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros - * @brief Aliases. - * @{ - */ - -/* Memory management macros */ - -/** Alias for memory allocation. */ -#define USBD_malloc (void*)USBD_static_malloc - -/** Alias for memory release. */ -#define USBD_free USBD_static_free - -/** Alias for memory set. */ -#define USBD_memset memset - -/** Alias for memory copy. */ -#define USBD_memcpy memcpy - -/** Alias for delay. */ -#define USBD_Delay HAL_Delay -/* DEBUG macros */ - -#if(USBD_DEBUG_LEVEL > 0) -#define USBD_UsrLog(...) \ - printf(__VA_ARGS__); \ - printf("\n"); -#else -#define USBD_UsrLog(...) -#endif - -#if(USBD_DEBUG_LEVEL > 1) - -#define USBD_ErrLog(...) \ - printf("ERROR: "); \ - printf(__VA_ARGS__); \ - printf("\n"); -#else -#define USBD_ErrLog(...) -#endif - -#if(USBD_DEBUG_LEVEL > 2) -#define USBD_DbgLog(...) \ - printf("DEBUG : "); \ - printf(__VA_ARGS__); \ - printf("\n"); -#else -#define USBD_DbgLog(...) -#endif - -/** - * @} - */ - -/** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types - * @brief Types. - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype - * @brief Declaration of public functions for Usb device. - * @{ - */ - -/* Exported functions -------------------------------------------------------*/ -void* USBD_static_malloc(uint32_t size); -void USBD_static_free(void* p); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_CONF__H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Inc/usbd_desc.h b/firmware/targets/f7/cube/Inc/usbd_desc.h deleted file mode 100644 index 67a70dc6..00000000 --- a/firmware/targets/f7/cube/Inc/usbd_desc.h +++ /dev/null @@ -1,145 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usbd_desc.c - * @version : v3.0_Cube - * @brief : Header for usbd_conf.c file. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_DESC__C__ -#define __USBD_DESC__C__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_def.h" - -/* USER CODE BEGIN INCLUDE */ - -/* USER CODE END INCLUDE */ - -/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup USBD_DESC USBD_DESC - * @brief Usb device descriptors module. - * @{ - */ - -/** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants - * @brief Constants. - * @{ - */ -#define DEVICE_ID1 (UID_BASE) -#define DEVICE_ID2 (UID_BASE + 0x4) -#define DEVICE_ID3 (UID_BASE + 0x8) - -#define USB_SIZ_STRING_SERIAL 0x1A - -/* USER CODE BEGIN EXPORTED_CONSTANTS */ - -/* USER CODE END EXPORTED_CONSTANTS */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines - * @brief Defines. - * @{ - */ - -/* USER CODE BEGIN EXPORTED_DEFINES */ - -/* USER CODE END EXPORTED_DEFINES */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions - * @brief Types. - * @{ - */ - -/* USER CODE BEGIN EXPORTED_TYPES */ - -/* USER CODE END EXPORTED_TYPES */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros - * @brief Aliases. - * @{ - */ - -/* USER CODE BEGIN EXPORTED_MACRO */ - -/* USER CODE END EXPORTED_MACRO */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables - * @brief Public variables. - * @{ - */ - -extern USBD_DescriptorsTypeDef CDC_Desc; - -/* USER CODE BEGIN EXPORTED_VARIABLES */ - -/* USER CODE END EXPORTED_VARIABLES */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype - * @brief Public functions declaration. - * @{ - */ - -/* USER CODE BEGIN EXPORTED_FUNCTIONS */ - -/* USER CODE END EXPORTED_FUNCTIONS */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_DESC__C__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Makefile b/firmware/targets/f7/cube/Makefile deleted file mode 100644 index 4f5ffc8b..00000000 --- a/firmware/targets/f7/cube/Makefile +++ /dev/null @@ -1,253 +0,0 @@ -########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [3.14.1] date: [Fri Sep 10 04:36:47 MSK 2021] -########################################################################################################################## - -# ------------------------------------------------ -# Generic Makefile (based on gcc) -# -# ChangeLog : -# 2017-02-10 - Several enhancements + project update mode -# 2015-07-22 - first version -# ------------------------------------------------ - -###################################### -# target -###################################### -TARGET = f7 - - -###################################### -# building variables -###################################### -# debug build? -DEBUG = 1 -# optimization -OPT = -Og - - -####################################### -# paths -####################################### -# Build path -BUILD_DIR = build - -###################################### -# source -###################################### -# C sources -C_SOURCES = \ -Src/main.c \ -Src/gpio.c \ -Src/app_freertos.c \ -Src/adc.c \ -Src/aes.c \ -Src/comp.c \ -Src/crc.c \ -Src/i2c.c \ -Src/pka.c \ -Src/rf.c \ -Src/rng.c \ -Src/rtc.c \ -Src/spi.c \ -Src/tim.c \ -Src/usart.c \ -Src/usb_device.c \ -Src/usbd_conf.c \ -Src/usbd_desc.c \ -Src/usbd_cdc_if.c \ -Src/stm32wbxx_it.c \ -Src/stm32wbxx_hal_msp.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_utils.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_exti.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd_ex.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_usb.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc_ex.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_flash.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_flash_ex.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_gpio.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_hsem.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_dma.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_dma_ex.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr_ex.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_cortex.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_exti.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_adc.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_adc_ex.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_adc.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_cryp.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_cryp_ex.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_comp.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_crc.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_crc_ex.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_i2c.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_gpio.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_dma.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pka.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rng.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc_ex.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_spi.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_spi_ex.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_tim.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_tim_ex.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_usart.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_rcc.c \ -Src/system_stm32wbxx.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/croutine.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/list.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/queue.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/tasks.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/timers.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c \ -/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c - -# ASM sources -ASM_SOURCES = \ -startup_stm32wb55xx_cm4.s - - -####################################### -# binaries -####################################### -PREFIX = arm-none-eabi- -# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) -# either it can be added to the PATH environment variable. -ifdef GCC_PATH -CC = $(GCC_PATH)/$(PREFIX)gcc -AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp -CP = $(GCC_PATH)/$(PREFIX)objcopy -SZ = $(GCC_PATH)/$(PREFIX)size -else -CC = $(PREFIX)gcc -AS = $(PREFIX)gcc -x assembler-with-cpp -CP = $(PREFIX)objcopy -SZ = $(PREFIX)size -endif -HEX = $(CP) -O ihex -BIN = $(CP) -O binary -S - -####################################### -# CFLAGS -####################################### -# cpu -CPU = -mcpu=cortex-m4 - -# fpu -FPU = -mfpu=fpv4-sp-d16 - -# float-abi -FLOAT-ABI = -mfloat-abi=hard - -# mcu -MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) - -# macros for gcc -# AS defines -AS_DEFS = - -# C defines -C_DEFS = \ --DUSE_FULL_LL_DRIVER \ --DUSE_HAL_DRIVER \ --DSTM32WB55xx - - -# AS includes -AS_INCLUDES = \ --IInc - -# C includes -C_INCLUDES = \ --IInc \ --I/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Inc \ --I/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Inc/Legacy \ --I/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/include \ --I/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \ --I/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F \ --I/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/ST/STM32_USB_Device_Library/Core/Inc \ --I/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc \ --I/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/CMSIS/Device/ST/STM32WBxx/Include \ --I/Users/aku/Work/flipper/flipperzero-firmware/lib/STM32CubeWB/Drivers/CMSIS/Include - - -# compile gcc flags -ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections - -CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections - -ifeq ($(DEBUG), 1) -CFLAGS += -g -gdwarf-2 -endif - - -# Generate dependency information -CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" - - -####################################### -# LDFLAGS -####################################### -# link script -LDSCRIPT = stm32wb55xx_flash_cm4.ld - -# libraries -LIBS = -lc -lm -lnosys -LIBDIR = -LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections - -# default action: build all -all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin - - -####################################### -# build the application -####################################### -# list of objects -OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) -vpath %.c $(sort $(dir $(C_SOURCES))) -# list of ASM program objects -OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))) -vpath %.s $(sort $(dir $(ASM_SOURCES))) - -$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) - $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ - -$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR) - $(AS) -c $(CFLAGS) $< -o $@ - -$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile - $(CC) $(OBJECTS) $(LDFLAGS) -o $@ - $(SZ) $@ - -$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR) - $(HEX) $< $@ - -$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) - $(BIN) $< $@ - -$(BUILD_DIR): - mkdir $@ - -####################################### -# clean up -####################################### -clean: - -rm -fR $(BUILD_DIR) - -####################################### -# dependencies -####################################### --include $(wildcard $(BUILD_DIR)/*.d) - -# *** EOF *** \ No newline at end of file diff --git a/firmware/targets/f7/cube/Src/adc.c b/firmware/targets/f7/cube/Src/adc.c deleted file mode 100644 index d0c3d98e..00000000 --- a/firmware/targets/f7/cube/Src/adc.c +++ /dev/null @@ -1,128 +0,0 @@ -/** - ****************************************************************************** - * @file adc.c - * @brief This file provides code for the configuration - * of the ADC instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "adc.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -ADC_HandleTypeDef hadc1; - -/* ADC1 init function */ -void MX_ADC1_Init(void) { - /* USER CODE BEGIN ADC1_Init 0 */ - - /* USER CODE END ADC1_Init 0 */ - - ADC_ChannelConfTypeDef sConfig = {0}; - - /* USER CODE BEGIN ADC1_Init 1 */ - - /* USER CODE END ADC1_Init 1 */ - /** Common config - */ - hadc1.Instance = ADC1; - hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; - hadc1.Init.Resolution = ADC_RESOLUTION_12B; - hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; - hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; - hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; - hadc1.Init.LowPowerAutoWait = DISABLE; - hadc1.Init.ContinuousConvMode = DISABLE; - hadc1.Init.NbrOfConversion = 1; - hadc1.Init.DiscontinuousConvMode = DISABLE; - hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; - hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; - hadc1.Init.DMAContinuousRequests = DISABLE; - hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; - hadc1.Init.OversamplingMode = DISABLE; - if(HAL_ADC_Init(&hadc1) != HAL_OK) { - Error_Handler(); - } - /** Configure Regular Channel - */ - sConfig.Channel = ADC_CHANNEL_14; - sConfig.Rank = ADC_REGULAR_RANK_1; - sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5; - sConfig.SingleDiff = ADC_SINGLE_ENDED; - sConfig.OffsetNumber = ADC_OFFSET_NONE; - sConfig.Offset = 0; - if(HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN ADC1_Init 2 */ - - /* USER CODE END ADC1_Init 2 */ -} - -void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(adcHandle->Instance == ADC1) { - /* USER CODE BEGIN ADC1_MspInit 0 */ - - /* USER CODE END ADC1_MspInit 0 */ - /* ADC1 clock enable */ - __HAL_RCC_ADC_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**ADC1 GPIO Configuration - PC5 ------> ADC1_IN14 - */ - GPIO_InitStruct.Pin = RFID_RF_IN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(RFID_RF_IN_GPIO_Port, &GPIO_InitStruct); - - /* ADC1 interrupt Init */ - HAL_NVIC_SetPriority(ADC1_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(ADC1_IRQn); - /* USER CODE BEGIN ADC1_MspInit 1 */ - - /* USER CODE END ADC1_MspInit 1 */ - } -} - -void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) { - if(adcHandle->Instance == ADC1) { - /* USER CODE BEGIN ADC1_MspDeInit 0 */ - - /* USER CODE END ADC1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_ADC_CLK_DISABLE(); - - /**ADC1 GPIO Configuration - PC5 ------> ADC1_IN14 - */ - HAL_GPIO_DeInit(RFID_RF_IN_GPIO_Port, RFID_RF_IN_Pin); - - /* ADC1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(ADC1_IRQn); - /* USER CODE BEGIN ADC1_MspDeInit 1 */ - - /* USER CODE END ADC1_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/aes.c b/firmware/targets/f7/cube/Src/aes.c deleted file mode 100644 index ace83341..00000000 --- a/firmware/targets/f7/cube/Src/aes.c +++ /dev/null @@ -1,129 +0,0 @@ -/** - ****************************************************************************** - * @file aes.c - * @brief This file provides code for the configuration - * of the AES instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "aes.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -CRYP_HandleTypeDef hcryp1; -__ALIGN_BEGIN static const uint32_t pKeyAES1[4] __ALIGN_END = - {0x00000000, 0x00000000, 0x00000000, 0x00000000}; -CRYP_HandleTypeDef hcryp2; -__ALIGN_BEGIN static const uint32_t pKeyAES2[4] __ALIGN_END = - {0x00000000, 0x00000000, 0x00000000, 0x00000000}; - -/* AES1 init function */ -void MX_AES1_Init(void) { - /* USER CODE BEGIN AES1_Init 0 */ - - /* USER CODE END AES1_Init 0 */ - - /* USER CODE BEGIN AES1_Init 1 */ - - /* USER CODE END AES1_Init 1 */ - hcryp1.Instance = AES1; - hcryp1.Init.DataType = CRYP_DATATYPE_32B; - hcryp1.Init.KeySize = CRYP_KEYSIZE_128B; - hcryp1.Init.pKey = (uint32_t*)pKeyAES1; - hcryp1.Init.Algorithm = CRYP_AES_ECB; - hcryp1.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD; - hcryp1.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS; - if(HAL_CRYP_Init(&hcryp1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN AES1_Init 2 */ - - /* USER CODE END AES1_Init 2 */ -} -/* AES2 init function */ -void MX_AES2_Init(void) { - /* USER CODE BEGIN AES2_Init 0 */ - - /* USER CODE END AES2_Init 0 */ - - /* USER CODE BEGIN AES2_Init 1 */ - - /* USER CODE END AES2_Init 1 */ - hcryp2.Instance = AES2; - hcryp2.Init.DataType = CRYP_DATATYPE_32B; - hcryp2.Init.KeySize = CRYP_KEYSIZE_128B; - hcryp2.Init.pKey = (uint32_t*)pKeyAES2; - hcryp2.Init.Algorithm = CRYP_AES_ECB; - hcryp2.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD; - hcryp2.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS; - if(HAL_CRYP_Init(&hcryp2) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN AES2_Init 2 */ - - /* USER CODE END AES2_Init 2 */ -} - -void HAL_CRYP_MspInit(CRYP_HandleTypeDef* crypHandle) { - if(crypHandle->Instance == AES1) { - /* USER CODE BEGIN AES1_MspInit 0 */ - - /* USER CODE END AES1_MspInit 0 */ - /* AES1 clock enable */ - __HAL_RCC_AES1_CLK_ENABLE(); - /* USER CODE BEGIN AES1_MspInit 1 */ - - /* USER CODE END AES1_MspInit 1 */ - } else if(crypHandle->Instance == AES2) { - /* USER CODE BEGIN AES2_MspInit 0 */ - - /* USER CODE END AES2_MspInit 0 */ - /* AES2 clock enable */ - __HAL_RCC_AES2_CLK_ENABLE(); - /* USER CODE BEGIN AES2_MspInit 1 */ - - /* USER CODE END AES2_MspInit 1 */ - } -} - -void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef* crypHandle) { - if(crypHandle->Instance == AES1) { - /* USER CODE BEGIN AES1_MspDeInit 0 */ - - /* USER CODE END AES1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_AES1_CLK_DISABLE(); - /* USER CODE BEGIN AES1_MspDeInit 1 */ - - /* USER CODE END AES1_MspDeInit 1 */ - } else if(crypHandle->Instance == AES2) { - /* USER CODE BEGIN AES2_MspDeInit 0 */ - - /* USER CODE END AES2_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_AES2_CLK_DISABLE(); - /* USER CODE BEGIN AES2_MspDeInit 1 */ - - /* USER CODE END AES2_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/app_freertos.c b/firmware/targets/f7/cube/Src/app_freertos.c deleted file mode 100644 index fcb18ce6..00000000 --- a/firmware/targets/f7/cube/Src/app_freertos.c +++ /dev/null @@ -1,173 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * File Name : app_freertos.c - * Description : Code for freertos applications - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "FreeRTOS.h" -#include "task.h" -#include "main.h" -#include "cmsis_os.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN PD */ - -/* USER CODE END PD */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN PM */ - -/* USER CODE END PM */ - -/* Private variables ---------------------------------------------------------*/ -/* USER CODE BEGIN Variables */ - -/* USER CODE END Variables */ -/* Definitions for app_main */ -osThreadId_t app_mainHandle; -const osThreadAttr_t app_main_attributes = { - .name = "app_main", - .priority = (osPriority_t)osPriorityNormal, - .stack_size = 1024 * 4}; - -/* Private function prototypes -----------------------------------------------*/ -/* USER CODE BEGIN FunctionPrototypes */ - -/* USER CODE END FunctionPrototypes */ - -void app(void* argument); - -void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ - -/* Hook prototypes */ -void configureTimerForRunTimeStats(void); -unsigned long getRunTimeCounterValue(void); -void vApplicationIdleHook(void); -void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char* pcTaskName); - -/* USER CODE BEGIN 1 */ -/* Functions needed when configGENERATE_RUN_TIME_STATS is on */ -__weak void configureTimerForRunTimeStats(void) { -} - -__weak unsigned long getRunTimeCounterValue(void) { - return 0; -} -/* USER CODE END 1 */ - -/* USER CODE BEGIN 2 */ -void vApplicationIdleHook(void) { - /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set - to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle - task. It is essential that code added to this hook function never attempts - to block in any way (for example, call xQueueReceive() with a block time - specified, or call vTaskDelay()). If the application makes use of the - vTaskDelete() API function (as this demo application does) then it is also - important that vApplicationIdleHook() is permitted to return to its calling - function, because it is the responsibility of the idle task to clean up - memory allocated by the kernel to any task that has since been deleted. */ -} -/* USER CODE END 2 */ - -/* USER CODE BEGIN 4 */ -void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char* pcTaskName) { - /* Run time stack overflow checking is performed if - configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is - called if a stack overflow is detected. */ -} -/* USER CODE END 4 */ - -/* USER CODE BEGIN VPORT_SUPPORT_TICKS_AND_SLEEP */ -__weak void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime) { - // Generated when configUSE_TICKLESS_IDLE == 2. - // Function called in tasks.c (in portTASK_FUNCTION). - // TO BE COMPLETED or TO BE REPLACED by a user one, overriding that weak one. -} -/* USER CODE END VPORT_SUPPORT_TICKS_AND_SLEEP */ - -/** - * @brief FreeRTOS initialization - * @param None - * @retval None - */ -void MX_FREERTOS_Init(void) { - /* USER CODE BEGIN Init */ - - /* USER CODE END Init */ - - /* USER CODE BEGIN RTOS_MUTEX */ - /* add mutexes, ... */ - /* USER CODE END RTOS_MUTEX */ - - /* USER CODE BEGIN RTOS_SEMAPHORES */ - /* add semaphores, ... */ - /* USER CODE END RTOS_SEMAPHORES */ - - /* USER CODE BEGIN RTOS_TIMERS */ - /* start timers, add new ones, ... */ - /* USER CODE END RTOS_TIMERS */ - - /* USER CODE BEGIN RTOS_QUEUES */ - /* add queues, ... */ - /* USER CODE END RTOS_QUEUES */ - - /* Create the thread(s) */ - /* creation of app_main */ - app_mainHandle = osThreadNew(app, NULL, &app_main_attributes); - - /* USER CODE BEGIN RTOS_THREADS */ - /* add threads, ... */ - /* USER CODE END RTOS_THREADS */ - - /* USER CODE BEGIN RTOS_EVENTS */ - /* add events, ... */ - /* USER CODE END RTOS_EVENTS */ -} - -/* USER CODE BEGIN Header_app */ -/** - * @brief Function implementing the app_main thread. - * @param argument: Not used - * @retval None - */ -/* USER CODE END Header_app */ -__weak void app(void* argument) { - /* USER CODE BEGIN app */ - /* Infinite loop */ - for(;;) { - osDelay(1); - } - /* USER CODE END app */ -} - -/* Private application code --------------------------------------------------*/ -/* USER CODE BEGIN Application */ - -/* USER CODE END Application */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/comp.c b/firmware/targets/f7/cube/Src/comp.c deleted file mode 100644 index 95e697e3..00000000 --- a/firmware/targets/f7/cube/Src/comp.c +++ /dev/null @@ -1,103 +0,0 @@ -/** - ****************************************************************************** - * @file comp.c - * @brief This file provides code for the configuration - * of the COMP instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "comp.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -COMP_HandleTypeDef hcomp1; - -/* COMP1 init function */ -void MX_COMP1_Init(void) { - /* USER CODE BEGIN COMP1_Init 0 */ - - /* USER CODE END COMP1_Init 0 */ - - /* USER CODE BEGIN COMP1_Init 1 */ - - /* USER CODE END COMP1_Init 1 */ - hcomp1.Instance = COMP1; - hcomp1.Init.InputMinus = COMP_INPUT_MINUS_1_4VREFINT; - hcomp1.Init.InputPlus = COMP_INPUT_PLUS_IO1; - hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED; - hcomp1.Init.Hysteresis = COMP_HYSTERESIS_HIGH; - hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE; - hcomp1.Init.Mode = COMP_POWERMODE_MEDIUMSPEED; - hcomp1.Init.WindowMode = COMP_WINDOWMODE_DISABLE; - hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_IT_RISING_FALLING; - if(HAL_COMP_Init(&hcomp1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN COMP1_Init 2 */ - - /* USER CODE END COMP1_Init 2 */ -} - -void HAL_COMP_MspInit(COMP_HandleTypeDef* compHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(compHandle->Instance == COMP1) { - /* USER CODE BEGIN COMP1_MspInit 0 */ - - /* USER CODE END COMP1_MspInit 0 */ - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**COMP1 GPIO Configuration - PC5 ------> COMP1_INP - */ - GPIO_InitStruct.Pin = RFID_RF_IN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(RFID_RF_IN_GPIO_Port, &GPIO_InitStruct); - - /* COMP1 interrupt Init */ - HAL_NVIC_SetPriority(COMP_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(COMP_IRQn); - /* USER CODE BEGIN COMP1_MspInit 1 */ - - /* USER CODE END COMP1_MspInit 1 */ - } -} - -void HAL_COMP_MspDeInit(COMP_HandleTypeDef* compHandle) { - if(compHandle->Instance == COMP1) { - /* USER CODE BEGIN COMP1_MspDeInit 0 */ - - /* USER CODE END COMP1_MspDeInit 0 */ - - /**COMP1 GPIO Configuration - PC5 ------> COMP1_INP - */ - HAL_GPIO_DeInit(RFID_RF_IN_GPIO_Port, RFID_RF_IN_Pin); - - /* COMP1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(COMP_IRQn); - /* USER CODE BEGIN COMP1_MspDeInit 1 */ - - /* USER CODE END COMP1_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/crc.c b/firmware/targets/f7/cube/Src/crc.c deleted file mode 100644 index 203032ea..00000000 --- a/firmware/targets/f7/cube/Src/crc.c +++ /dev/null @@ -1,82 +0,0 @@ -/** - ****************************************************************************** - * @file crc.c - * @brief This file provides code for the configuration - * of the CRC instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "crc.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -CRC_HandleTypeDef hcrc; - -/* CRC init function */ -void MX_CRC_Init(void) { - /* USER CODE BEGIN CRC_Init 0 */ - - /* USER CODE END CRC_Init 0 */ - - /* USER CODE BEGIN CRC_Init 1 */ - - /* USER CODE END CRC_Init 1 */ - hcrc.Instance = CRC; - hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE; - hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE; - hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE; - hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE; - hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES; - if(HAL_CRC_Init(&hcrc) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN CRC_Init 2 */ - - /* USER CODE END CRC_Init 2 */ -} - -void HAL_CRC_MspInit(CRC_HandleTypeDef* crcHandle) { - if(crcHandle->Instance == CRC) { - /* USER CODE BEGIN CRC_MspInit 0 */ - - /* USER CODE END CRC_MspInit 0 */ - /* CRC clock enable */ - __HAL_RCC_CRC_CLK_ENABLE(); - /* USER CODE BEGIN CRC_MspInit 1 */ - - /* USER CODE END CRC_MspInit 1 */ - } -} - -void HAL_CRC_MspDeInit(CRC_HandleTypeDef* crcHandle) { - if(crcHandle->Instance == CRC) { - /* USER CODE BEGIN CRC_MspDeInit 0 */ - - /* USER CODE END CRC_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_CRC_CLK_DISABLE(); - /* USER CODE BEGIN CRC_MspDeInit 1 */ - - /* USER CODE END CRC_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/gpio.c b/firmware/targets/f7/cube/Src/gpio.c deleted file mode 100644 index d8fd35dc..00000000 --- a/firmware/targets/f7/cube/Src/gpio.c +++ /dev/null @@ -1,177 +0,0 @@ -/** - ****************************************************************************** - * @file gpio.c - * @brief This file provides code for the configuration - * of all used GPIO pins. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "gpio.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure GPIO */ -/*----------------------------------------------------------------------------*/ -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI -*/ -void MX_GPIO_Init(void) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOH_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOE_CLK_ENABLE(); - __HAL_RCC_GPIOD_CLK_ENABLE(); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOA, RFID_PULL_Pin | VIBRO_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(PERIPH_POWER_GPIO_Port, PERIPH_POWER_Pin, GPIO_PIN_SET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(RF_SW_0_GPIO_Port, RF_SW_0_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOB, DISPLAY_RST_Pin | DISPLAY_DI_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(NFC_CS_GPIO_Port, NFC_CS_Pin, GPIO_PIN_SET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOC, DISPLAY_CS_Pin | SD_CS_Pin, GPIO_PIN_SET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(CC1101_CS_GPIO_Port, CC1101_CS_Pin, GPIO_PIN_SET); - - /*Configure GPIO pin : PtPin */ - GPIO_InitStruct.Pin = BUTTON_BACK_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(BUTTON_BACK_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pin : PtPin */ - GPIO_InitStruct.Pin = BUTTON_OK_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(BUTTON_OK_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : PCPin PCPin PCPin */ - GPIO_InitStruct.Pin = PC0_Pin | PC1_Pin | PC3_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /*Configure GPIO pins : PAPin PAPin PAPin PAPin - PAPin */ - GPIO_InitStruct.Pin = CC1101_G0_Pin | PA4_Pin | PA6_Pin | PA7_Pin | RFID_CARRIER_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /*Configure GPIO pins : PAPin PAPin */ - GPIO_InitStruct.Pin = RFID_PULL_Pin | VIBRO_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /*Configure GPIO pin : PtPin */ - GPIO_InitStruct.Pin = PERIPH_POWER_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(PERIPH_POWER_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : PCPin PCPin */ - GPIO_InitStruct.Pin = RF_SW_0_Pin | DISPLAY_CS_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /*Configure GPIO pins : PBPin PBPin PBPin */ - GPIO_InitStruct.Pin = PB2_Pin | iBTN_Pin | PB3_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /*Configure GPIO pins : PBPin PBPin PBPin */ - GPIO_InitStruct.Pin = BUTTON_UP_Pin | BUTTON_LEFT_Pin | BUTTON_RIGHT_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /*Configure GPIO pins : PBPin PBPin */ - GPIO_InitStruct.Pin = DISPLAY_RST_Pin | DISPLAY_DI_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /*Configure GPIO pin : PtPin */ - GPIO_InitStruct.Pin = NFC_CS_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - HAL_GPIO_Init(NFC_CS_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : PCPin PCPin */ - GPIO_InitStruct.Pin = BUTTON_DOWN_Pin | SD_CD_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /*Configure GPIO pin : PtPin */ - GPIO_InitStruct.Pin = SD_CS_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - HAL_GPIO_Init(SD_CS_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pin : PtPin */ - GPIO_InitStruct.Pin = CC1101_CS_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - HAL_GPIO_Init(CC1101_CS_GPIO_Port, &GPIO_InitStruct); - - /* EXTI interrupt init*/ - HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI3_IRQn); - - HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/i2c.c b/firmware/targets/f7/cube/Src/i2c.c deleted file mode 100644 index 0ad9765a..00000000 --- a/firmware/targets/f7/cube/Src/i2c.c +++ /dev/null @@ -1,80 +0,0 @@ -/** - ****************************************************************************** - * @file i2c.c - * @brief This file provides code for the configuration - * of the I2C instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "i2c.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* I2C1 init function */ -void MX_I2C1_Init(void) { - /* USER CODE BEGIN I2C1_Init 0 */ - - /* USER CODE END I2C1_Init 0 */ - - LL_I2C_InitTypeDef I2C_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**I2C1 GPIO Configuration - PA9 ------> I2C1_SCL - PA10 ------> I2C1_SDA - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9 | LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; - GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; - GPIO_InitStruct.Alternate = LL_GPIO_AF_4; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1); - - /* USER CODE BEGIN I2C1_Init 1 */ - - /* USER CODE END I2C1_Init 1 */ - /** I2C Initialization - */ - I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; - I2C_InitStruct.Timing = 0x10707DBC; - I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; - I2C_InitStruct.DigitalFilter = 0; - I2C_InitStruct.OwnAddress1 = 0; - I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK; - I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT; - LL_I2C_Init(I2C1, &I2C_InitStruct); - LL_I2C_EnableAutoEndMode(I2C1); - LL_I2C_SetOwnAddress2(I2C1, 0, LL_I2C_OWNADDRESS2_NOMASK); - LL_I2C_DisableOwnAddress2(I2C1); - LL_I2C_DisableGeneralCall(I2C1); - LL_I2C_EnableClockStretching(I2C1); - /* USER CODE BEGIN I2C1_Init 2 */ - - /* USER CODE END I2C1_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/main.c b/firmware/targets/f7/cube/Src/main.c deleted file mode 100644 index d4ec7ec2..00000000 --- a/firmware/targets/f7/cube/Src/main.c +++ /dev/null @@ -1,275 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Includes ------------------------------------------------------------------*/ -#include "main.h" -#include "cmsis_os.h" -#include "adc.h" -#include "aes.h" -#include "comp.h" -#include "crc.h" -#include "i2c.h" -#include "pka.h" -#include "rf.h" -#include "rng.h" -#include "rtc.h" -#include "spi.h" -#include "tim.h" -#include "usart.h" -#include "usb_device.h" -#include "gpio.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN PD */ -/* USER CODE END PD */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN PM */ - -/* USER CODE END PM */ - -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -void SystemClock_Config(void); -void MX_FREERTOS_Init(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) { - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); - - /* USER CODE BEGIN Init */ - - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_ADC1_Init(); - MX_I2C1_Init(); - MX_RTC_Init(); - MX_SPI1_Init(); - MX_SPI2_Init(); - MX_USB_Device_Init(); - MX_TIM1_Init(); - MX_TIM2_Init(); - MX_TIM16_Init(); - MX_COMP1_Init(); - MX_RF_Init(); - MX_PKA_Init(); - MX_RNG_Init(); - MX_AES1_Init(); - MX_AES2_Init(); - MX_CRC_Init(); - MX_USART1_UART_Init(); - /* USER CODE BEGIN 2 */ - - /* USER CODE END 2 */ - - /* Init scheduler */ - osKernelInitialize(); /* Call init function for freertos objects (in freertos.c) */ - MX_FREERTOS_Init(); - /* Start scheduler */ - osKernelStart(); - - /* We should never get here as control is now taken by the scheduler */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while(1) { - /* USER CODE END WHILE */ - - /* USER CODE BEGIN 3 */ - } - /* USER CODE END 3 */ -} - -/** - * @brief System Clock Configuration - * @retval None - */ -void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_3); - while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_3) { - } - - /* HSE configuration and activation */ - LL_RCC_HSE_Enable(); - while(LL_RCC_HSE_IsReady() != 1) { - } - - /* HSI configuration and activation */ - LL_RCC_HSI_Enable(); - while(LL_RCC_HSI_IsReady() != 1) { - } - - LL_PWR_EnableBkUpAccess(); - if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE) { - LL_RCC_ForceBackupDomainReset(); - LL_RCC_ReleaseBackupDomainReset(); - } - LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_MEDIUMLOW); - LL_RCC_LSE_Enable(); - - /* Wait till LSE is ready */ - while(LL_RCC_LSE_IsReady() != 1) { - } - - LL_RCC_HSE_EnableCSS(); - LL_RCC_LSE_EnableCSS(); - /* Main PLL configuration and activation */ - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_2, 8, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_Enable(); - LL_RCC_PLL_EnableDomain_SYS(); - while(LL_RCC_PLL_IsReady() != 1) { - } - - LL_RCC_PLLSAI1_ConfigDomain_48M( - LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_2, 6, LL_RCC_PLLSAI1Q_DIV_2); - LL_RCC_PLLSAI1_ConfigDomain_ADC( - LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_2, 6, LL_RCC_PLLSAI1R_DIV_2); - LL_RCC_PLLSAI1_Enable(); - LL_RCC_PLLSAI1_EnableDomain_48M(); - LL_RCC_PLLSAI1_EnableDomain_ADC(); - - /* Wait till PLLSAI1 is ready */ - while(LL_RCC_PLLSAI1_IsReady() != 1) { - } - - /* Sysclk activation on the main PLL */ - /* Set CPU1 prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - - /* Set CPU2 prescaler*/ - LL_C2_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { - } - - /* Set AHB SHARED prescaler*/ - LL_RCC_SetAHB4Prescaler(LL_RCC_SYSCLK_DIV_1); - - /* Set APB1 prescaler*/ - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - - /* Set APB2 prescaler*/ - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - - /* Disable MSI */ - LL_RCC_MSI_Disable(); - while(LL_RCC_MSI_IsReady() != 0) { - } - - /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ - LL_SetSystemCoreClock(64000000); - - /* Update the time base */ - if(HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } - if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE) { - LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE); - } - LL_RCC_EnableRTC(); - LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2); - LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSOURCE_PLLSAI1); - LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_PCLK1); - LL_RCC_SetRNGClockSource(LL_RCC_RNG_CLKSOURCE_CLK48); - LL_RCC_SetUSBClockSource(LL_RCC_USB_CLKSOURCE_PLLSAI1); - LL_RCC_SetCLK48ClockSource(LL_RCC_CLK48_CLKSOURCE_PLLSAI1); - LL_RCC_SetSMPSClockSource(LL_RCC_SMPS_CLKSOURCE_HSE); - LL_RCC_SetSMPSPrescaler(LL_RCC_SMPS_DIV_1); - LL_RCC_SetRFWKPClockSource(LL_RCC_RFWKP_CLKSOURCE_LSE); - /* USER CODE BEGIN Smps */ - - /* USER CODE END Smps */ -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return state */ - __disable_irq(); - while(1) { - } - /* USER CODE END Error_Handler_Debug */ -} - -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t* file, uint32_t line) { - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line number, - ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/pka.c b/firmware/targets/f7/cube/Src/pka.c deleted file mode 100644 index 6a581317..00000000 --- a/firmware/targets/f7/cube/Src/pka.c +++ /dev/null @@ -1,77 +0,0 @@ -/** - ****************************************************************************** - * @file pka.c - * @brief This file provides code for the configuration - * of the PKA instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "pka.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -PKA_HandleTypeDef hpka; - -/* PKA init function */ -void MX_PKA_Init(void) { - /* USER CODE BEGIN PKA_Init 0 */ - - /* USER CODE END PKA_Init 0 */ - - /* USER CODE BEGIN PKA_Init 1 */ - - /* USER CODE END PKA_Init 1 */ - hpka.Instance = PKA; - if(HAL_PKA_Init(&hpka) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN PKA_Init 2 */ - - /* USER CODE END PKA_Init 2 */ -} - -void HAL_PKA_MspInit(PKA_HandleTypeDef* pkaHandle) { - if(pkaHandle->Instance == PKA) { - /* USER CODE BEGIN PKA_MspInit 0 */ - - /* USER CODE END PKA_MspInit 0 */ - /* PKA clock enable */ - __HAL_RCC_PKA_CLK_ENABLE(); - /* USER CODE BEGIN PKA_MspInit 1 */ - - /* USER CODE END PKA_MspInit 1 */ - } -} - -void HAL_PKA_MspDeInit(PKA_HandleTypeDef* pkaHandle) { - if(pkaHandle->Instance == PKA) { - /* USER CODE BEGIN PKA_MspDeInit 0 */ - - /* USER CODE END PKA_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_PKA_CLK_DISABLE(); - /* USER CODE BEGIN PKA_MspDeInit 1 */ - - /* USER CODE END PKA_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/rf.c b/firmware/targets/f7/cube/Src/rf.c deleted file mode 100644 index eaa4ba67..00000000 --- a/firmware/targets/f7/cube/Src/rf.c +++ /dev/null @@ -1,45 +0,0 @@ -/** - ****************************************************************************** - * @file rf.c - * @brief This file provides code for the configuration - * of the RF instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "rf.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* RF init function */ -void MX_RF_Init(void) { - /* USER CODE BEGIN RF_Init 0 */ - - /* USER CODE END RF_Init 0 */ - - /* USER CODE BEGIN RF_Init 1 */ - - /* USER CODE END RF_Init 1 */ - /* USER CODE BEGIN RF_Init 2 */ - - /* USER CODE END RF_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/rng.c b/firmware/targets/f7/cube/Src/rng.c deleted file mode 100644 index bab1b278..00000000 --- a/firmware/targets/f7/cube/Src/rng.c +++ /dev/null @@ -1,78 +0,0 @@ -/** - ****************************************************************************** - * @file rng.c - * @brief This file provides code for the configuration - * of the RNG instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "rng.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -RNG_HandleTypeDef hrng; - -/* RNG init function */ -void MX_RNG_Init(void) { - /* USER CODE BEGIN RNG_Init 0 */ - - /* USER CODE END RNG_Init 0 */ - - /* USER CODE BEGIN RNG_Init 1 */ - - /* USER CODE END RNG_Init 1 */ - hrng.Instance = RNG; - hrng.Init.ClockErrorDetection = RNG_CED_ENABLE; - if(HAL_RNG_Init(&hrng) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN RNG_Init 2 */ - - /* USER CODE END RNG_Init 2 */ -} - -void HAL_RNG_MspInit(RNG_HandleTypeDef* rngHandle) { - if(rngHandle->Instance == RNG) { - /* USER CODE BEGIN RNG_MspInit 0 */ - - /* USER CODE END RNG_MspInit 0 */ - /* RNG clock enable */ - __HAL_RCC_RNG_CLK_ENABLE(); - /* USER CODE BEGIN RNG_MspInit 1 */ - - /* USER CODE END RNG_MspInit 1 */ - } -} - -void HAL_RNG_MspDeInit(RNG_HandleTypeDef* rngHandle) { - if(rngHandle->Instance == RNG) { - /* USER CODE BEGIN RNG_MspDeInit 0 */ - - /* USER CODE END RNG_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_RNG_CLK_DISABLE(); - /* USER CODE BEGIN RNG_MspDeInit 1 */ - - /* USER CODE END RNG_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/rtc.c b/firmware/targets/f7/cube/Src/rtc.c deleted file mode 100644 index 416159f8..00000000 --- a/firmware/targets/f7/cube/Src/rtc.c +++ /dev/null @@ -1,122 +0,0 @@ -/** - ****************************************************************************** - * @file rtc.c - * @brief This file provides code for the configuration - * of the RTC instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "rtc.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -RTC_HandleTypeDef hrtc; - -/* RTC init function */ -void MX_RTC_Init(void) { - /* USER CODE BEGIN RTC_Init 0 */ - - /* USER CODE END RTC_Init 0 */ - - RTC_TimeTypeDef sTime = {0}; - RTC_DateTypeDef sDate = {0}; - - /* USER CODE BEGIN RTC_Init 1 */ - - /* USER CODE END RTC_Init 1 */ - /** Initialize RTC Only - */ - hrtc.Instance = RTC; - hrtc.Init.HourFormat = RTC_HOURFORMAT_24; - hrtc.Init.AsynchPrediv = 127; - hrtc.Init.SynchPrediv = 255; - hrtc.Init.OutPut = RTC_OUTPUT_DISABLE; - hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; - hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; - hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE; - if(HAL_RTC_Init(&hrtc) != HAL_OK) { - Error_Handler(); - } - - /* USER CODE BEGIN Check_RTC_BKUP */ - - /* USER CODE END Check_RTC_BKUP */ - - /** Initialize RTC and set the Time and Date - */ - sTime.Hours = 0x0; - sTime.Minutes = 0x0; - sTime.Seconds = 0x0; - sTime.SubSeconds = 0x0; - sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; - sTime.StoreOperation = RTC_STOREOPERATION_RESET; - if(HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK) { - Error_Handler(); - } - sDate.WeekDay = RTC_WEEKDAY_MONDAY; - sDate.Month = RTC_MONTH_JANUARY; - sDate.Date = 0x1; - sDate.Year = 0x0; - - if(HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN RTC_Init 2 */ - - /* USER CODE END RTC_Init 2 */ -} - -void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle) { - if(rtcHandle->Instance == RTC) { - /* USER CODE BEGIN RTC_MspInit 0 */ - - /* USER CODE END RTC_MspInit 0 */ - /* RTC clock enable */ - __HAL_RCC_RTC_ENABLE(); - __HAL_RCC_RTCAPB_CLK_ENABLE(); - - /* RTC interrupt Init */ - HAL_NVIC_SetPriority(TAMP_STAMP_LSECSS_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(TAMP_STAMP_LSECSS_IRQn); - /* USER CODE BEGIN RTC_MspInit 1 */ - - /* USER CODE END RTC_MspInit 1 */ - } -} - -void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle) { - if(rtcHandle->Instance == RTC) { - /* USER CODE BEGIN RTC_MspDeInit 0 */ - - /* USER CODE END RTC_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_RTC_DISABLE(); - __HAL_RCC_RTCAPB_CLK_DISABLE(); - - /* RTC interrupt Deinit */ - HAL_NVIC_DisableIRQ(TAMP_STAMP_LSECSS_IRQn); - /* USER CODE BEGIN RTC_MspDeInit 1 */ - - /* USER CODE END RTC_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/spi.c b/firmware/targets/f7/cube/Src/spi.c deleted file mode 100644 index 329bc3bb..00000000 --- a/firmware/targets/f7/cube/Src/spi.c +++ /dev/null @@ -1,214 +0,0 @@ -/** - ****************************************************************************** - * @file spi.c - * @brief This file provides code for the configuration - * of the SPI instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "spi.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -SPI_HandleTypeDef hspi1; -SPI_HandleTypeDef hspi2; - -/* SPI1 init function */ -void MX_SPI1_Init(void) { - /* USER CODE BEGIN SPI1_Init 0 */ - - /* USER CODE END SPI1_Init 0 */ - - /* USER CODE BEGIN SPI1_Init 1 */ - - /* USER CODE END SPI1_Init 1 */ - hspi1.Instance = SPI1; - hspi1.Init.Mode = SPI_MODE_MASTER; - hspi1.Init.Direction = SPI_DIRECTION_2LINES; - hspi1.Init.DataSize = SPI_DATASIZE_8BIT; - hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; - hspi1.Init.CLKPhase = SPI_PHASE_2EDGE; - hspi1.Init.NSS = SPI_NSS_SOFT; - hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; - hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; - hspi1.Init.TIMode = SPI_TIMODE_DISABLE; - hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; - hspi1.Init.CRCPolynomial = 7; - hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; - hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE; - if(HAL_SPI_Init(&hspi1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN SPI1_Init 2 */ - - /* USER CODE END SPI1_Init 2 */ -} -/* SPI2 init function */ -void MX_SPI2_Init(void) { - /* USER CODE BEGIN SPI2_Init 0 */ - - /* USER CODE END SPI2_Init 0 */ - - /* USER CODE BEGIN SPI2_Init 1 */ - - /* USER CODE END SPI2_Init 1 */ - hspi2.Instance = SPI2; - hspi2.Init.Mode = SPI_MODE_MASTER; - hspi2.Init.Direction = SPI_DIRECTION_2LINES; - hspi2.Init.DataSize = SPI_DATASIZE_8BIT; - hspi2.Init.CLKPolarity = SPI_POLARITY_LOW; - hspi2.Init.CLKPhase = SPI_PHASE_1EDGE; - hspi2.Init.NSS = SPI_NSS_SOFT; - hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; - hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB; - hspi2.Init.TIMode = SPI_TIMODE_DISABLE; - hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; - hspi2.Init.CRCPolynomial = 7; - hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; - hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE; - if(HAL_SPI_Init(&hspi2) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN SPI2_Init 2 */ - - /* USER CODE END SPI2_Init 2 */ -} - -void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(spiHandle->Instance == SPI1) { - /* USER CODE BEGIN SPI1_MspInit 0 */ - - /* USER CODE END SPI1_MspInit 0 */ - /* SPI1 clock enable */ - __HAL_RCC_SPI1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**SPI1 GPIO Configuration - PA5 ------> SPI1_SCK - PB4 ------> SPI1_MISO - PB5 ------> SPI1_MOSI - */ - GPIO_InitStruct.Pin = SPI_R_SCK_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; - HAL_GPIO_Init(SPI_R_SCK_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = SPI_R_MISO_Pin | SPI_R_MOSI_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* USER CODE BEGIN SPI1_MspInit 1 */ - - /* USER CODE END SPI1_MspInit 1 */ - } else if(spiHandle->Instance == SPI2) { - /* USER CODE BEGIN SPI2_MspInit 0 */ - - /* USER CODE END SPI2_MspInit 0 */ - /* SPI2 clock enable */ - __HAL_RCC_SPI2_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_GPIOD_CLK_ENABLE(); - /**SPI2 GPIO Configuration - PC2 ------> SPI2_MISO - PB15 ------> SPI2_MOSI - PD1 ------> SPI2_SCK - */ - GPIO_InitStruct.Pin = SPI_D_MISO_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; - HAL_GPIO_Init(SPI_D_MISO_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = SPI_D_MOSI_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; - HAL_GPIO_Init(SPI_D_MOSI_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = SPI_D_SCK_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; - HAL_GPIO_Init(SPI_D_SCK_GPIO_Port, &GPIO_InitStruct); - - /* USER CODE BEGIN SPI2_MspInit 1 */ - - /* USER CODE END SPI2_MspInit 1 */ - } -} - -void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) { - if(spiHandle->Instance == SPI1) { - /* USER CODE BEGIN SPI1_MspDeInit 0 */ - - /* USER CODE END SPI1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_SPI1_CLK_DISABLE(); - - /**SPI1 GPIO Configuration - PA5 ------> SPI1_SCK - PB4 ------> SPI1_MISO - PB5 ------> SPI1_MOSI - */ - HAL_GPIO_DeInit(SPI_R_SCK_GPIO_Port, SPI_R_SCK_Pin); - - HAL_GPIO_DeInit(GPIOB, SPI_R_MISO_Pin | SPI_R_MOSI_Pin); - - /* USER CODE BEGIN SPI1_MspDeInit 1 */ - - /* USER CODE END SPI1_MspDeInit 1 */ - } else if(spiHandle->Instance == SPI2) { - /* USER CODE BEGIN SPI2_MspDeInit 0 */ - - /* USER CODE END SPI2_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_SPI2_CLK_DISABLE(); - - /**SPI2 GPIO Configuration - PC2 ------> SPI2_MISO - PB15 ------> SPI2_MOSI - PD1 ------> SPI2_SCK - */ - HAL_GPIO_DeInit(SPI_D_MISO_GPIO_Port, SPI_D_MISO_Pin); - - HAL_GPIO_DeInit(SPI_D_MOSI_GPIO_Port, SPI_D_MOSI_Pin); - - HAL_GPIO_DeInit(SPI_D_SCK_GPIO_Port, SPI_D_SCK_Pin); - - /* USER CODE BEGIN SPI2_MspDeInit 1 */ - - /* USER CODE END SPI2_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/stm32wbxx_hal_msp.c b/firmware/targets/f7/cube/Src/stm32wbxx_hal_msp.c deleted file mode 100644 index 90ef3c3f..00000000 --- a/firmware/targets/f7/cube/Src/stm32wbxx_hal_msp.c +++ /dev/null @@ -1,92 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32wbxx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN TD */ - -/* USER CODE END TD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN Define */ - -/* USER CODE END Define */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN Macro */ - -/* USER CODE END Macro */ - -/* Private variables ---------------------------------------------------------*/ -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* External functions --------------------------------------------------------*/ -/* USER CODE BEGIN ExternalFunctions */ - -/* USER CODE END ExternalFunctions */ - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ -/** - * Initializes the Global MSP. - */ -void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ - - /* USER CODE END MspInit 0 */ - - __HAL_RCC_HSEM_CLK_ENABLE(); - - /* System interrupt init*/ - /* PendSV_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0); - - /* Peripheral interrupt init */ - /* RCC_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(RCC_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(RCC_IRQn); - /* HSEM_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(HSEM_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(HSEM_IRQn); - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/stm32wbxx_it.c b/firmware/targets/f7/cube/Src/stm32wbxx_it.c deleted file mode 100644 index 57f420fb..00000000 --- a/firmware/targets/f7/cube/Src/stm32wbxx_it.c +++ /dev/null @@ -1,304 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32wbxx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" -#include "stm32wbxx_it.h" -#include "FreeRTOS.h" -#include "task.h" -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN TD */ - -/* USER CODE END TD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN PD */ - -/* USER CODE END PD */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN PM */ - -/* USER CODE END PM */ - -/* Private variables ---------------------------------------------------------*/ -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* External variables --------------------------------------------------------*/ -extern PCD_HandleTypeDef hpcd_USB_FS; -extern ADC_HandleTypeDef hadc1; -extern COMP_HandleTypeDef hcomp1; -extern RTC_HandleTypeDef hrtc; -extern TIM_HandleTypeDef htim1; -extern TIM_HandleTypeDef htim2; -/* USER CODE BEGIN EV */ - -/* USER CODE END EV */ - -/******************************************************************************/ -/* Cortex Processor Interruption and Exception Handlers */ -/******************************************************************************/ -/** - * @brief This function handles Non maskable interrupt. - */ -void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ - while(1) { - } - /* USER CODE END NonMaskableInt_IRQn 1 */ -} - -/** - * @brief This function handles Hard fault interrupt. - */ -void HardFault_Handler(void) { - /* USER CODE BEGIN HardFault_IRQn 0 */ - - /* USER CODE END HardFault_IRQn 0 */ - while(1) { - /* USER CODE BEGIN W1_HardFault_IRQn 0 */ - /* USER CODE END W1_HardFault_IRQn 0 */ - } -} - -/** - * @brief This function handles Memory management fault. - */ -void MemManage_Handler(void) { - /* USER CODE BEGIN MemoryManagement_IRQn 0 */ - - /* USER CODE END MemoryManagement_IRQn 0 */ - while(1) { - /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ - /* USER CODE END W1_MemoryManagement_IRQn 0 */ - } -} - -/** - * @brief This function handles Prefetch fault, memory access fault. - */ -void BusFault_Handler(void) { - /* USER CODE BEGIN BusFault_IRQn 0 */ - - /* USER CODE END BusFault_IRQn 0 */ - while(1) { - /* USER CODE BEGIN W1_BusFault_IRQn 0 */ - /* USER CODE END W1_BusFault_IRQn 0 */ - } -} - -/** - * @brief This function handles Undefined instruction or illegal state. - */ -void UsageFault_Handler(void) { - /* USER CODE BEGIN UsageFault_IRQn 0 */ - - /* USER CODE END UsageFault_IRQn 0 */ - while(1) { - /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ - /* USER CODE END W1_UsageFault_IRQn 0 */ - } -} - -/** - * @brief This function handles Debug monitor. - */ -void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - - /* USER CODE END DebugMonitor_IRQn 1 */ -} - -/** - * @brief This function handles System tick timer. - */ -void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ - - /* USER CODE END SysTick_IRQn 0 */ - /* USER CODE BEGIN SysTick_IRQn 1 */ - - /* USER CODE END SysTick_IRQn 1 */ -} - -/******************************************************************************/ -/* STM32WBxx Peripheral Interrupt Handlers */ -/* Add here the Interrupt Handlers for the used peripherals. */ -/* For the available peripheral interrupt handler names, */ -/* please refer to the startup file (startup_stm32wbxx.s). */ -/******************************************************************************/ - -/** - * @brief This function handles RTC tamper and time stamp, CSS on LSE interrupts through EXTI line 18. - */ -void TAMP_STAMP_LSECSS_IRQHandler(void) { - /* USER CODE BEGIN TAMP_STAMP_LSECSS_IRQn 0 */ - - /* USER CODE END TAMP_STAMP_LSECSS_IRQn 0 */ - /* USER CODE BEGIN TAMP_STAMP_LSECSS_IRQn 1 */ - - /* USER CODE END TAMP_STAMP_LSECSS_IRQn 1 */ -} - -/** - * @brief This function handles RCC global interrupt. - */ -void RCC_IRQHandler(void) { - /* USER CODE BEGIN RCC_IRQn 0 */ - - /* USER CODE END RCC_IRQn 0 */ - /* USER CODE BEGIN RCC_IRQn 1 */ - - /* USER CODE END RCC_IRQn 1 */ -} - -/** - * @brief This function handles EXTI line3 interrupt. - */ -void EXTI3_IRQHandler(void) { - /* USER CODE BEGIN EXTI3_IRQn 0 */ - - /* USER CODE END EXTI3_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3); - /* USER CODE BEGIN EXTI3_IRQn 1 */ - - /* USER CODE END EXTI3_IRQn 1 */ -} - -/** - * @brief This function handles ADC1 global interrupt. - */ -void ADC1_IRQHandler(void) { - /* USER CODE BEGIN ADC1_IRQn 0 */ - - /* USER CODE END ADC1_IRQn 0 */ - HAL_ADC_IRQHandler(&hadc1); - /* USER CODE BEGIN ADC1_IRQn 1 */ - - /* USER CODE END ADC1_IRQn 1 */ -} - -/** - * @brief This function handles USB low priority interrupt, USB wake-up interrupt through EXTI line 28. - */ -void USB_LP_IRQHandler(void) { - /* USER CODE BEGIN USB_LP_IRQn 0 */ - - /* USER CODE END USB_LP_IRQn 0 */ - HAL_PCD_IRQHandler(&hpcd_USB_FS); - /* USER CODE BEGIN USB_LP_IRQn 1 */ - - /* USER CODE END USB_LP_IRQn 1 */ -} - -/** - * @brief This function handles COMP1 and COMP2 interrupts through EXTI lines 20 and 21. - */ -void COMP_IRQHandler(void) { - /* USER CODE BEGIN COMP_IRQn 0 */ - - /* USER CODE END COMP_IRQn 0 */ - HAL_COMP_IRQHandler(&hcomp1); - /* USER CODE BEGIN COMP_IRQn 1 */ - - /* USER CODE END COMP_IRQn 1 */ -} - -/** - * @brief This function handles TIM1 trigger and commutation interrupts and TIM17 global interrupt. - */ -void TIM1_TRG_COM_TIM17_IRQHandler(void) { - /* USER CODE BEGIN TIM1_TRG_COM_TIM17_IRQn 0 */ - - /* USER CODE END TIM1_TRG_COM_TIM17_IRQn 0 */ - HAL_TIM_IRQHandler(&htim1); - /* USER CODE BEGIN TIM1_TRG_COM_TIM17_IRQn 1 */ - - /* USER CODE END TIM1_TRG_COM_TIM17_IRQn 1 */ -} - -/** - * @brief This function handles TIM2 global interrupt. - */ -void TIM2_IRQHandler(void) { - /* USER CODE BEGIN TIM2_IRQn 0 */ - - /* USER CODE END TIM2_IRQn 0 */ - HAL_TIM_IRQHandler(&htim2); - /* USER CODE BEGIN TIM2_IRQn 1 */ - - /* USER CODE END TIM2_IRQn 1 */ -} - -/** - * @brief This function handles EXTI line[15:10] interrupts. - */ -void EXTI15_10_IRQHandler(void) { - /* USER CODE BEGIN EXTI15_10_IRQn 0 */ - - /* USER CODE END EXTI15_10_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10); - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_11); - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_12); - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13); - /* USER CODE BEGIN EXTI15_10_IRQn 1 */ - - /* USER CODE END EXTI15_10_IRQn 1 */ -} - -/** - * @brief This function handles HSEM global interrupt. - */ -void HSEM_IRQHandler(void) { - /* USER CODE BEGIN HSEM_IRQn 0 */ - - /* USER CODE END HSEM_IRQn 0 */ - HAL_HSEM_IRQHandler(); - /* USER CODE BEGIN HSEM_IRQn 1 */ - - /* USER CODE END HSEM_IRQn 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/system_stm32wbxx.c b/firmware/targets/f7/cube/Src/system_stm32wbxx.c deleted file mode 100644 index ff09f34c..00000000 --- a/firmware/targets/f7/cube/Src/system_stm32wbxx.c +++ /dev/null @@ -1,384 +0,0 @@ -/** - ****************************************************************************** - * @file system_stm32wbxx.c - * @author MCD Application Team - * @brief CMSIS Cortex Device Peripheral Access Layer System Source File - * - * This file provides two functions and one global variable to be called from - * user application: - * - SystemInit(): This function is called at startup just after reset and - * before branch to main program. This call is made inside - * the "startup_stm32wbxx.s" file. - * - * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used - * by the user application to setup the SysTick - * timer or configure other parameters. - * - * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must - * be called whenever the core clock is changed - * during program execution. - * - * After each device reset the MSI (4 MHz) is used as system clock source. - * Then SystemInit() function is called, in "startup_stm32wbxx.s" file, to - * configure the system clock before to branch to main program. - * - * This file configures the system clock as follows: - *============================================================================= - *----------------------------------------------------------------------------- - * System Clock source | MSI - *----------------------------------------------------------------------------- - * SYSCLK(Hz) | 4000000 - *----------------------------------------------------------------------------- - * HCLK(Hz) | 4000000 - *----------------------------------------------------------------------------- - * AHB Prescaler | 1 - *----------------------------------------------------------------------------- - * APB1 Prescaler | 1 - *----------------------------------------------------------------------------- - * APB2 Prescaler | 1 - *----------------------------------------------------------------------------- - * PLL_M | 1 - *----------------------------------------------------------------------------- - * PLL_N | 8 - *----------------------------------------------------------------------------- - * PLL_P | 7 - *----------------------------------------------------------------------------- - * PLL_Q | 2 - *----------------------------------------------------------------------------- - * PLL_R | 2 - *----------------------------------------------------------------------------- - * PLLSAI1_P | NA - *----------------------------------------------------------------------------- - * PLLSAI1_Q | NA - *----------------------------------------------------------------------------- - * PLLSAI1_R | NA - *----------------------------------------------------------------------------- - * Require 48MHz for USB OTG FS, | Disabled - * SDIO and RNG clock | - *----------------------------------------------------------------------------- - *============================================================================= - ****************************************************************************** - * @attention - * - * Copyright (c) 2019-2021 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/** @addtogroup CMSIS - * @{ - */ - -/** @addtogroup stm32WBxx_system - * @{ - */ - -/** @addtogroup stm32WBxx_System_Private_Includes - * @{ - */ - -#include "stm32wbxx.h" - -#if !defined(HSE_VALUE) -#define HSE_VALUE (32000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(MSI_VALUE) -#define MSI_VALUE (4000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* MSI_VALUE */ - -#if !defined(HSI_VALUE) -#define HSI_VALUE (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ - -#if !defined(LSI_VALUE) -#define LSI_VALUE (32000UL) /*!< Value of LSI in Hz*/ -#endif /* LSI_VALUE */ - -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of LSE in Hz*/ -#endif /* LSE_VALUE */ - -/** - * @} - */ - -/** @addtogroup STM32WBxx_System_Private_TypesDefinitions - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32WBxx_System_Private_Defines - * @{ - */ - -/* Note: Following vector table addresses must be defined in line with linker - configuration. */ -/*!< Uncomment the following line if you need to relocate CPU1 CM4 and/or CPU2 - CM0+ vector table anywhere in Sram or Flash. Else vector table will be kept - at address 0x00 which correspond to automatic remap of boot address selected */ -/* #define USER_VECT_TAB_ADDRESS */ -#if defined(USER_VECT_TAB_ADDRESS) -/*!< Uncomment this line for user vector table remap in Sram else user remap - will be done in Flash. */ -/* #define VECT_TAB_SRAM */ -#if defined(VECT_TAB_SRAM) -#define VECT_TAB_BASE_ADDRESS \ - SRAM1_BASE /*!< Vector Table base address field. - This value must be a multiple of 0x200. */ -#define VECT_TAB_OFFSET \ - 0x00000000U /*!< Vector Table base offset field. - This value must be a multiple of 0x200. */ -#else -#define VECT_TAB_BASE_ADDRESS \ - FLASH_BASE /*!< Vector Table base address field. - This value must be a multiple of 0x200. */ -#define VECT_TAB_OFFSET \ - 0x00000000U /*!< Vector Table base offset field. - This value must be a multiple of 0x200. */ -#endif -#endif - -/** - * @} - */ - -/** @addtogroup STM32WBxx_System_Private_Macros - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32WBxx_System_Private_Variables - * @{ - */ -/* The SystemCoreClock variable is updated in three ways: - 1) by calling CMSIS function SystemCoreClockUpdate() - 2) by calling HAL API function HAL_RCC_GetHCLKFreq() - 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency - Note: If you use this function to configure the system clock; then there - is no need to call the 2 first functions listed above, since SystemCoreClock - variable is updated automatically. - */ -uint32_t SystemCoreClock = 4000000UL; /*CPU1: M4 on MSI clock after startup (4MHz)*/ - -const uint32_t AHBPrescTable[16UL] = - {1UL, 3UL, 5UL, 1UL, 1UL, 6UL, 10UL, 32UL, 2UL, 4UL, 8UL, 16UL, 64UL, 128UL, 256UL, 512UL}; - -const uint32_t APBPrescTable[8UL] = {0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL}; - -const uint32_t MSIRangeTable[16UL] = { - 100000UL, - 200000UL, - 400000UL, - 800000UL, - 1000000UL, - 2000000UL, - 4000000UL, - 8000000UL, - 16000000UL, - 24000000UL, - 32000000UL, - 48000000UL, - 0UL, - 0UL, - 0UL, - 0UL}; /* 0UL values are incorrect cases */ - -#if defined(STM32WB55xx) || defined(STM32WB5Mxx) || defined(STM32WB35xx) || \ - defined(STM32WB15xx) || defined(STM32WB10xx) -const uint32_t SmpsPrescalerTable[4UL][6UL] = { - {1UL, 3UL, 2UL, 2UL, 1UL, 2UL}, - {2UL, 6UL, 4UL, 3UL, 2UL, 4UL}, - {4UL, 12UL, 8UL, 6UL, 4UL, 8UL}, - {4UL, 12UL, 8UL, 6UL, 4UL, 8UL}}; -#endif - -/** - * @} - */ - -/** @addtogroup STM32WBxx_System_Private_FunctionPrototypes - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32WBxx_System_Private_Functions - * @{ - */ - -/** - * @brief Setup the microcontroller system. - * @param None - * @retval None - */ -void SystemInit(void) { -#if defined(USER_VECT_TAB_ADDRESS) - /* Configure the Vector Table location add offset address ------------------*/ - SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; -#endif - -/* FPU settings ------------------------------------------------------------*/ -#if(__FPU_PRESENT == 1) && (__FPU_USED == 1) - SCB->CPACR |= - ((3UL << (10UL * 2UL)) | (3UL << (11UL * 2UL))); /* set CP10 and CP11 Full Access */ -#endif - - /* Reset the RCC clock configuration to the default reset state ------------*/ - /* Set MSION bit */ - RCC->CR |= RCC_CR_MSION; - - /* Reset CFGR register */ - RCC->CFGR = 0x00070000U; - - /* Reset PLLSAI1ON, PLLON, HSECSSON, HSEON, HSION, and MSIPLLON bits */ - RCC->CR &= (uint32_t)0xFAF6FEFBU; - - /*!< Reset LSI1 and LSI2 bits */ - RCC->CSR &= (uint32_t)0xFFFFFFFAU; - - /*!< Reset HSI48ON bit */ - RCC->CRRCR &= (uint32_t)0xFFFFFFFEU; - - /* Reset PLLCFGR register */ - RCC->PLLCFGR = 0x22041000U; - -#if defined(STM32WB55xx) || defined(STM32WB5Mxx) - /* Reset PLLSAI1CFGR register */ - RCC->PLLSAI1CFGR = 0x22041000U; -#endif - - /* Reset HSEBYP bit */ - RCC->CR &= 0xFFFBFFFFU; - - /* Disable all interrupts */ - RCC->CIER = 0x00000000; -} - -/** - * @brief Update SystemCoreClock variable according to Clock Register Values. - * The SystemCoreClock variable contains the core clock (HCLK), it can - * be used by the user application to setup the SysTick timer or configure - * other parameters. - * - * @note Each time the core clock (HCLK) changes, this function must be called - * to update SystemCoreClock variable value. Otherwise, any configuration - * based on this variable will be incorrect. - * - * @note - The system frequency computed by this function is not the real - * frequency in the chip. It is calculated based on the predefined - * constant and the selected clock source: - * - * - If SYSCLK source is MSI, SystemCoreClock will contain the MSI_VALUE(*) - * - * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**) - * - * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***) - * - * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***) - * or HSI_VALUE(*) or MSI_VALUE(*) multiplied/divided by the PLL factors. - * - * (*) MSI_VALUE is a constant defined in stm32wbxx_hal.h file (default value - * 4 MHz) but the real value may vary depending on the variations - * in voltage and temperature. - * - * (**) HSI_VALUE is a constant defined in stm32wbxx_hal_conf.h file (default value - * 16 MHz) but the real value may vary depending on the variations - * in voltage and temperature. - * - * (***) HSE_VALUE is a constant defined in stm32wbxx_hal_conf.h file (default value - * 32 MHz), user has to ensure that HSE_VALUE is same as the real - * frequency of the crystal used. Otherwise, this function may - * have wrong result. - * - * - The result of this function could be not correct when using fractional - * value for HSE crystal. - * - * @param None - * @retval None - */ -void SystemCoreClockUpdate(void) { - uint32_t tmp, msirange, pllvco, pllr, pllsource, pllm; - - /* Get MSI Range frequency--------------------------------------------------*/ - - /*MSI frequency range in Hz*/ - msirange = MSIRangeTable[(RCC->CR & RCC_CR_MSIRANGE) >> RCC_CR_MSIRANGE_Pos]; - - /* Get SYSCLK source -------------------------------------------------------*/ - switch(RCC->CFGR & RCC_CFGR_SWS) { - case 0x00: /* MSI used as system clock source */ - SystemCoreClock = msirange; - break; - - case 0x04: /* HSI used as system clock source */ - /* HSI used as system clock source */ - SystemCoreClock = HSI_VALUE; - break; - - case 0x08: /* HSE used as system clock source */ - SystemCoreClock = HSE_VALUE; - break; - - case 0x0C: /* PLL used as system clock source */ - /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN - SYSCLK = PLL_VCO / PLLR - */ - pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC); - pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1UL; - - if(pllsource == 0x02UL) /* HSI used as PLL clock source */ - { - pllvco = (HSI_VALUE / pllm); - } else if(pllsource == 0x03UL) /* HSE used as PLL clock source */ - { - pllvco = (HSE_VALUE / pllm); - } else /* MSI used as PLL clock source */ - { - pllvco = (msirange / pllm); - } - - pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos); - pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> RCC_PLLCFGR_PLLR_Pos) + 1UL); - - SystemCoreClock = pllvco / pllr; - break; - - default: - SystemCoreClock = msirange; - break; - } - - /* Compute HCLK clock frequency --------------------------------------------*/ - /* Get HCLK1 prescaler */ - tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos)]; - /* HCLK clock frequency */ - SystemCoreClock = SystemCoreClock / tmp; -} - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/tim.c b/firmware/targets/f7/cube/Src/tim.c deleted file mode 100644 index 1182d420..00000000 --- a/firmware/targets/f7/cube/Src/tim.c +++ /dev/null @@ -1,347 +0,0 @@ -/** - ****************************************************************************** - * @file tim.c - * @brief This file provides code for the configuration - * of the TIM instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "tim.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -TIM_HandleTypeDef htim1; -TIM_HandleTypeDef htim2; -TIM_HandleTypeDef htim16; - -/* TIM1 init function */ -void MX_TIM1_Init(void) { - /* USER CODE BEGIN TIM1_Init 0 */ - - /* USER CODE END TIM1_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - TIM_OC_InitTypeDef sConfigOC = {0}; - TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; - - /* USER CODE BEGIN TIM1_Init 1 */ - - /* USER CODE END TIM1_Init 1 */ - htim1.Instance = TIM1; - htim1.Init.Prescaler = 0; - htim1.Init.CounterMode = TIM_COUNTERMODE_UP; - htim1.Init.Period = 65535; - htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim1.Init.RepetitionCounter = 0; - htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if(HAL_TIM_Base_Init(&htim1) != HAL_OK) { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if(HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) { - Error_Handler(); - } - if(HAL_TIM_OC_Init(&htim1) != HAL_OK) { - Error_Handler(); - } - if(HAL_TIM_PWM_Init(&htim1) != HAL_OK) { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if(HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK) { - Error_Handler(); - } - sConfigOC.OCMode = TIM_OCMODE_TIMING; - sConfigOC.Pulse = 0; - sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; - sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; - sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; - sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; - sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; - if(HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) { - Error_Handler(); - } - sConfigOC.OCMode = TIM_OCMODE_PWM1; - if(HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3) != HAL_OK) { - Error_Handler(); - } - sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; - sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; - sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; - sBreakDeadTimeConfig.DeadTime = 0; - sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; - sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; - sBreakDeadTimeConfig.BreakFilter = 0; - sBreakDeadTimeConfig.BreakAFMode = TIM_BREAK_AFMODE_INPUT; - sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE; - sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH; - sBreakDeadTimeConfig.Break2Filter = 0; - sBreakDeadTimeConfig.Break2AFMode = TIM_BREAK_AFMODE_INPUT; - sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; - if(HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN TIM1_Init 2 */ - - /* USER CODE END TIM1_Init 2 */ - HAL_TIM_MspPostInit(&htim1); -} -/* TIM2 init function */ -void MX_TIM2_Init(void) { - /* USER CODE BEGIN TIM2_Init 0 */ - - /* USER CODE END TIM2_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - TIM_IC_InitTypeDef sConfigIC = {0}; - - /* USER CODE BEGIN TIM2_Init 1 */ - - /* USER CODE END TIM2_Init 1 */ - htim2.Instance = TIM2; - htim2.Init.Prescaler = 64 - 1; - htim2.Init.CounterMode = TIM_COUNTERMODE_UP; - htim2.Init.Period = 4294967295; - htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; - if(HAL_TIM_Base_Init(&htim2) != HAL_OK) { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if(HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) { - Error_Handler(); - } - if(HAL_TIM_IC_Init(&htim2) != HAL_OK) { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if(HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) { - Error_Handler(); - } - sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING; - sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI; - sConfigIC.ICPrescaler = TIM_ICPSC_DIV1; - sConfigIC.ICFilter = 0; - if(HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_1) != HAL_OK) { - Error_Handler(); - } - sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING; - sConfigIC.ICSelection = TIM_ICSELECTION_INDIRECTTI; - if(HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_2) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN TIM2_Init 2 */ - - /* USER CODE END TIM2_Init 2 */ -} -/* TIM16 init function */ -void MX_TIM16_Init(void) { - /* USER CODE BEGIN TIM16_Init 0 */ - - /* USER CODE END TIM16_Init 0 */ - - TIM_OC_InitTypeDef sConfigOC = {0}; - TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; - - /* USER CODE BEGIN TIM16_Init 1 */ - - /* USER CODE END TIM16_Init 1 */ - htim16.Instance = TIM16; - htim16.Init.Prescaler = 500 - 1; - htim16.Init.CounterMode = TIM_COUNTERMODE_UP; - htim16.Init.Period = 291; - htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim16.Init.RepetitionCounter = 0; - htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if(HAL_TIM_Base_Init(&htim16) != HAL_OK) { - Error_Handler(); - } - if(HAL_TIM_PWM_Init(&htim16) != HAL_OK) { - Error_Handler(); - } - sConfigOC.OCMode = TIM_OCMODE_PWM1; - sConfigOC.Pulse = 145; - sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; - sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; - sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; - sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; - sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; - if(HAL_TIM_PWM_ConfigChannel(&htim16, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) { - Error_Handler(); - } - sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; - sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; - sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; - sBreakDeadTimeConfig.DeadTime = 0; - sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; - sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; - sBreakDeadTimeConfig.BreakFilter = 0; - sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; - if(HAL_TIMEx_ConfigBreakDeadTime(&htim16, &sBreakDeadTimeConfig) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN TIM16_Init 2 */ - - /* USER CODE END TIM16_Init 2 */ - HAL_TIM_MspPostInit(&htim16); -} - -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(tim_baseHandle->Instance == TIM1) { - /* USER CODE BEGIN TIM1_MspInit 0 */ - - /* USER CODE END TIM1_MspInit 0 */ - /* TIM1 clock enable */ - __HAL_RCC_TIM1_CLK_ENABLE(); - - /* TIM1 interrupt Init */ - HAL_NVIC_SetPriority(TIM1_TRG_COM_TIM17_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(TIM1_TRG_COM_TIM17_IRQn); - /* USER CODE BEGIN TIM1_MspInit 1 */ - - /* USER CODE END TIM1_MspInit 1 */ - } else if(tim_baseHandle->Instance == TIM2) { - /* USER CODE BEGIN TIM2_MspInit 0 */ - - /* USER CODE END TIM2_MspInit 0 */ - /* TIM2 clock enable */ - __HAL_RCC_TIM2_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**TIM2 GPIO Configuration - PA0 ------> TIM2_CH1 - */ - GPIO_InitStruct.Pin = IR_RX_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF1_TIM2; - HAL_GPIO_Init(IR_RX_GPIO_Port, &GPIO_InitStruct); - - /* TIM2 interrupt Init */ - HAL_NVIC_SetPriority(TIM2_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(TIM2_IRQn); - /* USER CODE BEGIN TIM2_MspInit 1 */ - - /* USER CODE END TIM2_MspInit 1 */ - } else if(tim_baseHandle->Instance == TIM16) { - /* USER CODE BEGIN TIM16_MspInit 0 */ - - /* USER CODE END TIM16_MspInit 0 */ - /* TIM16 clock enable */ - __HAL_RCC_TIM16_CLK_ENABLE(); - /* USER CODE BEGIN TIM16_MspInit 1 */ - - /* USER CODE END TIM16_MspInit 1 */ - } -} -void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(timHandle->Instance == TIM1) { - /* USER CODE BEGIN TIM1_MspPostInit 0 */ - - /* USER CODE END TIM1_MspPostInit 0 */ - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**TIM1 GPIO Configuration - PB9 ------> TIM1_CH3N - PB13 ------> TIM1_CH1N - */ - GPIO_InitStruct.Pin = IR_TX_Pin | RFID_OUT_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* USER CODE BEGIN TIM1_MspPostInit 1 */ - - /* USER CODE END TIM1_MspPostInit 1 */ - } else if(timHandle->Instance == TIM16) { - /* USER CODE BEGIN TIM16_MspPostInit 0 */ - - /* USER CODE END TIM16_MspPostInit 0 */ - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**TIM16 GPIO Configuration - PB8 ------> TIM16_CH1 - */ - GPIO_InitStruct.Pin = SPEAKER_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF14_TIM16; - HAL_GPIO_Init(SPEAKER_GPIO_Port, &GPIO_InitStruct); - - /* USER CODE BEGIN TIM16_MspPostInit 1 */ - - /* USER CODE END TIM16_MspPostInit 1 */ - } -} - -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) { - if(tim_baseHandle->Instance == TIM1) { - /* USER CODE BEGIN TIM1_MspDeInit 0 */ - - /* USER CODE END TIM1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM1_CLK_DISABLE(); - - /* TIM1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM1_TRG_COM_TIM17_IRQn); - /* USER CODE BEGIN TIM1_MspDeInit 1 */ - - /* USER CODE END TIM1_MspDeInit 1 */ - } else if(tim_baseHandle->Instance == TIM2) { - /* USER CODE BEGIN TIM2_MspDeInit 0 */ - - /* USER CODE END TIM2_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM2_CLK_DISABLE(); - - /**TIM2 GPIO Configuration - PA0 ------> TIM2_CH1 - */ - HAL_GPIO_DeInit(IR_RX_GPIO_Port, IR_RX_Pin); - - /* TIM2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM2_IRQn); - /* USER CODE BEGIN TIM2_MspDeInit 1 */ - - /* USER CODE END TIM2_MspDeInit 1 */ - } else if(tim_baseHandle->Instance == TIM16) { - /* USER CODE BEGIN TIM16_MspDeInit 0 */ - - /* USER CODE END TIM16_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM16_CLK_DISABLE(); - /* USER CODE BEGIN TIM16_MspDeInit 1 */ - - /* USER CODE END TIM16_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/usart.c b/firmware/targets/f7/cube/Src/usart.c deleted file mode 100644 index c0b3ecee..00000000 --- a/firmware/targets/f7/cube/Src/usart.c +++ /dev/null @@ -1,91 +0,0 @@ -/** - ****************************************************************************** - * @file usart.c - * @brief This file provides code for the configuration - * of the USART instances. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "usart.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* USART1 init function */ - -void MX_USART1_UART_Init(void) { - /* USER CODE BEGIN USART1_Init 0 */ - - /* USER CODE END USART1_Init 0 */ - - LL_USART_InitTypeDef USART_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* Peripheral clock enable */ - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - /**USART1 GPIO Configuration - PB6 ------> USART1_TX - PB7 ------> USART1_RX - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6 | LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* USER CODE BEGIN USART1_Init 1 */ - - /* USER CODE END USART1_Init 1 */ - USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1; - USART_InitStruct.BaudRate = 115200; - USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; - USART_InitStruct.StopBits = LL_USART_STOPBITS_1; - USART_InitStruct.Parity = LL_USART_PARITY_NONE; - USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX; - USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE; - USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16; - LL_USART_Init(USART1, &USART_InitStruct); - LL_USART_SetTXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); - LL_USART_SetRXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); - LL_USART_DisableFIFO(USART1); - LL_USART_EnableAutoBaudRate(USART1); - LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_STARTBIT); - LL_USART_ConfigAsyncMode(USART1); - - /* USER CODE BEGIN WKUPType USART1 */ - - /* USER CODE END WKUPType USART1 */ - - LL_USART_Enable(USART1); - - /* Polling USART1 initialisation */ - while(!(LL_USART_IsActiveFlag_TEACK(USART1))) { - } - /* USER CODE BEGIN USART1_Init 2 */ - - /* USER CODE END USART1_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/usb_device.c b/firmware/targets/f7/cube/Src/usb_device.c deleted file mode 100644 index d6d02cd6..00000000 --- a/firmware/targets/f7/cube/Src/usb_device.c +++ /dev/null @@ -1,98 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usb_device.c - * @version : v3.0_Cube - * @brief : This file implements the USB Device - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ - -#include "usb_device.h" -#include "usbd_core.h" -#include "usbd_desc.h" -#include "usbd_cdc.h" -#include "usbd_cdc_if.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE END PV */ - -/* USER CODE BEGIN PFP */ -/* Private function prototypes -----------------------------------------------*/ - -/* USER CODE END PFP */ - -extern void Error_Handler(void); -/* USB Device Core handle declaration. */ -USBD_HandleTypeDef hUsbDeviceFS; -extern USBD_DescriptorsTypeDef CDC_Desc; - -/* - * -- Insert your variables declaration here -- - */ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* - * -- Insert your external function declaration here -- - */ -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** - * Init USB device Library, add supported class and start the library - * @retval None - */ -void MX_USB_Device_Init(void) { - /* USER CODE BEGIN USB_Device_Init_PreTreatment */ - - /* USER CODE END USB_Device_Init_PreTreatment */ - - /* Init Device Library, add supported class and start the library. */ - if(USBD_Init(&hUsbDeviceFS, &CDC_Desc, DEVICE_FS) != USBD_OK) { - Error_Handler(); - } - if(USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) { - Error_Handler(); - } - if(USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) { - Error_Handler(); - } - if(USBD_Start(&hUsbDeviceFS) != USBD_OK) { - Error_Handler(); - } - /* USER CODE BEGIN USB_Device_Init_PostTreatment */ - - /* USER CODE END USB_Device_Init_PostTreatment */ -} - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/usbd_cdc_if.c b/firmware/targets/f7/cube/Src/usbd_cdc_if.c deleted file mode 100644 index e0d92f27..00000000 --- a/firmware/targets/f7/cube/Src/usbd_cdc_if.c +++ /dev/null @@ -1,318 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usbd_cdc_if.c - * @version : v3.0_Cube - * @brief : Usb device for Virtual Com Port. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_cdc_if.h" - -/* USER CODE BEGIN INCLUDE */ - -/* USER CODE END INCLUDE */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ - -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE END PV */ - -/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @brief Usb device library. - * @{ - */ - -/** @addtogroup USBD_CDC_IF - * @{ - */ - -/** @defgroup USBD_CDC_IF_Private_TypesDefinitions USBD_CDC_IF_Private_TypesDefinitions - * @brief Private types. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_TYPES */ - -/* USER CODE END PRIVATE_TYPES */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_IF_Private_Defines USBD_CDC_IF_Private_Defines - * @brief Private defines. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_DEFINES */ -/* USER CODE END PRIVATE_DEFINES */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_IF_Private_Macros USBD_CDC_IF_Private_Macros - * @brief Private macros. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_MACRO */ - -/* USER CODE END PRIVATE_MACRO */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_IF_Private_Variables USBD_CDC_IF_Private_Variables - * @brief Private variables. - * @{ - */ -/* Create buffer for reception and transmission */ -/* It's up to user to redefine and/or remove those define */ -/** Received data over USB are stored in this buffer */ -uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; - -/** Data to send over USB CDC are stored in this buffer */ -uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; - -/* USER CODE BEGIN PRIVATE_VARIABLES */ - -/* USER CODE END PRIVATE_VARIABLES */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables - * @brief Public variables. - * @{ - */ - -extern USBD_HandleTypeDef hUsbDeviceFS; - -/* USER CODE BEGIN EXPORTED_VARIABLES */ - -/* USER CODE END EXPORTED_VARIABLES */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_IF_Private_FunctionPrototypes USBD_CDC_IF_Private_FunctionPrototypes - * @brief Private functions declaration. - * @{ - */ - -static int8_t CDC_Init_FS(void); -static int8_t CDC_DeInit_FS(void); -static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length); -static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t* Len); -static int8_t CDC_TransmitCplt_FS(uint8_t* pbuf, uint32_t* Len, uint8_t epnum); - -/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ - -/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ - -/** - * @} - */ - -USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = - {CDC_Init_FS, CDC_DeInit_FS, CDC_Control_FS, CDC_Receive_FS, CDC_TransmitCplt_FS}; - -/* Private functions ---------------------------------------------------------*/ -/** - * @brief Initializes the CDC media low layer over the FS USB IP - * @retval USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_Init_FS(void) { - /* USER CODE BEGIN 3 */ - /* Set Application Buffers */ - USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); - USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); - return (USBD_OK); - /* USER CODE END 3 */ -} - -/** - * @brief DeInitializes the CDC media low layer - * @retval USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_DeInit_FS(void) { - /* USER CODE BEGIN 4 */ - return (USBD_OK); - /* USER CODE END 4 */ -} - -/** - * @brief Manage the CDC class requests - * @param cmd: Command code - * @param pbuf: Buffer containing command data (request parameters) - * @param length: Number of data to be sent (in bytes) - * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) { - /* USER CODE BEGIN 5 */ - switch(cmd) { - case CDC_SEND_ENCAPSULATED_COMMAND: - - break; - - case CDC_GET_ENCAPSULATED_RESPONSE: - - break; - - case CDC_SET_COMM_FEATURE: - - break; - - case CDC_GET_COMM_FEATURE: - - break; - - case CDC_CLEAR_COMM_FEATURE: - - break; - - /*******************************************************************************/ - /* Line Coding Structure */ - /*-----------------------------------------------------------------------------*/ - /* Offset | Field | Size | Value | Description */ - /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ - /* 4 | bCharFormat | 1 | Number | Stop bits */ - /* 0 - 1 Stop bit */ - /* 1 - 1.5 Stop bits */ - /* 2 - 2 Stop bits */ - /* 5 | bParityType | 1 | Number | Parity */ - /* 0 - None */ - /* 1 - Odd */ - /* 2 - Even */ - /* 3 - Mark */ - /* 4 - Space */ - /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ - /*******************************************************************************/ - case CDC_SET_LINE_CODING: - - break; - - case CDC_GET_LINE_CODING: - - break; - - case CDC_SET_CONTROL_LINE_STATE: - - break; - - case CDC_SEND_BREAK: - - break; - - default: - break; - } - - return (USBD_OK); - /* USER CODE END 5 */ -} - -/** - * @brief Data received over USB OUT endpoint are sent over CDC interface - * through this function. - * - * @note - * This function will issue a NAK packet on any OUT packet received on - * USB endpoint until exiting this function. If you exit this function - * before transfer is complete on CDC interface (ie. using DMA controller) - * it will result in receiving more data while previous ones are still - * not sent. - * - * @param Buf: Buffer of data to be received - * @param Len: Number of data received (in bytes) - * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t* Len) { - /* USER CODE BEGIN 6 */ - USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); - USBD_CDC_ReceivePacket(&hUsbDeviceFS); - return (USBD_OK); - /* USER CODE END 6 */ -} - -/** - * @brief CDC_Transmit_FS - * Data to send over USB IN endpoint are sent over CDC interface - * through this function. - * @note - * - * - * @param Buf: Buffer of data to be sent - * @param Len: Number of data to be sent (in bytes) - * @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY - */ -uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) { - uint8_t result = USBD_OK; - /* USER CODE BEGIN 7 */ - USBD_CDC_HandleTypeDef* hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData; - if(hcdc->TxState != 0) { - return USBD_BUSY; - } - USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); - result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); - /* USER CODE END 7 */ - return result; -} - -/** - * @brief CDC_TransmitCplt_FS - * Data transmitted callback - * - * @note - * This function is IN transfer complete callback used to inform user that - * the submitted Data is successfully sent over USB. - * - * @param Buf: Buffer of data to be received - * @param Len: Number of data received (in bytes) - * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_TransmitCplt_FS(uint8_t* Buf, uint32_t* Len, uint8_t epnum) { - uint8_t result = USBD_OK; - /* USER CODE BEGIN 13 */ - UNUSED(Buf); - UNUSED(Len); - UNUSED(epnum); - /* USER CODE END 13 */ - return result; -} - -/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ - -/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/usbd_conf.c b/firmware/targets/f7/cube/Src/usbd_conf.c deleted file mode 100644 index 667164eb..00000000 --- a/firmware/targets/f7/cube/Src/usbd_conf.c +++ /dev/null @@ -1,783 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usbd_conf.c - * @version : v3.0_Cube - * @brief : This file implements the board support package for the USB device library - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "stm32wbxx.h" -#include "stm32wbxx_hal.h" -#include "usbd_def.h" -#include "usbd_core.h" - -#include "usbd_cdc.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ - -/* Private variables ---------------------------------------------------------*/ -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -PCD_HandleTypeDef hpcd_USB_FS; -void Error_Handler(void); - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* Exported function prototypes ----------------------------------------------*/ - -/* USER CODE BEGIN PFP */ -/* Private function prototypes -----------------------------------------------*/ - -/* USER CODE END PFP */ - -/* Private functions ---------------------------------------------------------*/ -static USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status); -/* USER CODE BEGIN 1 */ -static void SystemClockConfig_Resume(void); - -/* USER CODE END 1 */ -extern void SystemClock_Config(void); - -/******************************************************************************* - LL Driver Callbacks (PCD -> USB Device Library) -*******************************************************************************/ -/* MSP Init */ - -#if(USE_HAL_PCD_REGISTER_CALLBACK == 1U) -static void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) -#else -void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) -#endif /* USE_HAL_PCD_REGISTER_CALLBACK */ -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(pcdHandle->Instance == USB) { - /* USER CODE BEGIN USB_MspInit 0 */ - - /* USER CODE END USB_MspInit 0 */ - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**USB GPIO Configuration - PA11 ------> USB_DM - PA12 ------> USB_DP - */ - GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF10_USB; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* Peripheral clock enable */ - __HAL_RCC_USB_CLK_ENABLE(); - - /* Peripheral interrupt init */ - HAL_NVIC_SetPriority(USB_LP_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(USB_LP_IRQn); - /* USER CODE BEGIN USB_MspInit 1 */ - - /* USER CODE END USB_MspInit 1 */ - } -} - -#if(USE_HAL_PCD_REGISTER_CALLBACK == 1U) -static void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) -#else -void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) -#endif /* USE_HAL_PCD_REGISTER_CALLBACK */ -{ - if(pcdHandle->Instance == USB) { - /* USER CODE BEGIN USB_MspDeInit 0 */ - - /* USER CODE END USB_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_USB_CLK_DISABLE(); - - /**USB GPIO Configuration - PA11 ------> USB_DM - PA12 ------> USB_DP - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11 | GPIO_PIN_12); - - /* Peripheral interrupt Deinit*/ - HAL_NVIC_DisableIRQ(USB_LP_IRQn); - - /* USER CODE BEGIN USB_MspDeInit 1 */ - - /* USER CODE END USB_MspDeInit 1 */ - } -} - -/** - * @brief Setup stage callback - * @param hpcd: PCD handle - * @retval None - */ -#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SetupStageCallback(PCD_HandleTypeDef* hpcd) -#else -void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef* hpcd) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - /* USER CODE BEGIN HAL_PCD_SetupStageCallback_PreTreatment */ - - /* USER CODE END HAL_PCD_SetupStageCallback_PreTreatment */ - USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t*)hpcd->Setup); - /* USER CODE BEGIN HAL_PCD_SetupStageCallback_PostTreatment */ - - /* USER CODE END HAL_PCD_SetupStageCallback_PostTreatment */ -} - -/** - * @brief Data Out stage callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ -#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DataOutStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) -#else -void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - /* USER CODE BEGIN HAL_PCD_DataOutStageCallback_PreTreatment */ - - /* USER CODE END HAL_PCD_DataOutStageCallback_PreTreatment */ - USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); - /* USER CODE BEGIN HAL_PCD_DataOutStageCallback_PostTreatment */ - - /* USER CODE END HAL_PCD_DataOutStageCallback_PostTreatment */ -} - -/** - * @brief Data In stage callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ -#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DataInStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) -#else -void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - /* USER CODE BEGIN HAL_PCD_DataInStageCallback_PreTreatment */ - - /* USER CODE END HAL_PCD_DataInStageCallback_PreTreatment */ - USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); - /* USER CODE BEGIN HAL_PCD_DataInStageCallback_PostTreatment */ - - /* USER CODE END HAL_PCD_DataInStageCallback_PostTreatment */ -} - -/** - * @brief SOF callback. - * @param hpcd: PCD handle - * @retval None - */ -#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SOFCallback(PCD_HandleTypeDef* hpcd) -#else -void HAL_PCD_SOFCallback(PCD_HandleTypeDef* hpcd) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - /* USER CODE BEGIN HAL_PCD_SOFCallback_PreTreatment */ - - /* USER CODE END HAL_PCD_SOFCallback_PreTreatment */ - USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); - /* USER CODE BEGIN HAL_PCD_SOFCallback_PostTreatment */ - - /* USER CODE END HAL_PCD_SOFCallback_PostTreatment */ -} - -/** - * @brief Reset callback. - * @param hpcd: PCD handle - * @retval None - */ -#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ResetCallback(PCD_HandleTypeDef* hpcd) -#else -void HAL_PCD_ResetCallback(PCD_HandleTypeDef* hpcd) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - /* USER CODE BEGIN HAL_PCD_ResetCallback_PreTreatment */ - - /* USER CODE END HAL_PCD_ResetCallback_PreTreatment */ - USBD_SpeedTypeDef speed = USBD_SPEED_FULL; - - if(hpcd->Init.speed != PCD_SPEED_FULL) { - Error_Handler(); - } - /* Set Speed. */ - USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); - - /* Reset Device. */ - USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); - /* USER CODE BEGIN HAL_PCD_ResetCallback_PostTreatment */ - - /* USER CODE END HAL_PCD_ResetCallback_PostTreatment */ -} - -/** - * @brief Suspend callback. - * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) - * @param hpcd: PCD handle - * @retval None - */ -#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SuspendCallback(PCD_HandleTypeDef* hpcd) -#else -void HAL_PCD_SuspendCallback(PCD_HandleTypeDef* hpcd) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - /* USER CODE BEGIN HAL_PCD_SuspendCallback_PreTreatment */ - - /* USER CODE END HAL_PCD_SuspendCallback_PreTreatment */ - /* Inform USB library that core enters in suspend Mode. */ - USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); - /* Enter in STOP mode. */ - /* USER CODE BEGIN 2 */ - if(hpcd->Init.low_power_enable) { - /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ - SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); - } - /* USER CODE END 2 */ - /* USER CODE BEGIN HAL_PCD_SuspendCallback_PostTreatment */ - - /* USER CODE END HAL_PCD_SuspendCallback_PostTreatment */ -} - -/** - * @brief Resume callback. - * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) - * @param hpcd: PCD handle - * @retval None - */ -#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ResumeCallback(PCD_HandleTypeDef* hpcd) -#else -void HAL_PCD_ResumeCallback(PCD_HandleTypeDef* hpcd) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - /* USER CODE BEGIN HAL_PCD_ResumeCallback_PreTreatment */ - - /* USER CODE END HAL_PCD_ResumeCallback_PreTreatment */ - - /* USER CODE BEGIN 3 */ - if(hpcd->Init.low_power_enable) { - /* Reset SLEEPDEEP bit of Cortex System Control Register. */ - SCB->SCR &= (uint32_t) ~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); - SystemClockConfig_Resume(); - } - /* USER CODE END 3 */ - - USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); - /* USER CODE BEGIN HAL_PCD_ResumeCallback_PostTreatment */ - - /* USER CODE END HAL_PCD_ResumeCallback_PostTreatment */ -} - -/** - * @brief ISOOUTIncomplete callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ -#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) -#else -void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - /* USER CODE BEGIN HAL_PCD_ISOOUTIncompleteCallback_PreTreatment */ - - /* USER CODE END HAL_PCD_ISOOUTIncompleteCallback_PreTreatment */ - USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); - /* USER CODE BEGIN HAL_PCD_ISOOUTIncompleteCallback_PostTreatment */ - - /* USER CODE END HAL_PCD_ISOOUTIncompleteCallback_PostTreatment */ -} - -/** - * @brief ISOINIncomplete callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ -#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) -#else -void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - /* USER CODE BEGIN HAL_PCD_ISOINIncompleteCallback_PreTreatment */ - - /* USER CODE END HAL_PCD_ISOINIncompleteCallback_PreTreatment */ - USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); - /* USER CODE BEGIN HAL_PCD_ISOINIncompleteCallback_PostTreatment */ - - /* USER CODE END HAL_PCD_ISOINIncompleteCallback_PostTreatment */ -} - -/** - * @brief Connect callback. - * @param hpcd: PCD handle - * @retval None - */ -#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ConnectCallback(PCD_HandleTypeDef* hpcd) -#else -void HAL_PCD_ConnectCallback(PCD_HandleTypeDef* hpcd) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - /* USER CODE BEGIN HAL_PCD_ConnectCallback_PreTreatment */ - - /* USER CODE END HAL_PCD_ConnectCallback_PreTreatment */ - USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); - /* USER CODE BEGIN HAL_PCD_ConnectCallback_PostTreatment */ - - /* USER CODE END HAL_PCD_ConnectCallback_PostTreatment */ -} - -/** - * @brief Disconnect callback. - * @param hpcd: PCD handle - * @retval None - */ -#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DisconnectCallback(PCD_HandleTypeDef* hpcd) -#else -void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef* hpcd) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PreTreatment */ - - /* USER CODE END HAL_PCD_DisconnectCallback_PreTreatment */ - USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); - /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PostTreatment */ - - /* USER CODE END HAL_PCD_DisconnectCallback_PostTreatment */ -} - -/* USER CODE BEGIN LowLevelInterface */ - -/* USER CODE END LowLevelInterface */ - -/******************************************************************************* - LL Driver Interface (USB Device Library --> PCD) -*******************************************************************************/ - -/** - * @brief Initializes the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef* pdev) { - /* Init USB Ip. */ - hpcd_USB_FS.pData = pdev; - /* Link the driver to the stack. */ - pdev->pData = &hpcd_USB_FS; - /* Enable USB power on Pwrctrl CR2 register. */ - HAL_PWREx_EnableVddUSB(); - - hpcd_USB_FS.Instance = USB; - hpcd_USB_FS.Init.dev_endpoints = 8; - hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; - hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED; - hpcd_USB_FS.Init.Sof_enable = DISABLE; - hpcd_USB_FS.Init.low_power_enable = DISABLE; - hpcd_USB_FS.Init.lpm_enable = DISABLE; - hpcd_USB_FS.Init.battery_charging_enable = DISABLE; - -#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) - /* register Msp Callbacks (before the Init) */ - HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_MSPINIT_CB_ID, PCD_MspInit); - HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_MSPDEINIT_CB_ID, PCD_MspDeInit); -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ - - if(HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK) { - Error_Handler(); - } - -#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) - /* Register USB PCD CallBacks */ - HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SOF_CB_ID, PCD_SOFCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_RESET_CB_ID, PCD_ResetCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_FS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback); - /* USER CODE BEGIN RegisterCallBackFirstPart */ - - /* USER CODE END RegisterCallBackFirstPart */ - HAL_PCD_RegisterLpmCallback(&hpcd_USB_FS, PCDEx_LPM_Callback); - HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_FS, PCD_DataOutStageCallback); - HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_FS, PCD_DataInStageCallback); - HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_FS, PCD_ISOOUTIncompleteCallback); - HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_FS, PCD_ISOINIncompleteCallback); - /* USER CODE BEGIN RegisterCallBackSecondPart */ - - /* USER CODE END RegisterCallBackSecondPart */ -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ - /* USER CODE BEGIN EndPoint_Configuration */ - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x00, PCD_SNG_BUF, 0x18); - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x80, PCD_SNG_BUF, 0x58); - /* USER CODE END EndPoint_Configuration */ - /* USER CODE BEGIN EndPoint_Configuration_CDC */ - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x81, PCD_SNG_BUF, 0xC0); - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x01, PCD_SNG_BUF, 0x110); - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x82, PCD_SNG_BUF, 0x100); - /* USER CODE END EndPoint_Configuration_CDC */ - return USBD_OK; -} - -/** - * @brief De-Initializes the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef* pdev) { - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_DeInit(pdev->pData); - - usb_status = USBD_Get_USB_Status(hal_status); - - return usb_status; -} - -/** - * @brief Starts the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef* pdev) { - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_Start(pdev->pData); - - usb_status = USBD_Get_USB_Status(hal_status); - - return usb_status; -} - -/** - * @brief Stops the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef* pdev) { - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_Stop(pdev->pData); - - usb_status = USBD_Get_USB_Status(hal_status); - - return usb_status; -} - -/** - * @brief Opens an endpoint of the low level driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @param ep_type: Endpoint type - * @param ep_mps: Endpoint max packet size - * @retval USBD status - */ -USBD_StatusTypeDef - USBD_LL_OpenEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) { - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); - - usb_status = USBD_Get_USB_Status(hal_status); - - return usb_status; -} - -/** - * @brief Closes an endpoint of the low level driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); - - usb_status = USBD_Get_USB_Status(hal_status); - - return usb_status; -} - -/** - * @brief Flushes an endpoint of the Low Level Driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); - - usb_status = USBD_Get_USB_Status(hal_status); - - return usb_status; -} - -/** - * @brief Sets a Stall condition on an endpoint of the Low Level Driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr); - - usb_status = USBD_Get_USB_Status(hal_status); - - return usb_status; -} - -/** - * @brief Clears a Stall condition on an endpoint of the Low Level Driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); - - usb_status = USBD_Get_USB_Status(hal_status); - - return usb_status; -} - -/** - * @brief Returns Stall condition. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval Stall (1: Yes, 0: No) - */ -uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { - PCD_HandleTypeDef* hpcd = (PCD_HandleTypeDef*)pdev->pData; - - if((ep_addr & 0x80) == 0x80) { - return hpcd->IN_ep[ep_addr & 0x7F].is_stall; - } else { - return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; - } -} - -/** - * @brief Assigns a USB address to the device. - * @param pdev: Device handle - * @param dev_addr: Device address - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef* pdev, uint8_t dev_addr) { - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); - - usb_status = USBD_Get_USB_Status(hal_status); - - return usb_status; -} - -/** - * @brief Transmits data over an endpoint. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @param pbuf: Pointer to data to be sent - * @param size: Data size - * @retval USBD status - */ -USBD_StatusTypeDef - USBD_LL_Transmit(USBD_HandleTypeDef* pdev, uint8_t ep_addr, uint8_t* pbuf, uint32_t size) { - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); - - usb_status = USBD_Get_USB_Status(hal_status); - - return usb_status; -} - -/** - * @brief Prepares an endpoint for reception. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @param pbuf: Pointer to data to be received - * @param size: Data size - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_PrepareReceive( - USBD_HandleTypeDef* pdev, - uint8_t ep_addr, - uint8_t* pbuf, - uint32_t size) { - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); - - usb_status = USBD_Get_USB_Status(hal_status); - - return usb_status; -} - -/** - * @brief Returns the last transferred packet size. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval Received Data Size - */ -uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { - return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*)pdev->pData, ep_addr); -} - -/** - * @brief Send LPM message to user layer - * @param hpcd: PCD handle - * @param msg: LPM message - * @retval None - */ -#if(USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCDEx_LPM_Callback(PCD_HandleTypeDef* hpcd, PCD_LPM_MsgTypeDef msg) -#else -void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef* hpcd, PCD_LPM_MsgTypeDef msg) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - /* USER CODE BEGIN LPM_Callback */ - switch(msg) { - case PCD_LPM_L0_ACTIVE: - if(hpcd->Init.low_power_enable) { - SystemClockConfig_Resume(); - - /* Reset SLEEPDEEP bit of Cortex System Control Register. */ - SCB->SCR &= (uint32_t) ~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); - } - USBD_LL_Resume(hpcd->pData); - break; - - case PCD_LPM_L1_ACTIVE: - USBD_LL_Suspend(hpcd->pData); - - /* Enter in STOP mode. */ - if(hpcd->Init.low_power_enable) { - /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ - SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); - } - break; - } - /* USER CODE END LPM_Callback */ -} - -/** - * @brief Delays routine for the USB Device Library. - * @param Delay: Delay in ms - * @retval None - */ -void USBD_LL_Delay(uint32_t Delay) { - HAL_Delay(Delay); -} - -/** - * @brief Static single allocation. - * @param size: Size of allocated memory - * @retval None - */ -void* USBD_static_malloc(uint32_t size) { - static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef) / 4) + 1]; /* On 32-bit boundary */ - return mem; -} - -/** - * @brief Dummy memory free - * @param p: Pointer to allocated memory address - * @retval None - */ -void USBD_static_free(void* p) { -} - -/* USER CODE BEGIN 5 */ -/** - * @brief Configures system clock after wake-up from USB resume callBack: - * enable HSI, PLL and select PLL as system clock source. - * @retval None - */ -static void SystemClockConfig_Resume(void) { - SystemClock_Config(); -} -/* USER CODE END 5 */ - -/** - * @brief Returns the USB status depending on the HAL status: - * @param hal_status: HAL status - * @retval USB status - */ -USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status) { - USBD_StatusTypeDef usb_status = USBD_OK; - - switch(hal_status) { - case HAL_OK: - usb_status = USBD_OK; - break; - case HAL_ERROR: - usb_status = USBD_FAIL; - break; - case HAL_BUSY: - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT: - usb_status = USBD_FAIL; - break; - default: - usb_status = USBD_FAIL; - break; - } - return usb_status; -} -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/Src/usbd_desc.c b/firmware/targets/f7/cube/Src/usbd_desc.c deleted file mode 100644 index 6e466cd3..00000000 --- a/firmware/targets/f7/cube/Src/usbd_desc.c +++ /dev/null @@ -1,368 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usbd_desc.c - * @version : v3.0_Cube - * @brief : This file implements the USB device descriptors. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_core.h" -#include "usbd_desc.h" -#include "usbd_conf.h" - -/* USER CODE BEGIN INCLUDE */ - -/* USER CODE END INCLUDE */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ - -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE END PV */ - -/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @{ - */ - -/** @addtogroup USBD_DESC - * @{ - */ - -/** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions - * @brief Private types. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_TYPES */ - -/* USER CODE END PRIVATE_TYPES */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines - * @brief Private defines. - * @{ - */ - -#define USBD_VID 1155 -#define USBD_LANGID_STRING 1033 -#define USBD_MANUFACTURER_STRING "Flipper" -#define USBD_PID 22336 -#define USBD_PRODUCT_STRING "Flipper Control Virtual ComPort" -#define USBD_CONFIGURATION_STRING "CDC Config" -#define USBD_INTERFACE_STRING "CDC Interface" - -/* USER CODE BEGIN PRIVATE_DEFINES */ - -/* USER CODE END PRIVATE_DEFINES */ - -/** - * @} - */ - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros - * @brief Private macros. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_MACRO */ - -/* USER CODE END PRIVATE_MACRO */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes - * @brief Private functions declaration. - * @{ - */ - -static void Get_SerialNum(void); -static void IntToUnicode(uint32_t value, uint8_t* pbuf, uint8_t len); - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes - * @brief Private functions declaration. - * @{ - */ - -uint8_t* USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); -uint8_t* USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); -uint8_t* USBD_CDC_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); -uint8_t* USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); -uint8_t* USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); -uint8_t* USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); -uint8_t* USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables - * @brief Private variables. - * @{ - */ - -USBD_DescriptorsTypeDef CDC_Desc = { - USBD_CDC_DeviceDescriptor, - USBD_CDC_LangIDStrDescriptor, - USBD_CDC_ManufacturerStrDescriptor, - USBD_CDC_ProductStrDescriptor, - USBD_CDC_SerialStrDescriptor, - USBD_CDC_ConfigStrDescriptor, - USBD_CDC_InterfaceStrDescriptor}; - -#if defined(__ICCARM__) /* IAR Compiler */ -#pragma data_alignment = 4 -#endif /* defined ( __ICCARM__ ) */ -/** USB standard device descriptor. */ -__ALIGN_BEGIN uint8_t USBD_CDC_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = { - 0x12, /*bLength */ - USB_DESC_TYPE_DEVICE, /*bDescriptorType*/ - 0x00, /*bcdUSB */ - 0x02, - 0x02, /*bDeviceClass*/ - 0x02, /*bDeviceSubClass*/ - 0x00, /*bDeviceProtocol*/ - USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ - LOBYTE(USBD_VID), /*idVendor*/ - HIBYTE(USBD_VID), /*idVendor*/ - LOBYTE(USBD_PID), /*idProduct*/ - HIBYTE(USBD_PID), /*idProduct*/ - 0x00, /*bcdDevice rel. 2.00*/ - 0x02, - USBD_IDX_MFC_STR, /*Index of manufacturer string*/ - USBD_IDX_PRODUCT_STR, /*Index of product string*/ - USBD_IDX_SERIAL_STR, /*Index of serial number string*/ - USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ -}; - -/* USB_DeviceDescriptor */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables - * @brief Private variables. - * @{ - */ - -#if defined(__ICCARM__) /* IAR Compiler */ -#pragma data_alignment = 4 -#endif /* defined ( __ICCARM__ ) */ - -/** USB lang identifier descriptor. */ -__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = { - USB_LEN_LANGID_STR_DESC, - USB_DESC_TYPE_STRING, - LOBYTE(USBD_LANGID_STRING), - HIBYTE(USBD_LANGID_STRING)}; - -#if defined(__ICCARM__) /* IAR Compiler */ -#pragma data_alignment = 4 -#endif /* defined ( __ICCARM__ ) */ -/* Internal string descriptor. */ -__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; - -#if defined(__ICCARM__) /*!< IAR Compiler */ -#pragma data_alignment = 4 -#endif -__ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = { - USB_SIZ_STRING_SERIAL, - USB_DESC_TYPE_STRING, -}; - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions - * @brief Private functions. - * @{ - */ - -/** - * @brief Return the device descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t* USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) { - UNUSED(speed); - *length = sizeof(USBD_CDC_DeviceDesc); - return USBD_CDC_DeviceDesc; -} - -/** - * @brief Return the LangID string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t* USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) { - UNUSED(speed); - *length = sizeof(USBD_LangIDDesc); - return USBD_LangIDDesc; -} - -/** - * @brief Return the product string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t* USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) { - if(speed == 0) { - USBD_GetString((uint8_t*)USBD_PRODUCT_STRING, USBD_StrDesc, length); - } else { - USBD_GetString((uint8_t*)USBD_PRODUCT_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** - * @brief Return the manufacturer string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t* USBD_CDC_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) { - UNUSED(speed); - USBD_GetString((uint8_t*)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); - return USBD_StrDesc; -} - -/** - * @brief Return the serial number string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t* USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) { - UNUSED(speed); - *length = USB_SIZ_STRING_SERIAL; - - /* Update the serial number string descriptor with the data from the unique - * ID */ - Get_SerialNum(); - - /* USER CODE BEGIN USBD_CDC_SerialStrDescriptor */ - - /* USER CODE END USBD_CDC_SerialStrDescriptor */ - - return (uint8_t*)USBD_StringSerial; -} - -/** - * @brief Return the configuration string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t* USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) { - if(speed == USBD_SPEED_HIGH) { - USBD_GetString((uint8_t*)USBD_CONFIGURATION_STRING, USBD_StrDesc, length); - } else { - USBD_GetString((uint8_t*)USBD_CONFIGURATION_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** - * @brief Return the interface string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t* USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) { - if(speed == 0) { - USBD_GetString((uint8_t*)USBD_INTERFACE_STRING, USBD_StrDesc, length); - } else { - USBD_GetString((uint8_t*)USBD_INTERFACE_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** - * @brief Create the serial number string descriptor - * @param None - * @retval None - */ -static void Get_SerialNum(void) { - uint32_t deviceserial0, deviceserial1, deviceserial2; - - deviceserial0 = *(uint32_t*)DEVICE_ID1; - deviceserial1 = *(uint32_t*)DEVICE_ID2; - deviceserial2 = *(uint32_t*)DEVICE_ID3; - - deviceserial0 += deviceserial2; - - if(deviceserial0 != 0) { - IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); - IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); - } -} - -/** - * @brief Convert Hex 32Bits value into char - * @param value: value to convert - * @param pbuf: pointer to the buffer - * @param len: buffer length - * @retval None - */ -static void IntToUnicode(uint32_t value, uint8_t* pbuf, uint8_t len) { - uint8_t idx = 0; - - for(idx = 0; idx < len; idx++) { - if(((value >> 28)) < 0xA) { - pbuf[2 * idx] = (value >> 28) + '0'; - } else { - pbuf[2 * idx] = (value >> 28) + 'A' - 10; - } - - value = value << 4; - - pbuf[2 * idx + 1] = 0; - } -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/f7.ioc b/firmware/targets/f7/cube/f7.ioc deleted file mode 100644 index e55ecca4..00000000 --- a/firmware/targets/f7/cube/f7.ioc +++ /dev/null @@ -1,598 +0,0 @@ -#MicroXplorer Configuration settings - do not modify -ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_14 -ADC1.ContinuousConvMode=DISABLE -ADC1.EnableAnalogWatchDog1=false -ADC1.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,OffsetNumber-0\#ChannelRegularConversion,NbrOfConversionFlag,master,EnableAnalogWatchDog1,ContinuousConvMode -ADC1.NbrOfConversionFlag=1 -ADC1.OffsetNumber-0\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.Rank-0\#ChannelRegularConversion=1 -ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_2CYCLES_5 -ADC1.master=1 -COMP1.Hysteresis=COMP_HYSTERESIS_HIGH -COMP1.IPParameters=TriggerMode,Hysteresis,Mode -COMP1.Mode=COMP_POWERMODE_MEDIUMSPEED -COMP1.TriggerMode=COMP_TRIGGERMODE_IT_RISING_FALLING -FREERTOS.FootprintOK=true -FREERTOS.HEAP_NUMBER=4 -FREERTOS.INCLUDE_vTaskCleanUpResources=1 -FREERTOS.IPParameters=Tasks01,configTOTAL_HEAP_SIZE,HEAP_NUMBER,configUSE_TIMERS,configUSE_IDLE_HOOK,FootprintOK,configCHECK_FOR_STACK_OVERFLOW,configRECORD_STACK_HIGH_ADDRESS,configGENERATE_RUN_TIME_STATS,configENABLE_FPU,configUSE_TICKLESS_IDLE,configENABLE_BACKWARD_COMPATIBILITY,INCLUDE_vTaskCleanUpResources,configTICK_RATE_HZ -FREERTOS.Tasks01=app_main,24,1024,app,As weak,NULL,Dynamic,NULL,NULL -FREERTOS.configCHECK_FOR_STACK_OVERFLOW=1 -FREERTOS.configENABLE_BACKWARD_COMPATIBILITY=0 -FREERTOS.configENABLE_FPU=1 -FREERTOS.configGENERATE_RUN_TIME_STATS=1 -FREERTOS.configRECORD_STACK_HIGH_ADDRESS=1 -FREERTOS.configTICK_RATE_HZ=1000 -FREERTOS.configTOTAL_HEAP_SIZE=40960 -FREERTOS.configUSE_IDLE_HOOK=1 -FREERTOS.configUSE_TICKLESS_IDLE=2 -FREERTOS.configUSE_TIMERS=1 -File.Version=6 -GPIO.groupedBy=Show All -I2C1.CustomTiming=Disabled -I2C1.I2C_Fall_Time=0 -I2C1.I2C_Rise_Time=0 -I2C1.IPParameters=Timing,CustomTiming,I2C_Rise_Time,I2C_Fall_Time -I2C1.Timing=0x10707DBC -KeepUserPlacement=false -Mcu.Family=STM32WB -Mcu.IP0=ADC1 -Mcu.IP1=AES1 -Mcu.IP10=RCC -Mcu.IP11=RF -Mcu.IP12=RNG -Mcu.IP13=RTC -Mcu.IP14=SPI1 -Mcu.IP15=SPI2 -Mcu.IP16=SYS -Mcu.IP17=TIM1 -Mcu.IP18=TIM2 -Mcu.IP19=TIM16 -Mcu.IP2=AES2 -Mcu.IP20=USART1 -Mcu.IP21=USB -Mcu.IP22=USB_DEVICE -Mcu.IP3=COMP1 -Mcu.IP4=CRC -Mcu.IP5=FREERTOS -Mcu.IP6=HSEM -Mcu.IP7=I2C1 -Mcu.IP8=NVIC -Mcu.IP9=PKA -Mcu.IPNb=23 -Mcu.Name=STM32WB55RGVx -Mcu.Package=VFQFPN68 -Mcu.Pin0=PC13 -Mcu.Pin1=PC14-OSC32_IN -Mcu.Pin10=PA0 -Mcu.Pin11=PA1 -Mcu.Pin12=PA2 -Mcu.Pin13=PA3 -Mcu.Pin14=PA4 -Mcu.Pin15=PA5 -Mcu.Pin16=PA6 -Mcu.Pin17=PA7 -Mcu.Pin18=PA8 -Mcu.Pin19=PA9 -Mcu.Pin2=PC15-OSC32_OUT -Mcu.Pin20=PC4 -Mcu.Pin21=PC5 -Mcu.Pin22=PB2 -Mcu.Pin23=PB10 -Mcu.Pin24=PB11 -Mcu.Pin25=RF1 -Mcu.Pin26=OSC_OUT -Mcu.Pin27=OSC_IN -Mcu.Pin28=PB0 -Mcu.Pin29=PB1 -Mcu.Pin3=PH3-BOOT0 -Mcu.Pin30=PE4 -Mcu.Pin31=PB12 -Mcu.Pin32=PB13 -Mcu.Pin33=PB14 -Mcu.Pin34=PB15 -Mcu.Pin35=PC6 -Mcu.Pin36=PA10 -Mcu.Pin37=PA11 -Mcu.Pin38=PA12 -Mcu.Pin39=PA13 -Mcu.Pin4=PB8 -Mcu.Pin40=PA14 -Mcu.Pin41=PA15 -Mcu.Pin42=PC10 -Mcu.Pin43=PC11 -Mcu.Pin44=PC12 -Mcu.Pin45=PD0 -Mcu.Pin46=PD1 -Mcu.Pin47=PB3 -Mcu.Pin48=PB4 -Mcu.Pin49=PB5 -Mcu.Pin5=PB9 -Mcu.Pin50=PB6 -Mcu.Pin51=PB7 -Mcu.Pin52=VP_ADC1_TempSens_Input -Mcu.Pin53=VP_ADC1_Vref_Input -Mcu.Pin54=VP_AES1_VS_AES -Mcu.Pin55=VP_AES2_VS_AES -Mcu.Pin56=VP_COMP1_VS_VREFINT14 -Mcu.Pin57=VP_CRC_VS_CRC -Mcu.Pin58=VP_FREERTOS_VS_CMSIS_V2 -Mcu.Pin59=VP_HSEM_VS_HSEM -Mcu.Pin6=PC0 -Mcu.Pin60=VP_PKA_VS_PKA -Mcu.Pin61=VP_RNG_VS_RNG -Mcu.Pin62=VP_RTC_VS_RTC_Activate -Mcu.Pin63=VP_RTC_VS_RTC_Calendar -Mcu.Pin64=VP_SYS_VS_Systick -Mcu.Pin65=VP_TIM1_VS_ClockSourceINT -Mcu.Pin66=VP_TIM2_VS_ClockSourceINT -Mcu.Pin67=VP_TIM16_VS_ClockSourceINT -Mcu.Pin68=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS -Mcu.Pin7=PC1 -Mcu.Pin8=PC2 -Mcu.Pin9=PC3 -Mcu.PinsNb=69 -Mcu.ThirdPartyNb=0 -Mcu.UserConstants= -Mcu.UserName=STM32WB55RGVx -MxCube.Version=6.3.0 -MxDb.Version=DB.6.0.30 -NVIC.ADC1_IRQn=true\:5\:0\:true\:false\:true\:false\:true\:true -NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.COMP_IRQn=true\:5\:0\:true\:false\:true\:false\:false\:true -NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.EXTI15_10_IRQn=true\:5\:0\:true\:false\:true\:false\:true\:true -NVIC.EXTI3_IRQn=true\:5\:0\:true\:false\:true\:false\:true\:true -NVIC.ForceEnableDMAVector=true -NVIC.HSEM_IRQn=true\:5\:0\:true\:false\:true\:false\:false\:true -NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true -NVIC.PendSV_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:false -NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 -NVIC.RCC_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:false -NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false -NVIC.SavedPendsvIrqHandlerGenerated=false -NVIC.SavedSvcallIrqHandlerGenerated=false -NVIC.SavedSystickIrqHandlerGenerated=true -NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:true\:false\:false -NVIC.TAMP_STAMP_LSECSS_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true -NVIC.TIM1_TRG_COM_TIM17_IRQn=true\:5\:0\:false\:false\:true\:false\:false\:true -NVIC.TIM2_IRQn=true\:5\:0\:true\:false\:true\:false\:true\:true -NVIC.USB_LP_IRQn=true\:5\:0\:true\:false\:true\:false\:false\:true -NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -OSC_IN.GPIOParameters=GPIO_Label -OSC_IN.GPIO_Label=QUARTZ_32KHZ_IN -OSC_IN.Locked=true -OSC_IN.Mode=HSE-External-Oscillator -OSC_IN.Signal=RCC_OSC_IN -OSC_OUT.GPIOParameters=GPIO_Label -OSC_OUT.GPIO_Label=QUARTZ_32KHZ_OUT -OSC_OUT.Locked=true -OSC_OUT.Mode=HSE-External-Oscillator -OSC_OUT.Signal=RCC_OSC_OUT -PA0.GPIOParameters=GPIO_Label -PA0.GPIO_Label=IR_RX -PA0.Signal=S_TIM2_CH1 -PA1.GPIOParameters=GPIO_Label -PA1.GPIO_Label=CC1101_G0 -PA1.Locked=true -PA1.Signal=GPIO_Analog -PA10.GPIOParameters=GPIO_Speed,GPIO_Label,GPIO_Pu -PA10.GPIO_Label=I2C_SDA -PA10.GPIO_Pu=GPIO_PULLUP -PA10.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PA10.Locked=true -PA10.Mode=I2C -PA10.Signal=I2C1_SDA -PA11.GPIOParameters=GPIO_Speed -PA11.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PA11.Locked=true -PA11.Mode=Device -PA11.Signal=USB_DM -PA12.GPIOParameters=GPIO_Speed -PA12.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PA12.Locked=true -PA12.Mode=Device -PA12.Signal=USB_DP -PA13.Locked=true -PA13.Mode=Serial_Wire -PA13.Signal=SYS_JTMS-SWDIO -PA14.Locked=true -PA14.Mode=Serial_Wire -PA14.Signal=SYS_JTCK-SWCLK -PA15.GPIOParameters=GPIO_Label -PA15.GPIO_Label=RFID_CARRIER -PA15.Locked=true -PA15.Signal=GPIO_Analog -PA2.GPIOParameters=GPIO_Label -PA2.GPIO_Label=RFID_PULL -PA2.Locked=true -PA2.Signal=GPIO_Output -PA3.GPIOParameters=GPIO_Speed,PinState,GPIO_Label,GPIO_ModeDefaultOutputPP -PA3.GPIO_Label=PERIPH_POWER -PA3.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD -PA3.GPIO_Speed=GPIO_SPEED_FREQ_LOW -PA3.Locked=true -PA3.PinState=GPIO_PIN_SET -PA3.Signal=GPIO_Output -PA4.GPIOParameters=GPIO_Label -PA4.GPIO_Label=PA4 -PA4.Signal=GPIO_Analog -PA5.GPIOParameters=GPIO_Label -PA5.GPIO_Label=SPI_R_SCK -PA5.Locked=true -PA5.Mode=Full_Duplex_Master -PA5.Signal=SPI1_SCK -PA6.GPIOParameters=GPIO_Label -PA6.GPIO_Label=PA6 -PA6.Signal=GPIO_Analog -PA7.GPIOParameters=GPIO_Label -PA7.GPIO_Label=PA7 -PA7.Signal=GPIO_Analog -PA8.GPIOParameters=GPIO_Label -PA8.GPIO_Label=VIBRO -PA8.Locked=true -PA8.Signal=GPIO_Output -PA9.GPIOParameters=GPIO_Speed,GPIO_Label,GPIO_Pu -PA9.GPIO_Label=I2C_SCL -PA9.GPIO_Pu=GPIO_PULLUP -PA9.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PA9.Locked=true -PA9.Mode=I2C -PA9.Signal=I2C1_SCL -PB0.GPIOParameters=GPIO_Label -PB0.GPIO_Label=DISPLAY_RST -PB0.Locked=true -PB0.Signal=GPIO_Output -PB1.GPIOParameters=GPIO_Label -PB1.GPIO_Label=DISPLAY_DI -PB1.Locked=true -PB1.Signal=GPIO_Output -PB10.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI -PB10.GPIO_Label=BUTTON_UP -PB10.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING_FALLING -PB10.GPIO_PuPd=GPIO_PULLUP -PB10.Locked=true -PB10.Signal=GPXTI10 -PB11.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI -PB11.GPIO_Label=BUTTON_LEFT -PB11.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING_FALLING -PB11.GPIO_PuPd=GPIO_PULLUP -PB11.Locked=true -PB11.Signal=GPXTI11 -PB12.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI -PB12.GPIO_Label=BUTTON_RIGHT -PB12.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING_FALLING -PB12.GPIO_PuPd=GPIO_PULLUP -PB12.Locked=true -PB12.Signal=GPXTI12 -PB13.GPIOParameters=GPIO_Label -PB13.GPIO_Label=RFID_OUT -PB13.Locked=true -PB13.Mode=Output Compare1 CH1N -PB13.Signal=TIM1_CH1N -PB14.GPIOParameters=GPIO_Label -PB14.GPIO_Label=iBTN -PB14.Signal=GPIO_Analog -PB15.GPIOParameters=GPIO_Label -PB15.GPIO_Label=SPI_D_MOSI -PB15.Locked=true -PB15.Mode=Full_Duplex_Master -PB15.Signal=SPI2_MOSI -PB2.GPIOParameters=GPIO_Label -PB2.GPIO_Label=PB2 -PB2.Signal=GPIO_Analog -PB3.GPIOParameters=GPIO_Label -PB3.GPIO_Label=PB3 -PB3.Locked=true -PB3.Signal=GPIO_Analog -PB4.GPIOParameters=GPIO_Label -PB4.GPIO_Label=SPI_R_MISO -PB4.Locked=true -PB4.Mode=Full_Duplex_Master -PB4.Signal=SPI1_MISO -PB5.GPIOParameters=GPIO_Label -PB5.GPIO_Label=SPI_R_MOSI -PB5.Locked=true -PB5.Mode=Full_Duplex_Master -PB5.Signal=SPI1_MOSI -PB6.Locked=true -PB6.Mode=Asynchronous -PB6.Signal=USART1_TX -PB7.Locked=true -PB7.Mode=Asynchronous -PB7.Signal=USART1_RX -PB8.GPIOParameters=GPIO_Label -PB8.GPIO_Label=SPEAKER -PB8.Locked=true -PB8.Signal=S_TIM16_CH1 -PB9.GPIOParameters=GPIO_Label -PB9.GPIO_Label=IR_TX -PB9.Locked=true -PB9.Mode=PWM Generation3 CH3N -PB9.Signal=TIM1_CH3N -PC0.GPIOParameters=GPIO_Label -PC0.GPIO_Label=PC0 -PC0.Locked=true -PC0.Signal=GPIO_Analog -PC1.GPIOParameters=GPIO_Label -PC1.GPIO_Label=PC1 -PC1.Locked=true -PC1.Signal=GPIO_Analog -PC10.GPIOParameters=GPIO_Label -PC10.GPIO_Label=SD_CD -PC10.Locked=true -PC10.Signal=GPIO_Input -PC11.GPIOParameters=PinState,GPIO_Label -PC11.GPIO_Label=DISPLAY_CS -PC11.Locked=true -PC11.PinState=GPIO_PIN_SET -PC11.Signal=GPIO_Output -PC12.GPIOParameters=GPIO_Speed,PinState,GPIO_Label -PC12.GPIO_Label=SD_CS -PC12.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PC12.Locked=true -PC12.PinState=GPIO_PIN_SET -PC12.Signal=GPIO_Output -PC13.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI -PC13.GPIO_Label=BUTTON_BACK -PC13.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING_FALLING -PC13.GPIO_PuPd=GPIO_PULLUP -PC13.Locked=true -PC13.Signal=GPXTI13 -PC14-OSC32_IN.GPIOParameters=GPIO_Label -PC14-OSC32_IN.GPIO_Label=QUARTZ_32MHZ_IN -PC14-OSC32_IN.Locked=true -PC14-OSC32_IN.Mode=LSE-External-Oscillator -PC14-OSC32_IN.Signal=RCC_OSC32_IN -PC15-OSC32_OUT.GPIOParameters=GPIO_Label -PC15-OSC32_OUT.GPIO_Label=QUARTZ_32MHZ_OUT -PC15-OSC32_OUT.Locked=true -PC15-OSC32_OUT.Mode=LSE-External-Oscillator -PC15-OSC32_OUT.Signal=RCC_OSC32_OUT -PC2.GPIOParameters=GPIO_Label -PC2.GPIO_Label=SPI_D_MISO -PC2.Locked=true -PC2.Mode=Full_Duplex_Master -PC2.Signal=SPI2_MISO -PC3.GPIOParameters=GPIO_Label -PC3.GPIO_Label=PC3 -PC3.Signal=GPIO_Analog -PC4.GPIOParameters=GPIO_Label -PC4.GPIO_Label=RF_SW_0 -PC4.Locked=true -PC4.Signal=GPIO_Output -PC5.GPIOParameters=GPIO_Label -PC5.GPIO_Label=RFID_RF_IN -PC5.Locked=true -PC5.Signal=SharedAnalog_PC5 -PC6.GPIOParameters=GPIO_Label -PC6.GPIO_Label=BUTTON_DOWN -PC6.Locked=true -PC6.Signal=GPIO_Input -PCC.Ble.ConnectionInterval=1000.0 -PCC.Ble.DataLength=6 -PCC.Ble.IsUsed=false -PCC.Ble.Mode=NOT_SELECTED -PCC.Ble.PowerLevel=Min -PCC.Zigbee.IsUsed=false -PCC.Zigbee.Mode=Sleepy End Device -PCC.Zigbee.Payload=15 -PCC.Zigbee.PoolPeriodicity=480.0 -PCC.Zigbee.PowerLevel=Min -PCC.Zigbee.RequestPeriodicity=1500.0 -PD0.GPIOParameters=GPIO_Speed,PinState,GPIO_Label -PD0.GPIO_Label=CC1101_CS -PD0.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PD0.Locked=true -PD0.PinState=GPIO_PIN_SET -PD0.Signal=GPIO_Output -PD1.GPIOParameters=GPIO_Label -PD1.GPIO_Label=SPI_D_SCK -PD1.Locked=true -PD1.Mode=Full_Duplex_Master -PD1.Signal=SPI2_SCK -PE4.GPIOParameters=GPIO_Speed,PinState,GPIO_Label -PE4.GPIO_Label=NFC_CS -PE4.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PE4.Locked=true -PE4.PinState=GPIO_PIN_SET -PE4.Signal=GPIO_Output -PH3-BOOT0.GPIOParameters=GPIO_Label,GPIO_ModeDefaultEXTI -PH3-BOOT0.GPIO_Label=BUTTON_OK -PH3-BOOT0.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING_FALLING -PH3-BOOT0.Locked=true -PH3-BOOT0.Signal=GPXTI3 -PinOutPanel.RotationAngle=0 -ProjectManager.AskForMigrate=true -ProjectManager.BackupPrevious=false -ProjectManager.CompilerOptimize=6 -ProjectManager.ComputerToolchain=false -ProjectManager.CoupleFile=true -ProjectManager.CustomerFirmwarePackage=../../../../lib/STM32CubeWB -ProjectManager.DefaultFWLocation=false -ProjectManager.DeletePrevious=true -ProjectManager.DeviceId=STM32WB55RGVx -ProjectManager.FirmwarePackage=STM32Cube FW_WB V1.12.1 -ProjectManager.FreePins=false -ProjectManager.HalAssertFull=false -ProjectManager.HeapSize=0x400 -ProjectManager.KeepUserCode=true -ProjectManager.LastFirmware=true -ProjectManager.LibraryCopy=2 -ProjectManager.MainLocation=Src -ProjectManager.NoMain=false -ProjectManager.PreviousToolchain= -ProjectManager.ProjectBuild=false -ProjectManager.ProjectFileName=f7.ioc -ProjectManager.ProjectName=f7 -ProjectManager.RegisterCallBack= -ProjectManager.StackSize=0x1000 -ProjectManager.TargetToolchain=Makefile -ProjectManager.ToolChainLocation= -ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-LL-false,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_I2C1_Init-I2C1-false-LL-true,5-MX_RTC_Init-RTC-false-HAL-true,6-MX_SPI1_Init-SPI1-false-HAL-true,7-MX_SPI2_Init-SPI2-false-HAL-true,8-MX_USB_Device_Init-USB_DEVICE-false-HAL-false,9-MX_TIM1_Init-TIM1-false-HAL-true,10-MX_TIM2_Init-TIM2-false-HAL-true,11-MX_TIM16_Init-TIM16-false-HAL-true,12-MX_COMP1_Init-COMP1-false-HAL-true,13-MX_RF_Init-RF-false-HAL-true,14-MX_PKA_Init-PKA-false-HAL-true,15-MX_RNG_Init-RNG-false-HAL-true,16-MX_AES1_Init-AES1-false-HAL-true,17-MX_AES2_Init-AES2-false-HAL-true,18-MX_CRC_Init-CRC-false-HAL-true,19-MX_USART1_UART_Init-USART1-false-LL-true,0-MX_HSEM_Init-HSEM-false-HAL-true -RCC.ADCFreq_Value=48000000 -RCC.AHB2CLKDivider=RCC_SYSCLK_DIV2 -RCC.AHBFreq_Value=64000000 -RCC.APB1Freq_Value=64000000 -RCC.APB1TimFreq_Value=64000000 -RCC.APB2Freq_Value=64000000 -RCC.APB2TimFreq_Value=64000000 -RCC.APB3Freq_Value=16000000 -RCC.Cortex2Freq_Value=32000000 -RCC.CortexFreq_Value=64000000 -RCC.EnableCSSLSE=true -RCC.EnbaleCSS=true -RCC.FCLK2Freq_Value=32000000 -RCC.FCLKCortexFreq_Value=64000000 -RCC.FamilyName=M -RCC.HCLK2Freq_Value=32000000 -RCC.HCLK3Freq_Value=64000000 -RCC.HCLKFreq_Value=64000000 -RCC.HCLKRFFreq_Value=16000000 -RCC.HSE_VALUE=32000000 -RCC.HSI48_VALUE=48000000 -RCC.HSI_VALUE=16000000 -RCC.I2C1Freq_Value=64000000 -RCC.I2C3Freq_Value=64000000 -RCC.IPParameters=ADCFreq_Value,AHB2CLKDivider,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,APB3Freq_Value,Cortex2Freq_Value,CortexFreq_Value,EnableCSSLSE,EnbaleCSS,FCLK2Freq_Value,FCLKCortexFreq_Value,FamilyName,HCLK2Freq_Value,HCLK3Freq_Value,HCLKFreq_Value,HCLKRFFreq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C3Freq_Value,LCDFreq_Value,LPTIM1CLockSelection,LPTIM1Freq_Value,LPTIM2Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_Drive_Capability,LSE_Timout,LSI_VALUE,MCO1PinFreq_Value,MSIOscState,PLLM,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PLLSAI1N,PLLSAI1PoutputFreq_Value,PLLSAI1QoutputFreq_Value,PLLSAI1RoutputFreq_Value,PLLSourceVirtual,PREFETCH_ENABLE,PWRFreq_Value,RFWKPClockSelection,RFWKPFreq_Value,RNGCLockSelection,RNGFreq_Value,RTCClockSelection,RTCFreq_Value,SAI1Freq_Value,SMPS1Freq_Value,SMPSCLockSelectionVirtual,SMPSDivider,SMPSFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,USART1Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VCOSAI1OutputFreq_Value -RCC.LCDFreq_Value=32768 -RCC.LPTIM1CLockSelection=RCC_LPTIM1CLKSOURCE_LSE -RCC.LPTIM1Freq_Value=32768 -RCC.LPTIM2Freq_Value=64000000 -RCC.LPUART1Freq_Value=64000000 -RCC.LSCOPinFreq_Value=32000 -RCC.LSE_Drive_Capability=RCC_LSEDRIVE_MEDIUMLOW -RCC.LSE_Timout=1000 -RCC.LSI_VALUE=32000 -RCC.MCO1PinFreq_Value=64000000 -RCC.MSIOscState=DISABLED -RCC.PLLM=RCC_PLLM_DIV2 -RCC.PLLPoutputFreq_Value=64000000 -RCC.PLLQoutputFreq_Value=64000000 -RCC.PLLRCLKFreq_Value=64000000 -RCC.PLLSAI1N=6 -RCC.PLLSAI1PoutputFreq_Value=48000000 -RCC.PLLSAI1QoutputFreq_Value=48000000 -RCC.PLLSAI1RoutputFreq_Value=48000000 -RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE -RCC.PREFETCH_ENABLE=1 -RCC.PWRFreq_Value=64000000 -RCC.RFWKPClockSelection=RCC_RFWKPCLKSOURCE_LSE -RCC.RFWKPFreq_Value=32768 -RCC.RNGCLockSelection=RCC_RNGCLKSOURCE_CLK48 -RCC.RNGFreq_Value=16000000 -RCC.RTCClockSelection=RCC_RTCCLKSOURCE_LSE -RCC.RTCFreq_Value=32768 -RCC.SAI1Freq_Value=48000000 -RCC.SMPS1Freq_Value=8000000 -RCC.SMPSCLockSelectionVirtual=RCC_SMPSCLKSOURCE_HSE -RCC.SMPSDivider=4 -RCC.SMPSFreq_Value=4000000 -RCC.SYSCLKFreq_VALUE=64000000 -RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK -RCC.USART1Freq_Value=64000000 -RCC.USBFreq_Value=48000000 -RCC.VCOInputFreq_Value=16000000 -RCC.VCOOutputFreq_Value=128000000 -RCC.VCOSAI1OutputFreq_Value=96000000 -RF1.Locked=true -RF1.Mode=RF1_Activate -RF1.Signal=RF_RF1 -SH.GPXTI10.0=GPIO_EXTI10 -SH.GPXTI10.ConfNb=1 -SH.GPXTI11.0=GPIO_EXTI11 -SH.GPXTI11.ConfNb=1 -SH.GPXTI12.0=GPIO_EXTI12 -SH.GPXTI12.ConfNb=1 -SH.GPXTI13.0=GPIO_EXTI13 -SH.GPXTI13.ConfNb=1 -SH.GPXTI3.0=GPIO_EXTI3 -SH.GPXTI3.ConfNb=1 -SH.S_TIM16_CH1.0=TIM16_CH1,PWM Generation1 CH1 -SH.S_TIM16_CH1.ConfNb=1 -SH.S_TIM2_CH1.0=TIM2_CH1,Input_Capture1_from_TI1 -SH.S_TIM2_CH1.1=TIM2_CH1,Input_Capture2_from_TI1 -SH.S_TIM2_CH1.ConfNb=2 -SH.SharedAnalog_PC5.0=COMP1_INP,INP -SH.SharedAnalog_PC5.1=ADC1_IN14,IN14-Single-Ended -SH.SharedAnalog_PC5.ConfNb=2 -SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_16 -SPI1.CLKPhase=SPI_PHASE_2EDGE -SPI1.CalculateBaudRate=4.0 MBits/s -SPI1.DataSize=SPI_DATASIZE_8BIT -SPI1.Direction=SPI_DIRECTION_2LINES -SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,CLKPhase,BaudRatePrescaler -SPI1.Mode=SPI_MODE_MASTER -SPI1.VirtualType=VM_MASTER -SPI2.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_16 -SPI2.CLKPhase=SPI_PHASE_1EDGE -SPI2.CalculateBaudRate=4.0 MBits/s -SPI2.DataSize=SPI_DATASIZE_8BIT -SPI2.Direction=SPI_DIRECTION_2LINES -SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,BaudRatePrescaler,CLKPhase -SPI2.Mode=SPI_MODE_MASTER -SPI2.VirtualType=VM_MASTER -TIM1.Channel-Output\ Compare1\ CH1N=TIM_CHANNEL_1 -TIM1.Channel-PWM\ Generation3\ CH3N=TIM_CHANNEL_3 -TIM1.IPParameters=Channel-Output Compare1 CH1N,Channel-PWM Generation3 CH3N -TIM16.Channel=TIM_CHANNEL_1 -TIM16.IPParameters=Channel,Pulse,Prescaler,Period -TIM16.Period=291 -TIM16.Prescaler=500 - 1 -TIM16.Pulse=145 -TIM2.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE -TIM2.Channel-Input_Capture1_from_TI1=TIM_CHANNEL_1 -TIM2.Channel-Input_Capture2_from_TI1=TIM_CHANNEL_2 -TIM2.ICPolarity_CH1=TIM_INPUTCHANNELPOLARITY_FALLING -TIM2.IPParameters=Channel-Input_Capture1_from_TI1,ICPolarity_CH1,AutoReloadPreload,Prescaler,Channel-Input_Capture2_from_TI1 -TIM2.Prescaler=64-1 -USART1.AutoBaudRateEnableParam=UART_ADVFEATURE_AUTOBAUDRATE_ENABLE -USART1.IPParameters=VirtualMode-Asynchronous,Mode,AutoBaudRateEnableParam -USART1.Mode=MODE_TX -USART1.VirtualMode-Asynchronous=VM_ASYNC -USB_DEVICE.APP_RX_DATA_SIZE=512 -USB_DEVICE.APP_TX_DATA_SIZE=512 -USB_DEVICE.CLASS_NAME_FS=CDC -USB_DEVICE.IPParameters=VirtualMode,VirtualModeFS,CLASS_NAME_FS,MANUFACTURER_STRING,PRODUCT_STRING_CDC_FS,APP_RX_DATA_SIZE,APP_TX_DATA_SIZE -USB_DEVICE.MANUFACTURER_STRING=Flipper -USB_DEVICE.PRODUCT_STRING_CDC_FS=Flipper Control Virtual ComPort -USB_DEVICE.VirtualMode=Cdc -USB_DEVICE.VirtualModeFS=Cdc_FS -VP_ADC1_TempSens_Input.Mode=IN-TempSens -VP_ADC1_TempSens_Input.Signal=ADC1_TempSens_Input -VP_ADC1_Vref_Input.Mode=IN-Vrefint -VP_ADC1_Vref_Input.Signal=ADC1_Vref_Input -VP_AES1_VS_AES.Mode=AES_Activate -VP_AES1_VS_AES.Signal=AES1_VS_AES -VP_AES2_VS_AES.Mode=AES_Activate -VP_AES2_VS_AES.Signal=AES2_VS_AES -VP_COMP1_VS_VREFINT14.Mode=VREFINT_14 -VP_COMP1_VS_VREFINT14.Signal=COMP1_VS_VREFINT14 -VP_CRC_VS_CRC.Mode=CRC_Activate -VP_CRC_VS_CRC.Signal=CRC_VS_CRC -VP_FREERTOS_VS_CMSIS_V2.Mode=CMSIS_V2 -VP_FREERTOS_VS_CMSIS_V2.Signal=FREERTOS_VS_CMSIS_V2 -VP_HSEM_VS_HSEM.Mode=HSEM_Activate -VP_HSEM_VS_HSEM.Signal=HSEM_VS_HSEM -VP_PKA_VS_PKA.Mode=PKA_Activate -VP_PKA_VS_PKA.Signal=PKA_VS_PKA -VP_RNG_VS_RNG.Mode=RNG_Activate -VP_RNG_VS_RNG.Signal=RNG_VS_RNG -VP_RTC_VS_RTC_Activate.Mode=RTC_Enabled -VP_RTC_VS_RTC_Activate.Signal=RTC_VS_RTC_Activate -VP_RTC_VS_RTC_Calendar.Mode=RTC_Calendar -VP_RTC_VS_RTC_Calendar.Signal=RTC_VS_RTC_Calendar -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick -VP_TIM16_VS_ClockSourceINT.Mode=Enable_Timer -VP_TIM16_VS_ClockSourceINT.Signal=TIM16_VS_ClockSourceINT -VP_TIM1_VS_ClockSourceINT.Mode=Internal -VP_TIM1_VS_ClockSourceINT.Signal=TIM1_VS_ClockSourceINT -VP_TIM2_VS_ClockSourceINT.Mode=Internal -VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT -VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS -VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_FS -board=custom diff --git a/firmware/targets/f7/cube/startup_stm32wb55xx_cm4.s b/firmware/targets/f7/cube/startup_stm32wb55xx_cm4.s deleted file mode 100644 index 053db01e..00000000 --- a/firmware/targets/f7/cube/startup_stm32wb55xx_cm4.s +++ /dev/null @@ -1,446 +0,0 @@ -/** - ****************************************************************************** - * @file startup_stm32wb55xx_cm4.s - * @author MCD Application Team - * @brief STM32WB55xx devices vector table GCC toolchain. - * This module performs: - * - Set the initial SP - * - Set the initial PC == Reset_Handler, - * - Set the vector table entries with the exceptions ISR address - * - Branches to main in the C library (which eventually - * calls main()). - * After Reset the Cortex-M4 processor is in Thread mode, - * priority is Privileged, and the Stack is set to Main. - ****************************************************************************** - * @attention - * - * Copyright (c) 2019-2021 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -.syntax unified -.cpu cortex-m4 -.fpu softvfp -.thumb - -.global g_pfnVectors -.global Default_Handler - -/* start address for the initialization values of the .data section. -defined in linker script */ -.word _sidata -/* start address for the .data section. defined in linker script */ -.word _sdata -/* end address for the .data section. defined in linker script */ -.word _edata -/* start address for the .bss section. defined in linker script */ -.word _sbss -/* end address for the .bss section. defined in linker script */ -.word _ebss -/* start address for the .MB_MEM2 section. defined in linker script */ -.word _sMB_MEM2 -/* end address for the .MB_MEM2 section. defined in linker script */ -.word _eMB_MEM2 - -/* INIT_BSS macro is used to fill the specified region [start : end] with zeros */ -.macro INIT_BSS start, end - ldr r0, =\start - ldr r1, =\end - movs r3, #0 - bl LoopFillZerobss -.endm - -/* INIT_DATA macro is used to copy data in the region [start : end] starting from 'src' */ -.macro INIT_DATA start, end, src - ldr r0, =\start - ldr r1, =\end - ldr r2, =\src - movs r3, #0 - bl LoopCopyDataInit -.endm - -.section .text.data_initializers -CopyDataInit: - ldr r4, [r2, r3] - str r4, [r0, r3] - adds r3, r3, #4 - -LoopCopyDataInit: - adds r4, r0, r3 - cmp r4, r1 - bcc CopyDataInit - bx lr - -FillZerobss: - str r3, [r0] - adds r0, r0, #4 - -LoopFillZerobss: - cmp r0, r1 - bcc FillZerobss - bx lr - - -.section .text.Reset_Handler -.weak Reset_Handler -.type Reset_Handler, %function - -Reset_Handler: - ldr r0, =_estack - mov sp, r0 /* set stack pointer */ - /* Call the clock system intitialization function.*/ - bl SystemInit - -/* Copy the data segment initializers from flash to SRAM */ - INIT_DATA _sdata, _edata, _sidata - -/* Zero fill the bss segments. */ - INIT_BSS _sbss, _ebss - INIT_BSS _sMB_MEM2, _eMB_MEM2 - -/* Call static constructors */ - bl __libc_init_array -/* Call the application s entry point.*/ - bl main - -LoopForever: - b LoopForever - -.size Reset_Handler, .-Reset_Handler - -/** - * @brief This is the code that gets called when the processor receives an - * unexpected interrupt. This simply enters an infinite loop, preserving - * the system state for examination by a debugger. - * - * @param None - * @retval None -*/ - .section .text.Default_Handler,"ax",%progbits -Default_Handler: -Infinite_Loop: - b Infinite_Loop - .size Default_Handler, .-Default_Handler -/****************************************************************************** -* -* The minimal vector table for a Cortex-M4. Note that the proper constructs -* must be placed on this to ensure that it ends up at physical address -* 0x0000.0000. -* -******************************************************************************/ - .section .isr_vector,"a",%progbits - .type g_pfnVectors, %object - .size g_pfnVectors, .-g_pfnVectors - - -g_pfnVectors: - .word _estack - .word Reset_Handler - .word NMI_Handler - .word HardFault_Handler - .word MemManage_Handler - .word BusFault_Handler - .word UsageFault_Handler - .word 0 - .word 0 - .word 0 - .word 0 - .word SVC_Handler - .word DebugMon_Handler - .word 0 - .word PendSV_Handler - .word SysTick_Handler - .word WWDG_IRQHandler - .word PVD_PVM_IRQHandler - .word TAMP_STAMP_LSECSS_IRQHandler - .word RTC_WKUP_IRQHandler - .word FLASH_IRQHandler - .word RCC_IRQHandler - .word EXTI0_IRQHandler - .word EXTI1_IRQHandler - .word EXTI2_IRQHandler - .word EXTI3_IRQHandler - .word EXTI4_IRQHandler - .word DMA1_Channel1_IRQHandler - .word DMA1_Channel2_IRQHandler - .word DMA1_Channel3_IRQHandler - .word DMA1_Channel4_IRQHandler - .word DMA1_Channel5_IRQHandler - .word DMA1_Channel6_IRQHandler - .word DMA1_Channel7_IRQHandler - .word ADC1_IRQHandler - .word USB_HP_IRQHandler - .word USB_LP_IRQHandler - .word C2SEV_PWR_C2H_IRQHandler - .word COMP_IRQHandler - .word EXTI9_5_IRQHandler - .word TIM1_BRK_IRQHandler - .word TIM1_UP_TIM16_IRQHandler - .word TIM1_TRG_COM_TIM17_IRQHandler - .word TIM1_CC_IRQHandler - .word TIM2_IRQHandler - .word PKA_IRQHandler - .word I2C1_EV_IRQHandler - .word I2C1_ER_IRQHandler - .word I2C3_EV_IRQHandler - .word I2C3_ER_IRQHandler - .word SPI1_IRQHandler - .word SPI2_IRQHandler - .word USART1_IRQHandler - .word LPUART1_IRQHandler - .word SAI1_IRQHandler - .word TSC_IRQHandler - .word EXTI15_10_IRQHandler - .word RTC_Alarm_IRQHandler - .word CRS_IRQHandler - .word PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler - .word IPCC_C1_RX_IRQHandler - .word IPCC_C1_TX_IRQHandler - .word HSEM_IRQHandler - .word LPTIM1_IRQHandler - .word LPTIM2_IRQHandler - .word LCD_IRQHandler - .word QUADSPI_IRQHandler - .word AES1_IRQHandler - .word AES2_IRQHandler - .word RNG_IRQHandler - .word FPU_IRQHandler - .word DMA2_Channel1_IRQHandler - .word DMA2_Channel2_IRQHandler - .word DMA2_Channel3_IRQHandler - .word DMA2_Channel4_IRQHandler - .word DMA2_Channel5_IRQHandler - .word DMA2_Channel6_IRQHandler - .word DMA2_Channel7_IRQHandler - .word DMAMUX1_OVR_IRQHandler - -/******************************************************************************* -* -* Provide weak aliases for each Exception handler to the Default_Handler. -* As they are weak aliases, any function with the same name will override -* this definition. -* -*******************************************************************************/ - .weak NMI_Handler - .thumb_set NMI_Handler,Default_Handler - - .weak HardFault_Handler - .thumb_set HardFault_Handler,Default_Handler - - .weak MemManage_Handler - .thumb_set MemManage_Handler,Default_Handler - - .weak BusFault_Handler - .thumb_set BusFault_Handler,Default_Handler - - .weak UsageFault_Handler - .thumb_set UsageFault_Handler,Default_Handler - - .weak SVC_Handler - .thumb_set SVC_Handler,Default_Handler - - .weak DebugMon_Handler - .thumb_set DebugMon_Handler,Default_Handler - - .weak PendSV_Handler - .thumb_set PendSV_Handler,Default_Handler - - .weak SysTick_Handler - .thumb_set SysTick_Handler,Default_Handler - - .weak WWDG_IRQHandler - .thumb_set WWDG_IRQHandler,Default_Handler - - .weak PVD_PVM_IRQHandler - .thumb_set PVD_PVM_IRQHandler,Default_Handler - - .weak TAMP_STAMP_LSECSS_IRQHandler - .thumb_set TAMP_STAMP_LSECSS_IRQHandler,Default_Handler - - .weak RTC_WKUP_IRQHandler - .thumb_set RTC_WKUP_IRQHandler,Default_Handler - - .weak FLASH_IRQHandler - .thumb_set FLASH_IRQHandler,Default_Handler - - .weak RCC_IRQHandler - .thumb_set RCC_IRQHandler,Default_Handler - - .weak EXTI0_IRQHandler - .thumb_set EXTI0_IRQHandler,Default_Handler - - .weak EXTI1_IRQHandler - .thumb_set EXTI1_IRQHandler,Default_Handler - - .weak EXTI2_IRQHandler - .thumb_set EXTI2_IRQHandler,Default_Handler - - .weak EXTI3_IRQHandler - .thumb_set EXTI3_IRQHandler,Default_Handler - - .weak EXTI4_IRQHandler - .thumb_set EXTI4_IRQHandler,Default_Handler - - .weak DMA1_Channel1_IRQHandler - .thumb_set DMA1_Channel1_IRQHandler,Default_Handler - - .weak DMA1_Channel2_IRQHandler - .thumb_set DMA1_Channel2_IRQHandler,Default_Handler - - .weak DMA1_Channel3_IRQHandler - .thumb_set DMA1_Channel3_IRQHandler,Default_Handler - - .weak DMA1_Channel4_IRQHandler - .thumb_set DMA1_Channel4_IRQHandler,Default_Handler - - .weak DMA1_Channel5_IRQHandler - .thumb_set DMA1_Channel5_IRQHandler,Default_Handler - - .weak DMA1_Channel6_IRQHandler - .thumb_set DMA1_Channel6_IRQHandler,Default_Handler - - .weak DMA1_Channel7_IRQHandler - .thumb_set DMA1_Channel7_IRQHandler,Default_Handler - - .weak ADC1_IRQHandler - .thumb_set ADC1_IRQHandler,Default_Handler - - .weak USB_HP_IRQHandler - .thumb_set USB_HP_IRQHandler,Default_Handler - - .weak USB_LP_IRQHandler - .thumb_set USB_LP_IRQHandler,Default_Handler - - .weak C2SEV_PWR_C2H_IRQHandler - .thumb_set C2SEV_PWR_C2H_IRQHandler,Default_Handler - - .weak COMP_IRQHandler - .thumb_set COMP_IRQHandler,Default_Handler - - .weak EXTI9_5_IRQHandler - .thumb_set EXTI9_5_IRQHandler,Default_Handler - - .weak TIM1_BRK_IRQHandler - .thumb_set TIM1_BRK_IRQHandler,Default_Handler - - .weak TIM1_UP_TIM16_IRQHandler - .thumb_set TIM1_UP_TIM16_IRQHandler,Default_Handler - - .weak TIM1_TRG_COM_TIM17_IRQHandler - .thumb_set TIM1_TRG_COM_TIM17_IRQHandler,Default_Handler - - .weak TIM1_CC_IRQHandler - .thumb_set TIM1_CC_IRQHandler,Default_Handler - - .weak TIM2_IRQHandler - .thumb_set TIM2_IRQHandler,Default_Handler - - .weak PKA_IRQHandler - .thumb_set PKA_IRQHandler,Default_Handler - - .weak I2C1_EV_IRQHandler - .thumb_set I2C1_EV_IRQHandler,Default_Handler - - .weak I2C1_ER_IRQHandler - .thumb_set I2C1_ER_IRQHandler,Default_Handler - - .weak I2C3_EV_IRQHandler - .thumb_set I2C3_EV_IRQHandler,Default_Handler - - .weak I2C3_ER_IRQHandler - .thumb_set I2C3_ER_IRQHandler,Default_Handler - - .weak SPI1_IRQHandler - .thumb_set SPI1_IRQHandler,Default_Handler - - .weak SPI2_IRQHandler - .thumb_set SPI2_IRQHandler,Default_Handler - - .weak USART1_IRQHandler - .thumb_set USART1_IRQHandler,Default_Handler - - .weak LPUART1_IRQHandler - .thumb_set LPUART1_IRQHandler,Default_Handler - - .weak SAI1_IRQHandler - .thumb_set SAI1_IRQHandler,Default_Handler - - .weak TSC_IRQHandler - .thumb_set TSC_IRQHandler,Default_Handler - - .weak EXTI15_10_IRQHandler - .thumb_set EXTI15_10_IRQHandler,Default_Handler - - .weak RTC_Alarm_IRQHandler - .thumb_set RTC_Alarm_IRQHandler,Default_Handler - - .weak CRS_IRQHandler - .thumb_set CRS_IRQHandler,Default_Handler - - .weak PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler - .thumb_set PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler,Default_Handler - - .weak IPCC_C1_RX_IRQHandler - .thumb_set IPCC_C1_RX_IRQHandler,Default_Handler - - .weak IPCC_C1_TX_IRQHandler - .thumb_set IPCC_C1_TX_IRQHandler,Default_Handler - - .weak HSEM_IRQHandler - .thumb_set HSEM_IRQHandler,Default_Handler - - .weak LPTIM1_IRQHandler - .thumb_set LPTIM1_IRQHandler,Default_Handler - - .weak LPTIM2_IRQHandler - .thumb_set LPTIM2_IRQHandler,Default_Handler - - .weak LCD_IRQHandler - .thumb_set LCD_IRQHandler,Default_Handler - - .weak QUADSPI_IRQHandler - .thumb_set QUADSPI_IRQHandler,Default_Handler - - .weak AES1_IRQHandler - .thumb_set AES1_IRQHandler,Default_Handler - - .weak AES2_IRQHandler - .thumb_set AES2_IRQHandler,Default_Handler - - .weak RNG_IRQHandler - .thumb_set RNG_IRQHandler,Default_Handler - - .weak FPU_IRQHandler - .thumb_set FPU_IRQHandler,Default_Handler - - .weak DMA2_Channel1_IRQHandler - .thumb_set DMA2_Channel1_IRQHandler,Default_Handler - - .weak DMA2_Channel2_IRQHandler - .thumb_set DMA2_Channel2_IRQHandler,Default_Handler - - .weak DMA2_Channel3_IRQHandler - .thumb_set DMA2_Channel3_IRQHandler,Default_Handler - - .weak DMA2_Channel4_IRQHandler - .thumb_set DMA2_Channel4_IRQHandler,Default_Handler - - .weak DMA2_Channel5_IRQHandler - .thumb_set DMA2_Channel5_IRQHandler,Default_Handler - - .weak DMA2_Channel6_IRQHandler - .thumb_set DMA2_Channel6_IRQHandler,Default_Handler - - .weak DMA2_Channel7_IRQHandler - .thumb_set DMA2_Channel7_IRQHandler,Default_Handler - - .weak DMAMUX1_OVR_IRQHandler - .thumb_set DMAMUX1_OVR_IRQHandler,Default_Handler - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/firmware/targets/f7/cube/stm32wb55xx_flash_cm4.ld b/firmware/targets/f7/cube/stm32wb55xx_flash_cm4.ld deleted file mode 100644 index caa19463..00000000 --- a/firmware/targets/f7/cube/stm32wb55xx_flash_cm4.ld +++ /dev/null @@ -1,187 +0,0 @@ -/** -***************************************************************************** -** -** File : stm32wb55xx_flash_cm4.ld -** -** Abstract : System Workbench Minimal System calls file -** -** For more information about which c-functions -** need which of these lowlevel functions -** please consult the Newlib libc-manual -** -** Environment : System Workbench for MCU -** -** Distribution: The file is distributed “as is,” without any warranty -** of any kind. -** -***************************************************************************** -** -**

© COPYRIGHT(c) 2019 Ac6

-** -** Redistribution and use in source and binary forms, with or without modification, -** are permitted provided that the following conditions are met: -** 1. Redistributions of source code must retain the above copyright notice, -** this list of conditions and the following disclaimer. -** 2. Redistributions in binary form must reproduce the above copyright notice, -** this list of conditions and the following disclaimer in the documentation -** and/or other materials provided with the distribution. -** 3. Neither the name of Ac6 nor the names of its contributors -** may be used to endorse or promote products derived from this software -** without specific prior written permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -** -***************************************************************************** -*/ - -/* Entry Point */ -ENTRY(Reset_Handler) - -/* Highest address of the user mode stack */ -_estack = 0x20030000; /* end of RAM */ -/* Generate a link error if heap and stack don't fit into RAM */ -_Min_Heap_Size = 0x400; /* required amount of heap */ -_Min_Stack_Size = 0x1000; /* required amount of stack */ - -/* Specify the memory areas */ -MEMORY -{ -FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K -RAM1 (xrw) : ORIGIN = 0x20000008, LENGTH = 0x2FFF8 -RAM_SHARED (xrw) : ORIGIN = 0x20030000, LENGTH = 10K -} - -/* Define output sections */ -SECTIONS -{ - /* The startup code goes first into FLASH */ - .isr_vector : - { - . = ALIGN(4); - KEEP(*(.isr_vector)) /* Startup code */ - . = ALIGN(4); - } >FLASH - - /* The program code and other data goes into FLASH */ - .text : - { - . = ALIGN(4); - *(.text) /* .text sections (code) */ - *(.text*) /* .text* sections (code) */ - *(.glue_7) /* glue arm to thumb code */ - *(.glue_7t) /* glue thumb to arm code */ - *(.eh_frame) - - KEEP (*(.init)) - KEEP (*(.fini)) - - . = ALIGN(4); - _etext = .; /* define a global symbols at end of code */ - } >FLASH - - /* Constant data goes into FLASH */ - .rodata : - { - . = ALIGN(4); - *(.rodata) /* .rodata sections (constants, strings, etc.) */ - *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ - . = ALIGN(4); - } >FLASH - - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH - .ARM : { - __exidx_start = .; - *(.ARM.exidx*) - __exidx_end = .; - } >FLASH - - .preinit_array : - { - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP (*(.preinit_array*)) - PROVIDE_HIDDEN (__preinit_array_end = .); - } >FLASH - .init_array : - { - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array*)) - PROVIDE_HIDDEN (__init_array_end = .); - } >FLASH - .fini_array : - { - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP (*(SORT(.fini_array.*))) - KEEP (*(.fini_array*)) - PROVIDE_HIDDEN (__fini_array_end = .); - } >FLASH - - /* used by the startup to initialize data */ - _sidata = LOADADDR(.data); - - /* Initialized data sections goes into RAM, load LMA copy after code */ - .data : - { - . = ALIGN(4); - _sdata = .; /* create a global symbol at data start */ - *(.data) /* .data sections */ - *(.data*) /* .data* sections */ - - . = ALIGN(4); - _edata = .; /* define a global symbol at data end */ - } >RAM1 AT> FLASH - - - /* Uninitialized data section */ - . = ALIGN(4); - .bss : - { - /* This is used by the startup in order to initialize the .bss secion */ - _sbss = .; /* define a global symbol at bss start */ - __bss_start__ = _sbss; - *(.bss) - *(.bss*) - *(COMMON) - - . = ALIGN(4); - _ebss = .; /* define a global symbol at bss end */ - __bss_end__ = _ebss; - } >RAM1 - - /* User_heap_stack section, used to check that there is enough RAM left */ - ._user_heap_stack : - { - . = ALIGN(8); - PROVIDE ( end = . ); - PROVIDE ( _end = . ); - . = . + _Min_Heap_Size; - . = . + _Min_Stack_Size; - . = ALIGN(8); - } >RAM1 - - - - /* Remove information from the standard libraries */ - /DISCARD/ : - { - libc.a ( * ) - libm.a ( * ) - libgcc.a ( * ) - } - - .ARM.attributes 0 : { *(.ARM.attributes) } - MAPPING_TABLE (NOLOAD) : { *(MAPPING_TABLE) } >RAM_SHARED - MB_MEM1 (NOLOAD) : { *(MB_MEM1) } >RAM_SHARED - MB_MEM2 (NOLOAD) : { _sMB_MEM2 = . ; *(MB_MEM2) ; _eMB_MEM2 = . ; } >RAM_SHARED -} - - diff --git a/firmware/targets/f7/fatfs/ffconf.h b/firmware/targets/f7/fatfs/ffconf.h index 91c6c00c..83bcfc78 100644 --- a/firmware/targets/f7/fatfs/ffconf.h +++ b/firmware/targets/f7/fatfs/ffconf.h @@ -27,8 +27,11 @@ /*-----------------------------------------------------------------------------/ / Function Configurations /-----------------------------------------------------------------------------*/ - +#ifdef FURI_RAM_EXEC +#define _FS_READONLY 1 /* 0:Read/Write or 1:Read only */ +#else #define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */ +#endif /* This option switches read-only configuration. (0:Read/Write or 1:Read-only) / Read-only configuration removes writing API functions, f_write(), f_sync(), / f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() @@ -55,7 +58,11 @@ /* This option switches filtered directory read functions, f_findfirst() and / f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ +#ifdef FURI_RAM_EXEC +#define _USE_MKFS 0 +#else #define _USE_MKFS 1 +#endif /* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ #define _USE_FASTSEEK 1 diff --git a/firmware/targets/f7/furi_hal/furi_hal.c b/firmware/targets/f7/furi_hal/furi_hal.c index a8be527b..e671dd8c 100644 --- a/firmware/targets/f7/furi_hal/furi_hal.c +++ b/firmware/targets/f7/furi_hal/furi_hal.c @@ -6,15 +6,43 @@ #define TAG "FuriHal" -void furi_hal_init() { - furi_hal_rtc_init(); - furi_hal_interrupt_init(); +void furi_hal_init_early() { + furi_hal_clock_init_early(); furi_hal_delay_init(); + furi_hal_resources_init_early(); + + furi_hal_spi_init_early(); + + furi_hal_i2c_init_early(); + furi_hal_light_init(); + + furi_hal_rtc_init_early(); +} + +void furi_hal_deinit_early() { + furi_hal_rtc_deinit_early(); + + furi_hal_i2c_deinit_early(); + furi_hal_spi_deinit_early(); + + furi_hal_resources_deinit_early(); + + furi_hal_clock_deinit_early(); +} + +void furi_hal_init() { + furi_hal_clock_init(); + furi_hal_console_init(); + furi_hal_rtc_init(); + + furi_hal_interrupt_init(); + + furi_hal_flash_init(); + furi_hal_resources_init(); FURI_LOG_I(TAG, "GPIO OK"); - furi_hal_bootloader_init(); furi_hal_version_init(); furi_hal_spi_init(); @@ -25,21 +53,26 @@ void furi_hal_init() { FURI_LOG_I(TAG, "Speaker OK"); furi_hal_crypto_init(); + furi_hal_crc_init(true); // VCP + USB +#ifndef FURI_RAM_EXEC furi_hal_usb_init(); furi_hal_vcp_init(); FURI_LOG_I(TAG, "USB OK"); +#endif furi_hal_i2c_init(); // High Level furi_hal_power_init(); furi_hal_light_init(); +#ifndef FURI_RAM_EXEC furi_hal_vibro_init(); furi_hal_subghz_init(); furi_hal_nfc_init(); furi_hal_rfid_init(); +#endif furi_hal_bt_init(); furi_hal_compress_icon_init(); @@ -62,7 +95,13 @@ void furi_hal_init() { LL_MPU_Enable(LL_MPU_CTRL_PRIVILEGED_DEFAULT); } -void furi_hal_init_critical() { - furi_hal_clock_init(); - furi_hal_console_init(); +void furi_hal_switch(void* address) { + __set_BASEPRI(0); + asm volatile("ldr r3, [%0] \n" + "msr msp, r3 \n" + "ldr r3, [%1] \n" + "mov pc, r3 \n" + : + : "r"(address), "r"(address + 0x4) + : "r3"); } diff --git a/firmware/targets/f7/furi_hal/furi_hal_bootloader.c b/firmware/targets/f7/furi_hal/furi_hal_bootloader.c deleted file mode 100644 index 3b549955..00000000 --- a/firmware/targets/f7/furi_hal/furi_hal_bootloader.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include - -#define TAG "FuriHalBoot" - -// Boot request enum -#define BOOT_REQUEST_TAINTED 0x00000000 -#define BOOT_REQUEST_CLEAN 0xDADEDADE -#define BOOT_REQUEST_DFU 0xDF00B000 - -void furi_hal_bootloader_init() { -#ifndef DEBUG - furi_hal_rtc_set_register(FuriHalRtcRegisterBoot, BOOT_REQUEST_TAINTED); -#endif - FURI_LOG_I(TAG, "Init OK"); -} - -void furi_hal_bootloader_set_mode(FuriHalBootloaderMode mode) { - if(mode == FuriHalBootloaderModeNormal) { - furi_hal_rtc_set_register(FuriHalRtcRegisterBoot, BOOT_REQUEST_CLEAN); - } else if(mode == FuriHalBootloaderModeDFU) { - furi_hal_rtc_set_register(FuriHalRtcRegisterBoot, BOOT_REQUEST_DFU); - } -} diff --git a/firmware/targets/f7/furi_hal/furi_hal_clock.c b/firmware/targets/f7/furi_hal/furi_hal_clock.c index 962f2123..ca5e5649 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_clock.c +++ b/firmware/targets/f7/furi_hal/furi_hal_clock.c @@ -13,6 +13,39 @@ #define HS_CLOCK_IS_READY() (LL_RCC_HSE_IsReady() && LL_RCC_HSI_IsReady()) #define LS_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady()) +void furi_hal_clock_init_early() { + LL_Init1msTick(4000000); + LL_SetSystemCoreClock(4000000); + + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOE); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOH); + + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1); + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2); + + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1); + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C3); +} + +void furi_hal_clock_deinit_early() { + LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_I2C1); + LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_I2C3); + + LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_SPI1); + LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_SPI2); + + LL_AHB2_GRP1_DisableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_DisableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_DisableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_DisableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + LL_AHB2_GRP1_DisableClock(LL_AHB2_GRP1_PERIPH_GPIOE); + LL_AHB2_GRP1_DisableClock(LL_AHB2_GRP1_PERIPH_GPIOH); +} + void furi_hal_clock_init() { /* Prepare Flash memory for 64mHz system clock */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_3); diff --git a/firmware/targets/f7/furi_hal/furi_hal_clock.h b/firmware/targets/f7/furi_hal/furi_hal_clock.h index 3ec59205..0a1099ac 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_clock.h +++ b/firmware/targets/f7/furi_hal/furi_hal_clock.h @@ -1,5 +1,11 @@ #pragma once +/** Early initialization */ +void furi_hal_clock_init_early(); + +/** Early deinitialization */ +void furi_hal_clock_deinit_early(); + /** Initialize clocks */ void furi_hal_clock_init(); diff --git a/firmware/targets/f7/furi_hal/furi_hal_crc.c b/firmware/targets/f7/furi_hal/furi_hal_crc.c new file mode 100644 index 00000000..321809d9 --- /dev/null +++ b/firmware/targets/f7/furi_hal/furi_hal_crc.c @@ -0,0 +1,88 @@ +#include +#include + +typedef enum { + CRC_State_Reset, + CRC_State_Ready, + CRC_State_Busy, +} CRC_State; + +typedef struct { + CRC_State state; + osMutexId_t mtx; +} HAL_CRC_Control; + +static volatile HAL_CRC_Control hal_crc_control = { + .state = CRC_State_Reset, + .mtx = NULL, +}; + +void furi_hal_crc_init(bool synchronize) { + /* initialize peripheral with default generating polynomial */ + LL_CRC_SetInputDataReverseMode(CRC, LL_CRC_INDATA_REVERSE_BYTE); + LL_CRC_SetOutputDataReverseMode(CRC, LL_CRC_OUTDATA_REVERSE_BIT); + LL_CRC_SetPolynomialCoef(CRC, LL_CRC_DEFAULT_CRC32_POLY); + LL_CRC_SetPolynomialSize(CRC, LL_CRC_POLYLENGTH_32B); + LL_CRC_SetInitialData(CRC, LL_CRC_DEFAULT_CRC_INITVALUE); + + if(synchronize) { + hal_crc_control.mtx = osMutexNew(NULL); + } + hal_crc_control.state = CRC_State_Ready; +} + +void furi_hal_crc_reset() { + furi_check(hal_crc_control.state == CRC_State_Ready); + if(hal_crc_control.mtx) { + osMutexRelease(hal_crc_control.mtx); + } + LL_CRC_ResetCRCCalculationUnit(CRC); +} + +static uint32_t furi_hal_crc_handle_8(uint8_t pBuffer[], uint32_t BufferLength) { + uint32_t i; /* input data buffer index */ + hal_crc_control.state = CRC_State_Busy; + /* Processing time optimization: 4 bytes are entered in a row with a single word write, + * last bytes must be carefully fed to the CRC calculator to ensure a correct type + * handling by the peripheral */ + for(i = 0U; i < (BufferLength / 4U); i++) { + LL_CRC_FeedData32( + CRC, + ((uint32_t)pBuffer[4U * i] << 24U) | ((uint32_t)pBuffer[(4U * i) + 1U] << 16U) | + ((uint32_t)pBuffer[(4U * i) + 2U] << 8U) | (uint32_t)pBuffer[(4U * i) + 3U]); + } + /* last bytes specific handling */ + if((BufferLength % 4U) != 0U) { + if((BufferLength % 4U) == 1U) { + LL_CRC_FeedData8(CRC, pBuffer[4U * i]); + } else if((BufferLength % 4U) == 2U) { + LL_CRC_FeedData16( + CRC, ((uint16_t)(pBuffer[4U * i]) << 8U) | (uint16_t)pBuffer[(4U * i) + 1U]); + } else if((BufferLength % 4U) == 3U) { + LL_CRC_FeedData16( + CRC, ((uint16_t)(pBuffer[4U * i]) << 8U) | (uint16_t)pBuffer[(4U * i) + 1U]); + LL_CRC_FeedData8(CRC, pBuffer[(4U * i) + 2U]); + } + } + + hal_crc_control.state = CRC_State_Ready; + /* Return the CRC computed value */ + return LL_CRC_ReadData32(CRC); +} + +static uint32_t furi_hal_crc_accumulate(uint32_t pBuffer[], uint32_t BufferLength) { + furi_check(hal_crc_control.state == CRC_State_Ready); + if(hal_crc_control.mtx) { + furi_check(osMutexGetOwner(hal_crc_control.mtx) != NULL); + } + return furi_hal_crc_handle_8((uint8_t*)pBuffer, BufferLength); +} + +uint32_t furi_hal_crc_feed(void* data, uint16_t length) { + return ~furi_hal_crc_accumulate(data, length); +} + +bool furi_hal_crc_acquire(uint32_t timeout) { + furi_assert(hal_crc_control.mtx); + return osMutexAcquire(hal_crc_control.mtx, timeout) == osOK; +} diff --git a/firmware/targets/f7/furi_hal/furi_hal_crc.h b/firmware/targets/f7/furi_hal/furi_hal_crc.h new file mode 100644 index 00000000..110e6c05 --- /dev/null +++ b/firmware/targets/f7/furi_hal/furi_hal_crc.h @@ -0,0 +1,35 @@ +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Configure for CRC32 calculation + * @param synchronize enforce acquisition & release in multithreaded environment + */ +void furi_hal_crc_init(bool synchronize); + +/** Blocking call to get control of CRC block. Mandatory while RTOS is running + * @param timeout time to wait for CRC to be available. Can be osWaitForever + * @return bool acquisition success + */ +bool furi_hal_crc_acquire(uint32_t timeout); + +/** Reset current calculation state and release CRC block + */ +void furi_hal_crc_reset(); + +/** Process data block. Does not reset current state, + * allowing to process arbitrary data lengths + * @param data pointer to data + * @param length data length + * @return uint32_t CRC32 value + */ +uint32_t furi_hal_crc_feed(void* data, uint16_t length); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/firmware/targets/f7/furi_hal/furi_hal_delay.c b/firmware/targets/f7/furi_hal/furi_hal_delay.c index bb852ca9..8a26d8dc 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_delay.c +++ b/firmware/targets/f7/furi_hal/furi_hal_delay.c @@ -2,17 +2,20 @@ #include #include +#include #define TAG "FuriHalDelay" -uint32_t instructions_per_us; + static volatile uint32_t tick_cnt = 0; -void furi_hal_delay_init(void) { +void furi_hal_delay_init() { CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; DWT->CYCCNT = 0U; - instructions_per_us = SystemCoreClock / 1000000.0f; - FURI_LOG_I(TAG, "Init OK"); +} + +uint32_t furi_hal_delay_instructions_per_microsecond() { + return SystemCoreClock / 1000000; } void furi_hal_tick(void) { @@ -25,7 +28,7 @@ uint32_t furi_hal_get_tick(void) { void furi_hal_delay_us(float microseconds) { uint32_t start = DWT->CYCCNT; - uint32_t time_ticks = microseconds * instructions_per_us; + uint32_t time_ticks = microseconds * furi_hal_delay_instructions_per_microsecond(); while((DWT->CYCCNT - start) < time_ticks) { }; } @@ -33,8 +36,12 @@ void furi_hal_delay_us(float microseconds) { // cannot be used in ISR // TODO add delay_ISR variant void furi_hal_delay_ms(float milliseconds) { - uint32_t ticks = milliseconds / (1000.0f / osKernelGetTickFreq()); - osStatus_t result = osDelay(ticks); - (void)result; - furi_assert(result == osOK); + if(!FURI_IS_ISR() && osKernelGetState() == osKernelRunning) { + uint32_t ticks = milliseconds / (1000.0f / osKernelGetTickFreq()); + osStatus_t result = osDelay(ticks); + (void)result; + furi_assert(result == osOK); + } else { + furi_hal_delay_us(milliseconds * 1000); + } } diff --git a/firmware/targets/f7/furi_hal/furi_hal_flash.c b/firmware/targets/f7/furi_hal/furi_hal_flash.c index fc1dbd2f..aaf7f1a2 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_flash.c +++ b/firmware/targets/f7/furi_hal/furi_hal_flash.c @@ -14,7 +14,9 @@ #define FURI_HAL_FLASH_CYCLES_COUNT 10000 #define FURI_HAL_FLASH_TIMEOUT 1000 #define FURI_HAL_FLASH_KEY1 0x45670123U + #define FURI_HAL_FLASH_KEY2 0xCDEF89ABU +#define FURI_HAL_FLASH_TOTAL_PAGES 256 #define FURI_HAL_FLASH_SR_ERRORS \ (FLASH_SR_OPERR | FLASH_SR_PROGERR | FLASH_SR_WRPERR | FLASH_SR_PGAERR | FLASH_SR_SIZERR | \ FLASH_SR_PGSERR | FLASH_SR_MISERR | FLASH_SR_FASTERR | FLASH_SR_RDERR | FLASH_SR_OPTVERR) @@ -72,6 +74,12 @@ size_t furi_hal_flash_get_free_page_count() { return (end - page_start) / FURI_HAL_FLASH_PAGE_SIZE; } +void furi_hal_flash_init() { + // Errata 2.2.9, Flash OPTVERR flag is always set after system reset + WRITE_REG(FLASH->SR, FLASH_SR_OPTVERR); + //__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR); +} + static void furi_hal_flash_unlock() { /* verify Flash is locked */ furi_check(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != 0U); @@ -283,6 +291,22 @@ bool furi_hal_flash_erase(uint8_t page) { return true; } +static inline bool furi_hal_flash_write_dword_internal(size_t address, uint64_t* data) { + /* Program first word */ + *(uint32_t*)address = (uint32_t)*data; + + // Barrier to ensure programming is performed in 2 steps, in right order + // (independently of compiler optimization behavior) + __ISB(); + + /* Program second word */ + *(uint32_t*)(address + 4U) = (uint32_t)(*data >> 32U); + + /* Wait for last operation to be completed */ + furi_check(furi_hal_flash_wait_last_operation(FURI_HAL_FLASH_TIMEOUT)); + return true; +} + bool furi_hal_flash_write_dword(size_t address, uint64_t data) { furi_hal_flash_begin(false); @@ -296,23 +320,70 @@ bool furi_hal_flash_write_dword(size_t address, uint64_t data) { /* Set PG bit */ SET_BIT(FLASH->CR, FLASH_CR_PG); - /* Program first word */ - *(uint32_t*)address = (uint32_t)data; - - // Barrier to ensure programming is performed in 2 steps, in right order - // (independently of compiler optimization behavior) - __ISB(); - - /* Program second word */ - *(uint32_t*)(address + 4U) = (uint32_t)(data >> 32U); - - /* Wait for last operation to be completed */ - furi_check(furi_hal_flash_wait_last_operation(FURI_HAL_FLASH_TIMEOUT)); + /* Do the thing */ + furi_check(furi_hal_flash_write_dword_internal(address, &data)); /* If the program operation is completed, disable the PG or FSTPG Bit */ CLEAR_BIT(FLASH->CR, FLASH_CR_PG); furi_hal_flash_end(false); + /* Wait for last operation to be completed */ + furi_check(furi_hal_flash_wait_last_operation(FURI_HAL_FLASH_TIMEOUT)); return true; } + +static size_t furi_hal_flash_get_page_address(uint8_t page) { + return furi_hal_flash_get_base() + page * FURI_HAL_FLASH_PAGE_SIZE; +} + +bool furi_hal_flash_program_page(const uint8_t page, const uint8_t* data, uint16_t _length) { + uint16_t length = _length; + furi_check(length <= FURI_HAL_FLASH_PAGE_SIZE); + + furi_hal_flash_erase(page); + + furi_hal_flash_begin(false); + + // Ensure that controller state is valid + furi_check(FLASH->SR == 0); + + size_t page_start_address = furi_hal_flash_get_page_address(page); + + /* Set PG bit */ + SET_BIT(FLASH->CR, FLASH_CR_PG); + size_t i_dwords = 0; + for(i_dwords = 0; i_dwords < (length / 8); ++i_dwords) { + /* Do the thing */ + size_t data_offset = i_dwords * 8; + furi_check(furi_hal_flash_write_dword_internal( + page_start_address + data_offset, (uint64_t*)&data[data_offset])); + } + if((length % 8) != 0) { + /* there are more bytes, not fitting into dwords */ + uint64_t tail_data = 0; + size_t data_offset = i_dwords * 8; + for(int32_t tail_i = 0; tail_i < (length % 8); ++tail_i) { + tail_data |= (((uint64_t)data[data_offset + tail_i]) << (tail_i * 8)); + } + + furi_check( + furi_hal_flash_write_dword_internal(page_start_address + data_offset, &tail_data)); + } + + /* If the program operation is completed, disable the PG or FSTPG Bit */ + CLEAR_BIT(FLASH->CR, FLASH_CR_PG); + + furi_hal_flash_end(false); + return true; +} + +int16_t furi_hal_flash_get_page_number(size_t address) { + const size_t flash_base = furi_hal_flash_get_base(); + if((address < flash_base) || + (address > flash_base + FURI_HAL_FLASH_TOTAL_PAGES * FURI_HAL_FLASH_PAGE_SIZE)) { + return -1; + } + + return (address - flash_base) / FURI_HAL_FLASH_PAGE_SIZE; +} \ No newline at end of file diff --git a/firmware/targets/f7/furi_hal/furi_hal_flash.h b/firmware/targets/f7/furi_hal/furi_hal_flash.h index 37f714b8..004c1340 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_flash.h +++ b/firmware/targets/f7/furi_hal/furi_hal_flash.h @@ -4,6 +4,10 @@ #include #include +/** Init flash, applying necessary workarounds + */ +void furi_hal_flash_init(); + /** Get flash base address * * @return pointer to flash base @@ -78,3 +82,22 @@ bool furi_hal_flash_erase(uint8_t page); * @return true on success */ bool furi_hal_flash_write_dword(size_t address, uint64_t data); + +/** Write aligned page data (up to page size) + * + * @warning locking operation with critical section, stales execution + * + * @param address destination address, must be page aligned. + * @param data data to write + * @param length data length + * + * @return true on success + */ +bool furi_hal_flash_program_page(const uint8_t page, const uint8_t* data, uint16_t length); + +/** Get flash page number for address + * + * @return page number, -1 for invalid address + */ + +int16_t furi_hal_flash_get_page_number(size_t address); \ No newline at end of file diff --git a/firmware/targets/f7/furi_hal/furi_hal_i2c.c b/firmware/targets/f7/furi_hal/furi_hal_i2c.c index 03c39a44..7e0bee58 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_i2c.c +++ b/firmware/targets/f7/furi_hal/furi_hal_i2c.c @@ -9,8 +9,15 @@ #define TAG "FuriHalI2C" -void furi_hal_i2c_init() { +void furi_hal_i2c_init_early() { furi_hal_i2c_bus_power.callback(&furi_hal_i2c_bus_power, FuriHalI2cBusEventInit); +} + +void furi_hal_i2c_deinit_early() { + furi_hal_i2c_bus_power.callback(&furi_hal_i2c_bus_power, FuriHalI2cBusEventDeinit); +} + +void furi_hal_i2c_init() { furi_hal_i2c_bus_external.callback(&furi_hal_i2c_bus_external, FuriHalI2cBusEventInit); FURI_LOG_I(TAG, "Init OK"); } diff --git a/firmware/targets/f7/furi_hal/furi_hal_i2c_config.c b/firmware/targets/f7/furi_hal/furi_hal_i2c_config.c index 84cada61..2cdef23a 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_i2c_config.c +++ b/firmware/targets/f7/furi_hal/furi_hal_i2c_config.c @@ -27,7 +27,11 @@ static void furi_hal_i2c_bus_power_event(FuriHalI2cBus* bus, FuriHalI2cBusEvent FURI_CRITICAL_EXIT(); bus->current_handle = NULL; } else if(event == FuriHalI2cBusEventDeinit) { - osMutexDelete(furi_hal_i2c_bus_power_mutex); + furi_check(osMutexDelete(furi_hal_i2c_bus_power_mutex) == osOK); + FURI_CRITICAL_ENTER(); + LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C1); + LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C1); + FURI_CRITICAL_EXIT(); } else if(event == FuriHalI2cBusEventLock) { furi_check(osMutexAcquire(furi_hal_i2c_bus_power_mutex, osWaitForever) == osOK); } else if(event == FuriHalI2cBusEventUnlock) { @@ -51,7 +55,24 @@ FuriHalI2cBus furi_hal_i2c_bus_power = { osMutexId_t furi_hal_i2c_bus_external_mutex = NULL; static void furi_hal_i2c_bus_external_event(FuriHalI2cBus* bus, FuriHalI2cBusEvent event) { - if(event == FuriHalI2cBusEventActivate) { + if(event == FuriHalI2cBusEventInit) { + furi_hal_i2c_bus_external_mutex = osMutexNew(NULL); + FURI_CRITICAL_ENTER(); + LL_RCC_SetI2CClockSource(LL_RCC_I2C3_CLKSOURCE_PCLK1); + LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C3); + FURI_CRITICAL_EXIT(); + bus->current_handle = NULL; + } else if(event == FuriHalI2cBusEventDeinit) { + furi_check(osMutexDelete(furi_hal_i2c_bus_external_mutex) == osOK); + FURI_CRITICAL_ENTER(); + LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C3); + LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C3); + FURI_CRITICAL_EXIT(); + } else if(event == FuriHalI2cBusEventLock) { + furi_check(osMutexAcquire(furi_hal_i2c_bus_external_mutex, osWaitForever) == osOK); + } else if(event == FuriHalI2cBusEventUnlock) { + furi_check(osMutexRelease(furi_hal_i2c_bus_external_mutex) == osOK); + } else if(event == FuriHalI2cBusEventActivate) { FURI_CRITICAL_ENTER(); LL_RCC_SetI2CClockSource(LL_RCC_I2C3_CLKSOURCE_PCLK1); LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C3); diff --git a/firmware/targets/f7/furi_hal/furi_hal_info.c b/firmware/targets/f7/furi_hal/furi_hal_info.c index 893716db..77eab128 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_info.c +++ b/firmware/targets/f7/furi_hal/furi_hal_info.c @@ -50,22 +50,14 @@ void furi_hal_info_get(FuriHalInfoValueCallback out, void* context) { out("hardware_name", name, false, context); } - // Bootloader Version - const Version* bootloader_version = furi_hal_version_get_bootloader_version(); - if(bootloader_version) { - out("bootloader_commit", version_get_githash(bootloader_version), false, context); - out("bootloader_branch", version_get_gitbranch(bootloader_version), false, context); - out("bootloader_branch_num", version_get_gitbranchnum(bootloader_version), false, context); - out("bootloader_version", version_get_version(bootloader_version), false, context); - out("bootloader_build_date", version_get_builddate(bootloader_version), false, context); - string_printf(value, "%d", version_get_target(bootloader_version)); - out("bootloader_target", string_get_cstr(value), false, context); - } - // Firmware version const Version* firmware_version = furi_hal_version_get_firmware_version(); if(firmware_version) { out("firmware_commit", version_get_githash(firmware_version), false, context); + out("firmware_commit_dirty", + version_get_dirty_flag(firmware_version) ? "true" : "false", + false, + context); out("firmware_branch", version_get_gitbranch(firmware_version), false, context); out("firmware_branch_num", version_get_gitbranchnum(firmware_version), false, context); out("firmware_version", version_get_version(firmware_version), false, context); @@ -139,4 +131,4 @@ void furi_hal_info_get(FuriHalInfoValueCallback out, void* context) { out("protobuf_version_minor", string_get_cstr(value), true, context); string_clear(value); -} +} \ No newline at end of file diff --git a/firmware/targets/f7/furi_hal/furi_hal_interrupt.c b/firmware/targets/f7/furi_hal/furi_hal_interrupt.c index 5bee8067..e9fc023b 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_interrupt.c +++ b/firmware/targets/f7/furi_hal/furi_hal_interrupt.c @@ -253,7 +253,9 @@ void SysTick_Handler(void) { } void USB_LP_IRQHandler(void) { +#ifndef FURI_RAM_EXEC usbd_poll(&udev); +#endif } void IPCC_C1_TX_IRQHandler(void) { @@ -262,4 +264,4 @@ void IPCC_C1_TX_IRQHandler(void) { void IPCC_C1_RX_IRQHandler(void) { HW_IPCC_Rx_Handler(); -} +} \ No newline at end of file diff --git a/firmware/targets/f7/furi_hal/furi_hal_light.c b/firmware/targets/f7/furi_hal/furi_hal_light.c index 1bd1adad..864b3c6e 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_light.c +++ b/firmware/targets/f7/furi_hal/furi_hal_light.c @@ -1,4 +1,5 @@ #include +#include #include #define LED_CURRENT_RED 50 @@ -50,3 +51,30 @@ void furi_hal_light_set(Light light, uint8_t value) { } furi_hal_i2c_release(&furi_hal_i2c_handle_power); } + +void furi_hal_light_sequence(const char* sequence) { + do { + if(*sequence == 'R') { + furi_hal_light_set(LightRed, 0xFF); + } else if(*sequence == 'r') { + furi_hal_light_set(LightRed, 0x00); + } else if(*sequence == 'G') { + furi_hal_light_set(LightGreen, 0xFF); + } else if(*sequence == 'g') { + furi_hal_light_set(LightGreen, 0x00); + } else if(*sequence == 'B') { + furi_hal_light_set(LightBlue, 0xFF); + } else if(*sequence == 'b') { + furi_hal_light_set(LightBlue, 0x00); + } else if(*sequence == 'W') { + furi_hal_light_set(LightBacklight, 0xFF); + } else if(*sequence == 'w') { + furi_hal_light_set(LightBacklight, 0x00); + } else if(*sequence == '.') { + furi_hal_delay_ms(250); + } else if(*sequence == '-') { + furi_hal_delay_ms(500); + } + sequence++; + } while(*sequence != 0); +} diff --git a/firmware/targets/f7/furi_hal/furi_hal_resources.c b/firmware/targets/f7/furi_hal/furi_hal_resources.c index 734967b7..90195585 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_resources.c +++ b/firmware/targets/f7/furi_hal/furi_hal_resources.c @@ -56,6 +56,9 @@ const GpioPin gpio_speaker = {.port = GPIOB, .pin = LL_GPIO_PIN_8}; const GpioPin periph_power = {.port = PERIPH_POWER_GPIO_Port, .pin = PERIPH_POWER_Pin}; +const GpioPin gpio_usb_dm = {.port = GPIOA, .pin = LL_GPIO_PIN_11}; +const GpioPin gpio_usb_dp = {.port = GPIOA, .pin = LL_GPIO_PIN_12}; + const InputPin input_pins[] = { {.gpio = &gpio_button_up, .key = InputKeyUp, .inverted = true, .name = "Up"}, {.gpio = &gpio_button_down, .key = InputKeyDown, .inverted = true, .name = "Down"}, @@ -67,7 +70,22 @@ const InputPin input_pins[] = { const size_t input_pins_count = sizeof(input_pins) / sizeof(InputPin); -void furi_hal_resources_init(void) { +void furi_hal_resources_init_early() { + furi_hal_gpio_init(&gpio_button_left, GpioModeInput, GpioPullUp, GpioSpeedLow); + furi_hal_gpio_init_simple(&gpio_display_rst, GpioModeOutputPushPull); + furi_hal_gpio_init_simple(&gpio_display_di, GpioModeOutputPushPull); + + // Hard reset USB + furi_hal_gpio_init_simple(&gpio_usb_dm, GpioModeOutputOpenDrain); + furi_hal_gpio_init_simple(&gpio_usb_dp, GpioModeOutputOpenDrain); + furi_hal_gpio_write(&gpio_usb_dm, 0); + furi_hal_gpio_write(&gpio_usb_dp, 0); +} + +void furi_hal_resources_deinit_early() { +} + +void furi_hal_resources_init() { // Button pins for(size_t i = 0; i < input_pins_count; i++) { furi_hal_gpio_init( diff --git a/firmware/targets/f7/furi_hal/furi_hal_resources.h b/firmware/targets/f7/furi_hal/furi_hal_resources.h index 1f3a4bce..eaafd7c5 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_resources.h +++ b/firmware/targets/f7/furi_hal/furi_hal_resources.h @@ -54,6 +54,13 @@ extern const GpioPin gpio_sdcard_cs; extern const GpioPin gpio_sdcard_cd; extern const GpioPin gpio_nfc_cs; +extern const GpioPin gpio_button_up; +extern const GpioPin gpio_button_down; +extern const GpioPin gpio_button_right; +extern const GpioPin gpio_button_left; +extern const GpioPin gpio_button_ok; +extern const GpioPin gpio_button_back; + extern const GpioPin gpio_spi_d_miso; extern const GpioPin gpio_spi_d_mosi; extern const GpioPin gpio_spi_d_sck; @@ -87,6 +94,9 @@ extern const GpioPin gpio_speaker; extern const GpioPin periph_power; +extern const GpioPin gpio_usb_dm; +extern const GpioPin gpio_usb_dp; + #define BUTTON_BACK_GPIO_Port GPIOC #define BUTTON_BACK_Pin LL_GPIO_PIN_13 #define BUTTON_DOWN_GPIO_Port GPIOC @@ -193,7 +203,11 @@ extern const GpioPin periph_power; #define NFC_IRQ_Pin RFID_PULL_Pin #define NFC_IRQ_GPIO_Port RFID_PULL_GPIO_Port -void furi_hal_resources_init(void); +void furi_hal_resources_init_early(); + +void furi_hal_resources_deinit_early(); + +void furi_hal_resources_init(); #ifdef __cplusplus } diff --git a/firmware/targets/f7/furi_hal/furi_hal_rtc.c b/firmware/targets/f7/furi_hal/furi_hal_rtc.c index 33fc9307..748d7e41 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_rtc.c +++ b/firmware/targets/f7/furi_hal/furi_hal_rtc.c @@ -1,20 +1,84 @@ #include +#include + +#include +#include #include #include +#include #include #define TAG "FuriHalRtc" +#define RTC_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady()) + +#define FURI_HAL_RTC_HEADER_MAGIC 0x10F1 +#define FURI_HAL_RTC_HEADER_VERSION 0 + +typedef struct { + uint16_t magic; + uint8_t version; + uint8_t unused; +} FuriHalRtcHeader; + typedef struct { uint8_t log_level : 4; uint8_t log_reserved : 4; uint8_t flags; - uint16_t reserved; + uint8_t boot_mode : 4; + uint16_t reserved : 12; } DeveloperReg; _Static_assert(sizeof(DeveloperReg) == 4, "DeveloperReg size mismatch"); +void furi_hal_rtc_init_early() { + // LSE and RTC + LL_PWR_EnableBkUpAccess(); + if(!RTC_CLOCK_IS_READY()) { + // Start LSI1 needed for CSS + LL_RCC_LSI1_Enable(); + // Try to start LSE normal way + LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_HIGH); + LL_RCC_LSE_Enable(); + uint32_t c = 0; + while(!RTC_CLOCK_IS_READY() && c < 200) { + LL_mDelay(10); + c++; + } + // Plan B: reset backup domain + if(!RTC_CLOCK_IS_READY()) { + furi_hal_light_sequence("rgb R.r.R.r.R"); + LL_RCC_ForceBackupDomainReset(); + LL_RCC_ReleaseBackupDomainReset(); + NVIC_SystemReset(); + } + // Set RTC domain clock to LSE + LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE); + // Enable LSE CSS + LL_RCC_LSE_EnableCSS(); + } + // Enable clocking + LL_RCC_EnableRTC(); + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTCAPB); + + // Verify header register + uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterHeader); + FuriHalRtcHeader* data = (FuriHalRtcHeader*)&data_reg; + if(data->magic != FURI_HAL_RTC_HEADER_MAGIC || data->version != FURI_HAL_RTC_HEADER_VERSION) { + // Reset all our registers to ensure consistency + for(size_t i = 0; i < FuriHalRtcRegisterMAX; i++) { + furi_hal_rtc_set_register(i, 0); + } + data->magic = FURI_HAL_RTC_HEADER_MAGIC; + data->version = FURI_HAL_RTC_HEADER_VERSION; + furi_hal_rtc_set_register(FuriHalRtcRegisterHeader, data_reg); + } +} + +void furi_hal_rtc_deinit_early() { +} + void furi_hal_rtc_init() { if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE) { LL_RCC_ForceBackupDomainReset(); @@ -77,6 +141,19 @@ bool furi_hal_rtc_is_flag_set(FuriHalRtcFlag flag) { return data->flags & flag; } +void furi_hal_rtc_set_boot_mode(FuriHalRtcBootMode mode) { + uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem); + DeveloperReg* data = (DeveloperReg*)&data_reg; + data->boot_mode = mode; + furi_hal_rtc_set_register(FuriHalRtcRegisterSystem, data_reg); +} + +FuriHalRtcBootMode furi_hal_rtc_get_boot_mode() { + uint32_t data_reg = furi_hal_rtc_get_register(FuriHalRtcRegisterSystem); + DeveloperReg* data = (DeveloperReg*)&data_reg; + return (FuriHalRtcBootMode)data->boot_mode; +} + void furi_hal_rtc_set_datetime(FuriHalRtcDateTime* datetime) { furi_assert(datetime); diff --git a/firmware/targets/f7/furi_hal/furi_hal_spi.c b/firmware/targets/f7/furi_hal/furi_hal_spi.c index 8af2879f..d74a394a 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_spi.c +++ b/firmware/targets/f7/furi_hal/furi_hal_spi.c @@ -11,13 +11,21 @@ #define TAG "FuriHalSpi" +void furi_hal_spi_init_early() { + furi_hal_spi_bus_init(&furi_hal_spi_bus_d); + furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_display); +} + +void furi_hal_spi_deinit_early() { + furi_hal_spi_bus_handle_deinit(&furi_hal_spi_bus_handle_display); + furi_hal_spi_bus_deinit(&furi_hal_spi_bus_d); +} + void furi_hal_spi_init() { furi_hal_spi_bus_init(&furi_hal_spi_bus_r); - furi_hal_spi_bus_init(&furi_hal_spi_bus_d); furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_subghz); furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_nfc); - furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_display); furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_sd_fast); furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_sd_slow); diff --git a/firmware/targets/f7/furi_hal/furi_hal_spi_config.c b/firmware/targets/f7/furi_hal/furi_hal_spi_config.c index 440a64a0..0bdb2508 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_spi_config.c +++ b/firmware/targets/f7/furi_hal/furi_hal_spi_config.c @@ -80,7 +80,11 @@ static void furi_hal_spi_bus_r_event_callback(FuriHalSpiBus* bus, FuriHalSpiBusE FURI_CRITICAL_EXIT(); bus->current_handle = NULL; } else if(event == FuriHalSpiBusEventDeinit) { - furi_check(osMutexDelete(furi_hal_spi_bus_r_mutex)); + furi_check(osMutexDelete(furi_hal_spi_bus_r_mutex) == osOK); + FURI_CRITICAL_ENTER(); + LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_SPI1); + LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_SPI1); + FURI_CRITICAL_EXIT(); } else if(event == FuriHalSpiBusEventLock) { furi_check(osMutexAcquire(furi_hal_spi_bus_r_mutex, osWaitForever) == osOK); } else if(event == FuriHalSpiBusEventUnlock) { @@ -111,7 +115,11 @@ static void furi_hal_spi_bus_d_event_callback(FuriHalSpiBus* bus, FuriHalSpiBusE FURI_CRITICAL_EXIT(); bus->current_handle = NULL; } else if(event == FuriHalSpiBusEventDeinit) { - furi_check(osMutexDelete(furi_hal_spi_bus_d_mutex)); + furi_check(osMutexDelete(furi_hal_spi_bus_d_mutex) == osOK); + FURI_CRITICAL_ENTER(); + LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_SPI2); + LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_SPI2); + FURI_CRITICAL_EXIT(); } else if(event == FuriHalSpiBusEventLock) { furi_check(osMutexAcquire(furi_hal_spi_bus_d_mutex, osWaitForever) == osOK); } else if(event == FuriHalSpiBusEventUnlock) { diff --git a/firmware/targets/f7/furi_hal/furi_hal_vcp.c b/firmware/targets/f7/furi_hal/furi_hal_vcp.c index b0edf9db..5040deed 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_vcp.c +++ b/firmware/targets/f7/furi_hal/furi_hal_vcp.c @@ -64,6 +64,11 @@ void furi_hal_vcp_init() { vcp->tx_stream = xStreamBufferCreate(VCP_TX_BUF_SIZE, 1); vcp->rx_stream = xStreamBufferCreate(VCP_RX_BUF_SIZE, 1); + if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) { + FURI_LOG_W(TAG, "Skipped worker init: device in special startup mode="); + return; + } + vcp->thread = furi_thread_alloc(); furi_thread_set_name(vcp->thread, "VcpDriver"); furi_thread_set_stack_size(vcp->thread, 1024); diff --git a/firmware/targets/f7/furi_hal/furi_hal_version.c b/firmware/targets/f7/furi_hal/furi_hal_version.c index 821de05a..be92b348 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_version.c +++ b/firmware/targets/f7/furi_hal/furi_hal_version.c @@ -192,7 +192,7 @@ void furi_hal_version_init() { furi_crash(NULL); } - furi_hal_rtc_set_register(FuriHalRtcRegisterSystemVersion, (uint32_t)version_get()); + furi_hal_rtc_set_register(FuriHalRtcRegisterVersion, (uint32_t)version_get()); FURI_LOG_I(TAG, "Init OK"); } @@ -280,15 +280,6 @@ const struct Version* furi_hal_version_get_firmware_version(void) { return version_get(); } -const struct Version* furi_hal_version_get_bootloader_version(void) { -#ifdef NO_BOOTLOADER - return 0; -#else - /* Backup register which points to structure in flash memory */ - return (const struct Version*)furi_hal_rtc_get_register(FuriHalRtcRegisterBootVersion); -#endif -} - size_t furi_hal_version_uid_size() { return 64 / 8; } diff --git a/firmware/targets/f7/stm32wb55xx_flash_cm4_no_bootloader.ld b/firmware/targets/f7/stm32wb55xx_flash.ld similarity index 100% rename from firmware/targets/f7/stm32wb55xx_flash_cm4_no_bootloader.ld rename to firmware/targets/f7/stm32wb55xx_flash.ld diff --git a/firmware/targets/f7/stm32wb55xx_flash_cm4_with_bootloader.ld b/firmware/targets/f7/stm32wb55xx_ram_fw.ld similarity index 95% rename from firmware/targets/f7/stm32wb55xx_flash_cm4_with_bootloader.ld rename to firmware/targets/f7/stm32wb55xx_ram_fw.ld index e2a21716..8c4d41c5 100644 --- a/firmware/targets/f7/stm32wb55xx_flash_cm4_with_bootloader.ld +++ b/firmware/targets/f7/stm32wb55xx_ram_fw.ld @@ -55,8 +55,8 @@ _Min_Stack_Size = 0x1000; /* required amount of stack */ /* Specify the memory areas */ MEMORY { -FLASH (rx) : ORIGIN = 0x08008000, LENGTH = 992K -RAM1 (xrw) : ORIGIN = 0x20000008, LENGTH = 0x2FFF8 +FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K +RAM1 (xrw) : ORIGIN = 0x20000000, LENGTH = 0x30000 RAM_SHARED (xrw) : ORIGIN = 0x20030000, LENGTH = 10K } @@ -69,7 +69,7 @@ SECTIONS . = ALIGN(4); KEEP(*(.isr_vector)) /* Startup code */ . = ALIGN(4); - } >FLASH + } >RAM1 /* The program code and other data goes into FLASH */ .text : @@ -86,7 +86,7 @@ SECTIONS . = ALIGN(4); _etext = .; /* define a global symbols at end of code */ - } >FLASH + } >RAM1 /* Constant data goes into FLASH */ .rodata : @@ -95,35 +95,35 @@ SECTIONS *(.rodata) /* .rodata sections (constants, strings, etc.) */ *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ . = ALIGN(4); - } >FLASH + } >RAM1 .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH .ARM : { __exidx_start = .; *(.ARM.exidx*) __exidx_end = .; - } >FLASH + } >RAM1 .preinit_array : { PROVIDE_HIDDEN (__preinit_array_start = .); KEEP (*(.preinit_array*)) PROVIDE_HIDDEN (__preinit_array_end = .); - } >FLASH + } >RAM1 .init_array : { PROVIDE_HIDDEN (__init_array_start = .); KEEP (*(SORT(.init_array.*))) KEEP (*(.init_array*)) PROVIDE_HIDDEN (__init_array_end = .); - } >FLASH + } >RAM1 .fini_array : { PROVIDE_HIDDEN (__fini_array_start = .); KEEP (*(SORT(.fini_array.*))) KEEP (*(.fini_array*)) PROVIDE_HIDDEN (__fini_array_end = .); - } >FLASH + } >RAM1 /* used by the startup to initialize data */ _sidata = LOADADDR(.data); @@ -138,7 +138,7 @@ SECTIONS . = ALIGN(4); _edata = .; /* define a global symbol at data end */ - } >RAM1 AT> FLASH + } >RAM1 AT> RAM1 /* Uninitialized data section */ @@ -169,11 +169,11 @@ SECTIONS } >RAM1 /* Free Flash space, that can be used for internal storage */ - .free_flash(NOLOAD): + /*.free_flash(NOLOAD): { __free_flash_start__ = .; . = ORIGIN(FLASH) + LENGTH(FLASH); - } >FLASH + } >FLASH*/ /* Remove information from the standard libraries */ /DISCARD/ : diff --git a/firmware/targets/f7/target.mk b/firmware/targets/f7/target.mk index 6f010890..1822b628 100644 --- a/firmware/targets/f7/target.mk +++ b/firmware/targets/f7/target.mk @@ -1,17 +1,12 @@ TOOLCHAIN = arm -BOOT_ADDRESS = 0x08000000 -FW_ADDRESS = 0x08008000 -OS_OFFSET = 0x00008000 -FLASH_ADDRESS = 0x08008000 - -NO_BOOTLOADER ?= 0 -ifeq ($(NO_BOOTLOADER), 1) -BOOT_ADDRESS = 0x08000000 -FW_ADDRESS = 0x08000000 -OS_OFFSET = 0x00000000 FLASH_ADDRESS = 0x08000000 -CFLAGS += -DNO_BOOTLOADER + +RAM_EXEC ?= 0 +ifeq ($(RAM_EXEC), 1) +CFLAGS += -DFURI_RAM_EXEC -DVECT_TAB_SRAM -DFLIPPER_STREAM_LITE +else +LDFLAGS += -u _printf_float endif DEBUG_RTOS_THREADS ?= 1 @@ -21,11 +16,10 @@ else OPENOCD_OPTS = -f interface/stlink.cfg -c "transport select hla_swd" -f ../debug/stm32wbx.cfg -c "init" endif -BOOT_CFLAGS = -DBOOT_ADDRESS=$(BOOT_ADDRESS) -DFW_ADDRESS=$(FW_ADDRESS) -DOS_OFFSET=$(OS_OFFSET) MCU_FLAGS = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -CFLAGS += $(MCU_FLAGS) $(BOOT_CFLAGS) -DSTM32WB55xx -Wall -fdata-sections -ffunction-sections -LDFLAGS += $(MCU_FLAGS) -specs=nosys.specs -specs=nano.specs -u _printf_float +CFLAGS += $(MCU_FLAGS) -DSTM32WB55xx -Wall -fdata-sections -ffunction-sections +LDFLAGS += $(MCU_FLAGS) -specs=nosys.specs -specs=nano.specs CPPFLAGS += -fno-rtti -fno-use-cxa-atexit -fno-exceptions LDFLAGS += -Wl,--start-group -lstdc++ -lsupc++ -Wl,--end-group @@ -146,11 +140,11 @@ C_SOURCES += \ $(wildcard $(MXPROJECT_DIR)/Src/*.c) \ $(wildcard $(MXPROJECT_DIR)/fatfs/*.c) +ifeq ($(RAM_EXEC), 1) +LDFLAGS += -T$(MXPROJECT_DIR)/stm32wb55xx_ram_fw.ld +else # RAM_EXEC # Linker options -ifeq ($(NO_BOOTLOADER), 1) -LDFLAGS += -T$(MXPROJECT_DIR)/stm32wb55xx_flash_cm4_no_bootloader.ld -else -LDFLAGS += -T$(MXPROJECT_DIR)/stm32wb55xx_flash_cm4_with_bootloader.ld -endif +LDFLAGS += -T$(MXPROJECT_DIR)/stm32wb55xx_flash.ld +endif # RAM_EXEC SVD_FILE = ../debug/STM32WB55_CM4.svd diff --git a/firmware/targets/furi_hal_include/furi_hal.h b/firmware/targets/furi_hal_include/furi_hal.h index 59e9e89b..76e96ef6 100644 --- a/firmware/targets/furi_hal_include/furi_hal.h +++ b/firmware/targets/furi_hal_include/furi_hal.h @@ -9,7 +9,6 @@ template struct STOP_EXTERNING_ME {}; #endif -#include "furi_hal_bootloader.h" #include "furi_hal_clock.h" #include "furi_hal_crypto.h" #include "furi_hal_console.h" @@ -40,12 +39,27 @@ template struct STOP_EXTERNING_ME {}; #include "furi_hal_uart.h" #include "furi_hal_info.h" #include "furi_hal_random.h" +#include "furi_hal_crc.h" -/** Init furi_hal */ +#ifdef __cplusplus +extern "C" { +#endif + +/** Early FuriHal init, only essential subsystems */ +void furi_hal_init_early(); + +/** Early FuriHal deinit */ +void furi_hal_deinit_early(); + +/** Init FuriHal */ void furi_hal_init(); -/** - * Init critical parts of furi_hal - * That code should not use memory allocations +/** Transfer execution to address + * + * @param[in] address pointer to new executable */ -void furi_hal_init_critical(); +void furi_hal_switch(void* address); + +#ifdef __cplusplus +} +#endif diff --git a/firmware/targets/furi_hal_include/furi_hal_bootloader.h b/firmware/targets/furi_hal_include/furi_hal_bootloader.h deleted file mode 100644 index 51a9c4e8..00000000 --- a/firmware/targets/furi_hal_include/furi_hal_bootloader.h +++ /dev/null @@ -1,29 +0,0 @@ -/** - * @file furi_hal_bootloader.h - * Bootloader HAL API - */ - -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** Boot modes */ -typedef enum { FuriHalBootloaderModeNormal, FuriHalBootloaderModeDFU } FuriHalBootloaderMode; - -/** Initialize boot subsystem - */ -void furi_hal_bootloader_init(); - -/** Set bootloader mode - * - * @param[in] mode FuriHalBootloaderMode - */ -void furi_hal_bootloader_set_mode(FuriHalBootloaderMode mode); - -#ifdef __cplusplus -} -#endif diff --git a/firmware/targets/furi_hal_include/furi_hal_delay.h b/firmware/targets/furi_hal_include/furi_hal_delay.h index d0e216f8..58b4ed9b 100644 --- a/firmware/targets/furi_hal_include/furi_hal_delay.h +++ b/firmware/targets/furi_hal_include/furi_hal_delay.h @@ -6,16 +6,17 @@ #pragma once #include +#include #ifdef __cplusplus extern "C" { #endif -extern uint32_t instructions_per_us; +/** Init Delay subsystem */ +void furi_hal_delay_init(); -/** Init DWT - */ -void furi_hal_delay_init(void); +/** Get instructions per microsecond count */ +uint32_t furi_hal_delay_instructions_per_microsecond(); /** Increase tick counter. * Should be called from SysTick ISR diff --git a/firmware/targets/furi_hal_include/furi_hal_i2c.h b/firmware/targets/furi_hal_include/furi_hal_i2c.h index 5550ab08..566574ab 100644 --- a/firmware/targets/furi_hal_include/furi_hal_i2c.h +++ b/firmware/targets/furi_hal_include/furi_hal_i2c.h @@ -13,8 +13,13 @@ extern "C" { #endif -/** Init I2C - */ +/** Early Init I2C */ +void furi_hal_i2c_init_early(); + +/** Early DeInit I2C */ +void furi_hal_i2c_deinit_early(); + +/** Init I2C */ void furi_hal_i2c_init(); /** Acquire i2c bus handle diff --git a/firmware/targets/furi_hal_include/furi_hal_light.h b/firmware/targets/furi_hal_include/furi_hal_light.h index 569778d0..e3d244c3 100644 --- a/firmware/targets/furi_hal_include/furi_hal_light.h +++ b/firmware/targets/furi_hal_include/furi_hal_light.h @@ -24,6 +24,12 @@ void furi_hal_light_init(); */ void furi_hal_light_set(Light light, uint8_t value); +/** Execute sequence + * + * @param sequence Sequence to execute + */ +void furi_hal_light_sequence(const char* sequence); + #ifdef __cplusplus } #endif diff --git a/firmware/targets/furi_hal_include/furi_hal_rtc.h b/firmware/targets/furi_hal_include/furi_hal_rtc.h index e06978e1..5b6a7780 100644 --- a/firmware/targets/furi_hal_include/furi_hal_rtc.h +++ b/firmware/targets/furi_hal_include/furi_hal_rtc.h @@ -31,15 +31,32 @@ typedef enum { } FuriHalRtcFlag; typedef enum { - FuriHalRtcRegisterBoot, - FuriHalRtcRegisterBootVersion, - FuriHalRtcRegisterSystem, - FuriHalRtcRegisterSystemVersion, - FuriHalRtcRegisterLfsFingerprint, - FuriHalRtcRegisterFaultData, - FuriHalRtcRegisterPinFails, + FuriHalRtcBootModeNormal = 0, /**< Normal boot mode, default value */ + FuriHalRtcBootModeDfu, /**< Boot to DFU (MCU bootloader by ST) */ + FuriHalRtcBootModePreUpdate, /**< Boot to Update, pre update */ + FuriHalRtcBootModeUpdate, /**< Boot to Update, main */ + FuriHalRtcBootModePostUpdate, /**< Boot to Update, post update */ +} FuriHalRtcBootMode; + +typedef enum { + FuriHalRtcRegisterHeader, /**< RTC structure header */ + FuriHalRtcRegisterSystem, /**< Various system bits */ + FuriHalRtcRegisterVersion, /**< Pointer to Version */ + FuriHalRtcRegisterLfsFingerprint, /**< LFS geometry fingerprint */ + FuriHalRtcRegisterFaultData, /**< Pointer to last fault message */ + FuriHalRtcRegisterPinFails, /**< Failed pins count */ + /* Index of FS directory entry corresponding to FW update to be applied */ + FuriHalRtcRegisterUpdateFolderFSIndex, + + FuriHalRtcRegisterMAX, /**< Service value, do not use */ } FuriHalRtcRegister; +/** Early initialization */ +void furi_hal_rtc_init_early(); + +/** Early deinitialization */ +void furi_hal_rtc_deinit_early(); + /** Initialize RTC subsystem */ void furi_hal_rtc_init(); @@ -57,6 +74,10 @@ void furi_hal_rtc_reset_flag(FuriHalRtcFlag flag); bool furi_hal_rtc_is_flag_set(FuriHalRtcFlag flag); +void furi_hal_rtc_set_boot_mode(FuriHalRtcBootMode mode); + +FuriHalRtcBootMode furi_hal_rtc_get_boot_mode(); + void furi_hal_rtc_set_datetime(FuriHalRtcDateTime* datetime); void furi_hal_rtc_get_datetime(FuriHalRtcDateTime* datetime); diff --git a/firmware/targets/furi_hal_include/furi_hal_spi.h b/firmware/targets/furi_hal_include/furi_hal_spi.h index be31727f..df7ffa93 100644 --- a/firmware/targets/furi_hal_include/furi_hal_spi.h +++ b/firmware/targets/furi_hal_include/furi_hal_spi.h @@ -7,6 +7,12 @@ extern "C" { #endif +/** Early initialize SPI HAL */ +void furi_hal_spi_init_early(); + +/** Early deinitialize SPI HAL */ +void furi_hal_spi_deinit_early(); + /** Initialize SPI HAL */ void furi_hal_spi_init(); @@ -99,4 +105,4 @@ bool furi_hal_spi_bus_trx( #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/firmware/targets/furi_hal_include/furi_hal_version.h b/firmware/targets/furi_hal_include/furi_hal_version.h index 62f0147f..f174ade8 100644 --- a/firmware/targets/furi_hal_include/furi_hal_version.h +++ b/firmware/targets/furi_hal_include/furi_hal_version.h @@ -70,55 +70,55 @@ const char* furi_hal_version_get_model_name(); * * @return OTP Version */ -const FuriHalVersionOtpVersion furi_hal_version_get_otp_version(); +FuriHalVersionOtpVersion furi_hal_version_get_otp_version(); /** Get hardware version * * @return Hardware Version */ -const uint8_t furi_hal_version_get_hw_version(); +uint8_t furi_hal_version_get_hw_version(); /** Get hardware target * * @return Hardware Target */ -const uint8_t furi_hal_version_get_hw_target(); +uint8_t furi_hal_version_get_hw_target(); /** Get hardware body * * @return Hardware Body */ -const uint8_t furi_hal_version_get_hw_body(); +uint8_t furi_hal_version_get_hw_body(); /** Get hardware body color * * @return Hardware Color */ -const FuriHalVersionColor furi_hal_version_get_hw_color(); +FuriHalVersionColor furi_hal_version_get_hw_color(); /** Get hardware connect * * @return Hardware Interconnect */ -const uint8_t furi_hal_version_get_hw_connect(); +uint8_t furi_hal_version_get_hw_connect(); /** Get hardware region * * @return Hardware Region */ -const FuriHalVersionRegion furi_hal_version_get_hw_region(); +FuriHalVersionRegion furi_hal_version_get_hw_region(); /** Get hardware display id * * @return Display id */ -const FuriHalVersionDisplay furi_hal_version_get_hw_display(); +FuriHalVersionDisplay furi_hal_version_get_hw_display(); /** Get hardware timestamp * * @return Hardware Manufacture timestamp */ -const uint32_t furi_hal_version_get_hw_timestamp(); +uint32_t furi_hal_version_get_hw_timestamp(); /** Get pointer to target name * @@ -144,12 +144,6 @@ const char* furi_hal_version_get_ble_local_device_name_ptr(); */ const uint8_t* furi_hal_version_get_ble_mac(); -/** Get address of version structure of bootloader, stored in chip flash. - * - * @return Address of boot version structure. - */ -const struct Version* furi_hal_version_get_bootloader_version(); - /** Get address of version structure of firmware. * * @return Address of firmware version structure. diff --git a/lib/ReadMe.md b/lib/ReadMe.md index 89a09f41..0bdf3d63 100644 --- a/lib/ReadMe.md +++ b/lib/ReadMe.md @@ -3,20 +3,20 @@ - `app-scened-template` - Scened template app library - `app-template` - Template app library - `callback-connector` - Callback connector library -- `common-api` - Common api declaration library -- `cyfral` - Cyfral library - `drivers` - Drivers that we wrote - `fatfs` - External storage file system -- `flipper_file` - Flipper File Format library +- `flipper_format` - Flipper File Format library - `fnv1a-hash` - Fnv1a hash library +- `heatshrink` - Image compression library - `infrared` - Infrared library - `libusb_stm32` - STM32 USB library - `littlefs` - Internal storage file system -- `micro-ecc` - Elyptic Curve Crpytography library +- `micro-ecc` - Elliptic Curve Crpytography library +- `microtar` - TAR archive support library - `mlib` - Algorithms and containers - `nanopb` - Nano Protobuf library - `nfc_protocols` - Nfc protocols library -- `onewire` - One wire library +- `one_wire` - One wire library - `qrcode` - Qr code generator library - `ST25RFAL002` - ST253916 driver and NFC hal - `STM32CubeWB` - STM32WB series cube package diff --git a/lib/flipper_format/flipper_format_stream.c b/lib/flipper_format/flipper_format_stream.c index bc12cd17..b3a08590 100644 --- a/lib/flipper_format/flipper_format_stream.c +++ b/lib/flipper_format/flipper_format_stream.c @@ -273,10 +273,12 @@ bool flipper_format_stream_write_value_line(Stream* stream, FlipperStreamWriteDa const uint8_t* data = write_data->data; string_printf(value, "%02X", data[i]); }; break; +#ifndef FLIPPER_STREAM_LITE case FlipperStreamValueFloat: { const float* data = write_data->data; string_printf(value, "%f", data[i]); }; break; +#endif case FlipperStreamValueInt32: { const int32_t* data = write_data->data; string_printf(value, "%" PRIi32, data[i]); @@ -357,6 +359,7 @@ bool flipper_format_stream_read_value_line( } } }; break; +#ifndef FLIPPER_STREAM_LITE case FlipperStreamValueFloat: { float* data = _data; // newlib-nano does not have sscanf for floats @@ -368,6 +371,7 @@ bool flipper_format_stream_read_value_line( scan_values = 1; } }; break; +#endif case FlipperStreamValueInt32: { int32_t* data = _data; scan_values = sscanf(string_get_cstr(value), "%" PRIi32, &data[i]); @@ -503,4 +507,4 @@ bool flipper_format_stream_write_comment_cstr(Stream* stream, const char* data) } while(false); return result; -} +} \ No newline at end of file diff --git a/lib/lib.mk b/lib/lib.mk index 7d221331..c1ee2cc0 100644 --- a/lib/lib.mk +++ b/lib/lib.mk @@ -123,3 +123,10 @@ C_SOURCES += $(wildcard $(LIB_DIR)/micro-ecc/*.c) C_SOURCES += $(wildcard $(LIB_DIR)/one_wire/*.c) C_SOURCES += $(wildcard $(LIB_DIR)/one_wire/*/*.c) C_SOURCES += $(wildcard $(LIB_DIR)/one_wire/*/*/*.c) + +# microtar +CFLAGS += -I$(LIB_DIR)/microtar/src +C_SOURCES += $(wildcard $(LIB_DIR)/microtar/src/*.c) + +# Update-related common code +C_SOURCES += $(wildcard $(LIB_DIR)/update_util/*.c) diff --git a/lib/microtar b/lib/microtar new file mode 160000 index 00000000..1e921369 --- /dev/null +++ b/lib/microtar @@ -0,0 +1 @@ +Subproject commit 1e921369b2c92bb219fcef84a37d4d2347794c0f diff --git a/lib/one_wire/ibutton/encoder/encoder_cyfral.c b/lib/one_wire/ibutton/encoder/encoder_cyfral.c index 717bf898..f6cbe630 100644 --- a/lib/one_wire/ibutton/encoder/encoder_cyfral.c +++ b/lib/one_wire/ibutton/encoder/encoder_cyfral.c @@ -2,7 +2,7 @@ #include #define CYFRAL_DATA_SIZE sizeof(uint16_t) -#define CYFRAL_PERIOD (125 * instructions_per_us) +#define CYFRAL_PERIOD (125 * furi_hal_delay_instructions_per_microsecond()) #define CYFRAL_0_LOW (CYFRAL_PERIOD * 0.66f) #define CYFRAL_0_HI (CYFRAL_PERIOD * 0.33f) #define CYFRAL_1_LOW (CYFRAL_PERIOD * 0.33f) diff --git a/lib/one_wire/ibutton/encoder/encoder_metakom.c b/lib/one_wire/ibutton/encoder/encoder_metakom.c index ea2a28f0..3b597e7c 100644 --- a/lib/one_wire/ibutton/encoder/encoder_metakom.c +++ b/lib/one_wire/ibutton/encoder/encoder_metakom.c @@ -2,7 +2,7 @@ #include #define METAKOM_DATA_SIZE sizeof(uint32_t) -#define METAKOM_PERIOD (125 * instructions_per_us) +#define METAKOM_PERIOD (125 * furi_hal_delay_instructions_per_microsecond()) #define METAKOM_0_LOW (METAKOM_PERIOD * 0.33f) #define METAKOM_0_HI (METAKOM_PERIOD * 0.66f) #define METAKOM_1_LOW (METAKOM_PERIOD * 0.66f) diff --git a/lib/one_wire/ibutton/pulse_protocols/protocol_cyfral.c b/lib/one_wire/ibutton/pulse_protocols/protocol_cyfral.c index 09635edf..a992f00d 100644 --- a/lib/one_wire/ibutton/pulse_protocols/protocol_cyfral.c +++ b/lib/one_wire/ibutton/pulse_protocols/protocol_cyfral.c @@ -104,7 +104,7 @@ static void cyfral_reset(void* context) { cyfral->nibble = 0; cyfral->data_valid = true; - cyfral->max_period = CYFRAL_MAX_PERIOD_US * instructions_per_us; + cyfral->max_period = CYFRAL_MAX_PERIOD_US * furi_hal_delay_instructions_per_microsecond(); } static bool cyfral_process_bit( diff --git a/lib/one_wire/one_wire_slave.c b/lib/one_wire/one_wire_slave.c index 4e385e9e..e8cc5ac1 100644 --- a/lib/one_wire/one_wire_slave.c +++ b/lib/one_wire/one_wire_slave.c @@ -38,14 +38,14 @@ struct OneWireSlave { uint32_t onewire_slave_wait_while_gpio_is(OneWireSlave* bus, uint32_t time, const bool pin_value) { uint32_t start = DWT->CYCCNT; - uint32_t time_ticks = time * instructions_per_us; + uint32_t time_ticks = time * furi_hal_delay_instructions_per_microsecond(); uint32_t time_captured; do { time_captured = DWT->CYCCNT; if(furi_hal_ibutton_pin_get_level() != pin_value) { uint32_t remaining_time = time_ticks - (time_captured - start); - remaining_time /= instructions_per_us; + remaining_time /= furi_hal_delay_instructions_per_microsecond(); return remaining_time; } } while((time_captured - start) < time_ticks); @@ -211,7 +211,7 @@ static void exti_cb(void* context) { static uint32_t pulse_start = 0; if(input_state) { - uint32_t pulse_length = (DWT->CYCCNT - pulse_start) / instructions_per_us; + uint32_t pulse_length = (DWT->CYCCNT - pulse_start) / furi_hal_delay_instructions_per_microsecond(); if(pulse_length >= OWS_RESET_MIN) { if(pulse_length <= OWS_RESET_MAX) { // reset cycle ok diff --git a/lib/subghz/subghz_keystore.c b/lib/subghz/subghz_keystore.c index af953f95..1acb6ba5 100644 --- a/lib/subghz/subghz_keystore.c +++ b/lib/subghz/subghz_keystore.c @@ -85,7 +85,7 @@ static void subghz_keystore_mess_with_iv(uint8_t* iv) { // Sharing them will bring some discomfort to legal owners // And potential legal action against you // While you reading this code think about your own personal responsibility - asm volatile("nani: \n" + asm volatile("nani%=: \n" "ldrd r0, r2, [%0, #0x0] \n" "lsl r1, r0, #8 \n" "lsl r3, r2, #8 \n" @@ -601,4 +601,4 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t* string_clear(str_temp); return result; -} +} \ No newline at end of file diff --git a/lib/toolbox/path.c b/lib/toolbox/path.c index 07318801..4fd042e4 100644 --- a/lib/toolbox/path.c +++ b/lib/toolbox/path.c @@ -18,3 +18,43 @@ void path_extract_filename_no_ext(const char* path, string_t filename) { string_mid(filename, start_position, end_position - start_position); } + +static inline void path_cleanup(string_t path) { + string_strim(path); + while(string_end_with_str_p(path, "/")) { + string_left(path, string_size(path) - 1); + } +} + +void path_extract_basename(const char* path, string_t basename) { + string_set(basename, path); + path_cleanup(basename); + size_t pos = string_search_rchar(basename, '/'); + if(pos != STRING_FAILURE) { + string_right(basename, pos); + } +} + +void path_extract_dirname(const char* path, string_t dirname) { + string_set(dirname, path); + path_cleanup(dirname); + size_t pos = string_search_rchar(dirname, '/'); + if(pos != STRING_FAILURE) { + string_left(dirname, pos); + } +} + +void path_append(string_t path, const char* suffix) { + path_cleanup(path); + string_t suffix_str; + string_init_set(suffix_str, suffix); + string_strim(suffix_str); + string_strim(suffix_str, "/"); + string_cat_printf(path, "/%s", string_get_cstr(suffix_str)); + string_clear(suffix_str); +} + +void path_concat(const char* path, const char* suffix, string_t out_path) { + string_set(out_path, path); + path_append(out_path, suffix); +} diff --git a/lib/toolbox/path.h b/lib/toolbox/path.h index da9b703d..0de63bb2 100644 --- a/lib/toolbox/path.h +++ b/lib/toolbox/path.h @@ -14,6 +14,39 @@ extern "C" { */ void path_extract_filename_no_ext(const char* path, string_t filename); +/** + * @brief Extract last path component + * + * @param path path string + * @param filename output string. Must be initialized before. + */ +void path_extract_basename(const char* path, string_t basename); + +/** + * @brief Extract path, except for last component + * + * @param path path string + * @param filename output string. Must be initialized before. + */ +void path_extract_dirname(const char* path, string_t dirname); + +/** + * @brief Appends new component to path, adding path delimiter + * + * @param path path string + * @param suffix path part to apply + */ +void path_append(string_t path, const char* suffix); + +/** + * @brief Appends new component to path, adding path delimiter + * + * @param path first path part + * @param suffix second path part + * @param out_path output string to combine parts into. Must be initialized + */ +void path_concat(const char* path, const char* suffix, string_t out_path); + #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/toolbox/tar/tar_archive.c b/lib/toolbox/tar/tar_archive.c new file mode 100644 index 00000000..7be68bd8 --- /dev/null +++ b/lib/toolbox/tar/tar_archive.c @@ -0,0 +1,306 @@ +#include "tar_archive.h" + +#include +#include +#include +#include + +#define TAG "TarArch" +#define MAX_NAME_LEN 255 +#define FILE_BLOCK_SIZE 512 + +#define FILE_OPEN_NTRIES 10 +#define FILE_OPEN_RETRY_DELAY 25 + +typedef struct TarArchive { + Storage* storage; + mtar_t tar; +} TarArchive; + +/* API WRAPPER */ +static int mtar_storage_file_write(void* stream, const void* data, unsigned size) { + uint16_t bytes_written = storage_file_write(stream, data, size); + return (bytes_written == size) ? bytes_written : MTAR_EWRITEFAIL; +} + +static int mtar_storage_file_read(void* stream, void* data, unsigned size) { + uint16_t bytes_read = storage_file_read(stream, data, size); + return (bytes_read == size) ? bytes_read : MTAR_EREADFAIL; +} + +static int mtar_storage_file_seek(void* stream, unsigned offset) { + bool res = storage_file_seek(stream, offset, true); + return res ? MTAR_ESUCCESS : MTAR_ESEEKFAIL; +} + +static int mtar_storage_file_close(void* stream) { + if(stream) { + storage_file_close(stream); + } + return MTAR_ESUCCESS; +} + +const struct mtar_ops filesystem_ops = { + .read = mtar_storage_file_read, + .write = mtar_storage_file_write, + .seek = mtar_storage_file_seek, + .close = mtar_storage_file_close, +}; + +TarArchive* tar_archive_alloc(Storage* storage) { + furi_check(storage); + TarArchive* archive = malloc(sizeof(TarArchive)); + archive->storage = storage; + return archive; +} + +bool tar_archive_open(TarArchive* archive, const char* path, TarOpenMode mode) { + furi_assert(archive); + FS_AccessMode access_mode; + FS_OpenMode open_mode; + int mtar_access = 0; + + switch(mode) { + case TAR_OPEN_MODE_READ: + mtar_access = MTAR_READ; + access_mode = FSAM_READ; + open_mode = FSOM_OPEN_EXISTING; + break; + case TAR_OPEN_MODE_WRITE: + mtar_access = MTAR_WRITE; + access_mode = FSAM_WRITE; + open_mode = FSOM_CREATE_ALWAYS; + break; + default: + return false; + } + + File* stream = storage_file_alloc(archive->storage); + if(!storage_file_open(stream, path, access_mode, open_mode)) { + storage_file_free(stream); + return false; + } + mtar_init(&archive->tar, mtar_access, &filesystem_ops, stream); + + return true; +} + +void tar_archive_free(TarArchive* archive) { + furi_assert(archive); + if(mtar_is_open(&archive->tar)) { + mtar_close(&archive->tar); + } +} + +bool tar_archive_dir_add_element(TarArchive* archive, const char* dirpath) { + furi_assert(archive); + return (mtar_write_dir_header(&archive->tar, dirpath) == MTAR_ESUCCESS); +} + +bool tar_archive_finalize(TarArchive* archive) { + furi_assert(archive); + return (mtar_finalize(&archive->tar) == MTAR_ESUCCESS); +} + +bool tar_archive_store_data( + TarArchive* archive, + const char* path, + const uint8_t* data, + const int32_t data_len) { + furi_assert(archive); + + return ( + tar_archive_file_add_header(archive, path, data_len) && + tar_archive_file_add_data_block(archive, data, data_len) && + tar_archive_file_finalize(archive)); +} + +bool tar_archive_file_add_header(TarArchive* archive, const char* path, const int32_t data_len) { + furi_assert(archive); + + return (mtar_write_file_header(&archive->tar, path, data_len) == MTAR_ESUCCESS); +} + +bool tar_archive_file_add_data_block( + TarArchive* archive, + const uint8_t* data_block, + const int32_t block_len) { + furi_assert(archive); + + return (mtar_write_data(&archive->tar, data_block, block_len) == block_len); +} + +bool tar_archive_file_finalize(TarArchive* archive) { + furi_assert(archive); + return (mtar_end_data(&archive->tar) == MTAR_ESUCCESS); +} + +typedef struct { + TarArchive* archive; + const char* work_dir; +} TarArchiveDirectoryOpParams; + +static int archive_extract_foreach_cb(mtar_t* tar, const mtar_header_t* header, void* param) { + TarArchiveDirectoryOpParams* op_params = param; + string_t fname; + + if(header->type == MTAR_TDIR) { + string_init(fname); + path_concat(op_params->work_dir, header->name, fname); + + bool create_res = + storage_simply_mkdir(op_params->archive->storage, string_get_cstr(fname)); + string_clear(fname); + return create_res ? 0 : -1; + } + + if(header->type != MTAR_TREG) { + FURI_LOG_W(TAG, "not extracting unsupported type \"%s\"", header->name); + return 0; + } + + string_init(fname); + path_concat(op_params->work_dir, header->name, fname); + FURI_LOG_I(TAG, "Extracting %d bytes to '%s'", header->size, header->name); + File* out_file = storage_file_alloc(op_params->archive->storage); + uint8_t* readbuf = malloc(FILE_BLOCK_SIZE); + + bool failed = false; + uint8_t n_tries = FILE_OPEN_NTRIES; + do { + while( + (n_tries-- > 0) && + !storage_file_open(out_file, string_get_cstr(fname), FSAM_WRITE, FSOM_CREATE_ALWAYS)) { + FURI_LOG_W(TAG, "Failed to open '%s', reties: %d", string_get_cstr(fname), n_tries); + osDelay(FILE_OPEN_RETRY_DELAY); + continue; + } + + if(!storage_file_is_open(out_file)) { + failed = true; + break; + } + + while(!mtar_eof_data(tar)) { + int32_t readcnt = mtar_read_data(tar, readbuf, FILE_BLOCK_SIZE); + if(!readcnt || !storage_file_write(out_file, readbuf, readcnt)) { + failed = true; + break; + } + } + } while(false); + + storage_file_free(out_file); + free(readbuf); + string_clear(fname); + return failed ? -1 : 0; +} + +bool tar_archive_unpack_to(TarArchive* archive, const char* destination) { + furi_assert(archive); + TarArchiveDirectoryOpParams param = { + .archive = archive, + .work_dir = destination, + }; + + FURI_LOG_I(TAG, "Restoring '%s'", destination); + + return (mtar_foreach(&archive->tar, archive_extract_foreach_cb, ¶m) == MTAR_ESUCCESS); +}; + +bool tar_archive_add_file( + TarArchive* archive, + const char* fs_file_path, + const char* archive_fname, + const int32_t file_size) { + furi_assert(archive); + uint8_t* file_buffer = malloc(FILE_BLOCK_SIZE); + bool success = false; + File* src_file = storage_file_alloc(archive->storage); + uint8_t n_tries = FILE_OPEN_NTRIES; + do { + while((n_tries-- > 0) && + !storage_file_open(src_file, fs_file_path, FSAM_READ, FSOM_OPEN_EXISTING)) { + FURI_LOG_W(TAG, "Failed to open '%s', reties: %d", fs_file_path, n_tries); + osDelay(FILE_OPEN_RETRY_DELAY); + continue; + } + + if(!storage_file_is_open(src_file) || + !tar_archive_file_add_header(archive, archive_fname, file_size)) { + break; + } + + uint16_t bytes_read = 0; + while((bytes_read = storage_file_read(src_file, file_buffer, FILE_BLOCK_SIZE))) { + success = tar_archive_file_add_data_block(archive, file_buffer, bytes_read); + if(!success) { + break; + } + } + + success = success && tar_archive_file_finalize(archive); + } while(false); + + storage_file_free(src_file); + free(file_buffer); + return success; +} + +bool tar_archive_add_dir(TarArchive* archive, const char* fs_full_path, const char* path_prefix) { + furi_assert(archive); + furi_check(path_prefix); + File* directory = storage_file_alloc(archive->storage); + FileInfo file_info; + + FURI_LOG_I(TAG, "Backing up '%s', '%s'", fs_full_path, path_prefix); + char* name = malloc(MAX_NAME_LEN); + bool success = false; + + do { + if(!storage_dir_open(directory, fs_full_path)) { + break; + } + + while(true) { + if(!storage_dir_read(directory, &file_info, name, MAX_NAME_LEN)) { + success = true; /* empty dir / no more files */ + break; + } + + string_t element_name, element_fs_abs_path; + string_init(element_name); + string_init(element_fs_abs_path); + path_concat(fs_full_path, name, element_fs_abs_path); + if(strlen(path_prefix)) { + path_concat(path_prefix, name, element_name); + } else { + string_init_set(element_name, name); + } + + if(file_info.flags & FSF_DIRECTORY) { + success = tar_archive_dir_add_element(archive, string_get_cstr(element_name)) && + tar_archive_add_dir( + archive, + string_get_cstr(element_fs_abs_path), + string_get_cstr(element_name)); + } else { + success = tar_archive_add_file( + archive, + string_get_cstr(element_fs_abs_path), + string_get_cstr(element_name), + file_info.size); + } + string_clear(element_name); + string_clear(element_fs_abs_path); + + if(!success) { + break; + } + } + } while(false); + + free(name); + storage_file_free(directory); + return success; +} \ No newline at end of file diff --git a/lib/toolbox/tar/tar_archive.h b/lib/toolbox/tar/tar_archive.h new file mode 100644 index 00000000..fe3e248e --- /dev/null +++ b/lib/toolbox/tar/tar_archive.h @@ -0,0 +1,59 @@ +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct TarArchive TarArchive; + +typedef struct Storage Storage; + +typedef enum { + TAR_OPEN_MODE_READ = 'r', + TAR_OPEN_MODE_WRITE = 'w', + TAR_OPEN_MODE_STDOUT = 's' /* to be implemented */ +} TarOpenMode; + +TarArchive* tar_archive_alloc(Storage* storage); + +bool tar_archive_open(TarArchive* archive, const char* path, TarOpenMode mode); + +void tar_archive_free(TarArchive* archive); + +/* High-level API - assumes archive is open */ +bool tar_archive_unpack_to(TarArchive* archive, const char* destination); + +bool tar_archive_add_file( + TarArchive* archive, + const char* fs_file_path, + const char* archive_fname, + const int32_t file_size); + +bool tar_archive_add_dir(TarArchive* archive, const char* fs_full_path, const char* path_prefix); + +/* Low-level API */ +bool tar_archive_dir_add_element(TarArchive* archive, const char* dirpath); + +bool tar_archive_file_add_header(TarArchive* archive, const char* path, const int32_t data_len); + +bool tar_archive_file_add_data_block( + TarArchive* archive, + const uint8_t* data_block, + const int32_t block_len); + +bool tar_archive_file_finalize(TarArchive* archive); + +bool tar_archive_store_data( + TarArchive* archive, + const char* path, + const uint8_t* data, + const int32_t data_len); + +bool tar_archive_finalize(TarArchive* archive); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/lib/toolbox/version.c b/lib/toolbox/version.c index ddf8e7ef..902be876 100644 --- a/lib/toolbox/version.c +++ b/lib/toolbox/version.c @@ -7,6 +7,7 @@ struct Version { const char* build_date; const char* version; const uint8_t target; + const bool build_is_dirty; }; /* version of current running firmware (bootloader/flipper) */ @@ -15,8 +16,13 @@ static const Version version = { .git_branch = GIT_BRANCH, .git_branch_num = GIT_BRANCH_NUM, .build_date = BUILD_DATE, - .version = VERSION, + .version = VERSION +#ifdef FURI_RAM_EXEC + " (RAM)" +#endif + , .target = TARGET, + .build_is_dirty = BUILD_DIRTY, }; const Version* version_get(void) { @@ -43,6 +49,10 @@ const char* version_get_version(const Version* v) { return v ? v->version : version.version; } -const uint8_t version_get_target(const Version* v) { +uint8_t version_get_target(const Version* v) { return v ? v->target : version.target; } + +bool version_get_dirty_flag(const Version* v) { + return v ? v->build_is_dirty : version.build_is_dirty; +} \ No newline at end of file diff --git a/lib/toolbox/version.h b/lib/toolbox/version.h index 545358a5..7e82e45d 100644 --- a/lib/toolbox/version.h +++ b/lib/toolbox/version.h @@ -1,6 +1,7 @@ #pragma once #include +#include #ifdef __cplusplus extern "C" { @@ -70,8 +71,17 @@ const char* version_get_version(const Version* v); * * @return build date */ -const uint8_t version_get_target(const Version* v); +uint8_t version_get_target(const Version* v); + +/** Get flag indicating if this build is "dirty" (source code had uncommited changes) + * + * @param v pointer to Version data. NULL for currently running + * software. + * + * @return build date + */ +bool version_get_dirty_flag(const Version* v); #ifdef __cplusplus } -#endif +#endif \ No newline at end of file diff --git a/lib/update_util/dfu_file.c b/lib/update_util/dfu_file.c new file mode 100644 index 00000000..2fcf95ac --- /dev/null +++ b/lib/update_util/dfu_file.c @@ -0,0 +1,183 @@ +#include "dfu_file.h" +#include + +#define VALID_WHOLE_FILE_CRC 0xFFFFFFFF +#define DFU_SUFFIX_VERSION 0x011A +#define DFU_DATA_BUFFER_MAX_LEN 512 +#define DFU_SIGNATURE "DfuSe" + +bool dfu_file_validate_crc(File* dfuf, const DfuPageTaskProgressCb progress_cb, void* context) { + if(!storage_file_is_open(dfuf) || !storage_file_seek(dfuf, 0, true)) { + return false; + } + + furi_hal_crc_reset(); + + uint32_t file_crc = 0; + + uint8_t* data_buffer = malloc(DFU_DATA_BUFFER_MAX_LEN); + uint16_t data_buffer_valid_len; + + uint32_t file_size = storage_file_size(dfuf); + + /* Feed file contents per sector into CRC calc */ + furi_hal_crc_acquire(osWaitForever); + for(uint32_t fptr = 0; fptr < file_size;) { + data_buffer_valid_len = storage_file_read(dfuf, data_buffer, DFU_DATA_BUFFER_MAX_LEN); + if(data_buffer_valid_len == 0) { + break; + } + fptr += data_buffer_valid_len; + + if((fptr % DFU_DATA_BUFFER_MAX_LEN == 0)) { + progress_cb(fptr * 100 / file_size, context); + } + + file_crc = furi_hal_crc_feed(data_buffer, data_buffer_valid_len); + } + furi_hal_crc_reset(); + free(data_buffer); + + /* Last 4 bytes of DFU file = CRC of previous file contents, inverted + * If we calculate whole file CRC32, incl. embedded CRC, + * that should give us 0xFFFFFFFF + */ + return file_crc == VALID_WHOLE_FILE_CRC; +} + +uint8_t dfu_file_validate_headers(File* dfuf, const DfuValidationParams* reference_params) { + furi_assert(reference_params); + + DfuPrefix dfu_prefix = {0}; + DfuSuffix dfu_suffix = {0}; + uint16_t bytes_read = 0; + + if(!storage_file_is_open(dfuf) || !storage_file_seek(dfuf, 0, true)) { + return 0; + } + + const uint32_t dfu_suffix_offset = storage_file_size(dfuf) - sizeof(DfuSuffix); + + bytes_read = storage_file_read(dfuf, &dfu_prefix, sizeof(DfuPrefix)); + if(bytes_read != sizeof(DfuPrefix)) { + return 0; + } + + if(memcmp(dfu_prefix.szSignature, DFU_SIGNATURE, sizeof(dfu_prefix.szSignature))) { + return 0; + } + + if((dfu_prefix.bVersion != 1) || (dfu_prefix.DFUImageSize != dfu_suffix_offset)) { + return 0; + } + + if(!storage_file_seek(dfuf, dfu_suffix_offset, true)) { + return 0; + } + + bytes_read = storage_file_read(dfuf, &dfu_suffix, sizeof(DfuSuffix)); + if(bytes_read != sizeof(DfuSuffix)) { + return 0; + } + + if((dfu_suffix.bLength != sizeof(DfuSuffix)) || (dfu_suffix.bcdDFU != DFU_SUFFIX_VERSION)) { + return 0; + } + /* TODO: check DfuSignature?.. */ + + if((dfu_suffix.idVendor != reference_params->vendor) || + (dfu_suffix.idProduct != reference_params->product) || + (dfu_suffix.bcdDevice != reference_params->device)) { + return 0; + } + + return dfu_prefix.bTargets; +} + +/* Assumes file is open, valid and read pointer is set at the start of image data + */ +static DfuUpdateBlockResult dfu_file_perform_task_for_update_pages( + const DfuUpdateTask* task, + File* dfuf, + const ImageElementHeader* header) { + furi_assert(task); + furi_assert(header); + task->progress_cb(0, task->context); + const size_t FLASH_PAGE_SIZE = furi_hal_flash_get_page_size(); + const size_t FLASH_PAGE_ALIGNMENT_MASK = FLASH_PAGE_SIZE - 1; + if((header->dwElementAddress & FLASH_PAGE_ALIGNMENT_MASK) != 0) { + /* start address is not aligned by page boundary -- we don't support that. Yet. */ + return UpdateBlockResult_Failed; + } + + if(task->address_cb && (!task->address_cb(header->dwElementAddress) || + !task->address_cb(header->dwElementAddress + header->dwElementSize))) { + storage_file_seek(dfuf, header->dwElementSize, false); + task->progress_cb(100, task->context); + return UpdateBlockResult_Skipped; + } + + uint8_t* fw_block = malloc(FLASH_PAGE_SIZE); + uint16_t bytes_read = 0; + uint32_t element_offs = 0; + + while(element_offs < header->dwElementSize) { + uint32_t n_bytes_to_read = FLASH_PAGE_SIZE; + if((element_offs + n_bytes_to_read) > header->dwElementSize) { + n_bytes_to_read = header->dwElementSize - element_offs; + } + + bytes_read = storage_file_read(dfuf, fw_block, n_bytes_to_read); + if(bytes_read == 0) { + break; + } + + int16_t i_page = furi_hal_flash_get_page_number(header->dwElementAddress + element_offs); + if(i_page < 0) { + break; + } + + if(!task->task_cb(i_page, fw_block, bytes_read)) { + break; + } + + element_offs += bytes_read; + task->progress_cb(element_offs * 100 / header->dwElementSize, task->context); + } + + free(fw_block); + return (element_offs == header->dwElementSize) ? UpdateBlockResult_OK : + UpdateBlockResult_Failed; +} + +bool dfu_file_process_targets(const DfuUpdateTask* task, File* dfuf, const uint8_t n_targets) { + TargetPrefix target_prefix = {0}; + ImageElementHeader image_element = {0}; + uint16_t bytes_read = 0; + + if(!storage_file_seek(dfuf, sizeof(DfuPrefix), true)) { + return UpdateBlockResult_Failed; + }; + + for(uint8_t i_target = 0; i_target < n_targets; ++i_target) { + bytes_read = storage_file_read(dfuf, &target_prefix, sizeof(TargetPrefix)); + if(bytes_read != sizeof(TargetPrefix)) { + return UpdateBlockResult_Failed; + } + + /* TODO: look into TargetPrefix and validate/filter?.. */ + for(uint32_t i_element = 0; i_element < target_prefix.dwNbElements; ++i_element) { + bytes_read = storage_file_read(dfuf, &image_element, sizeof(ImageElementHeader)); + if(bytes_read != sizeof(ImageElementHeader)) { + return UpdateBlockResult_Failed; + } + + if(dfu_file_perform_task_for_update_pages(task, dfuf, &image_element) == + UpdateBlockResult_Failed) { + return false; + } + } + } + + return true; +} diff --git a/lib/update_util/dfu_file.h b/lib/update_util/dfu_file.h new file mode 100644 index 00000000..81a6887c --- /dev/null +++ b/lib/update_util/dfu_file.h @@ -0,0 +1,40 @@ +#pragma once + +#include "dfu_headers.h" + +#include +#include + +typedef enum { + UpdateBlockResult_Unknown, + UpdateBlockResult_OK, + UpdateBlockResult_Skipped, + UpdateBlockResult_Failed +} DfuUpdateBlockResult; + +typedef bool ( + *DfuPageTaskCb)(const uint8_t i_page, const uint8_t* update_block, uint16_t update_block_len); +typedef void (*DfuPageTaskProgressCb)(const uint8_t progress, void* context); +typedef bool (*DfuAddressValidationCb)(const size_t address); + +typedef struct { + DfuPageTaskCb task_cb; + DfuPageTaskProgressCb progress_cb; + DfuAddressValidationCb address_cb; + void* context; +} DfuUpdateTask; + +typedef struct { + uint16_t vendor; + uint16_t product; + uint16_t device; +} DfuValidationParams; + +bool dfu_file_validate_crc(File* dfuf, const DfuPageTaskProgressCb progress_cb, void* context); + +/* Returns number of valid targets from file header + * If file is invalid, returns 0 + */ +uint8_t dfu_file_validate_headers(File* dfuf, const DfuValidationParams* reference_params); + +bool dfu_file_process_targets(const DfuUpdateTask* task, File* dfuf, const uint8_t n_targets); diff --git a/lib/update_util/dfu_headers.h b/lib/update_util/dfu_headers.h new file mode 100644 index 00000000..79726dea --- /dev/null +++ b/lib/update_util/dfu_headers.h @@ -0,0 +1,41 @@ +#pragma once + +#include + +#pragma pack(push, 1) + +typedef struct { + char szSignature[5]; + uint8_t bVersion; + uint32_t DFUImageSize; + uint8_t bTargets; +} DfuPrefix; + +typedef struct { + uint16_t bcdDevice; + uint16_t idProduct; + uint16_t idVendor; + uint16_t bcdDFU; + uint8_t ucDfuSignature_U; + uint8_t ucDfuSignature_F; + uint8_t ucDfuSignature_D; + uint8_t bLength; + uint32_t dwCRC; +} DfuSuffix; + +typedef struct { + char szSignature[6]; + uint8_t bAlternateSetting; + uint8_t bTargetNamed; + uint8_t _pad[3]; + char szTargetName[255]; + uint32_t dwTargetSize; + uint32_t dwNbElements; +} TargetPrefix; + +typedef struct { + uint32_t dwElementAddress; + uint32_t dwElementSize; +} ImageElementHeader; + +#pragma pack(pop) diff --git a/lib/update_util/lfs_backup.c b/lib/update_util/lfs_backup.c new file mode 100644 index 00000000..fa9141df --- /dev/null +++ b/lib/update_util/lfs_backup.c @@ -0,0 +1,22 @@ +#include "lfs_backup.h" + +#include + +#define LFS_BACKUP_DEFAULT_LOCATION "/ext/" LFS_BACKUP_DEFAULT_FILENAME + +bool lfs_backup_create(Storage* storage, const char* destination) { + const char* final_destination = + destination && strlen(destination) ? destination : LFS_BACKUP_DEFAULT_LOCATION; + return storage_int_backup(storage, final_destination) == FSE_OK; +} + +bool lfs_backup_exists(Storage* storage, const char* source) { + const char* final_source = source && strlen(source) ? source : LFS_BACKUP_DEFAULT_LOCATION; + FileInfo fi; + return storage_common_stat(storage, final_source, &fi) == FSE_OK; +} + +bool lfs_backup_unpack(Storage* storage, const char* source) { + const char* final_source = source && strlen(source) ? source : LFS_BACKUP_DEFAULT_LOCATION; + return storage_int_restore(storage, final_source) == FSE_OK; +} diff --git a/lib/update_util/lfs_backup.h b/lib/update_util/lfs_backup.h new file mode 100644 index 00000000..5a7738c8 --- /dev/null +++ b/lib/update_util/lfs_backup.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +#define LFS_BACKUP_DEFAULT_FILENAME "backup.tar" + +#ifdef __cplusplus +extern "C" { +#endif + +bool lfs_backup_create(Storage* storage, const char* destination); +bool lfs_backup_exists(Storage* storage, const char* source); +bool lfs_backup_unpack(Storage* storage, const char* source); + +#ifdef __cplusplus +} +#endif diff --git a/lib/update_util/update_manifest.c b/lib/update_util/update_manifest.c new file mode 100644 index 00000000..2ae52f17 --- /dev/null +++ b/lib/update_util/update_manifest.c @@ -0,0 +1,86 @@ +#include "update_manifest.h" + +#include +#include +#include + +UpdateManifest* update_manifest_alloc() { + UpdateManifest* update_manifest = malloc(sizeof(UpdateManifest)); + string_init(update_manifest->version); + string_init(update_manifest->firmware_dfu_image); + string_init(update_manifest->radio_image); + string_init(update_manifest->staged_loader_file); + update_manifest->target = 0; + update_manifest->valid = false; + return update_manifest; +} + +void update_manifest_free(UpdateManifest* update_manifest) { + furi_assert(update_manifest); + string_clear(update_manifest->version); + string_clear(update_manifest->firmware_dfu_image); + string_clear(update_manifest->radio_image); + string_clear(update_manifest->staged_loader_file); + free(update_manifest); +} + +static bool + update_manifest_init_from_ff(UpdateManifest* update_manifest, FlipperFormat* flipper_file) { + furi_assert(update_manifest); + furi_assert(flipper_file); + + string_t filetype; + uint32_t version = 0; + + // TODO: compare filetype? + string_init(filetype); + update_manifest->valid = + flipper_format_read_header(flipper_file, filetype, &version) && + flipper_format_read_string(flipper_file, "Info", update_manifest->version) && + flipper_format_read_uint32(flipper_file, "Target", &update_manifest->target, 1) && + flipper_format_read_string(flipper_file, "Loader", update_manifest->staged_loader_file) && + flipper_format_read_hex( + flipper_file, + "Loader CRC", + (uint8_t*)&update_manifest->staged_loader_crc, + sizeof(uint32_t)); + string_clear(filetype); + + /* Optional fields - we can have dfu, radio, or both */ + flipper_format_read_string(flipper_file, "Firmware", update_manifest->firmware_dfu_image); + flipper_format_read_string(flipper_file, "Radio", update_manifest->radio_image); + flipper_format_read_hex( + flipper_file, "Radio address", (uint8_t*)&update_manifest->radio_address, sizeof(uint32_t)); + + return update_manifest->valid; +} + +bool update_manifest_init(UpdateManifest* update_manifest, const char* manifest_filename) { + Storage* storage = furi_record_open("storage"); + FlipperFormat* flipper_file = flipper_format_file_alloc(storage); + if(flipper_format_file_open_existing(flipper_file, manifest_filename)) { + update_manifest_init_from_ff(update_manifest, flipper_file); + } + + flipper_format_free(flipper_file); + furi_record_close("storage"); + + return update_manifest->valid; +} + +bool update_manifest_init_mem( + UpdateManifest* update_manifest, + const uint8_t* manifest_data, + const uint16_t length) { + FlipperFormat* flipper_file = flipper_format_string_alloc(); + Stream* sstream = flipper_format_get_raw_stream(flipper_file); + + stream_write(sstream, manifest_data, length); + stream_seek(sstream, 0, StreamOffsetFromStart); + + update_manifest_init_from_ff(update_manifest, flipper_file); + + flipper_format_free(flipper_file); + + return update_manifest->valid; +} diff --git a/lib/update_util/update_manifest.h b/lib/update_util/update_manifest.h new file mode 100644 index 00000000..7b60f58a --- /dev/null +++ b/lib/update_util/update_manifest.h @@ -0,0 +1,40 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/* Paths don't include /ext -- because at startup SD card is mounted as root */ +#define UPDATE_DIR_DEFAULT_REL_PATH "/update" +#define UPDATE_MANIFEST_DEFAULT_NAME "update.fuf" +#define UPDATE_MAINFEST_DEFAULT_PATH UPDATE_DIR_DEFAULT_REL_PATH "/" UPDATE_MANIFEST_DEFAULT_NAME + +typedef struct { + string_t version; + uint32_t target; + string_t staged_loader_file; + uint32_t staged_loader_crc; + string_t firmware_dfu_image; + string_t radio_image; + uint32_t radio_address; + bool valid; +} UpdateManifest; + +UpdateManifest* update_manifest_alloc(); + +void update_manifest_free(UpdateManifest* update_manifest); + +bool update_manifest_init(UpdateManifest* update_manifest, const char* manifest_filename); + +bool update_manifest_init_mem( + UpdateManifest* update_manifest, + const uint8_t* manifest_data, + const uint16_t length); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/lib/update_util/update_operation.c b/lib/update_util/update_operation.c new file mode 100644 index 00000000..2fd510b5 --- /dev/null +++ b/lib/update_util/update_operation.c @@ -0,0 +1,207 @@ +#include "update_operation.h" + +#include "update_manifest.h" + +#include +#include +#include +#include +#include + +static const char* UPDATE_ROOT_DIR = "/ext" UPDATE_DIR_DEFAULT_REL_PATH; +static const char* UPDATE_PREFIX = "/ext" UPDATE_DIR_DEFAULT_REL_PATH "/"; +static const char* UPDATE_SUFFIX = "/" UPDATE_MANIFEST_DEFAULT_NAME; +static const uint32_t MAX_DIR_NAME_LEN = 250; + +static const char* update_prepare_result_descr[] = { + [UpdatePrepareResultOK] = "OK", + [UpdatePrepareResultManifestPathInvalid] = "Invalid manifest name or location", + [UpdatePrepareResultManifestFolderNotFound] = "Update folder not found", + [UpdatePrepareResultManifestInvalid] = "Invalid manifest data", + [UpdatePrepareResultStageMissing] = "Missing Stage2 loader", + [UpdatePrepareResultStageIntegrityError] = "Corrupted Stage2 loader", +}; + +const char* update_operation_describe_preparation_result(const UpdatePrepareResult value) { + if(value >= COUNT_OF(update_prepare_result_descr)) { + return "..."; + } else { + return update_prepare_result_descr[value]; + } +} + +bool update_operation_get_package_dir_name(const char* full_path, string_t out_manifest_dir) { + bool path_ok = false; + string_t full_path_str; + string_init_set(full_path_str, full_path); + string_reset(out_manifest_dir); + bool start_end_ok = string_start_with_str_p(full_path_str, UPDATE_PREFIX) && + string_end_with_str_p(full_path_str, UPDATE_SUFFIX); + int16_t dir_name_len = + strlen(full_path) - strlen(UPDATE_PREFIX) - strlen(UPDATE_MANIFEST_DEFAULT_NAME) - 1; + if(dir_name_len == -1) { + path_ok = true; + } else if(start_end_ok && (dir_name_len > 0)) { + string_set_n(out_manifest_dir, full_path_str, strlen(UPDATE_PREFIX), dir_name_len); + path_ok = true; + if(string_search_char(out_manifest_dir, '/') != STRING_FAILURE) { + string_reset(out_manifest_dir); + path_ok = false; + } + } + string_clear(full_path_str); + return path_ok; +} + +int32_t update_operation_get_package_index(Storage* storage, const char* update_package_dir) { + furi_assert(storage); + furi_assert(update_package_dir); + + if(strlen(update_package_dir) == 0) { + return 0; + } + + bool found = false; + int32_t index = 0; + File* dir = storage_file_alloc(storage); + FileInfo fi = {0}; + char* name_buffer = malloc(MAX_DIR_NAME_LEN); + do { + if(!storage_dir_open(dir, UPDATE_ROOT_DIR)) { + break; + } + + while(storage_dir_read(dir, &fi, name_buffer, MAX_DIR_NAME_LEN)) { + index++; + if(strcmp(name_buffer, update_package_dir)) { + continue; + } else { + found = true; + break; + } + } + } while(false); + + free(name_buffer); + storage_file_free(dir); + + return found ? index : -1; +} + +bool update_operation_get_current_package_path(Storage* storage, string_t out_path) { + uint32_t update_index = furi_hal_rtc_get_register(FuriHalRtcRegisterUpdateFolderFSIndex); + string_set_str(out_path, UPDATE_ROOT_DIR); + if(update_index == 0) { + return true; + } + + bool found = false; + uint32_t iter_index = 0; + File* dir = storage_file_alloc(storage); + FileInfo fi = {0}; + char* name_buffer = malloc(MAX_DIR_NAME_LEN); + do { + if(!storage_dir_open(dir, UPDATE_ROOT_DIR)) { + break; + } + + while(storage_dir_read(dir, &fi, name_buffer, MAX_DIR_NAME_LEN)) { + if(++iter_index == update_index) { + found = true; + path_append(out_path, name_buffer); + break; + } + } + } while(false); + + free(name_buffer); + storage_file_free(dir); + if(!found) { + string_reset(out_path); + } + + return found; +} + +UpdatePrepareResult update_operation_prepare(const char* manifest_file_path) { + string_t update_folder; + string_init(update_folder); + if(!update_operation_get_package_dir_name(manifest_file_path, update_folder)) { + string_clear(update_folder); + return UpdatePrepareResultManifestPathInvalid; + } + + Storage* storage = furi_record_open("storage"); + int32_t update_index = + update_operation_get_package_index(storage, string_get_cstr(update_folder)); + string_clear(update_folder); + + if(update_index < 0) { + furi_record_close("storage"); + return UpdatePrepareResultManifestFolderNotFound; + } + + string_t update_dir_path; + string_init(update_dir_path); + path_extract_dirname(manifest_file_path, update_dir_path); + + UpdatePrepareResult result = UpdatePrepareResultManifestInvalid; + UpdateManifest* manifest = update_manifest_alloc(); + if(update_manifest_init(manifest, manifest_file_path)) { + result = UpdatePrepareResultStageMissing; + File* file = storage_file_alloc(storage); + + string_t stage_path; + string_init(stage_path); + path_extract_dirname(manifest_file_path, stage_path); + path_append(stage_path, string_get_cstr(manifest->staged_loader_file)); + + const uint16_t READ_BLOCK = 0x1000; + uint8_t* read_buffer = malloc(READ_BLOCK); + uint32_t crc = 0; + do { + if(!storage_file_open( + file, string_get_cstr(stage_path), FSAM_READ, FSOM_OPEN_EXISTING)) { + break; + } + + result = UpdatePrepareResultStageIntegrityError; + furi_hal_crc_acquire(osWaitForever); + + uint16_t bytes_read = 0; + do { + bytes_read = storage_file_read(file, read_buffer, READ_BLOCK); + crc = furi_hal_crc_feed(read_buffer, bytes_read); + } while(bytes_read == READ_BLOCK); + + furi_hal_crc_reset(); + } while(false); + + string_clear(stage_path); + free(read_buffer); + storage_file_free(file); + + if(crc == manifest->staged_loader_crc) { + furi_hal_rtc_set_boot_mode(FuriHalRtcBootModePreUpdate); + update_operation_persist_package_index(update_index); + result = UpdatePrepareResultOK; + } + } + furi_record_close("storage"); + update_manifest_free(manifest); + + return result; +} + +bool update_operation_is_armed() { + return furi_hal_rtc_get_boot_mode() == FuriHalRtcBootModePreUpdate; +} + +void update_operation_disarm() { + furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); + furi_hal_rtc_set_register(FuriHalRtcRegisterUpdateFolderFSIndex, 0); +} + +void update_operation_persist_package_index(uint32_t index) { + furi_hal_rtc_set_register(FuriHalRtcRegisterUpdateFolderFSIndex, index); +} \ No newline at end of file diff --git a/lib/update_util/update_operation.h b/lib/update_util/update_operation.h new file mode 100644 index 00000000..6b6ab730 --- /dev/null +++ b/lib/update_util/update_operation.h @@ -0,0 +1,72 @@ +#pragma once + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Checks if supplied full manifest path is valid + * @param full_path Full path to manifest file. Must be named UPDATE_MANIFEST_DEFAULT_NAME + * @param out_manifest_dir Directory to apply update from, if supplied path is valid. + * May be empty if update is in root update directory + * @return bool if supplied path is valid and out_manifest_dir contains dir to apply + */ +bool update_operation_get_package_dir_name(const char* full_path, string_t out_manifest_dir); + +typedef enum { + UpdatePrepareResultOK, + UpdatePrepareResultManifestPathInvalid, + UpdatePrepareResultManifestFolderNotFound, + UpdatePrepareResultManifestInvalid, + UpdatePrepareResultStageMissing, + UpdatePrepareResultStageIntegrityError, +} UpdatePrepareResult; + +const char* update_operation_describe_preparation_result(const UpdatePrepareResult value); + +/* + * Validates next stage and sets up registers to apply update after restart + * @param manifest_dir_path Full path to manifest for update to apply + * @return UpdatePrepareResult validation & arm result + */ +UpdatePrepareResult update_operation_prepare(const char* manifest_file_path); + +/* + * Gets update package index to pass in RTC registers + * @param storage Storage API + * @param update_package_dir Package directory name + * @return int32_t <0 - error, >= 0 - update index value + */ +int32_t update_operation_get_package_index(Storage* storage, const char* update_package_dir); + +/* + * Gets filesystem path for current update package + * @param storage Storage API + * @param out_path Path to directory with manifest & related files. Must be initialized + * @return true if path was restored successfully + */ +bool update_operation_get_current_package_path(Storage* storage, string_t out_path); + +/* + * Stores given update index in RTC registers + * @param index Value to store + */ +void update_operation_persist_package_index(uint32_t index); + +/* + * Sets up update operation to be performed on reset + */ +bool update_operation_is_armed(); + +/* + * Cancels pending update operation + */ +void update_operation_disarm(); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/make/git.mk b/make/git.mk index dd8842e8..e58876a8 100644 --- a/make/git.mk +++ b/make/git.mk @@ -2,7 +2,14 @@ GIT_COMMIT := $(shell git rev-parse --short HEAD || echo 'unknown') GIT_BRANCH := $(shell echo $${WORKFLOW_BRANCH_OR_TAG-$$(git rev-parse --abbrev-ref HEAD || echo 'unknown')}) GIT_BRANCH_NUM := $(shell git rev-list --count HEAD || echo 'nan') BUILD_DATE := $(shell date '+%d-%m-%Y' || echo 'unknown') +BUILD_TIME := $(shell date '+%H:%M:%S' || echo 'unknown') VERSION := $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null || echo 'unknown') +GIT_DIRTY_BUILD := $(shell git diff --quiet ; echo $$?) + +GIT_DIRTY_SUFFIX := +ifeq ($(GIT_DIRTY_BUILD), 1) + GIT_DIRTY_SUFFIX := -dirty +endif CFLAGS += \ -DGIT_COMMIT=\"$(GIT_COMMIT)\" \ @@ -10,4 +17,16 @@ CFLAGS += \ -DGIT_BRANCH_NUM=\"$(GIT_BRANCH_NUM)\" \ -DBUILD_DATE=\"$(BUILD_DATE)\" \ -DVERSION=\"$(VERSION)\" \ - -DTARGET=$(HARDWARE_TARGET) \ No newline at end of file + -DTARGET=$(HARDWARE_TARGET) \ + -DBUILD_DIRTY=$(GIT_DIRTY_BUILD) + +# if suffix is set in environment (by Github), use it +ifeq (${DIST_SUFFIX},) + DIST_SUFFIX := local-$(GIT_COMMIT)$(GIT_DIRTY_SUFFIX) +else + DIST_SUFFIX := ${DIST_SUFFIX}$(GIT_DIRTY_SUFFIX) +endif + +#VERSION_STRING := $(VERSION) ($(GIT_BRANCH) @ $(GIT_COMMIT)), built $(BUILD_DATE) $(BUILD_TIME) +VERSION_STRING := $(DIST_SUFFIX), $(GIT_BRANCH) + diff --git a/make/rules.mk b/make/rules.mk index 16904333..e907b0eb 100644 --- a/make/rules.mk +++ b/make/rules.mk @@ -1,4 +1,4 @@ -OBJ_DIR := $(OBJ_DIR)/$(TARGET) +OBJ_DIR := $(OBJ_DIR)/$(TARGET)-$(PROJECT) # Include source folder paths to virtual paths C_SOURCES := $(abspath ${C_SOURCES}) @@ -22,6 +22,7 @@ endif $(foreach dir, $(OBJECT_DIRS),$(shell mkdir -p $(dir))) BUILD_FLAGS_SHELL=\ + echo $(OBJ_DIR) ;\ echo "$(CFLAGS)" > $(OBJ_DIR)/BUILD_FLAGS.tmp; \ diff -u $(OBJ_DIR)/BUILD_FLAGS $(OBJ_DIR)/BUILD_FLAGS.tmp 2>&1 > /dev/null \ && ( echo "CFLAGS ok"; rm $(OBJ_DIR)/BUILD_FLAGS.tmp) \ @@ -48,7 +49,7 @@ $(OBJ_DIR)/$(PROJECT).elf: $(OBJECTS) $(OBJ_DIR)/$(PROJECT).hex: $(OBJ_DIR)/$(PROJECT).elf @echo "\tHEX\t" $@ @$(HEX) $< $@ - + $(OBJ_DIR)/$(PROJECT).bin: $(OBJ_DIR)/$(PROJECT).elf @echo "\tBIN\t" $@ @$(BIN) $< $@ diff --git a/make/toolchain.mk b/make/toolchain.mk index 04144a3c..2946a2e2 100644 --- a/make/toolchain.mk +++ b/make/toolchain.mk @@ -4,12 +4,14 @@ OS := $(shell uname -s) ifeq ($(TOOLCHAIN), arm) PREFIX = arm-none-eabi- ifdef GCC_PATH -PREFIX = $(GCC_PATH)/$(PREFIX) +PREFIX := $(GCC_PATH)/$(PREFIX) endif endif -CC = $(PREFIX)gcc -std=gnu17 -CPP = $(PREFIX)g++ -std=gnu++17 +CCACHE := $(shell which ccache) + +CC = $(CCACHE) $(PREFIX)gcc -std=gnu17 +CPP = $(CCACHE) $(PREFIX)g++ -std=gnu++17 LD = $(PREFIX)g++ AS = $(PREFIX)gcc -x assembler-with-cpp CP = $(PREFIX)objcopy @@ -17,6 +19,7 @@ SZ = $(PREFIX)size HEX = $(CP) -O ihex BIN = $(CP) -O binary -S + ifeq ($(OS), Darwin) GDB = gdb else diff --git a/scripts/dist.py b/scripts/dist.py new file mode 100755 index 00000000..b149678b --- /dev/null +++ b/scripts/dist.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 + +from flipper.app import App +from os.path import join, exists +from os import makedirs +from update import Main as UpdateMain +import shutil + + +class Main(App): + def init(self): + self.subparsers = self.parser.add_subparsers(help="sub-command help") + + self.parser_copy = self.subparsers.add_parser( + "copy", help="Copy firmware binaries & metadata" + ) + + self.parser_copy.add_argument("-t", dest="target", required=True) + self.parser_copy.add_argument("-p", dest="projects", nargs="+", required=True) + self.parser_copy.add_argument("-s", dest="suffix", required=True) + self.parser_copy.add_argument( + "--bundlever", + dest="version", + help="If set, bundle update package for self-update", + required=False, + ) + self.parser_copy.add_argument( + "--noclean", + dest="noclean", + action="store_true", + help="Don't clean output directory", + required=False, + ) + self.parser_copy.set_defaults(func=self.copy) + + def get_project_filename(self, project, filetype): + return f"flipper-z-{self.args.target}-{project}-{self.args.suffix}.{filetype}" + + def get_dist_filepath(self, filename): + return join(self.output_dir_path, filename) + + def copy_single_project(self, project): + target_project = f"{self.args.target}-{project}" + obj_directory = join("firmware", ".obj", target_project) + + for filetype in ("elf", "bin", "dfu", "json"): + shutil.copyfile( + join(obj_directory, f"{project}.{filetype}"), + self.get_dist_filepath(self.get_project_filename(project, filetype)), + ) + + def copy(self): + self.output_dir_path = join("dist", self.args.target) + if exists(self.output_dir_path) and not self.args.noclean: + shutil.rmtree(self.output_dir_path) + + if not exists(self.output_dir_path): + makedirs(self.output_dir_path) + + for project in self.args.projects: + self.copy_single_project(project) + + self.logger.info( + f"Firmware binaries can be found at:\n\t{self.output_dir_path}" + ) + if self.args.version: + bundle_dir = join( + self.output_dir_path, f"{self.args.target}-update-{self.args.suffix}" + ) + bundle_args = [ + "generate", + "-d", + bundle_dir, + "-v", + self.args.version, + "-t", + self.args.target, + "-dfu", + self.get_dist_filepath(self.get_project_filename("firmware", "dfu")), + "-stage", + self.get_dist_filepath(self.get_project_filename("updater", "bin")), + ] + self.logger.info( + f"Use this directory to self-update your Flipper:\n\t{bundle_dir}" + ) + return UpdateMain(no_exit=True)(bundle_args) + + return 0 + + +if __name__ == "__main__": + Main()() diff --git a/scripts/dist.sh b/scripts/dist.sh deleted file mode 100755 index 03ee5e7e..00000000 --- a/scripts/dist.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash - -set -e - -suffix="${DIST_SUFFIX:=local}" - -rm -rf "dist/${TARGET}" -mkdir -p "dist/${TARGET}" - -# copy build outputs -cp bootloader/.obj/${TARGET}/bootloader.elf \ - dist/${TARGET}/flipper-z-${TARGET}-bootloader-${suffix}.elf -cp bootloader/.obj/${TARGET}/bootloader.bin \ - dist/${TARGET}/flipper-z-${TARGET}-bootloader-${suffix}.bin -cp bootloader/.obj/${TARGET}/bootloader.dfu \ - dist/${TARGET}/flipper-z-${TARGET}-bootloader-${suffix}.dfu -cp bootloader/.obj/${TARGET}/bootloader.json \ - dist/${TARGET}/flipper-z-${TARGET}-bootloader-${suffix}.json -cp firmware/.obj/${TARGET}/firmware.elf \ - dist/${TARGET}/flipper-z-${TARGET}-firmware-${suffix}.elf -cp firmware/.obj/${TARGET}/firmware.bin \ - dist/${TARGET}/flipper-z-${TARGET}-firmware-${suffix}.bin -cp firmware/.obj/${TARGET}/firmware.dfu \ - dist/${TARGET}/flipper-z-${TARGET}-firmware-${suffix}.dfu -cp firmware/.obj/${TARGET}/firmware.json \ - dist/${TARGET}/flipper-z-${TARGET}-firmware-${suffix}.json - -# generate full.bin -cp dist/${TARGET}/flipper-z-${TARGET}-bootloader-${suffix}.bin \ - dist/${TARGET}/flipper-z-${TARGET}-full-${suffix}.bin -dd if=/dev/null of=dist/${TARGET}/flipper-z-${TARGET}-full-${suffix}.bin bs=1 count=0 seek=32768 2> /dev/null -cat dist/${TARGET}/flipper-z-${TARGET}-firmware-${suffix}.bin \ - >>dist/${TARGET}/flipper-z-${TARGET}-full-${suffix}.bin \ - 2> /dev/null - -# generate full.dfu -./scripts/bin2dfu.py \ - -i dist/${TARGET}/flipper-z-${TARGET}-full-${suffix}.bin \ - -o dist/${TARGET}/flipper-z-${TARGET}-full-${suffix}.dfu \ - -a 0x08000000 \ - -l "Flipper Zero $(echo ${TARGET} | tr a-z A-Z)" - -# generate full.json -./scripts/meta.py merge \ - -i dist/${TARGET}/flipper-z-${TARGET}-bootloader-${suffix}.json \ - dist/${TARGET}/flipper-z-${TARGET}-firmware-${suffix}.json \ - >dist/${TARGET}/flipper-z-${TARGET}-full-${suffix}.json - -echo "Firmware binaries can be found at:" -echo -e "\t$(pwd)/dist/${TARGET}" -echo "Use this file to flash your Flipper:" -echo -e "\tflipper-z-${TARGET}-full-${suffix}.dfu" diff --git a/scripts/flipper/app.py b/scripts/flipper/app.py index 3c911bc4..ea62f674 100644 --- a/scripts/flipper/app.py +++ b/scripts/flipper/app.py @@ -5,8 +5,9 @@ import os class App: - def __init__(self): + def __init__(self, no_exit=False): # Argument Parser + self.no_exit = no_exit self.parser = argparse.ArgumentParser() self.parser.add_argument("-d", "--debug", action="store_true", help="Debug") # Logging @@ -14,8 +15,8 @@ class App: # Application specific initialization self.init() - def __call__(self): - self.args, _ = self.parser.parse_known_args() + def __call__(self, args=None): + self.args, _ = self.parser.parse_known_args(args=args) # configure log output self.log_level = logging.DEBUG if self.args.debug else logging.INFO self.logger.setLevel(self.log_level) @@ -30,10 +31,15 @@ class App: return_code = self.call() self.after() if isinstance(return_code, int): - exit(return_code) + return self._exit(return_code) else: self.logger.error(f"Missing return code") - exit(255) + return self._exit(255) + + def _exit(self, code): + if self.no_exit: + return code + exit(code) def call(self): if "func" not in self.args: diff --git a/scripts/flipper/utils/fff.py b/scripts/flipper/utils/fff.py index e44d3430..b7f89321 100644 --- a/scripts/flipper/utils/fff.py +++ b/scripts/flipper/utils/fff.py @@ -95,9 +95,9 @@ class FlipperFormatFile: self.writeKey("Version", version) def load(self, filename: str): - file = open(filename, "r") - self.lines = file.readlines() + with open(filename, "r") as file: + self.lines = file.readlines() def save(self, filename: str): - file = open(filename, "w") - file.write("\n".join(self.lines)) + with open(filename, "w") as file: + file.write("\n".join(self.lines)) diff --git a/scripts/lint.py b/scripts/lint.py index 6537b548..bf1f5e68 100755 --- a/scripts/lint.py +++ b/scripts/lint.py @@ -83,7 +83,7 @@ class Main(App): pool = multiprocessing.Pool() results = pool.map(self._format_source, tasks) - return not False in results + return all(results) def _fix_filename(self, filename: str): return filename.replace("-", "_") diff --git a/scripts/update.py b/scripts/update.py new file mode 100755 index 00000000..7e49aad0 --- /dev/null +++ b/scripts/update.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 + +from flipper.app import App +from flipper.utils.fff import FlipperFormatFile +from os.path import basename, join, exists +from os import makedirs +import shutil +import zlib + + +class Main(App): + def init(self): + self.subparsers = self.parser.add_subparsers(help="sub-command help") + + # generate + self.parser_generate = self.subparsers.add_parser( + "generate", help="Generate update description file" + ) + + self.parser_generate.add_argument("-d", dest="directory", required=True) + self.parser_generate.add_argument("-v", dest="version", required=True) + self.parser_generate.add_argument("-t", dest="target", required=True) + self.parser_generate.add_argument("-dfu", dest="dfu", required=True) + self.parser_generate.add_argument("-stage", dest="stage", required=True) + self.parser_generate.add_argument("-radio", dest="radiobin", required=False) + self.parser_generate.add_argument( + "-radioaddr", dest="radioaddr", required=False + ) + + self.parser_generate.set_defaults(func=self.generate) + + def generate(self): + stage_basename = basename(self.args.stage) + dfu_basename = basename(self.args.dfu) + + if not exists(self.args.directory): + makedirs(self.args.directory) + + shutil.copyfile(self.args.stage, join(self.args.directory, stage_basename)) + shutil.copyfile(self.args.dfu, join(self.args.directory, dfu_basename)) + + file = FlipperFormatFile() + file.setHeader("Flipper firmware upgrade configuration", 1) + file.writeKey("Info", self.args.version) + file.writeKey("Target", self.args.target[1:]) # dirty 'f' strip + file.writeKey("Loader", stage_basename) + file.writeComment("little-endian hex!") + file.writeKey("Loader CRC", self.int2ffhex(self.crc(self.args.stage))) + file.writeKey("Firmware", dfu_basename) + file.writeKey("Radio", self.args.radiobin or "") + file.writeKey("Radio address", self.int2ffhex(self.args.radioaddr or 0)) + file.save("%s/update.fuf" % self.args.directory) + + return 0 + + @staticmethod + def int2ffhex(value: int): + hexstr = "%08X" % value + return " ".join(list(Main.batch(hexstr, 2))[::-1]) + + @staticmethod + def crc(fileName): + prev = 0 + with open(fileName, "rb") as file: + for eachLine in file: + prev = zlib.crc32(eachLine, prev) + return prev & 0xFFFFFFFF + + @staticmethod + def batch(iterable, n=1): + l = len(iterable) + for ndx in range(0, l, n): + yield iterable[ndx : min(ndx + n, l)] + + +if __name__ == "__main__": + Main()()