mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-05-03 14:50:21 +00:00
half work
This commit is contained in:
parent
b95af34bfd
commit
31a74305f6
2
.settings/com.st.stm32cube.ide.mcu.sfrview.prefs
Normal file
2
.settings/com.st.stm32cube.ide.mcu.sfrview.prefs
Normal file
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
sfrviewstate={"fFavorites"\:{"fLists"\:{}},"fProperties"\:{"fNodeProperties"\:{}}}
|
@ -108,7 +108,7 @@ typedef struct __attribute__((packed)) {
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint32_t shotsInShot;
|
||||
uint32_t shotsInProgram;
|
||||
uint32_t totalMacros;
|
||||
uint32_t shotInMacro;
|
||||
} Statistics;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
|
@ -34,23 +34,25 @@ typedef enum State{
|
||||
}State;
|
||||
|
||||
typedef struct CurrentShot {
|
||||
uint8_t index;
|
||||
uint8_t indexGlobal;
|
||||
uint16_t currentBallCount;
|
||||
Shot shot;
|
||||
} CurrentShot;
|
||||
|
||||
typedef struct CurrentProgram {
|
||||
uint8_t index;
|
||||
uint8_t indexGlobal;
|
||||
Program program;
|
||||
CurrentShot currentShot;
|
||||
uint8_t programShotId;
|
||||
uint8_t currentShotIndexLocal;
|
||||
uint16_t currentBallCount;
|
||||
} CurrentProgram;
|
||||
|
||||
typedef struct CurrentMacro {
|
||||
uint8_t index;
|
||||
uint8_t indexGlobal;
|
||||
Macro macro;
|
||||
uint8_t program_index;
|
||||
CurrentProgram currentProgram;
|
||||
uint8_t currentProgramIndexLocal;
|
||||
uint16_t currentBallCount;
|
||||
} CurrentMacro;
|
||||
|
||||
//typedef struct CurrentState {
|
||||
@ -69,7 +71,7 @@ typedef struct CurrentInfo {
|
||||
|
||||
void Robot_INIT();
|
||||
|
||||
void shotApply(Shot*);
|
||||
void shotApply(CurrentShot*);
|
||||
void doShotForever(uint8_t number);
|
||||
|
||||
void BallEXT();
|
||||
@ -77,7 +79,7 @@ void RobotTick();
|
||||
|
||||
uint8_t prepareShot(uint8_t number);
|
||||
uint8_t prepareProgramm(uint8_t number);
|
||||
//uint8_t prepareMacro(uint8_t number);
|
||||
uint8_t prepareMacro(uint8_t number);
|
||||
|
||||
|
||||
void startShooting(uint32_t delayTime);
|
||||
|
@ -49,7 +49,7 @@ MemoryStatus EEPROM_INIT() {
|
||||
|
||||
infoBlock.statInfo.shotsInShot = 0;
|
||||
infoBlock.statInfo.shotsInProgram = 0;
|
||||
infoBlock.statInfo.totalMacros = 0;
|
||||
infoBlock.statInfo.shotInMacro = 0;
|
||||
|
||||
status = saveInfoBlock(&infoBlock);
|
||||
if (status != EEPROM_OK) {
|
||||
@ -121,7 +121,7 @@ MemoryStatus EEPROM_INIT() {
|
||||
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||
|
||||
snprintf(buffer, sizeof(buffer), "Total Macros: %lu\n\n",
|
||||
infoBlock.statInfo.totalMacros);
|
||||
infoBlock.statInfo.shotInMacro);
|
||||
CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||
|
||||
return status;
|
||||
|
@ -79,7 +79,7 @@ void IR_Home_Process() {
|
||||
|
||||
case IR_PAUSE: {
|
||||
uint8_t buf[1024]; // Буфер для чтения данных размером 128 байт
|
||||
uint16_t blockAddr16 = 0; // Начальный адрес EEPROM
|
||||
uint16_t blockAddr16 = START_ADR_MACRO; // Начальный адрес EEPROM
|
||||
uint8_t blockAddr[2] = { (uint8_t) (blockAddr16 >> 8),
|
||||
(uint8_t) (blockAddr16 & 0xFF) }; // Адрес в формате 2 байта
|
||||
int max_attempts = 15; // Максимальное количество попыток для операции
|
||||
|
@ -25,22 +25,23 @@ uint8_t ballDetected = 0;
|
||||
uint32_t ballReact_timer = 0;
|
||||
uint8_t isDelayTimerRun = 0;
|
||||
uint32_t startDelay_timer;
|
||||
Shot *postDelayShot = NULL;
|
||||
CurrentShot *postDelayShot = NULL;
|
||||
uint32_t lastIndicationTime = 0;
|
||||
uint32_t noBallTimer = 0;
|
||||
uint32_t noBallTimeout = 0xFFFFFFFF;
|
||||
|
||||
void BallEXT_Handler();
|
||||
Shot* getShotFromProgram(CurrentProgram *currentProg);
|
||||
void robotStateStart(uint32_t delayTime);
|
||||
void robotStatePause();
|
||||
void robotStateStop();
|
||||
float calculatePeriod(int pwm_value);
|
||||
uint8_t nextBallinShot(CurrentShot *shot);
|
||||
void shotApply(Shot *shot);
|
||||
uint8_t nextBallInShot(CurrentShot *shot);
|
||||
uint8_t nextProgramInMacro(CurrentMacro *macro);
|
||||
uint8_t nextShotInProgram(CurrentProgram *prog);
|
||||
uint8_t loadNextShotInProgram(CurrentProgram *currentProg);
|
||||
uint8_t loadShotFromProgram(CurrentProgram *currentProg);
|
||||
Shot* getShotFromProgram(CurrentProgram *currentProg);
|
||||
uint8_t loadNextProgramInMacro(CurrentMacro *currentMacro);
|
||||
uint8_t loadProgramFromMacro(CurrentMacro *currentMacro);
|
||||
|
||||
void robotStateStart(uint32_t delayTime) {
|
||||
currentInfo.state = PRERUN_WAIT;
|
||||
@ -56,13 +57,10 @@ void robotStateStop() {
|
||||
currentInfo.state = STOP;
|
||||
}
|
||||
|
||||
void BallEXT() {
|
||||
ballDetected = 1;
|
||||
ballReact_timer = millis();
|
||||
long map(long x, long in_min, long in_max, long out_min, long out_max) {
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
|
||||
// Функция для расчета периода вылета мяча на основе ШИМ
|
||||
float calculatePeriod(int pwm_value) {
|
||||
float calculatePeriod(int pwm_value) {// Функция для расчета периода вылета мяча на основе ШИМ
|
||||
// Коэффициенты из аппроксимации
|
||||
float a = 100382.255;
|
||||
float b = 0.21895;
|
||||
@ -73,130 +71,12 @@ float calculatePeriod(int pwm_value) {
|
||||
return period;
|
||||
}
|
||||
|
||||
void RobotTick() {
|
||||
BallEXT_Handler();
|
||||
|
||||
// No Ball Handler
|
||||
if (currentInfo.state == RUN && millis() - noBallTimer > noBallTimeout) {
|
||||
robotStateStop();
|
||||
setScrewkSpeed(0);
|
||||
setRollersSpeed(100, 100);
|
||||
setPos(infoBlock.hwInfo.servos[SERVO_AXIAL].def,
|
||||
infoBlock.hwInfo.servos[SERVO_HORIZONTAL].def,
|
||||
infoBlock.hwInfo.servos[SERVO_VERTICAL].min);
|
||||
print("NO BALL!!!");
|
||||
}
|
||||
|
||||
// PreRun delay
|
||||
if (isDelayTimerRun) {
|
||||
uint32_t elapsedTime = millis() - startDelay_timer;
|
||||
|
||||
if (elapsedTime > currentInfo.startDelay) {
|
||||
isDelayTimerRun = 0;
|
||||
if (currentInfo.state == PRERUN_WAIT) {
|
||||
currentInfo.state = RUN;
|
||||
shotApply(postDelayShot);
|
||||
}
|
||||
} else {
|
||||
uint32_t intervalStep = currentInfo.startDelay / NUMLEDS;
|
||||
if (elapsedTime - lastIndicationTime >= intervalStep) {
|
||||
lastIndicationTime = elapsedTime;
|
||||
uint8_t progress = (elapsedTime * 100) / currentInfo.startDelay;
|
||||
// indicate(progress);
|
||||
print("delay: ");
|
||||
printNumber(progress);
|
||||
print("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t nextBallinShot(CurrentShot *shot) {
|
||||
|
||||
print("shot->shot.countRepeatShot ");
|
||||
printNumber(shot->shot.countRepeatShot);
|
||||
print("\n");
|
||||
|
||||
if (shot->currentBallCount + 1 < shot->shot.countRepeatShot
|
||||
|| !shot->shot.countRepeatShot) {
|
||||
// nextBall
|
||||
print("Shot ");
|
||||
printNumber(shot->currentBallCount);
|
||||
print("\n\n");
|
||||
|
||||
shot->currentBallCount++;
|
||||
return 0;
|
||||
} else {
|
||||
print("Shot DONE\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void BallEXT_Handler() {
|
||||
if (ballDetected && millis() - ballReact_timer > ballReact_value) {
|
||||
ballDetected = 0;
|
||||
|
||||
if (currentInfo.state != RUN) {
|
||||
print("BallDetected on idle\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print("BallDetected ");
|
||||
uint16_t period = ballReact_timer - noBallTimer;
|
||||
printNumber(period);
|
||||
print("ms\n");
|
||||
noBallTimer = ballReact_timer;
|
||||
|
||||
switch (currentInfo.mode) {
|
||||
case NoneMode:
|
||||
|
||||
break;
|
||||
case ShotMode:
|
||||
if (nextBallinShot(¤tInfo.shot)) {
|
||||
stopShooting();
|
||||
}
|
||||
infoBlock.statInfo.shotsInShot++;
|
||||
saveInfoBlock();
|
||||
break;
|
||||
case ProgramMode:
|
||||
if (nextBallinShot(¤tInfo.program.currentShot)) {
|
||||
if (!loadNextShotInProgram(¤tInfo.program)) {
|
||||
stopShooting();
|
||||
print("loadNextShotInProgram ERR\n");
|
||||
}
|
||||
shotApply(getShotFromProgram(¤tInfo.program));
|
||||
}
|
||||
|
||||
if (currentInfo.program.currentBallCount + 1
|
||||
< currentInfo.program.program.header.countRepeat
|
||||
|| currentInfo.program.program.header.countRepeat == 0) {
|
||||
currentInfo.program.currentBallCount++;
|
||||
} else {
|
||||
stopShooting();
|
||||
print("Program DONE\n");
|
||||
}
|
||||
infoBlock.statInfo.shotsInProgram++;
|
||||
saveInfoBlock();
|
||||
break;
|
||||
case MacroMode:
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
long map(long x, long in_min, long in_max, long out_min, long out_max) {
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
void Robot_INIT() {
|
||||
memset(¤tInfo, 0x00, sizeof(currentInfo));
|
||||
// NULL
|
||||
currentInfo.shot.index = 0xFF;
|
||||
currentInfo.program.index = 0xFF;
|
||||
currentInfo.macro.index = 0xFF;
|
||||
currentInfo.shot.indexGlobal = 0xFF;
|
||||
currentInfo.program.indexGlobal = 0xFF;
|
||||
currentInfo.macro.indexGlobal = 0xFF;
|
||||
initPCA9685();
|
||||
EEPROM_INIT();
|
||||
UART3_START();
|
||||
@ -262,147 +142,50 @@ void Robot_INIT() {
|
||||
|
||||
}
|
||||
|
||||
void shotApply(Shot *shot) {
|
||||
setPos(shot->rotationAxial, shot->rotationHorizontal,
|
||||
shot->rotationVertical);
|
||||
setRollersSpeed(shot->speedRollerTop, shot->speedRollerBottom);
|
||||
setScrewkSpeed(shot->speedScrew);
|
||||
noBallTimeout = MIN(
|
||||
calculatePeriod( shot->speedScrew) * NOBALL_TIMEOUT_MULTIPLIER,
|
||||
30000);
|
||||
noBallTimer = millis();
|
||||
print("Fire!\n");
|
||||
print("isExist ");
|
||||
printNumber(shot->isExist);
|
||||
print("\ncountRepeatShot; ");
|
||||
printNumber(shot->countRepeatShot);
|
||||
print("\nspeedRollerTop; ");
|
||||
printNumber(shot->speedRollerTop);
|
||||
print("\nspeedRollerBottom; ");
|
||||
printNumber(shot->speedRollerBottom);
|
||||
print("\nspeedScrew; ");
|
||||
printNumber(shot->speedScrew);
|
||||
print("\nrotationAxial; ");
|
||||
printNumber(shot->rotationAxial);
|
||||
print("\nrotationHorizontal; ");
|
||||
printNumber(shot->rotationHorizontal);
|
||||
print("\nrotationVertical; ");
|
||||
printNumber(shot->rotationVertical);
|
||||
print("\nnoBallTimeout: ");
|
||||
printNumber(noBallTimeout);
|
||||
print("\n");
|
||||
print("\n\n");
|
||||
void BallEXT() {
|
||||
ballDetected = 1;
|
||||
ballReact_timer = millis();
|
||||
}
|
||||
|
||||
uint8_t loadShotFromProgram(CurrentProgram *currentProg) {
|
||||
Shot shot_;
|
||||
uint8_t currentProgramShotId = currentProg->programShotId;
|
||||
if (currentProgramShotId >= currentProg->program.header.shotCount) {
|
||||
print("Shot index out of range\n");
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
return 0;
|
||||
}
|
||||
uint8_t shotId = currentProg->program.shots[currentProgramShotId].id;
|
||||
currentProg->currentShot.index = shotId;
|
||||
getShot(shotId, &shot_);
|
||||
if (!shot_.isExist) {
|
||||
print("Shot in program is NULL\n");
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
return 0;
|
||||
|
||||
void RobotTick() {
|
||||
BallEXT_Handler();
|
||||
|
||||
// No Ball Handler
|
||||
if (currentInfo.state == RUN && millis() - noBallTimer > noBallTimeout) {
|
||||
robotStateStop();
|
||||
setScrewkSpeed(0);
|
||||
setRollersSpeed(100, 100);
|
||||
setPos(infoBlock.hwInfo.servos[SERVO_AXIAL].def,
|
||||
infoBlock.hwInfo.servos[SERVO_HORIZONTAL].def,
|
||||
infoBlock.hwInfo.servos[SERVO_VERTICAL].min);
|
||||
print("NO BALL!!!");
|
||||
}
|
||||
|
||||
uint8_t overridenSpeedScrew =
|
||||
currentProg->program.shots[currentProgramShotId].speedScrew;
|
||||
if (overridenSpeedScrew != 0) {
|
||||
shot_.speedScrew = overridenSpeedScrew;
|
||||
}
|
||||
// PreRun delay
|
||||
if (isDelayTimerRun) {
|
||||
uint32_t elapsedTime = millis() - startDelay_timer;
|
||||
|
||||
uint8_t repeatCountFromShot = currentProg->program.header.options & 2U;
|
||||
if (!repeatCountFromShot) {
|
||||
print("Repeat Count Override\n");
|
||||
shot_.countRepeatShot = 1;
|
||||
}
|
||||
currentProg->currentShot.shot = shot_;
|
||||
print("REPEAT ");
|
||||
printNumber(shot_.countRepeatShot);
|
||||
print("\n");
|
||||
currentProg->currentShot.currentBallCount = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t loadNextShotInProgram(CurrentProgram *currentProg) {
|
||||
uint8_t random = currentProg->program.header.options & 1U;
|
||||
uint8_t *currentProgramShotId = ¤tProg->programShotId;
|
||||
|
||||
if (random) {
|
||||
*currentProgramShotId = rand() % currentProg->program.header.shotCount;
|
||||
} else {
|
||||
if ((*currentProgramShotId) + 1
|
||||
< currentProg->program.header.shotCount) {
|
||||
++(*currentProgramShotId);
|
||||
} else {
|
||||
*currentProgramShotId = 0;
|
||||
}
|
||||
}
|
||||
return loadShotFromProgram(currentProg);
|
||||
}
|
||||
|
||||
Shot* getShotFromProgram(CurrentProgram *currentProg) {
|
||||
return ¤tProg->currentShot.shot;
|
||||
}
|
||||
|
||||
void startShooting(uint32_t delayTime) {
|
||||
print("StartShooting\n");
|
||||
switch (currentInfo.mode) {
|
||||
case ShotMode:
|
||||
if (currentInfo.shot.shot.isExist) {
|
||||
postDelayShot = ¤tInfo.shot.shot;
|
||||
if (PRE_RUN_DELAY_MODE) {
|
||||
setPosFromShot(postDelayShot);
|
||||
if (elapsedTime > currentInfo.startDelay) {
|
||||
isDelayTimerRun = 0;
|
||||
if (currentInfo.state == PRERUN_WAIT) {
|
||||
currentInfo.state = RUN;
|
||||
shotApply(postDelayShot);
|
||||
}
|
||||
robotStateStart(delayTime);
|
||||
} else {
|
||||
print("Current Shot is NULL\n");
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
}
|
||||
break;
|
||||
case ProgramMode:
|
||||
if (currentInfo.program.program.header.shotCount) {
|
||||
if (!loadShotFromProgram(¤tInfo.program)) {
|
||||
print("loadShotFromProgram ERR\n");
|
||||
break;
|
||||
uint32_t intervalStep = currentInfo.startDelay / NUMLEDS;
|
||||
if (elapsedTime - lastIndicationTime >= intervalStep) {
|
||||
lastIndicationTime = elapsedTime;
|
||||
uint8_t progress = (elapsedTime * 100) / currentInfo.startDelay;
|
||||
// indicate(progress);
|
||||
print("delay: ");
|
||||
printNumber(progress);
|
||||
print("\n");
|
||||
}
|
||||
postDelayShot = getShotFromProgram(¤tInfo.program);
|
||||
if (PRE_RUN_DELAY_MODE) {
|
||||
setPosFromShot(postDelayShot);
|
||||
}
|
||||
robotStateStart(delayTime);
|
||||
|
||||
} else {
|
||||
print("Current Program is NULL\n");
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
}
|
||||
break;
|
||||
case MacroMode:
|
||||
if (currentInfo.macro.macro.header.programmCount) {
|
||||
|
||||
} else {
|
||||
print("Current Macro is NULL\n");
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void stopShooting() {
|
||||
robotStateStop();
|
||||
setScrewkSpeed(0);
|
||||
setRollersSpeed(100, 100);
|
||||
setPosDefault();
|
||||
}
|
||||
|
||||
uint8_t prepareShot(uint8_t number) {
|
||||
Shot shot;
|
||||
getShot(number, &shot);
|
||||
@ -423,8 +206,8 @@ uint8_t prepareProgramm(uint8_t number) {
|
||||
if (program.header.shotCount) { // isExist
|
||||
currentInfo.mode = ProgramMode;
|
||||
currentInfo.program.program = program;
|
||||
currentInfo.program.index = number;
|
||||
currentInfo.program.programShotId = 0;
|
||||
currentInfo.program.indexGlobal = number;
|
||||
currentInfo.program.currentShotIndexLocal = 0;
|
||||
currentInfo.program.currentBallCount = 0;
|
||||
return 1;
|
||||
} else {
|
||||
@ -434,6 +217,343 @@ uint8_t prepareProgramm(uint8_t number) {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t prepareMacro(uint8_t number) {
|
||||
Macro macro;
|
||||
getMacro(number, ¯o);
|
||||
if (macro.header.programmCount) {
|
||||
currentInfo.mode = MacroMode;
|
||||
currentInfo.macro.macro = macro;
|
||||
currentInfo.macro.indexGlobal = number;
|
||||
currentInfo.macro.currentProgramIndexLocal = 0;
|
||||
currentInfo.macro.currentBallCount = 0;
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
print("Macro not exist ");
|
||||
printNumber(number);
|
||||
print("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void BallEXT_Handler() {
|
||||
if (ballDetected && millis() - ballReact_timer > ballReact_value) {
|
||||
ballDetected = 0;
|
||||
|
||||
if (currentInfo.state != RUN) {
|
||||
print("BallDetected on idle\n");
|
||||
return;
|
||||
}
|
||||
|
||||
print("BallDetected ");
|
||||
uint16_t period = ballReact_timer - noBallTimer;
|
||||
printNumber(period);
|
||||
print("ms\n");
|
||||
noBallTimer = ballReact_timer;
|
||||
|
||||
switch (currentInfo.mode) {
|
||||
case NoneMode:
|
||||
|
||||
break;
|
||||
case ShotMode:
|
||||
print("ShotMode\n");
|
||||
if (nextBallInShot(¤tInfo.shot)) {
|
||||
stopShooting();
|
||||
}
|
||||
infoBlock.statInfo.shotsInShot++;
|
||||
saveInfoBlock();
|
||||
break;
|
||||
case ProgramMode:
|
||||
print("ProgramMode\n");
|
||||
if (nextShotInProgram(¤tInfo.program)) {
|
||||
stopShooting();
|
||||
}
|
||||
infoBlock.statInfo.shotsInProgram++;
|
||||
saveInfoBlock();
|
||||
break;
|
||||
case MacroMode:
|
||||
print("MacroMode\n");
|
||||
if (nextProgramInMacro(¤tInfo.macro)) {
|
||||
stopShooting();
|
||||
}
|
||||
infoBlock.statInfo.shotInMacro++;
|
||||
saveInfoBlock();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t loadShotFromProgram(CurrentProgram *currentProg) {
|
||||
Shot shot_;
|
||||
uint8_t currentShotIndexLocal = currentProg->currentShotIndexLocal;
|
||||
if (currentShotIndexLocal >= currentProg->program.header.shotCount) {
|
||||
print("Shot indexGlobal out of range\n");
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
return 0;
|
||||
}
|
||||
uint8_t shotId = currentProg->program.shots[currentShotIndexLocal].id;
|
||||
currentProg->currentShot.indexGlobal = shotId;
|
||||
getShot(shotId, &shot_);
|
||||
if (!shot_.isExist) {
|
||||
print("Shot in program is NULL\n");
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t overridenSpeedScrew =
|
||||
currentProg->program.shots[currentShotIndexLocal].speedScrew;
|
||||
if (overridenSpeedScrew != 0) {
|
||||
shot_.speedScrew = overridenSpeedScrew;
|
||||
}
|
||||
|
||||
uint8_t repeatCountFromShot = currentProg->program.header.options & 2U;
|
||||
if (!repeatCountFromShot) {
|
||||
print("Repeat Count Override\n");
|
||||
shot_.countRepeatShot = 1;
|
||||
}else if(shot_.countRepeatShot == 0 && currentInfo.mode != ShotMode){
|
||||
shot_.countRepeatShot = 1;
|
||||
}
|
||||
currentProg->currentShot.shot = shot_;
|
||||
currentProg->currentShot.currentBallCount = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t loadNextShotInProgram(CurrentProgram *currentProg) {
|
||||
uint8_t random = currentProg->program.header.options & 1U;
|
||||
uint8_t *currentProgramShotId = ¤tProg->currentShotIndexLocal;
|
||||
|
||||
if (random) {
|
||||
*currentProgramShotId = rand() % currentProg->program.header.shotCount;
|
||||
} else {
|
||||
if ((*currentProgramShotId) + 1
|
||||
< currentProg->program.header.shotCount) {
|
||||
++(*currentProgramShotId);
|
||||
} else {
|
||||
*currentProgramShotId = 0;
|
||||
}
|
||||
}
|
||||
return loadShotFromProgram(currentProg);
|
||||
}
|
||||
|
||||
uint8_t loadProgramFromMacro(CurrentMacro *currentMacro) {
|
||||
Program program_;
|
||||
uint8_t currentProgIndexLocal = currentMacro->currentProgramIndexLocal;
|
||||
if (currentMacro->currentProgramIndexLocal
|
||||
>= currentMacro->macro.header.programmCount) {
|
||||
print("Program indexGlobal out of range in currentMacro\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
uint8_t programId = currentMacro->macro.programs[currentProgIndexLocal].id;
|
||||
currentMacro->currentProgram.indexGlobal = programId;
|
||||
getProg(programId, &program_);
|
||||
|
||||
if (program_.header.shotCount == 0) {
|
||||
print("Program in macro is NULL\n");
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t needOverride =
|
||||
currentMacro->macro.programs[currentProgIndexLocal].countRepeat != 0
|
||||
&& currentMacro->macro.programs[currentProgIndexLocal].speedScrew
|
||||
!= 0;
|
||||
|
||||
if (needOverride)
|
||||
{
|
||||
print("Override programs params\n");
|
||||
program_.header.countRepeat = currentMacro->macro.programs[currentProgIndexLocal].countRepeat;
|
||||
program_.header.options = currentMacro->macro.programs[currentProgIndexLocal].options;
|
||||
for (uint8_t i = 0; i < program_.header.shotCount; i++) {
|
||||
program_.shots[i].speedScrew =
|
||||
currentMacro->macro.programs[currentProgIndexLocal].speedScrew;
|
||||
}
|
||||
}
|
||||
currentMacro->currentProgram.program = program_;
|
||||
currentMacro->currentProgram.currentShotIndexLocal = 0;
|
||||
currentMacro->currentProgram.currentBallCount = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t loadNextProgramInMacro(CurrentMacro *currentMacro) {
|
||||
if (currentMacro->currentProgramIndexLocal + 1
|
||||
< currentMacro->macro.header.programmCount) {
|
||||
currentMacro->currentProgramIndexLocal++;
|
||||
} else {
|
||||
currentMacro->currentProgramIndexLocal = 0;
|
||||
}
|
||||
return loadProgramFromMacro(currentMacro);
|
||||
}
|
||||
|
||||
uint8_t nextBallInShot(CurrentShot *shot) {
|
||||
|
||||
print("shot->shot.countRepeatShot ");
|
||||
printNumber(shot->shot.countRepeatShot);
|
||||
print("\n");
|
||||
|
||||
if (shot->currentBallCount + 1 < shot->shot.countRepeatShot
|
||||
|| !shot->shot.countRepeatShot) {
|
||||
// nextBall
|
||||
print("Shot ");
|
||||
printNumber(shot->currentBallCount);
|
||||
print("\n\n");
|
||||
|
||||
shot->currentBallCount++;
|
||||
return 0;
|
||||
} else {
|
||||
print("Shot DONE\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t nextShotInProgram(CurrentProgram *prog) {
|
||||
if (nextBallInShot(&prog->currentShot)) {
|
||||
print("\nSwitch shot\n");
|
||||
if (!loadNextShotInProgram(prog)) {
|
||||
print("loadNextShotInProgram ERR\n");
|
||||
return 0;
|
||||
}
|
||||
shotApply(&prog->currentShot);
|
||||
}
|
||||
|
||||
// Проверка на завершение программы
|
||||
if (prog->currentBallCount + 1 < prog->program.header.countRepeat
|
||||
|| prog->program.header.countRepeat == 0) {
|
||||
prog->currentBallCount++;
|
||||
} else {
|
||||
print("Program DONE\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t nextProgramInMacro(CurrentMacro *currentMacro) {
|
||||
if (nextShotInProgram(¤tMacro->currentProgram)) {
|
||||
print("\nSwitch program\n");
|
||||
if (!loadNextProgramInMacro(currentMacro)) {
|
||||
print("loadNextProgramInMacro ERR\n");
|
||||
return 0;
|
||||
}
|
||||
// shotApply(¤tMacro->currentProgram.currentShot);
|
||||
}
|
||||
|
||||
// Проверка на завершение макро
|
||||
// if (currentMacro->currentProgramIndexLocal < currentMacro->macro.header.programmCount) {
|
||||
// } else {
|
||||
// print("Macro DONE\n");
|
||||
// return 1;
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
void startShooting(uint32_t delayTime) {
|
||||
print("StartShooting\n");
|
||||
switch (currentInfo.mode) {
|
||||
case ShotMode:
|
||||
if (currentInfo.shot.shot.isExist) {
|
||||
postDelayShot = ¤tInfo.shot;
|
||||
if (PRE_RUN_DELAY_MODE) {
|
||||
setPosFromShot(&postDelayShot->shot);
|
||||
}
|
||||
robotStateStart(delayTime);
|
||||
} else {
|
||||
print("Current Shot is NULL\n");
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
}
|
||||
break;
|
||||
case ProgramMode:
|
||||
if (currentInfo.program.program.header.shotCount) {
|
||||
if (!loadShotFromProgram(¤tInfo.program)) {
|
||||
print("loadShotFromProgram ERR\n");
|
||||
break;
|
||||
}
|
||||
postDelayShot = ¤tInfo.program.currentShot;
|
||||
if (PRE_RUN_DELAY_MODE) {
|
||||
setPosFromShot(&postDelayShot->shot);
|
||||
}
|
||||
robotStateStart(delayTime);
|
||||
|
||||
} else {
|
||||
print("Current Program is NULL\n");
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
}
|
||||
break;
|
||||
case MacroMode:
|
||||
if (currentInfo.macro.macro.header.programmCount) {
|
||||
if (!loadProgramFromMacro(¤tInfo.macro)) {
|
||||
print("loadProgramFromMacro ERR\n");
|
||||
break;
|
||||
}
|
||||
if (!loadShotFromProgram(¤tInfo.macro.currentProgram)) {
|
||||
print("loadShotFromProgram in macro ERR\n");
|
||||
break;
|
||||
}
|
||||
|
||||
postDelayShot = ¤tInfo.macro.currentProgram.currentShot;
|
||||
if (PRE_RUN_DELAY_MODE) {
|
||||
setPosFromShot(&postDelayShot->shot);
|
||||
}
|
||||
robotStateStart(delayTime);
|
||||
|
||||
} else {
|
||||
print("Current Macro is NULL\n");
|
||||
// TODO: sound_ERR(); ledFX_ERR();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void stopShooting() {
|
||||
robotStateStop();
|
||||
setScrewkSpeed(0);
|
||||
setRollersSpeed(100, 100);
|
||||
setPosDefault();
|
||||
}
|
||||
|
||||
void shotApply(CurrentShot *currentShot) {
|
||||
Shot* shot = ¤tShot->shot;
|
||||
setPos(shot->rotationAxial, shot->rotationHorizontal,
|
||||
shot->rotationVertical);
|
||||
setRollersSpeed(shot->speedRollerTop, shot->speedRollerBottom);
|
||||
setScrewkSpeed(shot->speedScrew);
|
||||
noBallTimeout = MIN(
|
||||
calculatePeriod( shot->speedScrew) * NOBALL_TIMEOUT_MULTIPLIER,
|
||||
30000);
|
||||
noBallTimer = millis();
|
||||
print("Global indx ");
|
||||
printNumber(currentShot->indexGlobal);
|
||||
print("\nisExist ");
|
||||
printNumber(shot->isExist);
|
||||
print("\ncountRepeatShot; ");
|
||||
printNumber(shot->countRepeatShot);
|
||||
print("\nspeedRollerTop; ");
|
||||
printNumber(shot->speedRollerTop);
|
||||
print("\nspeedRollerBottom; ");
|
||||
printNumber(shot->speedRollerBottom);
|
||||
print("\nspeedScrew; ");
|
||||
printNumber(shot->speedScrew);
|
||||
print("\nrotationAxial; ");
|
||||
printNumber(shot->rotationAxial);
|
||||
print("\nrotationHorizontal; ");
|
||||
printNumber(shot->rotationHorizontal);
|
||||
print("\nrotationVertical; ");
|
||||
printNumber(shot->rotationVertical);
|
||||
print("\nnoBallTimeout: ");
|
||||
printNumber(noBallTimeout);
|
||||
print("\n");
|
||||
print("\n\n");
|
||||
}
|
||||
|
||||
void setPosSingle(ServoMap servo, uint8_t value) {
|
||||
ServoSetting *currentServo = &infoBlock.hwInfo.servos[servo];
|
||||
uint8_t inv = currentServo->invert;
|
||||
|
@ -96,10 +96,11 @@ void UART3_SaveMacro(uint8_t *dataPtr, uint8_t len) {
|
||||
for (uint8_t i = 0; i < macro.header.programmCount; i++) {
|
||||
uint8_t pos = 2 + i * sizeof(MacroProgram);
|
||||
macro.programs[i].id = dataPtr[pos + 0];
|
||||
macro.programs[i].speedScrew = dataPtr[pos + 2];
|
||||
macro.programs[i].countRepeat = dataPtr[pos + 3];
|
||||
macro.programs[i].options = dataPtr[pos + 4];
|
||||
macro.programs[i].speedScrew = dataPtr[pos + 1];
|
||||
macro.programs[i].countRepeat = dataPtr[pos + 2];
|
||||
macro.programs[i].options = dataPtr[pos + 3];
|
||||
}
|
||||
saveMacro(macroIndx, ¯o);
|
||||
} else {
|
||||
delMacro(macroIndx);
|
||||
}
|
||||
@ -107,22 +108,28 @@ void UART3_SaveMacro(uint8_t *dataPtr, uint8_t len) {
|
||||
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||
}
|
||||
|
||||
// 100
|
||||
void UART3_StartMacro(uint8_t *dataPtr, uint8_t len) {
|
||||
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||
const uint8_t MIN_PARAM_LENGTH = 1;
|
||||
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||
return;
|
||||
|
||||
uint8_t macroIndx = dataPtr[1];
|
||||
if(prepareMacro(macroIndx))
|
||||
startShooting(infoBlock.hwInfo.timings.preRun);
|
||||
|
||||
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||
}
|
||||
|
||||
// 101
|
||||
void UART3_StartProgram(uint8_t *dataPtr, uint8_t len) {
|
||||
const uint8_t MIN_PARAM_LENGTH = 0;
|
||||
const uint8_t MIN_PARAM_LENGTH = 1;
|
||||
if (!checkLen(dataPtr[0], len, MIN_PARAM_LENGTH))
|
||||
return;
|
||||
|
||||
uint8_t progIndx = dataPtr[1];
|
||||
prepareProgramm(progIndx);
|
||||
startShooting(infoBlock.hwInfo.timings.preRun);
|
||||
if(prepareProgramm(progIndx))
|
||||
startShooting(infoBlock.hwInfo.timings.preRun);
|
||||
|
||||
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||
}
|
||||
@ -134,8 +141,8 @@ void UART3_StartShot(uint8_t *dataPtr, uint8_t len) {
|
||||
return;
|
||||
|
||||
uint8_t shotIndx = dataPtr[1];
|
||||
prepareShot(shotIndx);
|
||||
startShooting(infoBlock.hwInfo.timings.preRun);
|
||||
if(prepareShot(shotIndx))
|
||||
startShooting(infoBlock.hwInfo.timings.preRun);
|
||||
|
||||
SendResponse(dataPtr[0], 0, NULL, 0);
|
||||
}
|
||||
@ -470,13 +477,13 @@ void UART3_ReadStatistics(uint8_t *dataPtr, uint8_t len) {
|
||||
|
||||
switch (currentInfo.mode) {
|
||||
case ShotMode:
|
||||
res.shot_number = isRun ? currentInfo.shot.index : 0xFF;
|
||||
res.shot_number = isRun ? currentInfo.shot.indexGlobal : 0xFF;
|
||||
break;
|
||||
case ProgramMode:
|
||||
res.program_number = isRun ? currentInfo.program.index : 0xFF;
|
||||
res.program_number = isRun ? currentInfo.program.indexGlobal : 0xFF;
|
||||
break;
|
||||
case MacroMode:
|
||||
res.macro_number = isRun ? currentInfo.macro.index : 0xFF;
|
||||
res.macro_number = isRun ? currentInfo.macro.indexGlobal : 0xFF;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -488,8 +495,8 @@ void UART3_ReadStatistics(uint8_t *dataPtr, uint8_t len) {
|
||||
res.total_program_done_HIGH = HIGHBIT(infoBlock.statInfo.shotsInProgram);
|
||||
res.total_program_done_LOW = LOWBIT(infoBlock.statInfo.shotsInProgram);
|
||||
|
||||
res.total_macro_done_HIGH = HIGHBIT(infoBlock.statInfo.totalMacros);
|
||||
res.total_macro_done_LOW = LOWBIT(infoBlock.statInfo.totalMacros);
|
||||
res.total_macro_done_HIGH = HIGHBIT(infoBlock.statInfo.shotInMacro);
|
||||
res.total_macro_done_LOW = LOWBIT(infoBlock.statInfo.shotInMacro);
|
||||
|
||||
SendResponse(dataPtr[0], 0, (uint8_t*) &res, sizeof(res));
|
||||
}
|
||||
|
749
Core/Src/main.c
749
Core/Src/main.c
@ -106,28 +106,29 @@ static void MX_IWDG_Init(void);
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void) {
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
HAL_Init();
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
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 */
|
||||
SystemClock_Config();
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
/* USER CODE BEGIN SysInit */
|
||||
|
||||
SysTick->LOAD = 479999;
|
||||
|
||||
@ -135,19 +136,19 @@ int main(void) {
|
||||
HAL_Delay(10);
|
||||
__HAL_RCC_USB_RELEASE_RESET();
|
||||
HAL_Delay(10);
|
||||
/* USER CODE END SysInit */
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_DMA_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_USB_DEVICE_Init();
|
||||
MX_TIM1_Init();
|
||||
MX_TIM2_Init();
|
||||
MX_TIM3_Init();
|
||||
MX_USART3_UART_Init();
|
||||
MX_IWDG_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_DMA_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_USB_DEVICE_Init();
|
||||
MX_TIM1_Init();
|
||||
MX_TIM2_Init();
|
||||
MX_TIM3_Init();
|
||||
MX_USART3_UART_Init();
|
||||
MX_IWDG_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
__HAL_RCC_USART3_CLK_ENABLE();
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||
@ -169,10 +170,10 @@ int main(void) {
|
||||
HAL_TIM_Base_Start_IT(&htim3);
|
||||
HAL_NVIC_EnableIRQ(TIM3_IRQn);
|
||||
|
||||
/* USER CODE END 2 */
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
|
||||
while (1) {
|
||||
|
||||
@ -202,420 +203,445 @@ int main(void) {
|
||||
// CDC_Transmit_FS((uint8_t*) buffer, strlen(buffer));
|
||||
}
|
||||
|
||||
/* USER CODE END WHILE */
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
/* USER CODE BEGIN 3 */
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void) {
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = { 0 };
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI
|
||||
| RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
|
||||
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
|
||||
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
|
||||
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2C1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_I2C1_Init(void) {
|
||||
* @brief I2C1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_I2C1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN I2C1_Init 0 */
|
||||
/* USER CODE BEGIN I2C1_Init 0 */
|
||||
|
||||
/* USER CODE END I2C1_Init 0 */
|
||||
/* USER CODE END I2C1_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN I2C1_Init 1 */
|
||||
/* USER CODE BEGIN I2C1_Init 1 */
|
||||
|
||||
/* USER CODE END I2C1_Init 1 */
|
||||
hi2c1.Instance = I2C1;
|
||||
hi2c1.Init.ClockSpeed = 100000;
|
||||
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
||||
hi2c1.Init.OwnAddress1 = 0;
|
||||
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
hi2c1.Init.OwnAddress2 = 0;
|
||||
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
if (HAL_I2C_Init(&hi2c1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN I2C1_Init 2 */
|
||||
/* USER CODE END I2C1_Init 1 */
|
||||
hi2c1.Instance = I2C1;
|
||||
hi2c1.Init.ClockSpeed = 100000;
|
||||
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
||||
hi2c1.Init.OwnAddress1 = 0;
|
||||
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
hi2c1.Init.OwnAddress2 = 0;
|
||||
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN I2C1_Init 2 */
|
||||
|
||||
/* USER CODE END I2C1_Init 2 */
|
||||
/* USER CODE END I2C1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IWDG Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_IWDG_Init(void) {
|
||||
* @brief IWDG Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_IWDG_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN IWDG_Init 0 */
|
||||
/* USER CODE BEGIN IWDG_Init 0 */
|
||||
|
||||
/* USER CODE END IWDG_Init 0 */
|
||||
/* USER CODE END IWDG_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN IWDG_Init 1 */
|
||||
/* USER CODE BEGIN IWDG_Init 1 */
|
||||
|
||||
/* USER CODE END IWDG_Init 1 */
|
||||
hiwdg.Instance = IWDG;
|
||||
hiwdg.Init.Prescaler = IWDG_PRESCALER_64;
|
||||
hiwdg.Init.Reload = 625 * 5;
|
||||
if (HAL_IWDG_Init(&hiwdg) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN IWDG_Init 2 */
|
||||
/* USER CODE END IWDG_Init 1 */
|
||||
hiwdg.Instance = IWDG;
|
||||
hiwdg.Init.Prescaler = IWDG_PRESCALER_64;
|
||||
hiwdg.Init.Reload = 625*3;
|
||||
// if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
|
||||
// {
|
||||
// Error_Handler();
|
||||
// }
|
||||
/* USER CODE BEGIN IWDG_Init 2 */
|
||||
|
||||
/* USER CODE END IWDG_Init 2 */
|
||||
/* USER CODE END IWDG_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM1_Init(void) {
|
||||
* @brief TIM1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN TIM1_Init 0 */
|
||||
/* USER CODE BEGIN TIM1_Init 0 */
|
||||
|
||||
/* USER CODE END TIM1_Init 0 */
|
||||
/* USER CODE END TIM1_Init 0 */
|
||||
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = { 0 };
|
||||
TIM_MasterConfigTypeDef sMasterConfig = { 0 };
|
||||
TIM_OC_InitTypeDef sConfigOC = { 0 };
|
||||
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = { 0 };
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||
TIM_OC_InitTypeDef sConfigOC = {0};
|
||||
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN TIM1_Init 1 */
|
||||
/* USER CODE BEGIN TIM1_Init 1 */
|
||||
|
||||
/* USER CODE END TIM1_Init 1 */
|
||||
htim1.Instance = TIM1;
|
||||
htim1.Init.Prescaler = 0;
|
||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim1.Init.Period = 4000;
|
||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim1.Init.RepetitionCounter = 0;
|
||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_Init(&htim1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig)
|
||||
!= HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 0;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1)
|
||||
!= HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2)
|
||||
!= HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
|
||||
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
|
||||
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
|
||||
sBreakDeadTimeConfig.DeadTime = 0;
|
||||
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
|
||||
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
|
||||
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
|
||||
if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig)
|
||||
!= HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM1_Init 2 */
|
||||
/* USER CODE END TIM1_Init 1 */
|
||||
htim1.Instance = TIM1;
|
||||
htim1.Init.Prescaler = 0;
|
||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim1.Init.Period = 4000;
|
||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim1.Init.RepetitionCounter = 0;
|
||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 0;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
|
||||
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
|
||||
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
|
||||
sBreakDeadTimeConfig.DeadTime = 0;
|
||||
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
|
||||
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
|
||||
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
|
||||
if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM1_Init 2 */
|
||||
|
||||
/* USER CODE END TIM1_Init 2 */
|
||||
HAL_TIM_MspPostInit(&htim1);
|
||||
/* USER CODE END TIM1_Init 2 */
|
||||
HAL_TIM_MspPostInit(&htim1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM2 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM2_Init(void) {
|
||||
* @brief TIM2 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM2_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN TIM2_Init 0 */
|
||||
/* USER CODE BEGIN TIM2_Init 0 */
|
||||
|
||||
/* USER CODE END TIM2_Init 0 */
|
||||
/* USER CODE END TIM2_Init 0 */
|
||||
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = { 0 };
|
||||
TIM_MasterConfigTypeDef sMasterConfig = { 0 };
|
||||
TIM_OC_InitTypeDef sConfigOC = { 0 };
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||
TIM_OC_InitTypeDef sConfigOC = {0};
|
||||
|
||||
/* USER CODE BEGIN TIM2_Init 1 */
|
||||
/* USER CODE BEGIN TIM2_Init 1 */
|
||||
|
||||
/* USER CODE END TIM2_Init 1 */
|
||||
htim2.Instance = TIM2;
|
||||
htim2.Init.Prescaler = 0;
|
||||
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim2.Init.Period = 4000;
|
||||
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim2) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_Init(&htim2) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig)
|
||||
!= HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 0;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1)
|
||||
!= HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_2)
|
||||
!= HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_3)
|
||||
!= HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4)
|
||||
!= HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM2_Init 2 */
|
||||
/* USER CODE END TIM2_Init 1 */
|
||||
htim2.Instance = TIM2;
|
||||
htim2.Init.Prescaler = 0;
|
||||
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim2.Init.Period = 4000;
|
||||
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 0;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM2_Init 2 */
|
||||
|
||||
/* USER CODE END TIM2_Init 2 */
|
||||
HAL_TIM_MspPostInit(&htim2);
|
||||
/* USER CODE END TIM2_Init 2 */
|
||||
HAL_TIM_MspPostInit(&htim2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM3 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM3_Init(void) {
|
||||
* @brief TIM3 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM3_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN TIM3_Init 0 */
|
||||
/* USER CODE BEGIN TIM3_Init 0 */
|
||||
__HAL_RCC_TIM3_CLK_ENABLE();
|
||||
/* USER CODE END TIM3_Init 0 */
|
||||
/* USER CODE END TIM3_Init 0 */
|
||||
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = { 0 };
|
||||
TIM_MasterConfigTypeDef sMasterConfig = { 0 };
|
||||
TIM_IC_InitTypeDef sConfigIC = { 0 };
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||
TIM_IC_InitTypeDef sConfigIC = {0};
|
||||
|
||||
/* USER CODE BEGIN TIM3_Init 1 */
|
||||
/* USER CODE BEGIN TIM3_Init 1 */
|
||||
|
||||
/* USER CODE END TIM3_Init 1 */
|
||||
htim3.Instance = TIM3;
|
||||
htim3.Init.Prescaler = 47;
|
||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim3.Init.Period = 65000;
|
||||
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim3) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_IC_Init(&htim3) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig)
|
||||
!= HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
|
||||
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
|
||||
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
|
||||
sConfigIC.ICFilter = 0;
|
||||
if (HAL_TIM_IC_ConfigChannel(&htim3, &sConfigIC, TIM_CHANNEL_1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_IC_ConfigChannel(&htim3, &sConfigIC, TIM_CHANNEL_2) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM3_Init 2 */
|
||||
/* USER CODE END TIM3_Init 1 */
|
||||
htim3.Instance = TIM3;
|
||||
htim3.Init.Prescaler = 47;
|
||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim3.Init.Period = 65000;
|
||||
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_IC_Init(&htim3) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
|
||||
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
|
||||
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
|
||||
sConfigIC.ICFilter = 0;
|
||||
if (HAL_TIM_IC_ConfigChannel(&htim3, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_IC_ConfigChannel(&htim3, &sConfigIC, TIM_CHANNEL_2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM3_Init 2 */
|
||||
|
||||
/* USER CODE END TIM3_Init 2 */
|
||||
/* USER CODE END TIM3_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USART3 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_USART3_UART_Init(void) {
|
||||
* @brief USART3 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_USART3_UART_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN USART3_Init 0 */
|
||||
/* USER CODE BEGIN USART3_Init 0 */
|
||||
|
||||
/* USER CODE END USART3_Init 0 */
|
||||
/* USER CODE END USART3_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN USART3_Init 1 */
|
||||
/* USER CODE BEGIN USART3_Init 1 */
|
||||
|
||||
/* USER CODE END USART3_Init 1 */
|
||||
huart3.Instance = USART3;
|
||||
huart3.Init.BaudRate = 9600;
|
||||
huart3.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
huart3.Init.StopBits = UART_STOPBITS_1;
|
||||
huart3.Init.Parity = UART_PARITY_NONE;
|
||||
huart3.Init.Mode = UART_MODE_TX_RX;
|
||||
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
if (HAL_UART_Init(&huart3) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN USART3_Init 2 */
|
||||
/* USER CODE END USART3_Init 1 */
|
||||
huart3.Instance = USART3;
|
||||
huart3.Init.BaudRate = 9600;
|
||||
huart3.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
huart3.Init.StopBits = UART_STOPBITS_1;
|
||||
huart3.Init.Parity = UART_PARITY_NONE;
|
||||
huart3.Init.Mode = UART_MODE_TX_RX;
|
||||
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
if (HAL_UART_Init(&huart3) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN USART3_Init 2 */
|
||||
// if (HAL_UART_Receive_IT(&huart3, uart_rx_buffer, UART_BUFFER_SIZE) != HAL_OK)
|
||||
// {
|
||||
// Error_Handler();
|
||||
// }
|
||||
/* USER CODE END USART3_Init 2 */
|
||||
/* USER CODE END USART3_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable DMA controller clock
|
||||
*/
|
||||
static void MX_DMA_Init(void) {
|
||||
* Enable DMA controller clock
|
||||
*/
|
||||
static void MX_DMA_Init(void)
|
||||
{
|
||||
|
||||
/* DMA controller clock enable */
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||
/* 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);
|
||||
/* 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
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_GPIO_Init(void) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct = { 0 };
|
||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||
/* USER CODE END MX_GPIO_Init_1 */
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||
/* USER CODE END MX_GPIO_Init_1 */
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOA, LED_DATA_Pin | LED_CLK_Pin, GPIO_PIN_RESET);
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOA, LED_DATA_Pin|LED_CLK_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin : PC13 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_13;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
/*Configure GPIO pin : PC13 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_13;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : LED_DATA_Pin LED_CLK_Pin */
|
||||
GPIO_InitStruct.Pin = LED_DATA_Pin | LED_CLK_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
/*Configure GPIO pins : LED_DATA_Pin LED_CLK_Pin */
|
||||
GPIO_InitStruct.Pin = LED_DATA_Pin|LED_CLK_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : BALL_EXT_Pin */
|
||||
GPIO_InitStruct.Pin = BALL_EXT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(BALL_EXT_GPIO_Port, &GPIO_InitStruct);
|
||||
/*Configure GPIO pin : BALL_EXT_Pin */
|
||||
GPIO_InitStruct.Pin = BALL_EXT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(BALL_EXT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : IR_EXT_Pin */
|
||||
GPIO_InitStruct.Pin = IR_EXT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(IR_EXT_GPIO_Port, &GPIO_InitStruct);
|
||||
/*Configure GPIO pin : IR_EXT_Pin */
|
||||
GPIO_InitStruct.Pin = IR_EXT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(IR_EXT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* EXTI interrupt init*/
|
||||
HAL_NVIC_SetPriority(EXTI0_IRQn, 7, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
|
||||
/* EXTI interrupt init*/
|
||||
HAL_NVIC_SetPriority(EXTI0_IRQn, 7, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
|
||||
|
||||
HAL_NVIC_SetPriority(EXTI1_IRQn, 7, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
|
||||
HAL_NVIC_SetPriority(EXTI1_IRQn, 7, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
|
||||
|
||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
@ -623,17 +649,18 @@ static void MX_GPIO_Init(void) {
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void) {
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
// GPIOC->ODR &= ~GPIO_PIN_13;
|
||||
while (1) {
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
|
@ -367,7 +367,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
|
||||
__HAL_LINKDMA(huart,hdmarx,hdma_usart3_rx);
|
||||
|
||||
/* USART3 interrupt Init */
|
||||
HAL_NVIC_SetPriority(USART3_IRQn, 3, 0);
|
||||
HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(USART3_IRQn);
|
||||
/* USER CODE BEGIN USART3_MspInit 1 */
|
||||
|
||||
|
@ -17,7 +17,7 @@ File.Version=6
|
||||
GPIO.groupedBy=Group By Peripherals
|
||||
IWDG.IPParameters=Prescaler,Reload
|
||||
IWDG.Prescaler=IWDG_PRESCALER_64
|
||||
IWDG.Reload=625*5
|
||||
IWDG.Reload=625*3
|
||||
KeepUserPlacement=false
|
||||
Mcu.CPN=STM32F103C8T6
|
||||
Mcu.Family=STM32F1
|
||||
|
Loading…
x
Reference in New Issue
Block a user