Click Here to enter Utsource  site

IC Chips

74 series Digital Integrated Circuits

CD40 series Digital Integrated Circuits

Optical Couplers

Clock & Calculator ICs

Operational Amplifiers

Power Switch Ics

Driver Ics

Flash Memory

Memory

Audio Special Purpose

Clock/Timing - Application Specific

Clock/Timing - Clock Buffers, Drivers

Clock/Timing - Clock Generators, PLLs, Frequency Synthesizers

Clock/Timing - Delay Lines

Clock/Timing - IC Batteries

Clock/Timing - Programmable Timers and Oscillators

Clock/Timing - Real Time Clocks

Data Acquisition - ADCs/DACs - Special Purpose

Data Acquisition - Analog Front End (AFE)

Data Acquisition - Analog to Digital Converters (ADC)

Data Acquisition - Digital Potentiometers

Data Acquisition - Digital to Analog Converters (DAC)

Data Acquisition - Touch Screen Controllers

Embedded - CPLDs (Complex Programmable Logic Devices)

Embedded - DSP (Digital Signal Processors)

Embedded - FPGAs (Field Programmable Gate Array)

Embedded - FPGAs (Field Programmable Gate Array) with Microcontrollers

Embedded - Microcontroller, Microprocessor, FPGA Modules

Embedded - Microcontrollers

Embedded - Microcontrollers - Application Specific

Embedded - Microprocessors

Embedded - PLDs (Programmable Logic Device)

Embedded - System On Chip (SoC)

Interface - Analog Switches - Special Purpose

Interface - Analog Switches, Multiplexers, Demultiplexers

Interface - CODECs

Interface - Controllers

Interface - Direct Digital Synthesis (DDS)

Interface - Drivers, Receivers, Transceivers

Interface - Encoders, Decoders, Converters

Interface - Filters - Active

Interface - I/O Expanders

Interface - Modems - ICs and Modules

Interface - Modules

Interface - Sensor and Detector Interfaces

Interface - Sensor, Capacitive Touch

Interface - Serializers, Deserializers

Interface - Signal Buffers, Repeaters, Splitters

Interface - Signal Terminators

Interface - Specialized

Interface - Telecom

Interface - UARTs (Universal Asynchronous Receiver Transmitter)

Interface - Voice Record and Playback

Linear - Amplifiers - Audio

Linear - Amplifiers - Instrumentation, OP Amps, Buffer Amps

Linear - Amplifiers - Special Purpose

Linear - Amplifiers - Video Amps and Modules

Linear - Analog Multipliers, Dividers

Linear - Comparators

Linear - Video Processing

Logic - Buffers, Drivers, Receivers, Transceivers

Logic - Comparators

Logic - Counters, Dividers

Logic - FIFOs Memory

Logic - Flip Flops

Logic - Gates and Inverters

Logic - Gates and Inverters - Multi-Function, Configurable

Logic - Latches

Logic - Multivibrators

Logic - Parity Generators and Checkers

Logic - Shift Registers

Logic - Signal Switches, Multiplexers, Decoders

Logic - Specialty Logic

Logic - Translators, Level Shifters

Logic - Universal Bus Functions

Memory - Batteries

Memory - Configuration Proms for FPGAs

Memory - Controllers

PMIC - AC DC Converters, Offline Switchers

PMIC - Battery Chargers

PMIC - Battery Management

PMIC - Current Regulation/Management

PMIC - Display Drivers

PMIC - Energy Metering

PMIC - Full, Half-Bridge Drivers

PMIC - Gate Drivers

PMIC - Hot Swap Controllers

PMIC - Laser Drivers

PMIC - LED Drivers

PMIC - Lighting, Ballast Controllers

PMIC - Motor Drivers, Controllers

PMIC - OR Controllers, Ideal Diodes

PMIC - PFC (Power Factor Correction)

PMIC - Power Distribution Switches, Load Drivers

PMIC - Power Management - Specialized

PMIC - Power Over Ethernet (PoE) Controllers

PMIC - Power Supply Controllers, Monitors

PMIC - RMS to DC Converters

PMIC - Supervisors

PMIC - Thermal Management

PMIC - V/F and F/V Converters

PMIC - Voltage Reference

