Introduction: For block programming of STM8 MCU Flash, the code must be run in Ram memory. Therefore, the code stored in Flash must be copied to Ram for compilation, linking, and running. Cosmic compiler has two implementation methods: creating segments in STVD project and creating memory segments in link file.
1. Create a segment in the STVD project
1) Set the segment name in the project
'project'->'settings'->'linker'->'category'->'input', as shown below:
Set the segment name to '.FLASH_CODE'. Note that options should also be set to '-ic'. The meaning of ic is moveable code.
2) Write the code stored in the FLASH_CODE segment as shown below
#pragma section(FLASH_CODE) //Put the code in the FLASH_CODE section
void writeFlash(void)
{
……
}
void eraseFlash(void)
{
……
}
#pragma section()//code is placed in the default section
2. Create a memory segment in the link file
1) Define a special memory segment in the link file (*.lkf) and mark it with '-ic', as shown below:
2) Write the code stored in the FLASH_CODE segment as shown below
#pragma section(FLASH_CODE) //Put the code in the FLASH_CODE section
void writeFlash(void)
{
……
}
void eraseFlash(void)
{
……
}
#pragma section()//code is placed in the default section
3. You can check whether the settings of the above two methods are correct in the generated map file, as shown in the following map file:
The part marked 'from' is the code storage part, and the part marked 'initialized' is the execution code part.
4. Calling functions
Before calling these functions, the codes must be copied from flash to Ram. The cosmic compiler uses the built-in function 'int _fctcpy(char name)' to implement this function. Name is the first letter of the defined segment name, such as 'F' in this example.
void main(void)
{
……
_fctcpy('F'); //Copy the Flash code to Ram
……
}
Previous article:The principle of capacitive touch in induction cooker
Next article:Points to note when switching clock sources in STM8S MCU low-power applications
- Popular Resources
- Popular amplifiers
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
- 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)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- STEVAL-MKI109V3 Evaluation Method for LIS25BA
- Detailed explanation of Linux device driver development: based on the latest Linux 4.0 kernel
- Embedded Development Electronic Technology Classic Data 12G
- Purpose of inductor: choke, filter, oscillation
- Today's Live Broadcast | Use ModusToolbox to build a system to flexibly meet IoT design challenges
- A 6-year STC fan contribution: a general low-level driver function library based on the STC8 series
- The new TMS320F28377S cannot connect to the emulator, what should I do?
- The digital power supply power line & feedback line do not correspond to the battery
- Does anyone know how the baud rate error is calculated?
- msp430G2231 ADC10 configuration