To differentiate between the STM32F070 and STM32F042 microcontrollers by probing registers, you can leverage their Unique Device ID Register or check specific peripheral configurations and features that differ between the two. Here's a step-by-step guide based on available information:
1. Read the Unique Device ID Register
Both STM32F070 and STM32F042 have a 96-bit Unique Device ID register located at 0x1FFFF7AC in the STM32 memory map, which is guaranteed to be unique for each device. However, this alone doesn't directly identify the specific model (F070 vs. F042), as it’s more for distinguishing individual chips. To use it for model identification, you’d need to know additional details about the ID structure, which STMicroelectronics doesn’t fully document publicly. Internet discussions suggest the ID may include wafer position or manufacturing data, but this is speculative and not practical for direct differentiation.
2. Check Device ID in the DBGMCU_IDCODE Register
A more reliable method is to read the DBGMCU_IDCODE register at address 0xE0042000. This register contains a 12-bit Device ID (DEV_ID) field that identifies the specific STM32 model. According to STMicroelectronics documentation:
STM32F070: The DEV_ID is typically 0x445 for F070 series (e.g., STM32F070F6/CB/RB).
STM32F042: The DEV_ID is typically 0x448 for F042 series (e.g., STM32F042F6/K6).
Steps to read DBGMCU_IDCODE:
Access the register at 0xE0042000 using a debugger or code.
Read the lower 12 bits (bits 0–11) to get the DEV_ID.
Compare:
0x445 → STM32F070
0x448 → STM32F042
Code Example (Bare-Metal C):
#include "stm32f0xx.h"
uint32_t get_device_id(void) {
return (DBGMCU->IDCODE & 0xFFF); // Mask to get 12-bit DEV_ID
}
int main(void) {
uint32_t dev_id = get_device_id();
if (dev_id == 0x445) {
// STM32F070 detected
} else if (dev_id == 0x448) {
// STM32F042 detected
}
while (1);
}
3. Check Peripheral Differences
The STM32F042 and STM32F070 differ in their peripheral sets, which can be probed via registers. Here are key differences based on STMicroelectronics documentation:
HDMI CEC: The STM32F042 has a CEC (Consumer Electronics Control) peripheral, while the STM32F070 does not. You can check for the presence of the CEC peripheral by accessing its register base address (0x40007800) and verifying if it responds.
Check: Read the CEC_CR (Control Register) at 0x40007800. If it’s accessible and returns valid data, it’s an STM32F042. If it’s unresponsive or returns garbage, it’s likely an STM32F070.
CAN Peripheral: Both may have CAN, but the STM32F042 supports it across more packages (e.g., TSSOP20), while STM32F070 CAN is limited to larger packages (e.g., LQFP64). Check the CAN registers (0x40006400) to see if they’re functional.
USB Clock Recovery System (CRS): The STM32F042 has a CRS module for crystal-less USB operation, while the STM32F070 lacks this in smaller packages (e.g., SOP20). Check the CRS register base (0x40006C00) for accessibility.
Example for CEC Check:
#include "stm32f0xx.h"
uint32_t is_cec_present(void) {
// Enable CEC clock
RCC->APB1ENR |= RCC_APB1ENR_CECEN;
// Read CEC control register
return CEC->CR; // If readable and valid, it’s STM32F042
}
4. Flash and SRAM Sizes
The STM32F070 and STM32F042 have different memory configurations, which can be indirectly inferred:
STM32F070: Up to 128 KB Flash, 16 KB SRAM (e.g., STM32F070RB).
STM32F042: Up to 32 KB Flash, 6 KB SRAM (e.g., STM32F042F6). You can’t directly read memory size from registers, but you can attempt to access memory addresses beyond the STM32F042’s limits (e.g., write/read at 0x08008000 for 32 KB Flash) to see if it’s valid (STM32F070) or causes a fault (STM32F042).
5. Practical Approach
Primary Method: Use the DBGMCU_IDCODE register (0xE0042000) to check the DEV_ID (0x445 for F070, 0x448 for F042). This is the most straightforward and reliable method.
Secondary Method: Probe the CEC peripheral registers (0x40007800) to confirm STM32F042 (present) vs. STM32F070 (absent).
Fallback: If register access isn’t feasible, check the part number printed on the chip package (e.g., STM32F070F6P6 vs. STM32F042F6P6) using a magnifying tool, though this isn’t register-based.
Notes
Always consult the Reference Manual (RM0091 for STM32F0 series) for register details.
Ensure the peripheral clocks are enabled (via RCC registers) before accessing peripheral registers to avoid bus faults.
If using a debugger (e.g., ST-Link), you can directly inspect these registers via tools like STM32CubeIDE or ST-Link Utility.
If you need specific code or further clarification, let me know!
-
- Просто классика: ответ абсолютно точный и абсолютно бесполезный :-) LightElf(182 знак., 29.06.2025 17:36)