1. Modify the comments of stm8s_conf.h to allow #include "stm8s_flash.h" to compile
2. Modify the injection of stm8s.h to enable the Flash function to run from RAM
#if !defined (RAM_EXECUTION)
#define RAM_EXECUTION (1) // When writing to a block, you must enable injection here
#endif /* RAM_EXECUTION */
3. After the modification is completed, a lot of warnings will be generated. The method to eliminate them has not been found yet, but it will not affect the operation of the code.
Attach the code:
#include "fy_flash.h"
//Before operating the flash, you need to uncomment line 154 in stm8s.h /* #define RAM_EXECUTION (1) */
//Read data from the specified third byte of the block (entry number)
u8 Flash_ReadByte_3(u8 Block)
{
u32 addr;
addr = FLASH_PROG_START_PHYSICAL_ADDRESS + Block*FLASH_BLOCK_SIZE;
return FLASH_ReadByte(addr+2);
}
//Write the content to the specified block of Flash
void Flash_WriteBlock(u8 Block , u8 *buf)
{
if(Block>FLASH_PROG_BLOCKS_NUMBER) return;
FLASH_Unlock(FLASH_MEMTYPE_PROG); //解锁flash
while (FLASH_GetFlagStatus(FLASH_FLAG_PUL) == RESET); //Wait for the unlock flag to be set
//Block standard programming, before writing, the hardware automatically deletes the content
FLASH_ProgramBlock(Block, FLASH_MEMTYPE_PROG, FLASH_PROGRAMMODE_STANDARD,buf);
//Wait for the operation to complete
FLASH_WaitForLastOperation(FLASH_MEMTYPE_PROG);
//Lock after operation
FLASH_Lock(FLASH_MEMTYPE_PROG);
}
//Read the contents of the specified number of blocks from Flash
void Flash_ReadBlock(u8 Block ,u8 *buf)
{
u8 i;
u32 addr;
u8 sta=0;
if(Block>FLASH_PROG_BLOCKS_NUMBER) return;
//Calculate the address
addr = FLASH_PROG_START_PHYSICAL_ADDRESS + Block*FLASH_BLOCK_SIZE;
for(i=0;i { *(buf+i) = FLASH_ReadByte(addr+i); //Read a block of data /* if(buf[i]=='\r' && sta==0) sta=1; else if(buf[i]=='\n' && sta==1) return; else state=0; */ } } void Flash_Test(void) { u8 write_buf[FLASH_BLOCK_SIZE]="MARS->This is a Flash Data Memory write and read test...\r\n"; u8 read_buf[FLASH_BLOCK_SIZE]; Flash_WriteBlock(120,write_buf); Flash_ReadBlock(120,read_buf); UART1_SendString(read_buf); while(1) { LED_TOG;Delay_ms(350); } } /*********************************************END OF FILE**********************************************/
Previous article:[MCU Notes] OLED controller SSD1306 and driver code
Next article:[MCU Notes] Active Buzzer Driver-Efficiency Programming
Recommended ReadingLatest update time:2024-11-15 17:39
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Robot programming design and implementation
- SVPWM Vector Control System of Induction Motor Based on DSP
- 【RT-Thread Reading Notes】Virtual File System
- Read the good book "Electronic Engineer Self-study Handbook" + Reflection
- FPGA implementation of color restoration module in image acquisition system.pdf
- About the RF signal reception problem of AD9361
- The reason why Xiaomi was sanctioned by the United States was revealed, it was because...
- Basic principles and design methods of impedance matching
- Free Download: ADI Multi-Channel Source Measure Unit (SMU) Solutions
- Internet of Things Electricity Metering System Based on RVB2610