Projekt

Obecné

Profil

Akce

STM32 UNO programmer guide

Documentation version 1.0, 13 November 2026. Applies to the STM32-UNO_pcb files exported on 2026-11-13. This does not establish the manufacturing revision of an assembled board.

STM32-UNO is a development board based on the STM32F446RET6 microcontroller. It provides GPIO, analog inputs, headers in the UNO arrangement, mikroBUS, microSD, I2C, and direct USB. This guide explains how to prepare a first project, select the correct pins, and connect peripherals. The default programming environment is C with STM32 HAL.

Documentation home | Tutorial authoring notes

Basic rules

  • Use GPIO and analog signals in the 0 to 3.3 V range in these tutorials. A 5 V supply pin does not specify the GPIO voltage.
  • Every external device must share GND with the board.
  • For initial programming and debugging, use an external ST-LINK and the SWD interface on U5.
  • Select STM32F446RET6 in the project rather than a ready-made profile for another board with a similar processor.
  • Use names such as PA0, PB0, and PC0. Arduino pin numbers such as D0 and A0, or macros such as LED_BUILTIN, are not defined in these source files.
  • No HSE crystal is connected in the schematic. Use HSI for initial projects; X1 is a 32.768 kHz crystal for the RTC only.

Hardware overview

Part Programmer-relevant feature Source
U2 STM32F446RET6, Cortex-M4F, LQFP64 S1, B1
MCU memory 512 KiB Flash, 128 KiB SRAM; maximum CPU clock 180 MHz D1
Logic MCU supply and main logic levels: 3.3 V S1, p. 1
Clocks Internal HSI; X1 at 32.768 kHz on PC14 and PC15; PH0 and PH1 unconnected S1, p. 1
U5 SWD, reset, optional SWO, and USART2 S1, p. 4
USB-C D- on PA11, D+ on PA12; direct MCU USB S1, p. 1
SW1 Reset through NRST, active low S1, p. 1
SW2 User button on PA0, pressed = 0 S1, p. 1
Digital indicators Red and blue LEDs on 12 GPIOs; shared rails controlled by JP1 and JP2 S1, p. 1
CN1 I2C1, powered from PWR_USB S1, p. 2
J2 microSD wired to SPI2, card detection on PC8 S1, p. 1
mikroBUS SPI1, USART6, I2C3, analog input, PWM, reset, and interrupt S1, p. 5
RTC X1 crystal and B1 battery holder connected to VBAT S1, p. 1

MCU capabilities and maximum ratings are not the board's default settings. The first project below runs from HSI at 16 MHz. For MCU specifications, see the ST DS10693 datasheet.

Power supply and connecting modules

Supply rails

In the schematic, USB VBUS feeds the PWR_USB rail through diode D2. Converter U1 also supplies this rail from the external input. Regulator U3 generates +3.3V from it. Pins labelled 5 V are connected to PWR_USB; when powered from USB, this rail includes the diode voltage drop, so an exact 5.00 V is not guaranteed.

For initial experiments, power the board through USB-C with no DC supply or shields connected. Also connect the USB side of the ST-LINK. If the probe provides a power output, do not automatically connect it to the board; U5/3 is the target voltage reference. Follow the wiring instructions for your particular probe.

DC1 feeds VIN through D1. The VIN pin on the power header is downstream of this diode, so powering through the header bypasses D1 protection. The schematic includes the note "Operating up to 28 V", but no validated operating range for the complete assembled board or available module current is specified. Do not treat 28 V as a recommended user supply voltage. Before writing a tutorial using a DC supply, verify DC1 polarity, the voltage range, regulator temperatures, and current headroom.

When connecting sensors, check their supply voltage and data signal voltage separately. The CN1 power pin is connected to PWR_USB, while the onboard I2C pull-ups connect to 3.3 V. The four-pin connector alone therefore does not guarantee compatibility with every 3.3 V module. External pull-ups to 5 V may change the voltage level of the entire bus.

Analog signals and reference

The MCU VDDA/VREF+ supply is connected to 3.3 V. Do not exceed VDDA at ADC inputs, and use the actual reference voltage when converting readings to volts. The ref net on the headers is not connected to MCU VREF+ in the schematic. It is not an input for changing the ADC reference.

