Plan memory and packet sizes

USB Library ›› Device ››
… visits
Parent Previous Next

Start with the smallest configuration that does your job. Check Summary in the tool, then compile and check the compiler's RAM and program-memory reports. The tool's estimate helps you plan; the finished program decides whether everything fits.

A packet is not your whole message

The library's full-speed bulk and interrupt endpoints carry at most 64 bytes per packet. A file, text message or set of readings can be much larger.

Data you want to exchange

How it crosses USB

A HID report

One report with the exact size advertised by its descriptor

A long CDC message

A sequence of USB packets; your application reconstructs the byte stream

A large MSC file

Storage commands broken into small file-content requests

A browser page or JSON response

Network packets and USB transfers assembled by the network service

For a long HID message, split it into reports. Add a message type, sequence number and length if your application needs them. Use the same layout in the PIC and PC programs. For CDC, mark message boundaries with a delimiter, a length field or another clear rule. USB does not know where your command ends.


A larger file setting does not create a RAM array of that size. If your own code stores the file in an array, that array needs extra RAM.

Read Summary without counting RAM twice

Summary output listing PIC18F14K50 RAM regions, USB reservation, stack estimate, and report arrays.

Read Summary before compiling. Its RAM figures help you plan, but the compiler must also fit your variables, temporary storage and interrupt context.

Summary item

What it tells you

Total physical RAM

Implemented RAM in the selected device; it may contain regions with different addressing rules.

USB storage reserved / backing storage

Hardware descriptors and packet buffers used by this configuration.

USB storage limit

The permitted region or budget for those buffers, not an automatic allocation of the entire number.

Automatic/shared variable budget

The region used by the compiler and stack for ordinary variables; application variables and compiler working storage also need space.

Additional fixed-address RAM

A verified unused tail on supported PIC18 devices that can be exposed as an optional Byte array.

Stack storage estimate

A planning estimate for the selected features, not a statement that all remaining bytes are free for application code.

Also allow space for strings, arrays, procedure parameters, temporary variables and interrupt context. These can make a program fail to fit even when the tool's estimate looked close enough.

If memory is short: reduce buffers or features, simplify the application, or choose a PIC with enough suitable memory. Increasing a limit in the tool does not create more RAM.

Which choices use more memory?

Choice

Main memory effect

Larger TX/RX buffers

Larger application arrays and hardware packet buffers

Ping-pong

Additional alternating hardware data buffers

HID feature report

Feature data and related control-transfer storage

More MSC files

More file metadata/state; file contents only consume RAM if your handler stores them there

More published browser values

Live values plus response snapshots and formatting state

More browser input slots

More independent pending-command values and sequence information

Firmware HTML pages

Program-memory use; the library reads page data in pieces rather than allocating each entire page in RAM

External HTML page

Page layout stays on the PC; the PIC retains the network/data service

Ping-pong buffering can help keep transfers queued on targets that support it. It still uses packets of at most 64 bytes, and it does not promise a particular speed increase. Measure your application before spending RAM on it.


A firmware page may be within the per-page size limit and still be too large for the PIC. All page tables, descriptors, USB code and your application share program memory. Eight pages at the maximum allowed size will not necessarily fit. Check the final compiler report.

Check the notes for your PIC family

Choose the matching memory page below. The memory layout is different on PIC18, PIC16 and Positron16 targets.

See also

Created with the Personal Edition of HelpNDoc: Create Professional CHM Help Files with HelpNDoc's Easy-to-Use Tool