mirror of
https://github.com/EFeru/hoverboard-sideboard-hack-STM.git
synced 2025-08-17 00:56:10 +00:00
Improved UART Timeout
Major: - Improved UART Timeout: Apparently, the UART data Rx/Tx is quite unreliable (especially under motor load) leading to very often out-of-sync issues. This change allows to reset the DMA more often, leading to a faster re-sync of the UART transmission and thus avoiding UART timeout. Issue #1 Minor: - added #define MPU_SENSOR_ENABLE to allow to enable/disable the MPU6050 sensor and save code size if the sensors is not needed - fixed the orientation in the Processing sketch - updated ReadMe
This commit is contained in:
11
Src/main.c
11
Src/main.c
@@ -170,6 +170,8 @@ int main(void)
|
||||
#endif
|
||||
|
||||
intro_demo_led(100); // Short LEDs intro demo with 100 ms delay. This also gives some time for the MPU-6050 to power-up.
|
||||
|
||||
#ifdef MPU_SENSOR_ENABLE
|
||||
if(mpu_config()) { // IMU MPU-6050 config
|
||||
mpuStatus = ERROR;
|
||||
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET); // Turn on RED LED
|
||||
@@ -179,6 +181,9 @@ int main(void)
|
||||
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET); // Turn on GREEN LED
|
||||
}
|
||||
mpu_handle_input('h'); // Print the User Help commands to serial
|
||||
#else
|
||||
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET); // Turn on GREEN LED
|
||||
#endif
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
@@ -201,7 +206,7 @@ int main(void)
|
||||
#endif
|
||||
|
||||
// ==================================== USER Handling ====================================
|
||||
#ifdef SERIAL_DEBUG
|
||||
#if defined(MPU_SENSOR_ENABLE) && defined(SERIAL_DEBUG)
|
||||
// Get the user Input as one character from Serial
|
||||
if (userCommand != 0) { // Check the availability of a user command set by the UART DMA
|
||||
log_i("Command = %c\n", userCommand);
|
||||
@@ -212,6 +217,7 @@ int main(void)
|
||||
|
||||
|
||||
// ==================================== MPU-6050 Handling ====================================
|
||||
#if defined(MPU_SENSOR_ENABLE) && defined(SERIAL_DEBUG)
|
||||
// Get MPU data. Because the MPU-6050 interrupt pin is not wired we have to check DMP data by pooling periodically
|
||||
if (SUCCESS == mpuStatus) {
|
||||
mpu_get_data();
|
||||
@@ -222,6 +228,7 @@ int main(void)
|
||||
if (main_loop_counter % 50 == 0) {
|
||||
mpu_print_to_console();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// ==================================== SENSORS Handling ====================================
|
||||
@@ -293,7 +300,7 @@ int main(void)
|
||||
timeoutCntSerial = SERIAL_TIMEOUT; // Limit timout counter value
|
||||
}
|
||||
// Most probably we are out-of-sync. Try to re-sync by reseting the DMA
|
||||
if (main_loop_counter % 150 == 0) {
|
||||
if (NewFeedback.start != SERIAL_START_FRAME && NewFeedback.start != 0xFFFF && main_loop_counter % 5 == 0) {
|
||||
HAL_UART_DMAStop(&huart2);
|
||||
HAL_UART_Receive_DMA(&huart2, (uint8_t *)&NewFeedback, sizeof(NewFeedback));
|
||||
}
|
||||
|
@@ -44,7 +44,11 @@
|
||||
*/
|
||||
|
||||
|
||||
static signed char MPU_ORIENTATION[9] = {1, 0, 0, // [-] MPU Sensor orientation matrix: set this according to the sensor installation
|
||||
MPU_Data mpu; // holds the MPU-6050 data
|
||||
|
||||
#ifdef MPU_SENSOR_ENABLE
|
||||
|
||||
static signed char MPU_ORIENTATION[9] = {1, 0, 0, // [-] MPU Sensor orientation matrix: set this according to the sensor installation
|
||||
0, 1, 0,
|
||||
0, 0, 1};
|
||||
|
||||
@@ -3469,8 +3473,6 @@ int mpu_config(void)
|
||||
|
||||
/* =========================== MPU-6050 Get Packet Data =========================== */
|
||||
|
||||
MPU_Data mpu;
|
||||
|
||||
void mpu_get_data(void)
|
||||
{
|
||||
|
||||
@@ -3952,5 +3954,5 @@ void mpu_print_to_console(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif // MPU_SENSOR_ENABLE
|
||||
|
||||
|
@@ -22,12 +22,15 @@
|
||||
// Includes
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "config.h"
|
||||
#include "mpu6050.h"
|
||||
#include "mpu6050_dmp.h"
|
||||
#include "mpu6050_dmpKey.h"
|
||||
#include "mpu6050_dmpmap.h"
|
||||
|
||||
|
||||
#ifdef MPU_SENSOR_ENABLE
|
||||
|
||||
/* The following functions must be defined for this platform:
|
||||
* i2c_write(unsigned char slave_addr, unsigned char reg_addr,
|
||||
* unsigned char length, unsigned char const *data)
|
||||
@@ -1328,6 +1331,8 @@ int dmp_register_android_orient_cb(void (*func)(unsigned char))
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // MPU_SENSOR_ENABLE
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user