Difference between revisions of "NU32v2: A Detailed Look at Programming the PIC32"
Line 1: | Line 1: | ||
After you have [[NU32v2: Starting a New Project and Putting it on the NU32v2|programmed your PIC32 for the first time]] and verified that you can create a new project, compile it, and run it on your NU32v2, it is useful to take a step back and understand the basics of the programming process, beginning with a PIC32 fresh from the factory. We will do that on this page. We will begin by discussing the virtual memory map of the PIC32. To discuss the virtual memory map, it is useful to know |
After you have [[NU32v2: Starting a New Project and Putting it on the NU32v2|programmed your PIC32 for the first time]] and verified that you can create a new project, compile it, and run it on your NU32v2, it is useful to take a step back and understand the basics of the programming process, beginning with a PIC32 fresh from the factory. We will do that on this page. We will begin by discussing the virtual memory map of the PIC32. To discuss the virtual memory map, it is useful to know ''hexadecimal'' (hex, or base 16) notation, where each digit of a hex number takes one of 16 values, 0...9, A...F. Since 16 = 2^4, a single hex digit represents four digits of a number written in binary (base 2). The table below gives examples. |
||
<table border=1 cellpadding=5> |
<table border=1 cellpadding=5> |
||
Line 27: | Line 27: | ||
= The PIC32 Memory Map = |
= The PIC32 Virtual Memory Map = |
||
The PIC32 has a virtual memory |
The PIC32 has a ''virtual memory map'' consisting of 4 GB (four gigabytes, or 2^32 bytes, where each byte equals 8 bits) of addressable memory. All memory regions reside in this virtual memory space at their unique respective addresses. This includes (flash) program memory, data memory (RAM), peripheral special function registers (SFRs), and configuration registers (e.g., bits that control the the system clock period and other functions). For example, the peripheral SFRs begin at virtual memory location 0xBF800000 and end at virtual memory address 0xBF8FFFFF. Subtracting the begin address from the end address, and adding one byte, we get 0x100000, which is 1*16^5 = 1,048,576, commonly written as 1 MB. '''(Note: Section 3 of the reference manual has the calculation as 4 KB, so either the end address or the calculation is wrong in the reference manual.)''' |
||
In addition to this virtual memory map, there is also a ''physical memory map''. When you are writing a program, you only deal with the virtual memory map. The PIC implements a Fixed Mapping Translation (FMT) unit that takes the virtual memory address and maps it to a physical memory address. In other words, the virtual memory address is translated to a set of bit values on an addressing bus that allows the PIC's CPU to address the appropriate peripheral, flash memory location, RAM location, etc. We will focus on the virtual memory map, since our goal is to program the PIC. |
|||
Virtual memory is split into two types of address space: user address space and kernel address space. |
|||
Revision as of 07:53, 17 January 2011
After you have programmed your PIC32 for the first time and verified that you can create a new project, compile it, and run it on your NU32v2, it is useful to take a step back and understand the basics of the programming process, beginning with a PIC32 fresh from the factory. We will do that on this page. We will begin by discussing the virtual memory map of the PIC32. To discuss the virtual memory map, it is useful to know hexadecimal (hex, or base 16) notation, where each digit of a hex number takes one of 16 values, 0...9, A...F. Since 16 = 2^4, a single hex digit represents four digits of a number written in binary (base 2). The table below gives examples.
Hex | Binary | Base 10 |
7 | 0111 | 7 |
D | 1101 | 13 |
B5 | 1011 0101 | 181 |
To distinguish hex and binary numbers from base 10 numbers, we begin the numbers with 0x and 0b, respectively. For example, 0xA9 = 10*16^1 + 9*16^0 = 0b10101001 = 1*2^7 + 0*2^6 + 1*2^5 + 0*2^4 + 1*2^3 + 0*2^2 + 0*2^1 + 1*2^0 = 160 = 1*10^2 + 6*10^1 + 0*10^0. The 0x and 0b conventions are also used in the C language.
The PIC32 Virtual Memory Map
The PIC32 has a virtual memory map consisting of 4 GB (four gigabytes, or 2^32 bytes, where each byte equals 8 bits) of addressable memory. All memory regions reside in this virtual memory space at their unique respective addresses. This includes (flash) program memory, data memory (RAM), peripheral special function registers (SFRs), and configuration registers (e.g., bits that control the the system clock period and other functions). For example, the peripheral SFRs begin at virtual memory location 0xBF800000 and end at virtual memory address 0xBF8FFFFF. Subtracting the begin address from the end address, and adding one byte, we get 0x100000, which is 1*16^5 = 1,048,576, commonly written as 1 MB. (Note: Section 3 of the reference manual has the calculation as 4 KB, so either the end address or the calculation is wrong in the reference manual.)
In addition to this virtual memory map, there is also a physical memory map. When you are writing a program, you only deal with the virtual memory map. The PIC implements a Fixed Mapping Translation (FMT) unit that takes the virtual memory address and maps it to a physical memory address. In other words, the virtual memory address is translated to a set of bit values on an addressing bus that allows the PIC's CPU to address the appropriate peripheral, flash memory location, RAM location, etc. We will focus on the virtual memory map, since our goal is to program the PIC.
Virtual memory is split into two types of address space: user address space and kernel address space.
can execute from data memory
FMT to physical memory. as programmer, only need to know virtual.