fixed sd_logger

This commit is contained in:
2024-05-21 22:51:32 +02:00
parent bd8779b5aa
commit c3322ed571
6 changed files with 87 additions and 6 deletions

View File

@@ -10,7 +10,7 @@
#include "cmsis_os2.h"
#include "BSP_GPIO.h"
#include "BSP_ADC.h"
#include "BSP_SDLogger.h"
#define LPTIM_CLK 500 // Hz
#define SLEEP_TICK_TIME 1 // seconds to wait
#define STAY_AWAKE_TIME 60 // seconds to stay awake without K15
@@ -52,6 +52,8 @@ void BSP_POWER_WakeUp() {
*/
void BSP_POWER_EnterStandby() {
BSP_SDLogger_Flush();
// stop the sytem interrupts
__disable_irq();

View File

@@ -4,7 +4,7 @@
#include "stdio.h"
#include "string.h"
uint8_t block_buffer[512] = {0};
uint8_t block_buffer[2048] = {0};
size_t block_buffer_index = 0;
char file_name[20];
@@ -41,7 +41,7 @@ void BSP_SDLogger_Flush() {
// open the file
FIL file;
FRESULT res = f_open(&file, file_name, FA_WRITE);
FRESULT res = f_open(&file, file_name, FA_OPEN_APPEND | FA_WRITE );
if (res != FR_OK) {
ULOG_ERROR("Failed to open file %s", file_name);
}
@@ -75,6 +75,7 @@ void BSP_SDLogger_Write(char *data, size_t length) {
if (length > remaining_size) {
// write the remaining space to the buffer
memcpy(&block_buffer[block_buffer_index], data, remaining_size);
block_buffer_index += remaining_size;
// write the buffer to the file
BSP_SDLogger_Flush();
// write the remaining data to the buffer

View File

@@ -9,4 +9,6 @@
void BSP_SDLogger_Init(int log_number);
void BSP_SDLogger_Write(char *data, size_t length);
void BSP_SDLogger_Write(char *data, size_t length);
void BSP_SDLogger_Flush();