Skip to content

Commit

Permalink
Merge pull request #9 from Northeastern-Electric-Racing/testing-imu
Browse files Browse the repository at this point in the history
Updated MSB for Platform Agnostic IMU driver
  • Loading branch information
caiodasilva2005 authored Oct 27, 2024
2 parents 72b7917 + bccd354 commit 1d8a8f6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Core/Src/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ uint16_t convert_can(uint16_t original_value, device_loc_t mode)
osThreadId_t temp_monitor_handle;
const osThreadAttr_t temp_monitor_attributes = {
.name = "TempMonitor",
.stack_size = 64 * 8,
.stack_size = 64 * 16,
.priority = (osPriority_t)osPriorityHigh1,
};

Expand Down
20 changes: 18 additions & 2 deletions Core/Src/msb.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ extern device_loc_t device_loc;

osMutexId_t i2c_mutex;

// reads imu reg
static inline int imu_read_reg(uint8_t *data, uint8_t reg, uint8_t length)
{
return HAL_I2C_Mem_Read(&hi2c3, LSM6DSO_I2C_ADDRESS, reg,
I2C_MEMADD_SIZE_8BIT, data, length,
HAL_MAX_DELAY);
}

// read imu write
static inline int imu_write_reg(uint8_t *data, uint8_t reg, uint8_t length)
{
return HAL_I2C_Mem_Write(&hi2c3, LSM6DSO_I2C_ADDRESS, reg,
I2C_MEMADD_SIZE_8BIT, data, length,
HAL_MAX_DELAY);
}

#ifdef SENSOR_TEMP
sht30_t temp_sensor;
#endif
Expand Down Expand Up @@ -42,8 +58,8 @@ int8_t msb_init()

#ifdef SENSOR_IMU
/* Initialize the IMU */
imu = (lsm6dso_t){ .i2c_handle = &hi2c3 };
assert(!lsm6dso_init(&imu, &hi2c3)); /* This is always connected */
assert(!lsm6dso_init(&imu, imu_read_reg,
imu_write_reg)); /* This is always connected */
#endif

#ifdef SENSOR_TOF
Expand Down
15 changes: 14 additions & 1 deletion Core/Src/stm32f4xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,24 @@ void NMI_Handler(void)
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */

/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
// this is an ISR where the MCU doesnt have an intact stack frame or peripherals, so its ok to f around
// no sleep exists in an ISR, for good reason
volatile uint32_t i = 0;
while (i < 120000) {
i += 1;
}
HAL_GPIO_WritePin(Debug_LED_1_GPIO_Port, Debug_LED_1_Pin, 0);
HAL_GPIO_WritePin(Debug_LED_2_GPIO_Port, Debug_LED_2_Pin, 0);
i = 0;
while (i < 120000) {
i += 1;
}
HAL_GPIO_WritePin(Debug_LED_1_GPIO_Port, Debug_LED_1_Pin, 1);
HAL_GPIO_WritePin(Debug_LED_2_GPIO_Port, Debug_LED_2_Pin, 1);
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Embedded-Base

0 comments on commit 1d8a8f6

Please sign in to comment.