|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Host-side DFU ladder + console helpers for usb_selftest_dfu. More...
#include "usb_selftest_dfu_steps.h"#include <stdint.h>#include <string.h>#include "ra8_board_ek_ra8d2.h"#include "ra8_err.h"#include "ra8_time.h"#include "ra8_usb.h"Go to the source code of this file.
Functions | |
| static void | dfu_pattern_fill (uint32_t block, uint8_t *out, uint32_t len) |
| Fill a firmware block with this block's deterministic bytes. | |
| static uint8_t | dfu_nibble_to_hex (uint32_t nibble) |
| Format one nibble (0..15) into an uppercase hex character. | |
| static uint32_t | dfu_str_len (const char *text) |
| Bounded ASCII string length (cap k_dfu_print_cap). | |
| static ra8_err_t | dfu_sci_write (const uint8_t *data, uint32_t len) |
| Push a literal block over the J-Link OB CDC console (SCI8) polled. | |
| static ra8_err_t | dfu_print (const char *text) |
| Print a NUL-terminated ASCII string over the console. | |
| static ra8_err_t | dfu_print_hex (uint32_t value, uint8_t digits) |
| Print a value as fixed-width uppercase hex. | |
| static ra8_err_t | dfu_print_dec (uint32_t value) |
| Print a uint32_t as ASCII decimal. | |
| static ra8_err_t | dfu_print_fail (const char *what, ra8_err_t err) |
| Print "FAIL <what> err=0xNNNNNNNN" on its own line. | |
| static ra8_err_t | dfu_ctrl_get_dev_desc (uint8_t *desc) |
| GET_DESCRIPTOR(DEVICE) over the polled control engine. | |
| static ra8_err_t | dfu_enum_hunt (uint8_t *desc) |
| Wait for attach, then bus-reset + read the device descriptor. | |
| static ra8_err_t | dfu_enum_set_address (void) |
| SET_ADDRESS to k_dfu_dev_addr, then retarget the DCP. | |
| static ra8_err_t | dfu_enum_set_config (void) |
| SET_CONFIGURATION(::k_dfu_config_val) on the addressed device. | |
| static ra8_err_t | dfu_getstatus (uint8_t *out_state) |
| DFU_GETSTATUS: read the 6-byte status and return the bState field. | |
| static ra8_err_t | dfu_wait_state (uint8_t want_state) |
Poll DFU_GETSTATUS until the device reports want_state. | |
| static ra8_err_t | dfu_dnload_block (uint16_t block, uint8_t *data, uint16_t len) |
| DFU_DNLOAD one block, then poll to dfuDNLOAD-IDLE. | |
| static ra8_err_t | dfu_download_all (void) |
| Download the whole rehearsal image, then DFU_ABORT back to dfuIDLE. | |
| static ra8_err_t | dfu_upload_verify (void) |
| DFU_UPLOAD the image back block by block and byte-check each. | |
| static ra8_err_t | dfu_host_enumerate (void) |
| Enumerate the looped-back device: descriptor hunt, address, config. | |
| ra8_err_t | dfu_host_pass (void) |
| Run the full host pass: enumerate, download, upload-verify. | |
Variables | |
| static volatile uint32_t | s_dbg_phase |
| Host-ladder phase marker (dfu_phase_t). | |
| static volatile uint32_t | s_dbg_pid |
| Device-reported product id captured at enumeration. | |
| static volatile uint32_t | s_dbg_blocks_ok |
| Blocks the host confirmed byte-equal on upload (expect k_dfu_blocks). | |
| static volatile uint32_t | s_dbg_mismatch = (uint32_t)k_dfu_no_mismatch |
| First mismatching block, or k_dfu_no_mismatch. | |
| static volatile uint32_t | s_dbg_pass_count |
| Completed full passes (sticky success counter). | |
Host-side DFU ladder + console helpers for usb_selftest_dfu.
Holds the polled USB-HS host ladder (enumerate -> DFU_DNLOAD -> DFU_UPLOAD verify) together with the SCI8 console text-formatter helpers and the shared per-block firmware pattern, split out of main.c so each translation unit stays under the file-size cap. main.c drives the device-side DFU class, the board bring-up, and the ThreadX worker threads; it calls into here only through dfu_host_pass.
The J-Link probes that mark host-ladder progress (s_dbg_phase and friends) live here because only the host ladder reads or writes them; the device-side probes stay in main.c.
Definition in file usb_selftest_dfu_steps.c.
|
staticnodiscard |
GET_DESCRIPTOR(DEVICE) over the polled control engine.
| [out] | desc | Receives the 18-byte device descriptor. |
| k_ra8_ok | All 18 bytes arrived. |
| k_ra8_err_hw_error | A short descriptor came back. |
desc holds at least k_dfu_dev_desc_len bytes. desc carries the device descriptor on success. Definition at line 279 of file usb_selftest_dfu_steps.c.
References k_dfu_bm_std_dev_in, k_dfu_breq_get_desc, k_dfu_byte_bits, k_dfu_desc_device, k_dfu_dev_desc_len, k_ra8_err_hw_error, k_ra8_ok, k_ra8_usb_speed_hs, and ra8_usb_host_control_xfer().
Referenced by dfu_enum_hunt().
|
staticnodiscard |
DFU_DNLOAD one block, then poll to dfuDNLOAD-IDLE.
| [in] | block | The DFU block sequence number (wValue). |
| [in] | data | Block payload (control-OUT data stage). |
| [in] | len | Block length in bytes. |
| k_ra8_ok | The block was downloaded and the device is DNLOAD-IDLE. |
data holds len bytes. Definition at line 472 of file usb_selftest_dfu_steps.c.
References dfu_wait_state(), k_dfu_bm_class_if_out, k_dfu_breq_dnload, k_dfu_intf, k_dfu_state_dnload_idle, k_ra8_ok, k_ra8_usb_speed_hs, and ra8_usb_host_control_xfer().
Referenced by dfu_download_all().
|
staticnodiscard |
Download the whole rehearsal image, then DFU_ABORT back to dfuIDLE.
| k_ra8_ok | All blocks downloaded; the device is back in dfuIDLE. |
Definition at line 505 of file usb_selftest_dfu_steps.c.
References dfu_dnload_block(), dfu_pattern_fill(), dfu_wait_state(), k_dfu_blocks, k_dfu_bm_class_if_out, k_dfu_breq_abort, k_dfu_intf, k_dfu_state_idle, k_dfu_xfer_size, k_ra8_ok, k_ra8_usb_speed_hs, and ra8_usb_host_control_xfer().
Referenced by dfu_host_pass().
|
staticnodiscard |
Wait for attach, then bus-reset + read the device descriptor.
| [out] | desc | Receives the winning 18-byte device descriptor. |
| k_ra8_ok | The device answered at address 0. |
| k_ra8_err_hw_timeout | Nothing attached / nothing answered. |
Definition at line 310 of file usb_selftest_dfu_steps.c.
References dfu_ctrl_get_dev_desc(), k_dfu_attach_spin, k_dfu_attach_to_ms, k_dfu_debounce_ms, k_dfu_enum_tries, k_dfu_recovery_ms, k_dfu_reset_hold_ms, k_dfu_vbus_settle_ms, k_ra8_err_hw_timeout, k_ra8_ok, k_ra8_usb_speed_hs, ra8_delay_ms(), ra8_time_ms(), ra8_usb_host_bus_reset(), ra8_usb_host_line_state(), ra8_usb_host_set_target(), and ra8_usb_host_set_uact().
Referenced by dfu_host_enumerate().
|
staticnodiscard |
SET_ADDRESS to k_dfu_dev_addr, then retarget the DCP.
| k_ra8_ok | The DCP now targets the operating address. |
Definition at line 350 of file usb_selftest_dfu_steps.c.
References k_dfu_addr_settle_ms, k_dfu_bm_std_dev_out, k_dfu_breq_set_addr, k_dfu_dev_addr, k_ra8_ok, k_ra8_usb_speed_hs, ra8_delay_ms(), ra8_usb_host_control_xfer(), and ra8_usb_host_set_target().
Referenced by dfu_host_enumerate().
|
staticnodiscard |
SET_CONFIGURATION(::k_dfu_config_val) on the addressed device.
| k_ra8_ok | The device entered the Configured state (dfuIDLE). |
Definition at line 378 of file usb_selftest_dfu_steps.c.
References k_dfu_bm_std_dev_out, k_dfu_breq_set_config, k_dfu_config_val, k_ra8_usb_speed_hs, and ra8_usb_host_control_xfer().
Referenced by dfu_host_enumerate().
|
staticnodiscard |
DFU_GETSTATUS: read the 6-byte status and return the bState field.
| [out] | out_state | Receives the DFU state machine byte. |
| k_ra8_ok | Status read; out_state valid. |
| k_ra8_err_hw_error | A short status payload came back. |
out_state is non-NULL. out_state holds bState on success. Definition at line 403 of file usb_selftest_dfu_steps.c.
References k_dfu_bm_class_if_in, k_dfu_breq_getstatus, k_dfu_getstatus_len, k_dfu_intf, k_dfu_off_status_state, k_ra8_err_hw_error, k_ra8_ok, k_ra8_usb_speed_hs, and ra8_usb_host_control_xfer().
Referenced by dfu_wait_state().
|
staticnodiscard |
Enumerate the looped-back device: descriptor hunt, address, config.
Runs the k_dfu_phase_enum portion of the host pass – fetch the device descriptor, latch the product id into s_dbg_pid, assign the bus address, select configuration 1, and print the enumerated pid. Any failing step deinitializes the host controller so the caller can retry cleanly.
| k_ra8_ok | Device enumerated and the pid line printed. |
| k_ra8_err_invalid_state | Propagated descriptor / control-transfer error. |
Definition at line 595 of file usb_selftest_dfu_steps.c.
References dfu_enum_hunt(), dfu_enum_set_address(), dfu_enum_set_config(), dfu_print(), dfu_print_fail(), dfu_print_hex(), k_dfu_byte_bits, k_dfu_dev_desc_len, k_dfu_hex_chars_u16, k_dfu_off_dev_pid, k_dfu_phase_enum, k_ra8_ok, k_ra8_usb_speed_hs, ra8_usb_host_deinit(), s_dbg_phase, and s_dbg_pid.
Referenced by dfu_host_pass().
|
nodiscard |
Run the full host pass: enumerate, download, upload-verify.
| k_ra8_ok | The pass printed DFU PASS. |
Definition at line 629 of file usb_selftest_dfu_steps.c.
References dfu_download_all(), dfu_host_enumerate(), dfu_print(), dfu_print_dec(), dfu_print_fail(), dfu_upload_verify(), k_dfu_blocks, k_dfu_phase_download, k_dfu_phase_init, k_dfu_phase_pass, k_dfu_phase_upload, k_ra8_board_led2, k_ra8_ok, k_ra8_usb_speed_hs, ra8_board_led_on(), ra8_usb_host_deinit(), ra8_usb_host_init(), s_dbg_pass_count, and s_dbg_phase.
|
static |
Format one nibble (0..15) into an uppercase hex character.
| [in] | nibble | 4-bit value. |
| '0' | For a zero nibble. |
Definition at line 98 of file usb_selftest_dfu_steps.c.
References k_dfu_hex_digit_split.
Referenced by dfu_print_hex().
|
static |
Fill a firmware block with this block's deterministic bytes.
Byte i = (block*131 + i*7 + 0xA5) & 0xFF – distinct per block so the upload check proves the bytes read back are the ones downloaded.
| [in] | block | The block index (0..k_dfu_blocks-1). |
| [out] | out | Destination buffer. |
| [in] | len | Bytes to fill. |
out has len writable bytes; len <= k_dfu_xfer_size. block < k_dfu_blocks. out[0..len-1] hold the block's pattern bytes. Definition at line 73 of file usb_selftest_dfu_steps.c.
References k_dfu_byte_mask, k_dfu_pat_bias, k_dfu_pat_blk_mul, and k_dfu_pat_idx_mul.
Referenced by dfu_download_all(), and dfu_upload_verify().
|
staticnodiscard |
Print a NUL-terminated ASCII string over the console.
| [in] | text | String to print (CR/LF included by the caller). |
| k_ra8_ok | All bytes queued. |
text is non-NULL. text is NUL-terminated within k_dfu_print_cap bytes. Definition at line 160 of file usb_selftest_dfu_steps.c.
References dfu_sci_write(), and dfu_str_len().
Referenced by dfu_host_enumerate(), dfu_host_pass(), and dfu_print_fail().
|
staticnodiscard |
Print a uint32_t as ASCII decimal.
| [in] | value | Value to print. |
| k_ra8_ok | All bytes queued. |
Definition at line 204 of file usb_selftest_dfu_steps.c.
References dfu_sci_write(), k_dfu_dec_chars_u32, and k_dfu_dec_radix.
Referenced by dfu_host_pass().
Print "FAIL <what> err=0xNNNNNNNN" on its own line.
| [in] | what | Short description of the failed step. |
| [in] | err | Error code returned by the step. |
| k_ra8_ok | The diagnostic line is queued. |
what is NUL-terminated within the cap. Definition at line 241 of file usb_selftest_dfu_steps.c.
References dfu_print(), dfu_print_hex(), k_dfu_hex_chars_u32, and k_ra8_ok.
Referenced by dfu_host_enumerate(), and dfu_host_pass().
|
staticnodiscard |
Print a value as fixed-width uppercase hex.
| [in] | value | Value to print. |
| [in] | digits | Hex digit count (4 for u16, 8 for u32). |
| k_ra8_ok | All bytes queued. |
digits is at most k_dfu_hex_chars_u32. Definition at line 178 of file usb_selftest_dfu_steps.c.
References dfu_nibble_to_hex(), dfu_sci_write(), k_dfu_hex_chars_u32, k_dfu_nibble_bits, and k_dfu_nibble_mask.
Referenced by dfu_host_enumerate(), and dfu_print_fail().
|
staticnodiscard |
Push a literal block over the J-Link OB CDC console (SCI8) polled.
| [in] | data | Buffer to send. |
| [in] | len | Byte count. |
| k_ra8_ok | All bytes queued. |
data is non-NULL; the board console init already ran. len excludes any NUL terminator. Definition at line 143 of file usb_selftest_dfu_steps.c.
References ra8_board_uart_console_write().
Referenced by dfu_print(), dfu_print_dec(), and dfu_print_hex().
|
static |
Bounded ASCII string length (cap k_dfu_print_cap).
| [in] | text | NUL-terminated string. |
| 0 | For an empty string. |
text is non-NULL with readable storage. text fits the cap. Definition at line 118 of file usb_selftest_dfu_steps.c.
References k_dfu_print_cap.
Referenced by dfu_print().
|
staticnodiscard |
DFU_UPLOAD the image back block by block and byte-check each.
| k_ra8_ok | All blocks matched their downloaded pattern. |
| k_ra8_err_invalid_size | A block returned the wrong length. |
| k_ra8_err_invalid_state | A block's bytes differed. |
Definition at line 545 of file usb_selftest_dfu_steps.c.
References dfu_pattern_fill(), k_dfu_blocks, k_dfu_bm_class_if_in, k_dfu_breq_upload, k_dfu_intf, k_dfu_xfer_size, k_ra8_err_invalid_size, k_ra8_err_invalid_state, k_ra8_ok, k_ra8_usb_speed_hs, memcmp(), ra8_usb_host_control_xfer(), s_dbg_blocks_ok, and s_dbg_mismatch.
Referenced by dfu_host_pass().
|
staticnodiscard |
Poll DFU_GETSTATUS until the device reports want_state.
| [in] | want_state | The DFU bState the caller is waiting for. |
| k_ra8_ok | The device reached want_state. |
| k_ra8_err_hw_timeout | It did not within k_dfu_status_tries. |
want_state. Definition at line 442 of file usb_selftest_dfu_steps.c.
References dfu_getstatus(), k_dfu_status_poll_ms, k_dfu_status_tries, k_ra8_err_hw_timeout, k_ra8_ok, and ra8_delay_ms().
Referenced by dfu_dnload_block(), and dfu_download_all().
|
static |
Blocks the host confirmed byte-equal on upload (expect k_dfu_blocks).
Definition at line 48 of file usb_selftest_dfu_steps.c.
|
static |
First mismatching block, or k_dfu_no_mismatch.
Definition at line 50 of file usb_selftest_dfu_steps.c.
|
static |
Completed full passes (sticky success counter).
Definition at line 52 of file usb_selftest_dfu_steps.c.
|
static |
Host-ladder phase marker (dfu_phase_t).
Definition at line 44 of file usb_selftest_dfu_steps.c.
|
static |
Device-reported product id captured at enumeration.
Definition at line 46 of file usb_selftest_dfu_steps.c.