l452 usart working
This commit is contained in:
+40
-38
File diff suppressed because one or more lines are too long
@@ -0,0 +1,52 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file dma.h
|
||||||
|
* @brief This file contains all the function prototypes for
|
||||||
|
* the dma.c file
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __DMA_H__
|
||||||
|
#define __DMA_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
/* DMA memory to memory transfer handles -------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Includes */
|
||||||
|
|
||||||
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Private defines */
|
||||||
|
|
||||||
|
/* USER CODE END Private defines */
|
||||||
|
|
||||||
|
void MX_DMA_Init(void);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN Prototypes */
|
||||||
|
|
||||||
|
/* USER CODE END Prototypes */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __DMA_H__ */
|
||||||
|
|
||||||
@@ -57,10 +57,13 @@ void PendSV_Handler(void);
|
|||||||
void SysTick_Handler(void);
|
void SysTick_Handler(void);
|
||||||
void EXTI0_IRQHandler(void);
|
void EXTI0_IRQHandler(void);
|
||||||
void EXTI3_IRQHandler(void);
|
void EXTI3_IRQHandler(void);
|
||||||
|
void DMA1_Channel4_IRQHandler(void);
|
||||||
|
void DMA1_Channel5_IRQHandler(void);
|
||||||
void ADC1_IRQHandler(void);
|
void ADC1_IRQHandler(void);
|
||||||
void EXTI9_5_IRQHandler(void);
|
void EXTI9_5_IRQHandler(void);
|
||||||
void I2C1_EV_IRQHandler(void);
|
void I2C1_EV_IRQHandler(void);
|
||||||
void SPI1_IRQHandler(void);
|
void SPI1_IRQHandler(void);
|
||||||
|
void USART1_IRQHandler(void);
|
||||||
void SDMMC1_IRQHandler(void);
|
void SDMMC1_IRQHandler(void);
|
||||||
void TIM6_DAC_IRQHandler(void);
|
void TIM6_DAC_IRQHandler(void);
|
||||||
void USB_IRQHandler(void);
|
void USB_IRQHandler(void);
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/* USER CODE BEGIN Header */
|
||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file dma.c
|
||||||
|
* @brief This file provides code for the configuration
|
||||||
|
* of all the requested memory to memory DMA transfers.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
/* USER CODE END Header */
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "dma.h"
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* Configure DMA */
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable DMA controller clock
|
||||||
|
*/
|
||||||
|
void MX_DMA_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* DMA controller clock enable */
|
||||||
|
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||||
|
|
||||||
|
/* DMA interrupt init */
|
||||||
|
/* DMA1_Channel4_IRQn interrupt configuration */
|
||||||
|
HAL_NVIC_SetPriority(DMA1_Channel4_IRQn, 0, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(DMA1_Channel4_IRQn);
|
||||||
|
/* DMA1_Channel5_IRQn interrupt configuration */
|
||||||
|
HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
@@ -54,13 +54,11 @@ void initialize_lsm6dsv(SPI_HandleTypeDef *hspi1) {
|
|||||||
HAL_GPIO_WritePin(GPIOC, IMU_CS_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOC, IMU_CS_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
// todo: get watermark working
|
// todo: get watermark working
|
||||||
|
tx_buff[0] = 0x07;
|
||||||
// tx_buff[0] = 0x07; // Set the watermark to 10
|
tx_buff[1] = 0x07;
|
||||||
// tx_buff[1] = 100;
|
HAL_GPIO_WritePin(GPIOC, IMU_CS_Pin, GPIO_PIN_RESET);
|
||||||
// HAL_GPIO_WritePin(GPIOC, IMU_CS_Pin, GPIO_PIN_RESET);
|
HAL_SPI_TransmitReceive(hspi1, tx_buff, rx_buff, 2, HAL_MAX_DELAY);
|
||||||
// HAL_SPI_TransmitReceive(hspi1, tx_buff, rx_buff, 8, HAL_MAX_DELAY);
|
HAL_GPIO_WritePin(GPIOC, IMU_CS_Pin, GPIO_PIN_SET);
|
||||||
// HAL_GPIO_WritePin(GPIOC, IMU_CS_Pin, GPIO_PIN_SET);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct packet_imu p_imu;
|
struct packet_imu p_imu;
|
||||||
@@ -83,19 +81,11 @@ void read_lsm6dsv(SPI_HandleTypeDef *hspi1) {
|
|||||||
tx_buff[0] = 0b10000000 + 0x1B;
|
tx_buff[0] = 0b10000000 + 0x1B;
|
||||||
tx_buff[1] = 0;
|
tx_buff[1] = 0;
|
||||||
HAL_GPIO_WritePin(GPIOC, IMU_CS_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOC, IMU_CS_Pin, GPIO_PIN_RESET);
|
||||||
HAL_SPI_TransmitReceive(hspi1, tx_buff, rx_buff, 2, HAL_MAX_DELAY);
|
HAL_SPI_TransmitReceive(hspi1, tx_buff, rx_buff, 3, HAL_MAX_DELAY);
|
||||||
HAL_GPIO_WritePin(GPIOC, IMU_CS_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOC, IMU_CS_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
char buffer[64];
|
// todo: read in batches
|
||||||
int cx;
|
|
||||||
|
|
||||||
// todo: read in batches
|
|
||||||
|
|
||||||
if (rx_buff[1] != 0) {
|
if (rx_buff[1] != 0) {
|
||||||
// cx = snprintf(buffer, 64, "%02x %02x\n\r",
|
|
||||||
// rx_buff[0],
|
|
||||||
// rx_buff[1]);
|
|
||||||
// CDC_Transmit_FS((uint8_t*)buffer, cx);
|
|
||||||
tx_buff[0] = 0b10000000 + 0x78; // FIFO addr
|
tx_buff[0] = 0b10000000 + 0x78; // FIFO addr
|
||||||
tx_buff[1] = 0;
|
tx_buff[1] = 0;
|
||||||
HAL_GPIO_WritePin(GPIOC, IMU_CS_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOC, IMU_CS_Pin, GPIO_PIN_RESET);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
|
#include "dma.h"
|
||||||
#include "fatfs.h"
|
#include "fatfs.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "rtc.h"
|
#include "rtc.h"
|
||||||
@@ -79,8 +80,13 @@ volatile uint16_t adc_value = 0;
|
|||||||
volatile uint8_t adc_ready = 0;
|
volatile uint8_t adc_ready = 0;
|
||||||
volatile uint16_t tim6_reloads = 0;
|
volatile uint16_t tim6_reloads = 0;
|
||||||
volatile bool usb_ready = false;
|
volatile bool usb_ready = false;
|
||||||
|
volatile bool wb1mmc_ready = false;
|
||||||
volatile bool print_desc = false;
|
volatile bool print_desc = false;
|
||||||
|
|
||||||
|
volatile bool uart_rx_busy = false;
|
||||||
|
uint8_t uart_rx_data[1];
|
||||||
|
volatile bool queue_send = false;
|
||||||
|
|
||||||
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
|
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
|
||||||
if (hadc->Instance == ADC1) {
|
if (hadc->Instance == ADC1) {
|
||||||
adc_value = HAL_ADC_GetValue(hadc);
|
adc_value = HAL_ADC_GetValue(hadc);
|
||||||
@@ -88,11 +94,13 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 80MHz clock, 39999 prescaler and 19999 period for 0.1Hz
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||||
if (htim->Instance == TIM6) {
|
if (htim->Instance == TIM6) {
|
||||||
tim6_reloads += 1;
|
tim6_reloads += 1;
|
||||||
to_recordVbatt = true;
|
to_recordVbatt = true;
|
||||||
to_recordTime = true;
|
to_recordTime = true;
|
||||||
|
queue_send = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,14 +111,16 @@ void USB_CDC_RxHandler(uint8_t* Buf, uint32_t Len) {
|
|||||||
if (memcmp(Buf, "?", Len) == 0) {
|
if (memcmp(Buf, "?", Len) == 0) {
|
||||||
print_desc = true;
|
print_desc = true;
|
||||||
}
|
}
|
||||||
//if (Len == 1) {
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
// use with stty -F /dev/ttyACM1 raw -echo
|
|
||||||
//char buffer[100];
|
|
||||||
//int i = snprintf(buffer, sizeof(buffer), "Length: %d\n\r", Len);
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
|
||||||
|
if (uart_rx_data[0] == 'R') {
|
||||||
|
HAL_GPIO_TogglePin(GPIOB, LED1_Pin | LED2_Pin | LED3_Pin);
|
||||||
|
}
|
||||||
|
HAL_UART_Receive_DMA(&huart1, uart_rx_data, sizeof(uart_rx_data));
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {}
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,6 +155,7 @@ int main(void)
|
|||||||
|
|
||||||
/* Initialize all configured peripherals */
|
/* Initialize all configured peripherals */
|
||||||
MX_GPIO_Init();
|
MX_GPIO_Init();
|
||||||
|
MX_DMA_Init();
|
||||||
MX_SDMMC1_SD_Init();
|
MX_SDMMC1_SD_Init();
|
||||||
MX_FATFS_Init();
|
MX_FATFS_Init();
|
||||||
MX_RTC_Init();
|
MX_RTC_Init();
|
||||||
@@ -161,10 +172,11 @@ int main(void)
|
|||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
/* USER CODE BEGIN WHILE */
|
/* USER CODE BEGIN WHILE */
|
||||||
HAL_TIM_Base_Start_IT(&htim6);
|
HAL_TIM_Base_Start_IT(&htim6);
|
||||||
|
HAL_UART_Receive_DMA(&huart1, uart_rx_data, sizeof(uart_rx_data));
|
||||||
|
// For some reason initializing the ads131 first breaks the lsm6dsv gyro readings
|
||||||
|
//initialize_lsm6dsv(&hspi1);
|
||||||
//initialize_ads131(&hspi1);
|
//initialize_ads131(&hspi1);
|
||||||
initialize_lsm6dsv(&hspi1);
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
/* USER CODE END WHILE */
|
/* USER CODE END WHILE */
|
||||||
@@ -205,6 +217,13 @@ int main(void)
|
|||||||
// CDC_Transmit_FS((uint8_t*) "Not Detected\n\r", 14);
|
// CDC_Transmit_FS((uint8_t*) "Not Detected\n\r", 14);
|
||||||
// HAL_Delay(10);
|
// HAL_Delay(10);
|
||||||
// }
|
// }
|
||||||
|
uint8_t uart_tx_data[1] = {'T'};
|
||||||
|
if (queue_send) {
|
||||||
|
HAL_UART_Transmit_DMA(&huart1, (uint8_t*)uart_tx_data, sizeof(uart_tx_data));
|
||||||
|
queue_send = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
|
||||||
if (print_desc) {
|
if (print_desc) {
|
||||||
data_description();
|
data_description();
|
||||||
@@ -237,24 +256,6 @@ int main(void)
|
|||||||
read_ads131(&hspi1);
|
read_ads131(&hspi1);
|
||||||
read_lsm6dsv(&hspi1);
|
read_lsm6dsv(&hspi1);
|
||||||
|
|
||||||
// char buffer[32];
|
|
||||||
// int cx;
|
|
||||||
// for (int i = 0; i < 39; ++i) {
|
|
||||||
// if (i == 38) {
|
|
||||||
// cx = snprintf(buffer, 32, "%02x\n\r", rxbuff[i]);
|
|
||||||
// CDC_Transmit_FS((uint8_t*)buffer, cx);
|
|
||||||
// HAL_Delay(10);
|
|
||||||
// } else if (i % 3 == 2) {
|
|
||||||
// cx = snprintf(buffer, 32, " ", rxbuff[i]);
|
|
||||||
// CDC_Transmit_FS((uint8_t*)buffer, cx);
|
|
||||||
// HAL_Delay(10);
|
|
||||||
// } else {
|
|
||||||
// cx = snprintf(buffer, 32, "%02x ", rxbuff[i]);
|
|
||||||
// CDC_Transmit_FS((uint8_t*)buffer, cx);
|
|
||||||
// HAL_Delay(10);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// HAL_GPIO_WritePin(GPIOB, LED1_Pin|LED2_Pin|LED3_Pin, GPIO_PIN_SET);
|
// HAL_GPIO_WritePin(GPIOB, LED1_Pin|LED2_Pin|LED3_Pin, GPIO_PIN_SET);
|
||||||
// HAL_Delay(100);
|
// HAL_Delay(100);
|
||||||
// HAL_GPIO_WritePin(GPIOB, LED1_Pin|LED2_Pin|LED3_Pin, GPIO_PIN_RESET);
|
// HAL_GPIO_WritePin(GPIOB, LED1_Pin|LED2_Pin|LED3_Pin, GPIO_PIN_RESET);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ void MX_SPI1_Init(void)
|
|||||||
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||||
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
|
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
|
||||||
hspi1.Init.NSS = SPI_NSS_SOFT;
|
hspi1.Init.NSS = SPI_NSS_SOFT;
|
||||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
|
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
|
||||||
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||||
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||||
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ extern I2C_HandleTypeDef hi2c1;
|
|||||||
extern SD_HandleTypeDef hsd1;
|
extern SD_HandleTypeDef hsd1;
|
||||||
extern SPI_HandleTypeDef hspi1;
|
extern SPI_HandleTypeDef hspi1;
|
||||||
extern TIM_HandleTypeDef htim6;
|
extern TIM_HandleTypeDef htim6;
|
||||||
|
extern DMA_HandleTypeDef hdma_usart1_rx;
|
||||||
|
extern DMA_HandleTypeDef hdma_usart1_tx;
|
||||||
|
extern UART_HandleTypeDef huart1;
|
||||||
/* USER CODE BEGIN EV */
|
/* USER CODE BEGIN EV */
|
||||||
|
|
||||||
/* USER CODE END EV */
|
/* USER CODE END EV */
|
||||||
@@ -231,6 +234,34 @@ void EXTI3_IRQHandler(void)
|
|||||||
/* USER CODE END EXTI3_IRQn 1 */
|
/* USER CODE END EXTI3_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles DMA1 channel4 global interrupt.
|
||||||
|
*/
|
||||||
|
void DMA1_Channel4_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN DMA1_Channel4_IRQn 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA1_Channel4_IRQn 0 */
|
||||||
|
HAL_DMA_IRQHandler(&hdma_usart1_tx);
|
||||||
|
/* USER CODE BEGIN DMA1_Channel4_IRQn 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA1_Channel4_IRQn 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles DMA1 channel5 global interrupt.
|
||||||
|
*/
|
||||||
|
void DMA1_Channel5_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN DMA1_Channel5_IRQn 0 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA1_Channel5_IRQn 0 */
|
||||||
|
HAL_DMA_IRQHandler(&hdma_usart1_rx);
|
||||||
|
/* USER CODE BEGIN DMA1_Channel5_IRQn 1 */
|
||||||
|
|
||||||
|
/* USER CODE END DMA1_Channel5_IRQn 1 */
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function handles ADC1 global interrupt.
|
* @brief This function handles ADC1 global interrupt.
|
||||||
*/
|
*/
|
||||||
@@ -288,6 +319,20 @@ void SPI1_IRQHandler(void)
|
|||||||
/* USER CODE END SPI1_IRQn 1 */
|
/* USER CODE END SPI1_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles USART1 global interrupt.
|
||||||
|
*/
|
||||||
|
void USART1_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN USART1_IRQn 0 */
|
||||||
|
|
||||||
|
/* USER CODE END USART1_IRQn 0 */
|
||||||
|
HAL_UART_IRQHandler(&huart1);
|
||||||
|
/* USER CODE BEGIN USART1_IRQn 1 */
|
||||||
|
|
||||||
|
/* USER CODE END USART1_IRQn 1 */
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function handles SDMMC1 global interrupt.
|
* @brief This function handles SDMMC1 global interrupt.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ void MX_TIM6_Init(void)
|
|||||||
htim6.Instance = TIM6;
|
htim6.Instance = TIM6;
|
||||||
htim6.Init.Prescaler = 39999;
|
htim6.Init.Prescaler = 39999;
|
||||||
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
|
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
htim6.Init.Period = 19999;
|
htim6.Init.Period = 1999;
|
||||||
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
||||||
if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
|
if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
UART_HandleTypeDef huart1;
|
UART_HandleTypeDef huart1;
|
||||||
|
DMA_HandleTypeDef hdma_usart1_rx;
|
||||||
|
DMA_HandleTypeDef hdma_usart1_tx;
|
||||||
|
|
||||||
/* USART1 init function */
|
/* USART1 init function */
|
||||||
|
|
||||||
@@ -93,6 +95,44 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
|||||||
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
|
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
|
||||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* USART1 DMA Init */
|
||||||
|
/* USART1_RX Init */
|
||||||
|
hdma_usart1_rx.Instance = DMA1_Channel5;
|
||||||
|
hdma_usart1_rx.Init.Request = DMA_REQUEST_2;
|
||||||
|
hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
||||||
|
hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||||
|
hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
|
||||||
|
hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||||
|
hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||||
|
hdma_usart1_rx.Init.Mode = DMA_NORMAL;
|
||||||
|
hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW;
|
||||||
|
if (HAL_DMA_Init(&hdma_usart1_rx) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
__HAL_LINKDMA(uartHandle,hdmarx,hdma_usart1_rx);
|
||||||
|
|
||||||
|
/* USART1_TX Init */
|
||||||
|
hdma_usart1_tx.Instance = DMA1_Channel4;
|
||||||
|
hdma_usart1_tx.Init.Request = DMA_REQUEST_2;
|
||||||
|
hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||||||
|
hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||||
|
hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE;
|
||||||
|
hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||||
|
hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||||
|
hdma_usart1_tx.Init.Mode = DMA_NORMAL;
|
||||||
|
hdma_usart1_tx.Init.Priority = DMA_PRIORITY_LOW;
|
||||||
|
if (HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
__HAL_LINKDMA(uartHandle,hdmatx,hdma_usart1_tx);
|
||||||
|
|
||||||
|
/* USART1 interrupt Init */
|
||||||
|
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(USART1_IRQn);
|
||||||
/* USER CODE BEGIN USART1_MspInit 1 */
|
/* USER CODE BEGIN USART1_MspInit 1 */
|
||||||
|
|
||||||
/* USER CODE END USART1_MspInit 1 */
|
/* USER CODE END USART1_MspInit 1 */
|
||||||
@@ -116,6 +156,12 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
|
|||||||
*/
|
*/
|
||||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
|
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
|
||||||
|
|
||||||
|
/* USART1 DMA DeInit */
|
||||||
|
HAL_DMA_DeInit(uartHandle->hdmarx);
|
||||||
|
HAL_DMA_DeInit(uartHandle->hdmatx);
|
||||||
|
|
||||||
|
/* USART1 interrupt Deinit */
|
||||||
|
HAL_NVIC_DisableIRQ(USART1_IRQn);
|
||||||
/* USER CODE BEGIN USART1_MspDeInit 1 */
|
/* USER CODE BEGIN USART1_MspDeInit 1 */
|
||||||
|
|
||||||
/* USER CODE END USART1_MspDeInit 1 */
|
/* USER CODE END USART1_MspDeInit 1 */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
##########################################################################################################################
|
##########################################################################################################################
|
||||||
# File automatically-generated by tool: [projectgenerator] version: [4.9.0-B19] date: [Tue Apr 28 17:15:25 CDT 2026]
|
# File automatically-generated by tool: [projectgenerator] version: [4.9.0-B19] date: [Wed Apr 29 16:32:32 CDT 2026]
|
||||||
##########################################################################################################################
|
##########################################################################################################################
|
||||||
|
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
|
|||||||
@@ -10,6 +10,27 @@ ADC1.master=1
|
|||||||
CAD.formats=
|
CAD.formats=
|
||||||
CAD.pinconfig=
|
CAD.pinconfig=
|
||||||
CAD.provider=
|
CAD.provider=
|
||||||
|
Dma.Request0=USART1_RX
|
||||||
|
Dma.Request1=USART1_TX
|
||||||
|
Dma.RequestsNb=2
|
||||||
|
Dma.USART1_RX.0.Direction=DMA_PERIPH_TO_MEMORY
|
||||||
|
Dma.USART1_RX.0.Instance=DMA1_Channel5
|
||||||
|
Dma.USART1_RX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE
|
||||||
|
Dma.USART1_RX.0.MemInc=DMA_MINC_ENABLE
|
||||||
|
Dma.USART1_RX.0.Mode=DMA_NORMAL
|
||||||
|
Dma.USART1_RX.0.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
|
||||||
|
Dma.USART1_RX.0.PeriphInc=DMA_PINC_DISABLE
|
||||||
|
Dma.USART1_RX.0.Priority=DMA_PRIORITY_LOW
|
||||||
|
Dma.USART1_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
|
||||||
|
Dma.USART1_TX.1.Direction=DMA_MEMORY_TO_PERIPH
|
||||||
|
Dma.USART1_TX.1.Instance=DMA1_Channel4
|
||||||
|
Dma.USART1_TX.1.MemDataAlignment=DMA_MDATAALIGN_BYTE
|
||||||
|
Dma.USART1_TX.1.MemInc=DMA_MINC_ENABLE
|
||||||
|
Dma.USART1_TX.1.Mode=DMA_NORMAL
|
||||||
|
Dma.USART1_TX.1.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
|
||||||
|
Dma.USART1_TX.1.PeriphInc=DMA_PINC_DISABLE
|
||||||
|
Dma.USART1_TX.1.Priority=DMA_PRIORITY_LOW
|
||||||
|
Dma.USART1_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
|
||||||
FATFS.BSP.number=1
|
FATFS.BSP.number=1
|
||||||
FATFS0.BSP.STBoard=false
|
FATFS0.BSP.STBoard=false
|
||||||
FATFS0.BSP.api=Unknown
|
FATFS0.BSP.api=Unknown
|
||||||
@@ -29,20 +50,21 @@ KeepUserPlacement=false
|
|||||||
Mcu.CPN=STM32L452RET3
|
Mcu.CPN=STM32L452RET3
|
||||||
Mcu.Family=STM32L4
|
Mcu.Family=STM32L4
|
||||||
Mcu.IP0=ADC1
|
Mcu.IP0=ADC1
|
||||||
Mcu.IP1=FATFS
|
Mcu.IP1=DMA
|
||||||
Mcu.IP10=TIM6
|
Mcu.IP10=TIM2
|
||||||
Mcu.IP11=USART1
|
Mcu.IP11=TIM6
|
||||||
Mcu.IP12=USB
|
Mcu.IP12=USART1
|
||||||
Mcu.IP13=USB_DEVICE
|
Mcu.IP13=USB
|
||||||
Mcu.IP2=I2C1
|
Mcu.IP14=USB_DEVICE
|
||||||
Mcu.IP3=NVIC
|
Mcu.IP2=FATFS
|
||||||
Mcu.IP4=RCC
|
Mcu.IP3=I2C1
|
||||||
Mcu.IP5=RTC
|
Mcu.IP4=NVIC
|
||||||
Mcu.IP6=SDMMC1
|
Mcu.IP5=RCC
|
||||||
Mcu.IP7=SPI1
|
Mcu.IP6=RTC
|
||||||
Mcu.IP8=SYS
|
Mcu.IP7=SDMMC1
|
||||||
Mcu.IP9=TIM2
|
Mcu.IP8=SPI1
|
||||||
Mcu.IPNb=14
|
Mcu.IP9=SYS
|
||||||
|
Mcu.IPNb=15
|
||||||
Mcu.Name=STM32L452R(C-E)Tx
|
Mcu.Name=STM32L452R(C-E)Tx
|
||||||
Mcu.Package=LQFP64
|
Mcu.Package=LQFP64
|
||||||
Mcu.Pin0=PC3
|
Mcu.Pin0=PC3
|
||||||
@@ -90,6 +112,8 @@ MxCube.Version=6.17.0
|
|||||||
MxDb.Version=DB.6.0.170
|
MxDb.Version=DB.6.0.170
|
||||||
NVIC.ADC1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
NVIC.ADC1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||||
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
|
NVIC.DMA1_Channel4_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
|
||||||
|
NVIC.DMA1_Channel5_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
|
||||||
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.EXTI0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
NVIC.EXTI0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||||
NVIC.EXTI3_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
NVIC.EXTI3_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||||
@@ -106,6 +130,7 @@ NVIC.SPI1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
|||||||
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
|
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
|
||||||
NVIC.TIM6_DAC_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
NVIC.TIM6_DAC_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||||
|
NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||||
NVIC.USB_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
|
NVIC.USB_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
|
||||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
PA0.GPIOParameters=GPIO_Label
|
PA0.GPIOParameters=GPIO_Label
|
||||||
@@ -236,7 +261,7 @@ ProjectManager.ToolChainLocation=
|
|||||||
ProjectManager.UAScriptAfterPath=
|
ProjectManager.UAScriptAfterPath=
|
||||||
ProjectManager.UAScriptBeforePath=
|
ProjectManager.UAScriptBeforePath=
|
||||||
ProjectManager.UnderRoot=false
|
ProjectManager.UnderRoot=false
|
||||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_SDMMC1_SD_Init-SDMMC1-false-HAL-true,4-MX_FATFS_Init-FATFS-false-HAL-false,5-MX_RTC_Init-RTC-false-HAL-true,6-MX_I2C1_Init-I2C1-false-HAL-true,7-MX_SPI1_Init-SPI1-false-HAL-true,8-MX_ADC1_Init-ADC1-false-HAL-true,9-MX_TIM2_Init-TIM2-false-HAL-true,10-MX_USART1_UART_Init-USART1-false-HAL-true,11-MX_TIM6_Init-TIM6-false-HAL-true,12-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false
|
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_SDMMC1_SD_Init-SDMMC1-false-HAL-true,5-MX_FATFS_Init-FATFS-false-HAL-false,6-MX_RTC_Init-RTC-false-HAL-true,7-MX_I2C1_Init-I2C1-false-HAL-true,8-MX_SPI1_Init-SPI1-false-HAL-true,9-MX_ADC1_Init-ADC1-false-HAL-true,10-MX_TIM2_Init-TIM2-false-HAL-true,11-MX_USART1_UART_Init-USART1-false-HAL-true,12-MX_TIM6_Init-TIM6-false-HAL-true,13-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false
|
||||||
RCC.ADCFreq_Value=48000000
|
RCC.ADCFreq_Value=48000000
|
||||||
RCC.AHBFreq_Value=80000000
|
RCC.AHBFreq_Value=80000000
|
||||||
RCC.APB1Freq_Value=80000000
|
RCC.APB1Freq_Value=80000000
|
||||||
@@ -308,9 +333,11 @@ SPI1.Mode=SPI_MODE_MASTER
|
|||||||
SPI1.VirtualType=VM_MASTER
|
SPI1.VirtualType=VM_MASTER
|
||||||
TIM6.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
|
TIM6.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
|
||||||
TIM6.IPParameters=Prescaler,AutoReloadPreload,Period
|
TIM6.IPParameters=Prescaler,AutoReloadPreload,Period
|
||||||
TIM6.Period=19999
|
TIM6.Period=1999
|
||||||
TIM6.Prescaler=39999
|
TIM6.Prescaler=39999
|
||||||
USART1.IPParameters=VirtualMode-Asynchronous
|
USART1.DMADisableonRxErrorParam=ADVFEATURE_DMA_ENABLEONRXERROR
|
||||||
|
USART1.IPParameters=VirtualMode-Asynchronous,OverrunDisableParam,DMADisableonRxErrorParam
|
||||||
|
USART1.OverrunDisableParam=ADVFEATURE_OVERRUN_ENABLE
|
||||||
USART1.VirtualMode-Asynchronous=VM_ASYNC
|
USART1.VirtualMode-Asynchronous=VM_ASYNC
|
||||||
USB.IPParameters=Sof_enable
|
USB.IPParameters=Sof_enable
|
||||||
USB.Sof_enable=ENABLE
|
USB.Sof_enable=ENABLE
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import serial
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from scipy import signal
|
from scipy import signal
|
||||||
|
import time
|
||||||
#should be running at 244Hz
|
|
||||||
|
|
||||||
fs = 244
|
fs = 244
|
||||||
b, a = signal.butter(
|
b, a = signal.butter(
|
||||||
@@ -46,13 +45,17 @@ for i in range(13):
|
|||||||
ser.flush()
|
ser.flush()
|
||||||
ser.timeout = 5
|
ser.timeout = 5
|
||||||
|
|
||||||
ys = []
|
adcs = []
|
||||||
|
accs = []
|
||||||
|
gyros = []
|
||||||
|
|
||||||
imu_readings = {}
|
fig, axs = plt.subplots(2,2)
|
||||||
|
then = time.time()
|
||||||
for i in range(1000):
|
for i in range(10):
|
||||||
ser.write(b'R')
|
ser.write(b'R')
|
||||||
data = ser.read(1024)
|
data = ser.read(1024)
|
||||||
|
continue
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
while (index < 1024):
|
while (index < 1024):
|
||||||
packet_type = (data[index + 1]<<8) + data[index]
|
packet_type = (data[index + 1]<<8) + data[index]
|
||||||
@@ -65,17 +68,23 @@ for i in range(1000):
|
|||||||
for e in t['elements']:
|
for e in t['elements']:
|
||||||
block = d[e['offset']:e['offset'] + e['size']]
|
block = d[e['offset']:e['offset'] + e['size']]
|
||||||
element_size = int(len(block) / e['n_elements'])
|
element_size = int(len(block) / e['n_elements'])
|
||||||
# if t['type_name'] == b'packet_ekg' and e['name'] == b'readings_cnts[50]':
|
if t['type_name'] == b'packet_ekg' and e['name'] == b'readings_cnts[50]':
|
||||||
# chunked = [(2.4 / (1<<24)) * int.from_bytes(block[i:i + element_size], byteorder='little', signed = True) for i in range(0, len(block), element_size)]
|
chunked = [(2.4 / (1<<24)) * int.from_bytes(block[i:i + element_size], byteorder='little', signed = True) for i in range(0, len(block), element_size)]
|
||||||
# #BB = [block[i:i + element_size] for i in range(0, len(block), element_size)]
|
adcs += chunked
|
||||||
# #if t['type_name'] == b'packet_ekg' and e['name'] == b'readings_cnts[50]':
|
axs[0][0].cla()
|
||||||
# ys += chunked
|
axs[0][1].cla()
|
||||||
# plt.clf()
|
axs[1][1].cla()
|
||||||
# dat = np.array(ys[-1000:])
|
dat = np.array(adcs[-1000:])
|
||||||
# plt.plot(dat, 'k.', linestyle = '--')#signal.filtfilt(b, a, dat))
|
axs[0][0].set_title("ADC")
|
||||||
# plt.pause(0.01)
|
axs[0][1].set_title("ACC")
|
||||||
# ##print(BB)
|
axs[1][1].set_title("GYRO")
|
||||||
# e['readings'].append(chunked)
|
axs[0][0].plot(dat, 'k.', linestyle = '--')#signal.filtfilt(b, a, dat))
|
||||||
|
axs[0][1].plot(accs[-30:], 'k.', linestyle = '--')#signal.filtfilt(b, a, dat))
|
||||||
|
axs[1][1].plot(gyros[-30:], 'k.', linestyle = '--')#signal.filtfilt(b, a, dat))
|
||||||
|
|
||||||
|
plt.pause(0.01)
|
||||||
|
##print(BB)
|
||||||
|
e['readings'].append(chunked)
|
||||||
if t['type_name'] == b'packet_imu' and e['name'] == b'readings_cnts[4]':
|
if t['type_name'] == b'packet_imu' and e['name'] == b'readings_cnts[4]':
|
||||||
imu_reading_type = block[0] >> 3
|
imu_reading_type = block[0] >> 3
|
||||||
imu_reading_tag_cnt = (block[0] >> 1) & 3 # tag count is sensor time slow
|
imu_reading_tag_cnt = (block[0] >> 1) & 3 # tag count is sensor time slow
|
||||||
@@ -84,9 +93,9 @@ for i in range(1000):
|
|||||||
int.from_bytes(block[6:8], byteorder = 'big', signed = True)]
|
int.from_bytes(block[6:8], byteorder = 'big', signed = True)]
|
||||||
if imu_reading_type == 1:
|
if imu_reading_type == 1:
|
||||||
#print("{:02x} {:d}".format(imu_reading_type, imu_reading_tag_cnt))
|
#print("{:02x} {:d}".format(imu_reading_type, imu_reading_tag_cnt))
|
||||||
print("Gyro: {:f} {:f} {:f}".format(*[250 * e / (1<<16) for e in reading_xyz]))
|
gyros.append([250 * e / (1<<16) for e in reading_xyz])
|
||||||
elif imu_reading_type == 2:
|
elif imu_reading_type == 2:
|
||||||
print("Acc: {:f} {:f} {:f}".format(*[4 * e / (1<<16) for e in reading_xyz]))
|
accs.append([4 * e / (1<<16) for e in reading_xyz])
|
||||||
else:
|
else:
|
||||||
print("ERR")
|
print("ERR")
|
||||||
#chunked = [int.from_bytes(block[i:i + element_size], byteorder='little', signed = True) for i in range(0, len(block), element_size)]
|
#chunked = [int.from_bytes(block[i:i + element_size], byteorder='little', signed = True) for i in range(0, len(block), element_size)]
|
||||||
@@ -99,3 +108,4 @@ for i in range(1000):
|
|||||||
# if t['type_name'] == b'packet_ekg':
|
# if t['type_name'] == b'packet_ekg':
|
||||||
# print(t)
|
# print(t)
|
||||||
|
|
||||||
|
print((time.time() - then) / 10)
|
||||||
|
|||||||
Reference in New Issue
Block a user