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)
{
  SH_SendChar(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,-Map=cdctest.map -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)
{
	SH_SendChar(c);
}
 
/** Required for proper compilation. */
//struct _reent r = {0, (FILE *) 0, (FILE *) 1, (FILE *) 0};
//struct _reent *_impure_ptr = &r;
 
...

Rebuild and problem solved.

PCBs in the Wild!

I have been working on a couple of prototyping boards for general “hey I need a PCB for this oh I have one here” type of projects. Since I’m working more with Surface Mount Technology (SMT) these days and have more of those part in my “stock”, I designed some prototyping boards with this in mind:

PMWVqK05NScwOySx7d_rqpRDDEQCtxBRgKVb5fMP5_Y

w8qOk0l8Cf6-VvLJCz_le5dyH_54Me0o0eiwX4rdkM8

I have sent a few of these to some people that I chat with on the #eevblog IRC channel, and one of them was kind enough to send me an “action shot” of a little LED-based project he used my PCB for!

WP_20150906_16_12_12_Pro

And another one from c4757p:

pcb-in-the-wild-2

 

Power Designs Inc 6050C Display Mod

Here’s a modification that I have been meaning to do for a while. It involved replacing the PCB in one of my power supplies with a modified version designed by me that upgraded the size of the 7-segment LED display.

IMG_5736

I ordered the board from OSHPark. My experience with them has been positive; the turn around time was about 2 weeks and the gold finish is very nice. I’m fine with the colour of the solder mask, however note that the mask is a matte finish rather than the typical “pearl” or “glossy” finish that I am accustomed to seeing on PCBs. Not a big deal, but something to think about. Also, the traces are a bit difficult to see through the solder mask.

IMG_5737 IMG_5739 IMG_5741

I of course did not fully check my notes when throwing together the schematic for this project which resulted in the boards I received having the ‘a’ and ‘g’ segments reversed. A few cut traces and a jumper wires later and all was working as expected.

IMG_5745 IMG_5744  IMG_5742IMG_5743

I originally tried to think of a better way of re-attaching the new display board to the existing display measurement/logic board, but in the end the simplest solution won out and  I just re-soldered the new display board back. The header pitch is 3.81mm and was a total pain to find (yay eBay!).

IMG_5746

The end result is a bright, clear and LARGER display. Here I have contrasted it with the model right after the 6050C, the 6050D which has a larger digital display (and also does not display the measurement mode as the 6050C does, E or I).IMG_5748If I decide to pick up any more of these supplies, I think I’d make the same display modification to them as well. I have been looking at the 6050A models (which can usually be had for cheaper): these might also be good for a “digital makeover” involving removing the analog meter and designing a new digital display PCB.

 

Tektronix DMM 916 Back-light Mod

In keeping with the theme of back-light mods, I have another one here for you all. Recently I was able to get my hands on a well-loved (read: had the piss kicked out of it) Tektronix DMM 916. The specs are nice:

  • 4.75 digits
  • 40,000 count
  • Basic DC accuracy of 0.06%+1 count

The only problem which I didn’t know until I got the meter in my hands was that the back light was horrible:

IMG_5669

Wait, where is that back-light?IMG_5671

Still can’t see it? Turn off the lights!IMG_5670

I’m not sure if this is “factory standard” or just a sign of the age of the unit, but either way it needed some change. The first thing I did was to open up the meter and check out the display:

IMG_5675

There is a small slot on one side of the display assembly where the lamp bulb pokes into the light pipe. At first I thought I might use a standard through-hole LED, but realized that I wouldn’t be able to mount it without either cutting the trace (for the limiting resistor) or cutting the display. I didn’t want to mod the board, in case I or someone else wanted to restore it back to a incandescent bulb. So I choose to use a SMD chip LED and resistor, and build it “tee-pee” style on the top of the display PCB, so that the LED and resistor would stick up vertically into the display light-pipe recess:

IMG_5679

The LED is blue, Digikey part number 475-2816-1-ND with a 270ohm current limit resistor. The bulb sank about 20mA while the LED uses ~18mA, so a bit more efficient. I’m still not sure about the blue, but I figured it matches the theme of the case, so why not:

IMG_5680

And as is evident, it is much brighter even with the lab lights on. Curiously, it is not much more legible in the dark in terms of the digits on the screen as I would have thought.

HP8642B Signal Generator Mod

A quick mod post here. I saw this post by Kerry Wong, and having the same hardware myself (and finding the backlight ridiculously dim) I thought this mod was a great idea and wanted to try it myself. First, here is a shot of the original backlight:

HP8642B-OrigBL

I pulled the front panel apart, and decided to use white SMD LEDs for my replacement mod:

IMG_5664

After soldering up everything and reassembling (and of course cursing a lot due to the number of defective white LEDs that I didn’t realize that I had), the result is beautiful!

 

HP8642B-Mod

And here is the same Easter egg that Kerry found (hold down the MSSG key while powering on the unit):

HP8642B-ModBL1

 

Function Generator Shenanigans

So my problem turned out to be not the saving of the status of the HDG2002, but actually doing the following:

  • Go to Utility, select System Status
  • Toggle the “Startup” option to “Last” (to set the function generator to restore to the last setup before power-off I assumed!)
  • Exit back to the main channels screen
  • Power Cycle the generator using the power button on the front panel.

When the HDG2002 reboots, POOF! No more main screen after the Hantek logo briefly flashes on screen. So what happened? It turns out that the problem is actually that the BACKLIGHT is set to level 0 by doing the above procedure. I found this out by logging into the serial console and finding the /dso/app directory. In here, there are a couple of “test” binaries:

test_beep
test_bkl

I tried them both but the test_bkl was the interesting one. When I ran it with the following options:

./test_bkl on 105

Poof the display popped back on! Of course on reboot it turned back off again. So after temporarily re-enabling the backlight, I went back into Utility -> System Status -> Startup and set it to Default, power cycled and boom, back in business no worries.

Well I guess there are still a few bugs in the firmware.  Please note that you can run into this bug REGARDLESS OF WHETHER YOU CRACK THIS FUNCTION GENERATOR OPEN OR NOT, and it has nothing to do with modifying the HDG2002. Except that if you don’t crack it open after you do this, you seemingly have no way to recover.

Hope this helps someone else!

Signal Generator

This is an acquisition that I purchased earlier in the year (a great bargain off EBay!).

IMG_5570

I decided to have a look inside it (not having any clue what goes into a function generator of this caliber.

IMG_5569 IMG_5572

Nice idea of putting the wiring schematics on the cover of the unit, as that way one can always figure out how to put the whole thing back together. And then I saw this:

IMG_0807

Wow.  So I decided to save a deeper dive into the unit for a later date. I built a stand for the generator and called it a day.

IMG_5574 IMG_5576 IMG_0810 IMG_0809

Lab Frequency Standard

I’ve been rather silent for a couple of months now, but I have been busy! This time it is a laboratory frequency standard! This project is modeled on the work done by Gerry Sweeney over on his blog. I have been assembling the various pieces needed for this build for several months now, and just recently decided to take the plunge and do the build.

It started off with a Rubidium frequency standard from Frequency Electronics, the FE-5680A. These can be purchased used off of EBay for ~120$ CAD. Buyers beware: I had success with my first unit, but others have not been so lucky. There are numerous configurations of this unit, with various features present or missing, including the 10MHz sine output. This project requires at a minimum the 10MHz out. Some units will have this via a dedicated BNC or SMA connector, others (like my unit) will have it present on a pin from a DB-9 connector.

The second most important component is the case which will house the completed project. I was originally going to choose a basic project box, but Gerry was pointed towards a distribution amplifier for video. Since the signal from the FE-5680 would need to be replicated on multiple outputs to be useful, some sort of amplifier was going to be needed. It just so happens that 10MHz lies in the range of off the shelf video amplifiers, and the model I got by Extron, the ADA 6 Component was perfect for the job AND was only 40$ on EBay.

Other than just putting the Rb standard in a box with a bunch of outputs, I wanted to have an indicator LED that lit up when the Rb was locked on 10MHz. My particular unit will pull a pin on the DB-9 connector LOW when the Rb is locked. A quick transistor circuit with a regulator feeding off a 17V supply and I had a small prototype board completed:

IMG_5579

Once I had the “interface circuit” figured out, I started laying out what the mechanical construction of the project would look like. I decided to use the case itself as a heat-sink and seeing as how the Rb standard likes to be warm (haha, non-heat-sinked, the case measures ~65C), I decided to mount it to the top half of the box:

IMG_5577 IMG_5578

The Rb standard requires 2 different power inputs: 5V and15-18V. The distribution amplifier also required 2 different power rails: 6.2V and 17V. I decided that the easiest way to power it all would be to pick up a 18.4V laptop power brick, rip the guts out, and add a LM317-based regulator to get the 6.2V to my existing interface circuit. I discovered that the Extron was actually using the 17V rail to power a buck converter-inverter circuit, so the 18.4V input didn’t change it too much.

IMG_5580 IMG_5581 IMG_5585 IMG_5587 IMG_5588 IMG_5589 IMG_5590 IMG_5591

I wired up a small wiring harness to go from the Rb standard’s DB-9 connector to the various parts of the interface board. I then modified the amplifier board to change the input/output impedance from 75ohm to 50ohm:

IMG_5582

Not having any 50ohm resistors handy (and they’re damn expensive as well!), I used 2 100ohm resistors in parallel stacked on top of each other:

IMG_5584 IMG_5583

I soldered in the coax to the center channel, and then jumped the signal from the center channel to the 2 other ones with some wire. This means I will have a total of 18 10MHz outputs on this standard 🙂

The testing and assembly:IMG_5593 IMG_5597 IMG_5598 IMG_5600 IMG_5601

I ran into one problem when testing, which was a deformed lower part of the sine wave on the outputs (all of them). You can see it on the oscilloscope to the upper right:

IMG_5602

I started probing around (“THOU SHALL CHECK VOLTAGES!”), and discovered that the negative rail to the op-amps was running at ~0.3V, which was not right. Running back through the circuit on the amplifier board I realized that I had flipped the 6.2V and 17V rails on the input connector after splicing it into my interface board. After switching them back, everything was working as expected!

IMG_5604

Turns out my frequency counter on the upper right is probably off by 0.5 Hz… not too shabby. There are a couple of things that need to be done: adding a heat-sink to the top of the case for extra dissipation and adding some passive ventilation holes on the top/back of the case and on the bottom.