PMIC - Voltage Regulators - DC DC Switching Controllers

PMIC - Voltage Regulators - DC DC Switching Regulators

PMIC - Voltage Regulators - Linear

PMIC - Voltage Regulators - Linear + Switching

PMIC - Voltage Regulators - Linear Regulator Controllers

PMIC - Voltage Regulators - Special Purpose

Specialized ICs

Modules

IGBT

IPM

Thyristors

Rectifiers

Power Supply

Smart Power Module

SCR,GTO and Diode

FET

Darlington Transistors

RF Modules

CNC PRODUCTS

ENCODER

Motor

Servo drive & amplifier & Servo

Diode Module

Transistor Module

Switch Relay

PLC

Inverter

Contactor & Breaker

Elevator Board

Industry Control

Transistors

Diodes

Bipolar transistors

Resistors

Carbon Film Resistors

Cement Resistors

Chassis Mount Resistors

Chip Resistor - Surface Mount

Current Sense Resistors

Fusible Chip Resistor

High Precision & Low TCR SMD Resistors

High Voltage Resistor

LED Strip Resistors

MELF Resistor

Metal Alloy Resistors

Metal Film Resistor (TH)

Metal Glaze Resistors

Metal Oxide Film Resistors

Metal Oxide Resistors

NTC Thermistors

PTC Thermistors

Photoresistors

Potentiometers & Variable Resistors

Precision Potentiometer

Resistor Networks & Arrays

Resistor Networks & Arrays (TH)

Ultra Low Resistors (SMD)

Variable Resistors

Varistors

Wirewound Resistors

Capacitors

Aluminum Electrolytic Capacitors - SMD

CL21 Capacitor

Ceramic Disc Capacitors

High Voltage Capacitors

Metallized Polyester Film Capacitor

Multilayer Ceramic Capacitors MLCC - Leaded

Multilayer Ceramic Capacitors MLCC - SMD/SMT

Mylar Capacitor

Niobium Oxide Capacitors

Polyester Film Capacitors

Solid Polymer Electrolytic Capacitor

Supercapacitors & Ultracapacitors

Suppression Capacitors

Tantalum Capacitors

Trimmers, Variable Capacitors

Inductors & Ferrite Beads & Transformers

Antennas

Current Transformers

General Inductors (TH)

HF Inductors

Inductors (SMD)

LINE Filter

Power Inductors

Power Transformer

RJ45 Transformer

Radial Inductor (TH)

The circular inductors

Crystals

49S

49SMD

49U

Ceramic Resonators

DIP Oscillators(XO)

Radial Cylinder Crystals

SAW Resonators

SMD Crystals

SMD Oscillators(XO)

Connectors

AV Connectors

Audio & Video Connectors

Banana and Tip Connectors

Card Edge Connectors

Circular Connectors

Connector - Card Sockets

Connectors

Connectors - Accessories

Connectors - Housings

Contacts

D-Sub Connectors

Ethernet Connectors/Modular Connectors

FFC, FPC (Flat Flexible) Connectors

Fiber Optic Connectors

IC & Component Sockets

LED Light Pipes

Mezzanine Connectors (Board to Board)

PCB Connectors - Headers, Male Pins

PCB Connectors - Headers, Receptacles, Female Sockets

PCB Connectors - Housings

Power Connectors

RF Connectors/Coaxial Connectors

Shunts & Jumpers

Terminal Blocks - Accessories

Terminal Blocks - Barrier Blocks

Terminal Blocks - Din Rail, Channel

Terminal Blocks - Headers, Plugs and Sockets

Terminals

Test Clips

Test Points/Test Rings

USB Connectors

Unspecified Connectors

Screw-type wiring

Spring-type wiring

Pluggable Terminal Blocks

Through-wall Terminal Blocks

Automotive Terminals

Terminal Housings, Insulation Sleeves & Blocks

Quick Disconnect Wire Connectors and Terminals

Spare & Wear Tooling

Automotive Connectors

PCB Connectors

PC Laptop Parts

Lenovo Spare Parts

HP Spare Parts

Dell Spare Parts

Samsung Spare Parts

Asus Spare Parts

Microsoft Spare Parts

Huawei Spare Parts

