STM32F1xx micro-controller C firmware template
Go to file
King Kévin 517f58d463 application: limit lid power to 50% 2020-12-08 23:15:21 +01:00
lib oled_text: add library to show text on SSD1306 OLED display 2020-12-07 19:12:41 +01:00
libopencm3@cb0661f81d update libopencm3 2020-02-17 11:43:47 +01:00
.gitignore cherry-pick from busvoodoo branch, part 2 2018-02-18 15:20:01 +01:00
.gitmodules remove STM32duino-bootloader 2016-08-14 19:03:17 +02:00
Doxyfile doc: fix documentation 2020-01-03 00:16:59 +01:00
LICENSE.txt add GPLv3 license file 2018-02-13 15:14:10 +01:00
README.md application: working WIP firmware to control thermocycler 2020-12-07 19:14:00 +01:00
Rakefile Rakefile: allow to specify CPUTADIP to use SWD with CKS32 2020-06-24 11:57:45 +02:00
application.c application: limit lid power to 50% 2020-12-08 23:15:21 +01:00
application.ld ld: use a MCU with 128 KB of flash (e.g. original STM32) 2020-12-07 18:56:33 +01:00
bootloader.c bootloader: disable clocks after domains used 2020-06-24 11:57:22 +02:00
bootloader.ld ld: use a MCU with 128 KB of flash (e.g. original STM32) 2020-12-07 18:56:33 +01:00
global.c global: fix ADD_SAFE macro and add function returning sum 2020-12-07 19:10:04 +01:00
global.h global: fix ADD_SAFE macro and add function returning sum 2020-12-07 19:10:04 +01:00

README.md

This firmware template is designed for development boards based around STM32 F1 series micro-controller.

project

summary

describe project purpose

technology

described electronic details

board

The current implementation uses a core board.

The underlying template also supports following board:

Which board is used is defined in the Makefile. This is required to map the user LED and button provided on the board

The ST-LINK V2 mini clone has SWD test points on the board. Because read protection is enabled, you will first need to remove the protection to be able to flash the firmware. To remove the read protection (and erase flash), run rake remove_protection while a SWD adapter is connected.

The Altera USB-Blaster clone has a pin header for SWD and UART1 on the board. SWD is disabled in the main firmware, and it has read protection. To be able to flash using SWD (or the serial port), the BOOT0 pin must be set to 1 to boot the system memory install of the flash memory. To set BOOT0 to 1, apply 3.3 V on R11, between the resistor and the reference designator, when powering the device. The red LED should stay off while the green LED is on. Now you can remove the read protection (and erase flash), run rake remove_protection while a SWD adapter is connected.

ST 339 is a quad voltage comparator. I don't know what it compares.

LN 393 is a dual comparator. I don't know what it compares.

there is also an external reference (REF1). this is probably for the MAX1247 (only the MAX1246 has an internal voltage reference).

MAX1247 is a 4-channel 12-bit ADC. it is used to measure the temperatures.

there are four 2.2 kOhm thermistors. one side is connected to REF1, the other to a MAX1247 channel.

  • TH4: on the sink, connected to CH2 through R8 (2702), and COM through R4
  • TH3: in the tube, connected to CH3 through R7 (2702), and COM through R3
  • in the top of the tub heating bed, connected to CH0
  • in the bottom of the tub heating bed, connected to CH1

heating block MBLK-008:

  1. NC
  2. VCC
  3. LN393 OUTPUT-A
  4. MAX1247 DIN
  5. MAX1247 DOUT
  6. MAX1247 SCLK
  7. MAX1247 nCS
  8. ST339 OUTPUT-3
  9. LK1 jumper (missing), other side connected to ground
  10. LK2 jumper (missing), other side connected to ground
  11. LK3 jumper (present), other side connected to ground
  12. LK4 jumper (present), other side connected to ground
  13. ground
  14. LN393 OUTPUT-A through 10 kOhm resistor (not sure what this is used for, probably not just to pull)

heated lid, 12 kOhm NTC thermistor, 3-pin (pin 1 has notch):

  1. thermistor lead 1
  2. thermistor lead 2
  3. chassis

thermocouple (e.g. peltier elements) controller board, MBLK019, 2x3 pin plug (IDC numbering):

  1. red, VCC
  2. red/green, sink to control IC/TR 2/6
  3. red/black, sink to control IC/TR 1/4
  4. red/blue, connected to pin 6
  5. red/brown, sink to control IC/TR 3/5
  6. black, connected to pin 4

front control panel, 1x5 connector:

  1. ground
  2. play/pause indicator, green LED anode
  3. play/pause indicator, orange LED anode
  4. power indicator, red LED
  5. play/pause button, connected to ground when pressed

fan:

  1. red: 12V
  2. black: ground

MBLK-078, power + heater, 2x2 connector:

  1. red, 12V
  2. black, ground
  3. yellow/red, optocoupler anode for triac controlling the lid heater
  4. yellow/black, optocoupler cathode for triac controlling the lid heater

