i implement firmware upgrade with bootloader.
i have a bootloader that use Uart, DMA, timers and interrupt.
how can i Reset all of the registers of the CPU after bootloader is jumping to the Application software, in the Application Software.
I hope that you are doing excellent.
I understand , you want to have everything "clear" for the application usage.
I am not sure if you are using one of our Bootloaders and/or which Kinetis part.
However, I recommend you to take a look at the below function :
/*! * @brief Prepare system for exiting the bootloader. * * Performs any cleanup necessary to restore the system to default state prior to * exiting the bootloader. This involves restoring the vector table to default, * managing the flash cache, and so on. * * This routine *must* be invoked prior to permanently exiting the bootloader. * * @param shutdown Specifies different uses for this function * 'kShutdownType_Shutdown' means clean up prior to permanently exiting the bootloader. * 'kShutdownType_Cleanup' means only clear (flush) the flash cache * 'kShutdownType_Reset' means only shutdown all peripherals. */ void shutdown_cleanup(shutdown_type_t shutdown);
This to get an idea of how the bootloader shutdown peripherals when jumping to the main application.
That function can be found in the Freedom Bootloader (flash resident bootloader). Specifically I checked this from the FRDM-K64F MCUXpresso SDK
I hope this could help you.
my boot software is old and i build new application.
the bootloader is use hardware peripheral and interrupt with his vector interrupt.
the application has vector inetrrupt.
the bootloader is not clear hardware register and interrupt
i see that the hardware register (UART, UDMA, DMUX) is not clear after jump to Application.
there is a way to clear/Reset hardware Register in the application
Generating a software reset will clear all of the registers to the data sheet values.
You'll need to look at the RCM registers of your part (you did not say what it was) to decide when to do this.
Here is example code to do the software reset.
When the code restarts SWS will be set in RCM.
Someplace in main() to decide how to handle start up:
* 7 6 5 4 3 2 1 0
* POR PIN WDOG 0 0 0 LVD WAKEUP
* POR (including LVD) — 0x82
• LVD (without POR) — 0x02
• VLLS mode wakeup due to RESET pin assertion — 0x41
• VLLS mode wakeup due to other wakeup sources — 0x01
* RESET pin assertion — 0x40
• Other reset — a bit is set if its corresponding reset source
* caused the reset
* 7 6 5 4 3 2 1 0
* 0 0 SACKERR 0 MDM_AP SW LOCKUP 0
* ACKERR: Stop Mode Acknowledge Error Reset
* MDM_AP (Debugger): MDM-AP System Reset Request
* SW (Software): Indicates a reset has been caused by software
* setting of SYSRESETREQ bit in Application
* Interrupt and Reset Control Register in the
* ARM core.
* LOCKUP (Core Lockup): Indicates a reset has been caused by the
* ARM core indication of a LOCKUP event
wdt_src_u16 = (((uint16_t) RCM_SSRS1 << 8U) | ((uint16_t) RCM_SSRS0) );
Function to call to clear to data sheet values:
#define ATTR_NO_INSTRUMENT_FUNCTION __attribute__( ( no_instrument_function ) )
* The CPSID instruction is self-synchronized to the instruction
* stream and there is no requirement to insert memory barrier
* instructions after CPSID.
static inline ATTR_NO_INSTRUMENT_FUNCTION void irq_disable( void )
__asm__ __volatile__ ("cpsid i");
__asm__ __volatile__ ("" ::: "memory");
static inline ATTR_NO_INSTRUMENT_FUNCTION void sync_barrier_data( void )
__asm__ __volatile__ ("dsb");
__asm__ __volatile__ ("" ::: "memory");
void __attribute__ ((noreturn)) reset_mcu( void );
void __attribute__ ((noreturn)) reset_mcu( void )
* A DSB is required before generating self-reset to ensure all
* outstanding transfers are completed. The use of the CPSID I
* instruction is optional.
SCB_AIRCR = (SCB_AIRCR_VECTKEY(0x05FAU) | SCB_AIRCR_SYSRESETREQ_MASK);
you mast to read my messages.
i don't want to reset the cpu just clear all of the registers in the Application (not in the bootloader) like in Power up after the bootloader is jump to application.
"how can i Reset all of the registers of the CPU after bootloader is jumping to the Application software, in the Application Software. "
As I understand what you wrote above:
The bootloader has messed with lots of things, we don't know what, so we want to start as if we are starting from a clean reset out of the bootloader when it has jumped to our application.
This is how that is handled:
We look at the BOOTLOADER bit in RCM.
When we see that the bootloader was what got us to main(), we issue a software reset to reset the hardware registers to the data sheet values.
How at this second boot we look at RCM again to see if we got here via either Watchdog or SWS reset.
SWS tells us that we got here because the bootloader started us and this is our reset from that event, and this is the second reset in this boot process.
If nothing special needs done on this second boot then no need to look at SWS and the software can treat it as it would POR or PIN-Reset.
This is what I have in my own vectors.c that is the first code executed out of hardware reset:
/* This overrides the weakly linked funciton in vectors.c so we can found out why we rebooted */
void bootloader_mr_setup( void );
void bootloader_mr_setup( void )
* RCM_MR Indicates the boot source, the boot source remains set
* until the next System Reset or software can write logic one to
* clear the corresponding mode bit. While either bit is set the
* NMI input is disabled and the vector table is relocated to the
* ROM base address at 0x1C00_0000. These bits should be cleared by
* writing logic one before executing any code from either Flash or
* A reset is forced to clear out anything that the ROM
* bootloader did, so we are sure we have the data sheet reset
* This method works around the buggy KL43/27/17 bootloaders as
* described in: "Problem Analysis and solutions for booting from
* ROM BOOTLOADER in KL series".
boot_src_u16_n = ( ( ( uint32_t ) RCM_FM << 8U ) | ( ( uint32_t ) RCM_MR ) );
if( 0U != ( RCM_MR & RCM_MR_BOOTROM_MASK ) )
RCM_MR = RCM_MR_BOOTROM_MASK; /* Clear the bits that indicated a bootlaoder boot via ROM */
RCM_FM = 0U; /* Boot from Flash not ROM on next reset */
SCB_AIRCR = ( SCB_AIRCR_VECTKEY( 0x05FAU ) | SCB_AIRCR_SYSRESETREQ_MASK ); /* Force a Software Reset */
RCM_FM = 0U;