Replacement Keyboards

Others

Laptop Screen

Mac Parts

LCD Screen

LCD Related Parts

Bottom Cover

Keyboard

Screws

Flex Cable

Touchpad

Power Board

Network Adapter

SSD Related Parts

Motherboard

Cooling Fan

Earpiece & Loundspeaker

Rubber Mats

Others

DJI Spare Parts

For DJI Phantom Series

For DJI Mavic Series

For DJI Spark Series

For DJI FPV Series

For DJI Mini Series

Others

iPhone 15 Pro Max Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

Others

iPhone 15 Pro Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

Others

iPhone 15 Plus Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

Others

iPhone 15 Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

Others

iPhone 14 Pro Max Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

FPC Connector

Others

iPhone 14 Pro Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

FPC Connector

Others

GoPro Spare Parts

Digital Camera Parts

Outer Screen

LCD Screen

Motherboard

Drive Board

Bayonet Mount Ring

Eyecups

Mode Dial

USB Cover Cap

Battery Cover

Flex Cable

Protective Leather

Card Slot

Button Cap

Shutter Blade Curtain

Others

iPhone 14 Plus Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

FPC Connector

Others

VR Spare Parts

iPhone 14 Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

Others

iPhone 13 Pro Max Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

Others

iPhone 13 Pro Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

Others

iPhone 13 Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

Others

iPhone 13 Mini Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

Others

iPhone 12 Pro Max Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

Side Key & Card Tray

Others

iPhone 12/12 Pro Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

Metal Parts

Others

iPhone 12 Mini Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

Metal Parts

Others

iPhone 11 Parts

Back Cover

LCD Related Parts

Flex Cable

Camera Series

Metal Parts

Others

iPhone 11 Pro Parts

Back Cover

LCD Related Parts

Flex Cable

Camera Series

Metal Parts

Others

iPhone 11 Pro Max Parts

Back Cover

LCD Related Parts

Flex Cable

Camera Series

Metal Parts

Others

iPhone XS Parts

Back Cover

LCD Related Parts

Flex Cable

Camera Series

Metal Parts

Others

iPhone XS Max Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

Metal Parts

Others

iPhone XR Parts

LCD Related Parts

Back Cover

Flex Cable

Camera Series

Metal Parts

Others

iPhone X Parts

Back Cover

LCD Related Parts

Flex Cable

Camera Series

Metal Parts

Others

iPhone 8 Parts

LCD Screen

Glass Lens

Back Cover

Camera Series

Card Tray

Flex Cable

Metal Parts

Others

iPhone 8 Plus Parts

LCD Screen

Glass Lens

Back Cover

Camera Series

Button & Card Slots

Flex Cable

Metal Parts

Others

iPhone 7 Parts

LCD Screen

Glass Lens

Back Cover

Camera

Flex Cable

Metal Parts

Others

iPhone 7 Plus Parts

LCD Screen

Glass Lens

Back Cover

Camera

Flex Cable

Metal Parts

Others

Other iPhone Parts

iPhone 6S/6S Plus Parts

iPhone 6/6 Plus Parts

iPhone 5 Parts

iPhone 4/4S Parts

iPhone SE 2020 / 2022 Parts

SE 3rd Generation Parts

SE 2nd Generation Parts

SE 1st Generation Parts

iPad Pro Series Parts

12.9 inch

10.5 inch

9.7 inch

iPad Air Series Parts

iPad Air 2 Parts

iPad Air Parts

vivo Parts

LCD Screen

Outer Glass Lens

Touch Panel

Frame Bezel Plate

Back Cover

Flex Cable

Camera Parts

Charging Port Board

Single Tail Connector

Speaker Ringer Buzzer

Card Socket

Home key & Side Key

Others

iPad mini Series Parts

iPad mini 4 Parts

iPad mini 3 Parts

iPad mini 2 Parts

iPad mini Parts

OPPO Parts

LCD Screen

Outer Glass Lens

Touch Panel

Frame Bezel Plate

Back Cover

Camera Series

Flex Cable

Single Tail Connector

Speaker Ringer Buzzer

Card Socket

Home key & Side Key

Small Board

Others

Tecno Spare Parts

LCD Screen

Outer Glass Lens

Back Cover

Small Board

Single Tail Connector

