Files
L'électron rareandClaude Opus 4.6 58e785e53e feat(mistral): dataset builders + 549 training examples across 10 domains (Plan 23)
- build_datasets.py: unified generator for ChatML JSONL (kicad, spice, freecad,
  stm32, embedded, iot, emc, dsp, power, platformio)
- validate_dataset.py: format/structure/duplicate validation
- 549 examples generated and validated, zero API calls
- Plans 23 + 23v2: all build_*_dataset.py tasks marked done

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
2026-03-25 13:23:45 +01:00

50 lines
28 KiB
JSON

{"messages": [{"role": "user", "content": "How do I create a FreeRTOS task for sensor reading?"}, {"role": "assistant", "content": "```c\n#include \"FreeRTOS.h\"\n#include \"task.h\"\n\nvoid vSensorTask(void *pvParameters) {\n TickType_t xLastWakeTime = xTaskGetTickCount();\n const TickType_t xPeriod = pdMS_TO_TICKS(100); // 100ms\n \n for (;;) {\n float temp = read_temperature_sensor();\n float humidity = read_humidity_sensor();\n \n // Send to queue for processing\n SensorData_t data = {temp, humidity, xTaskGetTickCount()};\n xQueueSend(xSensorQueue, &data, pdMS_TO_TICKS(10));\n \n vTaskDelayUntil(&xLastWakeTime, xPeriod);\n }\n}\n\n// Create task (in main):\nxTaskCreate(vSensorTask, \"Sensor\", 256, NULL, 2, &xSensorHandle);\n```\nStack size 256 words (1KB) is typical for simple sensor tasks. Priority 2 (above idle, below critical)."}]}
{"messages": [{"role": "user", "content": "How do I use a mutex to protect shared resource?"}, {"role": "assistant", "content": "```c\nSemaphoreHandle_t xI2CMutex = xSemaphoreCreateMutex();\n\n// Task A:\nif (xSemaphoreTake(xI2CMutex, pdMS_TO_TICKS(100)) == pdTRUE) {\n i2c_read_sensor_a(data_a);\n xSemaphoreGive(xI2CMutex);\n} else {\n // Timeout — handle error\n}\n\n// Task B:\nif (xSemaphoreTake(xI2CMutex, pdMS_TO_TICKS(100)) == pdTRUE) {\n i2c_read_sensor_b(data_b);\n xSemaphoreGive(xI2CMutex);\n}\n```\nMutex provides priority inheritance to prevent priority inversion. Always use timeout (not portMAX_DELAY) in production. Never take a mutex from an ISR — use binary semaphore instead."}]}
{"messages": [{"role": "user", "content": "How do I implement a producer-consumer pattern with queues?"}, {"role": "assistant", "content": "```c\n// Create queue: 10 items of SensorData_t\nQueueHandle_t xDataQueue = xQueueCreate(10, sizeof(SensorData_t));\n\n// Producer task:\nvoid vProducerTask(void *pv) {\n for (;;) {\n SensorData_t sample = acquire_sample();\n if (xQueueSend(xDataQueue, &sample, pdMS_TO_TICKS(50)) != pdTRUE) {\n // Queue full — log overflow, drop oldest or block\n overflows++;\n }\n vTaskDelay(pdMS_TO_TICKS(10));\n }\n}\n\n// Consumer task:\nvoid vConsumerTask(void *pv) {\n SensorData_t received;\n for (;;) {\n if (xQueueReceive(xDataQueue, &received, portMAX_DELAY) == pdTRUE) {\n process_and_transmit(received);\n }\n }\n}\n```\nQueue depth = burst_rate * max_processing_time. Monitor with uxQueueMessagesWaiting()."}]}
{"messages": [{"role": "user", "content": "How do I implement software timer for periodic LED blink?"}, {"role": "assistant", "content": "```c\nTimerHandle_t xBlinkTimer;\n\nvoid vBlinkCallback(TimerHandle_t xTimer) {\n HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);\n}\n\n// In main, after scheduler init:\nxBlinkTimer = xTimerCreate(\"Blink\", pdMS_TO_TICKS(500), pdTRUE, NULL, vBlinkCallback);\nxTimerStart(xBlinkTimer, 0);\n```\nSoftware timers run in the timer daemon task context. Don't block in the callback. For variable timing, use xTimerChangePeriod(). For one-shot: set auto-reload to pdFALSE."}]}
{"messages": [{"role": "user", "content": "best practices for interrupt handlers on Cortex-M"}, {"role": "assistant", "content": "ISR best practices:\n1. **Keep ISRs short**: Set flags or send to queue, process in task\n2. **No blocking calls**: Never use HAL_Delay(), malloc(), printf() in ISR\n3. **Volatile variables**: Declare shared variables as `volatile`\n4. **Priority levels**: NVIC priority 0=highest. FreeRTOS: set configMAX_SYSCALL_INTERRUPT_PRIORITY (default 5), ISRs above this can't call FreeRTOS API\n5. **Critical sections**: Use `__disable_irq()/__enable_irq()` sparingly, prefer BASEPRI masking\n6. **Tail-chaining**: Cortex-M optimizes back-to-back ISRs, no need to combine\n7. **DMA**: Prefer DMA over byte-by-byte ISR for bulk transfers\n8. **Atomic access**: Use LDREX/STREX or `__LDREXW()` for lock-free shared data"}]}
{"messages": [{"role": "user", "content": "nested interrupt priority configuration"}, {"role": "assistant", "content": "Cortex-M NVIC priority:\n```c\n// Set priority grouping: 4 bits preemption, 0 bits sub-priority\nHAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);\n\n// High priority (preempts others):\nHAL_NVIC_SetPriority(TIM2_IRQn, 1, 0); // Motor control\nHAL_NVIC_SetPriority(EXTI0_IRQn, 2, 0); // Safety switch\n\n// Medium priority:\nHAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 5, 0); // ADC DMA\nHAL_NVIC_SetPriority(USART2_IRQn, 6, 0); // Communication\n\n// Low priority (for FreeRTOS-compatible ISRs):\nHAL_NVIC_SetPriority(TIM6_IRQn, 10, 0); // Background timing\n```\nRule: Safety-critical > Real-time control > Communication > Background. FreeRTOS API only callable from priority >= configMAX_SYSCALL_INTERRUPT_PRIORITY."}]}
{"messages": [{"role": "user", "content": "How do I debug a stack overflow on an embedded system?"}, {"role": "assistant", "content": "Stack overflow detection:\n1. **FreeRTOS**: Enable `configCHECK_FOR_STACK_OVERFLOW = 2` in FreeRTOSConfig.h. Implement `vApplicationStackOverflowHook()` to log task name.\n2. **Canary pattern**: FreeRTOS writes 0xA5A5A5A5 at stack bottom, checks on context switch.\n3. **MPU**: Configure MPU region at stack bottom as no-access. HardFault on overflow.\n4. **Static analysis**: Use `-fstack-usage` GCC flag to get per-function stack usage. Sum call chains.\n5. **Runtime**: Monitor `uxTaskGetStackHighWaterMark()` — returns minimum free stack words ever.\n6. **Fix**: Increase stack size in xTaskCreate(), reduce local variables (use static or heap), avoid recursive calls, reduce printf() buffer sizes.\n\nTypical stack sizes: Simple task 256-512 words, printf task 512-1024 words, TCP/IP task 1024+ words."}]}
{"messages": [{"role": "user", "content": "When should I use static vs dynamic memory allocation in embedded?"}, {"role": "assistant", "content": "**Static allocation** (preferred for safety-critical):\n- `static uint8_t buffer[256];` — lifetime of program, no fragmentation\n- FreeRTOS: `xTaskCreateStatic()`, `xQueueCreateStatic()`\n- Pros: deterministic, no heap fragmentation, MISRA compliant\n- Cons: memory reserved even when unused\n\n**Dynamic allocation** (use with care):\n- `pvPortMalloc()` / `pvPortFree()` in FreeRTOS\n- heap_1: allocate only (simplest, no free)\n- heap_4: coalescing free, best general-purpose\n- Pros: flexible, memory shared between features\n- Cons: fragmentation, non-deterministic timing, hard to debug leaks\n\n**Rule of thumb**: Allocate at startup, never at runtime. If you must use dynamic allocation, allocate during init phase and never free. Use memory pools for fixed-size objects."}]}
{"messages": [{"role": "user", "content": "How do I implement a ring buffer for UART reception?"}, {"role": "assistant", "content": "```c\n#define RING_BUF_SIZE 256 // must be power of 2\ntypedef struct {\n volatile uint8_t buf[RING_BUF_SIZE];\n volatile uint16_t head; // write index (ISR)\n volatile uint16_t tail; // read index (task)\n} RingBuf_t;\n\nstatic RingBuf_t rx_ring = {0};\n\n// In UART ISR:\nvoid USART2_IRQHandler(void) {\n if (USART2->SR & USART_SR_RXNE) {\n uint16_t next = (rx_ring.head + 1) & (RING_BUF_SIZE - 1);\n if (next != rx_ring.tail) { // not full\n rx_ring.buf[rx_ring.head] = USART2->DR;\n rx_ring.head = next;\n }\n }\n}\n\n// In task:\nint ring_read(uint8_t *byte) {\n if (rx_ring.tail == rx_ring.head) return 0; // empty\n *byte = rx_ring.buf[rx_ring.tail];\n rx_ring.tail = (rx_ring.tail + 1) & (RING_BUF_SIZE - 1);\n return 1;\n}\n```\nPower-of-2 size enables fast modulo via bitmask. No mutex needed if single producer (ISR) and single consumer (task)."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a high-priority sensor reading task?"}, {"role": "assistant", "content": "For a high-priority sensor reading task:\n\nPriority: 4 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 512-1024 words — needs buffer space for sensor data and I2C/SPI transactions\n\nCritical: use vTaskDelayUntil() for deterministic timing. Consider running in a timer ISR instead for sub-ms requirements."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a medium-priority sensor reading task?"}, {"role": "assistant", "content": "For a medium-priority sensor reading task:\n\nPriority: 2 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 512-1024 words — needs buffer space for sensor data and I2C/SPI transactions\n\nStandard periodic task pattern works well. Monitor stack high water mark during development."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a low-priority sensor reading task?"}, {"role": "assistant", "content": "For a low-priority sensor reading task:\n\nPriority: 1 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 512-1024 words — needs buffer space for sensor data and I2C/SPI transactions\n\nCan use vTaskDelay() instead of vTaskDelayUntil(). Consider combining with other low-priority work to reduce task count."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a high-priority motor control task?"}, {"role": "assistant", "content": "For a high-priority motor control task:\n\nPriority: 4 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 256-512 words — tight timing, keep ISR-driven with minimal task logic\n\nCritical: use vTaskDelayUntil() for deterministic timing. Consider running in a timer ISR instead for sub-ms requirements."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a medium-priority motor control task?"}, {"role": "assistant", "content": "For a medium-priority motor control task:\n\nPriority: 2 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 256-512 words — tight timing, keep ISR-driven with minimal task logic\n\nStandard periodic task pattern works well. Monitor stack high water mark during development."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a low-priority motor control task?"}, {"role": "assistant", "content": "For a low-priority motor control task:\n\nPriority: 1 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 256-512 words — tight timing, keep ISR-driven with minimal task logic\n\nCan use vTaskDelay() instead of vTaskDelayUntil(). Consider combining with other low-priority work to reduce task count."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a high-priority display update task?"}, {"role": "assistant", "content": "For a high-priority display update task:\n\nPriority: 4 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 1024-2048 words — display libraries (LVGL, u8g2) use significant stack for rendering\n\nCritical: use vTaskDelayUntil() for deterministic timing. Consider running in a timer ISR instead for sub-ms requirements."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a medium-priority display update task?"}, {"role": "assistant", "content": "For a medium-priority display update task:\n\nPriority: 2 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 1024-2048 words — display libraries (LVGL, u8g2) use significant stack for rendering\n\nStandard periodic task pattern works well. Monitor stack high water mark during development."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a low-priority display update task?"}, {"role": "assistant", "content": "For a low-priority display update task:\n\nPriority: 1 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 1024-2048 words — display libraries (LVGL, u8g2) use significant stack for rendering\n\nCan use vTaskDelay() instead of vTaskDelayUntil(). Consider combining with other low-priority work to reduce task count."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a high-priority data logging task?"}, {"role": "assistant", "content": "For a high-priority data logging task:\n\nPriority: 4 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 512-1024 words — depends on filesystem (FATFS) stack usage\n\nCritical: use vTaskDelayUntil() for deterministic timing. Consider running in a timer ISR instead for sub-ms requirements."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a medium-priority data logging task?"}, {"role": "assistant", "content": "For a medium-priority data logging task:\n\nPriority: 2 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 512-1024 words — depends on filesystem (FATFS) stack usage\n\nStandard periodic task pattern works well. Monitor stack high water mark during development."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a low-priority data logging task?"}, {"role": "assistant", "content": "For a low-priority data logging task:\n\nPriority: 1 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 512-1024 words — depends on filesystem (FATFS) stack usage\n\nCan use vTaskDelay() instead of vTaskDelayUntil(). Consider combining with other low-priority work to reduce task count."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a high-priority communication task?"}, {"role": "assistant", "content": "For a high-priority communication task:\n\nPriority: 4 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 1024-2048 words — TCP/IP stack (lwIP) needs large buffers\n\nCritical: use vTaskDelayUntil() for deterministic timing. Consider running in a timer ISR instead for sub-ms requirements."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a medium-priority communication task?"}, {"role": "assistant", "content": "For a medium-priority communication task:\n\nPriority: 2 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 1024-2048 words — TCP/IP stack (lwIP) needs large buffers\n\nStandard periodic task pattern works well. Monitor stack high water mark during development."}]}
{"messages": [{"role": "user", "content": "What FreeRTOS priority and stack size should I use for a low-priority communication task?"}, {"role": "assistant", "content": "For a low-priority communication task:\n\nPriority: 1 (FreeRTOS range 0=idle to configMAX_PRIORITIES-1)\nStack: 1024-2048 words — TCP/IP stack (lwIP) needs large buffers\n\nCan use vTaskDelay() instead of vTaskDelayUntil(). Consider combining with other low-priority work to reduce task count."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 1 byte over UART on an embedded system?"}, {"role": "assistant", "content": "Transferring 1 byte over UART:\n\nUse DMA for anything above a few bytes. Configure UART DMA TX channel, trigger with HAL_UART_Transmit_DMA(). For 1 byte, polling is fine (HAL_UART_Transmit with short timeout).\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 16 bytes over UART on an embedded system?"}, {"role": "assistant", "content": "Transferring 16 bytes over UART:\n\nUse DMA for anything above a few bytes. Configure UART DMA TX channel, trigger with HAL_UART_Transmit_DMA(). For 1 byte, polling is fine (HAL_UART_Transmit with short timeout).\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 256 bytes over UART on an embedded system?"}, {"role": "assistant", "content": "Transferring 256 bytes over UART:\n\nUse DMA for anything above a few bytes. Configure UART DMA TX channel, trigger with HAL_UART_Transmit_DMA(). For 1 byte, polling is fine (HAL_UART_Transmit with short timeout).\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 1 KB over UART on an embedded system?"}, {"role": "assistant", "content": "Transferring 1 KB over UART:\n\nUse DMA for anything above a few bytes. Configure UART DMA TX channel, trigger with HAL_UART_Transmit_DMA(). For 1 byte, polling is fine (HAL_UART_Transmit with short timeout).\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 1 byte over SPI on an embedded system?"}, {"role": "assistant", "content": "Transferring 1 byte over SPI:\n\nSPI is ideal for bulk transfers. Use DMA for {size} — set chip select manually (GPIO), call HAL_SPI_Transmit_DMA(), release CS in completion callback. SPI can easily handle multi-KB transfers at 10+ MHz.\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 16 bytes over SPI on an embedded system?"}, {"role": "assistant", "content": "Transferring 16 bytes over SPI:\n\nSPI is ideal for bulk transfers. Use DMA for {size} — set chip select manually (GPIO), call HAL_SPI_Transmit_DMA(), release CS in completion callback. SPI can easily handle multi-KB transfers at 10+ MHz.\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 256 bytes over SPI on an embedded system?"}, {"role": "assistant", "content": "Transferring 256 bytes over SPI:\n\nSPI is ideal for bulk transfers. Use DMA for {size} — set chip select manually (GPIO), call HAL_SPI_Transmit_DMA(), release CS in completion callback. SPI can easily handle multi-KB transfers at 10+ MHz.\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 1 KB over SPI on an embedded system?"}, {"role": "assistant", "content": "Transferring 1 KB over SPI:\n\nSPI is ideal for bulk transfers. Use DMA for {size} — set chip select manually (GPIO), call HAL_SPI_Transmit_DMA(), release CS in completion callback. SPI can easily handle multi-KB transfers at 10+ MHz.\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 1 byte over I2C on an embedded system?"}, {"role": "assistant", "content": "Transferring 1 byte over I2C:\n\nI2C is slower but simpler. For {size}: use HAL_I2C_Mem_Read/Write for register-based access. DMA worthwhile above 16 bytes. I2C limited to ~400kHz (fast mode), so large transfers are slow (~2.5KB/s).\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 16 bytes over I2C on an embedded system?"}, {"role": "assistant", "content": "Transferring 16 bytes over I2C:\n\nI2C is slower but simpler. For {size}: use HAL_I2C_Mem_Read/Write for register-based access. DMA worthwhile above 16 bytes. I2C limited to ~400kHz (fast mode), so large transfers are slow (~2.5KB/s).\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 256 bytes over I2C on an embedded system?"}, {"role": "assistant", "content": "Transferring 256 bytes over I2C:\n\nI2C is slower but simpler. For {size}: use HAL_I2C_Mem_Read/Write for register-based access. DMA worthwhile above 16 bytes. I2C limited to ~400kHz (fast mode), so large transfers are slow (~2.5KB/s).\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 1 KB over I2C on an embedded system?"}, {"role": "assistant", "content": "Transferring 1 KB over I2C:\n\nI2C is slower but simpler. For {size}: use HAL_I2C_Mem_Read/Write for register-based access. DMA worthwhile above 16 bytes. I2C limited to ~400kHz (fast mode), so large transfers are slow (~2.5KB/s).\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 1 byte over CAN on an embedded system?"}, {"role": "assistant", "content": "Transferring 1 byte over CAN:\n\nCAN frames are 8 bytes max (CAN 2.0B) or 64 bytes (CAN FD). For {size}: single frame is sufficient.\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 16 bytes over CAN on an embedded system?"}, {"role": "assistant", "content": "Transferring 16 bytes over CAN:\n\nCAN frames are 8 bytes max (CAN 2.0B) or 64 bytes (CAN FD). For {size}: single frame works, pad remaining bytes.\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 256 bytes over CAN on an embedded system?"}, {"role": "assistant", "content": "Transferring 256 bytes over CAN:\n\nCAN frames are 8 bytes max (CAN 2.0B) or 64 bytes (CAN FD). For {size}: use ISO-TP (ISO 15765-2) transport protocol for segmentation.\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 1 KB over CAN on an embedded system?"}, {"role": "assistant", "content": "Transferring 1 KB over CAN:\n\nCAN frames are 8 bytes max (CAN 2.0B) or 64 bytes (CAN FD). For {size}: use ISO-TP (ISO 15765-2) transport protocol for segmentation.\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 1 byte over USB CDC on an embedded system?"}, {"role": "assistant", "content": "Transferring 1 byte over USB CDC:\n\nUSB CDC (virtual COM port) is best for bulk data. For {size}: buffer data and send in USB packet-sized chunks (64 bytes for FS). Use double-buffering for continuous streaming. Throughput up to ~1 MB/s on Full-Speed USB.\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 16 bytes over USB CDC on an embedded system?"}, {"role": "assistant", "content": "Transferring 16 bytes over USB CDC:\n\nUSB CDC (virtual COM port) is best for bulk data. For {size}: buffer data and send in USB packet-sized chunks (64 bytes for FS). Use double-buffering for continuous streaming. Throughput up to ~1 MB/s on Full-Speed USB.\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 256 bytes over USB CDC on an embedded system?"}, {"role": "assistant", "content": "Transferring 256 bytes over USB CDC:\n\nUSB CDC (virtual COM port) is best for bulk data. For {size}: buffer data and send in USB packet-sized chunks (64 bytes for FS). Use double-buffering for continuous streaming. Throughput up to ~1 MB/s on Full-Speed USB.\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I efficiently transfer 1 KB over USB CDC on an embedded system?"}, {"role": "assistant", "content": "Transferring 1 KB over USB CDC:\n\nUSB CDC (virtual COM port) is best for bulk data. For {size}: buffer data and send in USB packet-sized chunks (64 bytes for FS). Use double-buffering for continuous streaming. Throughput up to ~1 MB/s on Full-Speed USB.\n\nGeneral tips: Always use DMA for transfers > 4 bytes to free the CPU. Use double-buffering (ping-pong) for continuous data streams. Handle errors (timeout, NACK, bus errors) in the ISR callback."}]}
{"messages": [{"role": "user", "content": "How do I minimize boot time on STM32F1?"}, {"role": "assistant", "content": "Boot time optimization for STM32F1:\n\n1. Use HSI (internal 8MHz) initially, switch to PLL after critical init\n2. Skip HAL_Init() delay (remove HAL_Delay in SystemClock_Config)\n3. Initialize only needed peripherals\n4. Use __attribute__((section(\".fast\"))) for critical init code in SRAM\n\nGeneral: Measure boot time with GPIO toggle + oscilloscope. Target: <50ms for sensor wake, <200ms for user-facing devices."}]}
{"messages": [{"role": "user", "content": "How do I minimize boot time on STM32F4?"}, {"role": "assistant", "content": "Boot time optimization for STM32F4:\n\n1. Use HSI (internal 8MHz) initially, switch to PLL after critical init\n2. Skip HAL_Init() delay (remove HAL_Delay in SystemClock_Config)\n3. Initialize only needed peripherals\n4. Use __attribute__((section(\".fast\"))) for critical init code in SRAM\n\nGeneral: Measure boot time with GPIO toggle + oscilloscope. Target: <50ms for sensor wake, <200ms for user-facing devices."}]}
{"messages": [{"role": "user", "content": "How do I minimize boot time on STM32H7?"}, {"role": "assistant", "content": "Boot time optimization for STM32H7:\n\n1. Use HSI (internal 8MHz) initially, switch to PLL after critical init\n2. Skip HAL_Init() delay (remove HAL_Delay in SystemClock_Config)\n3. Initialize only needed peripherals\n4. Use __attribute__((section(\".fast\"))) for critical init code in SRAM\n\nGeneral: Measure boot time with GPIO toggle + oscilloscope. Target: <50ms for sensor wake, <200ms for user-facing devices."}]}
{"messages": [{"role": "user", "content": "How do I minimize boot time on ESP32?"}, {"role": "assistant", "content": "Boot time optimization for ESP32:\n\n1. Reduce bootloader log level: CONFIG_BOOTLOADER_LOG_LEVEL_NONE\n2. Skip WiFi/BT init if not immediately needed\n3. Use fast boot mode: CONFIG_ESPTOOLPY_FLASHFREQ_80M\n4. Minimize partition table scanning\n5. Use ULP coprocessor for wake-from-sleep tasks\n\nGeneral: Measure boot time with GPIO toggle + oscilloscope. Target: <50ms for sensor wake, <200ms for user-facing devices."}]}
{"messages": [{"role": "user", "content": "How do I minimize boot time on nRF52840?"}, {"role": "assistant", "content": "Boot time optimization for nRF52840:\n\n1. Use HFXO (32MHz) instead of HFINT for faster PLL lock\n2. Enable DCDC converter early for power efficiency\n3. Pre-configure GPIO before enabling peripherals\n4. Use SoftDevice minimal config if BLE not needed at boot\n\nGeneral: Measure boot time with GPIO toggle + oscilloscope. Target: <50ms for sensor wake, <200ms for user-facing devices."}]}