|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
USBX DFU device class wired to real MRAM, bound to either controller. More...
Go to the source code of this file.
Functions | |
| void | ra8_dfu_device_set_target (ra8_dfu_slot_t target_slot) |
| Select the slot DFU_DNLOAD programs into / DFU_UPLOAD reads from. | |
| ra8_err_t | ra8_dfu_device_start (ra8_usb_speed_t speed, void *usbx_pool, uint32_t pool_bytes, unsigned char *framework, uint32_t framework_len, unsigned char *strings, uint32_t strings_len, unsigned char *langids, uint32_t langids_len) |
| Bring up USBX + the DFU class on one controller and raise D+. | |
| ra8_err_t | ra8_dfu_device_worker_step (void) |
| Program any pending DNLOAD block into MRAM; commit on end-of-download. | |
| uint32_t | ra8_dfu_device_image_len (void) |
| Total image bytes accepted so far (diagnostic). | |
| uint32_t | ra8_dfu_device_block_writes (void) |
| Count of DNLOAD blocks programmed into MRAM (diagnostic). | |
| bool | ra8_dfu_device_manifested (void) |
| Whether the host has signalled end-of-download / manifest. | |
| ra8_err_t | ra8_dfu_device_last_error (void) |
| Latched last program error (diagnostic). | |
| bool | ra8_dfu_device_committed (void) |
| Whether the image header has been committed (slot now bootable). | |
USBX DFU device class wired to real MRAM, bound to either controller.
Front-half of the controller-agnostic DFU device. Registers the vendored USBX DFU class and points its write/read/get_status/notify callbacks at the ra8_dfu_program MRAM path so a DFU_DNLOAD actually programs the inactive application slot and a DFU_UPLOAD reads it back. Which USB controller it runs on is purely the ra8_usb_speed_t passed to ra8_dfu_device_start (threaded through the ux_dcd_ra8_usb bridge) – the same core drives the FS device in Config A and the HS device in Config B.
The slow MRAM erase/program runs in the caller's device-worker thread via ra8_dfu_device_worker_step (the code-MRAM program loop must not run in an ISR or from MRAM); dfu_write only stages a block and the host's DFU_GETSTATUS sees dfuDNBUSY until the worker catches up.
Definition in file ra8_dfu_device.h.
| uint32_t ra8_dfu_device_block_writes | ( | void | ) |
Count of DNLOAD blocks programmed into MRAM (diagnostic).
Returns the value of the internal writes field, which is incremented once per successfully programmed DNLOAD block inside ::internal_dfu_write. A block is only counted if the MRAM program call returned k_ra8_ok; blocks that fault increment prog_err instead. Intended for J-Link live-watch or host diagnostics.
| 0 | No blocks have been successfully programmed yet. |
| bool ra8_dfu_device_committed | ( | void | ) |
Whether the image header has been committed (slot now bootable).
Returns the internal committed flag, which is set to true by ra8_dfu_device_worker_step immediately after ra8_dfu_program_commit succeeds (or even on failure, to prevent repeated commit attempts). Goes true after ra8_dfu_device_worker_step writes the header on end-of-download. A bootloader polls this to know when it is safe to reset into the freshly programmed slot.
| true | The slot header has been committed; the slot is now bootable (assuming no program error was latched). |
| false | The commit has not yet run; download may still be in flight. |
Referenced by blc_device_worker(), and dfu_host_pass().
| uint32_t ra8_dfu_device_image_len | ( | void | ) |
Total image bytes accepted so far (diagnostic).
Returns the value of the internal img_len field, which tracks the highest byte offset written: (block_number * wTransferSize) + padded block length. Updated by ra8_dfu_device_worker_step on each successful DNLOAD block. Intended for J-Link live-watch or host diagnostics; not needed for correct DFU operation.
| 0 | No blocks have been successfully programmed yet. |
| ra8_err_t ra8_dfu_device_last_error | ( | void | ) |
Latched last program error (diagnostic).
Returns the value of s_dev.prog_err, which is latched to the first non-k_ra8_ok result from any ra8_dfu_program_image or ra8_dfu_program_commit call. Once set to a non-OK code it is never cleared within the session. ::internal_dfu_get_status and ::internal_dfu_write both read this field to decide which USBX media-status code to report to the host.
| k_ra8_ok | No program fault has occurred in this session. |
| k_ra8_err_* | The error from the first failing ::ra8_dfu_program_* call; subsequent errors do not overwrite this value. |
Referenced by blc_device_worker(), and dfu_host_pass().
| bool ra8_dfu_device_manifested | ( | void | ) |
Whether the host has signalled end-of-download / manifest.
Returns the internal manifest flag, which is set to true by ::internal_dfu_write when a zero-length DNLOAD block (end-of-download) is received, or by ::internal_dfu_notify on a UX_SLAVE_CLASS_DFU_NOTIFICATION_END_DOWNLOAD event. Once set it is never cleared within a session. ra8_dfu_device_worker_step polls this flag to decide when to commit the image header.
| true | End-of-download has been signalled; header commit is pending or already done. |
| false | No end-of-download has arrived yet; download still in flight. |
| void ra8_dfu_device_set_target | ( | ra8_dfu_slot_t | target_slot | ) |
Select the slot DFU_DNLOAD programs into / DFU_UPLOAD reads from.
Records the INACTIVE slot all subsequent DFU transfers act on; an out-of-range value is ignored so the default (Slot B) stands. Set once during init, before ra8_dfu_device_start.
| [in] | target_slot | Slot A or B (must NOT be the slot the caller runs from). |
Referenced by dfu_device_worker(), and main().
|
nodiscard |
Bring up USBX + the DFU class on one controller and raise D+.
Initialises the USBX system + device stack with the caller's descriptor framework, registers the DFU class with the MRAM-backed callbacks, runs ux_dcd_ra8_usb_initialize for speed, and attaches the D+ pull-up. The device enumerates directly into dfuIDLE (DFU-mode interface).
| [in] | speed | Which USB controller (FS or HS). |
| [in] | usbx_pool | Static byte pool for USBX (non-NULL). |
| [in] | pool_bytes | Size of usbx_pool. |
| [in] | framework | USB descriptor framework (device + config + DFU). |
| [in] | framework_len | Length of framework. |
| [in] | strings | String-descriptor framework. |
| [in] | strings_len | Length of strings. |
| [in] | langids | LANGID framework. |
| [in] | langids_len | Length of langids. |
| k_ra8_ok | Device stack up, class registered, D+ raised. |
| k_ra8_err_null_ptr | A required pointer was NULL. |
| k_ra8_err_invalid_state | USBX init / class register failed. |
| k_ra8_err_hw_error | DCD init or attach failed. |
Referenced by blc_device_worker(), and dfu_device_worker().
| ra8_err_t ra8_dfu_device_worker_step | ( | void | ) |
Program any pending DNLOAD block into MRAM; commit on end-of-download.
Call repeatedly from the device-worker thread. On the first block it prepares the target slot (ra8_dfu_program_prepare). Each staged block is programmed via ra8_dfu_program_image. When the host signals end-of-download (zero-length DNLOAD / manifest) the slot header is committed (ra8_dfu_program_commit) so the slot becomes bootable. Slow + SRAM-resident, which is why it lives in thread context and not the DFU callback.
| k_ra8_ok | Idle, or the pending block programmed cleanly. |
| k_ra8_err_* | The failing ::ra8_dfu_program_* code (latched). |
Referenced by blc_device_worker(), and dfu_device_worker().