H2 pin 1 is unconnected, pin 2 is ref, and pin 3 is 3.3 V. A jumper between pins 2 and 3 therefore connects ref to 3.3 V. It does not switch the GPIO supply between 3.3 V and 5 V.

First connection and programming

What you need

  • The board with no expansion modules connected, and a USB-C data cable.
  • An external ST-LINK providing SWDIO, SWCLK, GND, and a target voltage reference; NRST is also recommended.
  • A cable or adapter matching the U5 connector actually fitted. The BOM lists a 2 x 7 connector with 1.27 mm pitch; page 1 of the schematic includes a note about a future change to 2.54 mm.
  • STM32CubeIDE, STM32CubeMX for project configuration, and the STM32CubeF4 package. You can also program the board separately using STM32CubeProgrammer.

Connecting the ST-LINK

The numbers below are U5 contact numbers in the schematic, not the numbers on an arbitrary probe connector. Identify pin 1 from the marking on the actual PCB or connector. Do not reverse the cable or offset it by one row.

U5 pin Board net Probe connection
1, 2 Unconnected Leave open
3 +3.3V VTref / T_VCC, target reference
4 PA13 / T_SWDIO SWDIO
5 GND GND
6 PA14 / T_SWCLK SWCLK
7 GND GND
8 PB3 / T_SWO SWO, optional
9, 10 Unconnected Leave open
11 GND GND / GNDDetect, depending on the probe
12 NRST NRST
13 PA3 / USART2_RX Probe serial adapter TX, optional
14 PA2 / USART2_TX Probe serial adapter RX, optional

U5 wiring is shown on page 4 of the schematic. Signals 13 and 14 are named from the MCU's perspective: PA2 transmits and PA3 receives. The ST-LINK must support a virtual COM port if you want to use this feature; the serial connection is not required for SWD.

  1. With power disconnected, connect GND, VTref, SWDIO, SWCLK, and NRST.
  2. Power the board through USB-C and connect the ST-LINK to the computer.
  3. In STM32CubeProgrammer, select ST-LINK and the SWD interface. Start at a lower frequency, such as 100 to 400 kHz.
  4. Connect and verify that the tool recognizes the target MCU and can read Flash.
  5. If the connection fails, check wiring and the reference voltage, then try connecting under reset with NRST connected.

Creating your first project

  1. In STM32CubeMX, create a project by selecting the STM32F446RET6 MCU. Depending on your tool version, the configurator may be standalone or accessible from the development environment.
  2. Keep Serial Wire enabled in the SYS configuration. Reserve PA13 and PA14 for debugging.
  3. In RCC, select HSI as the SYSCLK source without PLL, giving 16 MHz. Leave HSE disabled. The first example does not need LSE or RTC.
  4. Configure PB0 as GPIO Output, push-pull, no pull-up or pull-down, low speed, initial level 0.
  5. Configure PA0 as GPIO Input without internal pull-up or pull-down. External resistor R3 already provides a 10 kΩ pull-up.
  6. Generate the project for STM32CubeIDE. This guide assumes STM32F4 HAL and the usual generated functions HAL_Init(), SystemClock_Config(), and MX_GPIO_Init().
  7. Insert the blinking example below, build the project, and start debugging through ST-LINK/SWD.
  8. After programming, let the application run without stopping at a breakpoint. Check the changing PB0 level and the corresponding LED indication.

For a standard application without a custom bootloader, Flash starts at 0x08000000. ELF and HEX files contain addresses; for a raw BIN file, set the correct start address. Do not copy an offset from another board. For initial projects, leave memory protection and option bytes unchanged.

USB and the bootloader

USB-C is not a USB-to-UART adapter or an onboard ST-LINK. Connecting it may not create a COM port. USB CDC or another USB class requires appropriate firmware and correctly configured USB clocks.

According to ST AN2606, STM32F446xx chapter, the factory USB DFU bootloader in STM32F446 requires an external HSE clock. PH0 and PH1 are unconnected in the supplied schematic, so USB DFU is not the default method for initial programming of this board. The 32.768 kHz X1 crystal does not meet this requirement.

