|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
ThreadX + USBX Mass-Storage RAM-disk for EK-RA8D2 (USB-FS). More...
#include <stdint.h>#include <string.h>#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_gpio_constants.h"#include "ra8_isr.h"#include "ra8_port_constants.h"#include "ra8_port_utils.h"#include "ra8_time.h"#include "ra8_usb.h"#include "tx_api.h"#include "ux_api.h"#include "ux_dcd_ra8_usb.h"#include "ux_device_class_storage.h"#include "ux_device_stack.h"Go to the source code of this file.
Enumerations | |
| enum | scsi_sense_code_t : uint8_t { k_scsi_sense_illegal_request = 0x05U , k_scsi_asc_lba_out_of_range = 0x21U , k_scsi_ascq_none = 0x00U } |
| SCSI sense triple for an unsupported / out-of-range request. More... | |
| enum | demo_config_t : uint32_t { k_demo_thread_stack = 4096U , k_demo_usbx_pool_bytes = 32768U , k_demo_block_size = 512U , k_demo_block_count = 1024U , k_demo_idle_ticks = 50U } |
| Compile-time settings for the worker thread + USBX pool + RAM-disk geometry. More... | |
| enum | usb_langid_byte_t : uint8_t { k_usb_langid_en_us_lo = 0x09U , k_usb_langid_en_us_hi = 0x04U } |
Functions | |
| void | _tx_timer_interrupt (void) |
| void | SysTick_Handler (void) |
| Service the SysTick exception selected by the linked application. | |
| static UINT | demo_msc_read (VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status) |
| Storage media-read callback. | |
| static UINT | demo_msc_write (VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status) |
| Storage media-write callback. | |
| static UINT | demo_msc_status (VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status) |
| Storage media-status callback. | |
| static UINT | demo_usbx_stack_up (void) |
| Brings USBX system + FS device stack up. | |
| static UINT | demo_msc_class_register (void) |
| Registers the Mass-Storage class with one LUN backed by s_ramdisk. | |
| static VOID | demo_worker (ULONG arg) |
| VOID | tx_application_define (VOID *first_unused_memory) |
| ThreadX application-define hook. | |
| static void | demo_panic_halt (void) |
| Halt forever in WFI – panic stop on init failure. | |
| static ra8_err_t | demo_pins_init (void) |
| Route the four USB-FS pins to the USBFS controller. | |
| void | main (void) |
| Application entry. | |
Variables | |
| static const ra8_port_pin_t | k_demo_pin_vbus = (ra8_port_pin_t)k_ra8_board_usbfs_pin_vbus |
| USB-FS pin identifiers, packed ra8_port_pin_t (port << 8 | pin). | |
| static const ra8_port_pin_t | k_demo_pin_vbusen = (ra8_port_pin_t)k_ra8_board_usbfs_pin_vbusen |
| static const ra8_port_pin_t | k_demo_pin_dp = (ra8_port_pin_t)k_ra8_board_usbfs_pin_dp |
| static const ra8_port_pin_t | k_demo_pin_dm = (ra8_port_pin_t)k_ra8_board_usbfs_pin_dm |
| static TX_THREAD | s_demo_thread |
| ThreadX TCB for the USBX worker thread. | |
| static UCHAR | s_demo_stack [k_demo_thread_stack] |
| Stack backing storage for s_demo_thread. | |
| static UCHAR | s_usbx_pool [k_demo_usbx_pool_bytes] |
| USBX memory pool (USBX uses tx_byte_pool internally). | |
| static UCHAR | s_ramdisk [k_demo_block_count *k_demo_block_size] |
| RAM-disk backing store (4 KiB = 8 x 512-byte sectors). | |
| static UCHAR | s_msc_vendor_id [] = "RA8D2 " |
| static UCHAR | s_msc_product_id [] = "USBX RAM Disk " |
| static UCHAR | s_msc_product_rev [] = "0001" |
| static UCHAR | s_device_framework_fs [] |
| static UCHAR | s_string_framework [] |
| USBX string descriptor table (vendor / product / serial). | |
| static UCHAR | s_language_id_framework [] = {k_usb_langid_en_us_lo, k_usb_langid_en_us_hi} |
| USBX language-id table – US English. | |
ThreadX + USBX Mass-Storage RAM-disk for EK-RA8D2 (USB-FS).
Brings the chip up via ra8_cgc_init() (XTAL -> PLL1 -> CPUCLK0 = 1 GHz, PCLKA = 125 MHz), routes the four USB-FS pins per the EK-RA8D2 v1 User's Manual to the on-board USB-FS receptacle, hands control to ThreadX, and brings the Mass-Storage device class up via Eclipse USBX (_ux_device_class_storage_initialize). The class sits on top of the project's port/usbx/ux_dcd_ra8_usb bridge to the hand-written ra8_usb register-level driver (HUM Ch. 36 USBFS, sec. 36.2.x for SYSCFG / DCPCFG / DCPMAXP / PIPECFG / CFIFO). The host actually enumerates the device because USBX's chapter-9 + SCSI/BBB state machines answer SETUP and BOT packets through the DCD bridge.
The single LUN is backed by an 8-sector x 512-byte (4 KiB) RAM buffer in DTCM/SRAM. There is no filesystem on it – the goal is proof-of-enumeration only. The host sees an unformatted removable drive of 4 KiB; macOS will offer to initialize the disk, which is the expected behaviour for this demo.
P4_07 = VBUS, P5_00 = VBUSEN, P8_14 = D+, P8_15 = D-, all PSEL = k_ra8_psel_usb_fs.
After flashing, the EK-RA8D2's USB-FS receptacle (J11) enumerates as a USB Mass-Storage device. system_profiler SPUSBDataType lists it under "USB Bus" with class Mass Storage; Disk Utility shows an unformatted 4 KiB volume.
Definition in file main.c.
| enum demo_config_t : uint32_t |
Compile-time settings for the worker thread + USBX pool + RAM-disk geometry.
| enum scsi_sense_code_t : uint8_t |
| enum usb_langid_byte_t : uint8_t |
|
extern |
|
static |
Registers the Mass-Storage class with one LUN backed by s_ramdisk.
| UX_SUCCESS | Class registered. |
Definition at line 509 of file main.c.
References demo_msc_read(), demo_msc_status(), demo_msc_write(), k_demo_block_count, k_demo_block_size, memset(), s_msc_product_id, s_msc_product_rev, and s_msc_vendor_id.
Referenced by demo_worker().
|
static |
Storage media-read callback.
Splats from RAM-disk into USBX.
| [in,out] | storage | USBX storage class instance (unused). |
| [in] | lun | Logical unit number (must be 0). |
| [out] | data_pointer | USBX-owned destination buffer. |
| [in] | number_blocks | Number of 512-byte blocks to copy. |
| [in] | lba | Starting LBA. |
| [out] | media_status | Filled with sense status word. |
| UX_SUCCESS | Read completed. |
| UX_ERROR | Out-of-range LBA / count. |
Definition at line 361 of file main.c.
References k_demo_block_count, k_demo_block_size, k_ra8_board_led1, k_scsi_asc_lba_out_of_range, k_scsi_ascq_none, k_scsi_sense_illegal_request, memcpy(), ra8_board_led_toggle(), and s_ramdisk.
Referenced by demo_msc_class_register().
Storage media-status callback.
Always reports media-present.
| [in,out] | storage | USBX storage class instance (unused). |
| [in] | lun | Logical unit number (unused). |
| [in] | media_id | Media id (unused). |
| [out] | media_status | Filled with 0 (no fault). |
| UX_SUCCESS | Media is present and ready. |
Definition at line 452 of file main.c.
Referenced by demo_msc_class_register().
|
static |
Storage media-write callback.
Splats from USBX into RAM-disk.
| [in,out] | storage | USBX storage class instance (unused). |
| [in] | lun | Logical unit number (must be 0). |
| [in] | data_pointer | USBX-owned source buffer. |
| [in] | number_blocks | Number of 512-byte blocks to copy. |
| [in] | lba | Starting LBA. |
| [out] | media_status | Filled with sense status word. |
| UX_SUCCESS | Write completed. |
| UX_ERROR | Out-of-range LBA / count. |
Definition at line 411 of file main.c.
References k_demo_block_count, k_demo_block_size, k_ra8_board_led1, k_scsi_asc_lba_out_of_range, k_scsi_ascq_none, k_scsi_sense_illegal_request, memcpy(), ra8_board_led_toggle(), and s_ramdisk.
Referenced by demo_msc_class_register().
|
static |
|
staticnodiscard |
Route the four USB-FS pins to the USBFS controller.
| k_ra8_ok | All four pins routed. |
Definition at line 633 of file main.c.
References k_demo_pin_dm, k_demo_pin_dp, k_demo_pin_vbus, k_demo_pin_vbusen, k_ra8_level_low, k_ra8_ok, k_ra8_psel_usb_fs, ra8_gpio_output_init(), and ra8_pfs_route_peripheral().
|
static |
Brings USBX system + FS device stack up.
| UX_SUCCESS | Stack ready. |
Definition at line 479 of file main.c.
References k_demo_usbx_pool_bytes, s_device_framework_fs, s_language_id_framework, s_string_framework, and s_usbx_pool.
|
static |
Definition at line 544 of file main.c.
References demo_msc_class_register(), demo_usbx_stack_up(), k_demo_idle_ticks, k_ra8_ok, k_ra8_usb_speed_fs, ra8_usb_device_attach(), tx_thread_sleep, and ux_dcd_ra8_usb_initialize().
| void main | ( | void | ) |
Application entry.
The application entry point Reset_Handler hands control to.
Brings up CGC + USB-FS pins + LED1 + ThreadX.
Definition at line 663 of file main.c.
References demo_panic_halt(), demo_pins_init(), k_ra8_board_led1, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_led_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_cgc_usbfs_clock_enable(), ra8_isr_globals_enable(), and ra8_time_init().
| void SysTick_Handler | ( | void | ) |
Service the SysTick exception selected by the linked application.
Service one SysTick event for the core timebase.
Service one SysTick event for the core timebase.
Resolves to the weak core timebase handler unless a strong RTOS or application handler overrides it. The vector table references the selected implementation without owning its subsystem policy.
The weak firmware implementation advances the millisecond counter, then services linked ThreadX and USB hooks when their weak symbols and readiness state permit. The host-test implementation advances only the counter. An application may replace either weak definition with a strong handler.
Service the SysTick exception selected by the linked application.
The weak firmware implementation advances the millisecond counter, then services linked ThreadX and USB hooks when their weak symbols and readiness state permit. The host-test implementation advances only the counter. An application may replace either weak definition with a strong handler.
Service the SysTick exception selected by the linked application.
Definition at line 77 of file main.c.
References _tx_timer_interrupt(), ra8_time_on_tick(), and ux_dcd_ra8_usb_irq_reenable().
| VOID tx_application_define | ( | VOID * | first_unused_memory | ) |
ThreadX application-define hook.
Spawns the demo worker.
| [in] | first_unused_memory | Sentinel (unused; static stacks). |
Definition at line 582 of file main.c.
References demo_worker(), k_demo_thread_stack, s_demo_stack, s_demo_thread, s_thread_name, TX_AUTO_START, TX_NO_TIME_SLICE, and tx_thread_create.
|
static |
|
static |
|
static |
USB-FS pin identifiers, packed ra8_port_pin_t (port << 8 | pin).
Built as a runtime cast so clang-tidy's enum-range check is happy with the otherwise out-of-enum value.
|
static |
|
static |
|
static |
|
static |
|
static |
RAM-disk backing store (4 KiB = 8 x 512-byte sectors).
Zero-initialized at boot. There is no filesystem on it; macOS will offer to initialize the volume.
Definition at line 167 of file main.c.
Referenced by demo_msc_read(), and demo_msc_write().
|
static |
|
static |