Compare commits
12 Commits
release/1.
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3728b45b90 | ||
|
|
8ea5166aa1 | ||
|
|
9c2667bbe5 | ||
|
|
68f478625e | ||
|
|
3acaa773de | ||
|
|
389d3d23b8 | ||
|
|
51b12ac970 | ||
|
|
3fe2c86773 | ||
|
|
485480e042 | ||
|
|
9db1fb42e0 | ||
|
|
4561bcc255 | ||
|
|
fb819e50a1 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -7,3 +7,8 @@
|
||||
*.map
|
||||
/Debug/
|
||||
/Release/
|
||||
/firmware/Debug/
|
||||
/firmware/Release/
|
||||
/bootloader/Debug/
|
||||
/bootloader/Release/
|
||||
*debug*
|
||||
|
||||
@@ -50,9 +50,10 @@
|
||||
<listOptionValue builtIn="false" value="../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy"/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Core/Inc"/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc"/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc"/>
|
||||
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32F1xx/Include"/>
|
||||
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/BMS_v3/Middlewares/Third_Party/FatFs/src}""/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/FatFs/src"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols.1889788482" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
|
||||
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
|
||||
@@ -176,9 +177,10 @@
|
||||
<listOptionValue builtIn="false" value="../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy"/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Core/Inc"/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc"/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc"/>
|
||||
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32F1xx/Include"/>
|
||||
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Middlewares/Third_Party/FatFs/src}""/>
|
||||
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/FatFs/src"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols.390483859" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
|
||||
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
|
||||
7
bootloader/.gitignore
vendored
Normal file
7
bootloader/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
*.log
|
||||
*.elf
|
||||
*.o
|
||||
*.d
|
||||
*.tmp
|
||||
*.list
|
||||
*.map
|
||||
49
bootloader/.project
Normal file
49
bootloader/.project
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>BMS_BootloaderPlusSD</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
<nature>com.st.stm32cube.ide.mcu.MCUSW4STM32ConvertedProjectNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
</natures>
|
||||
<linkedResources>
|
||||
<link>
|
||||
<name>USB_Device_Library/usbd_cdc.c</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>USB_Device_Library/usbd_core.c</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>USB_Device_Library/usbd_ctlreq.c</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>USB_Device_Library/usbd_ioreq.c</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c</locationURI>
|
||||
</link>
|
||||
</linkedResources>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
sfrviewstate={"fFavorites"\:{"fLists"\:{}},"fProperties"\:{"fNodeProperties"\:{}}}
|
||||
@@ -5,7 +5,7 @@
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="892067782257261287" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1691016109063658528" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
@@ -16,7 +16,7 @@
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="892067782257261287" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1691016109063658528" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
80
bootloader/BMS_BootloaderPlusSD Debug.launch
Normal file
80
bootloader/BMS_BootloaderPlusSD Debug.launch
Normal file
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="com.st.stm32cube.ide.mcu.debug.launch.launchConfigurationType">
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.access_port_id" value="0"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_live_expr" value="false"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.enable_swv" value="false"/>
|
||||
<intAttribute key="com.st.stm32cube.ide.mcu.debug.launch.formatVersion" value="2"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.ip_address_local" value="localhost"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.enabled" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.limit_swo_clock.value" value=""/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.loadList" value="{"fItems":[{"fIsFromMainTab":true,"fPath":"Debug/BMS_BootloaderPlusSD.elf","fProjectName":"BMS_BootloaderPlusSD","fPerformBuild":true,"fDownload":true,"fLoadSymbols":true}]}"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.override_start_address_mode" value="default"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.remoteCommand" value="target remote"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startServer" value="true"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.exception.divby0" value="true"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.exception.unaligned" value="false"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.startuptab.haltonexception" value="true"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swd_mode" value="true"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swv_port" value="61235"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.swv_trace_hclk" value="16000000"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.useRemoteTarget" value="true"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.launch.vector_table" value=""/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.launch.verify_flash_download" value="true"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.cti_allow_halt" value="false"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.cti_signal_halt" value="false"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_external_loader" value="false"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_logging" value="false"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_max_halt_delay" value="false"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.enable_shared_stlink" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.external_loader" value=""/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.external_loader_init" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.frequency" value="0"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.halt_all_on_reset" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.log_file" value="E:\GIT\BMS_BootloaderPlusSD\Debug\st-link_gdbserver_log.txt"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.low_power_debug" value="enable"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.max_halt_delay" value="2"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.reset_strategy" value="system_reset"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_check_serial_number" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_txt_serial_number" value=""/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.watchdog_config" value="disable"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkenable_rtos" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkrestart_configurations" value="{"fVersion":1,"fItems":[{"fDisplayName":"Reset","fIsSuppressible":false,"fResetAttribute":"Software system reset","fResetStrategies":[{"fDisplayName":"Software system reset","fLaunchAttribute":"system_reset","fGdbCommands":["monitor reset\r\n"],"fCmdOptions":["-g"]},{"fDisplayName":"Hardware reset","fLaunchAttribute":"hardware_reset","fGdbCommands":["monitor reset hardware\r\n"],"fCmdOptions":["-g"]},{"fDisplayName":"Core reset","fLaunchAttribute":"core_reset","fGdbCommands":["monitor reset core\r\n"],"fCmdOptions":["-g"]},{"fDisplayName":"None","fLaunchAttribute":"no_reset","fGdbCommands":[],"fCmdOptions":["-g"]}],"fGdbCommandGroup":{"name":"Additional commands","commands":[]},"fStartApplication":true}]}"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.enableRtosProxy" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyCustomProperties" value=""/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriver" value="threadx"/>
|
||||
<booleanAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriverAuto" value="false"/>
|
||||
<stringAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyDriverPort" value="cortex_m0"/>
|
||||
<intAttribute key="com.st.stm32cube.ide.mcu.rtosproxy.rtosProxyPort" value="60000"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doHalt" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doReset" value="false"/>
|
||||
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.initCommands" value=""/>
|
||||
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
|
||||
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDeviceId" value="com.st.stm32cube.ide.mcu.debug.stlink"/>
|
||||
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
|
||||
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="61234"/>
|
||||
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.runCommands" value=""/>
|
||||
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="true"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
|
||||
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
|
||||
<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="arm-none-eabi-gdb"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.NON_STOP" value="false"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
|
||||
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="remote"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="true"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN_SYMBOL" value="main"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/BMS_BootloaderPlusSD.elf"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="BMS_BootloaderPlusSD"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="true"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.889467840"/>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/BMS_BootloaderPlusSD"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="4"/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><memoryBlockExpressionList context="reserved-for-future-use"/>"/>
|
||||
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
|
||||
</launchConfiguration>
|
||||
275
bootloader/Core/Inc/ffconf.h
Normal file
275
bootloader/Core/Inc/ffconf.h
Normal file
@@ -0,0 +1,275 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* FatFs - FAT file system module configuration file R0.11 (C)ChaN, 2015
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* 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 */
|
||||
|
||||
#ifndef _FFCONF
|
||||
#define _FFCONF 32020 /* Revision ID */
|
||||
|
||||
/*-----------------------------------------------------------------------------/
|
||||
/ Additional user header to be used
|
||||
/-----------------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "stm32f1xx_hal.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------/
|
||||
/ Functions and Buffer Configurations
|
||||
/-----------------------------------------------------------------------------*/
|
||||
|
||||
#define _FS_TINY 0 /* 0:Normal or 1:Tiny */
|
||||
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
|
||||
/ At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS
|
||||
/ bytes. Instead of private sector buffer eliminated from the file object,
|
||||
/ common sector buffer in the file system object (FATFS) is used for the file
|
||||
/ data transfer. */
|
||||
|
||||
#define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */
|
||||
/* 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()
|
||||
/ and optional writing functions as well. */
|
||||
|
||||
#define _FS_MINIMIZE 0 /* 0 to 3 */
|
||||
/* This option defines minimization level to remove some basic API functions.
|
||||
/
|
||||
/ 0: All basic functions are enabled.
|
||||
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_chmod(), f_utime(),
|
||||
/ f_truncate() and f_rename() function are removed.
|
||||
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
|
||||
/ 3: f_lseek() function is removed in addition to 2. */
|
||||
|
||||
#define _USE_STRFUNC 2 /* 0:Disable or 1-2:Enable */
|
||||
/* This option switches string functions, f_gets(), f_putc(), f_puts() and
|
||||
/ f_printf().
|
||||
/
|
||||
/ 0: Disable string functions.
|
||||
/ 1: Enable without LF-CRLF conversion.
|
||||
/ 2: Enable with LF-CRLF conversion. */
|
||||
|
||||
#define _USE_FIND 0
|
||||
/* This option switches filtered directory read feature and related functions,
|
||||
/ f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */
|
||||
|
||||
#define _USE_MKFS 1
|
||||
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
|
||||
|
||||
#define _USE_FASTSEEK 1
|
||||
/* This option switches fast seek feature. (0:Disable or 1:Enable) */
|
||||
|
||||
#define _USE_LABEL 0
|
||||
/* This option switches volume label functions, f_getlabel() and f_setlabel().
|
||||
/ (0:Disable or 1:Enable) */
|
||||
|
||||
#define _USE_FORWARD 0
|
||||
/* This option switches f_forward() function. (0:Disable or 1:Enable)
|
||||
/ To enable it, also _FS_TINY need to be set to 1. */
|
||||
|
||||
/*-----------------------------------------------------------------------------/
|
||||
/ Locale and Namespace Configurations
|
||||
/-----------------------------------------------------------------------------*/
|
||||
|
||||
#define _CODE_PAGE 850
|
||||
/* This option specifies the OEM code page to be used on the target system.
|
||||
/ Incorrect setting of the code page can cause a file open failure.
|
||||
/
|
||||
/ 932 - Japanese Shift_JIS (DBCS, OEM, Windows)
|
||||
/ 936 - Simplified Chinese GBK (DBCS, OEM, Windows)
|
||||
/ 949 - Korean (DBCS, OEM, Windows)
|
||||
/ 950 - Traditional Chinese Big5 (DBCS, OEM, Windows)
|
||||
/ 1250 - Central Europe (Windows)
|
||||
/ 1251 - Cyrillic (Windows)
|
||||
/ 1252 - Latin 1 (Windows)
|
||||
/ 1253 - Greek (Windows)
|
||||
/ 1254 - Turkish (Windows)
|
||||
/ 1255 - Hebrew (Windows)
|
||||
/ 1256 - Arabic (Windows)
|
||||
/ 1257 - Baltic (Windows)
|
||||
/ 1258 - Vietnam (OEM, Windows)
|
||||
/ 437 - U.S. (OEM)
|
||||
/ 720 - Arabic (OEM)
|
||||
/ 737 - Greek (OEM)
|
||||
/ 775 - Baltic (OEM)
|
||||
/ 850 - Multilingual Latin 1 (OEM)
|
||||
/ 858 - Multilingual Latin 1 + Euro (OEM)
|
||||
/ 852 - Latin 2 (OEM)
|
||||
/ 855 - Cyrillic (OEM)
|
||||
/ 866 - Russian (OEM)
|
||||
/ 857 - Turkish (OEM)
|
||||
/ 862 - Hebrew (OEM)
|
||||
/ 874 - Thai (OEM, Windows)
|
||||
/ 1 - ASCII (No extended character. Valid for only non-LFN configuration.) */
|
||||
|
||||
#define _USE_LFN 0 /* 0 to 3 */
|
||||
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
|
||||
/* The _USE_LFN option switches the LFN feature.
|
||||
/
|
||||
/ 0: Disable LFN feature. _MAX_LFN has no effect.
|
||||
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
|
||||
/ 2: Enable LFN with dynamic working buffer on the STACK.
|
||||
/ 3: Enable LFN with dynamic working buffer on the HEAP.
|
||||
/
|
||||
/ When enable the LFN feature, Unicode handling functions (option/unicode.c) must
|
||||
/ be added to the project. The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes.
|
||||
/ When use stack for the working buffer, take care on stack overflow. When use heap
|
||||
/ memory for the working buffer, memory management functions, ff_memalloc() and
|
||||
/ ff_memfree(), must be added to the project. */
|
||||
|
||||
#define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
|
||||
/* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode)
|
||||
/ To use Unicode string for the path name, enable LFN feature and set _LFN_UNICODE
|
||||
/ to 1. This option also affects behavior of string I/O functions. */
|
||||
|
||||
#define _STRF_ENCODE 3
|
||||
/* When _LFN_UNICODE is 1, this option selects the character encoding on the file to
|
||||
/ be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
|
||||
/
|
||||
/ 0: ANSI/OEM
|
||||
/ 1: UTF-16LE
|
||||
/ 2: UTF-16BE
|
||||
/ 3: UTF-8
|
||||
/
|
||||
/ When _LFN_UNICODE is 0, this option has no effect. */
|
||||
|
||||
#define _FS_RPATH 0 /* 0 to 2 */
|
||||
/* This option configures relative path feature.
|
||||
/
|
||||
/ 0: Disable relative path feature and remove related functions.
|
||||
/ 1: Enable relative path feature. f_chdir() and f_chdrive() are available.
|
||||
/ 2: f_getcwd() function is available in addition to 1.
|
||||
/
|
||||
/ Note that directory items read via f_readdir() are affected by this option. */
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Drive/Volume Configurations
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
#define _VOLUMES 1
|
||||
/* Number of volumes (logical drives) to be used. */
|
||||
|
||||
/* USER CODE BEGIN Volumes */
|
||||
#define _STR_VOLUME_ID 0 /* 0:Use only 0-9 for drive ID, 1:Use strings for drive ID */
|
||||
#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
|
||||
/* _STR_VOLUME_ID option switches string volume ID feature.
|
||||
/ When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
|
||||
/ number in the path name. _VOLUME_STRS defines the drive ID strings for each
|
||||
/ logical drives. Number of items must be equal to _VOLUMES. Valid characters for
|
||||
/ the drive ID strings are: A-Z and 0-9. */
|
||||
/* USER CODE END Volumes */
|
||||
|
||||
#define _MULTI_PARTITION 1 /* 0:Single partition, 1:Multiple partition */
|
||||
/* This option switches multi-partition feature. By default (0), each logical drive
|
||||
/ number is bound to the same physical drive number and only an FAT volume found on
|
||||
/ the physical drive will be mounted. When multi-partition feature is enabled (1),
|
||||
/ each logical drive number is bound to arbitrary physical drive and partition
|
||||
/ listed in the VolToPart[]. Also f_fdisk() funciton will be available. */
|
||||
|
||||
#define _MIN_SS 512 /* 512, 1024, 2048 or 4096 */
|
||||
#define _MAX_SS 4096 /* 512, 1024, 2048 or 4096 */
|
||||
/* These options configure the range of sector size to be supported. (512, 1024,
|
||||
/ 2048 or 4096) Always set both 512 for most systems, all type of memory cards and
|
||||
/ harddisk. But a larger value may be required for on-board flash memory and some
|
||||
/ type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured
|
||||
/ to variable sector size and GET_SECTOR_SIZE command must be implemented to the
|
||||
/ disk_ioctl() function. */
|
||||
|
||||
#define _USE_TRIM 0
|
||||
/* This option switches ATA-TRIM feature. (0:Disable or 1:Enable)
|
||||
/ To enable Trim feature, also CTRL_TRIM command should be implemented to the
|
||||
/ disk_ioctl() function. */
|
||||
|
||||
#define _FS_NOFSINFO 0 /* 0,1,2 or 3 */
|
||||
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
|
||||
/ option, and f_getfree() function at first time after volume mount will force
|
||||
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
|
||||
/
|
||||
/ bit0=0: Use free cluster count in the FSINFO if available.
|
||||
/ bit0=1: Do not trust free cluster count in the FSINFO.
|
||||
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
|
||||
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
|
||||
*/
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ System Configurations
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
#define _FS_NORTC 0
|
||||
#define _NORTC_MON 6
|
||||
#define _NORTC_MDAY 4
|
||||
#define _NORTC_YEAR 2015
|
||||
/* The _FS_NORTC option switches timestamp feature. If the system does not have
|
||||
/ an RTC function or valid timestamp is not needed, set _FS_NORTC to 1 to disable
|
||||
/ the timestamp feature. All objects modified by FatFs will have a fixed timestamp
|
||||
/ defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR.
|
||||
/ When timestamp feature is enabled (_FS_NORTC == 0), get_fattime() function need
|
||||
/ to be added to the project to read current time form RTC. _NORTC_MON,
|
||||
/ _NORTC_MDAY and _NORTC_YEAR have no effect.
|
||||
/ These options have no effect at read-only configuration (_FS_READONLY == 1). */
|
||||
|
||||
#define _FS_LOCK 2 /* 0:Disable or >=1:Enable */
|
||||
/* The _FS_LOCK option switches file lock feature to control duplicated file open
|
||||
/ and illegal operation to open objects. This option must be 0 when _FS_READONLY
|
||||
/ is 1.
|
||||
/
|
||||
/ 0: Disable file lock feature. To avoid volume corruption, application program
|
||||
/ should avoid illegal open, remove and rename to the open objects.
|
||||
/ >0: Enable file lock feature. The value defines how many files/sub-directories
|
||||
/ can be opened simultaneously under file lock control. Note that the file
|
||||
/ lock feature is independent of re-entrancy. */
|
||||
|
||||
#define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */
|
||||
#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */
|
||||
#define _SYNC_t NULL
|
||||
/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs
|
||||
/ module itself. Note that regardless of this option, file access to different
|
||||
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
|
||||
/ and f_fdisk() function, are always not re-entrant. Only file/directory access
|
||||
/ to the same volume is under control of this feature.
|
||||
/
|
||||
/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
|
||||
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
|
||||
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
|
||||
/ function, must be added to the project. Samples are available in
|
||||
/ option/syscall.c.
|
||||
/
|
||||
/ The _FS_TIMEOUT defines timeout period in unit of time tick.
|
||||
/ The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
|
||||
/ SemaphoreHandle_t and etc.. */
|
||||
|
||||
#define _WORD_ACCESS 0 /* 0 or 1 */
|
||||
/* The _WORD_ACCESS option is an only platform dependent option. It defines
|
||||
/ which access method is used to the word data on the FAT volume.
|
||||
/
|
||||
/ 0: Byte-by-byte access. Always compatible with all platforms.
|
||||
/ 1: Word access. Do not choose this unless under both the following conditions.
|
||||
/
|
||||
/ * Address misaligned memory access is always allowed to ALL instructions.
|
||||
/ * Byte order on the memory is little-endian.
|
||||
/
|
||||
/ If it is the case, _WORD_ACCESS can also be set to 1 to reduce code size.
|
||||
/ Following table shows allowable settings of some processor types.
|
||||
/
|
||||
/ ARM7TDMI 0 ColdFire 0 V850E 0
|
||||
/ Cortex-M3 0 Z80 0/1 V850ES 0/1
|
||||
/ Cortex-M0 0 x86 0/1 TLCS-870 0/1
|
||||
/ AVR 0/1 RX600(LE) 0/1 TLCS-900 0/1
|
||||
/ AVR32 0 RL78 0 R32C 0
|
||||
/ PIC18 0/1 SH-2 0 M16C 0/1
|
||||
/ PIC24 0 H8S 0 MSP430 0
|
||||
/ PIC32 0 H8/300H 0 8051 0/1
|
||||
*/
|
||||
|
||||
#endif /* _FFCONF */
|
||||
16
bootloader/Core/Inc/generalDefines.h
Normal file
16
bootloader/Core/Inc/generalDefines.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//#define HWVersion_0_3 /* Define this when HW les then HW 0.4 */
|
||||
#define HWVersion_0_4 /* Define this with the newer hardware */
|
||||
|
||||
|
||||
// Hardware name
|
||||
#define HW_NAME "DieBieMS"
|
||||
#define HW_VERSION "V0.5"
|
||||
|
||||
// Firmware version
|
||||
#define FW_VERSION_MAJOR 3
|
||||
#define FW_VERSION_MINOR 29
|
||||
#define FW_REAL_VERSION "V0.11"
|
||||
|
||||
// UUID
|
||||
#define STM32_UUID ((uint32_t*)0x1FFFF7AC)
|
||||
#define STM32_UUID_8 ((uint8_t*)0x1FFFF7AC)
|
||||
40
bootloader/Core/Inc/libBuffer.h
Normal file
40
bootloader/Core/Inc/libBuffer.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright 2016 Benjamin Vedder benjamin@vedder.se
|
||||
|
||||
This file is part of the VESC firmware.
|
||||
|
||||
The VESC firmware is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
The VESC firmware is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef BUFFER_H_
|
||||
#define BUFFER_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index);
|
||||
void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index);
|
||||
void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index);
|
||||
void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index);
|
||||
void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index);
|
||||
void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index);
|
||||
void buffer_append_float32_auto(uint8_t* buffer, float number, int32_t *index);
|
||||
int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index);
|
||||
uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index);
|
||||
int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index);
|
||||
uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index);
|
||||
float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index);
|
||||
float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index);
|
||||
float buffer_get_float32_auto(const uint8_t *buffer, int32_t *index);
|
||||
|
||||
#endif /* BUFFER_H_ */
|
||||
142
bootloader/Core/Inc/main.h
Normal file
142
bootloader/Core/Inc/main.h
Normal file
@@ -0,0 +1,142 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.h
|
||||
* @brief : Header for main.c file.
|
||||
* This file contains the common defines of the application.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* 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 "stm32f1xx_hal.h"
|
||||
|
||||
extern void usbTIM(uint8_t OnOff);
|
||||
|
||||
extern uint16_t load_current;
|
||||
extern uint16_t charge_current;
|
||||
extern float float_current;
|
||||
extern uint8_t load_switch_state;
|
||||
extern uint8_t charge_switch_state;
|
||||
|
||||
extern uint16_t export_adc_average_res;
|
||||
|
||||
extern float export_real_capacity;
|
||||
|
||||
extern float cellVoltageHigh_Maximum;
|
||||
extern float cellVoltageHigh_Maximum_Hyst;
|
||||
extern float maxChargeCurrent;
|
||||
extern float maxLoadCurrent;
|
||||
extern float cellVoltageLow_Minimum;
|
||||
extern float cellVoltageLow_Minimum_Hyst;
|
||||
extern float currentZero_config;
|
||||
|
||||
extern float Brush_Minimum_SoC;
|
||||
extern uint8_t Brush_Default_State;
|
||||
|
||||
extern float maxTemperature;
|
||||
extern float maxTemperature_Hyst;
|
||||
|
||||
|
||||
extern uint8_t Pilot_Status;
|
||||
extern uint8_t Maximum_Charge_Current_Status;
|
||||
extern uint8_t Maximum_Voltage_Status;
|
||||
extern uint8_t Maximum_Temp_Status;
|
||||
extern uint8_t Maximum_Load_Current_Status;
|
||||
extern uint8_t Minimum_Voltage_Status;
|
||||
|
||||
/* 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);
|
||||
|
||||
void UpdateGSMParamsFromConfig();
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
#define Output_2_Pin GPIO_PIN_2
|
||||
#define Output_2_GPIO_Port GPIOE
|
||||
#define Output_3_Pin GPIO_PIN_3
|
||||
#define Output_3_GPIO_Port GPIOE
|
||||
#define Output_4_Pin GPIO_PIN_4
|
||||
#define Output_4_GPIO_Port GPIOE
|
||||
#define Output_5_Pin GPIO_PIN_5
|
||||
#define Output_5_GPIO_Port GPIOE
|
||||
#define SD_CD_Pin GPIO_PIN_10
|
||||
#define SD_CD_GPIO_Port GPIOA
|
||||
#define SPI3_CS_Pin GPIO_PIN_3
|
||||
#define SPI3_CS_GPIO_Port GPIOC
|
||||
#define Input_1_Pin GPIO_PIN_7
|
||||
#define Input_1_GPIO_Port GPIOE
|
||||
#define Input_2_Pin GPIO_PIN_8
|
||||
#define Input_2_GPIO_Port GPIOE
|
||||
#define Input_3_Pin GPIO_PIN_9
|
||||
#define Input_3_GPIO_Port GPIOE
|
||||
#define GSM_RST_Pin GPIO_PIN_10
|
||||
#define GSM_RST_GPIO_Port GPIOE
|
||||
#define HL5_Pin GPIO_PIN_12
|
||||
#define HL5_GPIO_Port GPIOE
|
||||
#define HL4_Pin GPIO_PIN_13
|
||||
#define HL4_GPIO_Port GPIOE
|
||||
#define HL3_Pin GPIO_PIN_14
|
||||
#define HL3_GPIO_Port GPIOE
|
||||
#define HL2_Pin GPIO_PIN_15
|
||||
#define HL2_GPIO_Port GPIOE
|
||||
#define SD_CS_Pin GPIO_PIN_8
|
||||
#define SD_CS_GPIO_Port GPIOA
|
||||
#define Charging_Pin GPIO_PIN_2
|
||||
#define Charging_GPIO_Port GPIOD
|
||||
#define Output_0_Pin GPIO_PIN_0
|
||||
#define Output_0_GPIO_Port GPIOE
|
||||
#define Output_1_Pin GPIO_PIN_1
|
||||
#define Output_1_GPIO_Port GPIOE
|
||||
/* USER CODE BEGIN Private defines */
|
||||
#define SD_SPI_HANDLE hspi1
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
161
bootloader/Core/Inc/modFlash.h
Normal file
161
bootloader/Core/Inc/modFlash.h
Normal file
@@ -0,0 +1,161 @@
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "stdbool.h"
|
||||
|
||||
#ifndef MODFLASH_H__
|
||||
#define MODFLASH_H__
|
||||
|
||||
#define FLASH_PAGES 128
|
||||
#define BOOTLOADER_BASE 104
|
||||
#define MAIN_APP_BASE 0
|
||||
#define NEW_APP_BASE 52
|
||||
#define NEW_APP_SECTORS 52
|
||||
#define NEW_APP_MAX_SIZE (NEW_APP_SECTORS * (1 << 11))
|
||||
|
||||
/* Base address of the Flash sectors */
|
||||
#define ADDR_FLASH_PAGE_0 ((uint32_t)0x08000000) /* Base @ of Page 0, 2 Kbytes */ // Startup Code - Main application
|
||||
#define ADDR_FLASH_PAGE_1 ((uint32_t)0x08000800) /* Base @ of Page 1, 2 Kbytes */ //
|
||||
#define ADDR_FLASH_PAGE_2 ((uint32_t)0x08001000) /* Base @ of Page 2, 2 Kbytes */ //
|
||||
#define ADDR_FLASH_PAGE_3 ((uint32_t)0x08001800) /* Base @ of Page 3, 2 Kbytes */ //
|
||||
#define ADDR_FLASH_PAGE_4 ((uint32_t)0x08002000) /* Base @ of Page 4, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_5 ((uint32_t)0x08002800) /* Base @ of Page 5, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_6 ((uint32_t)0x08003000) /* Base @ of Page 6, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_7 ((uint32_t)0x08003800) /* Base @ of Page 7, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_8 ((uint32_t)0x08004000) /* Base @ of Page 8, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_9 ((uint32_t)0x08004800) /* Base @ of Page 9, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_10 ((uint32_t)0x08005000) /* Base @ of Page 10, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_11 ((uint32_t)0x08005800) /* Base @ of Page 11, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_12 ((uint32_t)0x08006000) /* Base @ of Page 12, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_13 ((uint32_t)0x08006800) /* Base @ of Page 13, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_14 ((uint32_t)0x08007000) /* Base @ of Page 14, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_15 ((uint32_t)0x08007800) /* Base @ of Page 15, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_16 ((uint32_t)0x08008000) /* Base @ of Page 16, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_17 ((uint32_t)0x08008800) /* Base @ of Page 17, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_18 ((uint32_t)0x08009000) /* Base @ of Page 18, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_19 ((uint32_t)0x08009800) /* Base @ of Page 19, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_20 ((uint32_t)0x0800A000) /* Base @ of Page 20, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_21 ((uint32_t)0x0800A800) /* Base @ of Page 21, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_22 ((uint32_t)0x0800B000) /* Base @ of Page 22, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_23 ((uint32_t)0x0800B800) /* Base @ of Page 23, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_24 ((uint32_t)0x0800C000) /* Base @ of Page 24, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_25 ((uint32_t)0x0800C800) /* Base @ of Page 25, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_26 ((uint32_t)0x0800D000) /* Base @ of Page 26, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_27 ((uint32_t)0x0800D800) /* Base @ of Page 27, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_28 ((uint32_t)0x0800E000) /* Base @ of Page 28, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_29 ((uint32_t)0x0800E800) /* Base @ of Page 29, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_30 ((uint32_t)0x0800F000) /* Base @ of Page 30, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_31 ((uint32_t)0x0800F800) /* Base @ of Page 31, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_32 ((uint32_t)0x08010000) /* Base @ of Page 32, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_33 ((uint32_t)0x08010800) /* Base @ of Page 33, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_34 ((uint32_t)0x08011000) /* Base @ of Page 34, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_35 ((uint32_t)0x08011800) /* Base @ of Page 35, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_36 ((uint32_t)0x08012000) /* Base @ of Page 36, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_37 ((uint32_t)0x08012800) /* Base @ of Page 37, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_38 ((uint32_t)0x08013000) /* Base @ of Page 38, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_39 ((uint32_t)0x08013800) /* Base @ of Page 39, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_40 ((uint32_t)0x08014000) /* Base @ of Page 40, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_41 ((uint32_t)0x08014800) /* Base @ of Page 41, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_42 ((uint32_t)0x08015000) /* Base @ of Page 42, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_43 ((uint32_t)0x08015800) /* Base @ of Page 43, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_44 ((uint32_t)0x08016000) /* Base @ of Page 44, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_45 ((uint32_t)0x08016800) /* Base @ of Page 45, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_46 ((uint32_t)0x08017000) /* Base @ of Page 46, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_47 ((uint32_t)0x08017800) /* Base @ of Page 47, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_48 ((uint32_t)0x08018000) /* Base @ of Page 48, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_49 ((uint32_t)0x08018800) /* Base @ of Page 49, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_50 ((uint32_t)0x08019000) /* Base @ of Page 50, 2 Kbytes *///Main ends here
|
||||
#define ADDR_FLASH_PAGE_51 ((uint32_t)0x08019800) /* Base @ of Page 51, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_52 ((uint32_t)0x0801A000) /* Base @ of Page 52, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_53 ((uint32_t)0x0801A800) /* Base @ of Page 53, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_54 ((uint32_t)0x0801B000) /* Base @ of Page 54, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_55 ((uint32_t)0x0801B800) /* Base @ of Page 55, 2 Kbytes */ //NEW app start
|
||||
#define ADDR_FLASH_PAGE_56 ((uint32_t)0x0801C000) /* Base @ of Page 56, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_57 ((uint32_t)0x0801C800) /* Base @ of Page 57, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_58 ((uint32_t)0x0801D000) /* Base @ of Page 58, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_59 ((uint32_t)0x0801D800) /* Base @ of Page 59, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_60 ((uint32_t)0x0801E000) /* Base @ of Page 60, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_61 ((uint32_t)0x0801E800) /* Base @ of Page 61, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_62 ((uint32_t)0x0801F000) /* Base @ of Page 62, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_63 ((uint32_t)0x0801F800) /* Base @ of Page 63, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_64 ((uint32_t)0x08020000) /* Base @ of Page 64, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_65 ((uint32_t)0x08020800) /* Base @ of Page 65, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_66 ((uint32_t)0x08021000) /* Base @ of Page 66, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_67 ((uint32_t)0x08021800) /* Base @ of Page 67, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_68 ((uint32_t)0x08022000) /* Base @ of Page 68, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_69 ((uint32_t)0x08022800) /* Base @ of Page 69, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_70 ((uint32_t)0x08023000) /* Base @ of Page 70, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_71 ((uint32_t)0x08023800) /* Base @ of Page 71, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_72 ((uint32_t)0x08024000) /* Base @ of Page 72, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_73 ((uint32_t)0x08024800) /* Base @ of Page 73, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_74 ((uint32_t)0x08025000) /* Base @ of Page 74, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_75 ((uint32_t)0x08025800) /* Base @ of Page 75, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_76 ((uint32_t)0x08026000) /* Base @ of Page 76, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_77 ((uint32_t)0x08026800) /* Base @ of Page 77, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_78 ((uint32_t)0x08027000) /* Base @ of Page 78, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_79 ((uint32_t)0x08027800) /* Base @ of Page 79, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_80 ((uint32_t)0x08028000) /* Base @ of Page 80, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_81 ((uint32_t)0x08028800) /* Base @ of Page 81, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_82 ((uint32_t)0x08029000) /* Base @ of Page 82, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_83 ((uint32_t)0x08029800) /* Base @ of Page 83, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_84 ((uint32_t)0x0802A000) /* Base @ of Page 84, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_85 ((uint32_t)0x0802A800) /* Base @ of Page 85, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_86 ((uint32_t)0x0802B000) /* Base @ of Page 86, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_87 ((uint32_t)0x0802B800) /* Base @ of Page 87, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_88 ((uint32_t)0x0802C000) /* Base @ of Page 88, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_89 ((uint32_t)0x0802C800) /* Base @ of Page 89, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_90 ((uint32_t)0x0802D000) /* Base @ of Page 90, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_91 ((uint32_t)0x0802D800) /* Base @ of Page 91, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_92 ((uint32_t)0x0802E000) /* Base @ of Page 92, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_93 ((uint32_t)0x0802E800) /* Base @ of Page 93, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_94 ((uint32_t)0x0802F000) /* Base @ of Page 94, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_95 ((uint32_t)0x0802F800) /* Base @ of Page 95, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_96 ((uint32_t)0x08030000) /* Base @ of Page 96, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_97 ((uint32_t)0x08030800) /* Base @ of Page 97, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_98 ((uint32_t)0x08031000) /* Base @ of Page 98, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_99 ((uint32_t)0x08031800) /* Base @ of Page 99, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_100 ((uint32_t)0x08032000) /* Base @ of Page 100, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_101 ((uint32_t)0x08032800) /* Base @ of Page 101, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_102 ((uint32_t)0x08033000) /* Base @ of Page 102, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_103 ((uint32_t)0x08033800) /* Base @ of Page 103, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_104 ((uint32_t)0x08034000) /* Base @ of Page 104, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_105 ((uint32_t)0x08034800) /* Base @ of Page 105, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_106 ((uint32_t)0x08035000) /* Base @ of Page 106, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_107 ((uint32_t)0x08035800) /* Base @ of Page 107, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_108 ((uint32_t)0x08036000) /* Base @ of Page 108, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_109 ((uint32_t)0x08036800) /* Base @ of Page 109, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_110 ((uint32_t)0x08037000) /* Base @ of Page 110, 2 Kbytes */ //bootloader
|
||||
#define ADDR_FLASH_PAGE_111 ((uint32_t)0x08037800) /* Base @ of Page 111, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_112 ((uint32_t)0x08038000) /* Base @ of Page 112, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_113 ((uint32_t)0x08038800) /* Base @ of Page 113, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_114 ((uint32_t)0x08039000) /* Base @ of Page 114, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_115 ((uint32_t)0x08039800) /* Base @ of Page 115, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_116 ((uint32_t)0x0803A000) /* Base @ of Page 116, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_117 ((uint32_t)0x0803A800) /* Base @ of Page 117, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_118 ((uint32_t)0x0803B000) /* Base @ of Page 118, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_119 ((uint32_t)0x0803B800) /* Base @ of Page 119, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_120 ((uint32_t)0x0803C000) /* Base @ of Page 120, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_121 ((uint32_t)0x0803C800) /* Base @ of Page 121, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_122 ((uint32_t)0x0803D000) /* Base @ of Page 122, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_123 ((uint32_t)0x0803D800) /* Base @ of Page 123, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_124 ((uint32_t)0x0803E000) /* Base @ of Page 124, 2 Kbytes */
|
||||
#define ADDR_FLASH_PAGE_125 ((uint32_t)0x0803E800) /* Base @ of Page 125, 2 Kbytes */ //EEprom page1
|
||||
#define ADDR_FLASH_PAGE_126 ((uint32_t)0x0803F000) /* Base @ of Page 126, 2 Kbytes */ //EEprom page2
|
||||
#define ADDR_FLASH_PAGE_127 ((uint32_t)0x0803F800) /* Base @ of Page 127, 2 Kbytes */ // uC flash ends here
|
||||
|
||||
|
||||
typedef void (application_t)(void);
|
||||
|
||||
typedef struct{
|
||||
uint32_t stack_addr;
|
||||
application_t* func_p;
|
||||
} JumpStruct;
|
||||
|
||||
uint16_t modFlashEraseNewAppData();
|
||||
uint16_t modFlashEraseMainAppData();
|
||||
uint16_t modFlashEraseSettingsData();
|
||||
//uint16_t modFlashWriteNewAppData(uint32_t offset, uint8_t *data, uint32_t len);
|
||||
uint16_t modFlashCopyNewAppToMainApp(uint32_t offset, uint8_t *data, uint32_t len);
|
||||
void modFlashJumpToBootloader(void);
|
||||
void modFlashJumpToMainApplication(void);
|
||||
void jumpToBootLoader(void);
|
||||
|
||||
#endif
|
||||
55
bootloader/Core/Inc/rtc.h
Normal file
55
bootloader/Core/Inc/rtc.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rtc.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the rtc.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* 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__
|
||||
|
||||
#ifndef __GSMMODULE_H
|
||||
#endif
|
||||
|
||||
|
||||
#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****/
|
||||
176
bootloader/Core/Src/libBuffer.c
Normal file
176
bootloader/Core/Src/libBuffer.c
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
Copyright 2016 Benjamin Vedder benjamin@vedder.se
|
||||
|
||||
This file is part of the VESC firmware.
|
||||
|
||||
The VESC firmware is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
The VESC firmware is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "libBuffer.h"
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index) {
|
||||
buffer[(*index)++] = number >> 8;
|
||||
buffer[(*index)++] = number;
|
||||
}
|
||||
|
||||
void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index) {
|
||||
buffer[(*index)++] = number >> 8;
|
||||
buffer[(*index)++] = number;
|
||||
}
|
||||
|
||||
void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index) {
|
||||
buffer[(*index)++] = number >> 24;
|
||||
buffer[(*index)++] = number >> 16;
|
||||
buffer[(*index)++] = number >> 8;
|
||||
buffer[(*index)++] = number;
|
||||
}
|
||||
|
||||
void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index) {
|
||||
buffer[(*index)++] = number >> 24;
|
||||
buffer[(*index)++] = number >> 16;
|
||||
buffer[(*index)++] = number >> 8;
|
||||
buffer[(*index)++] = number;
|
||||
}
|
||||
|
||||
void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index) {
|
||||
buffer_append_int16(buffer, (int16_t)(number * scale), index);
|
||||
}
|
||||
|
||||
void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index) {
|
||||
buffer_append_int32(buffer, (int32_t)(number * scale), index);
|
||||
}
|
||||
|
||||
/*
|
||||
* See my question:
|
||||
* http://stackoverflow.com/questions/40416682/portable-way-to-serialize-float-as-32-bit-integer
|
||||
*
|
||||
* Regarding the float32_auto functions:
|
||||
*
|
||||
* Noticed that frexp and ldexp fit the format of the IEEE float representation, so
|
||||
* they should be quite fast. They are (more or less) equivalent with the following:
|
||||
*
|
||||
* float frexp_slow(float f, int *e) {
|
||||
* if (f == 0.0) {
|
||||
* *e = 0;
|
||||
* return 0.0;
|
||||
* }
|
||||
*
|
||||
* *e = ceilf(log2f(fabsf(f)));
|
||||
* float res = f / powf(2.0, (float)*e);
|
||||
*
|
||||
* if (res >= 1.0) {
|
||||
* res -= 0.5;
|
||||
* *e += 1;
|
||||
* }
|
||||
*
|
||||
* if (res <= -1.0) {
|
||||
* res += 0.5;
|
||||
* *e += 1;
|
||||
* }
|
||||
*
|
||||
* return res;
|
||||
* }
|
||||
*
|
||||
* float ldexp_slow(float f, int e) {
|
||||
* return f * powf(2.0, (float)e);
|
||||
* }
|
||||
*
|
||||
* 8388608.0 is 2^23, which scales the result to fit within 23 bits if sig_abs < 1.0.
|
||||
*
|
||||
* This should be a relatively fast and efficient way to serialize
|
||||
* floating point numbers in a fully defined manner.
|
||||
*/
|
||||
void buffer_append_float32_auto(uint8_t* buffer, float number, int32_t *index) {
|
||||
int e = 0;
|
||||
float sig = frexpf(number, &e);
|
||||
float sig_abs = fabsf(sig);
|
||||
uint32_t sig_i = 0;
|
||||
|
||||
if (sig_abs >= 0.5f) {
|
||||
sig_i = (uint32_t)((sig_abs - 0.5f) * 2.0f * 8388608.0f);
|
||||
e += 126;
|
||||
}
|
||||
|
||||
uint32_t res = ((e & 0xFF) << 23) | (sig_i & 0x7FFFFF);
|
||||
if (sig < 0) {
|
||||
//res |= 1 << 31;
|
||||
res |= 0x80000000;
|
||||
}
|
||||
|
||||
buffer_append_uint32(buffer, res, index);
|
||||
}
|
||||
|
||||
int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index) {
|
||||
int16_t res = ((uint16_t) buffer[*index]) << 8 |
|
||||
((uint16_t) buffer[*index + 1]);
|
||||
*index += 2;
|
||||
return res;
|
||||
}
|
||||
|
||||
uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index) {
|
||||
uint16_t res = ((uint16_t) buffer[*index]) << 8 |
|
||||
((uint16_t) buffer[*index + 1]);
|
||||
*index += 2;
|
||||
return res;
|
||||
}
|
||||
|
||||
int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index) {
|
||||
int32_t res = ((uint32_t) buffer[*index]) << 24 |
|
||||
((uint32_t) buffer[*index + 1]) << 16 |
|
||||
((uint32_t) buffer[*index + 2]) << 8 |
|
||||
((uint32_t) buffer[*index + 3]);
|
||||
*index += 4;
|
||||
return res;
|
||||
}
|
||||
|
||||
uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index) {
|
||||
uint32_t res = ((uint32_t) buffer[*index]) << 24 |
|
||||
((uint32_t) buffer[*index + 1]) << 16 |
|
||||
((uint32_t) buffer[*index + 2]) << 8 |
|
||||
((uint32_t) buffer[*index + 3]);
|
||||
*index += 4;
|
||||
return res;
|
||||
}
|
||||
|
||||
float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index) {
|
||||
return (float)buffer_get_int16(buffer, index) / scale;
|
||||
}
|
||||
|
||||
float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index) {
|
||||
return (float)buffer_get_int32(buffer, index) / scale;
|
||||
}
|
||||
|
||||
float buffer_get_float32_auto(const uint8_t *buffer, int32_t *index) {
|
||||
uint32_t res = buffer_get_uint32(buffer, index);
|
||||
|
||||
int e = (res >> 23) & 0xFF;
|
||||
uint32_t sig_i = res & 0x7FFFFF;
|
||||
//bool neg = res & (1 << 31);
|
||||
bool neg = res & (0x80000000);
|
||||
|
||||
|
||||
float sig = 0.0;
|
||||
if (e != 0 || sig_i != 0) {
|
||||
sig = (float)sig_i / (8388608.0 * 2.0) + 0.5;
|
||||
e -= 126;
|
||||
}
|
||||
|
||||
if (neg) {
|
||||
sig = -sig;
|
||||
}
|
||||
|
||||
return ldexpf(sig, e);
|
||||
}
|
||||
824
bootloader/Core/Src/main.c
Normal file
824
bootloader/Core/Src/main.c
Normal file
@@ -0,0 +1,824 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* 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 "usb_device.h"
|
||||
#include "rtc.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include "stdint.h"
|
||||
#include "stdbool.h"
|
||||
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "modDelay.h"
|
||||
#include "modFlash.h"
|
||||
//#include "DPC_Timeout.h"
|
||||
#include "fatfs.h"
|
||||
#include "generalDefines.h"
|
||||
#include "libBuffer.h"
|
||||
#include "libCRC.h"
|
||||
|
||||
|
||||
#define LoByte(param) ((uint8_t *)¶m)[0]
|
||||
#define HiByte(param) ((uint8_t *)¶m)[1]
|
||||
|
||||
#define LoLoWord(param) ((uint16_t *)¶m)[0]
|
||||
#define LoHiWord(param) ((uint16_t *)¶m)[1]
|
||||
#define HiLoWord(param) ((uint16_t *)¶m)[2]
|
||||
#define HiHiWord(param) ((uint16_t *)¶m)[3]
|
||||
|
||||
#define LoWord(param) ((uint32_t *)¶m)[0]
|
||||
#define HiWord(param) ((uint32_t *)¶m)[1]
|
||||
|
||||
#define __DEEP_DISCHARGE_RATIO 0.8 //As a percent of undervoltage
|
||||
#define __STATUS_POWER_ON 1
|
||||
#define __STATUS_POWER_OFF 2
|
||||
#define __STATUS_CHARGE_ON 3 //Pilot contact exist
|
||||
#define __STATUS_CELL_UNDERVOLTAGE 4 //Cell below discharge level
|
||||
#define __STATUS_OVERLOAD 5 //Load current too high
|
||||
#define __STATUS_OVERHEATING 6 //Temp too high
|
||||
#define __STATUS_CHARGING_OVERVOLTAGE 7 //Cell voltage above max level
|
||||
#define __STATUS_CHARGING_DISCONNECT 8 //Pilot contact disconnect
|
||||
#define __STATUS_HEATING_ON 9 //
|
||||
#define __STATUS_HEATING_OFF 10 //
|
||||
#define __STATUS_TAKE_BRUSH 11 //Brush is in the upper state
|
||||
#define __STATUS_ERROR_1 12
|
||||
#define __STATUS_ERROR_2 13
|
||||
|
||||
#define __GLSTATUS_SHUTDOWN 1
|
||||
#define __GLSTATUS_IDLE 2
|
||||
#define __GLSTATUS_WORKING 3
|
||||
#define __GLSTATUS_CHARGING 4
|
||||
#define __GLSTATUS_ERROR 5
|
||||
|
||||
|
||||
#define __DEFAULT_BATTERY_RESISTANCE 0.0
|
||||
#define __BACKUP_TIMEOUT 30000
|
||||
#define __GRT_PERIOD 600000//3600000
|
||||
#define __DELAY_FOR_SIM 30000
|
||||
//#define __GRT_PERIOD 600000
|
||||
|
||||
#define _ON 1
|
||||
#define _OFF 0
|
||||
|
||||
#define __BLINK_INIT 1000
|
||||
#define __BLINK_GSM_AND_SD_OK 500
|
||||
#define __BLINK_SD_OK_NO_GSM 250
|
||||
#define __BLINK_GSM_OK_NO_SD 750
|
||||
#define __BLINK_ERROR 100
|
||||
|
||||
#define __SD_BUFFER_MAX_VAL 8
|
||||
#define __SS_BUFFER_MAX_VAL 8
|
||||
|
||||
#define __FILENAME_UPDATE_TIMEOUT 10000
|
||||
|
||||
|
||||
__IO uint8_t USB_On_Flag;
|
||||
|
||||
__IO uint32_t SS_status_ptr;
|
||||
|
||||
__IO uint64_t _global_clock;
|
||||
|
||||
|
||||
SPI_HandleTypeDef hspi1;
|
||||
|
||||
TIM_HandleTypeDef htim2;
|
||||
TIM_HandleTypeDef htim6;
|
||||
|
||||
#define __MA_WIN_SIZE (500)
|
||||
#define __MA_ARRAY_QTY 2
|
||||
|
||||
uint32_t SD_Storage_Switch;
|
||||
|
||||
typedef enum {
|
||||
BOOT_INIT = 0,
|
||||
BOOT_DELAY,
|
||||
BOOT_SIZE_CHECK,
|
||||
BOOT_SIZE_ZERO,
|
||||
BOOT_SIZE_WRONG,
|
||||
BOOT_SIZE_OK,
|
||||
BOOT_CRC_CHECK,
|
||||
BOOT_CRC_OK,
|
||||
BOOT_CRC_ERROR,
|
||||
BOOT_ERASE,
|
||||
BOOT_ERASE_ERROR,
|
||||
BOOT_ERASE_SUCCES,
|
||||
BOOT_COPYAPP,
|
||||
BOOT_COPYAPP_ERROR,
|
||||
BOOT_COPYAPP_SUCCES,
|
||||
BOOT_DONE,
|
||||
BOOT_REBOOT,
|
||||
BOOT_ERROR
|
||||
} bootLoaderState;
|
||||
|
||||
uint8_t bootloaderStateCurrent;
|
||||
uint8_t bootloaderStateNext;
|
||||
uint32_t bootloaderDelayLastTick;
|
||||
uint32_t bootloaderDelayTime;
|
||||
uint8_t* newAppAdress;
|
||||
uint32_t newAppSize;
|
||||
uint32_t newAppCRC;
|
||||
int32_t indexPointer;
|
||||
uint8_t yAxisOffset;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void Total_DeInit();
|
||||
void SystemClock_Config(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
|
||||
|
||||
static void MX_SPI1_Init(void);
|
||||
static void MX_TIM6_Init(void);
|
||||
static void MX_TIM2_Init(void);
|
||||
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
// testsi++;
|
||||
|
||||
|
||||
if (htim->Instance == TIM2)
|
||||
{
|
||||
TimeoutMng();
|
||||
_global_clock++;
|
||||
}
|
||||
else if (htim->Instance == TIM6)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
/* USER CODE END 0 */
|
||||
|
||||
|
||||
IWDG_HandleTypeDef handleIWDG;
|
||||
|
||||
void mainWatchDogReset(void) {
|
||||
|
||||
HAL_IWDG_Refresh(&handleIWDG);
|
||||
|
||||
}
|
||||
void mainWatchDogInitAndStart(void) {
|
||||
|
||||
|
||||
handleIWDG.Instance = IWDG;
|
||||
handleIWDG.Init.Prescaler = IWDG_PRESCALER_64;
|
||||
// handleIWDG.Init.Window = 4095;
|
||||
handleIWDG.Init.Reload = 4095;
|
||||
if (HAL_IWDG_Init(&handleIWDG) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
// HAL_IWDG_
|
||||
// if(HAL_IWDG_Start(&handleIWDG) != HAL_OK) {
|
||||
// Error_Handler();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
void heart_beat(){
|
||||
static uint32_t timer = 0;
|
||||
if(( (HAL_GetTick()) - timer ) > __BLINK_SD_OK_NO_GSM) {
|
||||
//HAL_GPIO_TogglePin(HL3_GPIO_Port, HL3_Pin);
|
||||
HAL_GPIO_TogglePin(HL3_GPIO_Port, HL5_Pin);
|
||||
// HAL_GPIO_TogglePin(HL3_GPIO_Port, HL1_Pin);
|
||||
//HAL_GPIO_TogglePin(HL2_GPIO_Port, HL2_Pin);
|
||||
timer = HAL_GetTick();
|
||||
}
|
||||
}
|
||||
|
||||
void Total_DeInit(){
|
||||
MX_FATFS_DeInit();
|
||||
HAL_TIM_Base_DeInit(&htim2);
|
||||
HAL_TIM_Base_DeInit(&htim6);
|
||||
MX_USB_DEVICE_DeInit();
|
||||
//HAL_UART_DeInit(&huart2);
|
||||
HAL_SPI_DeInit(&hspi1);
|
||||
//HAL_SPI_DeInit(&hspi3);
|
||||
//HAL_DAC_DeInit(&hdac);
|
||||
//HAL_ADC_DeInit(&hadc2);
|
||||
HAL_RTC_DeInit(&hrtc);
|
||||
|
||||
__HAL_RCC_GPIOE_CLK_DISABLE();
|
||||
__HAL_RCC_GPIOC_CLK_DISABLE();
|
||||
__HAL_RCC_GPIOA_CLK_DISABLE();
|
||||
__HAL_RCC_GPIOB_CLK_DISABLE();
|
||||
__HAL_RCC_GPIOD_CLK_DISABLE();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
SCB->VTOR = ADDR_FLASH_PAGE_104;
|
||||
/* 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();
|
||||
// modFlashJumpToBootloader();
|
||||
//jumpToBootLoader();
|
||||
|
||||
//HAL_Delay(2000);
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
// HAL_GPIO_WritePin(GSM_RST_GPIO_Port, GSM_RST_Pin, GPIO_PIN_RESET);
|
||||
|
||||
HAL_GPIO_WritePin(HL2_GPIO_Port, HL2_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL5_GPIO_Port, HL5_Pin, GPIO_PIN_SET);
|
||||
HAL_Delay(200);
|
||||
HAL_GPIO_WritePin(HL2_GPIO_Port, HL2_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL5_GPIO_Port, HL5_Pin, GPIO_PIN_RESET);
|
||||
HAL_Delay(200);
|
||||
HAL_GPIO_WritePin(HL2_GPIO_Port, HL2_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL5_GPIO_Port, HL5_Pin, GPIO_PIN_SET);
|
||||
HAL_Delay(200);
|
||||
HAL_GPIO_WritePin(HL2_GPIO_Port, HL2_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL5_GPIO_Port, HL5_Pin, GPIO_PIN_RESET);
|
||||
HAL_Delay(200);
|
||||
|
||||
yAxisOffset = 0;
|
||||
newAppAdress = (uint8_t*)ADDR_FLASH_PAGE_52;
|
||||
indexPointer = 0;
|
||||
newAppSize = buffer_get_uint32(newAppAdress, &indexPointer);
|
||||
newAppCRC = buffer_get_uint16(newAppAdress, &indexPointer);
|
||||
bootloaderStateCurrent = BOOT_INIT;
|
||||
bootloaderStateNext = BOOT_INIT;
|
||||
bootloaderDelayTime = 100;
|
||||
|
||||
// jumpToBootLoader();
|
||||
|
||||
MX_RTC_Init();
|
||||
|
||||
SD_Storage_Switch = HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR11);
|
||||
|
||||
//SD_Storage_Switch=1;
|
||||
|
||||
if (SD_Storage_Switch){
|
||||
MX_SPI1_Init();
|
||||
MX_USB_DEVICE_Init();
|
||||
MX_FATFS_Init();
|
||||
MX_TIM6_Init();
|
||||
MX_TIM2_Init();
|
||||
}
|
||||
|
||||
|
||||
// MX_SPI3_Init();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//jumpToBootLoader();// here it works
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
|
||||
|
||||
/* USER CODE BEGIN WHILE */
|
||||
|
||||
bootloaderDelayLastTick = HAL_GetTick();
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
|
||||
if (SD_Storage_Switch){
|
||||
heart_beat();
|
||||
}
|
||||
else {
|
||||
switch(bootloaderStateCurrent) {
|
||||
case BOOT_INIT:
|
||||
// modDisplayShowInfo(DISP_MODE_BOOTLOADER,emptyData);
|
||||
HAL_GPIO_WritePin(HL2_GPIO_Port, HL2_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_SET);
|
||||
bootloaderDelayTime = 200;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
bootloaderStateNext = BOOT_SIZE_CHECK;
|
||||
break;
|
||||
case BOOT_DELAY:
|
||||
if(modDelayTick1ms(&bootloaderDelayLastTick,bootloaderDelayTime))
|
||||
bootloaderStateCurrent = bootloaderStateNext;
|
||||
break;
|
||||
case BOOT_SIZE_CHECK:
|
||||
HAL_GPIO_WritePin(HL2_GPIO_Port, HL2_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL5_GPIO_Port, HL5_Pin, GPIO_PIN_RESET);
|
||||
|
||||
if(newAppSize == 0)
|
||||
bootloaderStateNext = BOOT_SIZE_ZERO;
|
||||
else if(newAppSize > NEW_APP_MAX_SIZE)
|
||||
bootloaderStateNext = BOOT_SIZE_WRONG;
|
||||
else
|
||||
bootloaderStateNext = BOOT_SIZE_OK;
|
||||
|
||||
|
||||
bootloaderDelayTime = 100;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
case BOOT_SIZE_ZERO:
|
||||
bootloaderStateNext = BOOT_REBOOT;
|
||||
|
||||
bootloaderDelayTime = 100;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
case BOOT_SIZE_WRONG:
|
||||
bootloaderStateNext = BOOT_REBOOT;
|
||||
|
||||
bootloaderDelayTime = 100;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
case BOOT_SIZE_OK:
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_SET);
|
||||
bootloaderDelayTime = 1000;
|
||||
bootloaderStateNext = BOOT_CRC_CHECK;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
case BOOT_CRC_CHECK:
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_RESET);
|
||||
|
||||
if(newAppCRC != libCRCCalcCRC16(newAppAdress + indexPointer, newAppSize))
|
||||
bootloaderStateNext = BOOT_CRC_ERROR;
|
||||
else
|
||||
bootloaderStateNext = BOOT_CRC_OK;
|
||||
|
||||
bootloaderDelayTime = 100;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
case BOOT_CRC_OK:
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_SET);
|
||||
bootloaderDelayTime = 1000;
|
||||
bootloaderStateNext = BOOT_ERASE;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
case BOOT_CRC_ERROR:
|
||||
|
||||
bootloaderStateNext = BOOT_REBOOT;
|
||||
|
||||
bootloaderDelayTime = 100;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
case BOOT_ERASE:
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_RESET);
|
||||
// Code to erasing main flash
|
||||
if(modFlashEraseMainAppData() == HAL_OK)
|
||||
bootloaderStateNext = BOOT_ERASE_SUCCES;
|
||||
else
|
||||
bootloaderStateNext = BOOT_ERASE_ERROR;
|
||||
|
||||
bootloaderDelayTime = 100;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
case BOOT_ERASE_ERROR:
|
||||
HAL_GPIO_WritePin(HL5_GPIO_Port, HL5_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL5_GPIO_Port, HL5_Pin, GPIO_PIN_SET);
|
||||
|
||||
bootloaderStateNext = BOOT_ERROR;
|
||||
|
||||
bootloaderDelayTime = 1000;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
case BOOT_ERASE_SUCCES:
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_SET);
|
||||
bootloaderStateNext = BOOT_COPYAPP;
|
||||
//bootloaderStateNext = BOOT_DELAY;
|
||||
bootloaderDelayTime = 1000;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
case BOOT_COPYAPP:
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_RESET);
|
||||
// Code to copy new app to main flash
|
||||
if(modFlashCopyNewAppToMainApp(0, newAppAdress + indexPointer, newAppSize) == HAL_OK){
|
||||
bootloaderStateNext = BOOT_COPYAPP_SUCCES;
|
||||
}
|
||||
else{
|
||||
bootloaderStateNext = BOOT_COPYAPP_ERROR;
|
||||
}
|
||||
|
||||
|
||||
bootloaderDelayTime = 100;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
case BOOT_COPYAPP_ERROR:
|
||||
HAL_GPIO_WritePin(HL2_GPIO_Port, HL2_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL5_GPIO_Port, HL5_Pin, GPIO_PIN_RESET);
|
||||
bootloaderStateNext = BOOT_ERROR;
|
||||
bootloaderDelayTime = 1000;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
case BOOT_COPYAPP_SUCCES:
|
||||
HAL_GPIO_WritePin(HL2_GPIO_Port, HL2_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL5_GPIO_Port, HL5_Pin, GPIO_PIN_SET);
|
||||
|
||||
modFlashEraseNewAppData();
|
||||
modFlashEraseSettingsData();
|
||||
|
||||
bootloaderStateNext = BOOT_DONE;
|
||||
|
||||
bootloaderDelayTime = 1000;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
case BOOT_DONE:
|
||||
HAL_GPIO_WritePin(HL2_GPIO_Port, HL2_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(HL5_GPIO_Port, HL5_Pin, GPIO_PIN_RESET);
|
||||
|
||||
bootloaderStateNext = BOOT_REBOOT;
|
||||
|
||||
bootloaderDelayTime = 5000;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
case BOOT_REBOOT:
|
||||
jumpToMainApplication();
|
||||
break;
|
||||
case BOOT_ERROR:
|
||||
|
||||
HAL_GPIO_WritePin(HL2_GPIO_Port, HL2_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL3_GPIO_Port, HL3_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL4_GPIO_Port, HL4_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(HL5_GPIO_Port, HL5_Pin, GPIO_PIN_SET);
|
||||
|
||||
// Do nothing but keep showing error.
|
||||
bootloaderStateNext = BOOT_INIT;
|
||||
bootloaderDelayTime = 5000;
|
||||
bootloaderStateCurrent = BOOT_DELAY;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
|
||||
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV5;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.Prediv1Source = RCC_PREDIV1_SOURCE_PLL2;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
|
||||
RCC_OscInitStruct.PLL2.PLL2State = RCC_PLL2_ON;
|
||||
RCC_OscInitStruct.PLL2.PLL2MUL = RCC_PLL2_MUL8;
|
||||
RCC_OscInitStruct.PLL2.HSEPrediv2Value = RCC_HSE_PREDIV2_DIV5;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_ADC
|
||||
|RCC_PERIPHCLK_USB;
|
||||
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
|
||||
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
|
||||
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV3;
|
||||
|
||||
|
||||
|
||||
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Configure the Systick interrupt time
|
||||
*/
|
||||
__HAL_RCC_PLLI2S_ENABLE();
|
||||
}
|
||||
|
||||
static 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};
|
||||
|
||||
/* USER CODE BEGIN TIM2_Init 1 */
|
||||
|
||||
/* USER CODE END TIM2_Init 1 */
|
||||
htim2.Instance = TIM2;
|
||||
htim2.Init.Prescaler = 71;
|
||||
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim2.Init.Period = 999;
|
||||
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
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();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM2_Init 2 */
|
||||
|
||||
/* USER CODE END TIM2_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
static void MX_TIM6_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN TIM6_Init 0 */
|
||||
|
||||
/* USER CODE END TIM6_Init 0 */
|
||||
|
||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN TIM6_Init 1 */
|
||||
|
||||
/* USER CODE END TIM6_Init 1 */
|
||||
htim6.Instance = TIM6;
|
||||
htim6.Init.Prescaler = 71;
|
||||
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim6.Init.Period = 999;
|
||||
htim6.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM6_Init 2 */
|
||||
|
||||
/* USER CODE END TIM6_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief SPI1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static 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 */
|
||||
/* SPI1 parameter configuration*/
|
||||
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_1EDGE;
|
||||
hspi1.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
|
||||
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
hspi1.Init.CRCPolynomial = 10;
|
||||
if (HAL_SPI_Init(&hspi1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN SPI1_Init 2 */
|
||||
|
||||
/* USER CODE END SPI1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOE, Output_2_Pin|Output_3_Pin|Output_4_Pin|Output_5_Pin
|
||||
|GSM_RST_Pin|HL4_Pin|HL5_Pin|HL3_Pin|HL2_Pin|Output_0_Pin
|
||||
|Output_1_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(SPI3_CS_GPIO_Port, SPI3_CS_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(SD_CS_GPIO_Port, SD_CS_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(Charging_GPIO_Port, Charging_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pins : Output_2_Pin Output_3_Pin Output_4_Pin Output_5_Pin
|
||||
HL3_Pin HL2_Pin Output_0_Pin Output_1_Pin */
|
||||
GPIO_InitStruct.Pin = Output_2_Pin|Output_3_Pin|Output_4_Pin|Output_5_Pin
|
||||
|HL5_Pin|HL3_Pin|HL4_Pin|HL2_Pin|Output_0_Pin|Output_1_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PE6 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_6;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : SD_CD_Pin */
|
||||
GPIO_InitStruct.Pin = SD_CD_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(SD_CD_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : SPI3_CS_Pin */
|
||||
GPIO_InitStruct.Pin = SPI3_CS_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(SPI3_CS_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
// GPIO_InitStruct.Pin = LTC6804_CS_Pin;
|
||||
//GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
//GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
//GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
//GPIO_InitStruct.Alternate = 0;
|
||||
//HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : Input_1_Pin Input_2_Pin Input_3_Pin */
|
||||
GPIO_InitStruct.Pin = Input_1_Pin|Input_2_Pin|Input_3_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : GSM_RST_Pin */
|
||||
GPIO_InitStruct.Pin = GSM_RST_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GSM_RST_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : SD_CS_Pin */
|
||||
GPIO_InitStruct.Pin = SD_CS_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(SD_CS_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : Charging_Pin */
|
||||
GPIO_InitStruct.Pin = Charging_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(Charging_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
void jumpToMainApplication(void) {
|
||||
HAL_RCC_DeInit();
|
||||
HAL_DeInit();
|
||||
SysTick->CTRL = 0;
|
||||
SysTick->LOAD = 0;
|
||||
SysTick->VAL = 0;
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
/* 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****/
|
||||
384
bootloader/Core/Src/modFlash.c
Normal file
384
bootloader/Core/Src/modFlash.c
Normal file
@@ -0,0 +1,384 @@
|
||||
#include "modFlash.h"
|
||||
|
||||
static const uint32_t flash_addr[FLASH_PAGES] = {
|
||||
ADDR_FLASH_PAGE_0,
|
||||
ADDR_FLASH_PAGE_1,
|
||||
ADDR_FLASH_PAGE_2,
|
||||
ADDR_FLASH_PAGE_3,
|
||||
ADDR_FLASH_PAGE_4,
|
||||
ADDR_FLASH_PAGE_5,
|
||||
ADDR_FLASH_PAGE_6,
|
||||
ADDR_FLASH_PAGE_7,
|
||||
ADDR_FLASH_PAGE_8,
|
||||
ADDR_FLASH_PAGE_9,
|
||||
ADDR_FLASH_PAGE_10,
|
||||
ADDR_FLASH_PAGE_11,
|
||||
ADDR_FLASH_PAGE_12,
|
||||
ADDR_FLASH_PAGE_13,
|
||||
ADDR_FLASH_PAGE_14,
|
||||
ADDR_FLASH_PAGE_15,
|
||||
ADDR_FLASH_PAGE_16,
|
||||
ADDR_FLASH_PAGE_17,
|
||||
ADDR_FLASH_PAGE_18,
|
||||
ADDR_FLASH_PAGE_19,
|
||||
ADDR_FLASH_PAGE_20,
|
||||
ADDR_FLASH_PAGE_21,
|
||||
ADDR_FLASH_PAGE_22,
|
||||
ADDR_FLASH_PAGE_23,
|
||||
ADDR_FLASH_PAGE_24,
|
||||
ADDR_FLASH_PAGE_25,
|
||||
ADDR_FLASH_PAGE_26,
|
||||
ADDR_FLASH_PAGE_27,
|
||||
ADDR_FLASH_PAGE_28,
|
||||
ADDR_FLASH_PAGE_29,
|
||||
ADDR_FLASH_PAGE_30,
|
||||
ADDR_FLASH_PAGE_31,
|
||||
ADDR_FLASH_PAGE_32,
|
||||
ADDR_FLASH_PAGE_33,
|
||||
ADDR_FLASH_PAGE_34,
|
||||
ADDR_FLASH_PAGE_35,
|
||||
ADDR_FLASH_PAGE_36,
|
||||
ADDR_FLASH_PAGE_37,
|
||||
ADDR_FLASH_PAGE_38,
|
||||
ADDR_FLASH_PAGE_39,
|
||||
ADDR_FLASH_PAGE_40,
|
||||
ADDR_FLASH_PAGE_41,
|
||||
ADDR_FLASH_PAGE_42,
|
||||
ADDR_FLASH_PAGE_43,
|
||||
ADDR_FLASH_PAGE_44,
|
||||
ADDR_FLASH_PAGE_45,
|
||||
ADDR_FLASH_PAGE_46,
|
||||
ADDR_FLASH_PAGE_47,
|
||||
ADDR_FLASH_PAGE_48,
|
||||
ADDR_FLASH_PAGE_49,
|
||||
ADDR_FLASH_PAGE_50,
|
||||
ADDR_FLASH_PAGE_51,
|
||||
ADDR_FLASH_PAGE_52,
|
||||
ADDR_FLASH_PAGE_53,
|
||||
ADDR_FLASH_PAGE_54,
|
||||
ADDR_FLASH_PAGE_55,
|
||||
ADDR_FLASH_PAGE_56,
|
||||
ADDR_FLASH_PAGE_57,
|
||||
ADDR_FLASH_PAGE_58,
|
||||
ADDR_FLASH_PAGE_59,
|
||||
ADDR_FLASH_PAGE_60,
|
||||
ADDR_FLASH_PAGE_61,
|
||||
ADDR_FLASH_PAGE_62,
|
||||
ADDR_FLASH_PAGE_63,
|
||||
ADDR_FLASH_PAGE_64,
|
||||
ADDR_FLASH_PAGE_65,
|
||||
ADDR_FLASH_PAGE_66,
|
||||
ADDR_FLASH_PAGE_67,
|
||||
ADDR_FLASH_PAGE_68,
|
||||
ADDR_FLASH_PAGE_69,
|
||||
ADDR_FLASH_PAGE_70,
|
||||
ADDR_FLASH_PAGE_71,
|
||||
ADDR_FLASH_PAGE_72,
|
||||
ADDR_FLASH_PAGE_73,
|
||||
ADDR_FLASH_PAGE_74,
|
||||
ADDR_FLASH_PAGE_75,
|
||||
ADDR_FLASH_PAGE_76,
|
||||
ADDR_FLASH_PAGE_77,
|
||||
ADDR_FLASH_PAGE_78,
|
||||
ADDR_FLASH_PAGE_79,
|
||||
ADDR_FLASH_PAGE_80,
|
||||
ADDR_FLASH_PAGE_81,
|
||||
ADDR_FLASH_PAGE_82,
|
||||
ADDR_FLASH_PAGE_83,
|
||||
ADDR_FLASH_PAGE_84,
|
||||
ADDR_FLASH_PAGE_85,
|
||||
ADDR_FLASH_PAGE_86,
|
||||
ADDR_FLASH_PAGE_87,
|
||||
ADDR_FLASH_PAGE_88,
|
||||
ADDR_FLASH_PAGE_89,
|
||||
ADDR_FLASH_PAGE_90,
|
||||
ADDR_FLASH_PAGE_91,
|
||||
ADDR_FLASH_PAGE_92,
|
||||
ADDR_FLASH_PAGE_93,
|
||||
ADDR_FLASH_PAGE_94,
|
||||
ADDR_FLASH_PAGE_95,
|
||||
ADDR_FLASH_PAGE_96,
|
||||
ADDR_FLASH_PAGE_97,
|
||||
ADDR_FLASH_PAGE_98,
|
||||
ADDR_FLASH_PAGE_99,
|
||||
ADDR_FLASH_PAGE_100,
|
||||
ADDR_FLASH_PAGE_101,
|
||||
ADDR_FLASH_PAGE_102,
|
||||
ADDR_FLASH_PAGE_103,
|
||||
ADDR_FLASH_PAGE_104,
|
||||
ADDR_FLASH_PAGE_105,
|
||||
ADDR_FLASH_PAGE_106,
|
||||
ADDR_FLASH_PAGE_107,
|
||||
ADDR_FLASH_PAGE_108,
|
||||
ADDR_FLASH_PAGE_109,
|
||||
ADDR_FLASH_PAGE_110,
|
||||
ADDR_FLASH_PAGE_111,
|
||||
ADDR_FLASH_PAGE_112,
|
||||
ADDR_FLASH_PAGE_113,
|
||||
ADDR_FLASH_PAGE_114,
|
||||
ADDR_FLASH_PAGE_115,
|
||||
ADDR_FLASH_PAGE_116,
|
||||
ADDR_FLASH_PAGE_117,
|
||||
ADDR_FLASH_PAGE_118,
|
||||
ADDR_FLASH_PAGE_119,
|
||||
ADDR_FLASH_PAGE_120,
|
||||
ADDR_FLASH_PAGE_121,
|
||||
ADDR_FLASH_PAGE_122,
|
||||
ADDR_FLASH_PAGE_123,
|
||||
ADDR_FLASH_PAGE_124,
|
||||
ADDR_FLASH_PAGE_125,
|
||||
ADDR_FLASH_PAGE_126,
|
||||
ADDR_FLASH_PAGE_127
|
||||
};
|
||||
|
||||
TIM_HandleTypeDef htim2;
|
||||
TIM_HandleTypeDef htim6;
|
||||
UART_HandleTypeDef huart2;
|
||||
|
||||
uint16_t modFlashEraseNewAppData() {
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
FLASH_EraseInitTypeDef flashEraseInit;
|
||||
flashEraseInit.NbPages = NEW_APP_SECTORS;
|
||||
flashEraseInit.PageAddress = flash_addr[NEW_APP_BASE];
|
||||
flashEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
|
||||
uint32_t page_error = 0;
|
||||
uint16_t result = HAL_FLASHEx_Erase(&flashEraseInit, &page_error);
|
||||
HAL_FLASH_Lock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint16_t modFlashEraseMainAppData() {
|
||||
// uint32_t page_error = 0;
|
||||
// HAL_FLASH_Unlock();
|
||||
// new_app_size += flash_addr[MAIN_APP_BASE];
|
||||
//
|
||||
// FLASH_EraseInitTypeDef flashEraseInit;
|
||||
// flashEraseInit.NbPages = 1;
|
||||
// flashEraseInit.PageAddress = flash_addr[MAIN_APP_BASE];
|
||||
// flashEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
//
|
||||
// for (int i = 0;i < NEW_APP_SECTORS;i++) {
|
||||
// if (new_app_size > flash_addr[MAIN_APP_BASE + i]) {
|
||||
// flashEraseInit.PageAddress = flash_addr[NEW_APP_BASE + i];
|
||||
// uint16_t res = HAL_FLASHEx_Erase(&flashEraseInit,&page_error);
|
||||
//
|
||||
// if (res != HAL_OK) {
|
||||
// return res;
|
||||
// }
|
||||
// } else {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// HAL_FLASH_Lock();
|
||||
// return HAL_OK;
|
||||
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
FLASH_EraseInitTypeDef flashEraseInit;
|
||||
flashEraseInit.NbPages = NEW_APP_SECTORS;
|
||||
flashEraseInit.PageAddress = flash_addr[MAIN_APP_BASE];
|
||||
flashEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
|
||||
uint32_t page_error = 0;
|
||||
uint16_t result = HAL_FLASHEx_Erase(&flashEraseInit, &page_error);
|
||||
HAL_FLASH_Lock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint16_t modFlashEraseSettingsData() {
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
FLASH_EraseInitTypeDef flashEraseInit;
|
||||
flashEraseInit.NbPages = 4;
|
||||
flashEraseInit.PageAddress = ADDR_FLASH_PAGE_124;
|
||||
flashEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
|
||||
uint32_t page_error = 0;
|
||||
uint16_t result = HAL_FLASHEx_Erase(&flashEraseInit, &page_error);
|
||||
HAL_FLASH_Lock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint16_t modFlashWriteByte(uint32_t offset, uint8_t data, bool lastByte) {
|
||||
static bool highLowByte;
|
||||
static bool newStoredData;
|
||||
static uint32_t newAddressOffset;
|
||||
static uint32_t newData;
|
||||
uint16_t returnValue = HAL_OK;
|
||||
|
||||
if(offset != 0){
|
||||
highLowByte = (offset & 0x01) ? true : false;
|
||||
newAddressOffset = (offset & 0xFFFFFFFE);
|
||||
|
||||
if(!highLowByte)
|
||||
newData = data;
|
||||
else
|
||||
newData |= (data << 8);
|
||||
newStoredData = true;
|
||||
}
|
||||
|
||||
if((highLowByte || lastByte) && newStoredData) {
|
||||
returnValue = HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,newAddressOffset,newData);
|
||||
newStoredData = false;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
//uint16_t modFlashWriteNewAppData(uint32_t offset, uint8_t *data, uint32_t len) {
|
||||
// uint16_t returnVal = HAL_OK;
|
||||
// HAL_FLASH_Unlock();
|
||||
// for (uint32_t i = 0;i < len;i++) {
|
||||
// uint16_t res = modFlashWriteByte(flash_addr[NEW_APP_BASE] + offset + i, data[i],false);
|
||||
// if (res != HAL_OK) {
|
||||
// return res;
|
||||
// }
|
||||
// }
|
||||
// HAL_FLASH_Lock();
|
||||
// return returnVal;
|
||||
//}
|
||||
|
||||
uint16_t modFlashCopyNewAppToMainApp(uint32_t offset, uint8_t *data, uint32_t len) {
|
||||
HAL_FLASH_Unlock();
|
||||
for (uint32_t i = 0; i < len; ++i) {
|
||||
uint16_t res = modFlashWriteByte(flash_addr[MAIN_APP_BASE] + offset + i, data[i], false);
|
||||
if (res != HAL_OK) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
modFlashWriteByte(0, 0, true);
|
||||
HAL_FLASH_Lock();
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
//void modFlashJumpToBootloader(void) {
|
||||
//
|
||||
// typedef void (*pFunction)(void);
|
||||
//
|
||||
// modFlashWriteByte(0,0,true);
|
||||
//
|
||||
// __HAL_RCC_CAN1_FORCE_RESET();
|
||||
// HAL_Delay(5);
|
||||
// __HAL_RCC_CAN1_RELEASE_RESET();
|
||||
// HAL_Delay(5);
|
||||
//
|
||||
// __HAL_RCC_USART2_FORCE_RESET();
|
||||
// HAL_Delay(5);
|
||||
// __HAL_RCC_USART2_RELEASE_RESET();
|
||||
// HAL_Delay(5);
|
||||
//
|
||||
// HAL_RCC_DeInit();
|
||||
//
|
||||
// pFunction jump_to_bootloader;
|
||||
//
|
||||
// // Variable that will be loaded with the start address of the application
|
||||
//// volatile uint32_t* jump_address;
|
||||
//// const volatile uint32_t* bootloader_address = (volatile uint32_t*)ADDR_FLASH_PAGE_110;//ADDR_FLASH_PAGE_100;
|
||||
////
|
||||
//// // Get jump address from application vector table
|
||||
//// jump_address = (volatile uint32_t*) bootloader_address[1];
|
||||
//
|
||||
// uint32_t JumpAddress;
|
||||
// JumpAddress = (uint32_t) *((__IO uint32_t*)ADDR_FLASH_PAGE_110);
|
||||
// jump_to_bootloader = (pFunction)(*(volatile uint32_t*) (ADDR_FLASH_PAGE_110+4u));
|
||||
//
|
||||
//
|
||||
//// // Load this address into function pointer
|
||||
//// jump_to_bootloader = (pFunction) jump_address;
|
||||
//
|
||||
// // Clear pending interrupts
|
||||
// SCB->ICSR = SCB_ICSR_PENDSVCLR_Msk;
|
||||
//
|
||||
// // Disable all interrupts
|
||||
// for(int i = 0;i < 8;i++) {
|
||||
// NVIC->ICER[i] = NVIC->IABR[i];
|
||||
// }
|
||||
//
|
||||
// SCB->VTOR = JumpAddress;
|
||||
// // Set stack pointer
|
||||
// //__set_MSP((uint32_t) (bootloader_address[0]));
|
||||
// __set_MSP(JumpAddress);
|
||||
//
|
||||
// // Jump to the bootloader
|
||||
// jump_to_bootloader();
|
||||
//}
|
||||
|
||||
//
|
||||
//typedef void (*pFunction)(void);
|
||||
//pFunction Jump_To_Application;
|
||||
|
||||
|
||||
//void modFlashJumpToBootloader(void)
|
||||
//{
|
||||
// uint32_t JumpAddress;
|
||||
//
|
||||
// HAL_DeInit();
|
||||
// HAL_RCC_DeInit();
|
||||
//
|
||||
// __disable_irq();
|
||||
//
|
||||
// JumpAddress = *( uint32_t*) (ADDR_FLASH_PAGE_110 + 4);
|
||||
// JumpAddress = 0x08037004;
|
||||
// Jump_To_Application = (pFunction)JumpAddress;
|
||||
// /* Initialize user application's Stack Pointer */
|
||||
// __set_MSP(*(__IO uint32_t*) ADDR_FLASH_PAGE_110);
|
||||
//
|
||||
// Jump_To_Application();
|
||||
|
||||
// uint32_t JumpAddress;
|
||||
// JumpAddress = (uint32_t) *((__IO uint32_t*)ADDR_FLASH_PAGE_110);
|
||||
// Jump_To_Application = (pFunction)(*(volatile uint32_t*) (0x08037000+4u));
|
||||
// __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
|
||||
//
|
||||
// for(int i = 0;i < 8;i++) {
|
||||
// NVIC->ICER[i] = NVIC->IABR[i];
|
||||
// }
|
||||
//
|
||||
// SCB->ICSR = SCB_ICSR_PENDSVCLR_Msk;
|
||||
// SCB->VTOR = 0x08037000;
|
||||
// __set_MSP(0x08037000);
|
||||
//
|
||||
// Jump_To_Application();
|
||||
//}
|
||||
|
||||
void deinitEverything()
|
||||
{
|
||||
//-- reset peripherals to guarantee flawless start of user application
|
||||
HAL_TIM_Base_Stop_IT(&htim2);
|
||||
HAL_TIM_Base_Stop_IT(&htim6);
|
||||
MX_USB_DEVICE_DeInit();
|
||||
MX_FATFS_DeInit();
|
||||
HAL_UART_DeInit(&huart2);
|
||||
|
||||
HAL_RCC_DeInit();
|
||||
HAL_DeInit();
|
||||
SysTick->CTRL = 0;
|
||||
SysTick->LOAD = 0;
|
||||
SysTick->VAL = 0;
|
||||
}
|
||||
|
||||
void jumpToBootLoader(void)
|
||||
{
|
||||
uint32_t adr=0x08037000;
|
||||
const JumpStruct* vector_p = (JumpStruct*)adr;
|
||||
|
||||
//Total_DeInit();
|
||||
deinitEverything();
|
||||
|
||||
/* let's do The Jump! */
|
||||
/* Jump, used asm to avoid stack optimization */
|
||||
asm("msr msp, %0; bx %1;" : : "r"(vector_p->stack_addr), "r"(vector_p->func_p));
|
||||
}
|
||||
|
||||
void modFlashJumpToMainApplication(void) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
121
bootloader/Core/Src/rtc.c
Normal file
121
bootloader/Core/Src/rtc.c
Normal file
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rtc.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the RTC instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* 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 */
|
||||
//extern Time_Struct Global_RTC_Time;
|
||||
/* 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 DateToUpdate = {0};
|
||||
|
||||
/* USER CODE BEGIN RTC_Init 1 */
|
||||
|
||||
/* USER CODE END RTC_Init 1 */
|
||||
/** Initialize RTC Only
|
||||
*/
|
||||
hrtc.Instance = RTC;
|
||||
hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
|
||||
hrtc.Init.OutPut = RTC_OUTPUTSOURCE_ALARM;
|
||||
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 = 18;
|
||||
// sTime.Minutes = 25;
|
||||
// sTime.Seconds = 58;
|
||||
//
|
||||
// if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
|
||||
// {
|
||||
// Error_Handler();
|
||||
// }
|
||||
// DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY;
|
||||
// DateToUpdate.Month = 11;
|
||||
// DateToUpdate.Date = 24;
|
||||
// DateToUpdate.Year = 21;
|
||||
//
|
||||
// if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, 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 */
|
||||
HAL_PWR_EnableBkUpAccess();
|
||||
/* Enable BKP CLK enable for backup registers */
|
||||
__HAL_RCC_BKP_CLK_ENABLE();
|
||||
/* RTC clock enable */
|
||||
__HAL_RCC_RTC_ENABLE();
|
||||
/* 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();
|
||||
/* 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****/
|
||||
408
bootloader/Core/Src/system_stm32f1xx.c
Normal file
408
bootloader/Core/Src/system_stm32f1xx.c
Normal file
@@ -0,0 +1,408 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32f1xx.c
|
||||
* @author MCD Application Team
|
||||
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
|
||||
*
|
||||
* 1. This file provides two functions and one global variable to be called from
|
||||
* user application:
|
||||
* - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
|
||||
* factors, AHB/APBx prescalers and Flash settings).
|
||||
* This function is called at startup just after reset and
|
||||
* before branch to main program. This call is made inside
|
||||
* the "startup_stm32f1xx_xx.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.
|
||||
*
|
||||
* 2. After each device reset the HSI (8 MHz) is used as system clock source.
|
||||
* Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to
|
||||
* configure the system clock before to branch to main program.
|
||||
*
|
||||
* 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on
|
||||
* the product used), refer to "HSE_VALUE".
|
||||
* When HSE is used as system clock source, directly or through PLL, and you
|
||||
* are using different crystal you have to adapt the HSE value to your own
|
||||
* configuration.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32f1xx_system
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "stm32f1xx.h"
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz.
|
||||
This value can be provided and adapted by the user application. */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz.
|
||||
This value can be provided and adapted by the user application. */
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/*!< Uncomment the following line if you need to use external SRAM */
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
/* #define DATA_IN_ExtSRAM */
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
|
||||
/* Note: Following vector table addresses must be defined in line with linker
|
||||
configuration. */
|
||||
/*!< Uncomment the following line if you need to relocate the vector table
|
||||
anywhere in Flash or Sram, else the vector table is kept at the automatic
|
||||
remap of boot address selected */
|
||||
#define USER_VECT_TAB_ADDRESS
|
||||
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
/*!< Uncomment the following line if you need to relocate your vector Table
|
||||
in Sram else user remap will be done in Flash. */
|
||||
/* #define VECT_TAB_SRAM */
|
||||
#if defined(VECT_TAB_SRAM)
|
||||
#define VECT_TAB_BASE_ADDRESS SRAM_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 0x00034000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#endif /* VECT_TAB_SRAM */
|
||||
#endif /* USER_VECT_TAB_ADDRESS */
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* This 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 = 16000000;
|
||||
const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
static void SystemInit_ExtMemCtl(void);
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system
|
||||
* Initialize the Embedded Flash Interface, the PLL and update the
|
||||
* SystemCoreClock variable.
|
||||
* @note This function should be used only after reset.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit (void)
|
||||
{
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
SystemInit_ExtMemCtl();
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
#endif
|
||||
|
||||
/* Configure the Vector Table location -------------------------------------*/
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
|
||||
#endif /* USER_VECT_TAB_ADDRESS */
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 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(*) multiplied by the PLL factors.
|
||||
*
|
||||
* (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value
|
||||
* 8 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
*
|
||||
* (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value
|
||||
* 8 MHz or 25 MHz, depending on the product used), 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 = 0U, pllmull = 0U, pllsource = 0U;
|
||||
|
||||
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||
uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U;
|
||||
#endif /* STM32F105xC */
|
||||
|
||||
#if defined(STM32F100xB) || defined(STM32F100xE)
|
||||
uint32_t prediv1factor = 0U;
|
||||
#endif /* STM32F100xB or STM32F100xE */
|
||||
|
||||
/* Get SYSCLK source -------------------------------------------------------*/
|
||||
tmp = RCC->CFGR & RCC_CFGR_SWS;
|
||||
|
||||
switch (tmp)
|
||||
{
|
||||
case 0x00U: /* HSI used as system clock */
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
case 0x04U: /* HSE used as system clock */
|
||||
SystemCoreClock = HSE_VALUE;
|
||||
break;
|
||||
case 0x08U: /* PLL used as system clock */
|
||||
|
||||
/* Get PLL clock source and multiplication factor ----------------------*/
|
||||
pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
|
||||
pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
|
||||
|
||||
#if !defined(STM32F105xC) && !defined(STM32F107xC)
|
||||
pllmull = ( pllmull >> 18U) + 2U;
|
||||
|
||||
if (pllsource == 0x00U)
|
||||
{
|
||||
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
|
||||
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(STM32F100xB) || defined(STM32F100xE)
|
||||
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
||||
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
||||
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
||||
#else
|
||||
/* HSE selected as PLL clock entry */
|
||||
if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET)
|
||||
{/* HSE oscillator clock divided by 2 */
|
||||
SystemCoreClock = (HSE_VALUE >> 1U) * pllmull;
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemCoreClock = HSE_VALUE * pllmull;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
pllmull = pllmull >> 18U;
|
||||
|
||||
if (pllmull != 0x0DU)
|
||||
{
|
||||
pllmull += 2U;
|
||||
}
|
||||
else
|
||||
{ /* PLL multiplication factor = PLL input clock * 6.5 */
|
||||
pllmull = 13U / 2U;
|
||||
}
|
||||
|
||||
if (pllsource == 0x00U)
|
||||
{
|
||||
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
|
||||
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
|
||||
}
|
||||
else
|
||||
{/* PREDIV1 selected as PLL clock entry */
|
||||
|
||||
/* Get PREDIV1 clock source and division factor */
|
||||
prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
|
||||
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
||||
|
||||
if (prediv1source == 0U)
|
||||
{
|
||||
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
||||
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
||||
}
|
||||
else
|
||||
{/* PLL2 clock selected as PREDIV1 clock entry */
|
||||
|
||||
/* Get PREDIV2 division factor and PLL2 multiplication factor */
|
||||
prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U;
|
||||
pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U;
|
||||
SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;
|
||||
}
|
||||
}
|
||||
#endif /* STM32F105xC */
|
||||
break;
|
||||
|
||||
default:
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Compute HCLK clock frequency ----------------*/
|
||||
/* Get HCLK prescaler */
|
||||
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
|
||||
/* HCLK clock frequency */
|
||||
SystemCoreClock >>= tmp;
|
||||
}
|
||||
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
/**
|
||||
* @brief Setup the external memory controller. Called in startup_stm32f1xx.s
|
||||
* before jump to __main
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
/**
|
||||
* @brief Setup the external memory controller.
|
||||
* Called in startup_stm32f1xx_xx.s/.c before jump to main.
|
||||
* This function configures the external SRAM mounted on STM3210E-EVAL
|
||||
* board (STM32 High density devices). This SRAM will be used as program
|
||||
* data memory (including heap and stack).
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit_ExtMemCtl(void)
|
||||
{
|
||||
__IO uint32_t tmpreg;
|
||||
/*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
|
||||
required, then adjust the Register Addresses */
|
||||
|
||||
/* Enable FSMC clock */
|
||||
RCC->AHBENR = 0x00000114U;
|
||||
|
||||
/* Delay after an RCC peripheral clock enabling */
|
||||
tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN);
|
||||
|
||||
/* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
|
||||
RCC->APB2ENR = 0x000001E0U;
|
||||
|
||||
/* Delay after an RCC peripheral clock enabling */
|
||||
tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);
|
||||
|
||||
(void)(tmpreg);
|
||||
|
||||
/* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
|
||||
/*---------------- SRAM Address lines configuration -------------------------*/
|
||||
/*---------------- NOE and NWE configuration --------------------------------*/
|
||||
/*---------------- NE3 configuration ----------------------------------------*/
|
||||
/*---------------- NBL0, NBL1 configuration ---------------------------------*/
|
||||
|
||||
GPIOD->CRL = 0x44BB44BBU;
|
||||
GPIOD->CRH = 0xBBBBBBBBU;
|
||||
|
||||
GPIOE->CRL = 0xB44444BBU;
|
||||
GPIOE->CRH = 0xBBBBBBBBU;
|
||||
|
||||
GPIOF->CRL = 0x44BBBBBBU;
|
||||
GPIOF->CRH = 0xBBBB4444U;
|
||||
|
||||
GPIOG->CRL = 0x44BBBBBBU;
|
||||
GPIOG->CRH = 0x444B4B44U;
|
||||
|
||||
/*---------------- FSMC Configuration ---------------------------------------*/
|
||||
/*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
|
||||
|
||||
FSMC_Bank1->BTCR[4U] = 0x00001091U;
|
||||
FSMC_Bank1->BTCR[5U] = 0x00110212U;
|
||||
}
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user