Use the spare PIC18 byte buffer

… visits
Parent Previous Next

On supported PIC18 devices, the tool can give your application a byte array in the verified unused space after the USB reservation. This is useful for a log fragment, a display staging buffer or file contents.

Turn it on

  1. Open Hardware.
  2. Enter the required Extra byte-buffer size. Use zero to leave it off.
  3. Check Summary. The tool checks that the array fits after the current USB reservation.
  4. Generate and compile the program again.

The library declares USB_ExtraRAM[] for you. It is ordinary application byte storage. It does not create another USB endpoint or send anything automatically.

Store and read bytes

' Requires Extra byte-buffer size of at least 2 in the tool.

' Do not declare USB_ExtraRAM again.

USB_ExtraRAM[0] = 100

USB_ExtraRAM[1] = 25

USB_EXTRA_RAM_BYTES is the configured size. Valid array indices go from 0 to that size minus 1. Use an index variable large enough for the size you chose.


The compile-time values USB_EXTRA_RAM_BASE and USB_EXTRA_RAM_AVAILABLE describe the starting address and maximum available space. Let the library place the array. Do not declare another At array at the same addresses.

Keep the safe allocation rules

This feature leaves the safe limit for automatically allocated variables unchanged. Do not turn parts of the Byte array into aliased Word/Dword variables across bank boundaries. For multi-byte values, store and rebuild individual bytes in a defined order, as in the HID data examples.


Changing the class, packet sizes or ping-pong setting can move the array's start and change how much space is available. Generate and compile again after any of those changes.

See also

Created with the Personal Edition of HelpNDoc: Free iPhone documentation generator