Camera Parts

Flex Cable

Card Tray

Infinix Spare Parts

LCD Screen

Outer Glass Lens

Small Board

Single Tail Connector

Camera Parts

Flex Cable

Earpiece & Loundspeaker

Card Tray

itel Spare Parts

Alcatel Spare Parts

LCD Screen

Outer Glass Lens

Touch Panel

Back Cover

Flex Cable

Single Tail Connector

Small Board

Card Tray

OnePlus Parts

LCD Screen

LCD Related Parts

Frame Bezel Plate

Back Cover

Camera Series

Flex Cable

Tail Connector

Speaker Ringer Buzzer

Card Tray

Earpiece

Home key & Side Key

Adhesive Sticker

Others

Game Spare Parts

Switch Lite Spare Parts

Switch Spare Parts

PS5 Spare Parts

PS4 Spare Parts

NDS Spare Parts

3DS Spare Parts

Wii Spare Parts

PSP Spare Parts

PS3 Spare Parts

PS2 Spare Parts

XBOX Spare Parts

Steam Deck Spare Parts

Tools

iPad Series Parts

iPad 4 Parts

iPad 3 Parts

iPad 2 Parts

iPad Parts

Galaxy Spare Parts

LCD Screen

Touch Panel

Outer Glass Lens

Frame Bezel Plate

Back Cover

Camera

Card Socket

FPC Connector

Single Tail Connector

Charging Port Board

Wireless Charging Module

Home key & Side Key

Flex Cable

Earpiece & Loundspeaker

Vibrating Motor

Adhesive Sticker

Polarizing Film

OCA & LCD Backlight

Others

Huawei Spare Parts

LCD Screen

Touch Panel

Outer Glass Lens

Adhesive Sticker

OCA & Polarizing Films

Camera

Card Socket

FPC Connector

Tail Connector

Back Cover

Full Housing Cover

Flex Cable

Home key & Side Key

Fingerprint Ring

Earpiece & Loundspeaker

Earphone Jack

Others

Xiaomi Spare Parts

LCD Screen

Touch Panel

LCD Related Parts

Back Cover

Frame Bezel Plate

Backlight Plate & OCA

Camera

Tail Connector

Card Tray

Flex Cable

Speaker Ringer Buzzer

Earpiece Speaker

Vibrating Motor

Home key & Side Key

Adhesive Sticker

Others

Meizu Spare Parts

LCD Screen

Outer Glass Lens

Touch Panel

Frame Bezel Plate

Camera

Back Cover

Full Housing Cover

Tail Connector

Card Socket

Flex Cable

Home key & Side Key

Earpiece & Loundspeaker

Apple Serie Parts

Airpods Series

Apple Pencil Series

Batteries

For iPhone

For iPad & iPod Series

For Mac

For Samsung

For Xiaomi

For Huawei

For Sony

For LG

For Nokia

For Motorola

For Lenovo

For HTC

For OnePlus

For OPPO

For Watch

Others

Apple Watch Parts

LCD Related Parts

Back Cover

Flex Cable

Vibrating Motor

Middle Frame

Adhesive Sticker

Other Parts

Watch Spare Parts

For Samsung

For Huawei

For Xiaomi

For Fitbit

For Garmin

Other

Sony Spare Parts

LCD Screen

Touch Panel

Back Cover

Frame Bezel Plate

Flex Cable

Camera

LCD Backlight Plate

Tail Connector

Speaker Ringer Buzzer

Earpiece Speaker

Adhesive Sticker

Card Tray

Dust Plug

Others

HTC Spare Parts

LCD Screen

Touch Panel

Back Cover

Full Housing Cover

Camera Series

Tail Connector

Flex Cable

Speaker Ringer Buzzer

Adhesive Sticker

Others

Nokia Spare Parts

LCD Screen

Touch Panel

Outer Glass Lens

Replacement Keypad

Flex Cable

Back Cover

Adhesive Sticker

Full Housing Cover

Earpiece & Loundspeaker

Card Tray

Camera

Charging Port Connector

Charging Port Board

Lenovo Spare Parts

LCD Screen

Touch Panel

Outer Glass Lens

Tail Connector

Back Cover

Camera

Flex Cable

Others

