Skip to content

Commit c416573

Browse files
committed
K64F - USBDevice addition
1 parent 9fcdbb8 commit c416573

File tree

4 files changed

+38
-35
lines changed

4 files changed

+38
-35
lines changed

libraries/USBDevice/USBDevice/USBEndpoints.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ typedef enum {
4141
#include "USBEndpoints_LPC17_LPC23.h"
4242
#elif defined(TARGET_LPC11UXX) || defined(TARGET_LPC1347)
4343
#include "USBEndpoints_LPC11U.h"
44-
#elif defined(TARGET_KL25Z)
44+
#elif defined(TARGET_KL25Z) | defined(TARGET_K64F)
4545
#include "USBEndpoints_KL25Z.h"
4646
#elif defined (TARGET_STM32F4XX)
4747
#include "USBEndpoints_STM32F4.h"

libraries/USBDevice/USBDevice/USBHAL_KL25Z.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1717
*/
1818

19-
#if defined(TARGET_KL25Z)
19+
#if defined(TARGET_KL25Z) | defined(TARGET_K64F)
2020

2121
#include "USBHAL.h"
2222

@@ -59,7 +59,7 @@ typedef struct BDT {
5959
uint8_t dummy; // RSVD: BD[8:15]
6060
uint16_t byte_count; // BD[16:32]
6161
uint32_t address; // Addr
62-
} BDT;
62+
} BDT;
6363

6464

6565
// there are:
@@ -82,10 +82,10 @@ uint32_t USBHAL::endpointReadcore(uint8_t endpoint, uint8_t *buffer) {
8282
return 0;
8383
}
8484

