Skip to content

Commit 8b6fffb

Browse files
author
Cruz Monrreal
authored
Merge pull request #9165 from TomoYamanaka/usb_device
Renesas : Add USB Device feature
2 parents 0e5dd39 + 4c47084 commit 8b6fffb

File tree

5 files changed

+2396
-2
lines changed

5 files changed

+2396
-2
lines changed

targets/targets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4991,7 +4991,7 @@
49914991
"supported_form_factors": ["ARDUINO"],
49924992
"extra_labels_add": ["RZA1H", "MBRZA1H", "RZ_A1_EMAC"],
49934993
"components_add": ["SD"],
4994-
"device_has_add": ["EMAC", "FLASH", "LPTICKER"],
4994+
"device_has_add": ["USBDEVICE", "EMAC", "FLASH", "LPTICKER"],
49954995
"release_versions": ["2", "5"],
49964996
"device_name": "R7S72100",
49974997
"bootloader_supported": true
@@ -5007,7 +5007,7 @@
50075007
"supported_form_factors": ["ARDUINO"],
50085008
"extra_labels_add": ["RZA1UL", "MBRZA1LU"],
50095009
"components_add": ["SD"],
5010-
"device_has_add": ["TRNG", "FLASH", "LPTICKER"],
5010+
"device_has_add": ["USBDEVICE", "TRNG", "FLASH", "LPTICKER"],
50115011
"device_has_remove": ["ETHERNET"],
50125012
"release_versions": ["2", "5"],
50135013
"device_name": "R7S72103",
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018-2018 ARM Limited, All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#define NUMBER_OF_LOGICAL_ENDPOINTS (16)
19+
#define NUMBER_OF_PHYSICAL_ENDPOINTS (NUMBER_OF_LOGICAL_ENDPOINTS * 2)
20+
21+
/* Define physical endpoint numbers */
22+
23+
/* Endpoint No. Type(s) MaxSiz DoubleBuf pipe */
24+
/* ---------------- --------- ------ --------- ---- */
25+
#define EP0OUT (0x00) /* Control 256 No 0 */
26+
#define EP0IN (0x80) /* Control 256 No 0 */
27+
#define EP1OUT (0x01) /* Int 64 No 6 */
28+
#define EP1IN (0x81) /* Int 64 No 7 */
29+
#define EP2OUT (0x02) /* Bulk 2048 Yes 3 */
30+
#define EP2IN (0x82) /* Bulk 2048 Yes 4 */
31+
#define EP3OUT (0x03) /* Bulk/Iso 2048 Yes 1 */
32+
#define EP3IN (0x83) /* Bulk/Iso 2048 Yes 2 */
33+
/*following EP is not configured in sample program*/
34+
#define EP6IN (0x86) /* Bulk 2048 Yes 5 */
35+
#define EP8IN (0x88) /* Int 64 No 8 */
36+
#define EP9IN (0x89) /* Bulk 512 Bulk 9 */
37+
#define EP10IN (0x8A) /* Int/Bulk 2048 Bulk 10 */
38+
#define EP11IN (0x8B) /* Bulk 2048 Yes 11 */
39+
#define EP12IN (0x8C) /* Bulk 2048 Yes 12 */
40+
#define EP13IN (0x8D) /* Bulk 2048 Yes 13 */
41+
#define EP14IN (0x8E) /* Bulk 2048 Yes 14 */
42+
#define EP15IN (0x8F) /* Bulk 2048 Yes 15 */
43+
44+
/* Maximum Packet sizes */
45+
#define MAX_PACKET_SIZE_EP0 (64) /*pipe0/pipe0: control */
46+
#define MAX_PACKET_SIZE_EP1 (64) /*pipe6/pipe7: interrupt */
47+
#define MAX_PACKET_SIZE_EP2 (512) /*pipe3/pipe4: bulk */
48+
#define MAX_PACKET_SIZE_EP3 (512) /*pipe1/pipe2: isochronous */
49+
#define MAX_PACKET_SIZE_EP6 (64) /*pipe5: Note *1 */
50+
#define MAX_PACKET_SIZE_EP8 (64) /*pipe7: Note *1 */
51+
#define MAX_PACKET_SIZE_EP9 (512) /*pipe8: Note *1 */
52+
#define MAX_PACKET_SIZE_EP10 (512) /*pipe9: Note *1 */
53+
#define MAX_PACKET_SIZE_EP11 (512) /*pipe10: Note *1 */
54+
#define MAX_PACKET_SIZE_EP12 (512) /*pipe11: Note *1 */
55+
#define MAX_PACKET_SIZE_EP13 (512) /*pipe12: Note *1 */
56+
#define MAX_PACKET_SIZE_EP14 (512) /*pipe13: Note *1 */
57+
#define MAX_PACKET_SIZE_EP15 (512) /*pipe14: Note *1 */
58+
/* Note *1: This pipe is not configure in sample program */
59+
60+
61+
/* Generic endpoints - intended to be portable accross devices */
62+
/* and be suitable for simple USB devices. */
63+
64+
/* Bulk endpoints */
65+
#define EPBULK_OUT (EP2OUT)
66+
#define EPBULK_IN (EP2IN)
67+
#define EPBULK_OUT_callback EP2_OUT_callback
68+
#define EPBULK_IN_callback EP2_IN_callback
69+
/* Interrupt endpoints */
70+
#define EPINT_OUT (EP1OUT)
71+
#define EPINT_IN (EP1IN)
72+
#define EPINT_OUT_callback EP1_OUT_callback
73+
#define EPINT_IN_callback EP1_IN_callback
74+
/* Isochronous endpoints */
75+
#define EPISO_OUT (EP3OUT)
76+
#define EPISO_IN (EP3IN)
77+
#define EPISO_OUT_callback EP3_OUT_callback
78+
#define EPISO_IN_callback EP3_IN_callback
79+
80+
#define MAX_PACKET_SIZE_EPBULK (MAX_PACKET_SIZE_EP2)
81+
#define MAX_PACKET_SIZE_EPINT (MAX_PACKET_SIZE_EP1)
82+
#define MAX_PACKET_SIZE_EPISO (MAX_PACKET_SIZE_EP3)
83+
84+
/*EOF*/
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018-2018 ARM Limited, All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef USBPHYHW_H
19+
#define USBPHYHW_H
20+
21+
#include "mbed.h"
22+
#include "USBPhy.h"
23+
24+
25+
class USBPhyHw : public USBPhy {
26+
public:
27+
USBPhyHw();
28+
virtual ~USBPhyHw();
29+
virtual void init(USBPhyEvents *events);
30+
virtual void deinit();
31+
virtual bool powered();
32+
virtual void connect();
33+
virtual void disconnect();
34+
virtual void configure();
35+
virtual void unconfigure();
36+
virtual void sof_enable();
37+
virtual void sof_disable();
38+
virtual void set_address(uint8_t address);
39+
virtual void remote_wakeup();
40+
virtual const usb_ep_table_t* endpoint_table();
41+
42+
virtual uint32_t ep0_set_max_packet(uint32_t max_packet);
43+
virtual void ep0_setup_read_result(uint8_t *buffer, uint32_t size);
44+
virtual void ep0_read(uint8_t *data, uint32_t size);
45+
virtual uint32_t ep0_read_result();
46+
virtual void ep0_write(uint8_t *buffer, uint32_t size);
47+
virtual void ep0_stall();
48+
49+
virtual bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type);
50+
virtual void endpoint_remove(usb_ep_t endpoint);
51+
virtual void endpoint_stall(usb_ep_t endpoint);
52+
virtual void endpoint_unstall(usb_ep_t endpoint);
53+
54+
virtual bool endpoint_read(usb_ep_t endpoint, uint8_t *data, uint32_t size);
55+
virtual uint32_t endpoint_read_result(usb_ep_t endpoint);
56+
virtual bool endpoint_write(usb_ep_t endpoint, uint8_t *data, uint32_t size);
57+
virtual void endpoint_abort(usb_ep_t endpoint);
58+
59+
virtual void process();
60+
61+
private:
62+
#define PIPE_NUM (16)
63+
64+
typedef struct {
65+
bool enable;
66+
uint16_t status;
67+
uint32_t req_size;
68+
uint32_t data_cnt;
69+
uint8_t *p_data;
70+
} pipe_ctrl_t;
71+
72+
USBPhyEvents *events;
73+
pipe_ctrl_t pipe_ctrl[PIPE_NUM];
74+
uint16_t setup_buffer[32];
75+
76+
static void _usbisr(void);
77+
void chg_curpipe(uint16_t pipe, uint16_t isel);
78+
uint16_t is_set_frdy(uint16_t pipe, uint16_t isel);
79+
uint8_t * read_fifo(uint16_t pipe, uint16_t count, uint8_t *read_p);
80+
uint16_t read_data(uint16_t pipe);
81+
void fifo_to_buf(uint16_t pipe);
82+
uint8_t * write_fifo(uint16_t pipe, uint16_t count, uint8_t *write_p);
83+
uint16_t write_data(uint16_t pipe);
84+
void buf_to_fifo(uint16_t pipe);
85+
uint16_t * get_pipectr_reg(uint16_t pipe);
86+
uint16_t * get_pipetre_reg(uint16_t pipe);
87+
uint16_t * get_pipetrn_reg(uint16_t pipe);
88+
uint16_t * get_fifoctr_reg(uint16_t pipe);
89+
uint16_t * get_fifosel_reg(uint16_t pipe);
90+
uint32_t * get_fifo_reg(uint16_t pipe);
91+
uint16_t get_pid(uint16_t pipe);
92+
void set_mbw(uint16_t pipe, uint16_t data);
93+
void set_pid(uint16_t pipe, uint16_t new_pid);
94+
void cpu_delay_1us(uint16_t time);
95+
uint16_t EP2PIPE(uint16_t endpoint);
96+
uint16_t PIPE2EP(uint16_t pipe);
97+
uint16_t PIPE2FIFO(uint16_t pipe);
98+
void reset_usb(uint16_t clockmode);
99+
bool chk_vbsts(void);
100+
void ctrl_end(uint16_t status);
101+
void data_end(uint16_t pipe, uint16_t status);
102+
void forced_termination(uint16_t pipe, uint16_t status);
103+
104+
};
105+
106+
#endif

0 commit comments

Comments
 (0)