29typedef enum : uint16_t {
56typedef enum : uint32_t {
161 for (uint8_t attempt = 0U; attempt < (uint8_t)
k_rdh_enum_tries; attempt++) {
341 if (state == want_state) {
428 const uint16_t blocks = (uint16_t)(img_len / (uint32_t)
k_rdh_xfer_size);
429 for (uint16_t b = 0U; b < blocks; b++) {
488 const uint16_t blocks = (uint16_t)(img_len / (uint32_t)
k_rdh_xfer_size);
489 for (uint16_t b = 0U; b < blocks; b++) {
552 const uint16_t blocks = (uint16_t)(img_len / (uint32_t)
k_rdh_xfer_size);
554 for (uint16_t b = 0U; b < blocks; b++) {
646 if ((img ==
nullptr) || (out ==
nullptr)) {
653 if ((img_len == 0U) || ((img_len % (uint32_t)
k_rdh_xfer_size) != 0U)) {
732 if ((img ==
nullptr) || (out ==
nullptr)) {
739 if ((img_len == 0U) || ((img_len % (uint32_t)
k_rdh_xfer_size) != 0U)) {
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
static ra8_err_t internal_enum_hunt(ra8_usb_speed_t speed, uint8_t *desc)
Wait for device attach, apply bus reset, and read the DEVICE descriptor.
rdh_tune_t
Timing / retry tunables for the polled enumeration + status polling.
@ k_rdh_mismatch_none
"no mismatch" sentinel.
@ k_rdh_reset_hold_ms
USB bus-reset hold (>=10 ms).
@ k_rdh_attach_spin
Attach spin cap.
@ k_rdh_debounce_ms
Post-attach debounce.
@ k_rdh_vbus_settle_ms
VBUS settle before probing.
@ k_rdh_enum_tries
Reset+probe attempts.
@ k_rdh_status_poll_ms
Pause between GETSTATUS polls.
@ k_rdh_addr_settle_ms
Post-SET_ADDRESS recovery.
@ k_rdh_recovery_ms
Post-reset recovery (TRSTRCY).
@ k_rdh_status_tries
GETSTATUS polls before giving up.
@ k_rdh_attach_to_ms
Wait for the D+ pull-up.
static ra8_err_t internal_upload_verify(ra8_usb_speed_t speed, const uint8_t *img, uint32_t img_len, ra8_dfu_host_result_t *out)
DFU_UPLOAD each block and byte-compare against img.
static ra8_err_t internal_get_dev_desc(ra8_usb_speed_t speed, uint8_t *desc)
Issue GET_DESCRIPTOR(DEVICE) over the polled control engine.
static ra8_err_t internal_set_config(ra8_usb_speed_t speed)
Issue SET_CONFIGURATION(1) on the addressed device.
static ra8_err_t internal_run_seq(ra8_usb_speed_t speed, const uint8_t *img, uint32_t img_len, ra8_dfu_host_result_t *out)
Run the full self-test sequence: enumerate, download, abort, upload-verify.
static ra8_err_t internal_wait_state(ra8_usb_speed_t speed, uint8_t want_state)
Poll DFU_GETSTATUS until the device reaches want_state or the retry cap.
ra8_err_t ra8_dfu_host_run(ra8_usb_speed_t host_speed, const uint8_t *img, uint32_t img_len, ra8_dfu_host_result_t *out)
Enumerate, DFU_DNLOAD img, DFU_ABORT, DFU_UPLOAD, and byte-verify.
static ra8_err_t internal_download_all(ra8_usb_speed_t speed, const uint8_t *img, uint32_t img_len)
Download the entire image in 64-byte blocks, then DFU_ABORT to dfuIDLE.
static ra8_err_t internal_set_address(ra8_usb_speed_t speed)
Issue SET_ADDRESS(1) and retarget the DCP to the new address.
static ra8_err_t internal_program_seq(ra8_usb_speed_t speed, const uint8_t *img, uint32_t img_len, ra8_dfu_host_result_t *out)
Run the real-flash sequence: enumerate, download, then send manifest.
static ra8_err_t internal_download_manifest(ra8_usb_speed_t speed, const uint8_t *img, uint32_t img_len)
Download the entire image in 64-byte blocks, then send a zero-length manifest.
ra8_err_t ra8_dfu_host_program(ra8_usb_speed_t host_speed, const uint8_t *img, uint32_t img_len, ra8_dfu_host_result_t *out)
Enumerate, DFU_DNLOAD img, then a zero-length DFU_DNLOAD (manifest).
static ra8_err_t internal_getstatus(ra8_usb_speed_t speed, uint8_t *out_state)
Issue DFU_GETSTATUS and return the bState byte.
rdh_proto_t
Chapter-9 + DFU class request / descriptor constants.
@ k_rdh_byte_bits
Bits per byte.
@ k_rdh_dev_desc_len
DEVICE descriptor length.
@ k_rdh_off_status_state
bState offset.
@ k_rdh_config_val
bConfigurationValue.
@ k_rdh_desc_device
DEVICE descriptor type.
@ k_rdh_intf
DFU interface number.
@ k_rdh_breq_dnload
DFU_DNLOAD.
@ k_rdh_breq_set_addr
SET_ADDRESS.
@ k_rdh_breq_set_config
SET_CONFIGURATION.
@ k_rdh_bm_class_if_out
Class | Interface | Out.
@ k_rdh_dev_addr
Operating device address.
@ k_rdh_state_idle
dfuIDLE.
@ k_rdh_off_dev_pid
idProduct LSB offset.
@ k_rdh_bm_std_dev_out
Std | Device | Out.
@ k_rdh_bm_std_dev_in
Std | Device | In.
@ k_rdh_getstatus_len
DFU_GETSTATUS payload.
@ k_rdh_breq_abort
DFU_ABORT (-> dfuIDLE).
@ k_rdh_breq_get_desc
GET_DESCRIPTOR.
@ k_rdh_breq_upload
DFU_UPLOAD.
@ k_rdh_xfer_size
wTransferSize per block.
@ k_rdh_breq_getstatus
DFU_GETSTATUS.
@ k_rdh_state_dnload_idle
dfuDNLOAD-IDLE.
@ k_rdh_bm_class_if_in
Class | Interface | In.
static ra8_err_t internal_dnload_block(ra8_usb_speed_t speed, uint16_t block, uint8_t *data, uint16_t len)
Issue DFU_DNLOAD for one block, then poll to dfuDNLOAD-IDLE.
Polled on-board USB-DFU host driver, bound to either controller.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
SysTick-based tick counter, delay and timestamp helpers.
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
uint32_t ra8_time_ms(void)
Get the current 1 kHz tick count.
Native USB controller driver public API (device + host modes).
ra8_usb_speed_t
Selects which controller instance the call targets.
ra8_err_t ra8_usb_host_bus_reset(ra8_usb_speed_t speed, bool assert_reset)
Drive (or release) the bus reset line.
uint16_t ra8_usb_host_line_state(ra8_usb_speed_t speed)
Read the host port's D+/D- line state (SYSSTS0.LNST).
ra8_err_t ra8_usb_host_init(ra8_usb_speed_t speed)
Bring up a USB controller in HOST mode.
ra8_err_t ra8_usb_host_deinit(ra8_usb_speed_t speed)
Tear down a host-mode controller and drop its MSTP reference.
ra8_err_t ra8_usb_host_control_xfer(ra8_usb_speed_t speed, const ra8_usb_setup_t *setup, uint8_t *data, uint16_t data_len, uint16_t *out_received)
Run a complete host control transfer (SETUP, optional DATA, STATUS).
ra8_err_t ra8_usb_host_set_uact(ra8_usb_speed_t speed, bool enable)
Enable / disable SOF (Start-of-Frame) generation on the bus.
ra8_err_t ra8_usb_host_set_target(ra8_usb_speed_t speed, uint8_t dev_addr)
Retarget the host's default control pipe at a device address.
Outcome of a DFU round-trip for diagnostics / banners.
uint32_t blocks_ok
Upload blocks that byte-matched.
uint32_t mismatch
First differing block, or 0xFFFFFFFF.
uint32_t pid
Enumerated idProduct.
ra8_err_t last_err
First failing step's error, or k_ra8_ok.
Decoded 8-byte USB SETUP packet.