How to disable Keil from initializing zero RAM & how to determine whether it is a soft reset or a power-on Reset

Source: Internet
Author: User

Notes:

(1) How do I disable Keil from initializing zero Ram?

1. Hook in Keil noinit

2. <1> specify a region with the _ at keyword for the variable requiring Hot Start and persistence; otherwise, it is useless (# include "absacc. H ")

<2> or _ attribute _ (zero_init) keyword. BSS segment

Int test1 = 1;

_ Attribute _ (zero_init) int Test2;

Int test3 _ at (0x20001000 );

View Map Files

Test1 0x20000000 data 4 main. O (. Data)
Test2 0x2000000c data 4 main. O (. BSS)
Test3 0x20001000 data 4 main. O (. Arm. _ at_0x20001000)

 

(2) How can I determine whether it is a soft reset or a power-on reset for stm32?

Flag = rcc_getflagstatus (rcc_flag_sftrst); // power-on reset flag = 0, software reset flag = 1

Void restful CPU (void)
{
_ Set_faultmask (1); // close all middle ends
Nvic_systemreset (); // Reset
}

 

Microprocessor: lpc2114

Compiling environment: Keil MDK v4.10

Ideas:

Reset of single-chip microcomputer systems is often dividedCold start and hot start. The so-called cold start, which is generally referred toPower-On Reset,After the cold start, the RAM content inside and outside the slice is random.Generally, it is 0x00 or 0xff. The hot start of the single chip microcomputer is realized by a reset level on the reset end of the Single Chip Microcomputer in the operation through an external circuit, that isKey reset or watchdog Reset. After resetting,Ram content has not changed. In some scenarios, You must distinguish whether the device restarts after a hot or cold restart. The common method is to determine the memory unit as the flag bit (for example, 0x40003ff4 ~ 0x40003ff7
Ram unit), first read the content of the memory unit at startup. If it is equal to a specific value (for example, 0xaa55aa55), it is considered as a hot start; otherwise, it is a cold start.

Define a variable based on the above design ideas:

Uint32Unstartflag;

Judge when the program starts:

If(Unstartflag = 0xaa55aa55)

{

// Hot start processing

}

Else

{

// Cold start processing

Unstartflag = 0xaa55aa55;

}

However, in actual debugging, it is found that either hot start or cold start,The value of all memory units is reset to 0 after startup.Of course, it cannot meet the hot start requirements. By looking at the startup code startup. s that comes with Keil MDK, no statement is found in this startup code to clear the entire Ram region. The disassembly program finds that the compiler also executes many library functions from the execution of the startup code to the jump to the main function,The _ scatterload_zeroinit function initializes all w/R Ram to 0 (under the default setting ).In order to judge cold and hot boot, some Ram must be manually controlled and not initialized to 0 by the compiler during resetting. Find the compiler manual, separate a small piece of RAM in the ram for the processor, and set it to noinit format (not initialized to 0), for example:

Then use the _ at keyword to locate the cold and hot start signs in the noinit area:

Uint32 unstartflag _ at (0x40003ff4 );

In this way, the memory region where the variable unstartflag is located will not be initialized to 0 during hot start, and the cold/hot start judgment is also realized.

Define a ferrite 0xff7 ~ 0xff8 region storage cold start times

0xff9 ~ 0xffa region Storage Hot Start times

0xffb ~ 0xffc total number of regional storage startup times

 

Another method:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.