Chinese STM32 Oled soldering controller – part2

By | February 14, 2018

Development environment

Lately I have been using the ST’s STM32CubeMX for pin, peripherals and midlleware configuration and initial project setup, and Ac6’s System Workbench for STM32 for code editing and debugging. They are both free and cross platform.

Starting with the STM32Cube software and working from the schematic from the previous post, we first create a project defining the processor type and continue by defining our inputs and outputs as follows:

Digital inputs

  • 3 inputs for the rotary switch plus button – configuration not critical in terms of speed or input type
  • 1 input for the wake from sleep functionality – “

Analog inputs

  • Thermocouple sensor – requires fast readings so best to use DMA
  • Ambient temperature sensor – not critical but since we already have DMA lets go with that
  • Input voltage sensing – same as above
  • Voltage reference – not used, don’t know what was the designer idea with it, probably for ADC calibration but since the STM32F103 ADC has an internal cal system lets just go with that

Digital outputs

  • Buzzer – not critical in terms of speed or output type
  • Iron heating element – using PWM so we can modulate its power
  • Oled’s CS, RESET and DC pint – configured as fast pins


  • Oled’s MOSI and CLK

We end up with something like:

Naming the pins allows us to refer to them by their name later while coding.

Next we can take care of the clocks. Not much to say here except the this board has no external oscillator so we must configure and use the internal one.

Next we need to configure the peripherals, ADC, SPI, Timers, etc. I won’t go into to much detail about this step, we don’t need to be certain about all the settings since we can always change them later.

For the ADC conversion I opted for the dual combined simultaneous ADC with DMA.

For PWM generation I had to keep the frequency lower than I would like (about 2KHz) due to the Mosfet and driver circuit used which some initial testing shown to have quite slow switching speed.

With the initial project setup we just need to tell the software to generate code for the SW4STM32 and we can choose to open it from there.

First hardware flash

For flashing and debugging the STM32’s I normally use the cheapo st-link clones from aliexpress, they are cheap, but I had two fail on me already (see below).

The board I received had the read protection enabled so I wasn’t able to flash it from within eclipse, I first had to remove the protection using openocd:

openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c “init” -c “halt” -c “stm32f1x unlock 0” -c “shutdown”

On windows the same can be done using the st-link utility

After that, only one small edit needs to be done to the eclipse project:

Go to project->properties->edit->debugger->show generator settings->reset mode, change to software system reset.

Pressing the “run” button should now flash the firmware with no issues.

The problem with the cloned st-links

The problem seems that they come with an STM32F101 working outside it’s specs (according to ST’s the USB on the 101 is not supported), so they eventually fail.

From the three I bought, two failed, to fix them I had to remove the 101 microprocessor, solder a new STM32F103 and flash new st-link firmware (after having a hard time finding it).

What’s next?

On the next post I will present the finished firmware and a few minor hardware changes I made to suit my needs

7 thoughts on “Chinese STM32 Oled soldering controller – part2

  1. Cidi Rome


    I’m trying to adapt this project to use with the V3 hardware…
    The problem is that I’m not used to this SDK (and hardware, did some arduino based things)… Can you point me out to the file where the pins are setup?

    For instance: I fount this function
    that seems to make reference to variables or constants, but I can’t find where they are set…

    You seem to be Portuguese, you should be able find me on FaceBook, I’m Cidious Romeus


    1. Cidi Rome


      I am now starting feeling at home with Eclipse, but while trying to build your project without changing yet anything and I get this error:

      c:/program files (x86)/gnu tools arm embedded/8 2018-q4-major/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: w_log.c:(.text.log+0x74): undefined reference to `__errno’

      I’ve tried with toolchains 2018-q4-major, 8.2.1-1.2 and 8.2.1-1.7, all of them throw the same errors based on w_log and __errno

      Any Ideas?


      1. jose Post author

        Try this:edit the project properties under C/C++ Build > Settings > Tool Settings > MCU GCC Linker > Libraries as follows:

        – Uncheck ‘Use C math library (-lm)’

        – Add the math library manually to the libraries list by simply adding ‘m’

        This way the ‘-lm’ part is moved to end of the make file instruction and it should compile properly.

        1. Cidi Rome


          Thank you for your answer.
          I believe that I’ve seen some similar instructions elsewhere, the thing is that I can’t find the option to uncheck “Use C math libraty (-lm)”. I have similar other use/don’t use options in General and Miscellaneous , but not on libraries.
          Please see the picture I’m attaching.

          1. Cidi Rome

            Thank you for your help.

            I manage to compile it just adding the “m” was enough even without the option to deselect the “lm”.

            Now I’m in the process of converting the ports interpreting your schematic, the one from V3 and my own board.


          2. Cidi Rome

            To keep my progress updated…
            Before starting “messing” with your code, I managed to get the display working with other library that I believe is very close to the one you use, but I’m not being able to do the same with your code.
            I modified plenty of code related to the port configurations because it is assumed that some pins are in the same port and that isn’t always true.
            Changed the pins to the V3 layout (there are some that I don’t know what they are), but presently I’m focusing on the Oled pins and HSPI, that in V3 is HSPI2.
            In fact V3 has a 1,3 inch screen do I used the SH1106_FIX define despite not knowing what it does when sending the command 02 instead of 00 in the update_display function.


          3. Cidi Rome


            I made some more progress, I can already display something, I’m now addressing the ADC inputs.
            I noticed that there are usage of some constants defined inside main.h in stm32f1xx_hal_msp.c, but this file doesn’t seem to be included in anywhere in the project.
            Is this file an old remain that is not used anymore?
            In witch file are the ADC pins selected?


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.