yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
STM32-BoardCar📖
0. Get started quickly
  • 0.ReadMe
  • 1. Installation Instructions
  • 2. Version configuration
  • 3. Smart car installation video
  • 4. Precautions for use
1. Introduction to STM32 development board
  • 1. Learn about STM32
  • 2. Introduction to STM32 development board
  • 3. Development board pin assignment
  • 4. Introduction to HAL library and LL library
2. Setting up and using the development environment
  • 1. Common development tools
  • 2. STM32CubeMX Install - Use
  • 3. STM32CubeIDE Install - Use
  • 4. Common Driver Installation
  • 5. Program download and simulation
  • 6. Engineering experience and migration
3. Development board basic tutorial
  • 1. RGB searchlight (GPIO)
  • 2. Buzzer control (GPIO)
  • 3. Button control (EXTI)
  • 4. Serial communication (UASRT)
  • 5. Voltage detection (ADC)
  • 6. Internal temperature sensor(ADC)
  • 7. Independent watchdog(IWDG)
  • 8. Window watchdog(WWDG)
  • 9. Basic timer (TIM6)
  • 10. Universal Timer (TIM3)
  • 11. Advanced timers (TIM1)
  • 12. I2C Communication (IIC)
  • 13. Off-chip Flash (SPI)
  • 14. On-chip Flash (Flash)
  • 15. DMA:USART
  • 16. DMA:SPI
  • 17. DMA:I2C
  • 18. USB communication
  • 19. USB analog U disk
  • 20. FreeRTOS
4. Car expansion tutorial
  • 1. Servo control
  • 2. Basic use of ultrasonic steering gear gimbal
  • 3. Motor control
  • 4. OLED display light sensitivity value
  • 5. Infrared sensor
  • 6. Four-way tracking module
  • 7. Infrared remote control
  • 8. Ultrasonic ranging
  • 9. PS2 controller test
  • 10.K230 Vision Module
  • 11.AI voice interaction integration module
5. Robot car tutorials
  • 1. Car line patrol
  • 2. Ultrasonic follow
  • 3. Ultrasonic obstacle avoidance
  • 4. Ultrasonic obstacle avoidance (servo gimbal version)
  • 5. Infrared sensor obstacle avoidance
  • 6. Infrared remote control
  • 7. PS2 handle remote control
  • 8.K230 face tracking on PTZ
  • 9.K230 color tracking
  • 10.K230 Color Line Patrol
  • 11.K230 QR code command
  • 12.K230 machine code tracking
  • 13.K230 road sign indication action (voice)
  • 14.K230 color response (voice)
  • 15.K230 gesture control (voice)
  • 16.K230 Rock-Paper-Scissors Game (Voice)
6. Operation video
  • 1-How to install STM32CubeIDE software
  • 2-How to create Demo project
  • 3-How to download code into STM32 robot car
  • 4-How to open and compile a code file for STM32
  • 5-About IR control and Charge battery
Download
  • Code
  • SCH
  • Software File
  • STM32 Chip DataSheet
  • Installation manual
Download ZIP

Welcome to STM32-BoardCar repository

14. On-chip Flash (Flash)

On-chip Flash

On-chip Flash1、Software-Hardware2、Brief principle2.1、Hardware schematic diagram2.2、Physical connection diagram2.3、Principle of control3、Engineering configuration3.1、Notes3.2、Pin configuration4、Main function4.1、User function4.2、HAL library function parsing5、Experimental phenomenon

This tutorial demonstrates how to control the internal Flash of the development board to read and write data through keys , and print the data through the serial port (USART1)

1、Software-Hardware

  • STM32F103CubeIDE

  • STM32 robot expansion board

    USART, internal Flash: chip internal peripherals

    Key: Onboard

  • Type-C cable or ST-Link

    Download or simulate the program of the development board

2、Brief principle

2.1、Hardware schematic diagram

image-20231018170623917

2.2、Physical connection diagram

image-20231020093159203

2.3、Principle of control

Use the keys to control the data written and read in flash, and print the data out through the serial port.

  • GPIO reading

By defining different functions for the key, the data read and write operation in flash is realized.

KEY(Schematic name)Control pinFunction
KEY1PG3Add 1 to the count
KEY2PG4The count is cleared to zero
KEY3PG5Reading count values
  • Flash

STM32F103ZET6 Flash memory capacity is 512K bytes, a total of 256 2K byte pages;

Flash memory is mainly used to store program code and constant data in order to retain these data when restarted after power failure.

Programming and erasing flash memoryregisterFunction
The FPEC key registerFLASH_KEYRUsed to erase and program Flash memory unlocking and locking
Select the byte key registerFLASH_OPTKEYROption bytes used to unlock and lock the Flash memory
Flash memory control registersFLASH_CRUsed to control Flash memory programming and erase operations
Flash memory status registerFLASH_SRUsed to report Flash memory status information
Flash address registerFLASH_ARUsed to specify the address of Flash memory to be programmed or erased
Select the byte registerFLASH_OBRThe value used to store the option bytes
Write the protected registerFLASH_WRPRUsed to specify that Flash memory sectors are write-protected to prevent accidental modification.
For detailed information, refer to "PM0042_STM32F10xxx Flash Memory Programming (Chinese)".
  • Flsah write