Google Spare Parts

LCD Screen

Outer Glass Lens

Frame Bezel Plate

Back Cover

Flex Cable

Small Board

Camera Parts

Earpiece & Loundspeaker

Vibrating Motor

Card Tray

Adhesive Sticker

Others

ASUS Spare Parts

LCD Screen

Touch Panel

Outer Glass Lens

Camera

Tail Connector

Back Cover

Flex Cable

Speaker Ringer Buzzer

Frame Bezel Plate

Card Tray

Others

Microsoft Spare Parts

LCD Screen

LCD Related Parts

Flex Cable

Back Cover

Full Housing Cover

Camera Series

Others

Motorola Spare Parts

LCD Screen

Touch Panel

Outer Glass Lens

Frame Bezel Plate

Charging Port Board

Card Socket

Back Cover

Camera Accessories

Flex Cable

Earpiece & Loundspeaker

Others

More Brand Parts

For LG

For Amazon

For BlackBerry

For ZTE

For Acer

For BQ Aquaris

For Wiko

For Letv

For Vodafone

For 360

For CAT

For TCL

For T-Mobile

Others

iPod Parts

Touch Series

Other Parts

Shenzhen Brand Phone Parts

AGM

Doogee

LEAGOO

Blackview

Ulefone

UMIDIGI

Cubot

IIIF150

Others

IC Chipset

IC for iPhone

IC for Samsung

IC for Huawei

Power IC

Audio IC

Hard Disk for iPhone

Repair Tools

Screwdriver

Screwdriver Set

Tool Kits

Test Tools

Repair Fixture

Repair Programmer

Power Supply

Repair Glue Series

Adhesive Sticker

Laminator Machine

Separation Equipment

Laser Machines

Polishing Repair

Defoaming Equipment

Laminating Machines

Repair Platform

Crowbar

Brushes

Working Mat

Magnetic Screws Mat

Magnetizer Demagnetizer Tool

Sucker

Tweezers

Glove

Dust Remove Tool

BGA Stencils

Mould

Microscope Magnifier Series

Tool Boxes & Bags

Phone Film Cutter

Others

Sign In

3.Enter "account center"->"My inquiries" and check the status of your inquiries
liveTop

Dear customers, due to the implementation of the GDPR policy in Europe, UTSOURCE has also made adjustment accordingly to meet the policy requirements. Please read the new privacy policy carefully and this window will no longer pop up after you accept it.

I agree all UTSOURCE Terms & Conditions,Privacy Statement
Agree Later Submit

Delivery Address

Alternate Text

+ Add Address

Confirm

The new shipping address

*Country/Region :
*Contact :
*Cell Phone:
+

* Please fill in the cell phone number correctly to make sure that you can receive the tracking info in time.

Country Code
*Address :
*City :
Province/State :
*Province/State :
*Post Code :
Please enter a new 5-digit zip code..
Company :
Cancel
Submit

STM32F103C8T6 read and write internal flash

PViews:1742

2021-11-12 11:23:48 source:Utsource author:Utsource
more information,enter the information center

Today I would like to share with you STM32F103C8T6 to read and write internal flash. Regarding the 103 series of single-chip microcomputers, you can refer to the option manual to check the flash capacity.

 

1. Chip FLASH capacity classification:

SupplierFile/202111/12/f_af37ecc4bfb249d38a603e4e9772e9a2.png 

The flash size of the chip introduced today is 64K, and some people on the Internet say that it can support up to 128K, but the official explanation is that the first 64K is guaranteed, and the latter cannot be guaranteed, so those who want to use it need careful.

Now that we know the flash size of the chip, let's see how the flash is divided. Through the chip data manual, we can see that the STM32F103C8T6 mentioned today is a medium-capacity device.

Since it is a medium-capacity device, let's take a look at the flash division. There is a paragraph in the STM32 flash programming manual: According to different capacities, the memory is organized into:

32 1K bytes/page (small capacity) 128 1K bytes/page (medium capacity) 256 2K bytes/page (large capacity)

How to understand this passage is to tell us that devices with small capacity (memory is 6K and 32K) are composed of 1K bytes per page.

