--some updates
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid.25849733" name="CPU" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid" value="0" valueType="string"/>
|
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid.25849733" name="CPU" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid" value="0" valueType="string"/>
|
||||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid.409440975" name="Core" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid" value="0" valueType="string"/>
|
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid.409440975" name="Core" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid" value="0" valueType="string"/>
|
||||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.124430228" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" value="genericBoard" valueType="string"/>
|
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.124430228" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" value="genericBoard" valueType="string"/>
|
||||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.201018160" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32G070CBTx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32G0xx_HAL_Driver/Inc | ../Drivers/STM32G0xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32G0xx/Include | ../Drivers/CMSIS/Include || || || USE_HAL_DRIVER | STM32G070xx || || Drivers | Core/Startup | Core || || || ${workspace_loc:/${ProjName}/STM32G070CBTX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
|
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.201018160" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32G070CBTx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32G0xx_HAL_Driver/Inc | ../Drivers/STM32G0xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32G0xx/Include | ../Drivers/CMSIS/Include || || || USE_HAL_DRIVER | STM32G070xx || || Drivers | Boot/Core/Startup | Core || || || ${workspace_loc:/${ProjName}/STM32G070CBTX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
|
||||||
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.1374904357" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" value="16" valueType="string"/>
|
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.1374904357" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" value="16" valueType="string"/>
|
||||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.1584764133" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
|
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.1584764133" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
|
||||||
<builder buildPath="${workspace_loc:/gm60}/Debug" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.597859245" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
|
<builder buildPath="${workspace_loc:/gm60}/Debug" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.597859245" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
|
||||||
@@ -73,6 +73,7 @@
|
|||||||
</folderInfo>
|
</folderInfo>
|
||||||
<sourceEntries>
|
<sourceEntries>
|
||||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
|
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
|
||||||
|
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Boot/Core/Startup"/>
|
||||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
|
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
|
||||||
</sourceEntries>
|
</sourceEntries>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -99,7 +100,7 @@
|
|||||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid.484966952" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid" value="0" valueType="string"/>
|
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid.484966952" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid" value="0" valueType="string"/>
|
||||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid.1465104717" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid" value="0" valueType="string"/>
|
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid.1465104717" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid" value="0" valueType="string"/>
|
||||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.2058696250" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" value="genericBoard" valueType="string"/>
|
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.2058696250" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" value="genericBoard" valueType="string"/>
|
||||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.695960716" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Release || false || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32G070CBTx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32G0xx_HAL_Driver/Inc | ../Drivers/STM32G0xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32G0xx/Include | ../Drivers/CMSIS/Include || || || USE_HAL_DRIVER | STM32G070xx || || Drivers | Core/Startup | Core || || || ${workspace_loc:/${ProjName}/STM32G070CBTX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
|
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.695960716" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Release || false || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32G070CBTx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32G0xx_HAL_Driver/Inc | ../Drivers/STM32G0xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32G0xx/Include | ../Drivers/CMSIS/Include || || || USE_HAL_DRIVER | STM32G070xx || || Drivers | Boot/Core/Startup | Core || || || ${workspace_loc:/${ProjName}/STM32G070CBTX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
|
||||||
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.278712525" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" value="16" valueType="string"/>
|
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.278712525" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" value="16" valueType="string"/>
|
||||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.32267443" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
|
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.32267443" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
|
||||||
<builder buildPath="${workspace_loc:/gm60}/Release" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.844751989" managedBuildOn="true" name="Gnu Make Builder.Release" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
|
<builder buildPath="${workspace_loc:/gm60}/Release" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.844751989" managedBuildOn="true" name="Gnu Make Builder.Release" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
|
||||||
@@ -147,6 +148,7 @@
|
|||||||
</folderInfo>
|
</folderInfo>
|
||||||
<sourceEntries>
|
<sourceEntries>
|
||||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
|
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
|
||||||
|
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Boot/Core/Startup"/>
|
||||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
|
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
|
||||||
</sourceEntries>
|
</sourceEntries>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
2
.idea/runConfigurations/OCD_Boot.xml
generated
2
.idea/runConfigurations/OCD_Boot.xml
generated
@@ -1,5 +1,5 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="OCD Boot" type="com.jetbrains.cidr.embedded.openocd.conf.type" factoryName="com.jetbrains.cidr.embedded.openocd.conf.factory" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="reader-boot" TARGET_NAME="reader-boot.elf" CONFIG_NAME="BOOT_DEBUG" version="1" RUN_TARGET_PROJECT_NAME="reader-boot" RUN_TARGET_NAME="reader-boot.elf">
|
<configuration default="false" name="OCD Boot" type="com.jetbrains.cidr.embedded.openocd.conf.type" factoryName="com.jetbrains.cidr.embedded.openocd.conf.factory" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="reader-main-prog" TARGET_NAME="reader-boot.elf" CONFIG_NAME="BOOT" version="1" RUN_TARGET_PROJECT_NAME="reader-main-prog" RUN_TARGET_NAME="reader-boot.elf">
|
||||||
<openocd version="1" gdb-port="3333" telnet-port="4444" board-config="board/st_nucleo_g0.cfg" reset-type="RUN" download-type="UPDATED_ONLY">
|
<openocd version="1" gdb-port="3333" telnet-port="4444" board-config="board/st_nucleo_g0.cfg" reset-type="RUN" download-type="UPDATED_ONLY">
|
||||||
<debugger kind="GDB" isBundled="true" />
|
<debugger kind="GDB" isBundled="true" />
|
||||||
</openocd>
|
</openocd>
|
||||||
|
|||||||
2
.idea/runConfigurations/OCD_mainprog.xml
generated
2
.idea/runConfigurations/OCD_mainprog.xml
generated
@@ -1,5 +1,5 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="OCD mainprog" type="com.jetbrains.cidr.embedded.openocd.conf.type" factoryName="com.jetbrains.cidr.embedded.openocd.conf.factory" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="reader-boot" TARGET_NAME="reader-main-prog.elf" CONFIG_NAME="Debug" version="1" RUN_TARGET_PROJECT_NAME="reader-boot" RUN_TARGET_NAME="reader-main-prog.elf">
|
<configuration default="false" name="OCD mainprog" type="com.jetbrains.cidr.embedded.openocd.conf.type" factoryName="com.jetbrains.cidr.embedded.openocd.conf.factory" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="reader-main-prog" TARGET_NAME="reader-main-prog.elf" CONFIG_NAME="Debug" version="1" RUN_TARGET_PROJECT_NAME="reader-main-prog" RUN_TARGET_NAME="reader-main-prog.elf">
|
||||||
<openocd version="1" gdb-port="3333" telnet-port="4444" board-config="board/st_nucleo_g0.cfg" reset-type="INIT" download-type="UPDATED_ONLY">
|
<openocd version="1" gdb-port="3333" telnet-port="4444" board-config="board/st_nucleo_g0.cfg" reset-type="INIT" download-type="UPDATED_ONLY">
|
||||||
<debugger kind="GDB" isBundled="true" />
|
<debugger kind="GDB" isBundled="true" />
|
||||||
</openocd>
|
</openocd>
|
||||||
|
|||||||
@@ -29,9 +29,13 @@
|
|||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
* Include files
|
* Include files
|
||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
|
extern "C" {
|
||||||
#include "header.h" /* generic header */
|
#include "header.h" /* generic header */
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "uart_bridge.hpp"
|
||||||
|
|
||||||
|
UartBridge bridge(true, USART1, USART2, 9600, 9600);
|
||||||
/************************************************************************************//**
|
/************************************************************************************//**
|
||||||
** \brief Initializes the user program application. Should be called once during
|
** \brief Initializes the user program application. Should be called once during
|
||||||
** software program initialization.
|
** software program initialization.
|
||||||
@@ -45,7 +49,10 @@ void AppInit(void)
|
|||||||
/* Initialize the led driver. */
|
/* Initialize the led driver. */
|
||||||
LedInit();
|
LedInit();
|
||||||
/* initialize the bootloader interface */
|
/* initialize the bootloader interface */
|
||||||
|
bridge.init();
|
||||||
|
/*
|
||||||
BootComInit();
|
BootComInit();
|
||||||
|
*/
|
||||||
} /*** end of AppInit ***/
|
} /*** end of AppInit ***/
|
||||||
|
|
||||||
|
|
||||||
@@ -57,11 +64,13 @@ void AppInit(void)
|
|||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
void AppTask(void)
|
void AppTask(void)
|
||||||
{
|
{
|
||||||
/* Toggle LED with a fixed frequency. */
|
|
||||||
LedToggle();
|
|
||||||
/* check for bootloader activation request */
|
/* check for bootloader activation request */
|
||||||
|
/*
|
||||||
BootComCheckActivationRequest();
|
BootComCheckActivationRequest();
|
||||||
|
*/
|
||||||
} /*** end of AppTask ***/
|
} /*** end of AppTask ***/
|
||||||
|
|
||||||
|
|
||||||
/*********************************** end of app.c **************************************/
|
/*********************************** end of app.c **************************************/
|
||||||
|
|
||||||
|
//////////// FINALLY NEED TO UNCOMMENT BootComCheckActivationRequest and BootComInit for success firmwaare update from HOST
|
||||||
@@ -115,7 +115,7 @@ static unsigned char Rs232ReceiveByte(unsigned char *data);
|
|||||||
static void BootComRs232Init(void)
|
static void BootComRs232Init(void)
|
||||||
{
|
{
|
||||||
/* Configure UART peripheral. */
|
/* Configure UART peripheral. */
|
||||||
rs232Handle.Instance = USART2;
|
rs232Handle.Instance = USART1;
|
||||||
rs232Handle.Init.BaudRate = BOOT_COM_RS232_BAUDRATE;
|
rs232Handle.Init.BaudRate = BOOT_COM_RS232_BAUDRATE;
|
||||||
rs232Handle.Init.WordLength = UART_WORDLENGTH_8B;
|
rs232Handle.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
rs232Handle.Init.StopBits = UART_STOPBITS_1;
|
rs232Handle.Init.StopBits = UART_STOPBITS_1;
|
||||||
|
|||||||
@@ -67,7 +67,7 @@
|
|||||||
/** \brief Enable/disable UART transport layer. */
|
/** \brief Enable/disable UART transport layer. */
|
||||||
#define BOOT_COM_RS232_ENABLE (1)
|
#define BOOT_COM_RS232_ENABLE (1)
|
||||||
/** \brief Configure the desired communication speed. */
|
/** \brief Configure the desired communication speed. */
|
||||||
#define BOOT_COM_RS232_BAUDRATE (57600)
|
#define BOOT_COM_RS232_BAUDRATE (9600)
|
||||||
/** \brief Configure number of bytes in the target->host data packet. */
|
/** \brief Configure number of bytes in the target->host data packet. */
|
||||||
#define BOOT_COM_RS232_TX_MAX_DATA (129)
|
#define BOOT_COM_RS232_TX_MAX_DATA (129)
|
||||||
/** \brief Configure number of bytes in the host->target data packet. */
|
/** \brief Configure number of bytes in the host->target data packet. */
|
||||||
|
|||||||
@@ -1,4 +1,26 @@
|
|||||||
cmake_minimum_required(VERSION 3.23)
|
cmake_minimum_required(VERSION 3.23)
|
||||||
|
set(CMAKE_SYSTEM_NAME Generic)
|
||||||
|
set(CMAKE_SYSTEM_VERSION 1)
|
||||||
|
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
|
||||||
|
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
|
||||||
|
set(CMAKE_AR arm-none-eabi-ar)
|
||||||
|
set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
|
||||||
|
set(CMAKE_OBJDUMP arm-none-eabi-objdump)
|
||||||
|
set(SIZE arm-none-eabi-size)
|
||||||
|
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||||
|
if (BOOT)
|
||||||
|
project(reader-boot C CXX ASM)
|
||||||
|
else()
|
||||||
|
project(reader-main-prog C CXX ASM)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CORTEX-M 0)
|
||||||
|
set(COMPILE_OPTIONS -mcpu=cortex-m${CORTEX-M} -mthumb -mthumb-interwork -ffunction-sections -fdata-sections -fno-common -fmessage-length=0 $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
|
||||||
|
set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/STM32G070CBTX_FLASH.ld)
|
||||||
|
set(LINK_OPTIONS -Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map -mcpu=cortex-m${CORTEX-M} -mthumb -mthumb-interwork -T ${LINKER_SCRIPT} -specs=nano.specs -specs=nosys.specs)
|
||||||
|
|
||||||
|
|
||||||
if(GTEST)
|
if(GTEST)
|
||||||
|
|
||||||
@@ -37,18 +59,7 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
math(EXPR LEN_ADDRESS "${FLASH_MAIN_ADDRESS} + ${LEN_OFFSET}" OUTPUT_FORMAT HEXADECIMAL)
|
math(EXPR LEN_ADDRESS "${FLASH_MAIN_ADDRESS} + ${LEN_OFFSET}" OUTPUT_FORMAT HEXADECIMAL)
|
||||||
add_compile_definitions("PAGE_SIZE=0x0800")
|
add_compile_definitions("PAGE_SIZE=0x0800")
|
||||||
set(CMAKE_SYSTEM_NAME Generic)
|
|
||||||
set(CMAKE_SYSTEM_VERSION 1)
|
|
||||||
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
|
|
||||||
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
|
|
||||||
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
|
|
||||||
set(CMAKE_AR arm-none-eabi-ar)
|
|
||||||
set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
|
|
||||||
set(CMAKE_OBJDUMP arm-none-eabi-objdump)
|
|
||||||
set(SIZE arm-none-eabi-size)
|
|
||||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
|
||||||
add_compile_options(-mcpu=cortex-m0 -mthumb -mthumb-interwork )
|
|
||||||
add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0)
|
|
||||||
#PAGE SIZE FOR F0 Series with 256KB Flash 0x0800 For 128Kb Flash 0x0400
|
#PAGE SIZE FOR F0 Series with 256KB Flash 0x0800 For 128Kb Flash 0x0400
|
||||||
|
|
||||||
# uncomment to mitigate c++17 absolute addresses warnings
|
# uncomment to mitigate c++17 absolute addresses warnings
|
||||||
@@ -85,9 +96,6 @@ else()
|
|||||||
|
|
||||||
add_compile_definitions("BOOT_FLASH_VECTOR_TABLE_CS_OFFSET=${LEN_OFFSET}" "LEN_ADDRESS=${LEN_ADDRESS}")
|
add_compile_definitions("BOOT_FLASH_VECTOR_TABLE_CS_OFFSET=${LEN_OFFSET}" "LEN_ADDRESS=${LEN_ADDRESS}")
|
||||||
add_definitions(-DDEBUG -DUSE_FULL_LL_DRIVER -DUSE_HAL_DRIVER -DSTM32G070xx)
|
add_definitions(-DDEBUG -DUSE_FULL_LL_DRIVER -DUSE_HAL_DRIVER -DSTM32G070xx)
|
||||||
project(reader-boot C CXX ASM)
|
|
||||||
add_compile_options(-mcpu=cortex-m0 -mthumb -mthumb-interwork)
|
|
||||||
add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0)
|
|
||||||
|
|
||||||
include_directories(Boot/Core/Inc Drivers/STM32G0xx_HAL_Driver/Inc Drivers/STM32G0xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32G0xx/Include Drivers/CMSIS/Include Boot/App)
|
include_directories(Boot/Core/Inc Drivers/STM32G0xx_HAL_Driver/Inc Drivers/STM32G0xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32G0xx/Include Drivers/CMSIS/Include Boot/App)
|
||||||
include_directories(Boot/loader)
|
include_directories(Boot/loader)
|
||||||
@@ -97,12 +105,9 @@ else()
|
|||||||
list(FILTER SOURCES EXCLUDE REGEX "IAR\\/.*.[c|h]$")
|
list(FILTER SOURCES EXCLUDE REGEX "IAR\\/.*.[c|h]$")
|
||||||
list(FILTER SOURCES EXCLUDE REGEX "Keil\\/.*.[c|h]$")
|
list(FILTER SOURCES EXCLUDE REGEX "Keil\\/.*.[c|h]$")
|
||||||
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/Boot/STM32G070CBTX_FLASH.ld)
|
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/Boot/STM32G070CBTX_FLASH.ld)
|
||||||
|
|
||||||
add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map)
|
|
||||||
add_link_options(-mcpu=cortex-m0 -mthumb -mthumb-interwork)
|
|
||||||
add_link_options(-T ${LINKER_SCRIPT})
|
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}.elf ${SOURCES} )
|
add_executable(${PROJECT_NAME}.elf ${SOURCES} )
|
||||||
|
target_compile_options(${PROJECT_NAME}.elf PUBLIC ${COMPILE_OPTIONS})
|
||||||
|
target_link_options(${PROJECT_NAME}.elf PUBLIC ${LINK_OPTIONS})
|
||||||
set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
|
set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
|
||||||
set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)
|
set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)
|
||||||
add_custom_command(TARGET ${PROJECT_NAME}.elf PRE_BUILD
|
add_custom_command(TARGET ${PROJECT_NAME}.elf PRE_BUILD
|
||||||
@@ -116,7 +121,6 @@ else()
|
|||||||
|
|
||||||
else()
|
else()
|
||||||
|
|
||||||
project(reader-main-prog C CXX ASM)
|
|
||||||
|
|
||||||
include_directories(Core/Inc Drivers/STM32G0xx_HAL_Driver/Inc Drivers/STM32G0xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32G0xx/Include Drivers/CMSIS/Include Core/Interfaces Core/Interfaces/Templates App)
|
include_directories(Core/Inc Drivers/STM32G0xx_HAL_Driver/Inc Drivers/STM32G0xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32G0xx/Include Drivers/CMSIS/Include Core/Interfaces Core/Interfaces/Templates App)
|
||||||
|
|
||||||
@@ -127,12 +131,9 @@ else()
|
|||||||
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32G070CBTX_FLASH.ld)
|
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32G070CBTX_FLASH.ld)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map)
|
|
||||||
add_link_options(-mcpu=cortex-m0 -mthumb -mthumb-interwork )
|
|
||||||
add_link_options(-T ${LINKER_SCRIPT})
|
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})
|
add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})
|
||||||
|
target_compile_options(${PROJECT_NAME}.elf PUBLIC ${COMPILE_OPTIONS})
|
||||||
|
target_link_options(${PROJECT_NAME}.elf PUBLIC ${LINK_OPTIONS})
|
||||||
set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
|
set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
|
||||||
set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)
|
set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)
|
||||||
set(HEX_FILE_SRECORD_WITH_LEN_AND_CRC ${PROJECT_BINARY_DIR}/${PROJECT_NAME}_SRECORD.hex)
|
set(HEX_FILE_SRECORD_WITH_LEN_AND_CRC ${PROJECT_BINARY_DIR}/${PROJECT_NAME}_SRECORD.hex)
|
||||||
|
|||||||
83
Core/Inc/circular_buffer.hpp
Normal file
83
Core/Inc/circular_buffer.hpp
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
//===================================================================
|
||||||
|
// File: circular_buffer.cpp
|
||||||
|
//
|
||||||
|
// Desc: A Circular Buffer implementation in C++.
|
||||||
|
//
|
||||||
|
// Copyright © 2019 Edwin Cloud. All rights reserved.
|
||||||
|
//
|
||||||
|
//===================================================================
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Includes
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
#include <memory>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Circular_Buffer (Class)
|
||||||
|
// We will implement the buffer with a templated class so
|
||||||
|
// the buffer can be a buffer of specified type.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
template <typename T> class Circular_Buffer {
|
||||||
|
private:
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
// Circular_Buffer - Private Member Variables
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
|
||||||
|
std::unique_ptr<T[]> buffer; // using a smart pointer is safer (and we don't
|
||||||
|
// have to implement a destructor)
|
||||||
|
size_t head = 0; // size_t is an unsigned long
|
||||||
|
size_t tail = 0;
|
||||||
|
size_t max_size;
|
||||||
|
T empty_item; // we will use this to clear data
|
||||||
|
public:
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
// Circular_Buffer - Public Methods
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Create a new Circular_Buffer.
|
||||||
|
Circular_Buffer<T>(size_t max_size)
|
||||||
|
: buffer(std::unique_ptr<T[]>(new T[max_size])), max_size(max_size){};
|
||||||
|
|
||||||
|
// Add an item to this circular buffer.
|
||||||
|
void enqueue(T item) {
|
||||||
|
|
||||||
|
// insert item at back of buffer
|
||||||
|
buffer[tail] = item;
|
||||||
|
|
||||||
|
// increment tail
|
||||||
|
tail = (tail + 1) % max_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove an item from this circular buffer and return it.
|
||||||
|
T dequeue() {
|
||||||
|
|
||||||
|
T item = buffer[head];
|
||||||
|
|
||||||
|
// set item at head to be empty
|
||||||
|
T empty;
|
||||||
|
buffer[head] = empty_item;
|
||||||
|
|
||||||
|
// move head foward
|
||||||
|
head = (head + 1) % max_size;
|
||||||
|
|
||||||
|
// return item
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the item at the front of this circular buffer.
|
||||||
|
T front() { return buffer[head]; }
|
||||||
|
|
||||||
|
// Return true if this circular buffer is empty, and false otherwise.
|
||||||
|
bool is_empty() { return head == tail; }
|
||||||
|
|
||||||
|
// Return true if this circular buffer is full, and false otherwise.
|
||||||
|
bool is_full() { return tail == (head - 1) % max_size; }
|
||||||
|
|
||||||
|
// Return the size of this circular buffer.
|
||||||
|
size_t size() {
|
||||||
|
if (tail >= head)
|
||||||
|
return tail - head;
|
||||||
|
return max_size - head - tail;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -58,7 +58,13 @@ void Error_Handler(void);
|
|||||||
/* USER CODE END EFP */
|
/* USER CODE END EFP */
|
||||||
|
|
||||||
/* Private defines -----------------------------------------------------------*/
|
/* Private defines -----------------------------------------------------------*/
|
||||||
void MX_USART2_UART_Init(void);
|
#define LIGHTING_EN_Pin GPIO_PIN_4
|
||||||
|
#define LIGHTING_EN_GPIO_Port GPIOA
|
||||||
|
#define READER_EN_Pin GPIO_PIN_5
|
||||||
|
#define READER_EN_GPIO_Port GPIOA
|
||||||
|
#define ZUMMER_PINOUT_Pin GPIO_PIN_5
|
||||||
|
#define ZUMMER_PINOUT_GPIO_Port GPIOB
|
||||||
|
|
||||||
/* USER CODE BEGIN Private defines */
|
/* USER CODE BEGIN Private defines */
|
||||||
|
|
||||||
/* USER CODE END Private defines */
|
/* USER CODE END Private defines */
|
||||||
@@ -68,5 +74,3 @@ void MX_USART2_UART_Init(void);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __MAIN_H */
|
#endif /* __MAIN_H */
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @file stm32g0xx_hal_conf.h
|
* @file stm32g0xx_hal_conf.h
|
||||||
@@ -6,16 +7,16 @@
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
* <h2><center>© Copyright (c) 2018 STMicroelectronics.
|
* Copyright (c) 2018 STMicroelectronics.
|
||||||
* All rights reserved.</center></h2>
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This software component is licensed by ST under BSD 3-Clause license,
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
* the "License"; You may not use this file except in compliance with the
|
* in the root directory of this software component.
|
||||||
* License. You may obtain a copy of the License at:
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
* opensource.org/licenses/BSD-3-Clause
|
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
#ifndef STM32G0xx_HAL_CONF_H
|
#ifndef STM32G0xx_HAL_CONF_H
|
||||||
@@ -42,7 +43,7 @@ extern "C" {
|
|||||||
/* #define HAL_EXTI_MODULE_ENABLED */
|
/* #define HAL_EXTI_MODULE_ENABLED */
|
||||||
/* #define HAL_FDCAN_MODULE_ENABLED */
|
/* #define HAL_FDCAN_MODULE_ENABLED */
|
||||||
/* #define HAL_HCD_MODULE_ENABLED */
|
/* #define HAL_HCD_MODULE_ENABLED */
|
||||||
/* #define HAL_I2C_MODULE_ENABLED */
|
#define HAL_I2C_MODULE_ENABLED
|
||||||
/* #define HAL_I2S_MODULE_ENABLED */
|
/* #define HAL_I2S_MODULE_ENABLED */
|
||||||
/* #define HAL_IWDG_MODULE_ENABLED */
|
/* #define HAL_IWDG_MODULE_ENABLED */
|
||||||
/* #define HAL_IRDA_MODULE_ENABLED */
|
/* #define HAL_IRDA_MODULE_ENABLED */
|
||||||
@@ -53,7 +54,7 @@ extern "C" {
|
|||||||
/* #define HAL_SMARTCARD_MODULE_ENABLED */
|
/* #define HAL_SMARTCARD_MODULE_ENABLED */
|
||||||
/* #define HAL_SMBUS_MODULE_ENABLED */
|
/* #define HAL_SMBUS_MODULE_ENABLED */
|
||||||
/* #define HAL_SPI_MODULE_ENABLED */
|
/* #define HAL_SPI_MODULE_ENABLED */
|
||||||
/* #define HAL_TIM_MODULE_ENABLED */
|
#define HAL_TIM_MODULE_ENABLED
|
||||||
#define HAL_UART_MODULE_ENABLED
|
#define HAL_UART_MODULE_ENABLED
|
||||||
/* #define HAL_USART_MODULE_ENABLED */
|
/* #define HAL_USART_MODULE_ENABLED */
|
||||||
/* #define HAL_WWDG_MODULE_ENABLED */
|
/* #define HAL_WWDG_MODULE_ENABLED */
|
||||||
@@ -153,7 +154,7 @@ in voltage and temperature.*/
|
|||||||
* frequency.
|
* frequency.
|
||||||
*/
|
*/
|
||||||
#if !defined (EXTERNAL_I2S1_CLOCK_VALUE)
|
#if !defined (EXTERNAL_I2S1_CLOCK_VALUE)
|
||||||
#define EXTERNAL_I2S1_CLOCK_VALUE (12288000UL) /*!< Value of the I2S1 External clock source in Hz*/
|
#define EXTERNAL_I2S1_CLOCK_VALUE (48000UL) /*!< Value of the I2S1 External clock source in Hz*/
|
||||||
#endif /* EXTERNAL_I2S1_CLOCK_VALUE */
|
#endif /* EXTERNAL_I2S1_CLOCK_VALUE */
|
||||||
|
|
||||||
#if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
|
#if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
|
||||||
@@ -175,7 +176,7 @@ in voltage and temperature.*/
|
|||||||
* @brief This is the HAL system configuration section
|
* @brief This is the HAL system configuration section
|
||||||
*/
|
*/
|
||||||
#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */
|
#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */
|
||||||
#define TICK_INT_PRIORITY 0U /*!< tick interrupt priority */
|
#define TICK_INT_PRIORITY 3U /*!< tick interrupt priority */
|
||||||
#define USE_RTOS 0U
|
#define USE_RTOS 0U
|
||||||
#define PREFETCH_ENABLE 1U
|
#define PREFETCH_ENABLE 1U
|
||||||
#define INSTRUCTION_CACHE_ENABLE 1U
|
#define INSTRUCTION_CACHE_ENABLE 1U
|
||||||
@@ -348,5 +349,3 @@ void assert_failed(uint8_t *file, uint32_t line);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* STM32G0xx_HAL_CONF_H */
|
#endif /* STM32G0xx_HAL_CONF_H */
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ void HardFault_Handler(void);
|
|||||||
void SVC_Handler(void);
|
void SVC_Handler(void);
|
||||||
void PendSV_Handler(void);
|
void PendSV_Handler(void);
|
||||||
void SysTick_Handler(void);
|
void SysTick_Handler(void);
|
||||||
|
void USART1_IRQHandler(void);
|
||||||
|
void USART2_IRQHandler(void);
|
||||||
/* USER CODE BEGIN EFP */
|
/* USER CODE BEGIN EFP */
|
||||||
|
|
||||||
/* USER CODE END EFP */
|
/* USER CODE END EFP */
|
||||||
@@ -61,5 +63,3 @@ void SysTick_Handler(void);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __STM32G0xx_IT_H */
|
#endif /* __STM32G0xx_IT_H */
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|
||||||
|
|||||||
39
Core/Inc/uart_bridge.hpp
Normal file
39
Core/Inc/uart_bridge.hpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
//
|
||||||
|
// Created by Mysteo on 14.07.2023.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef READER_MAIN_PROG_UART_BRIDGE_HPP
|
||||||
|
#define READER_MAIN_PROG_UART_BRIDGE_HPP
|
||||||
|
#include "circular_buffer.hpp"
|
||||||
|
#include "usart.h"
|
||||||
|
|
||||||
|
|
||||||
|
class UartBridge{
|
||||||
|
|
||||||
|
public:
|
||||||
|
UartBridge(bool isOn, USART_TypeDef *uart1, USART_TypeDef *uart2, uint16_t baudRate1,
|
||||||
|
uint16_t baudRate2);
|
||||||
|
Circular_Buffer<uint8_t> *uart1Buf;
|
||||||
|
Circular_Buffer<uint8_t> *uart2Buf;
|
||||||
|
bool isTurnOn() const;
|
||||||
|
void setIsTurnOn(bool isTurnOn);
|
||||||
|
static volatile uint8_t dataFromUart1;
|
||||||
|
static volatile uint8_t dataFromUart2;
|
||||||
|
void init(void);
|
||||||
|
private:
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void uartInit(UART_HandleTypeDef* huart);
|
||||||
|
bool turnOn;
|
||||||
|
static UART_HandleTypeDef uart1Handle, uart2Handle;
|
||||||
|
public:
|
||||||
|
UART_HandleTypeDef* getHuart1() ;
|
||||||
|
|
||||||
|
UART_HandleTypeDef* getHuart2() ;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
USART_TypeDef *uart1, *uart2;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //READER_MAIN_PROG_UART_BRIDGE_HPP
|
||||||
0
Core/Src/circular_buffer.cpp
Normal file
0
Core/Src/circular_buffer.cpp
Normal file
284
Core/Src/main.c
284
Core/Src/main.c
@@ -1,284 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file : main.c
|
|
||||||
* @brief : Main program body
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* <h2><center>© Copyright (c) 2020 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
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* USER CODE END Header */
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN Includes */
|
|
||||||
#include "header.h"
|
|
||||||
/* USER CODE END Includes */
|
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PTD */
|
|
||||||
|
|
||||||
/* USER CODE END PTD */
|
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PD */
|
|
||||||
/* USER CODE END PD */
|
|
||||||
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN PM */
|
|
||||||
|
|
||||||
/* USER CODE END PM */
|
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
UART_HandleTypeDef huart2;
|
|
||||||
|
|
||||||
/* USER CODE BEGIN PV */
|
|
||||||
|
|
||||||
/* USER CODE END PV */
|
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
void SystemClock_Config(void);
|
|
||||||
static void MX_GPIO_Init(void);
|
|
||||||
/* USER CODE BEGIN PFP */
|
|
||||||
|
|
||||||
/* USER CODE END PFP */
|
|
||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
|
||||||
/* USER CODE BEGIN 0 */
|
|
||||||
/**
|
|
||||||
* @brief Vector base address configuration. It should no longer be at the start of
|
|
||||||
* flash memory but moved forward because the first part of flash is
|
|
||||||
* reserved for the bootloader. Note that this is already done by the
|
|
||||||
* bootloader before starting this program. Unfortunately, function
|
|
||||||
* SystemInit() overwrites this change again.
|
|
||||||
* @return none.
|
|
||||||
*/
|
|
||||||
static void VectorBase_Config(void)
|
|
||||||
{
|
|
||||||
/* The constant array with vectors of the vector table is declared externally in the
|
|
||||||
* c-startup code.
|
|
||||||
*/
|
|
||||||
extern const unsigned long g_pfnVectors[];
|
|
||||||
|
|
||||||
/* Remap the vector table to where the vector table is located for this program. */
|
|
||||||
SCB->VTOR = (unsigned long)&g_pfnVectors[0];
|
|
||||||
}
|
|
||||||
/* USER CODE END 0 */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The application entry point.
|
|
||||||
* @retval int
|
|
||||||
*/
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN 1 */
|
|
||||||
/* Configure the vector table base address. */
|
|
||||||
VectorBase_Config();
|
|
||||||
/* USER CODE END 1 */
|
|
||||||
|
|
||||||
/* MCU Configuration--------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
||||||
HAL_Init();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
|
||||||
|
|
||||||
/* USER CODE END Init */
|
|
||||||
|
|
||||||
/* Configure the system clock */
|
|
||||||
SystemClock_Config();
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
|
||||||
|
|
||||||
/* USER CODE END SysInit */
|
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
|
||||||
MX_GPIO_Init();
|
|
||||||
/* USER CODE BEGIN 2 */
|
|
||||||
/* Initialize the user program application. */
|
|
||||||
AppInit();
|
|
||||||
/* USER CODE END 2 */
|
|
||||||
|
|
||||||
/* Infinite loop */
|
|
||||||
/* USER CODE BEGIN WHILE */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
/* Run the user program application. */
|
|
||||||
AppTask();
|
|
||||||
/* USER CODE END WHILE */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
|
||||||
}
|
|
||||||
/* 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};
|
|
||||||
|
|
||||||
/** Configure the main internal regulator output voltage
|
|
||||||
*/
|
|
||||||
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
|
||||||
* in the RCC_OscInitTypeDef structure.
|
|
||||||
*/
|
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
|
||||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
|
||||||
RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
|
|
||||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
|
||||||
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4;
|
|
||||||
RCC_OscInitStruct.PLL.PLLN = 64;
|
|
||||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
||||||
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV4;
|
|
||||||
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_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
|
||||||
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/** Initializes the peripherals clocks
|
|
||||||
*/
|
|
||||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
|
|
||||||
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
|
|
||||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USART2 Initialization Function
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void MX_USART2_UART_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART2_Init 0 */
|
|
||||||
/* Note that this function is generated but not actually used. BootComInit() handles
|
|
||||||
* the USART initialization.
|
|
||||||
*/
|
|
||||||
/* USER CODE END USART2_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART2_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END USART2_Init 1 */
|
|
||||||
huart2.Instance = USART2;
|
|
||||||
huart2.Init.BaudRate = 115200;
|
|
||||||
huart2.Init.WordLength = UART_WORDLENGTH_8B;
|
|
||||||
huart2.Init.StopBits = UART_STOPBITS_1;
|
|
||||||
huart2.Init.Parity = UART_PARITY_NONE;
|
|
||||||
huart2.Init.Mode = UART_MODE_TX_RX;
|
|
||||||
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
||||||
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
||||||
huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
|
||||||
huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
|
|
||||||
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
|
||||||
if (HAL_UART_Init(&huart2) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN USART2_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END USART2_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_GPIOA_CLK_ENABLE();
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : PA5 */
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_5;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
|
||||||
|
|
||||||
/* USER CODE END 4 */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function is executed in case of error occurrence.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void Error_Handler(void)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
|
||||||
|
|
||||||
/* 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,
|
|
||||||
tex: 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****/
|
|
||||||
199
Core/Src/main.cpp
Normal file
199
Core/Src/main.cpp
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file : main.c
|
||||||
|
* @brief : Main program body
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* <h2><center>© Copyright (c) 2020 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
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
extern "C" {
|
||||||
|
#include "main.h"
|
||||||
|
#include "i2c.h"
|
||||||
|
#include "tim.h"
|
||||||
|
#include "usart.h"
|
||||||
|
#include "gpio.h"
|
||||||
|
}
|
||||||
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
extern "C" {
|
||||||
|
#include "header.h"
|
||||||
|
}
|
||||||
|
#include "circular_buffer.hpp"
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PTD */
|
||||||
|
|
||||||
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PD */
|
||||||
|
/* USER CODE END PD */
|
||||||
|
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN PM */
|
||||||
|
|
||||||
|
/* USER CODE END PM */
|
||||||
|
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
/* USER CODE END PV */
|
||||||
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
void SystemClock_Config(void);
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
|
/* Private user code ---------------------------------------------------------*/
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
/**
|
||||||
|
* @brief Vector base address configuration. It should no longer be at the start of
|
||||||
|
* flash memory but moved forward because the first part of flash is
|
||||||
|
* reserved for the bootloader. Note that this is already done by the
|
||||||
|
* bootloader before starting this program. Unfortunately, function
|
||||||
|
* SystemInit() overwrites this change again.
|
||||||
|
* @return none.
|
||||||
|
*/
|
||||||
|
static void VectorBase_Config(void) {
|
||||||
|
/* The constant array with vectors of the vector table is declared externally in the
|
||||||
|
* c-startup code.
|
||||||
|
*/
|
||||||
|
extern const unsigned long g_pfnVectors[];
|
||||||
|
|
||||||
|
/* Remap the vector table to where the vector table is located for this program. */
|
||||||
|
SCB->VTOR = (unsigned long) &g_pfnVectors[0];
|
||||||
|
}
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
uint8_t data3[1024];
|
||||||
|
uint8_t data2[1024];
|
||||||
|
/**
|
||||||
|
* @brief The application entry point.
|
||||||
|
* @retval int
|
||||||
|
*/
|
||||||
|
int main(void) {
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
/* Configure the vector table base address. */
|
||||||
|
VectorBase_Config();
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/* MCU Configuration--------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
|
HAL_Init();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
/* USER CODE END Init */
|
||||||
|
|
||||||
|
/* Configure the system clock */
|
||||||
|
SystemClock_Config();
|
||||||
|
|
||||||
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
|
/* Initialize all configured peripherals */
|
||||||
|
MX_GPIO_Init();
|
||||||
|
MX_I2C2_Init();
|
||||||
|
MX_TIM3_Init();
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
HAL_GPIO_TogglePin(LIGHTING_EN_GPIO_Port, LIGHTING_EN_Pin);
|
||||||
|
/* Initialize the user program application. */
|
||||||
|
AppInit();
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
/* USER CODE BEGIN WHILE */
|
||||||
|
while (1) {
|
||||||
|
/* Run the user program application. */
|
||||||
|
AppTask();
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 3 */
|
||||||
|
}
|
||||||
|
/* USER CODE END 3 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief System Clock Configuration
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void SystemClock_Config(void) {
|
||||||
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
|
/** Configure the main internal regulator output voltage
|
||||||
|
*/
|
||||||
|
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
|
||||||
|
|
||||||
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
|
* in the RCC_OscInitTypeDef structure.
|
||||||
|
*/
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
|
RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||||||
|
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_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
||||||
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) {
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 4 */
|
||||||
|
|
||||||
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void Error_Handler(void) {
|
||||||
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
|
|
||||||
|
/* 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,
|
||||||
|
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
/* USER CODE END 6 */
|
||||||
|
}
|
||||||
|
#endif /* USE_FULL_ASSERT */
|
||||||
@@ -81,73 +81,6 @@ void HAL_MspInit(void)
|
|||||||
/* USER CODE END MspInit 1 */
|
/* USER CODE END MspInit 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief UART MSP Initialization
|
|
||||||
* This function configures the hardware resources used in this example
|
|
||||||
* @param huart: UART handle pointer
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
||||||
if(huart->Instance==USART2)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN USART2_MspInit 0 */
|
|
||||||
|
|
||||||
/* USER CODE END USART2_MspInit 0 */
|
|
||||||
/* Peripheral clock enable */
|
|
||||||
__HAL_RCC_USART2_CLK_ENABLE();
|
|
||||||
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
/**USART2 GPIO Configuration
|
|
||||||
PA2 ------> USART2_TX
|
|
||||||
PA3 ------> USART2_RX
|
|
||||||
*/
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF1_USART2;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART2_MspInit 1 */
|
|
||||||
|
|
||||||
/* USER CODE END USART2_MspInit 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief UART MSP De-Initialization
|
|
||||||
* This function freeze the hardware resources used in this example
|
|
||||||
* @param huart: UART handle pointer
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
|
|
||||||
{
|
|
||||||
if(huart->Instance==USART2)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN USART2_MspDeInit 0 */
|
|
||||||
|
|
||||||
/* USER CODE END USART2_MspDeInit 0 */
|
|
||||||
/* Peripheral clock disable */
|
|
||||||
__HAL_RCC_USART2_CLK_DISABLE();
|
|
||||||
|
|
||||||
/**USART2 GPIO Configuration
|
|
||||||
PA2 ------> USART2_TX
|
|
||||||
PA3 ------> USART2_RX
|
|
||||||
*/
|
|
||||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN USART2_MspDeInit 1 */
|
|
||||||
|
|
||||||
/* USER CODE END USART2_MspDeInit 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|
||||||
|
|||||||
@@ -139,7 +139,10 @@ void SysTick_Handler(void)
|
|||||||
/* please refer to the startup file (startup_stm32g0xx.s). */
|
/* please refer to the startup file (startup_stm32g0xx.s). */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles USART1 global interrupt / USART1 wake-up interrupt through EXTI line 25.
|
||||||
|
*/
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
/* USER CODE END 1 */
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|
||||||
|
|||||||
142
Core/Src/uart_bridge.cpp
Normal file
142
Core/Src/uart_bridge.cpp
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
//
|
||||||
|
// Created by Mysteo on 14.07.2023.
|
||||||
|
//
|
||||||
|
extern "C" {
|
||||||
|
#include "usart.h"
|
||||||
|
}
|
||||||
|
#include "uart_bridge.hpp"
|
||||||
|
|
||||||
|
UartBridge* bridgePnt;
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t data[2];
|
||||||
|
|
||||||
|
extern "C" void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart){
|
||||||
|
|
||||||
|
if (huart == bridgePnt->getHuart1())
|
||||||
|
{
|
||||||
|
if (!bridgePnt->uart1Buf->is_empty() && (__HAL_UART_GET_FLAG(bridgePnt->getHuart2(), UART_FLAG_TC)))
|
||||||
|
{
|
||||||
|
data[1] = bridgePnt->uart1Buf->dequeue();
|
||||||
|
HAL_UART_Transmit_IT(bridgePnt->getHuart2(), &data[1], 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (huart == bridgePnt->getHuart2())
|
||||||
|
{
|
||||||
|
if (!bridgePnt->uart2Buf->is_empty() && (__HAL_UART_GET_FLAG(bridgePnt->getHuart1(), UART_FLAG_TC)))
|
||||||
|
{
|
||||||
|
data[2] = bridgePnt->uart2Buf->dequeue();
|
||||||
|
HAL_UART_Transmit_IT(bridgePnt->getHuart1(), &data[2], 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
|
||||||
|
|
||||||
|
if (huart == bridgePnt->getHuart1())
|
||||||
|
{
|
||||||
|
bridgePnt->uart1Buf->enqueue(bridgePnt->dataFromUart1);
|
||||||
|
HAL_UART_Receive_IT(bridgePnt->getHuart1(), (uint8_t*)&bridgePnt->dataFromUart1, 1);
|
||||||
|
}
|
||||||
|
else if (huart == bridgePnt->getHuart2())
|
||||||
|
{
|
||||||
|
bridgePnt->uart2Buf->enqueue(bridgePnt->dataFromUart2);
|
||||||
|
HAL_UART_Receive_IT(bridgePnt->getHuart2(), (uint8_t*)&bridgePnt->dataFromUart2, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
UartBridge::UartBridge(bool isOn, USART_TypeDef *uart1, USART_TypeDef *uart2, uint16_t baudRate1,
|
||||||
|
uint16_t baudRate2) : turnOn(isOn),
|
||||||
|
uart1(uart1),
|
||||||
|
uart2(uart2)
|
||||||
|
{
|
||||||
|
bridgePnt = this;
|
||||||
|
UartBridge::uart1Buf = new Circular_Buffer<uint8_t>(1024);
|
||||||
|
UartBridge::uart2Buf = new Circular_Buffer<uint8_t>(1024);
|
||||||
|
uart1Handle.Instance = uart1;
|
||||||
|
uart1Handle.Init.BaudRate = baudRate1;
|
||||||
|
uart1Handle.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
|
uart1Handle.Init.StopBits = UART_STOPBITS_1;
|
||||||
|
uart1Handle.Init.Parity = UART_PARITY_NONE;
|
||||||
|
uart1Handle.Init.Mode = UART_MODE_TX_RX;
|
||||||
|
uart1Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||||
|
uart1Handle.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||||
|
uart1Handle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
||||||
|
uart1Handle.Init.ClockPrescaler = UART_PRESCALER_DIV1;
|
||||||
|
uart1Handle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
||||||
|
uart2Handle = uart1Handle;
|
||||||
|
uart2Handle.Instance = uart2;
|
||||||
|
uart2Handle.Init.BaudRate = baudRate2;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UartBridge::isTurnOn() const {
|
||||||
|
return turnOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UartBridge::setIsTurnOn(bool isTurnOn) {
|
||||||
|
UartBridge::turnOn = isTurnOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UartBridge::uartInit(UART_HandleTypeDef *huart) {
|
||||||
|
if (HAL_UART_Init(huart) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_UARTEx_SetTxFifoThreshold(huart, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_UARTEx_SetRxFifoThreshold(huart, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_UARTEx_DisableFifoMode(huart) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
UART_HandleTypeDef* UartBridge::getHuart1() {
|
||||||
|
return &uart1Handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
UART_HandleTypeDef* UartBridge::getHuart2() {
|
||||||
|
return &uart2Handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UartBridge::init(void) {
|
||||||
|
uartInit(&uart1Handle);
|
||||||
|
uartInit(&uart2Handle);
|
||||||
|
HAL_UART_Receive_IT(&uart1Handle, (uint8_t*)&dataFromUart1, 1);
|
||||||
|
HAL_UART_Receive_IT(&uart2Handle, (uint8_t*)&dataFromUart2, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" void USART1_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN USART1_IRQn 0 */
|
||||||
|
|
||||||
|
/* USER CODE END USART1_IRQn 0 */
|
||||||
|
HAL_UART_IRQHandler(bridgePnt->getHuart1());
|
||||||
|
/* USER CODE BEGIN USART1_IRQn 1 */
|
||||||
|
|
||||||
|
/* USER CODE END USART1_IRQn 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles USART2 global interrupt / USART2 wake-up interrupt through EXTI line 26.
|
||||||
|
*/
|
||||||
|
void USART2_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN USART2_IRQn 0 */
|
||||||
|
|
||||||
|
/* USER CODE END USART2_IRQn 0 */
|
||||||
|
HAL_UART_IRQHandler(bridgePnt->getHuart2());
|
||||||
|
/* USER CODE BEGIN USART2_IRQn 1 */
|
||||||
|
|
||||||
|
/* USER CODE END USART2_IRQn 1 */
|
||||||
|
}
|
||||||
@@ -39,8 +39,8 @@ INCLUDE memory_map.inc
|
|||||||
/* Highest address of the user mode stack */
|
/* Highest address of the user mode stack */
|
||||||
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
|
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
|
||||||
|
|
||||||
_Min_Heap_Size = 0x200; /* required amount of heap */
|
_Min_Heap_Size = 0x1000; /* required amount of heap */
|
||||||
_Min_Stack_Size = 0x400; /* required amount of stack */
|
_Min_Stack_Size = 0x1000; /* required amount of stack */
|
||||||
|
|
||||||
/* Memories definition */
|
/* Memories definition */
|
||||||
MEMORY
|
MEMORY
|
||||||
|
|||||||
2
gm60.ioc
2
gm60.ioc
@@ -67,6 +67,8 @@ PA2.Mode=Asynchronous
|
|||||||
PA2.Signal=USART2_TX
|
PA2.Signal=USART2_TX
|
||||||
PA3.Mode=Asynchronous
|
PA3.Mode=Asynchronous
|
||||||
PA3.Signal=USART2_RX
|
PA3.Signal=USART2_RX
|
||||||
|
PA4.GPIOParameters=GPIO_Label
|
||||||
|
PA4.GPIO_Label=LIGHTING_EN
|
||||||
PA4.Locked=true
|
PA4.Locked=true
|
||||||
PA4.Signal=GPIO_Output
|
PA4.Signal=GPIO_Output
|
||||||
PA5.GPIOParameters=GPIO_Label
|
PA5.GPIOParameters=GPIO_Label
|
||||||
|
|||||||
21537
stm32g070.svd
Normal file
21537
stm32g070.svd
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user