/* Glue between chibiOS and baselibc */ #include #include #include #include #include "ch.h" #include "hal.h" #include "usb_usart.h" static size_t stdout_write(FILE *stream, const char *ptr, size_t size) { if (USBD1.state == USB_ACTIVE) { chIOWriteTimeout(&SDU1, (const uint8_t*)ptr, size, 100); // USB } return chIOWriteTimeout(&SD1, (const uint8_t*)ptr, size, 100); }; static const struct File_methods stdout_methods = { stdout_write, NULL }; static const struct File _stdout = {&stdout_methods}; FILE* const stdout = (FILE*)&_stdout; FILE* const stderr = (FILE*)&_stdout; void free(void *p) { chHeapFree(p); } void *malloc(size_t s) { return chHeapAlloc(NULL, s); } void *calloc(size_t nmemb, size_t size) { size *= nmemb; void *p = chHeapAlloc(NULL, size); if (p != NULL) memset(p, 0, size); return p; }