BOOT0 is pulled to GND through R2, 10 kΩ. SW2 controls PA0, not BOOT0. Entering the system bootloader through BOOT0 and PB2/BOOT1 requires the correct levels at reset and access to BOOT0; the ordinary user button does not invoke it. UART bootloader pins may also differ from the application's UART pins. Prefer SWD for application recovery.

Connector pin map

The tables use schematic pin numbering. They do not define a top view or cable orientation. Locate pin 1 on the board before making physical connections. The schematic labels CP7 and CP9 are net-name typos connected to MCU pins PC7 and PC9; use PC7 and PC9 in software.

CONN_DIG1

Pin MCU Basic use Indicators
1 PA1 GPIO D_B6, D_R6
2 PB0 GPIO, first blinking example D_B1, D_R1
3 PB1 GPIO D_B4, D_R4
4 PB2 GPIO; also BOOT1 during boot-mode selection D_B5, D_R5
5 PB4 GPIO D_B3, D_R3
6 PB5 GPIO D_B2, D_R2
7 PB6 USART1_TX, AF7 No digital indicator pair
8 PB7 USART1_RX, AF7 No digital indicator pair

CONN-DIG2

Pin MCU or net Basic use Indicators
1 PB8 / I2C1_SCL I2C1 SCL, AF4 3.3 kΩ pull-up to 3.3 V
2 PB9 / I2C1_SDA I2C1 SDA, AF4 3.3 kΩ pull-up to 3.3 V
3 ref Net optionally connected to 3.3 V through H2 Not MCU VREF+
4 GND Ground None
5 PC10 SPI3 SCK, AF6 D_B11, D_R11
6 PC11 SPI3 MISO, AF6 D_B12, D_R12
7 PC12 SPI3 MOSI, AF6 D_B10, D_R10
8 PB3 GPIO or SWO D_B8, D_R8
9 PD2 GPIO for software-controlled SPI3 CS D_B9, D_R9
10 PC13 GPIO D_B7, D_R7

The PD2/SPI3SSEL net name does not imply a hardware SPI3_NSS alternate function. In this circuit, drive PD2 as a normal GPIO output for CS. Use PC13 for slow signals and observe its specific current and speed limits in the datasheet.

CONN-ANALOG

Pin MCU Channel for the suggested ADC1 configuration Other use
1 PA4 IN4 DAC_OUT1
2 PC4 IN14 GPIO
3 PC3 IN13 GPIO
4 PC2 IN12 GPIO
5 PC1 IN11 GPIO
6 PC0 IN10 GPIO

These signals do not automatically map to Arduino A0 through A5. A separate board variant would have to define numbering for the selected Arduino core.

CONN-POWER and H2

CONN-POWER pin Net Meaning
1 VIN Converter input, shared rail downstream of D1
2, 3 GND Ground
4 PWR_USB Rail nominally labelled 5 V
5 +3.3V 3.3 V regulator output
6 NRST Reset, active low
7 ref Optional connection to 3.3 V through H2
8 Unconnected No function
H2 pin Net
1 Unconnected
2 ref
3 +3.3V

CN1 for I2C

Pin Net Function
1 GND Ground
2 PWR_USB Module supply; not the 3.3 V rail
3 PB9 / I2C1_SDA Data
4 PB8 / I2C1_SCL Clock

The contact labelled 0 in the schematic connects to GND; it is not a fifth cable signal. The BOM specifies JST BM04B-SRSS-TB. The same I2C signals are available on CONN-DIG2, so devices on both connectors share one address space.

mikroBUS CONN-MB1

Function names follow the mikroBUS symbol in the schematic. Determine physical orientation from the actual socket. CONN-MB1 is listed in the pick-and-place file but has no separate entry in the supplied BOM; verify that the sockets are fitted.

mikroBUS signal MCU or net Suggested configuration
AN PC5 ADC1 IN15
RST PA9 GPIO output for module reset; not board NRST
CS PA15 GPIO output for software-controlled CS
SCK PA5 SPI1 SCK, AF5
MISO PA6 SPI1 MISO, AF5
MOSI PA7 SPI1 MOSI, AF5
3V3 +3.3V Supply
GND, left GND Ground
PWM PA10 For example, TIM1 CH3, AF1
INT PB10 GPIO input or EXTI10
RX PC7 USART6 RX, AF8
TX PC6 USART6 TX, AF8
SCL PA8 I2C3 SCL, AF4
SDA PC9 I2C3 SDA, AF4
5V PWR_USB Supply
GND, right GND Ground

