All filters

How to Migrate an STM32F103 Design to MG32F157


Migrating an existing STM32F103 design to MG32F157 involves more than changing the MCU part number. The hardware, firmware, clock configuration, peripheral functions, development environment, and system-level performance should all be reviewed before introducing the new MCU into production.

MG32F157 is a 32-bit ARM Cortex-M3 microcontroller with a maximum operating frequency of 96MHz. It provides up to 256KB Flash, 64KB SRAM, multiple communication interfaces, ADC, DAC, CAN, USB, SDIO, AES, TRNG, and other integrated functions. These features make MG32F157 a candidate for STM32F103 replacement and MCU localization projects.

Start with the Existing STM32F103 Design

Before beginning the migration, identify the exact STM32F103 part number used in the existing product.

The STM32F103 family contains different devices with different memory capacities, packages, I/O resources, and peripheral configurations. Therefore, the complete part number should be documented before selecting the MG32F157 device.

The existing design should be reviewed in several areas:

  • MCU part number

  • Package

  • Flash usage

  • SRAM usage

  • GPIO allocation

  • Clock configuration

  • ADC channels

  • Timers

  • UART

  • SPI

  • I2C

  • CAN

  • USB

  • Interrupts

  • DMA

  • External memory

  • Bootloader

  • Debug interface

This information provides the baseline for the replacement evaluation.

Check MG32F157 Memory Requirements

Memory compatibility should be evaluated before firmware migration.

MG32F157 provides up to 256KB Flash and 64KB SRAM. The available memory should be compared with the actual memory requirements of the existing STM32F103 application.

Engineers should determine how much Flash and SRAM the current firmware uses and leave sufficient space for future software updates.

A replacement MCU with additional memory can provide more room for application code, communication protocols, diagnostics, security functions, and future features.

Review the MCU Package and PCB

The next step is hardware migration.

MG32F157 is available in package options including LQFP48, LQFP64, and LQFP100, depending on the specific device.

The existing STM32F103 PCB should be compared with the selected MG32F157 package.

Important PCB items include:

  • Package dimensions

  • Pin arrangement

  • Power pins

  • Ground pins

  • GPIO locations

  • Analog inputs

  • Clock pins

  • Reset

  • Debug interface

  • USB pins

  • CAN pins

  • Communication interfaces

A similar package does not automatically mean that the two MCUs are pin-to-pin compatible.

If the pin functions differ, schematic and PCB modifications may be required.

Compare GPIO Functions

GPIO migration is one of the most important parts of an STM32F103 replacement project.

The existing STM32F103 may use GPIO pins for LEDs, buttons, sensors, relays, motors, communication interfaces, external memory, and other functions.

Each signal should be mapped from the STM32F103 design to the selected MG32F157 device.

A practical migration method is to document:

STM32F103 Pin → MG32F157 Pin → Function → Electrical Requirement

This helps engineers identify conflicts before redesigning the PCB.

Special attention should be paid to alternate functions. A pin used for UART, SPI, I2C, timer, ADC, or CAN on STM32F103 may have a different mapping on MG32F157.

Reconfigure the Clock System

Clock configuration should be reviewed carefully.

MG32F157 supports an external high-speed clock from 4MHz to 24MHz, an internal 8MHz high-speed clock, an external 32kHz low-speed clock, and an internal 40kHz low-speed clock. The maximum operating frequency is 96MHz.

The original STM32F103 clock configuration should not simply be copied into the new project.

The migration should verify:

  • Main oscillator

  • PLL configuration

  • System clock

  • Bus clocks

  • Timer clocks

  • USB clock

  • ADC clock

  • RTC clock

This is particularly important when the existing firmware depends on precise timer frequencies or communication baud rates.

Migrate GPIO and Peripheral Drivers

After establishing the basic clock configuration, peripheral drivers can be migrated.

A practical sequence is:

  1. GPIO

  2. UART

  3. Timer

  4. ADC

  5. SPI

  6. I2C

  7. CAN

  8. USB

  9. DMA

  10. Application-specific peripherals

MG32F157 provides multiple communication interfaces, including UART, SPI, I2C, QSPI, CAN, USB, and SDIO.

Each peripheral should still be checked against the original STM32F103 implementation.

Review Timer and Interrupt Functions

Many STM32F103 applications depend heavily on timers and interrupts.

