September 28, 2011
are reproduced from the Power Grid – the blog of the plush, three articles re-edit together as one, the content does not make any changes.
original link: Freescale 16-bit single-chip address mapping – (1) Introduction
Freescale 16-bit microcontroller address mapping – (2) Freescale 16-bit microcontroller Freescale 16-bit microcontroller, the allocation of resources
address mapping – (3) the codewarrior of prm file
Introduction:
the original has been less understand the MCU address mapping, there is no careful study, I think this is the reason I not a cow person. Usually begins to learn the microcontroller, is write some small programs, If you do not do enough project development, resource allocation Freescale 16-bit microcontroller. Long ago encountered a problem and need to keep a constant array in RAM, but just exist in RAM, then, is kept high, taking into account the array is constant, it can only exist in ROM, but it was time than short, there is no research to understand, also received a very painful lesson, and feel that can not be reconciled, and intend to take the time to study a little. In a future article, I will record my experiences down, hope everyone comments.
Freescale 16-bit MCU resource allocation
to MC9S12XS128MAL for example, in fact, DG128 class is similar. Figure 1, 128 represented by a Byte of the microcontroller FLASH size is 128K, the same reason 64 on behalf of a Byte of the microcontroller FLASH size is 64 K, 256 on behalf of the microcontroller FLASH size of 256 K, a Byte. But the S12 (X) the kernel CPU12 (X), address bus 16, the addressing range up to 2 ^ 16 = 64K a Byte, this 64K Byte address space also includes registers, EEPROM (Data Flash simulation ), RAM, so not all of the 64K byte are used to addressing the FLASH. S12 (X) series of microcontrollers, a lot of resources is a form of paging, including EEPROM, RAM, FLASH,. The EEPROM page size 1K Byte of RAM per page size of 4K a Byte FLASH page size is 16K a Byte. Therefore, the number of pages for the XS128 in EEPROM 8K/1K = 8 pages, the number of pages of RAM for the 8K/4K = 2 pages, Flash pages for 128K/16K = 8 pages.
a
two
in a single-chip common mode, after reset, all memory resources mapping as shown in Figure two, including the mapping from the range of 0×0000-0×07FF are 2K registers, such as I / O port registers, etc., of course, registers not so much , the latter actually does not use;
0×0800-0×0BFF, a total of 1K space mapping for the EEPROM area, by the above analysis, a total of eight in the XS128 a total of 8K EEPROM, so this 8 page of the EEPROM are in the form of the pagination, you can choose a different page by setting the register EPAGE visit;
from 0×0C00 to 0×0FFF 1K reserved area (in fact, there is also learned later explore);
RAM area from 0×1000 to 0×3FFF 12K space is divided into three, and said before the EEPROM, three 2 (XS128 and XS256 ) or a (for XS64) to a fixed page, in the 12K space part of the to XS128 example, the internal RAM resources for the 8K, so the last two of its three (0×2000-0×3FFF) as a fixed page, The first page (0×1000-0×1FFF) for the window area, by setting the register RPAGE to map other paged RAM, of course, in monolithic ordinary mode, the XS128 internal other RAM, so this page and it is no use. For XS256 this page is useful, because it is a total of 12K of RAM. However, in monolithic ordinary mode, ie no external expansion RAM, the user is not deliberately to configure RPAGE the point that a RAM reset when the default.
a total of 48K of space from 0×4000-0xFFFF Flash section is divided into three. The first and third pages of the fixed Flash page, the middle one (0×8000-0xBFFF The) for the window area, by setting PPAGE register can be mapped to other paging Flash.
the last 256 bytes in the last one fixed flash area, holds the interrupt vector.
for RAM and Flash, in fact, fixed page and paging resources are unified addressing different fixed page can not be mapped register (RPAGE, PPAGE) change, while others page must be mapped register set to select different page. prm file
the codewarrior of the widely circulated online article about 8 Freescale MCU memory map, and these days, what Codewarrior 5.0 prm file, based on 16 the microcontroller MC9S12XS128, little experience, and to share with you. What is wrong please correct me. of on Codewarrior in the prm file
strong> to discuss the address mapping of the microcontroller, you must contact the prm file, this discussion Codewarrior 5.0 compiler, the microcontroller using MC9S12XS128 .
new project created by the project template has a name for roject.prm file in the Project Settings-> Linker Files folder. A standard based on the XS128. Prm beginning of the file contents are as follows:
prm strong> The file example:
strong> < strong> NAMES
strong> END
strong> SEGMENTS
strong> RAM = READ_WRITEDATA_NEAR 0×2000 TO0×3FFF;
ROM_4000 = READ_ONLYDATA_NEAR IBCC_NEAR0×4000 TO0×7FFF;
ROM_C000 = READ_ONLYDATA_NEAR IBCC_NEAR0xC000 TO0xFEFF;
/ / OSVECTORS = READ_ONLY 0xFF10 TO 0xFFFF;
EEPROM_00 = READ_ONLYDATA_FAR IBCC_FAR0×000800 TO0×000BFF;
EEPROM_01 = READ_ONLYDATA_FAR IBCC_FAR0×010800 TO0×010BFF;
EEPROM_02 = READ_ONLYDATA_FAR IBCC_FAR0×020800 TO0×020BFF;
EEPROM_03 = READ_ONLYDATA_FAR IBCC_FAR0×030800 TO0×030BFF;
EEPROM_04 = READ_ONLYDATA_FAR IBCC_FAR0×040800 TO0×040BFF;
EEPROM_05 = READ_ONLYDATA_FAR IBCC_FAR0×050800 TO0×050BFF;
EEPROM_06 = READ_ONLYDATA_FAR IBCC_FAR0×060800 TO0×060BFF;
EEPROM_07 = READ_ONLYDATA_FAR IBCC_FAR0×070800TO0×070BFF;
PAGE_F8 = READ_ONLYDATA_FARIBCC_FAR0xF88000 TO0xF8BFFF;
PAGE_F9 = READ_ONLYDATA_FAR IBCC_FAR0xF98000 TO0xF9BFFF;
PAGE_FA = READ_ONLYDATA_FAR IBCC_FAR0xFA8000 TO0xFABFFF;
PAGE_FB = READ_ONLYDATA_FAR IBCC_FAR0xFB8000 TO0xFBBFFF;
PAGE_FC = READ_ONLYDATA_FAR IBCC_FAR0xFC8000 TO0xFCBFFF;
PAGE_FE = READ_ONLYDATA_FAR IBCC_FAR0xFE8000 TO0xFEBFFF;
END
strong> PLACEMENT
strong> _PRESTART,
STARTUP,
ROM_VAR,
STRINGS,
VIRTUAL_TABLE_SEGMENT,
/ /. ostext,
DEFAULT_ROM, NON_BANKED, < br />
COPYINTOROM_C000; OTHER_ROM INTOPAGE_FE, PAGE_FC, PAGE_FB, PAGE_FA, PAGE_F9, PAGE_F8 ;/ /. stackstart, SSTACK, / /. stackend, PAGED_RAM, DEFAULT_RAM INTORAM; DISTRIBUTE DISTRIBUTE_INTO ROM_4000, PAGE_FE, PAGE_FC, PAGE_FB, PAGE_FA , PAGE_F9, PAGE_F8; CONST_DISTRIBUTE DISTRIBUTE_INTO ROM_4000, PAGE_FE, PAGE_FC, PAGE_FB, PAGE_FA, PAGE_F9, PAGE_F8; DATA_DISTRIBUTE DISTRIBUTE_INTO RAM; / /. vectors INTO OSVECTORS; END strong> ENTRIES strong> / / _vectab OsBuildNumber _OsOrtiStackStart _OsOrtiStart END strong> STACKSIZE strong> 0×100 VECTOR 0 _Startup strong> / / VECTOR 0 Entry / / INIT Entry 1. strong> < of strong> prm strong> file structure
strong> has six components constitute the information contained in the different prm file, here we only discuss the mapping and memory space close three parts, the other will not be discussed.
SEGMENTS strong> … END
strong> defined and divided into chips of all available memory resources, including program space and data space . General our program space defined as the ROM, the data space is defined as the RAM, but these names are not retained by the system keywords, can be freely modified by the user. Users memory space addresses and property arbitrarily divided into different size blocks, each block can be freely named. For example, the same RAM, you can use different attributes, it is reset after the variable is cleared and not cleared.
in the back on the memory by Detailed. the
· ,-PLACEMENT strong> … END
strong> will be assigned to various sections, such as defined in the source data segment DATA_SEG , CONST_SEG and code snippets CODE_SEG specifically placed where a block of memory. It is linked to the bridge will be defined in the source description and the actual physical memory.
STACKSIZE
strong> defined length of the system stack, followed by the length of the given number of bytes depending on the application to modify. The actual positioning of the stack depends on the division and use of RAM memory. By default, the stack on the initial part of the RAM area. Of course, the definition of the stack is not only in this way can also use STACKTOP keywords. Later discussed in detail.
2 strong> by way of memory
strong> SEGMENTS to END until the middle you can add any multi-line memory the definition of the division, each line terminated by a semicolon. Defined line syntax type is:
[block] = [a property] [property], …, attribute n] [start address] TO [End address];
“block” the definition and the C language variable is identical to the definition based on the letters of the alphabet at the beginning of a string, the user can arbitrarily define the block.
“attribute” user can not define their own, because the property name is specified the above mentioned “block” corresponding to the different memory types and access methods, different types of physical memory and access is for certain.
“Properties”, Codewarrior 5.0 There are three different types of Flash-ROM read-only attribute is READ_ONLY, readable and writable RAM area property can be READ_WRITE, but also can be the NO_INIT. They are both the key difference is the ANSI-C initialization code will locate READ_WRITE block all global and static variables are automatically cleared in NO_INIT block variables will not be cleared automatically. Of course, just reset is cleared, or cleared when the power-down, but the SCM system, the variable reset automatically clears this feature is sometimes very critical in some applications for special purposes.
“attribute … attribute n”, given in accordance with the above. prm example file can be seen, may be in the form of the “DATA_FAR the” DATA_NEAR “, the” IBCC_FAR “,” IBCC_NEAR four types. Among them, “DATA_FAR and the” DATA_NEAR “corresponds to the memory area contains a variable or constant (usually RAM, Flash, and EEPROM), in one of the above two properties must be specified, as it relates to memory paging, can be understood: the DATA_FAR “attribute specifies the memory block can be saved non-fixed data page the the” DATA_NEAR “attribute specifies the block of memory that can save the data of the fixed page; Similarly the” IBCC_FAR “and” IBCC_NEAR corresponds to When the memory area that contains the code (Flash and EEPROM), must specify the above two properties the IBCC_FAR “attribute specifies the memory block can be saved non-fixed code page the the” IBCC_NEAR “attribute specifies the memory block You can save a fixed code page
discussed here, the careful reader has been found that the above example of the prm file, the attributes of RAM DATA_FAR “and” DATA_NEAR Flash properties mentioned is also four kinds are in EEPROM the only DATA_FAR “and both the” IBCC_FAR “This is just to verify the previous article (16 Freescale MCU resource allocation), RAM, Flash, have a fixed page, but the EEPROM non-fixed page.
start address and end address to determine the physical location of a memory block, for a fixed page four hexadecimal number, and for the non-fixed page, six hexadecimal said that the extra two in fact the register EPAGE, RPAGE or PPAGE value, visible for the paging resource is addressable register (combination of the EPAGE, RPAGE or PPAGE) and 16-bit address bus.
“TO” system reserved keywords must be uppercase.
Now, according to the content provided in the example above, a few examples:
cases 1 strong> RAM = READ_WRITEDATA_NEAR, 0×2000TO0×3FFF;
The above meaning of this sentence: Allocation 0×2000-0×3FFF region called “RAM” (of course you can define another name) on an article with knowledge, the nature of this area of ??physical memory as RAM property should READ_WRITE “, and two in this area for a fixed page, so DATA_NEAR.
cases 2 strong> the back of the 8K bytes of RAM 4K bytes defined as non-automatic cleared data retention, should be defined as follows:
SEGMENTS
strong> ……
strong> RAM = READ_WRITEDATA_NEAR 0×2000TO0×2FFF;
RAM_NO_INIT = NO_INITDATA_NEAR 0×3000TO0×3FFF;
……
strong> END
strong> Note that the distribution of each part of the RAM address overlap should not exist, otherwise an error will occur.
cases 3 strong> EEPROM_00 = READ_ONLYDATA_FARIBCC_FAR0×000800TO0×000BFF;
XS128 microcontroller EEPROM Data – Flash simulation, so the attribute is READ_ONLY. EEPROM are all non fixed page, and so the “DATA_FAR”, “IBCC_FAR. Behind the start and end addresses, respectively, six hex digits, the first two digits “00″ in real terms refers to the EEPROM paging the register EPAGE the value 0×00.
the SEGMENTS only from this point of view of the physical memory of the microcontroller to its space division. Source itself does not know the physical memory is divided and attributes defined in these details. Between them must pass the following PLACEMENT establish contact.
3 strong> the program and data segments placed
strong> PLACEMENT-the END within the description of the information is to tell the connector various types of segments are defined in the source should be specific to place where a memory block. The syntax type is:
[paragraph 1], [paragraph 2], …, [section name n] INTO [memory block 1], [memory block 2], … , [memory block n];
[paragraph 1], [2], …, [n] DISTRIBUTE_INTO memory block 1], [memory block 2], …, [memory block n];
name in the source code using “# pragma” The name of the statement of the data segment, constant segment or code segment. If you use the default name “DEFAULT”, the default data segment the called DEFAULT_RAM, code segment and the segment of constant named DEFAULT_ROM. If a program is defined in section name is not mentioned in the PLACEMENT, it will be deemed as the DEFAULT. Several of the same nature but different name of the segment can be placed in the same block of memory with each other, separated by commas.
INTO system retains the key words here to mean “put”.
DISTRIBUTE_INTO system reserved keywords. The Codewarrior function automatically optimize memory, but in the “Small memory model, this feature is not enabled, this feature will be enabled only when the 16-bit address space can not store all the variables and code.
SEGMENTS-END region, when the properties of the memory module with the “DATA_FAR”, “DATA_NEAR the” IBCC_FAR “,” the IBCC_NEAR “four kinds of properties of any kind, then PLACEMENT-END region specified in paragraph “DISTRIBUTE”, “CONST_DISTRIBUTE the” DATA_DISTRIBUTE “(the system default, non-keyword, the user can make changes to) the allocated memory space, which requires the use DISTRIBUTE_INTO keyword.
on automatic memory optimization capabilities, can refer to the freescale the official manual TN 262.pdf “. Memory block earlier SEGMENTS divided into good memory block name.
this intuitive positioning descriptive text can be easy and flexible data or code to any possible position of chip memory, and some special purpose applications.
The following example illustrates the correspondence between the various section name, PLACEMENT and SEGMENTS.
cases strong> 4 strong> definition of non-automatically clears the data segment
SEGMENTS
strong> ……
strong> RAM = READ_WRITEDATA_NEAR 0×2000TO0×2FFF;
RAM_NO_INIT = NO_INITDATA_NEAR 0×3000TO0×3FFF;
< strong> …
strong> END
strong> PLACEMENT
strong> ……
strong> DATA_PERSISTENT INTO RAM_NO_INIT;
……
strong> END
strong> / / to write source code:
# the pragma DATA_SEG DATA_PERSISTENT / / reset the definition of non-custom cleared data segment
byte sysState the ;
# pragma DATA_SEG, the DEFAULT
4 strong> stack settings
strong> on the stack set, Codewarrior in two ways: the STACKSIZE “command mode” STACKTOP command mode. These two methods in a prm file, not both. The STACKSIZE way when users care only about the size of the stack without concern stack location is recommended.
default way to use STACKSIZE way.
the STACKSIZE strong> command:
strong> When the STACKSIZE command mode, if in part PLACEMENT-END statement SSTACK INTORAM “, so, the stack area to be placed in the starting part of the RAM area, the following examples illustrate this way:
cases 5
strong> SEGMENTS
strong> ……
strong> RAM = READ_WRITEDATA_NEAR 0×2000 TO0×3FFF;
…
strong> END
strong> PLACEMENT
strong> ……
strong> SSTACK, PAGED_RAM, DEFAULT_RAM INTORAM;
……
strong> < strong> END
strong> STACKSIZE strong> 0×100
above example is stored in the stack area address 0×20FF-0×2000, the initial stack pointer to the top of the stack address 0×20FF.
On the contrary, in the PLACEMENT-END section is not declared “SSTACK INTORAM”, the stack is assigned to the allocated space in the RAM area behind. See Example 6.
cases 6
strong> SEGMENTS
strong> …
strong> RAM = READ_WRITEDATA_NEAR 0×2000TO0×3FFF;
……
strong> END
strong> PLACEMENT
strong> ……
strong> PAGED_RAM, DEFAULT_RAM INTORAM;
…
strong> END
strong> the STACKSIZE strong> 0×100 In this example, if the RAM area has been allocated variable occupies four bytes (from 0×2000 to 0×2003), and the stack on the back of the four bytes from 0×2103 to 0×2004, the initial stack pointer to 0×2103.
STACKYOP strong> command mode:
strong> When use STACKTOP command mode, if in the PLACEMENT-END section declares ” SSTACK INTORAM “, the same stack area on the RAM area of ??the initial part of the initial stack specified by the STACKTOP. If there is no corresponding statement, the initial stack STACKTOP specified stack size set by the compiler depending on the processor, its size is enough to hold the processor of the PC register.