I2C3 has its own 3.3 kΩ pull-ups to 3.3 V. The mikroBUS I2C3 bus is separate from I2C1 on CN1. When using PA15 and PB4 as GPIOs, keep debugging in Serial Wire mode so that full JTAG does not reserve them.

Buttons and LEDs

User button

SW2 connects PA0 to GND. R3 pulls PA0 up to 3.3 V, so released = 1 and pressed = 0. LED3 and R22 also connect to this net; LED3 lights when the net is pulled low. Use PA0 as an input in basic tutorials. Configuring PA0 as an output driven high would create a conflict between the output and ground when the button is pressed.

For an interrupt on a press, select EXTI0 on the falling edge and debounce the button. For wake-up from a low-power mode, check the required polarity separately; wake-up functionality is not the same as ordinary EXTI configuration.

Reset and power indicators

SW1 pulls NRST to ground and restarts the MCU. LED_RESET1 indicates that NRST is low. LED_PWR1 connects to the 3.3 V rail. LED_PWR2 is controlled by transistor Q2 according to VIN; it is not a user LED controlled by a GPIO. Do not use these indicators as substitutes for a software-controlled status LED.

Digital level indicators

Twelve GPIOs have blue and red LED pairs. JP1 connects the shared ledUp rail to 3.3 V, and JP2 connects ledDwn to GND. With both jumpers fitted, the schematic indicates blue for logic 0 and red for logic 1. D_B13 and D_R13 belong to the shared rails; they are not additional independently controlled GPIOs.

Both rails can be enabled for ordinary GPIO observation. Remove both jumpers for analog measurements on these pins, weak signal sources, low-power operation, or fast buses. The LEDs and resistors load the signals and do not reliably indicate a high-impedance state. PWM may produce a mixture of colors; color alone does not demonstrate the correct frequency or duty cycle.

Removing the jumpers breaks the direct connections between the shared rails and power or ground, but does not disconnect the individual LEDs from the GPIOs. The rails remain interconnected through the indicator circuits. For accurate analog measurements, prefer the dedicated analog inputs PC0 through PC4 or PA4.

Peripherals and shared functions

Use MCU instance Wiring
I2C on CN1 and the digital header I2C1 PB8 SCL, PB9 SDA
mikroBUS I2C I2C3 PA8 SCL, PC9 SDA
mikroBUS SPI SPI1 PA5 SCK, PA6 MISO, PA7 MOSI, PA15 software-controlled CS
microSD SPI2 PB13 SCK, PB14 MISO, PB15 MOSI, PB12 software-controlled CS
SPI on the digital header SPI3 PC10 SCK, PC11 MISO, PC12 MOSI, PD2 software-controlled CS
UART on CONN_DIG1 USART1 PB6 TX, PB7 RX
UART on U5 USART2 PA2 TX, PA3 RX
mikroBUS UART USART6 PC6 TX, PC7 RX

Alternate functions and analog channels follow DS10693, Tables 10 and 11. Always select the specific pins in CubeMX; automatically selecting a different pair does not change the PCB wiring.

PB3 is shared by U5/8, CONN-DIG2/8, and the LED indicators. Do not use another function on it while using SWO. PA9, used for mikroBUS RST, cannot simultaneously serve as the standard OTG_FS_VBUS input. PA10, used for mikroBUS PWM, cannot simultaneously serve as OTG_FS_ID. U5 is a connector for an external probe, not another onboard processor.

microSD

Slot J2 is wired for SPI2, not four-bit SDIO. Contact numbers below refer to the J2 slot symbol.

J2 contact Function in SPI mode Net
1 DAT2, unused in SPI Pull-up
2 CS PB12
3 DI / MOSI PB15
4 VDD +3.3V
5 CLK PB13
6 VSS GND
7 DO / MISO PB14
8 DAT1, unused in SPI Pull-up
9 CDN detection contact PC8