Timers may be used for:

  • PWM

  • Motor control

  • Periodic tasks

  • Sensor sampling

  • Communication timeouts

  • LED control

  • Software scheduling

  • Pulse measurement

MG32F157 provides multiple timer resources for general-purpose control and timing functions.

During migration, engineers should verify timer frequency, prescaler settings, interrupt behavior, PWM outputs, capture and compare functions, and timer-to-GPIO mappings.

Migrate ADC and DAC Functions

Analog functions should also be reviewed during the MCU replacement process.

MG32F157 provides 12-bit ADC resources and DAC functions for analog measurement and control applications.

These functions can be useful in:

  • Motor control

  • Power monitoring

  • Industrial sensing

  • Battery systems

  • Measurement equipment

  • Automation controllers

For an STM32F103 design using ADC measurements, engineers should compare channel assignment, resolution, sampling requirements, reference voltage, input range, conversion timing, DMA requirements, and calibration.

Migrate CAN and USB Functions

CAN and USB are important interfaces in many industrial and embedded systems.

MG32F157 integrates CAN and USB functions, making it suitable for applications such as industrial controllers, communication equipment, motor-control systems, and embedded terminals.

For an STM32F103 product using CAN or USB, engineers should review the existing protocol implementation and adapt the low-level peripheral configuration for MG32F157.

Testing should include:

  • Initialization

  • Communication speed

  • Data transmission

  • Data reception

  • Interrupt handling

  • Error handling

  • Bus recovery

  • Long-duration communication

Protocol-level compatibility does not automatically guarantee driver-level compatibility.

Migrate the Firmware

The Cortex-M3 architecture provides a familiar foundation for developers working with STM32F103.

However, firmware should not be assumed to be completely portable.

The migration may involve changes to:

  • Startup code

  • System initialization

  • Interrupt vector configuration

  • Clock initialization

  • GPIO configuration

  • Peripheral registers

  • Timer drivers

  • ADC drivers

  • Communication drivers

  • DMA configuration

  • Flash programming

  • Bootloader

  • Debug configuration

The amount of software modification depends on how closely the existing application is tied to STM32-specific registers, libraries, and development tools.

Replace MCU-Specific Libraries

Existing STM32F103 firmware may depend on MCU-specific libraries or middleware.

During migration, engineers should identify hardware-dependent software components such as:

  • Hardware abstraction layers

  • Peripheral libraries

  • Startup files

  • CMSIS components

  • Bootloader code

  • RTOS drivers

  • USB libraries

  • CAN drivers

  • Flash drivers

The application layer can often retain much of its original structure, while the low-level hardware abstraction layer may require more substantial modification.

Establish the MG32F157 Development Environment

Before porting the complete application, it is useful to establish a basic MG32F157 development project.

The initial firmware should verify:

  • MCU startup

  • Clock

  • GPIO

  • UART

  • Timer

  • Interrupt

  • SWD debugging

Once the basic platform is working, application modules can be migrated one by one.

This approach makes it easier to isolate hardware, driver, and software problems during the migration.

Use MG32F157 Features in the New Design

Migration does not necessarily mean reproducing every STM32F103 function exactly.

MG32F157 provides additional resources that may be useful in a redesigned product.

These include:

  • AES hardware encryption

  • TRNG

  • DAC

  • QSPI

  • SDIO

  • Multiple UART interfaces

  • Multiple ADC resources

  • CAN

  • USB

MG32F157 also provides a unique device ID and bootloader support.

For a new product revision, these functions can potentially be used to add security, communication, storage, or firmware-update capabilities.

Validate Power and Low-Power Operation

Power design should be reviewed before producing a new PCB.

MG32F157 operates within a low-voltage supply range and provides low-power operating modes such as Sleep, Stop, and Standby.

The engineering team should verify:

  • Supply voltage

  • Decoupling capacitors

  • Reset circuit

  • Power-on behavior

  • Analog supply

  • RTC supply

  • Low-power current

  • Peripheral power behavior

Battery-powered products should be tested under actual operating conditions rather than relying only on theoretical power calculations.

Test the Migrated STM32F103 Design

After hardware and firmware migration, testing should be performed in stages.

Stage 1: MCU Startup

Verify power-on reset, clock initialization, firmware startup, and debugging.

Stage 2: Peripheral Testing

Test GPIO, timers, ADC, DAC, UART, SPI, I2C, CAN, USB, and other required peripherals.

Stage 3: Application Testing

