mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-05-04 15:20:16 +00:00
EEPROM and USB CDC
This commit is contained in:
parent
beb5ed6be3
commit
419c55d807
@ -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"/>
|
<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 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"/>
|
||||||
|
@ -109,13 +109,18 @@ typedef struct Statistics{
|
|||||||
}Statistics;
|
}Statistics;
|
||||||
|
|
||||||
typedef struct InfoBlock{
|
typedef struct InfoBlock{
|
||||||
|
char init_uid[11];
|
||||||
HardwareInit_t hwInfo;
|
HardwareInit_t hwInfo;
|
||||||
Statistics statInfo;
|
Statistics statInfo;
|
||||||
}InfoBlock;
|
}InfoBlock;
|
||||||
|
|
||||||
|
extern InfoBlock infoBlock;
|
||||||
|
|
||||||
MemoryStatus FLASH_WriteBlock(uint16_t startAddr, uint8_t number, uint8_t *writeData, uint8_t dataSize);
|
MemoryStatus EEPROM_INIT();
|
||||||
MemoryStatus FLASH_ReadBlock(uint16_t startAddr, uint8_t number, uint8_t *readData, uint8_t dataSize);
|
MemoryStatus EEPROM_EARSE();
|
||||||
|
|
||||||
|
MemoryStatus FLASH_WriteBlock(uint16_t startAddr, uint8_t number, uint8_t *writeData, uint16_t dataSize);
|
||||||
|
MemoryStatus FLASH_ReadBlock(uint16_t startAddr, uint8_t number, uint8_t *readData, uint16_t dataSize);
|
||||||
|
|
||||||
|
|
||||||
MemoryStatus saveShot(unsigned char number, Shot *shot);
|
MemoryStatus saveShot(unsigned char number, Shot *shot);
|
||||||
|
@ -2,14 +2,18 @@
|
|||||||
#include "pca9685.h"
|
#include "pca9685.h"
|
||||||
#include "usbd_cdc_if.h"
|
#include "usbd_cdc_if.h"
|
||||||
#include "Print.h"
|
#include "Print.h"
|
||||||
|
#include "RobotFunctions.h"
|
||||||
|
|
||||||
|
InfoBlock infoBlock;
|
||||||
|
|
||||||
MemoryStatus saveInfoBlock(InfoBlock *infoBlock) {
|
MemoryStatus saveInfoBlock(InfoBlock *infoBlock) {
|
||||||
return FLASH_WriteBlock(START_ADR_STAT, 0, (uint8_t *)infoBlock, sizeof(InfoBlock));
|
return FLASH_WriteBlock(START_ADR_STAT, 0, (uint8_t*) infoBlock,
|
||||||
|
sizeof(InfoBlock));
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryStatus getInfoBlock(InfoBlock *infoBlock) {
|
MemoryStatus getInfoBlock(InfoBlock *infoBlock) {
|
||||||
MemoryStatus status = FLASH_ReadBlock(START_ADR_STAT, 0, (uint8_t *)infoBlock, sizeof(InfoBlock));
|
MemoryStatus status = FLASH_ReadBlock(START_ADR_STAT, 0,
|
||||||
|
(uint8_t*) infoBlock, sizeof(InfoBlock));
|
||||||
|
|
||||||
if (status != EEPROM_OK) {
|
if (status != EEPROM_OK) {
|
||||||
return EEPROM_FAIL;
|
return EEPROM_FAIL;
|
||||||
@ -18,18 +22,17 @@ MemoryStatus getInfoBlock(InfoBlock *infoBlock) {
|
|||||||
return EEPROM_OK;
|
return EEPROM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MemoryStatus saveShot(unsigned char number, Shot *shot) {
|
||||||
MemoryStatus saveShot(unsigned char number, Shot* shot)
|
if (FLASH_WriteBlock(START_ADR_SHOT, number, (uint8_t*) shot,
|
||||||
{
|
SHOT_BLOCKSIZE) == EEPROM_OK) {
|
||||||
if (FLASH_WriteBlock(START_ADR_SHOT, number, (uint8_t*)shot, SHOT_BLOCKSIZE) == EEPROM_OK) {
|
|
||||||
return EEPROM_OK;
|
return EEPROM_OK;
|
||||||
}
|
}
|
||||||
return EEPROM_FAIL;
|
return EEPROM_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryStatus getShot(unsigned char number, Shot* shot)
|
MemoryStatus getShot(unsigned char number, Shot *shot) {
|
||||||
{
|
if (FLASH_ReadBlock(START_ADR_SHOT, number, (uint8_t*) shot, SHOT_BLOCKSIZE)
|
||||||
if (FLASH_ReadBlock(START_ADR_SHOT, number, (uint8_t*)shot, SHOT_BLOCKSIZE) != EEPROM_OK) {
|
!= EEPROM_OK) {
|
||||||
return EEPROM_FAIL;
|
return EEPROM_FAIL;
|
||||||
}
|
}
|
||||||
if (!shot->isExist) {
|
if (!shot->isExist) {
|
||||||
@ -38,8 +41,7 @@ MemoryStatus getShot(unsigned char number, Shot* shot)
|
|||||||
return EEPROM_OK;
|
return EEPROM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
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_NUMBER_SHOTS_IN_PROGRAMS; ++i) {
|
||||||
Shot shot;
|
Shot shot;
|
||||||
@ -53,15 +55,16 @@ MemoryStatus saveProg(unsigned char number, Program* prog)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FLASH_WriteBlock(START_ADR_PROGRAM, number, (uint8_t*)prog, PROGRAM_BLOCKSIZE) != EEPROM_OK) {
|
if (FLASH_WriteBlock(START_ADR_PROGRAM, number, (uint8_t*) prog,
|
||||||
|
PROGRAM_BLOCKSIZE) != EEPROM_OK) {
|
||||||
return EEPROM_FAIL;
|
return EEPROM_FAIL;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryStatus getProg(unsigned char number, Program* prog)
|
MemoryStatus getProg(unsigned char number, Program *prog) {
|
||||||
{
|
if (FLASH_ReadBlock(START_ADR_PROGRAM, number, (uint8_t*) prog,
|
||||||
if (FLASH_ReadBlock(START_ADR_PROGRAM, number, (uint8_t*)prog, PROGRAM_BLOCKSIZE) != EEPROM_OK) {
|
PROGRAM_BLOCKSIZE) != EEPROM_OK) {
|
||||||
return EEPROM_FAIL;
|
return EEPROM_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,8 +75,7 @@ MemoryStatus getProg(unsigned char number, Program* prog)
|
|||||||
return EEPROM_OK;
|
return EEPROM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
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_NUMBER_PROGRAMS_IN_MACRO; ++i) {
|
||||||
Program prog;
|
Program prog;
|
||||||
@ -87,17 +89,17 @@ MemoryStatus saveMacro(unsigned char number, Macro* macro)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FLASH_WriteBlock(START_ADR_MACRO, number, (uint8_t*)macro, MACRO_BLOCKSIZE) != EEPROM_OK) {
|
if (FLASH_WriteBlock(START_ADR_MACRO, number, (uint8_t*) macro,
|
||||||
|
MACRO_BLOCKSIZE) != EEPROM_OK) {
|
||||||
return EEPROM_FAIL;
|
return EEPROM_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MemoryStatus getMacro(unsigned char number, Macro *macro) {
|
||||||
MemoryStatus getMacro(unsigned char number, Macro* macro)
|
if (FLASH_ReadBlock(START_ADR_MACRO, number, (uint8_t*) macro,
|
||||||
{
|
MACRO_BLOCKSIZE) != EEPROM_OK) {
|
||||||
if (FLASH_ReadBlock(START_ADR_MACRO, number, (uint8_t*)macro, MACRO_BLOCKSIZE) != EEPROM_OK) {
|
|
||||||
return EEPROM_FAIL;
|
return EEPROM_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,57 +109,194 @@ MemoryStatus getMacro(unsigned char number, Macro* macro)
|
|||||||
return EEPROM_OK;
|
return EEPROM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MemoryStatus EEPROM_EARSE() {
|
||||||
|
uint16_t addr = 0;
|
||||||
|
uint16_t old_addr = 0;
|
||||||
|
do {
|
||||||
|
uint8_t Buf[255];
|
||||||
|
memset(Buf, 0xFF, sizeof(Buf));
|
||||||
|
FLASH_WriteBlock(addr, 0, Buf, (uint8_t) sizeof(Buf));
|
||||||
|
old_addr = addr;
|
||||||
|
addr += sizeof(Buf);
|
||||||
|
} while (old_addr <= addr);
|
||||||
|
|
||||||
MemoryStatus FLASH_WriteBlock(uint16_t startAddr, uint8_t number, uint8_t *writeData, uint8_t dataSize)
|
return EEPROM_OK;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
MemoryStatus EEPROM_INIT() {
|
||||||
|
MemoryStatus status = getInfoBlock(&infoBlock);
|
||||||
|
if (status != EEPROM_OK) {
|
||||||
|
char errorMsg[] = "Error reading InfoBlock from EEPROM\n";
|
||||||
|
CDC_Transmit_FS((uint8_t*) errorMsg, strlen(errorMsg));
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
char uid_ref[11] = "Stack_Sport";
|
||||||
|
if (memcmp(&(infoBlock.init_uid), &uid_ref, 11) != 0) {
|
||||||
|
char errorMsg[] = "uid non equal\n\n";
|
||||||
|
CDC_Transmit_FS((uint8_t*) errorMsg, strlen(errorMsg));
|
||||||
|
|
||||||
|
EEPROM_EARSE();
|
||||||
|
|
||||||
|
memset(&infoBlock, 0x00, sizeof(InfoBlock));
|
||||||
|
char uid[] = "Stack_Sport";
|
||||||
|
memcpy(infoBlock.init_uid, uid, 11);
|
||||||
|
|
||||||
|
infoBlock.hwInfo.timings.preRun = 3500;
|
||||||
|
|
||||||
|
infoBlock.hwInfo.motors.speed_Rollers_min = 0;
|
||||||
|
infoBlock.hwInfo.motors.speed_Screw_min = 0;
|
||||||
|
|
||||||
|
infoBlock.hwInfo.servos[SERVO_AXIAL].invert = 0;
|
||||||
|
infoBlock.hwInfo.servos[SERVO_AXIAL].min = 0;
|
||||||
|
infoBlock.hwInfo.servos[SERVO_AXIAL].def = 90;
|
||||||
|
infoBlock.hwInfo.servos[SERVO_AXIAL].max = 180;
|
||||||
|
|
||||||
|
infoBlock.hwInfo.servos[SERVO_HORIZONTAL].invert = 0;
|
||||||
|
infoBlock.hwInfo.servos[SERVO_HORIZONTAL].min = 0;
|
||||||
|
infoBlock.hwInfo.servos[SERVO_HORIZONTAL].def = 90;
|
||||||
|
infoBlock.hwInfo.servos[SERVO_HORIZONTAL].max = 180;
|
||||||
|
|
||||||
|
infoBlock.hwInfo.servos[SERVO_VERTICAL].invert = 0;
|
||||||
|
infoBlock.hwInfo.servos[SERVO_VERTICAL].min = 0;
|
||||||
|
infoBlock.hwInfo.servos[SERVO_VERTICAL].def = 90;
|
||||||
|
infoBlock.hwInfo.servos[SERVO_VERTICAL].max = 180;
|
||||||
|
|
||||||
|
infoBlock.statInfo.totalShots = 0;
|
||||||
|
infoBlock.statInfo.totalPrograms = 0;
|
||||||
|
infoBlock.statInfo.totalMacros = 0;
|
||||||
|
|
||||||
|
status = saveInfoBlock(&infoBlock);
|
||||||
|
if (status != EEPROM_OK) {
|
||||||
|
char errorMsg[] = "EEPROM FAIL\n";
|
||||||
|
CDC_Transmit_FS((uint8_t*) errorMsg, strlen(errorMsg));
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
status = getInfoBlock(&infoBlock);
|
||||||
|
|
||||||
|
if (status != EEPROM_OK) {
|
||||||
|
char errorMsg[] = "Error reading InfoBlock from EEPROM\n";
|
||||||
|
CDC_Transmit_FS((uint8_t*) errorMsg, strlen(errorMsg));
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Буфер для строки вывода
|
||||||
|
char buffer[128];
|
||||||
|
|
||||||
|
// Вывод информации о HardwareInit_t
|
||||||
|
snprintf(buffer, sizeof(buffer), "Hardware Initialization:\n");
|
||||||
|
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||||
|
|
||||||
|
char char_tmp[12];
|
||||||
|
memcpy(char_tmp, infoBlock.init_uid, 11);
|
||||||
|
char_tmp[11] = '\0';
|
||||||
|
snprintf(buffer, sizeof(buffer), "init_uid: %s\n", char_tmp);
|
||||||
|
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||||
|
|
||||||
|
snprintf(buffer, sizeof(buffer),
|
||||||
|
"Servo 1: Invert=%u, Min=%u, Default=%u, Max=%u\n",
|
||||||
|
infoBlock.hwInfo.servos[0].invert, infoBlock.hwInfo.servos[0].min,
|
||||||
|
infoBlock.hwInfo.servos[0].def, infoBlock.hwInfo.servos[0].max);
|
||||||
|
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||||
|
|
||||||
|
snprintf(buffer, sizeof(buffer),
|
||||||
|
"Servo 2: Invert=%u, Min=%u, Default=%u, Max=%u\n",
|
||||||
|
infoBlock.hwInfo.servos[1].invert, infoBlock.hwInfo.servos[1].min,
|
||||||
|
infoBlock.hwInfo.servos[1].def, infoBlock.hwInfo.servos[1].max);
|
||||||
|
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||||
|
|
||||||
|
snprintf(buffer, sizeof(buffer),
|
||||||
|
"Servo 3: Invert=%u, Min=%u, Default=%u, Max=%u\n",
|
||||||
|
infoBlock.hwInfo.servos[2].invert, infoBlock.hwInfo.servos[2].min,
|
||||||
|
infoBlock.hwInfo.servos[2].def, infoBlock.hwInfo.servos[2].max);
|
||||||
|
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||||
|
|
||||||
|
snprintf(buffer, sizeof(buffer),
|
||||||
|
"Motors: Speed_Rollers_Min=%u, Speed_Screw_Min=%u\n",
|
||||||
|
infoBlock.hwInfo.motors.speed_Rollers_min,
|
||||||
|
infoBlock.hwInfo.motors.speed_Screw_min);
|
||||||
|
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||||
|
|
||||||
|
// Вывод информации о DelayTimes
|
||||||
|
snprintf(buffer, sizeof(buffer), "Timings: PreRun=%u\n",
|
||||||
|
infoBlock.hwInfo.timings.preRun);
|
||||||
|
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||||
|
|
||||||
|
// Вывод информации о Statistics
|
||||||
|
snprintf(buffer, sizeof(buffer), "Statistics:\n");
|
||||||
|
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||||
|
|
||||||
|
snprintf(buffer, sizeof(buffer), "Total Shots: %lu\n",
|
||||||
|
infoBlock.statInfo.totalShots);
|
||||||
|
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||||
|
|
||||||
|
snprintf(buffer, sizeof(buffer), "Total Programs: %lu\n",
|
||||||
|
infoBlock.statInfo.totalPrograms);
|
||||||
|
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||||
|
|
||||||
|
snprintf(buffer, sizeof(buffer), "Total Macros: %lu\n\n",
|
||||||
|
infoBlock.statInfo.totalMacros);
|
||||||
|
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
MemoryStatus FLASH_WriteBlock(uint16_t startAddr, uint8_t number,
|
||||||
|
uint8_t *writeData, uint16_t dataSize) {
|
||||||
HAL_StatusTypeDef result;
|
HAL_StatusTypeDef result;
|
||||||
|
|
||||||
// Проверка на корректность входных данных
|
// Проверка на корректность входных данных
|
||||||
if ((startAddr == START_ADR_SHOT && number > MAX_NUMBER_SHOTS) ||
|
if ((startAddr == START_ADR_SHOT && number > MAX_NUMBER_SHOTS)
|
||||||
(startAddr == START_ADR_PROGRAM && number > MAX_NUMBER_PROGRAMS) ||
|
|| (startAddr == START_ADR_PROGRAM && number > MAX_NUMBER_PROGRAMS)
|
||||||
(startAddr == START_ADR_MACRO && number > MAX_NUMBER_MACRO)) {
|
|| (startAddr == START_ADR_MACRO && number > MAX_NUMBER_MACRO)) {
|
||||||
return EEPROM_OUT_OF_RANGE;
|
return EEPROM_OUT_OF_RANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t blockAddr16 = (uint16_t)(startAddr + (uint16_t)(number * dataSize));
|
uint16_t blockAddr16 = (uint16_t) (startAddr
|
||||||
uint8_t blockAddr[2] = {HIBYTE(blockAddr16), LOBYTE(blockAddr16)};
|
+ (uint16_t) (number * dataSize));
|
||||||
|
uint8_t blockAddr[2] = { HIBYTE(blockAddr16), LOBYTE(blockAddr16) };
|
||||||
|
|
||||||
unsigned char Buf[dataSize + 2];
|
unsigned char Buf[dataSize + 2];
|
||||||
memset(Buf, 0x00, sizeof(Buf));
|
memset(Buf, 0x00, sizeof(Buf));
|
||||||
Buf[0] = blockAddr[0];
|
Buf[0] = blockAddr[0];
|
||||||
Buf[1] = blockAddr[1];
|
Buf[1] = blockAddr[1];
|
||||||
|
|
||||||
for (unsigned char i = 0; i < dataSize; i++) Buf[i + 2] = writeData[i];
|
for (unsigned char i = 0; i < dataSize; i++)
|
||||||
|
Buf[i + 2] = writeData[i];
|
||||||
|
|
||||||
result = HAL_I2C_Master_Transmit(&hi2c1, (AT24C_ADRESS << 1), Buf, (dataSize + 2), 10);
|
result = HAL_I2C_Master_Transmit(&hi2c1, (AT24C_ADRESS << 1), Buf,
|
||||||
|
(dataSize + 2), 10);
|
||||||
HAL_Delay(1);
|
HAL_Delay(1);
|
||||||
if(result != HAL_OK){
|
if (result != HAL_OK) {
|
||||||
return EEPROM_FAIL;
|
return EEPROM_FAIL;
|
||||||
}
|
}
|
||||||
return EEPROM_OK;
|
return EEPROM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryStatus FLASH_ReadBlock(uint16_t startAddr, uint8_t number, uint8_t *readData, uint8_t dataSize)
|
MemoryStatus FLASH_ReadBlock(uint16_t startAddr, uint8_t number,
|
||||||
{
|
uint8_t *readData, uint16_t dataSize) {
|
||||||
HAL_StatusTypeDef result;
|
HAL_StatusTypeDef result;
|
||||||
|
|
||||||
// Проверка на корректность входных данных
|
// Проверка на корректность входных данных
|
||||||
if ((startAddr == START_ADR_SHOT && number > MAX_NUMBER_SHOTS) ||
|
if ((startAddr == START_ADR_SHOT && number > MAX_NUMBER_SHOTS)
|
||||||
(startAddr == START_ADR_PROGRAM && number > MAX_NUMBER_PROGRAMS) ||
|
|| (startAddr == START_ADR_PROGRAM && number > MAX_NUMBER_PROGRAMS)
|
||||||
(startAddr == START_ADR_MACRO && number > MAX_NUMBER_MACRO)) {
|
|| (startAddr == START_ADR_MACRO && number > MAX_NUMBER_MACRO)) {
|
||||||
return EEPROM_OUT_OF_RANGE;
|
return EEPROM_OUT_OF_RANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(readData, 0x00, dataSize);
|
memset(readData, 0x00, dataSize);
|
||||||
|
|
||||||
uint16_t blockAddr16 = (uint16_t)(startAddr + (uint16_t)(number * dataSize));
|
uint16_t blockAddr16 = (uint16_t) (startAddr
|
||||||
uint8_t blockAddr[2] = {HIBYTE(blockAddr16), LOBYTE(blockAddr16)};
|
+ (uint16_t) (number * dataSize));
|
||||||
|
uint8_t blockAddr[2] = { HIBYTE(blockAddr16), LOBYTE(blockAddr16) };
|
||||||
|
|
||||||
result = HAL_I2C_Master_Transmit(&hi2c1, (AT24C_ADRESS << 1), blockAddr, 2, 10);
|
result = HAL_I2C_Master_Transmit(&hi2c1, (AT24C_ADRESS << 1), blockAddr, 2,
|
||||||
|
10);
|
||||||
HAL_Delay(1);
|
HAL_Delay(1);
|
||||||
result = HAL_I2C_Master_Receive(&hi2c1, (AT24C_ADRESS << 1) | 1, readData, dataSize, 10);
|
result = HAL_I2C_Master_Receive(&hi2c1, (AT24C_ADRESS << 1) | 1, readData,
|
||||||
|
dataSize, 10);
|
||||||
HAL_Delay(1);
|
HAL_Delay(1);
|
||||||
if(result != HAL_OK){
|
if (result != HAL_OK) {
|
||||||
return EEPROM_FAIL;
|
return EEPROM_FAIL;
|
||||||
}
|
}
|
||||||
return EEPROM_OK;
|
return EEPROM_OK;
|
||||||
|
@ -73,99 +73,50 @@ void IR_Home_Process() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case IR_F_BTN: {
|
case IR_F_BTN: {
|
||||||
InfoBlock infoBlock;
|
EEPROM_INIT();
|
||||||
|
|
||||||
// Чтение структуры InfoBlock из EEPROM
|
|
||||||
MemoryStatus status = getInfoBlock(&infoBlock);
|
|
||||||
if (status != EEPROM_OK) {
|
|
||||||
char errorMsg[] = "Error reading InfoBlock from EEPROM\n";
|
|
||||||
CDC_Transmit_FS((uint8_t*)errorMsg, strlen(errorMsg));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Буфер для строки вывода
|
|
||||||
char buffer[128];
|
|
||||||
|
|
||||||
// Вывод информации о HardwareInit_t
|
|
||||||
snprintf(buffer, sizeof(buffer), "Hardware Initialization:\n");
|
|
||||||
CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
|
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "Servo 1: Invert=%u, Min=%u, Default=%u, Max=%u\n",
|
|
||||||
infoBlock.hwInfo.servos[0].invert, infoBlock.hwInfo.servos[0].min,
|
|
||||||
infoBlock.hwInfo.servos[0].def, infoBlock.hwInfo.servos[0].max);
|
|
||||||
CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
|
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "Servo 2: Invert=%u, Min=%u, Default=%u, Max=%u\n",
|
|
||||||
infoBlock.hwInfo.servos[1].invert, infoBlock.hwInfo.servos[1].min,
|
|
||||||
infoBlock.hwInfo.servos[1].def, infoBlock.hwInfo.servos[1].max);
|
|
||||||
CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
|
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "Servo 3: Invert=%u, Min=%u, Default=%u, Max=%u\n",
|
|
||||||
infoBlock.hwInfo.servos[2].invert, infoBlock.hwInfo.servos[2].min,
|
|
||||||
infoBlock.hwInfo.servos[2].def, infoBlock.hwInfo.servos[2].max);
|
|
||||||
CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
|
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "Motors: Speed_Rollers_Min=%u, Speed_Screw_Min=%u\n",
|
|
||||||
infoBlock.hwInfo.motors.speed_Rollers_min, infoBlock.hwInfo.motors.speed_Screw_min);
|
|
||||||
CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
|
|
||||||
|
|
||||||
// Вывод информации о DelayTimes
|
|
||||||
snprintf(buffer, sizeof(buffer), "Timings: PreRun=%u\n", infoBlock.hwInfo.timings.preRun);
|
|
||||||
CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
|
|
||||||
|
|
||||||
// Вывод информации о Statistics
|
|
||||||
snprintf(buffer, sizeof(buffer), "Statistics:\n");
|
|
||||||
CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
|
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "Total Shots: %lu\n", infoBlock.statInfo.totalShots);
|
|
||||||
CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
|
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "Total Programs: %lu\n", infoBlock.statInfo.totalPrograms);
|
|
||||||
CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
|
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "Total Macros: %lu\n", infoBlock.statInfo.totalMacros);
|
|
||||||
CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
|
case IR_PAUSE: {
|
||||||
case IR_PAUSE:
|
uint8_t buf[1024]; // Буфер для чтения данных размером 128 байт
|
||||||
{
|
|
||||||
uint8_t buf[8]; // Буфер для чтения данных размером 128 байт
|
|
||||||
uint16_t blockAddr16 = 0; // Начальный адрес EEPROM
|
uint16_t blockAddr16 = 0; // Начальный адрес EEPROM
|
||||||
uint8_t blockAddr[2] = { (uint8_t)(blockAddr16 >> 8), (uint8_t)(blockAddr16 & 0xFF) }; // Адрес в формате 2 байта
|
uint8_t blockAddr[2] = { (uint8_t) (blockAddr16 >> 8),
|
||||||
|
(uint8_t) (blockAddr16 & 0xFF) }; // Адрес в формате 2 байта
|
||||||
int max_attempts = 15; // Максимальное количество попыток для операции
|
int max_attempts = 15; // Максимальное количество попыток для операции
|
||||||
int attempts = 0; // Счетчик попыток
|
int attempts = 0; // Счетчик попыток
|
||||||
HAL_StatusTypeDef status;
|
HAL_StatusTypeDef status;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// Отправляем адрес в EEPROM
|
// Отправляем адрес в EEPROM
|
||||||
status = HAL_I2C_Master_Transmit(&hi2c1, (AT24C_ADRESS << 1), blockAddr, 2, 1000);
|
status = HAL_I2C_Master_Transmit(&hi2c1, (AT24C_ADRESS << 1),
|
||||||
|
blockAddr, 2, 1000);
|
||||||
if (status != HAL_OK) {
|
if (status != HAL_OK) {
|
||||||
HAL_Delay(5); // Задержка перед повтором
|
HAL_Delay(1); // Задержка перед повтором
|
||||||
attempts++;
|
attempts++;
|
||||||
continue; // Переход к следующей попытке
|
continue; // Переход к следующей попытке
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_Delay(5); // Небольшая задержка
|
HAL_Delay(1); // Небольшая задержка
|
||||||
|
|
||||||
// Читаем 128 байт данных из EEPROM
|
// Читаем 128 байт данных из EEPROM
|
||||||
status = HAL_I2C_Master_Receive(&hi2c1, (AT24C_ADRESS << 1) | 1, buf, sizeof(buf), 1000);
|
status = HAL_I2C_Master_Receive(&hi2c1, (AT24C_ADRESS << 1) | 1,
|
||||||
|
buf, sizeof(buf), 1000);
|
||||||
if (status == HAL_OK) {
|
if (status == HAL_OK) {
|
||||||
// Данные успешно считаны, выводим их
|
// Данные успешно считаны, выводим их
|
||||||
char buffer[16];
|
char buffer[16];
|
||||||
for (int i = 0; i < sizeof(buf); ++i) {
|
for (int i = 0; i < sizeof(buf); ++i) {
|
||||||
if (i % 8 == 0) print(" ");
|
if (i % 8 == 0)
|
||||||
if (i % 32 == 0) print("\n");
|
print(" ");
|
||||||
|
if (i % 32 == 0)
|
||||||
|
print("\n");
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "%02X ", buf[i]); // Преобразуем байт в шестнадцатеричную строку
|
snprintf(buffer, sizeof(buffer), "%02X ", buf[i]); // Преобразуем байт в шестнадцатеричную строку
|
||||||
CDC_Transmit_FS((uint8_t*)buffer, strlen(buffer));
|
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||||
}
|
}
|
||||||
break; // Выход из попыток, если чтение успешно
|
break; // Выход из попыток, если чтение успешно
|
||||||
} else {
|
} else {
|
||||||
print("Read Error EEPROM\n");
|
print("Read Error EEPROM\n");
|
||||||
HAL_Delay(5); // Задержка перед повтором
|
HAL_Delay(1); // Задержка перед повтором
|
||||||
attempts++;
|
attempts++;
|
||||||
}
|
}
|
||||||
} while (attempts < max_attempts);
|
} while (attempts < max_attempts);
|
||||||
@ -173,9 +124,21 @@ void IR_Home_Process() {
|
|||||||
if (status != HAL_OK) {
|
if (status != HAL_OK) {
|
||||||
print("Failed to read EEPROM after multiple attempts\n");
|
print("Failed to read EEPROM after multiple attempts\n");
|
||||||
}
|
}
|
||||||
|
print("\n\n\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case IR_ESC: {
|
||||||
|
|
||||||
|
if (EEPROM_EARSE() != EEPROM_OK) {
|
||||||
|
char errorMsg[] = "Error EEPROM_EARSE\n\n";
|
||||||
|
CDC_Transmit_FS((uint8_t*) errorMsg, strlen(errorMsg));
|
||||||
|
} else {
|
||||||
|
char doneMsg[] = "EEPROM_EARSE Done\n\n";
|
||||||
|
CDC_Transmit_FS((uint8_t*) doneMsg, strlen(doneMsg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case IR_DEBUG: {
|
case IR_DEBUG: {
|
||||||
uint8_t i2c_address;
|
uint8_t i2c_address;
|
||||||
|
@ -13,7 +13,6 @@ void print(char* str){
|
|||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
CDC_Transmit_FS((unsigned char*)str, size);
|
CDC_Transmit_FS((unsigned char*)str, size);
|
||||||
HAL_Delay(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void int_to_str(int number, char *str, int base)
|
void int_to_str(int number, char *str, int base)
|
||||||
@ -56,5 +55,4 @@ 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));
|
||||||
HAL_Delay(1);
|
|
||||||
}
|
}
|
||||||
|
@ -176,11 +176,11 @@ int main(void)
|
|||||||
|
|
||||||
// BufShots[1] = GetShot(0);
|
// BufShots[1] = GetShot(0);
|
||||||
|
|
||||||
initcomlete = 1;
|
|
||||||
|
|
||||||
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);
|
||||||
|
EEPROM_INIT();
|
||||||
Shiftreg[0] = 0x01; Shiftreg[1] = 0x77; Shiftreg[2] = 0x01; SetShiftReg(Shiftreg); HAL_Delay(10);
|
Shiftreg[0] = 0x01; Shiftreg[1] = 0x77; Shiftreg[2] = 0x01; SetShiftReg(Shiftreg); HAL_Delay(10);
|
||||||
Shiftreg[0] = 0x03; Shiftreg[1] = 0x77; Shiftreg[2] = 0x03; SetShiftReg(Shiftreg); HAL_Delay(10);
|
Shiftreg[0] = 0x03; Shiftreg[1] = 0x77; Shiftreg[2] = 0x03; SetShiftReg(Shiftreg); HAL_Delay(10);
|
||||||
Shiftreg[0] = 0x07; Shiftreg[1] = 0x77; Shiftreg[2] = 0x07; SetShiftReg(Shiftreg); HAL_Delay(10);
|
Shiftreg[0] = 0x07; Shiftreg[1] = 0x77; Shiftreg[2] = 0x07; SetShiftReg(Shiftreg); HAL_Delay(10);
|
||||||
@ -190,6 +190,7 @@ initcomlete = 1;
|
|||||||
Shiftreg[0] = 0x7F; Shiftreg[1] = 0x77; Shiftreg[2] = 0x7F; SetShiftReg(Shiftreg); HAL_Delay(10);
|
Shiftreg[0] = 0x7F; Shiftreg[1] = 0x77; Shiftreg[2] = 0x7F; SetShiftReg(Shiftreg); HAL_Delay(10);
|
||||||
Shiftreg[0] = 0x00; Shiftreg[1] = 0x00; Shiftreg[2] = 0x00; SetShiftReg(Shiftreg); HAL_Delay(10);
|
Shiftreg[0] = 0x00; Shiftreg[1] = 0x00; Shiftreg[2] = 0x00; SetShiftReg(Shiftreg); HAL_Delay(10);
|
||||||
|
|
||||||
|
initcomlete = 1;
|
||||||
|
|
||||||
|
|
||||||
HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_1); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 <20>6 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> PA0 PA1
|
HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_1); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 <20>6 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> PA0 PA1
|
||||||
@ -203,6 +204,8 @@ initcomlete = 1;
|
|||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
/* USER CODE BEGIN WHILE */
|
/* USER CODE BEGIN WHILE */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Shot testShot;
|
Shot testShot;
|
||||||
memset(&testShot, 0x00, sizeof(Shot));
|
memset(&testShot, 0x00, sizeof(Shot));
|
||||||
getShot(3, &testShot);
|
getShot(3, &testShot);
|
||||||
|
@ -570,6 +570,8 @@ void TIM3_IRQHandler(void)
|
|||||||
// Обработка переполнения таймера
|
// Обработка переполнения таймера
|
||||||
if (TIM3->SR & TIM_SR_UIF)
|
if (TIM3->SR & TIM_SR_UIF)
|
||||||
{
|
{
|
||||||
|
current_capture1 = 0xFFFFFFFF;
|
||||||
|
current_capture2 = 0xFFFFFFFF;
|
||||||
// Сброс флага переполнения
|
// Сброс флага переполнения
|
||||||
TIM3->SR &= ~TIM_SR_UIF;
|
TIM3->SR &= ~TIM_SR_UIF;
|
||||||
}
|
}
|
||||||
|
@ -286,6 +286,7 @@ uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
|
|||||||
}
|
}
|
||||||
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);
|
||||||
/* USER CODE END 7 */
|
/* USER CODE END 7 */
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user