In addition to FatFs, the file system needs a disk I/O layer that controls the SD card over SPI. Enabling FatFs alone does not provide an SPI SD card driver. During initialization, keep CS high and use SPI mode 0, eight-bit data, MSB first, and a clock no higher than 400 kHz. Increase the speed only after successful initialization.

PC8 is the detection net with a pull-up. Verify the actual switch polarity when inserting a card in the fitted slot before basing application behavior on it. Finish writes and close files before removing the card. Do not simultaneously use PB14 and PB15 for USB HS.

RTC and backup power

The RTC can use the 32.768 kHz LSE clock from X1. Reserve PC14 and PC15 for the oscillator when doing so. B1 supplies backup voltage to VBAT; it does not keep the entire board running without main power. No battery charger is shown in the schematic. Check the cell type, polarity, and voltage against the actual holder and the VBAT range in the datasheet. Do not set the time on every reset without checking whether the backup domain has already been initialized.

USB applications

For custom USB applications, PA11 and PA12 connect to USB-C. The schematic does not route VBUS to PA9, because PA9 serves mikroBUS RST, and does not connect ID to PA10. Start with fixed USB Device mode and VBUS sensing configured for this topology; do not automatically copy OTG settings from another board.

USB requires both a correct 48 MHz clock and sufficient clock accuracy. A 48 MHz value in the configurator alone does not guarantee the tolerance of clocks derived from HSI. Before publishing a USB CDC tutorial, verify the clock design, stable enumeration, and data transfer. A USB-C connector alone does not guarantee USB High Speed, USB Power Delivery, or host functionality.

C examples for STM32 HAL

These examples are teaching fragments for a project generated for STM32F446RET6. They are not standalone applications or a complete BSP. They use blocking calls for clarity. They have not been built with a specific STM32CubeF4 version or tested on hardware. Place additions to generated files in USER CODE sections so that project regeneration preserves them.

The file containing an example must have access to the HAL header and declarations of the handles it uses: huart2, hi2c1, or hadc1. If the configurator generates peripherals in separate files, add the appropriate #include "usart.h", #include "i2c.h", or #include "adc.h". Check the names in your generated project.

Blinking on PB0

Prerequisite: PB0 is a push-pull GPIO Output without a pull-up or pull-down. On the board, it corresponds to CONN_DIG1/2 and the D_B1/D_R1 LED pair. Fit JP1 and JP2 for color indication. After GPIO initialization, use the following main loop:

while (1)
{
    HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0);
    HAL_Delay(500);
}

Expected result: PB0 changes level every 500 ms, giving a full period of approximately 1 s. With the indicator rails connected, blue and red alternate.

Button on PA0 controls PB0

Keep PB0 as an output. Configure PA0 as an input without internal pull resistors. The following code replaces the blinking example and accepts a change after at least 20 ms of stability. It runs in the main loop, not in an interrupt handler. Place the initial declarations and assignments before the loop.

GPIO_PinState candidate = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0);
GPIO_PinState stable = candidate;
uint32_t changed_at = HAL_GetTick();

while (1)
{
    GPIO_PinState now = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0);
    uint32_t tick = HAL_GetTick();

    if (now != candidate) {
        candidate = now;
        changed_at = tick;
    }
    if ((uint32_t)(tick - changed_at) >= 20U) {
        stable = candidate;
    }
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0,
        stable == GPIO_PIN_RESET ? GPIO_PIN_SET : GPIO_PIN_RESET);
}

Expected result: pressing the button sets PB0 high; releasing it sets PB0 low. With both jumpers fitted, the indication is red when pressed and blue when released.

Serial output through USART2

In CubeMX, configure USART2 on PA2/PA3 for asynchronous operation, 115200 baud, eight data bits, no parity, one stop bit, and no flow control. Generate initialization code and call MX_USART2_UART_Init() before this example. Use the COM port of a VCP-capable probe connected through U5, or an external USB-to-UART adapter with 3.3 V logic. Cross TX to RX and connect GND; do not use RS-232 voltage levels.

static const uint8_t message[] = "STM32-UNO ready\r\n";
if (HAL_UART_Transmit(&huart2, message, sizeof(message) - 1U, 100U)
    != HAL_OK) {
    Error_Handler();
}

