I am using the functions below to transfer the files to the host.
#ifdef SEMIHOSTING
static FILE* m_file = NULL;
#endif
void openFile(const char* name, const char* mode) {
#ifdef SEMIHOSTING
if (m_file == NULL) {
// mutex lock
m_file = fopen(name, mode);
// mutex unlock
}
#else
(void)name;
(void)mode;
#endif
}
bool writeFile(const void* buffer, size_t size) {
bool status = false;
#ifdef SEMIHOSTING
if (m_file != NULL) {
// mutex lock
status = (size == fwrite(buffer, sizeof(uint8_t), size, m_file));
// mutex unlock
}
#else
(void)buffer;
(void)size;
#endif
return status;
}
void closeFile(void) {
#ifdef SEMIHOSTING
if (m_file != NULL) {
// mutex lock
fclose(m_file);
// mutex unlock
}
m_file = NULL;
#endif
}