Skip to content

Add Kinetis USB Phy #6337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions TESTS/usb_device/basic/USBTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ void USBTester::callback_set_configuration(uint8_t configuration)
endpoint_add(bulk_in, MAX_EP_SIZE, USB_EP_TYPE_BULK);
endpoint_add(bulk_out, MAX_EP_SIZE, USB_EP_TYPE_BULK, &USBTester::epbulk_out_callback);

read_start(int_out);
read_start(bulk_out);

complete_set_configuration(true);
}

Expand All @@ -167,9 +164,6 @@ void USBTester::callback_set_interface(uint16_t interface, uint8_t alternate)
endpoint_add(bulk_in, MAX_EP_SIZE, USB_EP_TYPE_BULK);
endpoint_add(bulk_out, MAX_EP_SIZE, USB_EP_TYPE_BULK, &USBTester::epbulk_out_callback);

read_start(int_out);
read_start(bulk_out);

complete_set_interface(true);
return;
}
Expand All @@ -184,9 +178,6 @@ void USBTester::callback_set_interface(uint16_t interface, uint8_t alternate)
endpoint_add(bulk_in, MIN_EP_SIZE, USB_EP_TYPE_BULK);
endpoint_add(bulk_out, MIN_EP_SIZE, USB_EP_TYPE_BULK, &USBTester::epbulk_out_callback);

read_start(int_out);
read_start(bulk_out);

complete_set_interface(true);
return;
}
Expand Down Expand Up @@ -362,10 +353,7 @@ void USBTester::epint_out_callback(usb_ep_t endpoint)
uint8_t buffer[65];
uint32_t size = 0;

if (!read_finish(endpoint, buffer, sizeof(buffer), &size)) {
return;
}
if (!read_start(endpoint)) {
if (!read(endpoint, buffer, sizeof(buffer), &size)) {
return;
}
}
Expand All @@ -374,10 +362,7 @@ void USBTester::epbulk_out_callback(usb_ep_t endpoint)
uint8_t buffer[65];
uint32_t size = 0;

if (!read_finish(endpoint, buffer, sizeof(buffer), &size)) {
return;
}
if (!read_start(endpoint)) {
if (!read(endpoint, buffer, sizeof(buffer), &size)) {
return;
}
}
Expand Down
61 changes: 61 additions & 0 deletions targets/TARGET_Freescale/usb/USBEndpoints_Kinetis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* mbed Microcontroller Library
* Copyright (c) 2018-2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#define NUMBER_OF_LOGICAL_ENDPOINTS (4)
#define NUMBER_OF_PHYSICAL_ENDPOINTS (NUMBER_OF_LOGICAL_ENDPOINTS * 2)

/* Define physical endpoint numbers */

/* Endpoint No. */
/* ---------------- */
#define EP0OUT (0x00)
#define EP0IN (0x80)
#define EP1OUT (0x01)
#define EP1IN (0x81)
#define EP2OUT (0x02)
#define EP2IN (0x82)
#define EP3OUT (0x03)
#define EP3IN (0x83)

/* Maximum Packet sizes */

#define MAX_PACKET_SIZE_EP0 (64)
#define MAX_PACKET_SIZE_EP1 (64)
#define MAX_PACKET_SIZE_EP2 (64)
#define MAX_PACKET_SIZE_EP3 (1023)

/* Generic endpoints - intended to be portable accross devices */
/* and be suitable for simple USB devices. */

/* Bulk endpoints */
#define EPBULK_OUT (EP2OUT)
#define EPBULK_IN (EP2IN)
#define EPBULK_OUT_callback EP2_OUT_callback
#define EPBULK_IN_callback EP2_IN_callback
/* Interrupt endpoints */
#define EPINT_OUT (EP1OUT)
#define EPINT_IN (EP1IN)
#define EPINT_OUT_callback EP1_OUT_callback
#define EPINT_IN_callback EP1_IN_callback
/* Isochronous endpoints */
#define EPISO_OUT (EP3OUT)
#define EPISO_IN (EP3IN)
#define EPISO_OUT_callback EP3_OUT_callback
#define EPISO_IN_callback EP3_IN_callback

#define MAX_PACKET_SIZE_EPBULK (MAX_PACKET_SIZE_EP2)
#define MAX_PACKET_SIZE_EPINT (MAX_PACKET_SIZE_EP1)
#define MAX_PACKET_SIZE_EPISO (MAX_PACKET_SIZE_EP3)
66 changes: 66 additions & 0 deletions targets/TARGET_Freescale/usb/USBPhyHw.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* mbed Microcontroller Library
* Copyright (c) 2018-2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef USBPHYHW_H
#define USBPHYHW_H

#include "mbed.h"
#include "USBPhy.h"


class USBPhyHw : public USBPhy {
public:
USBPhyHw();
virtual ~USBPhyHw();
virtual void init(USBPhyEvents *events);
virtual void deinit();
virtual bool powered();
virtual void connect();
virtual void disconnect();
virtual void configure();
virtual void unconfigure();
virtual void sof_enable();
virtual void sof_disable();
virtual void set_address(uint8_t address);
virtual void remote_wakeup();
virtual const usb_ep_table_t* endpoint_table();

virtual uint32_t ep0_set_max_packet(uint32_t max_packet);
virtual void ep0_setup_read_result(uint8_t *buffer, uint32_t size);
virtual void ep0_read();
virtual uint32_t ep0_read_result(uint8_t *buffer, uint32_t size);
virtual void ep0_write(uint8_t *buffer, uint32_t size);
virtual void ep0_stall();

virtual bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type);
virtual void endpoint_remove(usb_ep_t endpoint);
virtual void endpoint_stall(usb_ep_t endpoint);
virtual void endpoint_unstall(usb_ep_t endpoint);

virtual bool endpoint_read(usb_ep_t endpoint, uint32_t maximumSize);
virtual bool endpoint_read_result(usb_ep_t endpoint, uint8_t *data, uint32_t size, uint32_t *bytesRead);
virtual bool endpoint_write(usb_ep_t endpoint, uint8_t *data, uint32_t size);
virtual void endpoint_abort(usb_ep_t endpoint);

virtual void process();

private:
USBPhyEvents *events;

static void _usbisr(void);
};

#endif
Loading