Expected result: one line appears in the terminal after reset. The board's USB-C connector does not automatically carry this UART output.

Finding I2C devices

Configure I2C1 on PB8/PB9 for 100 kHz, seven-bit addressing, and open-drain operation. Initialize hi2c1 using the generated function. The connected module's supply must satisfy the CN1 power requirements described above. Place this fragment in a section where static variables and functions may be defined, and call the function after I2C initialization.

static volatile uint8_t i2c_found[128];

static void ScanI2C1(void)
{
    for (uint16_t address = 0; address < 128U; ++address) {
        i2c_found[address] = 0U;
    }
    for (uint16_t address = 0x08; address <= 0x77; ++address) {
        if (HAL_I2C_IsDeviceReady(&hi2c1,
                (uint16_t)(address << 1), 2U, 20U) == HAL_OK) {
            i2c_found[address] = 1U;
        }
    }
}

Inspect i2c_found in the debugger. An index containing 1 identifies a seven-bit address that acknowledged the query. HAL accepts the address shifted left by one bit, hence address << 1. Scan only devices for which this type of probing is appropriate; then implement reads for a specific sensor according to its protocol. For mikroBUS, use hi2c3 and PA8/PC9 in the same way.

Analog measurement on PC0

For the first measurement, select ADC1 IN10 on PC0, available at CONN-ANALOG/6. Connect the outer terminals of a potentiometer, for example 10 kΩ, between 3.3 V and GND, with the wiper connected to PC0. Configure the GPIO in analog mode and the ADC for 12-bit resolution, right alignment, one channel, software triggering, and a single conversion. Start with a longer sampling time and an ADC clock within the permitted range. Initialize hadc1.

uint32_t raw;
float voltage;
const float vdda = 3.3f; /* Replace with measured VDDA for accuracy. */

if (HAL_ADC_Start(&hadc1) != HAL_OK) {
    Error_Handler();
}
if (HAL_ADC_PollForConversion(&hadc1, 100U) != HAL_OK) {
    Error_Handler();
}
raw = HAL_ADC_GetValue(&hadc1);
if (HAL_ADC_Stop(&hadc1) != HAL_OK) {
    Error_Handler();
}
voltage = ((float)raw * vdda) / 4095.0f;

Expected result: raw varies approximately from 0 to 4095 as the wiper moves. The voltage conversion is approximate and does not include reference, ADC, or signal-source errors.

The APIs follow the public STM32F4 HAL GPIO, I2C, UART, and ADC headers. A published tutorial should state the exact package version used.

Troubleshooting

Symptom What to check
ST-LINK cannot find the MCU Target power, U5/3 as the reference, shared ground, U5/4 and U5/6, cable orientation; try a lower SWD frequency and connection under reset
No COM port appears after connecting USB USB-C connects directly to the MCU. For UART, use the probe's VCP or a USB-to-UART adapter; direct USB needs USB firmware
USB DFU does not work This circuit lacks the HSE required by the ROM bootloader; use SWD
Clock configuration ends in Error_Handler Do not enable an unfitted HSE. Return the first project to HSI at 16 MHz
Blinking does not change the LEDs Correct PB0 selection, GPIO initialization, running application, JP1 and JP2; check the signal at CONN_DIG1/2
The LED color seems reversed Logic 0 lights blue; logic 1 lights red. Check both indicator rails
The button reads backwards PA0 is active low; SW2 is not BOOT0
The button triggers an event several times Add debouncing, for example accepting a state after 20 ms of stability
An I2C device does not respond I2C1 versus I2C3, specific pins, module power, shared ground, seven-bit address, and the HAL address shift
Analog readings do not make sense Correct ADC channel, analog mode, signal range, and VDDA; the ref net is not VREF+
microSD cannot be mounted SPI2 rather than SDIO, CS on PB12, slow initialization, disk I/O driver, and card format
Code disappears after regeneration Put changes in USER CODE sections or your own files
A shield intended for UNO does not work 3.3 V electrical levels, actual signal assignment, and available software support; the connector arrangement alone is insufficient

Aktualizováno uživatelem Ján Hýbl před 6 dny(ů) · 1 revizí