CoIDE, STM32F103 and Semihosting

I have been a little quiet lately as I have been working on a few projects. One of these are some experiments with the CooCox CoIDE and a STM32F103 dev board that I picked up off EBay a while back.

As a quick background, I have generated the bulk of the test project(s) with STM32CubeMX, and then modified what I needed. It should be noted that STM has updated the StdPeripheral library with a new HAL Library, which I decided to use. CoIDE has a neat feature called “semihosting” which allows you to shoot debug messages back to the IDE via the JTAG interface, freeing up the UART for your application-specific use.

The problem comes when adding semihosting. You need to add the “Retarget printf” component as well as the “Semihosting”. A quick implementation of PrintChar() in the semihosting code:

#include <semihosting/semihosting.h>
void PrintChar(char c)

If you try and compile this, you get the following error:

[cc] Starting link
[cc] arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -g -nostartfiles -Wl, -O0 -Wl,--gc-sections -LC:\CooCox\CoIDE\configuration\ProgramData\cdctest -Wl,-TC:\CooCox\CoIDE\configuration\ProgramData\cdctest/arm-gcc-link.ld -g -o cdctest.elf ..\obj\stm32f1xx_hal_rcc_ex.o ..\obj\semihosting.o ..\obj\stm32f1xx_hal_pwr.o ..\obj\stm32f1xx_hal_can.o ..\obj\stm32f1xx_hal.o ..\obj\stm32f1xx_it.o ..\obj\stm32f1xx_hal_dac.o ..\obj\stm32f1xx_hal_gpio_ex.o ..\obj\stm32f1xx_hal_wwdg.o ..\obj\stm32f1xx_hal_cortex.o ..\obj\stm32f1xx_hal_crc.o ..\obj\stm32f1xx_hal_iwdg.o ..\obj\system_stm32f1xx.o ..\obj\stm32f1xx_hal_rcc.o ..\obj\stm32f1xx_hal_dac_ex.o ..\obj\stm32f1xx_hal_adc.o ..\obj\stm32f1xx_hal_i2s.o ..\obj\stm32f1xx_hal_smartcard.o ..\obj\stm32f1xx_hal_pcd.o ..\obj\stm32f1xx_hal_uart.o ..\obj\usbd_core.o ..\obj\main.o ..\obj\startup_stm32f103xb.o ..\obj\stm32f1xx_hal_usart.o ..\obj\stm32f1xx_hal_nor.o ..\obj\stm32f1xx_ll_usb.o ..\obj\printf.o ..\obj\stm32f1xx_hal_spi_ex.o ..\obj\stm32f1xx_hal_cec.o ..\obj\stm32f1xx_hal_hcd.o ..\obj\stm32f1xx_hal_flash.o ..\obj\stm32f1xx_hal_gpio.o ..\obj\stm32f1xx_hal_dma.o ..\obj\usbd_desc.o ..\obj\usbd_conf.o ..\obj\stm32f1xx_hal_adc_ex.o ..\obj\stm32f1xx_hal_irda.o ..\obj\stm32f1xx_hal_sd.o ..\obj\sh_cmd.o ..\obj\stm32f1xx_hal_spi.o ..\obj\syscalls.o ..\obj\stm32f1xx_hal_i2c.o ..\obj\stm32f1xx_hal_msp.o ..\obj\usb_ctrl.o ..\obj\stm32f1xx_hal_eth.o ..\obj\stm32f1xx_ll_fsmc.o ..\obj\usbd_cdc.o ..\obj\stm32f1xx_hal_rtc.o ..\obj\stm32f1xx_hal_tim.o ..\obj\stm32f1xx_hal_flash_ex.o ..\obj\usbd_ctlreq.o ..\obj\stm32f1xx_hal_pcd_ex.o ..\obj\usbd_cdc_if.o ..\obj\stm32f1xx_hal_nand.o ..\obj\usbd_ioreq.o ..\obj\stm32f1xx_hal_pccard.o ..\obj\stm32f1xx_hal_sram.o ..\obj\usb_device.o ..\obj\stm32f1xx_hal_rtc_ex.o ..\obj\stm32f1xx_hal_tim_ex.o ..\obj\stm32f1xx_ll_sdmmc.o -lm -lgcc -lc
[cc] c:/program files (x86)/gnu tools arm embedded/5.3 2016q1/bin/../lib/gcc/arm-none-eabi/5.3.1/../../../../arm-none-eabi/lib/armv7-m\libc.a(lib_a-impure.o):(.data._impure_ptr+0x0): multiple definition of `_impure_ptr'
[cc] ..\obj\printf.o:(.data+0x428): first defined here
[cc] collect2.exe: error: ld returned 1 exit status

It turns out that after a lot of googling, pulling out of hair and cursing, the answer is rather simple. It seems that the struct “r” and “_impure_ptr” are being redefined in printf.c; so we just need to comment them out from the printf.c file in our project:

#include <semihosting/semihosting.h>
void PrintChar(char c)
/** Required for proper compilation. */
//struct _reent r = {0, (FILE *) 0, (FILE *) 1, (FILE *) 0};
//struct _reent *_impure_ptr = &r;

Rebuild and problem solved.

Your ownCloud

After using Google Drive for a while, I realized that while it is nice to have your data available to the various machines that I use on a daily basis, I didn’t like the idea of someone else controlling access to my data. And especially since Google have a habit of axing perfectly decent applications. Enter ownCloud.

What is it?


OwnCloud is free open source software consisting of both client and server packages, and allows one to set up a rather nifty private “cloud” service (one can also rent accounts or even get a free account although I have not looked at either of these options too closely. There is more info on the website). Please note that there is ALSO a site that provides professional/enterprise services based on the OSS owncloud project.

Your Data on the Go!

To take it for a drive, I cooked up a new VM on my home setup and started playing around with the owncloud server software (written in PHP, so easy to install, questionably secure). The first thing I noticed was that this is not just a file-sync service; there is a web front-end which allows access to upload/download your files, and an application framework that allows developers to write applications that can take advantage of the cloud and sync functionality. But we will get into that a bit later. First, I present what the cloud should look like:


I created a quick SSL certificate to ensure that at least my data was accessed with at least a bit of protection. After logging in, one is presented with the file view:


Before this, I had already downloaded the owncloud client for the Mac, installed and placed a few files in the sync directory (by default this is: /Users/[username]/ownCloud):


I had already created an account on the my owncloud server so as soon as the client logged in, it began to synchronize the files on my Mac with the server:


Pretty neat!  I could also download these files directly from the web interface (nice), all files are versioned on the server (awesome) and owncloud allows you to either share files with another owncloud user on the same server, or provide direct URL links to particular files that you can send via email to someone (bonus!). These shared links also can be password protected and can have an optional expiration date for the share.

The second immediately useful app in owncloud is the calendar:owncloud-cal1

This calendar supports both standard CalDAV and Apple’s Calendar iCal formats as well as various configuration information:owncloud-cal2

Creating an event in the calendar is very similar to many modern calendaring software packages (including Google Calendar):owncloud-cal3owncloud-cal4

Moving an event from one day to another works as one would expect, just drag and drop the event onto a different day.

Weird Behavior and Quirks

I did notice a couple of quirks, with the big one being that file size matters. I tried originally the same technique that I was using with Google Drive, which was: create an encrypted 2 GB partition file using Truecrypt, and then place my files in this encrypted container and synchronize that since file. This was a little bit of a pain with Google Drive, as even a small change to a single file in my encrypted partition would result in transferring the entire 2 GB file to Google Drive. OwnCloud had the same issue but worse: it would throw errors even trying to sync a 2+ GB file (there is a known bug open on this for owncloud). My recommendation would be to avoid using the file sync setup like I was above with large archive files; if anything keep your files small and separate.

As for the calendar, the single most annoying quirk was when event details were displayed, the scroll wheel acted on the main calendar screen instead of the currently open event. This was throughout the entire calendar app. It was very jarring to close an event and be looking at a different month.

Another annoyance is with the user interface in general: there is a general lack of feedback to the user if an operation succeeded or failed. Very annoying.


The overall feeling I get from owncloud is that it is decently written and works fairly well. Since it uses DAV for file transferring and versioning, I would recommend when choosing a server, give it some decent disk performance and CPU(s). The fact that there is an extensible application framework under the hood makes the design of owncloud very attractive as a central cloud data storage system. The interface is slick, works well enough although more feedback about the status of commands would be appreciated. Would I recommend it as an alternative to Google Drive or DropBox?  Absolutely!

Why are we here?

A lofty question, and one that I am unwilling to answer. But I think I can answer “Why is this clog here?”

After many years of having no formal writing outlet, I finally realized that I needed a place where my thoughts could coalesce into tangible form; in this case, words. I came to this realization while testing out our new wiki at work (very neat, definitely give it a look-see if you are at all interested in that sort of thing). I was examining its “blog” capabilities, and thought, “Hey, I could do this, it might even be kinda neat.” That started the wheels of my mind turning, and its logic flowed to the inevitable conclusion: Why not start my own personal “blog”?

But first, what the heck IS a “blog”? Indeed, just what is this bastard child supposed to be? Originally, (and I suppose we all know this by now) “blog” came as a short-hand for “web-log”. This was (as near as I can tell) supposed to be a form of online journal, published in electronic form using that new-fangled technology, The WebTM. Unfortunately, it seems this short-hand form of web log has stuck, so we are left with a throw back view of electronic publishing from the 1990s.

Being different, I called this a clog. The beauty is leaving the precise definition of what exactly a clog is up to you. It could be Chris’ Log, or Captain’s Log, or simply the thing that is backing the Internet pipes up. Whatever it may be to you, this is where I will be detailing what projects I’m working on, reflecting on experiences and musings that I may have, along with a general interest in everything around me.

Welcome to the clog.