SSD1306 OLED screen:

  1. GND
  2. VDD
  3. SCK
  4. SDA

power for thermocouples

use a 12V xA power supply. ideally it would be an adjustable constant current supply (probably what the original power supply was), but using PWM on constant voltage is good enough for thermocouples, even if less efficient.

I created a custom board with:

  • 2 relays to act as h-bridge, allowing to invert the voltage on the thermocouples
  • 1 power MOSFET, to PWM the power
  • 1 optocoupler, to control the MOSFET
  • an IDC 2x5 connector, to re-use to cable

relay 1:

  • COM: thermocouple yellow
  • NC: OUT
  • NO: 12V dedicated power supply
  • VCC: 5V
  • GND: ground
  • IN: IDC pin 3,4

relay 2:

  • COM: thermocouple orange
  • NC: OUT
  • NO: 12V dedicated power supply
  • VCC: 5V
  • GND: ground
  • IN: IDC pin 5,6

power nMOS (FQP30N06L, 60V 32A):

  • gate: PC817 optocoupler source, pulled low (100 kOhm to ground)
  • drain: OUT from relay
  • source: ground

IDC 2x5 connector:

  • 1,2: 5V to power the relays and optocoupler
  • 3,4: input to relay 1, active low (when sinking)
  • 5,6: input to relay 2, active low (when sinking)
  • 7,8: input optocoupler controlling MOSFET, active low (when sinking)
  • 9,10: ground

PC817 optocoupler:

  • source: power nMOS gate
  • drain: 12V dedicated power supply
  • anode: 5V though 330 Ohm
  • cathode: IDC pin 7,8

connections

All pins are configured using defines in the corresponding source code. Connect the peripherals the following way.

heating block MBLK-008 CO IDC 7x2:

  1. NC
  2. 3.3V
  3. PB3
  4. PB15 SPI2_MOSI
  5. PB14 SPI2_MISO
  6. PB13 SPI2_SCK
  7. PB12 SPI2_NSS
  8. PB4
  9. PB5
  10. PC14
  11. PC15
  12. PB1
  13. ground

heated lid, 12 kOhm NTC thermistor, 3-pin (pin 1 has notch):

  1. PA0/ADC1_CH0, pulled up to 5.0V by 10 kOhm resistor
  2. ground
  3. earth

thermocouple controller board, MBLK019, 2x3 IDC connector:

  1. 3.3 V
  2. PA1
  3. PA2
  4. PA3
  5. PA4
  6. ground

front panel:

  1. ground
  2. PA5, with 330 Ohm inline resistor
  3. PA6, with 330 Ohm inline resistor
  4. PA7, with 330 Ohm inline resistor
  5. PB0

fan:

  1. 12V front board power supply
  2. power nMOS drain power nMOS source. ground power nMOS gate. PA15, pulled up externally to 5V

MBLK-078, power + heater, 2x2 connector:

  1. LM7805 in
  2. ground
  3. 5V though 330 Ohm
  4. PA10

SSD1306 OLED screen:

  1. ground
  2. 3.3 V
  3. PB6/I2C1_SCL, pulled up to 3.3V by external 10 kOhm resistor
  4. PB7/I2C1_SDA, pulled up to 3.3V by external 10 kOhm resistor

thermocouple power supply control board. IDC 2x5:

  • 1,2: 5V
  • 3,4: PB10
  • 5,6: PB11
  • 7,8: PB9
  • 9,10: ground

code

dependencies

The source code uses the libopencm3 library. The projects is already a git submodules. It will be initialized when compiling the firmware. Alternatively you can run once: git submodule init and git submodule update.

firmware

To compile the firmware run rake.

documentation

To generate doxygen documentation run rake doc.

flash

There are two firmware images: bootloader and application. The bootloader image allows to flash the application over USB using the DFU protocol. The bootloader is started first and immediately jumps to the application if it is valid and the DFU mode is not forced (i.e. by pressing the user button on the board or requesting a DFU detach in the application). The application image is the main application and is implemented in application.c. It is up to the application to advertise USB DFU support (i.e. as does the provided USB CDC ACM example).

The bootloader image will be flashed using SWD (Serial Wire Debug). For that you need an SWD adapter. The Makefile uses a ST-Link V2 programmer along OpenOCD software (default), or Black Magic Probe. To flash the booltoader using SWD run rake flash_booloader. If the development board uses the CKS32 chip STM32 alternative, use CPUTAPID=0x2ba01477 rake flash_booloader.

Once the bootloader is flashed it is possible to flash the application over USB using the DFU protocol by running rake flash. To force the bootloader to start the DFU mode press the user button or short a pin, depending on the board. It is also possible to flash the application image using SWD by running rake flash_application.

debug

SWD also allows to debug the code running on the micro-controller using GDB. To start the debugging session run rake debug.

USB

The firmware offers serial communication over USART1 and USB (using the CDC ACM device class).