mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-05-06 00:00:18 +00:00
Uart working
This commit is contained in:
parent
419c55d807
commit
cad6b45c5d
@ -36,7 +36,7 @@
|
|||||||
</tool>
|
</tool>
|
||||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.400718382" name="MCU/MPU GCC Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler">
|
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.400718382" name="MCU/MPU GCC Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler">
|
||||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.1282773953" name="Debug level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.value.g3" valueType="enumerated"/>
|
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.1282773953" name="Debug level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.value.g3" valueType="enumerated"/>
|
||||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.394842051" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.oz" valueType="enumerated"/>
|
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.394842051" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.os" valueType="enumerated"/>
|
||||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols.1350178782" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
|
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols.1350178782" 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="DEBUG"/>
|
<listOptionValue builtIn="false" value="DEBUG"/>
|
||||||
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
|
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
|
||||||
@ -117,7 +117,7 @@
|
|||||||
</tool>
|
</tool>
|
||||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.422705567" name="MCU/MPU GCC Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler">
|
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.422705567" name="MCU/MPU GCC Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler">
|
||||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.131805638" name="Debug level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.value.g0" valueType="enumerated"/>
|
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.131805638" name="Debug level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.value.g0" valueType="enumerated"/>
|
||||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.324687102" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.os" valueType="enumerated"/>
|
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.324687102" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.o1" valueType="enumerated"/>
|
||||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols.971138536" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
|
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols.971138536" 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"/>
|
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
|
||||||
<listOptionValue builtIn="false" value="STM32F103xB"/>
|
<listOptionValue builtIn="false" value="STM32F103xB"/>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
<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.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" 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="4489868063458550" 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="1139920058673081605" 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.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
@ -16,7 +16,7 @@
|
|||||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
<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.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" 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="4489868063458550" 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="1139920058673081605" 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.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -10,21 +10,21 @@
|
|||||||
|
|
||||||
#define START_ADR_SHOT (START_ADR_STAT+STAT_BLOCKSIZE)
|
#define START_ADR_SHOT (START_ADR_STAT+STAT_BLOCKSIZE)
|
||||||
#define SHOT_BLOCKSIZE 10
|
#define SHOT_BLOCKSIZE 10
|
||||||
#define MAX_NUMBER_SHOTS 255
|
#define MAX_SHOT_COUNT 256
|
||||||
|
|
||||||
#define START_ADR_PROGRAM (START_ADR_SHOT + (SHOT_BLOCKSIZE*MAX_NUMBER_SHOTS))
|
#define START_ADR_PROGRAM (START_ADR_SHOT + (SHOT_BLOCKSIZE*MAX_SHOT_COUNT))
|
||||||
#define PROGRAM_BLOCKSIZE 203
|
#define PROGRAM_BLOCKSIZE 67
|
||||||
#define MAX_NUMBER_PROGRAMS 100
|
#define MAX_PROGRAM_COUNT 256
|
||||||
#define MAX_NUMBER_SHOTS_IN_PROGRAMS \
|
#define MAX_SHOT_COUNT_IN_PROGRAMS \
|
||||||
(PROGRAM_BLOCKSIZE-sizeof(ProgramHeader)) /sizeof(ProgramShot) // 100
|
(PROGRAM_BLOCKSIZE-sizeof(ProgramHeader)) /sizeof(ProgramShot) //
|
||||||
|
|
||||||
#define START_ADR_MACRO (START_ADR_PROGRAM + (PROGRAM_BLOCKSIZE*MAX_NUMBER_PROGRAMS))
|
#define START_ADR_MACRO (START_ADR_PROGRAM + (PROGRAM_BLOCKSIZE*MAX_PROGRAM_COUNT))
|
||||||
#define MACRO_BLOCKSIZE 81
|
#define MACRO_BLOCKSIZE 129
|
||||||
#define MAX_NUMBER_MACRO 100
|
#define MAX_MACRO_COUNT 100
|
||||||
#define MAX_NUMBER_PROGRAMS_IN_MACRO \
|
#define MAX_PROGRAM_COUNT_IN_MACRO \
|
||||||
(MACRO_BLOCKSIZE-sizeof(MacroHeader)) /sizeof(MacroProgram) // 20
|
(MACRO_BLOCKSIZE-sizeof(MacroHeader)) /sizeof(MacroProgram) //
|
||||||
|
|
||||||
#define MEMORY_END (START_ADR_MACRO + (MACRO_BLOCKSIZE*MAX_NUMBER_MACRO))
|
#define MEMORY_END (START_ADR_MACRO + (MACRO_BLOCKSIZE*MAX_MACRO_COUNT))
|
||||||
|
|
||||||
typedef enum MemoryStatus {
|
typedef enum MemoryStatus {
|
||||||
EEPROM_FAIL,
|
EEPROM_FAIL,
|
||||||
@ -58,7 +58,7 @@ typedef struct ProgramShot {
|
|||||||
|
|
||||||
typedef struct Program {
|
typedef struct Program {
|
||||||
ProgramHeader header;
|
ProgramHeader header;
|
||||||
ProgramShot shots[MAX_NUMBER_SHOTS_IN_PROGRAMS];
|
ProgramShot shots[MAX_SHOT_COUNT_IN_PROGRAMS];
|
||||||
} Program;
|
} Program;
|
||||||
|
|
||||||
typedef struct MacroHeader {
|
typedef struct MacroHeader {
|
||||||
@ -74,7 +74,7 @@ typedef struct MacroProgram {
|
|||||||
|
|
||||||
typedef struct Macro {
|
typedef struct Macro {
|
||||||
MacroHeader header;
|
MacroHeader header;
|
||||||
MacroProgram programs[MAX_NUMBER_PROGRAMS_IN_MACRO];
|
MacroProgram programs[MAX_PROGRAM_COUNT_IN_MACRO];
|
||||||
} Macro;
|
} Macro;
|
||||||
|
|
||||||
typedef struct ServoSetting {
|
typedef struct ServoSetting {
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
/*
|
|
||||||
* GlobalDefines.h
|
|
||||||
*
|
|
||||||
* Created on: Aug 25, 2024
|
|
||||||
* Author: DashyFox
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INC_GLOBALDEFINES_H_
|
|
||||||
#define INC_GLOBALDEFINES_H_
|
|
||||||
|
|
||||||
#define UART_BUFFER_SIZE 64
|
|
||||||
|
|
||||||
#endif /* INC_GLOBALDEFINES_H_ */
|
|
@ -9,3 +9,4 @@
|
|||||||
void print(char* str);
|
void print(char* str);
|
||||||
void int_to_str(int number, char *str, int base);
|
void int_to_str(int number, char *str, int base);
|
||||||
void printNumber(long int number);
|
void printNumber(long int number);
|
||||||
|
void printHexBuffer(uint8_t *buffer, uint16_t size);
|
||||||
|
@ -30,6 +30,7 @@ void stopShooting();
|
|||||||
|
|
||||||
|
|
||||||
void setPos(uint8_t axial, uint8_t horizontal, uint8_t vertical);
|
void setPos(uint8_t axial, uint8_t horizontal, uint8_t vertical);
|
||||||
|
void setPosSingle(ServoMap servo, uint8_t value);
|
||||||
void setPosDefault();
|
void setPosDefault();
|
||||||
|
|
||||||
// 0 .. 100
|
// 0 .. 100
|
||||||
|
42
Core/Inc/UART3_CMD_Handler.h
Normal file
42
Core/Inc/UART3_CMD_Handler.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* UART3_CMD_Handler.h
|
||||||
|
*
|
||||||
|
* Created on: Sep 12, 2024
|
||||||
|
* Author: DashyFox
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INC_UART3_CMD_HANDLER_H_
|
||||||
|
#define INC_UART3_CMD_HANDLER_H_
|
||||||
|
|
||||||
|
#include "stm32f1xx_hal.h"
|
||||||
|
|
||||||
|
void UART3_SaveShot(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_SaveProgram(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_SaveMacro(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_StartMacro(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_StartProgram(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_StartShot(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_Stop(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_DeleteShot(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_DeleteProgram(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_DeleteMacro(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_DeleteAllData(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_GetDeviceStatus(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_SetServoOffset(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_GetServoOffset(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_SetServoMaxAngle(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_GetServoMaxAngle(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_MoveServoToInitialPosition(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_SetStartupDelay(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_GetStartupDelay(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_SetMinRollerSpeed(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_GetMinRollerSpeed(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_SetMinScrewSpeed(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_GetMinScrewSpeed(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_SetServoInvertFlag(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_GetServoInvertFlag(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_ReadStatistics(uint8_t *dataPtr, uint8_t len);
|
||||||
|
void UART3_ResetStatistics(uint8_t *dataPtr, uint8_t len);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* INC_UART3_CMD_HANDLER_H_ */
|
20
Core/Inc/UART3_Handler.h
Normal file
20
Core/Inc/UART3_Handler.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* UART3_Handler.h
|
||||||
|
*
|
||||||
|
* Created on: Sep 12, 2024
|
||||||
|
* Author: DashyFox
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INC_UART3_HANDLER_H_
|
||||||
|
#define INC_UART3_HANDLER_H_
|
||||||
|
|
||||||
|
#include "stm32f1xx_hal.h"
|
||||||
|
|
||||||
|
#define UART_BUFFER_SIZE 256
|
||||||
|
|
||||||
|
extern uint8_t uart_rx_buffer[UART_BUFFER_SIZE];
|
||||||
|
|
||||||
|
void UART3_START();
|
||||||
|
void UART3_Handler();
|
||||||
|
|
||||||
|
#endif /* INC_UART3_HANDLER_H_ */
|
@ -42,7 +42,7 @@
|
|||||||
/*#define HAL_CORTEX_MODULE_ENABLED */
|
/*#define HAL_CORTEX_MODULE_ENABLED */
|
||||||
/*#define HAL_CRC_MODULE_ENABLED */
|
/*#define HAL_CRC_MODULE_ENABLED */
|
||||||
/*#define HAL_DAC_MODULE_ENABLED */
|
/*#define HAL_DAC_MODULE_ENABLED */
|
||||||
/*#define HAL_DMA_MODULE_ENABLED */
|
#define HAL_DMA_MODULE_ENABLED
|
||||||
/*#define HAL_ETH_MODULE_ENABLED */
|
/*#define HAL_ETH_MODULE_ENABLED */
|
||||||
/*#define HAL_FLASH_MODULE_ENABLED */
|
/*#define HAL_FLASH_MODULE_ENABLED */
|
||||||
#define HAL_GPIO_MODULE_ENABLED
|
#define HAL_GPIO_MODULE_ENABLED
|
||||||
|
@ -57,6 +57,7 @@ void PendSV_Handler(void);
|
|||||||
void SysTick_Handler(void);
|
void SysTick_Handler(void);
|
||||||
void EXTI0_IRQHandler(void);
|
void EXTI0_IRQHandler(void);
|
||||||
void EXTI1_IRQHandler(void);
|
void EXTI1_IRQHandler(void);
|
||||||
|
void DMA1_Channel3_IRQHandler(void);
|
||||||
void USB_LP_CAN1_RX0_IRQHandler(void);
|
void USB_LP_CAN1_RX0_IRQHandler(void);
|
||||||
void TIM3_IRQHandler(void);
|
void TIM3_IRQHandler(void);
|
||||||
void I2C1_EV_IRQHandler(void);
|
void I2C1_EV_IRQHandler(void);
|
||||||
|
@ -43,7 +43,7 @@ MemoryStatus getShot(unsigned char number, Shot *shot) {
|
|||||||
|
|
||||||
MemoryStatus saveProg(unsigned char number, Program *prog) {
|
MemoryStatus saveProg(unsigned char number, Program *prog) {
|
||||||
MemoryStatus result = EEPROM_OK;
|
MemoryStatus result = EEPROM_OK;
|
||||||
for (uint16_t i = 0; i < MAX_NUMBER_SHOTS_IN_PROGRAMS; ++i) {
|
for (uint16_t i = 0; i < MAX_SHOT_COUNT_IN_PROGRAMS; ++i) {
|
||||||
Shot shot;
|
Shot shot;
|
||||||
MemoryStatus stat = getShot(prog->shots[i].id, &shot);
|
MemoryStatus stat = getShot(prog->shots[i].id, &shot);
|
||||||
if (!(stat == EEPROM_OK || stat == EEPROM_MISSING_ELEMENT)) {
|
if (!(stat == EEPROM_OK || stat == EEPROM_MISSING_ELEMENT)) {
|
||||||
@ -77,7 +77,7 @@ MemoryStatus getProg(unsigned char number, Program *prog) {
|
|||||||
|
|
||||||
MemoryStatus saveMacro(unsigned char number, Macro *macro) {
|
MemoryStatus saveMacro(unsigned char number, Macro *macro) {
|
||||||
MemoryStatus result = EEPROM_OK;
|
MemoryStatus result = EEPROM_OK;
|
||||||
for (uint16_t i = 0; i < MAX_NUMBER_PROGRAMS_IN_MACRO; ++i) {
|
for (uint16_t i = 0; i < MAX_PROGRAM_COUNT_IN_MACRO; ++i) {
|
||||||
Program prog;
|
Program prog;
|
||||||
MemoryStatus stat = getProg(macro->programs[i].id, &prog);
|
MemoryStatus stat = getProg(macro->programs[i].id, &prog);
|
||||||
if (!(stat == EEPROM_OK || stat == EEPROM_MISSING_ELEMENT)) {
|
if (!(stat == EEPROM_OK || stat == EEPROM_MISSING_ELEMENT)) {
|
||||||
@ -246,9 +246,9 @@ MemoryStatus FLASH_WriteBlock(uint16_t startAddr, uint8_t number,
|
|||||||
HAL_StatusTypeDef result;
|
HAL_StatusTypeDef result;
|
||||||
|
|
||||||
// Проверка на корректность входных данных
|
// Проверка на корректность входных данных
|
||||||
if ((startAddr == START_ADR_SHOT && number > MAX_NUMBER_SHOTS)
|
if ((startAddr == START_ADR_SHOT && number >= MAX_SHOT_COUNT)
|
||||||
|| (startAddr == START_ADR_PROGRAM && number > MAX_NUMBER_PROGRAMS)
|
|| (startAddr == START_ADR_PROGRAM && number >= MAX_PROGRAM_COUNT)
|
||||||
|| (startAddr == START_ADR_MACRO && number > MAX_NUMBER_MACRO)) {
|
|| (startAddr == START_ADR_MACRO && number >= MAX_MACRO_COUNT)) {
|
||||||
return EEPROM_OUT_OF_RANGE;
|
return EEPROM_OUT_OF_RANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,9 +278,9 @@ MemoryStatus FLASH_ReadBlock(uint16_t startAddr, uint8_t number,
|
|||||||
HAL_StatusTypeDef result;
|
HAL_StatusTypeDef result;
|
||||||
|
|
||||||
// Проверка на корректность входных данных
|
// Проверка на корректность входных данных
|
||||||
if ((startAddr == START_ADR_SHOT && number > MAX_NUMBER_SHOTS)
|
if ((startAddr == START_ADR_SHOT && number > MAX_SHOT_COUNT)
|
||||||
|| (startAddr == START_ADR_PROGRAM && number > MAX_NUMBER_PROGRAMS)
|
|| (startAddr == START_ADR_PROGRAM && number > MAX_PROGRAM_COUNT)
|
||||||
|| (startAddr == START_ADR_MACRO && number > MAX_NUMBER_MACRO)) {
|
|| (startAddr == START_ADR_MACRO && number > MAX_MACRO_COUNT)) {
|
||||||
return EEPROM_OUT_OF_RANGE;
|
return EEPROM_OUT_OF_RANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,15 +8,13 @@
|
|||||||
|
|
||||||
void print(char *str) {
|
void print(char *str) {
|
||||||
unsigned int size = 0;
|
unsigned int size = 0;
|
||||||
while (str[size] != '\0')
|
while (str[size] != '\0') {
|
||||||
{
|
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
CDC_Transmit_FS((unsigned char*) str, size);
|
CDC_Transmit_FS((unsigned char*) str, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void int_to_str(int number, char *str, int base)
|
void int_to_str(int number, char *str, int base) {
|
||||||
{
|
|
||||||
static const char digits[] = "0123456789ABCDEF";
|
static const char digits[] = "0123456789ABCDEF";
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
char *ptr = buffer + sizeof(buffer) - 1;
|
char *ptr = buffer + sizeof(buffer) - 1;
|
||||||
@ -45,8 +43,7 @@ void int_to_str(int number, char *str, int base)
|
|||||||
strcpy(str, ptr);
|
strcpy(str, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printNumber(long int number)
|
void printNumber(long int number) {
|
||||||
{
|
|
||||||
char buffer[BUFFER_SIZE];
|
char buffer[BUFFER_SIZE];
|
||||||
|
|
||||||
// Преобразование числа в строку
|
// Преобразование числа в строку
|
||||||
@ -56,3 +53,28 @@ void printNumber(long int number)
|
|||||||
// Отправка строки через USB CDC
|
// Отправка строки через USB CDC
|
||||||
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printHexBuffer(uint8_t *buffer, uint16_t size) {
|
||||||
|
char hex_str[3 * size + 3]; // Строка для хранения шестнадцатеричных значений (2 символа на байт, пробелы и переносы строк)
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
for (uint16_t i = 0; i < size; i++) {
|
||||||
|
// Преобразуем каждый байт в шестнадцатеричный формат
|
||||||
|
index += sprintf(&hex_str[index], "%02X ", buffer[i]);
|
||||||
|
|
||||||
|
// Добавляем перенос строки после каждых 8 байт
|
||||||
|
if ((i + 1) % 32 == 0) {
|
||||||
|
hex_str[index++] = '\n';
|
||||||
|
} else if ((i + 1) % 8 == 0) {
|
||||||
|
hex_str[index++] = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Добавляем два переноса строки в конце
|
||||||
|
hex_str[index++] = '\n';
|
||||||
|
hex_str[index++] = '\n';
|
||||||
|
hex_str[index] = '\0'; // Завершаем строку символом конца строки
|
||||||
|
|
||||||
|
// Отправляем строку через UART (CDC)
|
||||||
|
CDC_Transmit_FS((uint8_t*) hex_str, strlen(hex_str));
|
||||||
|
}
|
||||||
|
@ -37,22 +37,15 @@ Current current;
|
|||||||
|
|
||||||
HardwareInit_t hwSettings = {
|
HardwareInit_t hwSettings = {
|
||||||
/*DelayTimes*/{
|
/*DelayTimes*/{
|
||||||
/*preRun*/ 0
|
/*preRun*/0 },
|
||||||
},
|
/*ServoSetting*/{ { 0, 0, 90, 180 }, { 0, 0, 90, 180 }, { 0, 0, 90, 180 } },
|
||||||
/*ServoSetting*/{
|
/*Motors*/{ 0, 0 } };
|
||||||
{0, 0, 90, 180},
|
|
||||||
{0, 0, 90, 180},
|
|
||||||
{0, 0, 90, 180}
|
|
||||||
},
|
|
||||||
/*Motors*/{
|
|
||||||
0, 0
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
extern int16_t Vz1;
|
extern int16_t Vz1;
|
||||||
extern int16_t Vz2;
|
extern int16_t Vz2;
|
||||||
|
|
||||||
int16_t map(int16_t x, int16_t in_min, int16_t in_max, int16_t out_min, int16_t out_max) {
|
int16_t map(int16_t x, int16_t in_min, int16_t in_max, int16_t out_min,
|
||||||
|
int16_t out_max) {
|
||||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,15 +65,22 @@ void startShooting() {
|
|||||||
if (current.shot.isExist) {
|
if (current.shot.isExist) {
|
||||||
print("Fire!\n");
|
print("Fire!\n");
|
||||||
|
|
||||||
print("isExist ");printNumber(current.shot.isExist);
|
print("isExist ");
|
||||||
print("countRepeatShot; ");printNumber(current.shot.countRepeatShot);
|
printNumber(current.shot.isExist);
|
||||||
print("speedRollerTop; ");printNumber(current.shot.speedRollerTop);
|
print("countRepeatShot; ");
|
||||||
print("speedRollerBottom; ");printNumber(current.shot.speedRollerBottom);
|
printNumber(current.shot.countRepeatShot);
|
||||||
print("speedScrew; ");printNumber(current.shot.speedScrew);
|
print("speedRollerTop; ");
|
||||||
print("rotationAxial; ");printNumber(current.shot.rotationAxial);
|
printNumber(current.shot.speedRollerTop);
|
||||||
print("rotationHorizontal; ");printNumber(current.shot.rotationHorizontal);
|
print("speedRollerBottom; ");
|
||||||
print("rotationVertical; ");printNumber(current.shot.rotationVertical);
|
printNumber(current.shot.speedRollerBottom);
|
||||||
|
print("speedScrew; ");
|
||||||
|
printNumber(current.shot.speedScrew);
|
||||||
|
print("rotationAxial; ");
|
||||||
|
printNumber(current.shot.rotationAxial);
|
||||||
|
print("rotationHorizontal; ");
|
||||||
|
printNumber(current.shot.rotationHorizontal);
|
||||||
|
print("rotationVertical; ");
|
||||||
|
printNumber(current.shot.rotationVertical);
|
||||||
|
|
||||||
isShooting = 1;
|
isShooting = 1;
|
||||||
doShot(¤t.shot);
|
doShot(¤t.shot);
|
||||||
@ -126,26 +126,30 @@ uint8_t prepareShot(uint8_t number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setPosSingle(ServoMap servo, uint8_t value) {
|
||||||
|
if (hwSettings.servos[servo].invert)
|
||||||
|
value = 180 - value;
|
||||||
|
SetServo(servo, value);
|
||||||
|
}
|
||||||
void setPos(uint8_t axial, uint8_t horizontal, uint8_t vertical) {
|
void setPos(uint8_t axial, uint8_t horizontal, uint8_t vertical) {
|
||||||
|
setPosSingle(SERVO_AXIAL, axial);
|
||||||
//todo:
|
setPosSingle(SERVO_HORIZONTAL, horizontal);
|
||||||
// hwSettings.servos[SERVO_AXIAL].invert
|
setPosSingle(SERVO_VERTICAL, vertical);
|
||||||
|
|
||||||
SetServo(SERVO_AXIAL, axial); // Axial
|
|
||||||
SetServo(SERVO_HORIZONTAL, horizontal); // Horizontal
|
|
||||||
SetServo(SERVO_VERTICAL, vertical); // Vertical
|
|
||||||
}
|
}
|
||||||
void setPosDefault() {
|
void setPosDefault() {
|
||||||
SetServo(SERVO_AXIAL, hwSettings.servos[SERVO_AXIAL].def); // Axial
|
setPos(
|
||||||
SetServo(SERVO_HORIZONTAL, hwSettings.servos[SERVO_HORIZONTAL].def); // Horizontal
|
hwSettings.servos[SERVO_AXIAL].def,
|
||||||
SetServo(SERVO_VERTICAL, hwSettings.servos[SERVO_VERTICAL].def); // Vertical
|
hwSettings.servos[SERVO_HORIZONTAL].def,
|
||||||
|
hwSettings.servos[SERVO_VERTICAL].def
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0 .. 100
|
// 0 .. 100
|
||||||
void setScrewkSpeed(uint8_t speed) {
|
void setScrewkSpeed(uint8_t speed) {
|
||||||
|
|
||||||
// if(speed < 0) speed = 0;
|
// if(speed < 0) speed = 0;
|
||||||
if(speed > 100) speed = 100;
|
if (speed > 100)
|
||||||
|
speed = 100;
|
||||||
|
|
||||||
speed = map(speed, 0, 100, hwSettings.motors.speed_Screw_min, 100);
|
speed = map(speed, 0, 100, hwSettings.motors.speed_Screw_min, 100);
|
||||||
|
|
||||||
|
239
Core/Src/UART3_CMD_Handler.c
Normal file
239
Core/Src/UART3_CMD_Handler.c
Normal file
@ -0,0 +1,239 @@
|
|||||||
|
/*
|
||||||
|
* UART3_CMD_Handler.c
|
||||||
|
*
|
||||||
|
* Created on: Sep 12, 2024
|
||||||
|
* Author: DashyFox
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "UART3_CMD_Handler.h"
|
||||||
|
#include "Print.h"
|
||||||
|
|
||||||
|
extern void SendResponse(uint8_t command, uint8_t result, uint8_t *data,
|
||||||
|
uint8_t data_length);
|
||||||
|
|
||||||
|
uint8_t checkLen(uint8_t cmd, uint8_t current_length, uint8_t required_length) {
|
||||||
|
if (current_length >= required_length) {
|
||||||
|
print("Invalid length for command");
|
||||||
|
printNumber(cmd);
|
||||||
|
print("\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_SaveShot(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_SaveProgram(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_SaveMacro(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_StartMacro(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_StartProgram(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_StartShot(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_Stop(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_DeleteShot(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_DeleteProgram(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_DeleteMacro(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_DeleteAllData(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_GetDeviceStatus(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_SetServoOffset(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_GetServoOffset(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_SetServoMaxAngle(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_GetServoMaxAngle(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_MoveServoToInitialPosition(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_SetStartupDelay(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_GetStartupDelay(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_SetMinRollerSpeed(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_GetMinRollerSpeed(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_SetMinScrewSpeed(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_GetMinScrewSpeed(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_SetServoInvertFlag(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_GetServoInvertFlag(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_ReadStatistics(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_ResetStatistics(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||||
|
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
295
Core/Src/UART3_Handler.c
Normal file
295
Core/Src/UART3_Handler.c
Normal file
@ -0,0 +1,295 @@
|
|||||||
|
/*
|
||||||
|
* UART3_Handler.c
|
||||||
|
*
|
||||||
|
* Created on: Sep 12, 2024
|
||||||
|
* Author: DashyFox
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "UART3_Handler.h"
|
||||||
|
#include "UART3_CMD_Handler.h"
|
||||||
|
#include "Print.h"
|
||||||
|
#include "SimpleTimer.h"
|
||||||
|
|
||||||
|
uint8_t uart_rx_buffer[UART_BUFFER_SIZE];
|
||||||
|
uint8_t uart_rx_buffer_out[UART_BUFFER_SIZE];
|
||||||
|
volatile uint8_t uart_rx_comlite = 0;
|
||||||
|
|
||||||
|
extern UART_HandleTypeDef huart3;
|
||||||
|
|
||||||
|
void UART3_CMD_Handler(uint8_t *dataPtr, uint8_t len);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void UART3_START() {
|
||||||
|
HAL_UART_Receive_DMA(&huart3, uart_rx_buffer, UART_BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
|
||||||
|
// if (huart->Instance == USART3) {
|
||||||
|
// uartTimer = millis();
|
||||||
|
// packet_index++;
|
||||||
|
//
|
||||||
|
// CDC_Transmit_FS(uart_rx_buffer, UART_BUFFER_SIZE);
|
||||||
|
//
|
||||||
|
// if (packet_index < UART_BUFFER_SIZE) {
|
||||||
|
// HAL_UART_Receive_DMA(&huart3, &uart_rx_buffer[packet_index], 1);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
volatile uint32_t last_rx_time = 0;
|
||||||
|
volatile uint32_t rx_complete_timeout = 10;
|
||||||
|
volatile uint32_t old_pos = 0;
|
||||||
|
volatile uint16_t rx_index = 0;
|
||||||
|
extern DMA_HandleTypeDef hdma_usart3_rx;
|
||||||
|
void handle_rx_complete(uint8_t *data, uint16_t len)
|
||||||
|
{
|
||||||
|
// Проверка, если данных пришло меньше двух байт
|
||||||
|
if (len < 2) {
|
||||||
|
char error_msg[64];
|
||||||
|
snprintf(error_msg, sizeof(error_msg),
|
||||||
|
"Received less than 2 bytes: len = %d\n", len);
|
||||||
|
CDC_Transmit_FS((uint8_t*) error_msg, strlen(error_msg));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Распечатать пришедший буфер с указанием номеров байт
|
||||||
|
char byte_msg[128];
|
||||||
|
snprintf(byte_msg, sizeof(byte_msg), "Received buffer (%d bytes):\n", len);
|
||||||
|
CDC_Transmit_FS((uint8_t*) byte_msg, strlen(byte_msg));
|
||||||
|
|
||||||
|
for (uint16_t i = 0; i < len; i++) {
|
||||||
|
char byte_info[32];
|
||||||
|
snprintf(byte_info, sizeof(byte_info), "Byte %d: 0x%02X\n", i, data[i]);
|
||||||
|
CDC_Transmit_FS((uint8_t*) byte_info, strlen(byte_info));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка правильности пакета (первый байт должен быть 0xF0)
|
||||||
|
if (data[0] != 0xF0) {
|
||||||
|
char error_msg[64];
|
||||||
|
snprintf(error_msg, sizeof(error_msg),
|
||||||
|
"Wrong fix 0xF0: received 0x%02X\n", data[0]);
|
||||||
|
CDC_Transmit_FS((uint8_t*) error_msg, strlen(error_msg));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка длины пакета
|
||||||
|
uint8_t length = data[1];
|
||||||
|
if (length + 3 > UART_BUFFER_SIZE) {
|
||||||
|
char error_msg[128];
|
||||||
|
snprintf(error_msg, sizeof(error_msg),
|
||||||
|
"Packet length exceeds buffer size: received length = %d, max size = %d\n",
|
||||||
|
length + 3, UART_BUFFER_SIZE);
|
||||||
|
CDC_Transmit_FS((uint8_t*) error_msg, strlen(error_msg));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка контрольной суммы
|
||||||
|
uint16_t checksum = 0;
|
||||||
|
for (uint8_t i = 0; i < length + 2; i++) {
|
||||||
|
checksum += data[i];
|
||||||
|
}
|
||||||
|
checksum %= 0xFF;
|
||||||
|
|
||||||
|
if (checksum != data[length + 2]) {
|
||||||
|
char error_msg[64];
|
||||||
|
snprintf(error_msg, sizeof(error_msg),
|
||||||
|
"Wrong checksum: calculated 0x%02X, received 0x%02X\n",
|
||||||
|
checksum, data[length + 2]);
|
||||||
|
CDC_Transmit_FS((uint8_t*) error_msg, strlen(error_msg));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CDC_Transmit_FS((uint8_t*)"\n\n", 2);
|
||||||
|
|
||||||
|
// Если пакет корректен, передать управление обработчику команд
|
||||||
|
uint8_t *data_ptr = &data[2];
|
||||||
|
UART3_CMD_Handler(data_ptr, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void handle_rx_data(uint8_t* data, uint16_t len)
|
||||||
|
{
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
if(!rx_index){
|
||||||
|
memset(uart_rx_buffer_out, 0x00, UART_BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
memcpy(uart_rx_buffer_out+rx_index, data, len);
|
||||||
|
rx_index += len;
|
||||||
|
|
||||||
|
// uint8_t ff = 0xFF;
|
||||||
|
// CDC_Transmit_FS(&ff, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void process_uart_data(uint32_t old_pos, uint32_t new_pos)
|
||||||
|
{
|
||||||
|
if (new_pos > old_pos)
|
||||||
|
{
|
||||||
|
// Обрабатываем данные между old_pos и new_pos
|
||||||
|
handle_rx_data(&uart_rx_buffer[old_pos], new_pos - old_pos);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Обрабатываем данные от old_pos до конца буфера и от начала до new_pos
|
||||||
|
handle_rx_data(&uart_rx_buffer[old_pos], UART_BUFFER_SIZE - old_pos);
|
||||||
|
handle_rx_data(&uart_rx_buffer[0], new_pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
volatile uint8_t rx_in_progress = 0;
|
||||||
|
void check_uart3_timeout(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_Handler() {
|
||||||
|
// Текущая позиция в буфере (DMA передаёт значение обратного счётчика)
|
||||||
|
uint32_t pos = UART_BUFFER_SIZE - __HAL_DMA_GET_COUNTER(&hdma_usart3_rx);
|
||||||
|
|
||||||
|
if (pos != old_pos)
|
||||||
|
{
|
||||||
|
// Если есть новые данные, обновляем таймер
|
||||||
|
last_rx_time = millis();
|
||||||
|
rx_in_progress = 1;
|
||||||
|
process_uart_data(old_pos, pos); // Обрабатываем новые данные
|
||||||
|
old_pos = pos; // Обновляем позицию
|
||||||
|
}
|
||||||
|
else if (rx_in_progress && (millis() - last_rx_time) > rx_complete_timeout)
|
||||||
|
{
|
||||||
|
handle_rx_complete(uart_rx_buffer_out, rx_index);
|
||||||
|
rx_index = 0;
|
||||||
|
last_rx_time = millis();
|
||||||
|
rx_in_progress = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SendResponse(uint8_t command, uint8_t result, uint8_t *data,
|
||||||
|
uint8_t data_length) {
|
||||||
|
uint8_t response_buffer[64];
|
||||||
|
uint8_t index = 0;
|
||||||
|
|
||||||
|
response_buffer[index++] = 0xF0;
|
||||||
|
response_buffer[index++] = data_length + 3;
|
||||||
|
response_buffer[index++] = command;
|
||||||
|
response_buffer[index++] = result;
|
||||||
|
|
||||||
|
if (data != NULL && data_length > 0) {
|
||||||
|
for (uint8_t i = 0; i < data_length; i++) {
|
||||||
|
response_buffer[index++] = data[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t checksum = 0;
|
||||||
|
for (uint8_t i = 0; i < index; i++) {
|
||||||
|
checksum += response_buffer[i];
|
||||||
|
}
|
||||||
|
checksum %= 0xFF;
|
||||||
|
|
||||||
|
response_buffer[index++] = checksum;
|
||||||
|
HAL_UART_Transmit(&huart3, response_buffer, index, HAL_MAX_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART3_CMD_Handler(uint8_t *dataPtr, uint8_t len) {
|
||||||
|
uint8_t command = dataPtr[0];
|
||||||
|
|
||||||
|
print("Received command: ");
|
||||||
|
printNumber(command);
|
||||||
|
print("\nParameters: [");
|
||||||
|
|
||||||
|
for (uint8_t i = 1; i < len; i++) {
|
||||||
|
printNumber(dataPtr[i]);
|
||||||
|
if (i < len - 1) {
|
||||||
|
print(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print("]\n");
|
||||||
|
|
||||||
|
switch (command) {
|
||||||
|
case 10:
|
||||||
|
UART3_SaveShot(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
UART3_SaveProgram(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
UART3_SaveMacro(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 100:
|
||||||
|
UART3_StartMacro(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 101:
|
||||||
|
UART3_StartProgram(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 102:
|
||||||
|
UART3_StartShot(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 110:
|
||||||
|
UART3_Stop(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 13:
|
||||||
|
UART3_DeleteShot(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 14:
|
||||||
|
UART3_DeleteProgram(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 15:
|
||||||
|
UART3_DeleteMacro(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 120:
|
||||||
|
UART3_DeleteAllData(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 180:
|
||||||
|
UART3_GetDeviceStatus(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 200:
|
||||||
|
UART3_SetServoOffset(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 204:
|
||||||
|
UART3_GetServoOffset(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 201:
|
||||||
|
UART3_SetServoMaxAngle(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 202:
|
||||||
|
UART3_GetServoMaxAngle(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 203:
|
||||||
|
UART3_MoveServoToInitialPosition(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 206:
|
||||||
|
UART3_SetStartupDelay(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 207:
|
||||||
|
UART3_GetStartupDelay(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 210:
|
||||||
|
UART3_SetMinRollerSpeed(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 211:
|
||||||
|
UART3_GetMinRollerSpeed(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 212:
|
||||||
|
UART3_SetMinScrewSpeed(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 213:
|
||||||
|
UART3_GetMinScrewSpeed(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 214:
|
||||||
|
UART3_SetServoInvertFlag(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 215:
|
||||||
|
UART3_GetServoInvertFlag(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 181:
|
||||||
|
UART3_ReadStatistics(dataPtr, len);
|
||||||
|
break;
|
||||||
|
case 121:
|
||||||
|
UART3_ResetStatistics(dataPtr, len);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
print("Unknown command");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
208
Core/Src/main.c
208
Core/Src/main.c
@ -23,8 +23,6 @@
|
|||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
|
|
||||||
#include "GlobalDefines.h"
|
|
||||||
|
|
||||||
#include "usbd_cdc_if.h"
|
#include "usbd_cdc_if.h"
|
||||||
#include "pca9685.h"
|
#include "pca9685.h"
|
||||||
#include "IR.h"
|
#include "IR.h"
|
||||||
@ -34,6 +32,7 @@
|
|||||||
#include "SimpleTimer.h"
|
#include "SimpleTimer.h"
|
||||||
#include "RobotFunctions.h"
|
#include "RobotFunctions.h"
|
||||||
#include "ShiftReg.h"
|
#include "ShiftReg.h"
|
||||||
|
#include "UART3_Handler.h"
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
@ -59,6 +58,7 @@ TIM_HandleTypeDef htim2;
|
|||||||
TIM_HandleTypeDef htim3;
|
TIM_HandleTypeDef htim3;
|
||||||
|
|
||||||
UART_HandleTypeDef huart3;
|
UART_HandleTypeDef huart3;
|
||||||
|
DMA_HandleTypeDef hdma_usart3_rx;
|
||||||
|
|
||||||
/* USER CODE BEGIN PV */
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
@ -68,8 +68,6 @@ uint8_t velosety[600];
|
|||||||
uint8_t rxcomlite = 0;
|
uint8_t rxcomlite = 0;
|
||||||
uint8_t initcomlete = 0;
|
uint8_t initcomlete = 0;
|
||||||
|
|
||||||
uint8_t uart_rx_buffer[UART_BUFFER_SIZE];
|
|
||||||
|
|
||||||
unsigned char Shiftreg[3];
|
unsigned char Shiftreg[3];
|
||||||
|
|
||||||
uint8_t rejim[60]; // 0 - chislo rejimov, 1-6 - rejim1, 7-12 - rejim2...
|
uint8_t rejim[60]; // 0 - chislo rejimov, 1-6 - rejim1, 7-12 - rejim2...
|
||||||
@ -84,10 +82,6 @@ uint16_t vi = 0;
|
|||||||
uint16_t timing1 = 0;
|
uint16_t timing1 = 0;
|
||||||
uint16_t timing2 = 0;
|
uint16_t timing2 = 0;
|
||||||
|
|
||||||
struct Shot BufShots[MAX_NUMBER_SHOTS];
|
|
||||||
struct Program BufPrograms;
|
|
||||||
struct Macro BufMacro;
|
|
||||||
|
|
||||||
extern PCD_HandleTypeDef hpcd_USB_FS;
|
extern PCD_HandleTypeDef hpcd_USB_FS;
|
||||||
|
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
@ -95,6 +89,7 @@ extern PCD_HandleTypeDef hpcd_USB_FS;
|
|||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
void SystemClock_Config(void);
|
void SystemClock_Config(void);
|
||||||
static void MX_GPIO_Init(void);
|
static void MX_GPIO_Init(void);
|
||||||
|
static void MX_DMA_Init(void);
|
||||||
static void MX_I2C1_Init(void);
|
static void MX_I2C1_Init(void);
|
||||||
static void MX_TIM1_Init(void);
|
static void MX_TIM1_Init(void);
|
||||||
static void MX_TIM2_Init(void);
|
static void MX_TIM2_Init(void);
|
||||||
@ -126,7 +121,7 @@ int main(void)
|
|||||||
HAL_Init();
|
HAL_Init();
|
||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
/* USER CODE BEGIN Init */
|
||||||
|
HAL_Delay(10);
|
||||||
/* USER CODE END Init */
|
/* USER CODE END Init */
|
||||||
|
|
||||||
/* Configure the system clock */
|
/* Configure the system clock */
|
||||||
@ -142,10 +137,12 @@ int main(void)
|
|||||||
__HAL_RCC_USB_FORCE_RESET();
|
__HAL_RCC_USB_FORCE_RESET();
|
||||||
HAL_Delay(10);
|
HAL_Delay(10);
|
||||||
__HAL_RCC_USB_RELEASE_RESET();
|
__HAL_RCC_USB_RELEASE_RESET();
|
||||||
|
HAL_Delay(10);
|
||||||
/* USER CODE END SysInit */
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
/* Initialize all configured peripherals */
|
||||||
MX_GPIO_Init();
|
MX_GPIO_Init();
|
||||||
|
MX_DMA_Init();
|
||||||
MX_I2C1_Init();
|
MX_I2C1_Init();
|
||||||
MX_USB_DEVICE_Init();
|
MX_USB_DEVICE_Init();
|
||||||
MX_TIM1_Init();
|
MX_TIM1_Init();
|
||||||
@ -153,10 +150,14 @@ int main(void)
|
|||||||
MX_TIM3_Init();
|
MX_TIM3_Init();
|
||||||
MX_USART3_UART_Init();
|
MX_USART3_UART_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
HAL_Delay(10);
|
||||||
|
__HAL_RCC_USART3_CLK_ENABLE();
|
||||||
|
HAL_Delay(10);
|
||||||
|
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||||
|
HAL_Delay(10);
|
||||||
|
|
||||||
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); //PA8
|
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); //PA8
|
||||||
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2); //PA9
|
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2); //PA9
|
||||||
|
|
||||||
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); //PA0
|
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); //PA0
|
||||||
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2); //PA1
|
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2); //PA1
|
||||||
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3); //PA2
|
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3); //PA2
|
||||||
@ -164,19 +165,6 @@ int main(void)
|
|||||||
|
|
||||||
initPCA9685();
|
initPCA9685();
|
||||||
|
|
||||||
//BufShots[0].countRepeatShot = 5;
|
|
||||||
//BufShots[0].speedRollerTop = 120;
|
|
||||||
//BufShots[0].speedRollerBottom = 130;
|
|
||||||
//BufShots[0].speedScrew = 50;
|
|
||||||
//BufShots[0].rotationAxial = 90;
|
|
||||||
//BufShots[0].rotationHorizontal = 90;
|
|
||||||
//BufShots[0].rotationVertical = 90;
|
|
||||||
|
|
||||||
// SaveShot(0, &BufShots[0]);
|
|
||||||
|
|
||||||
// BufShots[1] = GetShot(0);
|
|
||||||
|
|
||||||
|
|
||||||
Shiftreg[0] = 0x00; Shiftreg[1] = 0x44; Shiftreg[2] = 0x00; SetShiftReg(Shiftreg); HAL_Delay(10);
|
Shiftreg[0] = 0x00; Shiftreg[1] = 0x44; Shiftreg[2] = 0x00; SetShiftReg(Shiftreg); HAL_Delay(10);
|
||||||
Shiftreg[0] = 0x00; Shiftreg[1] = 0x66; Shiftreg[2] = 0x00; SetShiftReg(Shiftreg); HAL_Delay(10);
|
Shiftreg[0] = 0x00; Shiftreg[1] = 0x66; Shiftreg[2] = 0x00; SetShiftReg(Shiftreg); HAL_Delay(10);
|
||||||
Shiftreg[0] = 0x00; Shiftreg[1] = 0x77; Shiftreg[2] = 0x00; SetShiftReg(Shiftreg); HAL_Delay(10);
|
Shiftreg[0] = 0x00; Shiftreg[1] = 0x77; Shiftreg[2] = 0x00; SetShiftReg(Shiftreg); HAL_Delay(10);
|
||||||
@ -198,6 +186,7 @@ initcomlete = 1;
|
|||||||
|
|
||||||
HAL_TIM_Base_Start_IT(&htim3);
|
HAL_TIM_Base_Start_IT(&htim3);
|
||||||
HAL_NVIC_EnableIRQ(TIM3_IRQn);
|
HAL_NVIC_EnableIRQ(TIM3_IRQn);
|
||||||
|
UART3_START();
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
@ -226,148 +215,7 @@ initcomlete = 1;
|
|||||||
{
|
{
|
||||||
|
|
||||||
IR_CMD_Handler();
|
IR_CMD_Handler();
|
||||||
|
UART3_Handler();
|
||||||
// if (rxcomlite == 1)
|
|
||||||
// {
|
|
||||||
//
|
|
||||||
// txdata[0] = 'O';
|
|
||||||
// txdata[1] = 'K';
|
|
||||||
// txdata[2] = '?';
|
|
||||||
//
|
|
||||||
// switch (rxdata[0])
|
|
||||||
// {
|
|
||||||
//
|
|
||||||
// case 1:
|
|
||||||
// {
|
|
||||||
// SetServo(0, rxdata[1]);
|
|
||||||
// txdata[0] = 'O';
|
|
||||||
// txdata[1] = 'K';
|
|
||||||
// txdata[2] = '1';
|
|
||||||
//// CDC_Transmit_FS(txdata, 3);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// case 2:
|
|
||||||
// {
|
|
||||||
// SetServo(1, rxdata[1]);
|
|
||||||
// txdata[0] = 'O';
|
|
||||||
// txdata[1] = 'K';
|
|
||||||
// txdata[2] = '2';
|
|
||||||
//// CDC_Transmit_FS(txdata, 3);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// case 3:
|
|
||||||
// {
|
|
||||||
// SetServo(2, rxdata[1]);
|
|
||||||
// txdata[0] = 'O';
|
|
||||||
// txdata[1] = 'K';
|
|
||||||
// txdata[2] = '3';
|
|
||||||
//// CDC_Transmit_FS(txdata, 3);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// case 4:
|
|
||||||
// {
|
|
||||||
// SetServo(0, rxdata[1]);
|
|
||||||
// SetServo(1, rxdata[2]);
|
|
||||||
// SetServo(2, rxdata[3]);
|
|
||||||
//
|
|
||||||
// Vz1 = rxdata[4]; // rolic verh 0..200
|
|
||||||
// Vz2 = rxdata[5]; // rolic niz 0..200
|
|
||||||
// vi = 0;
|
|
||||||
//
|
|
||||||
// // shnek 0..100
|
|
||||||
// if (rxdata[6] < 101)
|
|
||||||
// {
|
|
||||||
// TIM1->CCR1 = 0;
|
|
||||||
// TIM1->CCR2 = (uint16_t)(40 * rxdata[6]);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// TIM1->CCR1 = 0;
|
|
||||||
// TIM1->CCR2 = 4000;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// txdata[0] = 'O';
|
|
||||||
// txdata[1] = 'K';
|
|
||||||
// txdata[2] = '4';
|
|
||||||
//// CDC_Transmit_FS(txdata, 3);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// case 5:
|
|
||||||
// {
|
|
||||||
// txdata[0] = LOBYTE(timing1);
|
|
||||||
// txdata[1] = HIBYTE(timing1);
|
|
||||||
//// CDC_Transmit_FS(txdata, 3);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case 6:
|
|
||||||
// {
|
|
||||||
//// CDC_Transmit_FS(velosety, 600);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// case 7:
|
|
||||||
// {
|
|
||||||
// rejim[0] = rxdata[1];
|
|
||||||
// // copy to buffer
|
|
||||||
// for (uint8_t i = 0; i < rejim[0]; i++)
|
|
||||||
// {
|
|
||||||
// rejim[(i * 6) + 1] = rxdata[(i * 6) + 2];
|
|
||||||
// rejim[(i * 6) + 2] = rxdata[(i * 6) + 3];
|
|
||||||
// rejim[(i * 6) + 3] = rxdata[(i * 6) + 4];
|
|
||||||
// rejim[(i * 6) + 4] = rxdata[(i * 6) + 5];
|
|
||||||
// rejim[(i * 6) + 5] = rxdata[(i * 6) + 6];
|
|
||||||
// rejim[(i * 6) + 6] = rxdata[(i * 6) + 7];
|
|
||||||
// }
|
|
||||||
// // set rejim #1
|
|
||||||
// SetServo(0, rejim[1]);
|
|
||||||
// SetServo(1, rejim[2]);
|
|
||||||
// SetServo(2, rejim[3]);
|
|
||||||
// Vz1 = rejim[4];
|
|
||||||
// Vz2 = rejim[5];
|
|
||||||
// TIM1->CCR1 = 0;
|
|
||||||
// TIM1->CCR2 = (uint16_t)(40 * rejim[6]);
|
|
||||||
// // set avto
|
|
||||||
// rejim_number = 1;
|
|
||||||
// avto = 1;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// case 8:
|
|
||||||
// { // stop avto
|
|
||||||
// avto = 0;
|
|
||||||
// rejim_number = 1;
|
|
||||||
// // stop mecanics
|
|
||||||
// SetServo(0, 90);
|
|
||||||
// SetServo(1, 90);
|
|
||||||
// SetServo(2, 90);
|
|
||||||
// Vz1 = 100;
|
|
||||||
// Vz2 = 100;
|
|
||||||
// TIM1->CCR1 = 0;
|
|
||||||
// TIM1->CCR2 = 0;
|
|
||||||
//
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// case 9:
|
|
||||||
// {
|
|
||||||
// txdata[0] = avto;
|
|
||||||
// txdata[1] = rejim_number;
|
|
||||||
//// CDC_Transmit_FS(txdata, 3);
|
|
||||||
//
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// default:
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// rxcomlite = 0;
|
|
||||||
//
|
|
||||||
// // // HAL_Delay(1000);
|
|
||||||
// }
|
|
||||||
|
|
||||||
forTimer(blinkTimer, 500)
|
forTimer(blinkTimer, 500)
|
||||||
{
|
{
|
||||||
@ -693,7 +541,7 @@ static void MX_USART3_UART_Init(void)
|
|||||||
|
|
||||||
/* USER CODE END USART3_Init 1 */
|
/* USER CODE END USART3_Init 1 */
|
||||||
huart3.Instance = USART3;
|
huart3.Instance = USART3;
|
||||||
huart3.Init.BaudRate = 115200;
|
huart3.Init.BaudRate = 9600;
|
||||||
huart3.Init.WordLength = UART_WORDLENGTH_8B;
|
huart3.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
huart3.Init.StopBits = UART_STOPBITS_1;
|
huart3.Init.StopBits = UART_STOPBITS_1;
|
||||||
huart3.Init.Parity = UART_PARITY_NONE;
|
huart3.Init.Parity = UART_PARITY_NONE;
|
||||||
@ -705,14 +553,30 @@ static void MX_USART3_UART_Init(void)
|
|||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
/* USER CODE BEGIN USART3_Init 2 */
|
/* USER CODE BEGIN USART3_Init 2 */
|
||||||
if (HAL_UART_Receive_IT(&huart3, uart_rx_buffer, UART_BUFFER_SIZE) != HAL_OK)
|
// if (HAL_UART_Receive_IT(&huart3, uart_rx_buffer, UART_BUFFER_SIZE) != HAL_OK)
|
||||||
{
|
// {
|
||||||
Error_Handler();
|
// Error_Handler();
|
||||||
}
|
// }
|
||||||
/* USER CODE END USART3_Init 2 */
|
/* USER CODE END USART3_Init 2 */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable DMA controller clock
|
||||||
|
*/
|
||||||
|
static void MX_DMA_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* DMA controller clock enable */
|
||||||
|
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||||
|
|
||||||
|
/* DMA interrupt init */
|
||||||
|
/* DMA1_Channel3_IRQn interrupt configuration */
|
||||||
|
HAL_NVIC_SetPriority(DMA1_Channel3_IRQn, 2, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(DMA1_Channel3_IRQn);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief GPIO Initialization Function
|
* @brief GPIO Initialization Function
|
||||||
* @param None
|
* @param None
|
||||||
@ -763,10 +627,10 @@ static void MX_GPIO_Init(void)
|
|||||||
HAL_GPIO_Init(IR_EXT_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(IR_EXT_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
/* EXTI interrupt init*/
|
/* EXTI interrupt init*/
|
||||||
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
|
HAL_NVIC_SetPriority(EXTI0_IRQn, 7, 0);
|
||||||
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
|
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
|
||||||
|
|
||||||
HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
|
HAL_NVIC_SetPriority(EXTI1_IRQn, 7, 0);
|
||||||
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
|
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
|
||||||
|
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
extern DMA_HandleTypeDef hdma_usart3_rx;
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN TD */
|
/* USER CODE BEGIN TD */
|
||||||
@ -348,8 +349,25 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
|
|||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
HAL_GPIO_Init(RX_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(RX_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* USART3 DMA Init */
|
||||||
|
/* USART3_RX Init */
|
||||||
|
hdma_usart3_rx.Instance = DMA1_Channel3;
|
||||||
|
hdma_usart3_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
||||||
|
hdma_usart3_rx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||||
|
hdma_usart3_rx.Init.MemInc = DMA_MINC_ENABLE;
|
||||||
|
hdma_usart3_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||||
|
hdma_usart3_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||||
|
hdma_usart3_rx.Init.Mode = DMA_CIRCULAR;
|
||||||
|
hdma_usart3_rx.Init.Priority = DMA_PRIORITY_HIGH;
|
||||||
|
if (HAL_DMA_Init(&hdma_usart3_rx) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
__HAL_LINKDMA(huart,hdmarx,hdma_usart3_rx);
|
||||||
|
|
||||||
/* USART3 interrupt Init */
|
/* USART3 interrupt Init */
|
||||||
HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
|
HAL_NVIC_SetPriority(USART3_IRQn, 3, 0);
|
||||||
HAL_NVIC_EnableIRQ(USART3_IRQn);
|
HAL_NVIC_EnableIRQ(USART3_IRQn);
|
||||||
/* USER CODE BEGIN USART3_MspInit 1 */
|
/* USER CODE BEGIN USART3_MspInit 1 */
|
||||||
|
|
||||||
@ -381,6 +399,9 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
|
|||||||
*/
|
*/
|
||||||
HAL_GPIO_DeInit(GPIOB, TX_Pin|RX_Pin);
|
HAL_GPIO_DeInit(GPIOB, TX_Pin|RX_Pin);
|
||||||
|
|
||||||
|
/* USART3 DMA DeInit */
|
||||||
|
HAL_DMA_DeInit(huart->hdmarx);
|
||||||
|
|
||||||
/* USART3 interrupt DeInit */
|
/* USART3 interrupt DeInit */
|
||||||
HAL_NVIC_DisableIRQ(USART3_IRQn);
|
HAL_NVIC_DisableIRQ(USART3_IRQn);
|
||||||
/* USER CODE BEGIN USART3_MspDeInit 1 */
|
/* USER CODE BEGIN USART3_MspDeInit 1 */
|
||||||
|
@ -28,8 +28,10 @@
|
|||||||
#include "usb_device.h"
|
#include "usb_device.h"
|
||||||
#include "usbd_cdc_if.h"
|
#include "usbd_cdc_if.h"
|
||||||
|
|
||||||
#include "GlobalDefines.h"
|
|
||||||
#include "Print.h"
|
#include "Print.h"
|
||||||
|
|
||||||
|
#include "UART3_Handler.h"
|
||||||
|
#include "SimpleTimer.h"
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
@ -50,6 +52,11 @@
|
|||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN PV */
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
|
extern uint8_t uart_rx_buffer[UART_BUFFER_SIZE];
|
||||||
|
extern volatile uint16_t packet_index;
|
||||||
|
extern volatile uint32_t uartTimer;
|
||||||
|
extern volatile uint8_t uart_rx_in_progress;
|
||||||
|
|
||||||
uint8_t myi;
|
uint8_t myi;
|
||||||
extern uint16_t vi; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><> 0..599
|
extern uint16_t vi; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><> 0..599
|
||||||
uint16_t v1[30]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) [0] - <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, [1-29] - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
uint16_t v1[30]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) [0] - <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, [1-29] - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
@ -93,82 +100,68 @@ int32_t computePID2(uint16_t input, uint16_t setpoint);
|
|||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
/* Private user code ---------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN 0 */
|
/* USER CODE BEGIN 0 */
|
||||||
int32_t computePID1(uint16_t input, uint16_t setpoint)
|
int32_t computePID1(uint16_t input, uint16_t setpoint) {
|
||||||
{
|
|
||||||
static int32_t integral = 0, prevErr = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
static int32_t integral = 0, prevErr = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
int32_t err = setpoint - input; // 1.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
int32_t err = setpoint - input; // 1.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
integral = integral + err / 20; // 2.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dt = 0.01, ki = 5;
|
integral = integral + err / 20; // 2.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dt = 0.01, ki = 5;
|
||||||
|
|
||||||
if (integral > 4000)
|
if (integral > 4000) {
|
||||||
{
|
|
||||||
integral = 4000;
|
integral = 4000;
|
||||||
}
|
}
|
||||||
if (integral < 0)
|
if (integral < 0) {
|
||||||
{
|
|
||||||
integral = 0;
|
integral = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t D = (err - prevErr); // 3.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dt = 0.01, kd = 0.01
|
int32_t D = (err - prevErr); // 3.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dt = 0.01, kd = 0.01
|
||||||
if (D > 4000)
|
if (D > 4000) {
|
||||||
{
|
|
||||||
D = 4000;
|
D = 4000;
|
||||||
}
|
}
|
||||||
if (D < 0)
|
if (D < 0) {
|
||||||
{
|
|
||||||
D = 0;
|
D = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
prevErr = err;
|
prevErr = err;
|
||||||
//
|
//
|
||||||
int32_t Rout = ((err * 3) >> 1) + integral + D; // 4. <20>=1,5 + <20>=5 + <20>=0.01
|
int32_t Rout = ((err * 3) >> 1) + integral + D; // 4. <20>=1,5 + <20>=5 + <20>=0.01
|
||||||
if (Rout > 4000)
|
if (Rout > 4000) {
|
||||||
{
|
|
||||||
Rout = 4000;
|
Rout = 4000;
|
||||||
} //
|
} //
|
||||||
if (Rout < 0)
|
if (Rout < 0) {
|
||||||
{
|
|
||||||
Rout = 0;
|
Rout = 0;
|
||||||
} //
|
} //
|
||||||
|
|
||||||
return Rout;
|
return Rout;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t computePID2(uint16_t input, uint16_t setpoint)
|
int32_t computePID2(uint16_t input, uint16_t setpoint) {
|
||||||
{
|
|
||||||
static int32_t integral = 0, prevErr = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
static int32_t integral = 0, prevErr = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
int32_t err = setpoint - input; // 1.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
int32_t err = setpoint - input; // 1.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
integral = integral + err / 20; // 2.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dt = 0.01, ki = 5;
|
integral = integral + err / 20; // 2.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dt = 0.01, ki = 5;
|
||||||
if (integral > 4000)
|
if (integral > 4000) {
|
||||||
{
|
|
||||||
integral = 4000;
|
integral = 4000;
|
||||||
}
|
}
|
||||||
if (integral < 0)
|
if (integral < 0) {
|
||||||
{
|
|
||||||
integral = 0;
|
integral = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t D = (err - prevErr); // 3.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dt = 0.01, kd = 0.01
|
int32_t D = (err - prevErr); // 3.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dt = 0.01, kd = 0.01
|
||||||
if (D > 4000)
|
if (D > 4000) {
|
||||||
{
|
|
||||||
D = 4000;
|
D = 4000;
|
||||||
}
|
}
|
||||||
if (D < 0)
|
if (D < 0) {
|
||||||
{
|
|
||||||
D = 0;
|
D = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
prevErr = err;
|
prevErr = err;
|
||||||
//
|
//
|
||||||
int32_t Rout = ((err * 3) >> 1) + integral + D; // 4. <20>=1,5 + <20>=5 + <20>=0.01
|
int32_t Rout = ((err * 3) >> 1) + integral + D; // 4. <20>=1,5 + <20>=5 + <20>=0.01
|
||||||
if (Rout > 4000)
|
if (Rout > 4000) {
|
||||||
{
|
|
||||||
Rout = 4000;
|
Rout = 4000;
|
||||||
} //
|
} //
|
||||||
if (Rout < 0)
|
if (Rout < 0) {
|
||||||
{
|
|
||||||
Rout = 0;
|
Rout = 0;
|
||||||
} //
|
} //
|
||||||
|
|
||||||
@ -180,6 +173,7 @@ int32_t computePID2(uint16_t input, uint16_t setpoint)
|
|||||||
extern PCD_HandleTypeDef hpcd_USB_FS;
|
extern PCD_HandleTypeDef hpcd_USB_FS;
|
||||||
extern I2C_HandleTypeDef hi2c1;
|
extern I2C_HandleTypeDef hi2c1;
|
||||||
extern TIM_HandleTypeDef htim3;
|
extern TIM_HandleTypeDef htim3;
|
||||||
|
extern DMA_HandleTypeDef hdma_usart3_rx;
|
||||||
extern UART_HandleTypeDef huart3;
|
extern UART_HandleTypeDef huart3;
|
||||||
/* USER CODE BEGIN EV */
|
/* USER CODE BEGIN EV */
|
||||||
extern uint8_t uart_rx_buffer[UART_BUFFER_SIZE];
|
extern uint8_t uart_rx_buffer[UART_BUFFER_SIZE];
|
||||||
@ -197,8 +191,7 @@ void NMI_Handler(void)
|
|||||||
|
|
||||||
/* USER CODE END NonMaskableInt_IRQn 0 */
|
/* USER CODE END NonMaskableInt_IRQn 0 */
|
||||||
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
/* USER CODE END NonMaskableInt_IRQn 1 */
|
/* USER CODE END NonMaskableInt_IRQn 1 */
|
||||||
}
|
}
|
||||||
@ -310,53 +303,42 @@ void SysTick_Handler(void)
|
|||||||
/* USER CODE BEGIN SysTick_IRQn 0 */
|
/* USER CODE BEGIN SysTick_IRQn 0 */
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1
|
||||||
if (v1[0] > 0)
|
if (v1[0] > 0) { // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
{ // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
vt1 = 0;
|
vt1 = 0;
|
||||||
for (uint8_t i = 1; i <= v1[0]; i++)
|
for (uint8_t i = 1; i <= v1[0]; i++) {
|
||||||
{
|
|
||||||
vt1 += v1[i];
|
vt1 += v1[i];
|
||||||
}
|
}
|
||||||
vt1 = vt1 / v1[0];
|
vt1 = vt1 / v1[0];
|
||||||
// <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>, <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>, <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
vt1 = timing1;
|
vt1 = timing1;
|
||||||
}
|
}
|
||||||
v1[0] = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
v1[0] = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2
|
||||||
if (v2[0] > 0)
|
if (v2[0] > 0) { // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
{ // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
vt2 = 0;
|
vt2 = 0;
|
||||||
for (uint8_t i = 1; i <= v2[0]; i++)
|
for (uint8_t i = 1; i <= v2[0]; i++) {
|
||||||
{
|
|
||||||
vt2 += v2[i];
|
vt2 += v2[i];
|
||||||
}
|
}
|
||||||
vt2 = vt2 / v2[0];
|
vt2 = vt2 / v2[0];
|
||||||
// <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>, <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>, <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
vt2 = timing2;
|
vt2 = timing2;
|
||||||
}
|
}
|
||||||
v2[0] = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
v2[0] = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 3
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 3
|
||||||
if (vs1[0] < 3)
|
if (vs1[0] < 3) {
|
||||||
{
|
|
||||||
vs1[vs1[0] + 1] = (uint16_t) vt1;
|
vs1[vs1[0] + 1] = (uint16_t) vt1;
|
||||||
vs1[0]++;
|
vs1[0]++;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
vs1[0] = 0;
|
vs1[0] = 0;
|
||||||
vs1[vs1[0] + 1] = (uint16_t) vt1;
|
vs1[vs1[0] + 1] = (uint16_t) vt1;
|
||||||
vs1[0]++;
|
vs1[0]++;
|
||||||
@ -364,13 +346,10 @@ void SysTick_Handler(void)
|
|||||||
|
|
||||||
vsk1 = (vs1[1] + vs1[2] + vs1[3]) / 3;
|
vsk1 = (vs1[1] + vs1[2] + vs1[3]) / 3;
|
||||||
|
|
||||||
if (vs2[0] < 3)
|
if (vs2[0] < 3) {
|
||||||
{
|
|
||||||
vs2[vs2[0] + 1] = (uint16_t) vt2;
|
vs2[vs2[0] + 1] = (uint16_t) vt2;
|
||||||
vs2[0]++;
|
vs2[0]++;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
vs2[0] = 0;
|
vs2[0] = 0;
|
||||||
vs2[vs2[0] + 1] = (uint16_t) vt2;
|
vs2[vs2[0] + 1] = (uint16_t) vt2;
|
||||||
vs2[0]++;
|
vs2[0]++;
|
||||||
@ -379,23 +358,19 @@ void SysTick_Handler(void)
|
|||||||
vsk2 = (vs2[1] + vs2[2] + vs2[3]) / 3;
|
vsk2 = (vs2[1] + vs2[2] + vs2[3]) / 3;
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 60*1000000/(<28>*10)
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 60*1000000/(<28>*10)
|
||||||
if (vsk1 != 0)
|
if (vsk1 != 0) {
|
||||||
{
|
|
||||||
vsk1 = 6000000 / vsk1;
|
vsk1 = 6000000 / vsk1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
vsk1 = 0;
|
vsk1 = 0;
|
||||||
}
|
}
|
||||||
if (vsk1 > 10000) vsk1 = 10000;
|
if (vsk1 > 10000)
|
||||||
if (vsk1 < 150) vsk1 = 0;
|
vsk1 = 10000;
|
||||||
|
if (vsk1 < 150)
|
||||||
|
vsk1 = 0;
|
||||||
|
|
||||||
if (vsk2 != 0)
|
if (vsk2 != 0) {
|
||||||
{
|
|
||||||
vsk2 = 6000000 / vsk2;
|
vsk2 = 6000000 / vsk2;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
vsk2 = 0;
|
vsk2 = 0;
|
||||||
}
|
}
|
||||||
if (vsk2 > 10000)
|
if (vsk2 > 10000)
|
||||||
@ -404,25 +379,27 @@ void SysTick_Handler(void)
|
|||||||
vsk2 = 0;
|
vsk2 = 0;
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 - 200 <20> -8000 ... 8000 <20><>./<2F><><EFBFBD>.
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 - 200 <20> -8000 ... 8000 <20><>./<2F><><EFBFBD>.
|
||||||
if (Vz1 < 0) {Vz1 = 0;}
|
if (Vz1 < 0) {
|
||||||
if (Vz1 > 200) {Vz1 = 200;}
|
Vz1 = 0;
|
||||||
if (Vz2 < 0) {Vz2 = 0;}
|
|
||||||
if (Vz2 > 200) {Vz2 = 200;}
|
|
||||||
|
|
||||||
if (Vz1 > 100)
|
|
||||||
{
|
|
||||||
Vzad1 = (Vz1 - 100) * 80;
|
|
||||||
}
|
}
|
||||||
else
|
if (Vz1 > 200) {
|
||||||
{
|
Vz1 = 200;
|
||||||
|
}
|
||||||
|
if (Vz2 < 0) {
|
||||||
|
Vz2 = 0;
|
||||||
|
}
|
||||||
|
if (Vz2 > 200) {
|
||||||
|
Vz2 = 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Vz1 > 100) {
|
||||||
|
Vzad1 = (Vz1 - 100) * 80;
|
||||||
|
} else {
|
||||||
Vzad1 = (100 - Vz1) * 80;
|
Vzad1 = (100 - Vz1) * 80;
|
||||||
}
|
}
|
||||||
if (Vz2 > 100)
|
if (Vz2 > 100) {
|
||||||
{
|
|
||||||
Vzad2 = (Vz2 - 100) * 80;
|
Vzad2 = (Vz2 - 100) * 80;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Vzad2 = (100 - Vz2) * 80;
|
Vzad2 = (100 - Vz2) * 80;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,24 +407,18 @@ void SysTick_Handler(void)
|
|||||||
Vupr1 = (uint16_t) computePID1(vsk1, Vzad1);
|
Vupr1 = (uint16_t) computePID1(vsk1, Vzad1);
|
||||||
Vupr2 = (uint16_t) computePID2(vsk2, Vzad2);
|
Vupr2 = (uint16_t) computePID2(vsk2, Vzad2);
|
||||||
|
|
||||||
if (Vz1 > 100)
|
if (Vz1 > 100) {
|
||||||
{
|
|
||||||
TIM2->CCR2 = 0;
|
TIM2->CCR2 = 0;
|
||||||
TIM2->CCR1 = Vupr1;
|
TIM2->CCR1 = Vupr1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
TIM2->CCR1 = 0;
|
TIM2->CCR1 = 0;
|
||||||
TIM2->CCR2 = Vupr1;
|
TIM2->CCR2 = Vupr1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Vz2 > 100)
|
if (Vz2 > 100) {
|
||||||
{
|
|
||||||
TIM2->CCR3 = 0;
|
TIM2->CCR3 = 0;
|
||||||
TIM2->CCR4 = Vupr2;
|
TIM2->CCR4 = Vupr2;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
TIM2->CCR4 = 0;
|
TIM2->CCR4 = 0;
|
||||||
TIM2->CCR3 = Vupr2;
|
TIM2->CCR3 = Vupr2;
|
||||||
}
|
}
|
||||||
@ -458,8 +429,7 @@ void SysTick_Handler(void)
|
|||||||
// TIM2->CCR2 = 0xffff;
|
// TIM2->CCR2 = 0xffff;
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><>
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><>
|
||||||
if (vi < 600)
|
if (vi < 600) {
|
||||||
{
|
|
||||||
velosety[vi] = LOBYTE(timing1);
|
velosety[vi] = LOBYTE(timing1);
|
||||||
velosety[vi + 1] = HIBYTE(timing1);
|
velosety[vi + 1] = HIBYTE(timing1);
|
||||||
velosety[vi + 2] = LOBYTE(vsk1);
|
velosety[vi + 2] = LOBYTE(vsk1);
|
||||||
@ -536,6 +506,20 @@ void EXTI1_IRQHandler(void)
|
|||||||
/* USER CODE END EXTI1_IRQn 1 */
|
/* USER CODE END EXTI1_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles DMA1 channel3 global interrupt.
|
||||||
|
*/
|
||||||
|
void DMA1_Channel3_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN DMA1_Channel3_IRQn 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA1_Channel3_IRQn 0 */
|
||||||
|
HAL_DMA_IRQHandler(&hdma_usart3_rx);
|
||||||
|
/* USER CODE BEGIN DMA1_Channel3_IRQn 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA1_Channel3_IRQn 1 */
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function handles USB low priority or CAN RX0 interrupts.
|
* @brief This function handles USB low priority or CAN RX0 interrupts.
|
||||||
*/
|
*/
|
||||||
@ -568,8 +552,7 @@ void TIM3_IRQHandler(void)
|
|||||||
/* USER CODE BEGIN TIM3_IRQn 0 */
|
/* USER CODE BEGIN TIM3_IRQn 0 */
|
||||||
|
|
||||||
// Обработка переполнения таймера
|
// Обработка переполнения таймера
|
||||||
if (TIM3->SR & TIM_SR_UIF)
|
if (TIM3->SR & TIM_SR_UIF) {
|
||||||
{
|
|
||||||
current_capture1 = 0xFFFFFFFF;
|
current_capture1 = 0xFFFFFFFF;
|
||||||
current_capture2 = 0xFFFFFFFF;
|
current_capture2 = 0xFFFFFFFF;
|
||||||
// Сброс флага переполнения
|
// Сброс флага переполнения
|
||||||
@ -577,27 +560,20 @@ void TIM3_IRQHandler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Обработка захвата сигнала для канала 1
|
// Обработка захвата сигнала для канала 1
|
||||||
if (TIM3->SR & TIM_SR_CC1IF)
|
if (TIM3->SR & TIM_SR_CC1IF) {
|
||||||
{
|
|
||||||
current_capture1 = TIM3->CCR1;
|
current_capture1 = TIM3->CCR1;
|
||||||
|
|
||||||
if (current_capture1 >= prev_capture1)
|
if (current_capture1 >= prev_capture1) {
|
||||||
{
|
|
||||||
elapsed_time1 = current_capture1 - prev_capture1;
|
elapsed_time1 = current_capture1 - prev_capture1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// Учёт переполнения таймера
|
// Учёт переполнения таймера
|
||||||
elapsed_time1 = (65000 - prev_capture1) + current_capture1 + 1;
|
elapsed_time1 = (65000 - prev_capture1) + current_capture1 + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ограничение значения для сохранения в 16-битную переменную
|
// Ограничение значения для сохранения в 16-битную переменную
|
||||||
if (elapsed_time1 > 65535)
|
if (elapsed_time1 > 65535) {
|
||||||
{
|
|
||||||
timing1 = 65535; // Максимальное значение
|
timing1 = 65535; // Максимальное значение
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
timing1 = (uint16_t) elapsed_time1;
|
timing1 = (uint16_t) elapsed_time1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -606,27 +582,20 @@ void TIM3_IRQHandler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Обработка захвата сигнала для канала 2
|
// Обработка захвата сигнала для канала 2
|
||||||
if (TIM3->SR & TIM_SR_CC2IF)
|
if (TIM3->SR & TIM_SR_CC2IF) {
|
||||||
{
|
|
||||||
current_capture2 = TIM3->CCR2;
|
current_capture2 = TIM3->CCR2;
|
||||||
|
|
||||||
if (current_capture2 >= prev_capture2)
|
if (current_capture2 >= prev_capture2) {
|
||||||
{
|
|
||||||
elapsed_time2 = current_capture2 - prev_capture2;
|
elapsed_time2 = current_capture2 - prev_capture2;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// Учёт переполнения таймера
|
// Учёт переполнения таймера
|
||||||
elapsed_time2 = (65000 - prev_capture2) + current_capture2 + 1;
|
elapsed_time2 = (65000 - prev_capture2) + current_capture2 + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ограничение значения для сохранения в 16-битную переменную
|
// Ограничение значения для сохранения в 16-битную переменную
|
||||||
if (elapsed_time2 > 65535)
|
if (elapsed_time2 > 65535) {
|
||||||
{
|
|
||||||
timing2 = 65535; // Максимальное значение
|
timing2 = 65535; // Максимальное значение
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
timing2 = (uint16_t) elapsed_time2;
|
timing2 = (uint16_t) elapsed_time2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -675,15 +644,19 @@ void I2C1_ER_IRQHandler(void)
|
|||||||
void USART3_IRQHandler(void)
|
void USART3_IRQHandler(void)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN USART3_IRQn 0 */
|
/* USER CODE BEGIN USART3_IRQn 0 */
|
||||||
HAL_UART_Receive_IT(&huart3, uart_rx_buffer, UART_BUFFER_SIZE);
|
// if (USART3->SR & USART_SR_RXNE) {
|
||||||
// CDC_Transmit_FS(uart_rx_buffer, UART_BUFFER_SIZE);
|
// uartTimer = millis();
|
||||||
|
// uart_rx_in_progress = 1;
|
||||||
|
// uint8_t received_byte = (uint8_t) (USART3->DR & 0xFF);
|
||||||
|
// uart_rx_buffer[uart_rx_index++] = received_byte;
|
||||||
|
// if (uart_rx_index >= UART_BUFFER_SIZE) {
|
||||||
|
// uart_rx_index = 0;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
/* USER CODE END USART3_IRQn 0 */
|
/* USER CODE END USART3_IRQn 0 */
|
||||||
HAL_UART_IRQHandler(&huart3);
|
HAL_UART_IRQHandler(&huart3);
|
||||||
/* USER CODE BEGIN USART3_IRQn 1 */
|
/* USER CODE BEGIN USART3_IRQn 1 */
|
||||||
|
|
||||||
/* USER CODE END USART3_IRQn 1 */
|
/* USER CODE END USART3_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,22 +2,34 @@
|
|||||||
CAD.formats=
|
CAD.formats=
|
||||||
CAD.pinconfig=
|
CAD.pinconfig=
|
||||||
CAD.provider=
|
CAD.provider=
|
||||||
|
Dma.Request0=USART3_RX
|
||||||
|
Dma.RequestsNb=1
|
||||||
|
Dma.USART3_RX.0.Direction=DMA_PERIPH_TO_MEMORY
|
||||||
|
Dma.USART3_RX.0.Instance=DMA1_Channel3
|
||||||
|
Dma.USART3_RX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE
|
||||||
|
Dma.USART3_RX.0.MemInc=DMA_MINC_ENABLE
|
||||||
|
Dma.USART3_RX.0.Mode=DMA_CIRCULAR
|
||||||
|
Dma.USART3_RX.0.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
|
||||||
|
Dma.USART3_RX.0.PeriphInc=DMA_PINC_DISABLE
|
||||||
|
Dma.USART3_RX.0.Priority=DMA_PRIORITY_HIGH
|
||||||
|
Dma.USART3_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
|
||||||
File.Version=6
|
File.Version=6
|
||||||
GPIO.groupedBy=Group By Peripherals
|
GPIO.groupedBy=Group By Peripherals
|
||||||
KeepUserPlacement=false
|
KeepUserPlacement=false
|
||||||
Mcu.CPN=STM32F103C8T6
|
Mcu.CPN=STM32F103C8T6
|
||||||
Mcu.Family=STM32F1
|
Mcu.Family=STM32F1
|
||||||
Mcu.IP0=I2C1
|
Mcu.IP0=DMA
|
||||||
Mcu.IP1=NVIC
|
Mcu.IP1=I2C1
|
||||||
Mcu.IP2=RCC
|
Mcu.IP10=USB_DEVICE
|
||||||
Mcu.IP3=SYS
|
Mcu.IP2=NVIC
|
||||||
Mcu.IP4=TIM1
|
Mcu.IP3=RCC
|
||||||
Mcu.IP5=TIM2
|
Mcu.IP4=SYS
|
||||||
Mcu.IP6=TIM3
|
Mcu.IP5=TIM1
|
||||||
Mcu.IP7=USART3
|
Mcu.IP6=TIM2
|
||||||
Mcu.IP8=USB
|
Mcu.IP7=TIM3
|
||||||
Mcu.IP9=USB_DEVICE
|
Mcu.IP8=USART3
|
||||||
Mcu.IPNb=10
|
Mcu.IP9=USB
|
||||||
|
Mcu.IPNb=11
|
||||||
Mcu.Name=STM32F103C(8-B)Tx
|
Mcu.Name=STM32F103C(8-B)Tx
|
||||||
Mcu.Package=LQFP48
|
Mcu.Package=LQFP48
|
||||||
Mcu.Pin0=PC13-TAMPER-RTC
|
Mcu.Pin0=PC13-TAMPER-RTC
|
||||||
@ -55,22 +67,23 @@ Mcu.UserName=STM32F103C8Tx
|
|||||||
MxCube.Version=6.12.0
|
MxCube.Version=6.12.0
|
||||||
MxDb.Version=DB.6.0.120
|
MxDb.Version=DB.6.0.120
|
||||||
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
|
NVIC.DMA1_Channel3_IRQn=true\:2\:0\:true\:false\:true\:false\:true\:true
|
||||||
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.EXTI0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
NVIC.EXTI0_IRQn=true\:7\:0\:true\:false\:true\:true\:true\:true
|
||||||
NVIC.EXTI1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
NVIC.EXTI1_IRQn=true\:7\:0\:true\:false\:true\:true\:true\:true
|
||||||
NVIC.ForceEnableDMAVector=true
|
NVIC.ForceEnableDMAVector=true
|
||||||
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.I2C1_ER_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
NVIC.I2C1_ER_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||||
NVIC.I2C1_EV_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
NVIC.I2C1_EV_IRQn=true\:0\:0\:true\:false\:true\:true\:true\:true
|
||||||
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
|
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
|
||||||
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
|
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
|
||||||
NVIC.TIM3_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
NVIC.TIM3_IRQn=true\:0\:0\:true\:false\:true\:true\:true\:true
|
||||||
NVIC.USART3_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
NVIC.USART3_IRQn=true\:3\:0\:true\:false\:true\:true\:true\:true
|
||||||
NVIC.USB_LP_CAN1_RX0_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
|
NVIC.USB_LP_CAN1_RX0_IRQn=true\:1\:0\:true\:false\:true\:false\:true\:true
|
||||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
PA0-WKUP.GPIOParameters=GPIO_Speed,GPIO_Label
|
PA0-WKUP.GPIOParameters=GPIO_Speed,GPIO_Label
|
||||||
PA0-WKUP.GPIO_Label=RPWM_UP
|
PA0-WKUP.GPIO_Label=RPWM_UP
|
||||||
@ -187,7 +200,7 @@ ProjectManager.ToolChainLocation=
|
|||||||
ProjectManager.UAScriptAfterPath=
|
ProjectManager.UAScriptAfterPath=
|
||||||
ProjectManager.UAScriptBeforePath=
|
ProjectManager.UAScriptBeforePath=
|
||||||
ProjectManager.UnderRoot=true
|
ProjectManager.UnderRoot=true
|
||||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_I2C1_Init-I2C1-false-HAL-true,4-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,5-MX_TIM1_Init-TIM1-false-HAL-true,6-MX_TIM2_Init-TIM2-false-HAL-true,7-MX_TIM3_Init-TIM3-false-HAL-true,8-MX_USART3_UART_Init-USART3-false-HAL-true
|
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_I2C1_Init-I2C1-false-HAL-true,5-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,6-MX_TIM1_Init-TIM1-false-HAL-true,7-MX_TIM2_Init-TIM2-false-HAL-true,8-MX_TIM3_Init-TIM3-false-HAL-true,9-MX_USART3_UART_Init-USART3-false-HAL-true
|
||||||
RCC.ADCFreqValue=24000000
|
RCC.ADCFreqValue=24000000
|
||||||
RCC.AHBFreq_Value=48000000
|
RCC.AHBFreq_Value=48000000
|
||||||
RCC.APB1CLKDivider=RCC_HCLK_DIV2
|
RCC.APB1CLKDivider=RCC_HCLK_DIV2
|
||||||
@ -243,7 +256,8 @@ TIM3.Channel-Input_Capture2_from_TI2=TIM_CHANNEL_2
|
|||||||
TIM3.IPParameters=Channel-Input_Capture1_from_TI1,Channel-Input_Capture2_from_TI2,Prescaler,Period
|
TIM3.IPParameters=Channel-Input_Capture1_from_TI1,Channel-Input_Capture2_from_TI2,Prescaler,Period
|
||||||
TIM3.Period=65000
|
TIM3.Period=65000
|
||||||
TIM3.Prescaler=47
|
TIM3.Prescaler=47
|
||||||
USART3.IPParameters=VirtualMode
|
USART3.BaudRate=9600
|
||||||
|
USART3.IPParameters=VirtualMode,BaudRate
|
||||||
USART3.VirtualMode=VM_ASYNC
|
USART3.VirtualMode=VM_ASYNC
|
||||||
USB_DEVICE.APP_RX_DATA_SIZE=64
|
USB_DEVICE.APP_RX_DATA_SIZE=64
|
||||||
USB_DEVICE.APP_TX_DATA_SIZE=64
|
USB_DEVICE.APP_TX_DATA_SIZE=64
|
||||||
|
@ -178,8 +178,7 @@ static int8_t CDC_DeInit_FS(void)
|
|||||||
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN 5 */
|
/* USER CODE BEGIN 5 */
|
||||||
switch(cmd)
|
switch (cmd) {
|
||||||
{
|
|
||||||
case CDC_SEND_ENCAPSULATED_COMMAND:
|
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -280,13 +279,20 @@ uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
|
|||||||
{
|
{
|
||||||
uint8_t result = USBD_OK;
|
uint8_t result = USBD_OK;
|
||||||
/* USER CODE BEGIN 7 */
|
/* USER CODE BEGIN 7 */
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
|
USBD_CDC_HandleTypeDef *hcdc =
|
||||||
|
(USBD_CDC_HandleTypeDef*) hUsbDeviceFS.pClassData;
|
||||||
if (hcdc->TxState != 0) {
|
if (hcdc->TxState != 0) {
|
||||||
return USBD_BUSY;
|
return USBD_BUSY;
|
||||||
}
|
}
|
||||||
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);
|
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);
|
||||||
result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);
|
result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);
|
||||||
while(hcdc->TxState != 0);
|
volatile uint32_t timeout = 5000;
|
||||||
|
while (hcdc->TxState != 0) {
|
||||||
|
if (!timeout) {
|
||||||
|
return USBD_FAIL;
|
||||||
|
}
|
||||||
|
timeout--;
|
||||||
|
}
|
||||||
/* USER CODE END 7 */
|
/* USER CODE END 7 */
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
|
|||||||
__HAL_RCC_USB_CLK_ENABLE();
|
__HAL_RCC_USB_CLK_ENABLE();
|
||||||
|
|
||||||
/* Peripheral interrupt init */
|
/* Peripheral interrupt init */
|
||||||
HAL_NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 0, 0);
|
HAL_NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 1, 0);
|
||||||
HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn);
|
HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn);
|
||||||
/* USER CODE BEGIN USB_MspInit 1 */
|
/* USER CODE BEGIN USB_MspInit 1 */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user