Saturday, May 9, 2020

More BC II Progress

The last few days since the last post on this have been trying.  Lots of information to plow through on how to make a bootloader work on a PIC32.  After solving the bootloader connecting as a USB HID device, it was off to loading an application.  This required modifying the linker script.  One would have thought this was straight forward, but it wasn't.  Reading the Micorchip forum found lots of people looking and what appeared to be lots of solutions.  Plus Micorchip had an old App Note (AN1388) that described the process.  So here are the parameters I used

  • Bootloader occupies 56K bytes(debug console/lots of printf), allocated 0x1000 space to it.
  • The PIC32MX470F512H has 512K bytes of program space, allocated 384K for the App.
  • App Space starts at  0x9D01 0000
  • Interrupt Vector table is at 0x9D01 0000
  • Reset Address is at 0x9D01 1000
  • App code starts at 0x9D01 1200
Through basic testing it all works as I expect.  There is still more testing needed and I need to update the PC program I use with my PC based applications.  Any firmware upgrades need to be part of the user application and not a separate program.

The important part of the linker script is shown below. The bootloader linker script was the default with only the length of the kesg0_program_memory changed.

OUTPUT_FORMAT("elf32-tradlittlemips")
OUTPUT_ARCH(pic32mx)
ENTRY(_reset)
/*
 * Provide for a minimum stack and heap size
 * - _min_stack_size - represents the minimum space that must be made
 *                     available for the stack.  Can be overridden from
 *                     the command line using the linker's --defsym option.
 * - _min_heap_size  - represents the minimum space that must be made
 *                     available for the heap.  Can be overridden from
 *                     the command line using the linker's --defsym option.
 */
EXTERN (_min_stack_size _min_heap_size)

/*************************************************************************
 * Processor-specific object file.  Contains SFR definitions.
 *************************************************************************/
INPUT("processor.o")


/*************************************************************************
 * Processor-specific peripheral libraries are optional
 *************************************************************************/
OPTIONAL("libmchp_peripheral.a")

/*************************************************************************
 * For interrupt vector handling
 *************************************************************************/
PROVIDE(_vector_spacing = 0x00000001);
_ebase_address =  0x9D010000;

/*************************************************************************
 * Memory Address Equates
 * _RESET_ADDR      -- Reset Vector
 * _BEV_EXCPT_ADDR  -- Boot exception Vector
 * _DBG_EXCPT_ADDR  -- In-circuit Debugging Exception Vector
 * _DBG_CODE_ADDR   -- In-circuit Debug Executive address
 * _DBG_CODE_SIZE   -- In-circuit Debug Executive size
 * _GEN_EXCPT_ADDR  -- General Exception Vector
 *************************************************************************/
_RESET_ADDR              = 0x9D011000;    /*  0xBFC00000;*/
_BEV_EXCPT_ADDR          = (0xBFC00000 + 0x380);
_DBG_EXCPT_ADDR          = (0xBFC00000 + 0x480);
_DBG_CODE_ADDR          = 0xBFC02000;
_DBG_CODE_SIZE           = 0xFF0;
_GEN_EXCPT_ADDR          = _ebase_address + 0x180;

/*************************************************************************
 * Memory Regions
 *
 * Memory regions without attributes cannot be used for orphaned sections.
 * Only sections specifically assigned to these regions can be allocated
 * into these regions.
 *************************************************************************/
MEMORY
{
  kseg0_program_mem    (rx)  : ORIGIN = 0x9D012000, LENGTH = 0x60000 /* All C Files will be located here */
  kseg0_boot_mem             : ORIGIN = 0x9D010000, LENGTH = 0x0 /* This memory region is dummy */
  exception_mem              : ORIGIN = 0x9D010000, LENGTH = 0x1000  /* Interrupt vector table */
  kseg1_boot_mem             : ORIGIN = 0x9D011000, LENGTH = 0x1000 /* C Startup code */
  debug_exec_mem             : ORIGIN = 0xBFC02000, LENGTH = 0xFF0
  config3                    : ORIGIN = 0xBFC02FF0, LENGTH = 0x4
  config2                    : ORIGIN = 0xBFC02FF4, LENGTH = 0x4
  config1                    : ORIGIN = 0xBFC02FF8, LENGTH = 0x4
  config0                    : ORIGIN = 0xBFC02FFC, LENGTH = 0x4
  kseg1_data_mem       (w!x) : ORIGIN = 0xA0000000, LENGTH = 0x20000
  sfrs                       : ORIGIN = 0xBF800000, LENGTH = 0x100000
  configsfrs                 : ORIGIN = 0xBFC02FF0, LENGTH = 0x10
}

No comments:

Post a Comment