For STM32, there are two ways to reset the software:
1) Use the official software library
The system reset function is directly provided in the stm32f10x_nvic.c file of the official software library
/****************************************************** ******************************
* Function Name: NVIC_GenerateSystemReset
* Description: Generates a system reset.
* Input: None
* Output: None
* Return : None
********************************************* **********************************/
void NVIC_GenerateSystemReset(void)
{
SCB->AIRCR = AIRCR_VECTKEY_MASK | (u32 )0x04;
}
But isn't it OK to just call this function?
There is such a sentence in the Cortex-M3 authoritative guide
There is a point to note here: there is often a delay from the time SYSRESETREQ is asserted to the time the reset generator executes the reset command
. During this delay, the processor can still respond to interrupt requests. But our original intention is often
to stop the execution here and not do anything else. Therefore, it is best to
set FAULTMASK before issuing a reset request.
So it is best to set FAULTMASK to be on the safe side.
The official stm32f10x_nvic.c file also provides this function directly
/****************************************************** ******************************
* Function Name: NVIC_SETFAULTMASK
* Description: Enables the FAULTMASK priority: Raises the execution priority to -1 .
* Input : None
* Output : None
* Return : None
************************************* ******************************************/
void NVIC_SETFAULTMASK(void)
{
__SETFAULTMASK ();
}
So to reset the system, just call these two functions.
NVIC_SETFAULTMASK();
GenerateSystemReset();
2) Write the corresponding assembly code yourself
In fact, the principle is the same. I didn't see the official function at first, so I wrote it myself. In fact, if you look at the official function, it actually calls the same code as cortexm3_macro.s. Haha.
My code:
/*******************************************************************************
* Function Name : SystemReset
* Description : Configures the port pin connected to the push button. GPIO_D_4
* Input : None
* Output : None
* Return : None
*******************************************************************************/
__asm void SystemReset(void)
{
MOV R0, #1 //;
MSR FAULTMASK, R0 //; Clear FAULTMASK Disable all interrupts
LDR R0, =0xE000ED0C //;
LDR R1, =0x05FA0004 //;
STR R1, [R0] //; System software reset
deadloop
B deadloop //; Dead loop prevents the program from running to the following code
}
Then when you need it, just call the function directly in the C program.
SystemReset();
In the MDK environment, when the assembly code is embedded in the C code, writing and calling it is the same as C function.
The above function is defined in misc.c;
The function is declared in misc.h: void SystemReset(void);
Call function in main.c: SystemReset();
Replenish:
Software reset code common to MDK and IAR:
#if defined ( __CC_ARM ) /*------------------RealView Compiler ------------------*/
__asm void GenerateSystemReset (void)
{
MOV R0, #1 //;
MSR FAULTMASK, R0 //; FAULTMASK disables all interrupts
LDR R0, =0xE000ED0C //;
LDR R1, =0x05FA0004 //;
STR R1, [R0] //;
deadloop
B deadloop //;
}
#elif (defined (__ICCARM__)) /*------------------ ICC Compiler -------------- -----*/
//#pragma diag_suppress=Pe940
void GenerateSystemReset(void)
{
__ASM("MOV R0, #1");
__ASM("MSR FAULTMASK, R0");
SCB->AIRCR = 0x05FA0004;
for( ;;);
}
In the above code, the program can be reset when running in FLASH, but it fails to be debugged in RAM. The reason may be that the boot on the board is loose, resulting in problems with the RAM boot selection.
From the above, we can see that the embedded assembly under IAR is not a simple asm("...");, such as asm("LDR R0, =0xE000ED0C "); will report an error
Previous article:STm32 uses stm32cube GPIO to light up the LED
Next article:STM32F0xx IAP implementation of interrupt vector table redefinition
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Let's talk about millimeter wave: What is millimeter wave? What can millimeter wave do?
- Request a switching power supply voltage regulator circuit principle explanation
- EEWORLD University ---- Live playback: The most important component of the analog world - Signal chain and power supply: Sensor
- MSP430 Software Development Manual
- bq25895 can't charge, urgent
- TMU Introduction and Usage
- Analysis of driving circuit in switching power supply 7
- TMS320F28035 bidirectional 400V-12V DC/DC converter design
- Why are the component angles in the AD09 component package library all changed to 10 degrees?
- How to improve the load capacity of power chip