log fix (added f_extend), other changes
This commit is contained in:
@@ -59,7 +59,7 @@ struct dbl_buff {
|
||||
|
||||
extern struct dbl_buff<1024, usb_send> usb_buff;
|
||||
extern struct dbl_buff<1024, uart_send> ble_buff;
|
||||
extern struct dbl_buff<1024, sd_send> sd_buff;
|
||||
extern struct dbl_buff<4096, sd_send> sd_buff;
|
||||
|
||||
volatile extern bool send_imu_usb;
|
||||
volatile extern bool send_imu_ble;
|
||||
|
||||
@@ -31,7 +31,7 @@ void initialize_ads131(SPI_HandleTypeDef *hspi1) {
|
||||
cmd[2] = 0x00;
|
||||
|
||||
cmd[3] = 0b00001111;
|
||||
cmd[4] = 0b00011111;
|
||||
cmd[4] = 0b00011011;
|
||||
cmd[5] = 0x00;
|
||||
|
||||
HAL_GPIO_WritePin(GPIOA, ADC_CS_Pin, GPIO_PIN_RESET);
|
||||
@@ -67,6 +67,7 @@ void initialize_ads131(SPI_HandleTypeDef *hspi1) {
|
||||
|
||||
struct packet_adc p_adc;
|
||||
|
||||
// With 5MHz SPI ~30uS for transfer
|
||||
void read_ads131(SPI_HandleTypeDef *hspi1) {
|
||||
|
||||
if (HAL_GPIO_ReadPin(GPIOA, ADC_DRDY_Pin) != GPIO_PIN_RESET) {
|
||||
|
||||
@@ -5,9 +5,16 @@ void sd_send(uint8_t data[], uint32_t len) {
|
||||
extern bool sd_ready;
|
||||
extern FIL file;
|
||||
if (sd_ready) {
|
||||
//char buff[80];
|
||||
|
||||
//CDC_Transmit_FS((uint8_t*)"W\n\r", 3);
|
||||
UINT bytes_written;
|
||||
FRESULT res = f_write(&file, data, len, &bytes_written);
|
||||
//if (res != FR_OK || bytes_written != db_size)) {}
|
||||
//f_sync(&file);
|
||||
//int cx = snprintf(buff, 80, "%d %d %ld %ld\n\r", res, bytes_written, len, *((uint32_t*)data));
|
||||
//CDC_Transmit_FS((uint8_t*)buff, cx);
|
||||
if (res != FR_OK || bytes_written != len) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +29,13 @@ void usb_send(uint8_t data[], uint32_t len) {
|
||||
void uart_send(uint8_t data[], uint32_t len) {
|
||||
extern bool wb1mmc_ready;
|
||||
if (wb1mmc_ready) {
|
||||
HAL_UART_Transmit_DMA(&huart1, data, len);
|
||||
wb1mmc_ready = false;
|
||||
if (huart1.gState == HAL_UART_STATE_READY) {
|
||||
HAL_UART_Transmit_DMA(&huart1, data, len);
|
||||
wb1mmc_ready = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct dbl_buff<1024, usb_send> usb_buff;
|
||||
struct dbl_buff<1024, uart_send> ble_buff;
|
||||
struct dbl_buff<1024, sd_send> sd_buff;
|
||||
struct dbl_buff<4096, sd_send> sd_buff;
|
||||
|
||||
@@ -39,20 +39,20 @@ void initialize_lsm6dsv(SPI_HandleTypeDef *hspi1) {
|
||||
tx_buff[1] = 0x01; // I2C and I3C disabled
|
||||
send_receive_lsm6dsv(tx_buff, rx_buff, 2);
|
||||
|
||||
tx_buff[0] = 0x09; // Set 120Hz data rate for fifo
|
||||
tx_buff[1] = 0b01100110;
|
||||
tx_buff[0] = 0x09; // Set 240Hz data rate for fifo
|
||||
tx_buff[1] = 0b01110111;
|
||||
send_receive_lsm6dsv(tx_buff, rx_buff, 2);
|
||||
|
||||
tx_buff[0] = 0x0D; // Set drdy based on fifo
|
||||
tx_buff[1] = 0b00111000;
|
||||
send_receive_lsm6dsv(tx_buff, rx_buff, 2);
|
||||
|
||||
tx_buff[0] = 0x10; // Set 120Hz accelerometer high performance
|
||||
tx_buff[0] = 0x10; // Set 240Hz accelerometer high performance
|
||||
tx_buff[1] = 0b00000111;
|
||||
send_receive_lsm6dsv(tx_buff, rx_buff, 2);
|
||||
|
||||
tx_buff[0] = 0x11; // Set 120Hz gyro high performance
|
||||
tx_buff[1] = 0b00000110;
|
||||
tx_buff[0] = 0x11; // Set 240Hz gyro high performance
|
||||
tx_buff[1] = 0b00000111;
|
||||
send_receive_lsm6dsv(tx_buff, rx_buff, 2);
|
||||
|
||||
tx_buff[0] = 0x07;
|
||||
@@ -66,6 +66,7 @@ void initialize_lsm6dsv(SPI_HandleTypeDef *hspi1) {
|
||||
|
||||
struct packet_imu p_imu;
|
||||
|
||||
// With 5MHz SPI, the transfer should take 0.2mS
|
||||
void read_lsm6dsv(SPI_HandleTypeDef *hspi1) {
|
||||
|
||||
if (HAL_GPIO_ReadPin(GPIOC, IMU_DRDY_Pin) == GPIO_PIN_RESET) {
|
||||
|
||||
@@ -114,6 +114,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
|
||||
volatile bool to_open_sd = false;
|
||||
volatile bool to_close_sd = false;
|
||||
volatile bool to_print_dir = false;
|
||||
void comm_handler(uint8_t ch) {
|
||||
switch (ch) {
|
||||
|
||||
@@ -150,7 +151,10 @@ void comm_handler(uint8_t ch) {
|
||||
break;
|
||||
case '?':
|
||||
print_desc = true;
|
||||
break;
|
||||
break;
|
||||
case 'l':
|
||||
to_print_dir = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,27 +185,54 @@ void open_sd(void) {
|
||||
return;
|
||||
}
|
||||
alignas(32) char buffer1[32];
|
||||
int cx = snprintf(buffer1, 32, "%08lu.log", ((uint32_t)tim6_reloads) * (htim6.Init.Period + 1) + TIM6->CNT % 99999999);
|
||||
int cx = snprintf(buffer1, 32, "%08lu.log", (((uint32_t)tim6_reloads) * (htim6.Init.Period + 1) + TIM6->CNT) % 99999999);
|
||||
res = f_open(&file, buffer1, FA_WRITE | FA_CREATE_ALWAYS);
|
||||
if (res != FR_OK) {
|
||||
res = f_mount(NULL, "", 1);
|
||||
return;
|
||||
}
|
||||
f_expand(&file, 1024 * 1024 * 100, 1);
|
||||
unsigned int bw;
|
||||
data_description(false, true);
|
||||
sd_ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
void close_sd(void) {
|
||||
sd_ready = false;
|
||||
to_close_sd = false;
|
||||
if (sd_ready) {
|
||||
f_sync(&file);
|
||||
f_close(&file);
|
||||
res = f_mount(NULL, "", 1);
|
||||
void print_dirs(void) {
|
||||
char buff[80];
|
||||
FRESULT fr;
|
||||
DIR dir;
|
||||
FILINFO fno;
|
||||
|
||||
res = f_mount(&fs, "", 1);
|
||||
fr = f_opendir(&dir, "");
|
||||
while (1)
|
||||
{
|
||||
fr = f_readdir(&dir, &fno);
|
||||
|
||||
if (fr != FR_OK || fno.fname[0] == 0)
|
||||
break;
|
||||
|
||||
// Skip directories just in case
|
||||
if (fno.fattrib & AM_DIR)
|
||||
continue;
|
||||
|
||||
int cx = snprintf(buff, 80, "%s %10lu\n\r", fno.fname, (unsigned long)fno.fsize);
|
||||
CDC_Transmit_FS((uint8_t*)buff, cx);
|
||||
}
|
||||
f_closedir(&dir);
|
||||
f_mount(NULL, "", 1);
|
||||
}
|
||||
|
||||
void close_sd(void) {
|
||||
if (!sd_ready) {
|
||||
return;
|
||||
}
|
||||
to_close_sd = false;
|
||||
res = f_sync(&file);
|
||||
res = f_close(&file);
|
||||
res = f_mount(NULL, "", 1);
|
||||
sd_ready = false;
|
||||
}
|
||||
/* USER CODE END 0 */
|
||||
|
||||
@@ -269,6 +300,11 @@ int main(void)
|
||||
read_ads131(&hspi1);
|
||||
read_max30101(&hi2c1);
|
||||
|
||||
if (to_print_dir) {
|
||||
to_print_dir = false;
|
||||
print_dirs();
|
||||
}
|
||||
|
||||
if (to_open_sd) {
|
||||
open_sd();
|
||||
}
|
||||
@@ -303,15 +339,20 @@ int main(void)
|
||||
write(p_vbatt);
|
||||
}
|
||||
|
||||
if (usb_ready and total_tim6() - usb_buff.last_write > 4000) {
|
||||
if (usb_ready and total_tim6() - usb_buff.last_write > 8000) {
|
||||
extern dbl_buff<1024, usb_send> usb_buff;
|
||||
usb_buff.send();
|
||||
}
|
||||
|
||||
if (wb1mmc_ready and total_tim6() - ble_buff.last_write > 4000) {
|
||||
if (wb1mmc_ready and total_tim6() - ble_buff.last_write > 8000) {
|
||||
extern dbl_buff<1024, uart_send> ble_buff;
|
||||
ble_buff.send();
|
||||
}
|
||||
|
||||
if (sd_ready and total_tim6() - sd_buff.last_write > 8000) {
|
||||
extern dbl_buff<4096, sd_send> sd_buff;
|
||||
sd_buff.send();
|
||||
}
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ void initialize_max30101(I2C_HandleTypeDef *hi2c1) {
|
||||
HAL_I2C_Mem_Read(hi2c1, 0xAE, 0x07, 1, p_spo2.bytes, 180, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
// 3mS transfer but shouldn't block...
|
||||
void read_max30101(I2C_HandleTypeDef *hi2c1) {
|
||||
if (print_ready) {
|
||||
p_spo2.t = total_tim6();
|
||||
|
||||
Reference in New Issue
Block a user