Medium-capacity devices (64K and 128K memory) devices are composed of 1K bytes per page. Large-capacity devices (256K, 384K, and 512K memory) devices are composed of 2K bytes per page.

For example: The storage capacity of a chip is 64K. What is this 64K? It is 64*1024 BYTE. A BYTE is composed of 8 bits 0 or 1, (for example, 0000 1111 These 8 binary arrays become a byte, using decimal Let’s say 15)

To summarize: 64K flash can store 64*1024 bytes of data.

 

Let's continue to talk about how to divide the 64K data. The storage is stored in units of pages. A page with a capacity of 1K means that a page can store 1024 bytes.

How many pages are there in total?

The answer is: 64 pages, let’s see if the official says so.

This is indeed said in the flash programming manual, so we just said that 64 pages are correct

 

2. Reading and writing steps:

Above we know how the chips are classified, below we will focus on how the chips read and write.

For internal flash, we refer to the HAL library or the standard library and directly call the library packaged by ST for programming. Here I use the standard library. If you are interested, you can check the HAL library.

Do some friends ask what is the standard library and what is the HAL library?

Here to explain to you, these two libraries are ST companies, directly encapsulate the registers into functions, so that you can directly call a certain function, you can complete the configuration of various registers. Use, because the name and function of each function are different, you can refer to the comment of the function before calling. There are even usages of each function in the standard library of F0 and F4. I don’t know why it is used in the library of F1. Step removed.

 

Let's continue, the library functions for reading and writing are divided into:

/*------------ Functions used for all STM32F10x devices -----*/void FLASH_SetLatency(uint32_t FLASH_Latency);void FLASH_HalfCycleAccessCmd(uint32_t FLASH_HalfCycleAccess);void FLASH_PrefetchBufferCmd(uint32_t FLASH_PrefetchBuffer);void FLASH_Unlock(void);void FLASH_Lock(void);

 

FLASH_Status FLASH_ErasePage(uint32_t Page_Address);FLASH_Status FLASH_EraseAllPages(void);

 

FLASH_Status FLASH_EraseOptionBytes(void);FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data);FLASH_Status FLASH_EnableWriteProtection(uint32_t FLASH_Pages);FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState);

 

FLASH_Status FLASH_UserOptionByteConfig(uint16_t OB_IWDG, uint16_t OB_STOP, uint16_t OB_STDBY);uint32_t FLASH_GetUserOptionByte(void);uint32_t FLASH_GetWriteProtectionOptionByte(void);

 

FlagStatus FLASH_GetReadOutProtectionStatus(void);FlagStatus FLASH_GetPrefetchBufferStatus(void);void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG);void FLASH_ClearFlag(uint32_t FLASH_FLAG);FLASH_Status FLASH_GetStatus(void);

 

FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout);

 

/*------------ New function used for all STM32F10x devices -----*/void FLASH_UnlockBank1(void);void FLASH_LockBank1(void);FLASH_Status FLASH_EraseAllBank1Pages(void);FLASH_Status FLASH_GetBank1Status(void);FLASH_Status FLASH_WaitForLastBank1Operation(uint32_t Timeout);

 

I won’t go into details one by one here, let’s just talk about the commonly used ones.

1. Unlock void FLASH_Unlock(void);

2. Lock void FLASH_Lock(void);

3. Page erase FLASH_Status FLASH_ErasePage (uint32_t Page_Address);

4. Write half word to FLASH_Status FLASH_ProgramHalfWord (uint32_t Address, uint16_t Data);

The above 4 functions are the most commonly used.

 

Let's talk about the steps of data writing:

 

The first step: unlock.

Step 2: Determine whether the written data has been erased, that is, whether 0xFFFF is stored in the written address. Here is an important point to say, why is it necessary to judge whether it is 0xFFFF instead of judging whether it is 0xFF? Because every time we write data, we have to write a half word, that is, two bytes of data, and the written address can only be an integer multiple of 2, not an odd number. Please pay attention here.

Step 3: Write data STM32F103C8T6 can only write data in half-word mode. The data before writing must be 0XFFFF. Because FLASH data is written, only 0 can be written, not 1, which is why we want Make sure that the data before writing is the cause of the erasure.

Step 4: Lock up.

Step 5: Verify that the writing is correct.

