i use stm32 bluebill with sd module to convert serial data from serial port to text file in the sd card and the data coming continuously from fpga with high buad rate and am stuck with this project my last experiment was using FreeRTOS with this code: #include <FreeRTOS.h>
#include <task.h>
#include <SD.h>
#include <SPI.h>
#include <stm32_def.h>
#define SERIAL_RX_PIN PA10
#define FILENAME "data.txt"
#define BUFFER_SIZE 20000
#define MAX_SERIAL_CHARS 100
#define SD_CS_PIN PA4
static void task1(void *pvParameters) {
char buffer[BUFFER_SIZE];
int index = 0;
for (;;) {
if (Serial.available()) {
char c = Serial.read();
if (index < BUFFER_SIZE && index < MAX_SERIAL_CHARS) {
buffer[index++] = c;
} else {
Serial.print("Serial buffer overflow, contents: ");
Serial.write(buffer, index);
index = 0;
}
}
vTaskDelay(pdMS_TO_TICKS(1));
}
}
static void task2(void *pvParameters) {
File file;
char buffer[BUFFER_SIZE];
int index = 0;
for (;;) {
if (SD.exists(FILENAME)) {
file = SD.open(FILENAME, FILE_WRITE);
if (file) {
if (index > 0) {
Serial.print("Writing to file, buffer contents: ");
Serial.write(buffer, index);
int bytes_written = file.write(buffer, index);
if (bytes_written != index) {
Serial.println("File write error!");
}
index = 0;
}
file.close();
} else {
Serial.println("Unable to open file for writing!");
}
} else {
file = SD.open(FILENAME, FILE_WRITE);
if (file) {
file.close();
} else {
Serial.println("Unable to create file!");
}
}
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
void setup()
{
Serial.begin(9600);
pinMode(SERIAL_RX_PIN, INPUT);
SPI.begin();
if (!SD.begin(20, SD_CS_PIN)) { // Use PA4 as CS pin and SPI1 bus
Serial.println("SD card initialization failed!");
while (1);
}
xTaskCreate(task1, "SerialTask", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
xTaskCreate(task2, "FileTask", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
vTaskStartScheduler();
}
void loop()
{
}
stm32f103c data logger
Return to “Let us know a bit about you and your projects”
Jump to
- Announcements
- New users start here
- ↳ Forum rules, FAQs and HowTo's
- ↳ Let us know a bit about you and your projects
- Arduino for STM32
- ↳ General discussion
- ↳ Ideas & suggestions
- ↳ Cores
- ↳ STM32 Core
- ↳ Builds and Announcements
- ↳ Code snippets
- ↳ Ideas & suggestions
- ↳ General discussion
- ↳ Installation and OS related
- ↳ Libraries & Hardware
- ↳ PR's bugs and enhancements
- ↳ LibMaple
- ↳ Builds and Announcements
- ↳ Code snippets
- ↳ General discussion
- ↳ Ideas & suggestions
- ↳ Installation and OS related
- ↳ Libraries & Hardware
- ↳ PR's bugs and enhancements
- ↳ Steve's LibMaple core
- ↳ General discussion
- ↳ PR's bugs and enhancements
- ↳ Projects
- ↳ IDE's
- ↳ Off topic
- Arduino for STM8
- ↳ General discussion
- ↳ Cores
- ↳ STM8 Core
- ↳ Other
- Boards
- ↳ Custom design boards
- ↳ Maple & Maple mini etc
- ↳ STM boards (Discovery, Eval, Nucleo, ...)
- ↳ All other boards
- ↳ STM32F0 based boards
- ↳ STM32F1 based boards
- ↳ STM32F2 based boards
- ↳ STM32F3 based boards
- ↳ STM32F4 based boards
- ↳ STM32F7 based boards
- ↳ STM32G0 based boards
- ↳ STM32G4 based boards
- ↳ STM32H7 based boards
- ↳ STM32L0 based boards
- ↳ STM32L1 based boards
- ↳ STM32L4 based boards
- ↳ STM32L5 based boards
- ↳ STM32MP1 based boards
- ↳ STM32WB based boards
- Bootloaders
- ↳ STM32 HID bootloader
- ↳ USB bootloader
- ↳ STM32 SD-Bootloader
- ↳ STM32 USB CDC bootloader
- Uploaders and debuggers
- ↳ STLink
- ↳ USB to Serial adaptors
- ↳ Black Magic Probe & other
- Dead Thread Graveyard
- ↳ Dead Thread Graveyard