Run the original application functions on MG32F157 and verify normal operation.

Stage 4: Stress Testing

Test the system under maximum expected processing load, communication traffic, temperature, and operating conditions.

Stage 5: Production Validation

Perform long-duration testing and system-level validation before approving the replacement for mass production.

STM32F103 to MG32F157 Migration Checklist

Before completing the migration, engineers should verify:

  • Exact STM32F103 part number

  • MG32F157 part number

  • Package

  • Pin assignment

  • Flash

  • SRAM

  • GPIO

  • Clock configuration

  • Timers

  • ADC

  • DAC

  • UART

  • SPI

  • I2C

  • CAN

  • USB

  • DMA

  • Interrupts

  • Power supply

  • Low-power modes

  • Bootloader

  • Debug interface

  • Firmware libraries

  • Application code

  • PCB layout

  • System performance

This checklist helps identify hardware and software differences before prototype production.

MG32F157 for STM32F103 Migration Projects

Migrating an STM32F103 design to MG32F157 is best approached as a structured hardware and firmware migration rather than a simple MCU substitution.

Both platforms use the ARM Cortex-M3 architecture, while MG32F157 provides a maximum operating frequency of 96MHz together with up to 256KB Flash, 64KB SRAM, multiple communication interfaces, analog resources, CAN, USB, AES, TRNG, and other functions.

For companies evaluating an STM32F103 replacement, the migration can begin with the existing schematic and firmware, followed by package and pin analysis, peripheral mapping, software adaptation, prototype testing, and system validation.

The exact MG32F157 device should be selected according to the requirements of the existing product. Successful migration requires verification at the PCB, firmware, peripheral, electrical, and system levels.

Contact

Email

vip@merrillchip.com

merrillchip@outlook.com

WhatsApp

+86 15002073447

+86 13688844543


Related Articles

Explore related electronics articles and guides.

Aug 15, 2026

Can MG32F157 Replace STM32F103 in an Existing Product?

Can MG32F157 replace STM32F103? Compare Cortex-M3 performance, memory, peripherals, packages, firmware migration, and hardware requirements for MCU replacement.

Aug 15, 2026

How to Migrate an STM32F103 Design to MG32F157

Learn how to migrate an STM32F103 design to MG32F157, including PCB, pin mapping, clock, peripherals, firmware, power, and system validation.

Aug 13, 2026

What Causes PCB Assembly Costs to Increase?

A PCB assembly quotation can change considerably even when the PCB itself has not changed.Sometimes the reason is obvious, such as a more expensive IC. In other...

Aug 13, 2026

How to Find a PCBA Supplier for Urgent Production?

When a production line is waiting for assembled boards, the usual PCBA supplier selection process changes. Price is still important, but lead time becomes the f...

Aug 13, 2026

Why Do PCBA Quotes Vary So Much Between Suppliers?

It is common to send the same PCB files to several assembly suppliers and receive quotations that are surprisingly different.One supplier may quote $1.80 per bo...

Aug 13, 2026

How to Find a PCB Manufacturer With Fast Lead Times?

When a PCB project is running late, finding a manufacturer with a low price is usually not the first priority. The main question is whether the supplier can act...

Aug 13, 2026

How to Check if a PCB Manufacturer Can Handle Your Project?

Choosing a PCB manufacturer is not just about finding a company that can make a circuit board.A supplier may be able to produce ordinary two-layer PCBs but stru...

Aug 13, 2026

How to Reduce PCB Assembly Costs for Mass Production?

When PCB assembly moves from prototypes to mass production, even a small saving on each board can make a noticeable difference to the total manufacturing cost.T...

Aug 13, 2026

How to Compare PCB Assembly Quotes From Different Suppliers?

When you ask several PCB assembly suppliers for quotations, it is normal to receive very different prices for the same PCB.Before comparing the numbers, make su...

Aug 13, 2026

What to Do When a PCB Component Is No Longer Available?

A component becoming unavailable does not always mean the PCB has to be redesigned immediately.The first step is to understand why the component cannot be purch...

Aug 13, 2026

How to Find a Replacement for an Obsolete Inductor?

When an inductor becomes obsolete, finding another part with the same inductance value is usually not enough.The original inductor may have been selected for a ...

Aug 13, 2026

Where to Find High Current Inductors for Power Supplies?

Finding a high current inductor is not difficult. Finding one that can handle the actual current and temperature of a power supply is a different matter.High cu...