In fact, the fifth step can be omitted. Let's take a look at the official writing process:

Well, it's actually the same. Let me share it with you (99% reference punctual atom routines).

//Write without checking //WriteAddr: start address //pBuffer: data pointer //NumToWrite: half word (16 bits) void STMFLASH_Write_NoCheck(u32 WriteAddr, u16 *pBuffer, u16 NumToWrite) {u16 i; for( i=0;i《NumToWrite;i++) {FLASH_ProgramHalfWord(WriteAddr, pBuffer); WriteAddr+=2;//Add 2.}}

 

//Write data of the specified length from the specified address//WriteAddr: starting address (this address must be a multiple of 2!!) //pBuffer: data pointer //NumToWrite: half word (16 bits) number (just to The number of 16-bit data written.) u16 STMFLASH_BUF [STM_SECTOR_SIZE/2];//Up to 2K bytes void STMFLASH_Write (u32 WriteAddr, u16 *pBuffer, u16 NumToWrite) {u32 secpos; //Sector address u16 secoff ; //Offset address in the sector (16-bit word calculation) u16 secremain; //Remaining address in the sector (16-bit word calculation) u16 i; u32 offaddr; //Remove the address after 0X08000000 if (WriteAddr《STM32_FLASH_BASE| |(WriteAddr"=(STM32_FLASH_BASE+1024*STM32_FLASH_SIZE))) return;//Illegal address FLASH_Unlock();

 

//Unlock offaddr=WriteAddr-STM32_FLASH_BASE; //The actual offset address. secpos=offaddr/STM_SECTOR_SIZE;

 

//Sector address 0~127 for STM32F103RBT6 secoff=(offaddr%STM_SECTOR_SIZE)/2;

 

//The offset within the sector (2 bytes are the basic unit.) secremain=STM_SECTOR_SIZE/2-secoff; //The size of the remaining space in the sector if (NumToWrite《=secremain) {secremain=NumToWrite;//Not greater than The sector range} while(1) {STMFLASH_Read(((secpos*STM_SECTOR_SIZE)+STM32_FLASH_BASE), STMFLASH_BUF, STM_SECTOR_SIZE/2);//Read the content of the entire sector for(i=0;i《secremain;i++) //Check data// for (i=0;i《(STM_SECTOR_SIZE/2);i++)//Check data{ if (STMFLASH_BUF[secoff+i]!=0XFFFF) break;//Need to erase// if (STMFLASH_BUF!=0XFFFF) break;//Need to erase} FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);

 

if(i《secremain)//Need to erase// if(i》(STM_SECTOR_SIZE/2))//Need to erase {FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR); FLASH_ErasePage(secpos*STM_SECTOR_/FLASH_SIZE+STM32; Except this sector for (i=0;i《secremain;i++)//copy {STMFLASH_BUF [i+secoff]=pBuffer;} STMFLASH_Write_NoCheck(secpos*STM_SECTOR_SIZE+STM32_FLASH_BASE, STMFLASH_BUF, STM_SECTOR_SIZE/2);//write the entire Sector}else STMFLASH_Write_NoCheck(WriteAddr, pBuffer, secremain);

 

//Write the erased ones, directly write into the remaining section of the sector. if (NumToWrite==secremain) break;//The writing is over else//The writing is not finished{ secpos++; //Increase the sector address by 1 secoff=0; //The offset position is 0 pBuffer+=secremain; //Pointer Offset WriteAddr+=(secremain*2); //Write address offset NumToWrite-=secremain; //Decrease the number of bytes (16 bits) if (NumToWrite" (STM_SECTOR_SIZE/2)) {secremain=STM_SECTOR_SIZE/2;// The next sector still cannot be written} else {secremain=NumToWrite;//The next sector can be written}}} FLASH_Lock();//Lock}

 

Finally, we call the STMFLASH_Write() function to write data. Are there any friends who don’t understand? Let me explain the writing process to you.

This STMFLASH_Write() function means that given a write address, data and number of writes, then start writing data according to the given address, pay attention to the red font.

How do you write data?

The first is to sort out the page address to be written and how many pages need to be written, what is the starting address for each page to be written, and then start writing page by page, when it comes to cross-page writing, the second page Write in the address, and just continue to write the number.

