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

#define FLASH_FIRMWARE_VALUES_LOCATION			0x9D07FFF8

const BYTE firmware_prog_memory_values[] __attribute__((section("firmware_prog_memory_values"),address(FLASH_FIRMWARE_VALUES_LOCATION), space(prog))) =
{
	0x12,
	0x34,
	0x56,
	0x78
};
Reading the values in your code

	p_flash = (DWORD*)FLASH_FIRMWARE_VALUES_LOCATION;
	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)))

const BYTE MY_ATTRIBUTES MasterBootRecord[MEDIA_SECTOR_SIZE] =
{
USEFUL?
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.

Comments

Your email address will not be published. Required fields are marked *