sd card logging working
This commit is contained in:
@@ -64,6 +64,11 @@ struct packet_spo2 {
|
||||
uint32_t ir_cnts[25];
|
||||
};
|
||||
|
||||
struct packet_msg {
|
||||
uint32_t t;
|
||||
char buff[32];
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
__inline__ uint8_t typecode() {
|
||||
return 0;
|
||||
@@ -113,3 +118,8 @@ template<>
|
||||
__inline__ uint8_t typecode<struct packet_imu>() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
template<>
|
||||
__inline__ uint8_t typecode<struct packet_msg>() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,6 @@ void USART1_IRQHandler(void);
|
||||
void SDMMC1_IRQHandler(void);
|
||||
void TIM6_DAC_IRQHandler(void);
|
||||
void DMA2_Channel4_IRQHandler(void);
|
||||
void DMA2_Channel5_IRQHandler(void);
|
||||
void USB_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//#include "buff.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
uint8_t databank1[1024];
|
||||
uint8_t databank2[1024];
|
||||
alignas(32) uint8_t databank1[1024];
|
||||
alignas(32) uint8_t databank2[1024];
|
||||
uint16_t pos = 0;
|
||||
|
||||
@@ -56,4 +56,9 @@ void data_description(bool to_usb, bool to_file) {
|
||||
if (to_usb) {CDC_Transmit_FS((uint8_t*)buff, cx);}
|
||||
HAL_Delay(50);
|
||||
|
||||
cx = snprintf(buff, sizeof(buff), "%s %d %d %s %d %d %s %d %d\n\r", "packet_msg", typecode<packet_msg>(), sizeof(packet_msg), "uint32_t t", offsetof(packet_msg, t), sizeof(uint32_t), "char buff[32]", offsetof(packet_msg, buff), sizeof(char));
|
||||
if (to_file) {unsigned int bw; f_write(&file, buff, cx, &bw);}
|
||||
if (to_usb) {CDC_Transmit_FS((uint8_t*)buff, cx);}
|
||||
HAL_Delay(50);
|
||||
|
||||
}
|
||||
|
||||
@@ -53,9 +53,6 @@ void MX_DMA_Init(void)
|
||||
/* DMA2_Channel4_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA2_Channel4_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA2_Channel4_IRQn);
|
||||
/* DMA2_Channel5_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA2_Channel5_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA2_Channel5_IRQn);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,6 @@ void USB_CDC_RxHandler(uint8_t* Buf, uint32_t Len) {
|
||||
|
||||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
if (uart_rx_data[0] == 'R') {
|
||||
//HAL_GPIO_TogglePin(GPIOB, LED1_Pin | LED2_Pin | LED3_Pin);
|
||||
wb1mmc_ready = true;
|
||||
}
|
||||
HAL_UART_Receive_DMA(&huart1, uart_rx_data, sizeof(uart_rx_data));
|
||||
@@ -136,37 +135,28 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {}
|
||||
void turn_on_sd(void) {
|
||||
to_turn_on_sd = false;
|
||||
if (BSP_SD_IsDetected() != SD_PRESENT) {
|
||||
CDC_Transmit_FS((uint8_t*)"SD NP\n\r", 7);
|
||||
return;
|
||||
}
|
||||
if (sd_ready) {
|
||||
CDC_Transmit_FS((uint8_t*)"SD RD\n\r", 7);
|
||||
return;
|
||||
}
|
||||
if ((BSP_SD_IsDetected() == SD_PRESENT) && (!sd_ready)) {
|
||||
CDC_Transmit_FS((uint8_t*)"HERE1\n\r", 7);
|
||||
res = f_mount(&fs, "", 1);
|
||||
if (res != FR_OK) {
|
||||
CDC_Transmit_FS((uint8_t*)"SD NOK1\n\r", 9);
|
||||
return;
|
||||
}
|
||||
CDC_Transmit_FS((uint8_t*)"HERE2\n\r", 7);
|
||||
alignas(32) char buffer1[32];
|
||||
alignas(32) char buffer2[32];
|
||||
int cx = snprintf(buffer1, 32, "%06lu.log", TIM6->CNT);
|
||||
int cx = snprintf(buffer1, 32, "%08lu.log", ((uint32_t)tim6_reloads) * (htim6.Init.Period + 1) + TIM6->CNT % 99999999);
|
||||
cx = snprintf(buffer2, 32, "%s\n\r", buffer1);
|
||||
CDC_Transmit_FS((uint8_t*)buffer2, cx);
|
||||
res = f_open(&file, buffer1, FA_WRITE | FA_CREATE_ALWAYS);
|
||||
if (res != FR_OK) {
|
||||
CDC_Transmit_FS((uint8_t*)"SD NOK2\n\r", 9);
|
||||
res = f_mount(NULL, "", 1);
|
||||
return;
|
||||
}
|
||||
CDC_Transmit_FS((uint8_t*)"SUCCESS\n\r", 9);
|
||||
unsigned int bw;
|
||||
res = f_write(&file, "HERE\n\r", 6, &bw);
|
||||
cx = snprintf(buffer2, 32, "%d %d\n\r", res, bw);
|
||||
CDC_Transmit_FS((uint8_t*)buffer2, cx);
|
||||
//data_description(false, true);
|
||||
data_description(false, true);
|
||||
sd_ready = true;
|
||||
}
|
||||
}
|
||||
@@ -217,7 +207,6 @@ int main(void)
|
||||
MX_GPIO_Init();
|
||||
MX_DMA_Init();
|
||||
MX_SDMMC1_SD_Init();
|
||||
MX_FATFS_Init();
|
||||
MX_RTC_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_SPI1_Init();
|
||||
@@ -226,17 +215,21 @@ int main(void)
|
||||
MX_USART1_UART_Init();
|
||||
MX_TIM6_Init();
|
||||
MX_USB_DEVICE_Init();
|
||||
MX_FATFS_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
HAL_TIM_Base_Start_IT(&htim6);
|
||||
HAL_UART_Receive_DMA(&huart1, uart_rx_data, sizeof(uart_rx_data));
|
||||
//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);
|
||||
HAL_Delay(3000);
|
||||
|
||||
uint8_t buf[512];
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (to_turn_on_sd) {
|
||||
|
||||
@@ -25,8 +25,7 @@
|
||||
/* USER CODE END 0 */
|
||||
|
||||
SD_HandleTypeDef hsd1;
|
||||
DMA_HandleTypeDef hdma_sdmmc1_rx;
|
||||
DMA_HandleTypeDef hdma_sdmmc1_tx;
|
||||
DMA_HandleTypeDef hdma_sdmmc1;
|
||||
|
||||
/* SDMMC1 init function */
|
||||
|
||||
@@ -46,7 +45,7 @@ void MX_SDMMC1_SD_Init(void)
|
||||
hsd1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
|
||||
hsd1.Init.BusWide = SDMMC_BUS_WIDE_4B;
|
||||
hsd1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
|
||||
hsd1.Init.ClockDiv = 0;
|
||||
hsd1.Init.ClockDiv = 6;
|
||||
/* USER CODE BEGIN SDMMC1_Init 2 */
|
||||
|
||||
/* USER CODE END SDMMC1_Init 2 */
|
||||
@@ -91,39 +90,27 @@ void HAL_SD_MspInit(SD_HandleTypeDef* sdHandle)
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
/* SDMMC1 DMA Init */
|
||||
/* SDMMC1_RX Init */
|
||||
hdma_sdmmc1_rx.Instance = DMA2_Channel4;
|
||||
hdma_sdmmc1_rx.Init.Request = DMA_REQUEST_7;
|
||||
hdma_sdmmc1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
||||
hdma_sdmmc1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_sdmmc1_rx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_sdmmc1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
|
||||
hdma_sdmmc1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
|
||||
hdma_sdmmc1_rx.Init.Mode = DMA_NORMAL;
|
||||
hdma_sdmmc1_rx.Init.Priority = DMA_PRIORITY_LOW;
|
||||
if (HAL_DMA_Init(&hdma_sdmmc1_rx) != HAL_OK)
|
||||
/* SDMMC1 Init */
|
||||
hdma_sdmmc1.Instance = DMA2_Channel4;
|
||||
hdma_sdmmc1.Init.Request = DMA_REQUEST_7;
|
||||
hdma_sdmmc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
||||
hdma_sdmmc1.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_sdmmc1.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_sdmmc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
|
||||
hdma_sdmmc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
|
||||
hdma_sdmmc1.Init.Mode = DMA_NORMAL;
|
||||
hdma_sdmmc1.Init.Priority = DMA_PRIORITY_LOW;
|
||||
if (HAL_DMA_Init(&hdma_sdmmc1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
__HAL_LINKDMA(sdHandle,hdmarx,hdma_sdmmc1_rx);
|
||||
|
||||
/* SDMMC1_TX Init */
|
||||
hdma_sdmmc1_tx.Instance = DMA2_Channel5;
|
||||
hdma_sdmmc1_tx.Init.Request = DMA_REQUEST_7;
|
||||
hdma_sdmmc1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||||
hdma_sdmmc1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_sdmmc1_tx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_sdmmc1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
|
||||
hdma_sdmmc1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
|
||||
hdma_sdmmc1_tx.Init.Mode = DMA_NORMAL;
|
||||
hdma_sdmmc1_tx.Init.Priority = DMA_PRIORITY_LOW;
|
||||
if (HAL_DMA_Init(&hdma_sdmmc1_tx) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
__HAL_LINKDMA(sdHandle,hdmatx,hdma_sdmmc1_tx);
|
||||
/* Several peripheral DMA handle pointers point to the same DMA handle.
|
||||
Be aware that there is only one channel to perform all the requested DMAs. */
|
||||
/* Be sure to change transfer direction before calling
|
||||
HAL_SD_ReadBlocks_DMA or HAL_SD_WriteBlocks_DMA. */
|
||||
__HAL_LINKDMA(sdHandle,hdmarx,hdma_sdmmc1);
|
||||
__HAL_LINKDMA(sdHandle,hdmatx,hdma_sdmmc1);
|
||||
|
||||
/* SDMMC1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(SDMMC1_IRQn, 0, 0);
|
||||
|
||||
@@ -58,8 +58,7 @@
|
||||
extern PCD_HandleTypeDef hpcd_USB_FS;
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
extern I2C_HandleTypeDef hi2c1;
|
||||
extern DMA_HandleTypeDef hdma_sdmmc1_rx;
|
||||
extern DMA_HandleTypeDef hdma_sdmmc1_tx;
|
||||
extern DMA_HandleTypeDef hdma_sdmmc1;
|
||||
extern SD_HandleTypeDef hsd1;
|
||||
extern SPI_HandleTypeDef hspi1;
|
||||
extern TIM_HandleTypeDef htim6;
|
||||
@@ -371,26 +370,12 @@ void DMA2_Channel4_IRQHandler(void)
|
||||
/* USER CODE BEGIN DMA2_Channel4_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA2_Channel4_IRQn 0 */
|
||||
HAL_DMA_IRQHandler(&hdma_sdmmc1_rx);
|
||||
HAL_DMA_IRQHandler(&hdma_sdmmc1);
|
||||
/* USER CODE BEGIN DMA2_Channel4_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA2_Channel4_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA2 channel5 global interrupt.
|
||||
*/
|
||||
void DMA2_Channel5_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DMA2_Channel5_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA2_Channel5_IRQn 0 */
|
||||
HAL_DMA_IRQHandler(&hdma_sdmmc1_tx);
|
||||
/* USER CODE BEGIN DMA2_Channel5_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA2_Channel5_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USB event interrupt through EXTI line 17.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user