Introduction to ARM Semihosting | Interrupt

Firmware developers are generally accustomed to using logging for execution information. On microcontrollers, this is usually done through a serial interface attached to a terminal on the host.


This is a companion discussion topic for the original entry at https://interrupt.memfault.com/blog/arm-semihosting

Thank you for the introduction, though since you mentioned camera in the beginning, I was expecting to see image transfer implementation. Do you have such article in mind?

Same question here, I hope you can extend your blog to show how you managed to move binary data to host.

Try this:

int fd = open ("framebuffer.bin", O_CREAT | O_SYNC);
write (fd, framebuffer, SIZE_OF_FRAMEBUFFER);
close (fd);

Includes and error handling are left as an exercise.

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
}

Quick question, what is the purpose of the (void) statements in the #else blocks?

Thanks,
Greg

The (void) statements you are referring to tell the compiler the variables are not used. This will prevent warnings about them.