When the program go into the external interrupt function, I can use NVIC_SetPendingIRQ to jump out to the main function. Then I use NVIC_ClearPendingIRQ in the main function, but I can't return back to the external interrupt function. So I want to know the right usage of it.
An interrupt can be (1) pending or not pending, (2) active or not active and (3) enabled or not enabled.
Pending means queued up to run.
Active mean running now (or was running but got pre-empted by a higher priority nested interrupt).
Enabled means that it can go from pending to active automatically.
If an interrupt is enabled and you call NVIC_SetPendingIRQ from the main context you have changed the state to "not active and pending", but this state is immediately changed by hardware to "active and not pending".
While the interrupt is active it can be triggered again either by hardware or software, in this case it would be "both active and pending" (ie: running and queued up to run again).
If you return from the interrupt function while you are active and pending then you will immediately jump back to the start of the same interrupt function again (assuming that no higher priority interrupt was also pending) but now you will be "active and not pending".
If you are active and pending but don't want to run the interrupt function twice, you can call NVIC_ClearPendingIRQ before you return from the interrupt function.