Another important point is that I modified the library function:

/** * [url=home.php?mod=space&uid=247401]@brief[/url] Programs a half word at a specified address. * [url=home.php?mod=space&uid=536309]@NOTE[/url] This function can be used for all STM32F10x devices. * @param Address: specifies the address to be programmed. * @param Data: specifies the data to be programmed. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. */FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data){ FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);

 

FLASH_Status status = FLASH_COMPLETE; /* Check the parameters */ assert_param(IS_FLASH_ADDRESS(Address));#ifdef STM32F10X_XL /* Wait for last operation to be completed */ status = FLASH_WaitForLastOperation(ProgramTimeout);

 

if(Address 《 FLASH_BANK1_END_ADDRESS) { if(status == FLASH_COMPLETE) { /* if the previous operation is completed, proceed to program the new data */ FLASH-》CR |= CR_PG_Set; *(__IO uint16_t*)Address = Data; /* Wait for last operation to be completed */ status = FLASH_WaitForLastBank1Operation(ProgramTimeout);

 

/* Disable the PG Bit */ FLASH-》CR &= CR_PG_Reset; } } else { if(status == FLASH_COMPLETE) { /* if the previous operation is completed, proceed to program the new data */ FLASH-》CR2 |= CR_PG_Set; *(__IO uint16_t*)Address = Data; /* Wait for last operation to be completed */ status = FLASH_WaitForLastBank2Operation(ProgramTimeout);

 

/* Disable the PG Bit */ FLASH-》CR2 &= CR_PG_Reset; } }#else /* Wait for last operation to be completed */ status = FLASH_WaitForLastOperation(ProgramTimeout); if(status == FLASH_COMPLETE) { /* if the previous operation is completed, proceed to program the new data */ FLASH-》CR |= CR_PG_Set; *(__IO uint16_t*)Address = Data;

 

/* Wait for last operation to be completed */ status = FLASH_WaitForLastOperation(ProgramTimeout); /* Disable the PG Bit */ FLASH-》CR &= CR_PG_Reset; } #endif /* STM32F10X_XL */ /* Return the Program Status */ return status;}

 

Can you see it? It is the red font part, adding a clear all abnormal state before each writing. Why add this?

Because, if the address of the data you write is not erased, if you write it, it will cause an abnormal state to occur, and this abnormal state must be manually cleared, if you do not clear the abnormal state, and continue to write data , Then any data you write later will report an error, and you will not be able to write it in, so I added an exception status clear here. If the data written earlier is reported wrong, it will not affect my subsequent data writing.

Here everyone clears up why.

We will write data, so let's talk about reading data. In fact, reading data here is much easier than external flash reading. We read the address directly, and what is returned is the data stored in the address. Is it very simple?

Look at the following function:

 

//Read the half word of the specified address (16-bit data) //faddr: read address (this address must be a multiple of 2!!) //Return value: corresponding data.u16 STMFLASH_ReadHalfWord(u32 faddr){ return *(vu16 *) faddr; }//Read the data of the specified length from the specified address //ReadAddr: start address //pBuffer: data pointer //NumToWrite: half word (16 bits) void STMFLASH_Read (u32 ReadAddr, u16 *pBuffer , U16 NumToRead) {u16 i; for(i=0;i《NumToRead;i++) {pBuffer=STMFLASH_ReadHalfWord(ReadAddr);//Read 2 bytes. ReadAddr+=2;//offset by 2 bytes. }}

Are you very happy? Reading and writing data is as simple as that.


Key words: STM32F103C8T6

participate in discussions

New customer

Please login ? to participate in the comments

New customer Start here.

Submit

Comments

Toll-Free Call

(888) 766 5577 USA & Canada

+52 5515436027
+52 5515436028 Mexico

+49 6931090199 Germany

Whatsapp

+1 (657) 605-6198 USA

+49 15217848563 Germany

+52 55 7637 4368 Mexico

Email

sales@utsource.com

GLOBAL PAYMENTS

Global logistics

footShip
Copyright © 2022 Power by UTSOURCE HOLDING COMPANY LIMITED ISO/IEC 20000-1:2011,ISO/IEC 27001:2013 鄂ICP备2021003526号-1