Unlock → erase → write data → lock

operationfunction
UnlockHAL_FLASH_Unlock
eraseHAL_FLASHEx_Erase
write dataHAL_FLASH_Program
lockHAL_FLASH_Lock

3、Engineering configuration

Project Configuration: Prompts for configuration options in the STM32CubeIDE project configuration process

3.1、Notes

Omitted project configuration: New project, chip selection, project configuration, SYS for pin configuration, RCC configuration, clock configuration, and project configuration content

The project configuration part, which is not omitted, is the key point to configure in this tutorial.

xxxxxxxxxx
Please refer to [2. Development environment construction and use: STM32CubeIDE installation and use] to understand how to configure the omitted parts of the project.

3.2、Pin configuration

  • Configure the specified pin function

You can directly select the corresponding pin number in the pin view, and the corresponding option will appear when the mouse is left clicked

5f368c0f80beabc0089a5fb5abf8b35b

  • GPIO

image-20231020122426785

  • USART

image-20231020122526760

image-20231020122549648

  • NVIC

    NVIC can modify interrupt priority

image-20231020122655542

  • Advanced Settings

image-20231030192315753

  • Generating code

image-20231020123054441

4、Main function

This section mainly introduces the functional code written by users. Detailed code can be opened by yourself in the project file we provide, and enter the Bsp folder to view the source code.

4.1、User function

function:STMFLASH_ReadHalfWord

Function prototypesu16 STMFLASH_ReadHalfWord(u32 faddr)
Functional DescriptionRead a half-word (16-bit data) at the specified address.
Input parametersfaddr:address
Return valueData for the address

function:STMFLASH_Write_NoCheck

Function prototypesvoid STMFLASH_Write_NoCheck(u32 WriteAddr,u16 *pBuffer,u16 NumToWrite)
Functional DescriptionWrites data of the specified length from the specified address without checking
Input parameters1WriteAddr:Start address
Input parameters2pBuffer:Data pointer
Input parameters3NumToWrite:Half-word (16 bit) number
Return valueNone

function:STMFLASH_Write

Function prototypesvoid STMFLASH_Write(u32 WriteAddr,u16 *pBuffer,u16 NumToWrite)
Functional DescriptionWrites data of the specified length starting at the specified address
Input parameters1WriteAddr:Start address
Input parameters2pBuffer:Data pointer
Input parameters3NumToWrite:Half-word (16 bit) number
Return valueNone

function:STMFLASH_Read

Function prototypesvoid STMFLASH_Read(u32 ReadAddr,u16 *pBuffer,u16 NumToRead)
Functional DescriptionRead data of the specified length starting at the specified address
Input parameters1ReadAddr:Start address
Input parameters2pBuffer:Data pointer
Input parameters3NumToRead:Half-word (16 bit) number
Return valueNone

4.2、HAL library function parsing

The HAL library functions that were covered in the previous tutorial will not be covered

xxxxxxxxxx
If you want to find the HAL library and LL library function analysis involved in the entire tutorial, you can view the documents in the folder [8. STM32 Manual: STM32F1_HAL Library and LL Library_User Manual]

function:HAL_FLASH_Unlock

Function prototypesHAL_StatusTypeDef HAL_FLASH_Unlock(void)
Functional DescriptionUnlock access to the flash control register
Input parametersNone
Return valueHAL status value:HAL_OK、HAL_ERROR、HAL_BUSY、HAL_TIMEOUT

function:HAL_FLASH_Lock

Function prototypesHAL_StatusTypeDef HAL_FLASH_Lock(void)
Functional DescriptionLock flash control register access
Input parametersNone
Return valueHAL status value:HAL_OK、HAL_ERROR、HAL_BUSY、HAL_TIMEOUT

function:HAL_FLASH_Program

Function prototypesHAL_StatusTypeDef HAL_FLASH_Program
(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
Functional DescriptionUsed for writing data to Flash
Input parameters1TypeProgram:Type of data written: half-word, byte, or double-word
Input parameters2Address:The address where Flash writes data
Input parameters3Data:To write data
Return valueHAL status value:HAL_OK、HAL_ERROR、HAL_BUSY、HAL_TIMEOUT

function:HAL_FLASHEx_Erase

Function prototypesHAL_StatusTypeDef HAL_FLASHEx_Erase
(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError)
Functional DescriptionA pointer to a FLASH_EraseInitTypeDef structure used to erase a sector in Flash memory
Input parameters1pEraseInit:Configure the parameters for the erase operation
Input parameters2PageError:Used to get the sector number of the error in the erase operation
Return valueHAL status value:HAL_OK、HAL_ERROR、HAL_BUSY、HAL_TIMEOUT

5、Experimental phenomenon

After downloading the program successfully, press the RESET button of the development board to open the serial debugging assistant to observe the phenomenon

xxxxxxxxxx
For program download, please refer to [2. Development environment construction and use: program download and simulation]

phenomenon:

Press KEY1: The serial debugging assistant will output the prompt of adding 1 to the count;

Press KEY2: The serial debugging assistant will output the prompt of zero count;

Press KEY3: Serial debugging assistant will read the current count value;

After the development board power off, you can also read the previous count value.

image-20231102193914514

Off-chip Flash (SPI)
DMA:USART

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文