85-
USBHAL::USBHAL(void) {
85+
USBHAL::USBHAL(void) {
8686
// Disable IRQ
8787
NVIC_DisableIRQ(USB0_IRQn);
88-
88+
8989
// fill in callback array
9090
epCallback[0] = &USBHAL::EP1_OUT_callback;
9191
epCallback[1] = &USBHAL::EP1_IN_callback;
@@ -117,24 +117,24 @@ USBHAL::USBHAL(void) {
117117
epCallback[27] = &USBHAL::EP14_IN_callback;
118118
epCallback[28] = &USBHAL::EP15_OUT_callback;
119119
epCallback[29] = &USBHAL::EP15_IN_callback;
120-
121-
120+
121+
122122
// choose usb src as PLL
123123
SIM->SOPT2 |= (SIM_SOPT2_USBSRC_MASK | SIM_SOPT2_PLLFLLSEL_MASK);
124-
124+
125125
// enable OTG clock
126126
SIM->SCGC4 |= SIM_SCGC4_USBOTG_MASK;
127127

128128
// Attach IRQ
129129
instance = this;
130130
NVIC_SetVector(USB0_IRQn, (uint32_t)&_usbisr);
131131
NVIC_EnableIRQ(USB0_IRQn);
132-
132+
133133
// USB Module Configuration
134134
// Reset USB Module
135135
USB0->USBTRC0 |= USB_USBTRC0_USBRESET_MASK;
136136
while(USB0->USBTRC0 & USB_USBTRC0_USBRESET_MASK);
137-
137+
138138
// Set BDT Base Register
139139
USB0->BDTPAGE1=(uint8_t)((uint32_t)bdt>>8);
140140
USB0->BDTPAGE2=(uint8_t)((uint32_t)bdt>>16);
@@ -144,14 +144,14 @@ USBHAL::USBHAL(void) {
144144
USB0->ISTAT = 0xff;
145145

146146
// USB Interrupt Enablers
147-
USB0->INTEN |= USB_INTEN_TOKDNEEN_MASK |
148-
USB_INTEN_SOFTOKEN_MASK |
147+
USB0->INTEN |= USB_INTEN_TOKDNEEN_MASK |
148+
USB_INTEN_SOFTOKEN_MASK |
149149
USB_INTEN_ERROREN_MASK |
150150
USB_INTEN_USBRSTEN_MASK;
151-
152-
// Disable weak pull downs
153-
USB0->USBCTRL &= ~(USB_USBCTRL_PDE_MASK | USB_USBCTRL_SUSP_MASK);
154-
151+
152+
// Disable weak pull downs
153+
USB0->USBCTRL &= ~(USB_USBCTRL_PDE_MASK | USB_USBCTRL_SUSP_MASK);
154+
155155
USB0->USBTRC0 |= 0x40;
156156
}
157157

@@ -296,9 +296,9 @@ EP_STATUS USBHAL::endpointReadResult(uint8_t endpoint, uint8_t * buffer, uint32_
296296
uint32_t n, sz, idx, setup = 0;
297297
uint8_t not_iso;
298298
uint8_t * ep_buf;
299-
299+
300300
uint32_t log_endpoint = PHY_TO_LOG(endpoint);
301-
301+
302302
if (endpoint > NUMBER_OF_PHYSICAL_ENDPOINTS - 1) {
303303
return EP_INVALID;
304304
}
@@ -335,7 +335,7 @@ EP_STATUS USBHAL::endpointReadResult(uint8_t endpoint, uint8_t * buffer, uint32_
335335
if (((Data1 >> endpoint) & 1) == ((bdt[idx].info >> 6) & 1)) {
336336
if (setup && (buffer[6] == 0)) // if no setup data stage,
337337
Data1 &= ~1UL; // set DATA0
338-
else
338+
else
339339
Data1 ^= (1 << endpoint);
340340
}
341341

@@ -345,7 +345,7 @@ EP_STATUS USBHAL::endpointReadResult(uint8_t endpoint, uint8_t * buffer, uint32_
345345
else {
346346
bdt[idx].info = BD_DTS_MASK | BD_OWN_MASK;
347347
}
348-
348+
349349
USB0->CTL &= ~USB_CTL_TXSUSPENDTOKENBUSY_MASK;
350350
*bytesRead = sz;
351351

@@ -368,27 +368,27 @@ EP_STATUS USBHAL::endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size)
368368

369369
idx = EP_BDT_IDX(PHY_TO_LOG(endpoint), TX, 0);
370370
bdt[idx].byte_count = size;
371-
372-
371+
372+
373373
// non iso endpoint
374374
if (USB0->ENDPOINT[PHY_TO_LOG(endpoint)].ENDPT & USB_ENDPT_EPHSHK_MASK) {
375375
ep_buf = endpoint_buffer[idx];
376376
} else {
377377
ep_buf = endpoint_buffer_iso[2];
378378
}
379-
379+
380380
for (n = 0; n < size; n++) {
381381
ep_buf[n] = data[n];
382382
}
383-
383+
384384
if ((Data1 >> endpoint) & 1) {
385385
bdt[idx].info = BD_OWN_MASK | BD_DTS_MASK;
386386
} else {
387387
bdt[idx].info = BD_OWN_MASK | BD_DTS_MASK | BD_DATA01_MASK;
388388
}
389-
389+
390390
Data1 ^= (1 << endpoint);
391-
391+
392392
return EP_PENDING;
393393
}
394394

@@ -429,7 +429,7 @@ void USBHAL::usbisr(void) {
429429
uint8_t istat = USB0->ISTAT;
430430

431431
// reset interrupt
432-
if (istat & USB_ISTAT_USBRST_MASK) {
432+
if (istat & USB_ISTAT_USBRST_MASK) {
433433
// disable all endpt
434434
for(i = 0; i < 16; i++) {
435435
USB0->ENDPOINT[i].ENDPT = 0x00;
@@ -457,11 +457,11 @@ void USBHAL::usbisr(void) {
457457

458458
// SOF interrupt
459459
if (istat & USB_ISTAT_SOFTOK_MASK) {
460-
USB0->ISTAT = USB_ISTAT_SOFTOK_MASK;
460+
USB0->ISTAT = USB_ISTAT_SOFTOK_MASK;
461461
// SOF event, read frame number
462462
SOF(frameNumber());
463463
}
464-
464+
465465
// stall interrupt
466466
if (istat & 1<<7) {
467467
if (USB0->ENDPOINT[0].ENDPT & USB_ENDPT_EPSTALL_MASK)
@@ -483,7 +483,7 @@ void USBHAL::usbisr(void) {
483483

484484
// EP0 SETUP event (SETUP data received)
485485
EP0setupCallback();
486-
486+
487487
} else {
488488
// OUT packet
489489
if (TOK_PID((EP_BDT_IDX(num, dir, ev_odd))) == OUT_TOKEN) {
@@ -517,11 +517,11 @@ void USBHAL::usbisr(void) {
517517

518518
USB0->ISTAT = USB_ISTAT_TOKDNE_MASK;
519519
}
520-
520+
521521
// sleep interrupt
522522
if (istat & 1<<4) {
523523
USB0->ISTAT |= USB_ISTAT_SLEEP_MASK;
524-
}
524+
}
525525

526526
// error interrupt
527527
if (istat & USB_ISTAT_ERROR_MASK) {

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/gpio_irq_api.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ static void handle_interrupt_in(PortName port, int ch_base) {
3838
for (i = 0; i < 32; i++) {
3939
if (port_hal_read_pin_interrupt_flag(port, i)) {
4040
uint32_t id = channel_ids[ch_base + i];
41-
if (id == 0)
41+
if (id == 0) {
4242
continue;
43+
}
4344

4445
gpio_irq_event event = IRQ_NONE;
4546
switch (BR_PORT_PCRn_IRQC(port, i)) {

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/pinmap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@
1818
#include "fsl_clock_manager.h"
1919

2020
void pin_function(PinName pin, int function) {
21-
if (pin == (PinName)NC)
21+
if (pin == (PinName)NC) {
2222
return;
23+
}
2324

2425
clock_manager_set_gate(kClockModulePORT, pin >> GPIO_PORT_SHIFT, true);
2526
port_hal_mux_control(pin >> GPIO_PORT_SHIFT, pin & 0xFF, (port_mux_t)function);
2627
}
2728

2829
void pin_mode(PinName pin, PinMode mode) {
29-
if (pin == (PinName)NC)
30+
if (pin == (PinName)NC) {
3031
return;
32+
}
3133

3234
uint32_t instance = pin >> GPIO_PORT_SHIFT;
3335
uint32_t pinName = pin & 0xFF;

0 commit comments

Comments
 (0)