PIC32 stores 32bit words with address incrementing by 4 for each instruction

PIC32's implement two address schemes: virtual and physical.

All hardware resources (program memory, data memory and peripherals) are located at their respective physical addresses.

Virtual addresses are exclusively used by the CPU to fetch and execute instructions as well as access peripherals.

Physical addresses are used by bus master peripherals, such as DMA and the Flash controller, that access memory independently of the CPU.

KSEG0 and KSEG1 both translate to the same physical memory. They are created as separate memory segments because KSEG0 can be cached by the application whilst KSEG1 cannot:

KSEG0 is cacheable

KSEG1 is not cacheable. On chip peripherals are only accessible through this segment (SFR not present in the KSEG0 memory range)

Storing Constants In Program Memory At A Fixed Address

The following works for V2.00 and above of the C32 compiler

Setting the values in program memory


const BYTE firmware_prog_memory_values[] __attribute__((section("firmware_prog_memory_values"),address(FLASH_FIRMWARE_VALUES_LOCATION), space(prog))) =
Reading the values in your code

	dw_temp.Val = p_flash[0];
	magic_marker.v[1] = dw_temp.v[0];
	magic_marker.v[0] = dw_temp.v[1];

C32 Storing in program memory example

From USB Device – Mass Storage – Internal Flash Demo – XC32 – PIC32MX460F512L PIM.mcp

//.MDD_FILES doesn't need to have been defined in the linker script etc, its just a name to be applied to this
//space(prog) forces the allocation into program memory - newer version of the C32 compiler changed from stored const memory in program memory to ram for some unknown reason
#define MY_ATTRIBUTES __attribute__ ((aligned (ERASE_BLOCK_SIZE),section(".MDD_FILES"),space(prog)))

We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.