Skip to content
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

Feature/usb ccid host v2 #5

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
19dcbda
Add usb host support
hemi454 May 30, 2021
8379e30
Add usb host support
hemi454 May 30, 2021
9bf8311
Merge branch 'feature/add-usb-host-support' of https://github.com/hem…
hemi454 May 31, 2021
7f64284
Merge branch 'feature/add-usb-host-support' of https://github.com/hem…
hemi454 May 31, 2021
31261ba
Merge branch 'feature/add-usb-host-support' of https://github.com/hem…
hemi454 Jun 3, 2021
f89d71c
Add keyboard events handling
hemi454 Jun 6, 2021
e18ed46
Add keyboard events handling
hemi454 Jun 6, 2021
471d522
Merge branch 'feature/add-usb-host-support' of https://github.com/hem…
hemi454 Jun 7, 2021
56d016c
Merge branch 'feature/add-usb-host-support' of https://github.com/hem…
hemi454 Jun 7, 2021
80541c7
Merge branch 'feature/add-usb-host-support' of https://github.com/hem…
hemi454 Jun 10, 2021
37ad1d8
Enable UART REPL mode
hemi454 Jun 10, 2021
ddf158c
Add cdc device support
hemi454 Jun 11, 2021
b031864
Convert cdc class into ccid
hemi454 Jun 12, 2021
365023d
Add proper endpoints for CCID class
hemi454 Jun 13, 2021
0548800
Add proper endpoints for CCID class
hemi454 Jun 13, 2021
9715023
Merge branch 'feature/usb-ccid-host-draft' of https://github.com/hemi…
hemi454 Jun 15, 2021
e4ddb9b
Add chip card descriptor
hemi454 Jun 16, 2021
5c4be78
Add chip card descriptor
hemi454 Jun 16, 2021
6552379
Merge branch 'feature/usb-ccid-host-v1' of https://github.com/hemi454…
hemi454 Jun 17, 2021
54bd249
Add usb smard card reader user module
hemi454 Jul 4, 2021
73e9927
Add usb smard card reader user module
hemi454 Jul 4, 2021
2107a61
Merge branch 'feature/usb-ccid-host-v2' of https://github.com/hemi454…
hemi454 Aug 24, 2021
eccbade
Merge branch 'feature/usb-ccid-host-v2' of https://github.com/hemi454…
hemi454 Aug 24, 2021
35f662d
Merge branch 'feature/usb-ccid-host-v2' of https://github.com/hemi454…
hemi454 Oct 7, 2021
530c6d2
Merge branch 'feature/usb-ccid-host-v2' of https://github.com/hemi454…
hemi454 Oct 7, 2021
ec7face
Merge branch 'feature/usb-ccid-host-v2' of https://github.com/hemi454…
Oct 23, 2021
477e755
Merge branch 'feature/usb-ccid-host-v2' of https://github.com/hemi454…
Oct 23, 2021
e8b56d4
Merge branch 'feature/usb-ccid-host-v2' of https://github.com/hemi454…
Oct 23, 2021
8b9e649
Merge branch 'feature/usb-ccid-host-v2' of https://github.com/hemi454…
Oct 23, 2021
1538a9a
Merge branch 'feature/usb-ccid-host-v2' of https://github.com/hemi454…
Oct 24, 2021
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
1 change: 1 addition & 0 deletions lib/stm32lib/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_hcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ HAL_StatusTypeDef HAL_HCD_Stop(HCD_HandleTypeDef *hhcd);
HCD_StateTypeDef HAL_HCD_GetState(HCD_HandleTypeDef *hhcd);
HCD_URBStateTypeDef HAL_HCD_HC_GetURBState(HCD_HandleTypeDef *hhcd, uint8_t chnum);
uint32_t HAL_HCD_HC_GetXferCount(HCD_HandleTypeDef *hhcd, uint8_t chnum);
uint32_t HAL_HCD_HC_GetXferPktCount(HCD_HandleTypeDef *hhcd, uint8_t chnum);
HCD_HCStateTypeDef HAL_HCD_HC_GetState(HCD_HandleTypeDef *hhcd, uint8_t chnum);
uint32_t HAL_HCD_GetCurrentFrame(HCD_HandleTypeDef *hhcd);
uint32_t HAL_HCD_GetCurrentSpeed(HCD_HandleTypeDef *hhcd);
Expand Down
2 changes: 2 additions & 0 deletions lib/stm32lib/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ typedef struct

uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer. */

uint32_t xfer_pktcnt; /*!< Partial transfer length in case of multi packet transfer. */

uint8_t toggle_in; /*!< IN transfer current toggle flag.
This parameter must be a number between Min_Data = 0 and Max_Data = 1 */

Expand Down
16 changes: 14 additions & 2 deletions lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"

#include <stdio.h>
/** @addtogroup STM32F4xx_HAL_Driver
* @{
*/
Expand Down Expand Up @@ -725,6 +725,18 @@ HCD_URBStateTypeDef HAL_HCD_HC_GetURBState(HCD_HandleTypeDef *hhcd, uint8_t chnu
return hhcd->hc[chnum].urb_state;
}

/**
* @brief Return the last host transfer size.
* @param hhcd: HCD handle
* @param chnum: Channel number.
* This parameter can be a value from 1 to 15
* @retval last transfer size in byte
*/
uint32_t HAL_HCD_HC_GetXferPktCount(HCD_HandleTypeDef *hhcd, uint8_t chnum)
{
return hhcd->hc[chnum].xfer_pktcnt;
}


/**
* @brief Return the last host transfer size.
Expand Down Expand Up @@ -1088,7 +1100,7 @@ static void HCD_RXQLVL_IRQHandler(HCD_HandleTypeDef *hhcd)
uint32_t pktcnt;
uint32_t temp = 0U;
uint32_t tmpreg = 0U;

temp = hhcd->Instance->GRXSTSP;
channelnum = temp & USB_OTG_GRXSTSP_EPNUM;
pktsts = (temp & USB_OTG_GRXSTSP_PKTSTS) >> 17U;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ HAL_StatusTypeDef HAL_HCD_Stop(HCD_HandleTypeDef *hhcd);
*/
HCD_StateTypeDef HAL_HCD_GetState(HCD_HandleTypeDef *hhcd);
HCD_URBStateTypeDef HAL_HCD_HC_GetURBState(HCD_HandleTypeDef *hhcd, uint8_t chnum);
uint32_t HAL_HCD_HC_GetXferPktCount(HCD_HandleTypeDef *hhcd, uint8_t chnum);
uint32_t HAL_HCD_HC_GetXferCount(HCD_HandleTypeDef *hhcd, uint8_t chnum);
HCD_HCStateTypeDef HAL_HCD_HC_GetState(HCD_HandleTypeDef *hhcd, uint8_t chnum);
uint32_t HAL_HCD_GetCurrentFrame(HCD_HandleTypeDef *hhcd);
Expand Down
14 changes: 9 additions & 5 deletions ports/stm32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BOARD ?= PYBV10
BUILD ?= build-$(BOARD)

SKIP_USBINIT ?= 0
MICROPY_HW_SDCARD_MOUNT_AT_BOOT ?= 0
MICROPY_HW_SDCARD_MOUNT_AT_BOOT ?= 1

BOARD_DIR ?= boards/$(BOARD)
ifeq ($(wildcard $(BOARD_DIR)/.),)
Expand Down Expand Up @@ -36,7 +36,7 @@ LD_DIR=boards
CMSIS_DIR=$(TOP)/lib/stm32lib/CMSIS/STM32$(MCU_SERIES_UPPER)xx/Include
HAL_DIR=lib/stm32lib/STM32$(MCU_SERIES_UPPER)xx_HAL_Driver
USBDEV_DIR=usbdev
#USBHOST_DIR=usbhost
USBHOST_DIR=usbhost
DFU=$(TOP)/tools/dfu.py
# may need to prefix dfu-util with sudo
USE_PYDFU ?= 1
Expand All @@ -48,7 +48,6 @@ OPENOCD ?= openocd
OPENOCD_CONFIG ?= boards/openocd_stm32f4.cfg
STARTUP_FILE ?= lib/stm32lib/CMSIS/STM32$(MCU_SERIES_UPPER)xx/Source/Templates/gcc/startup_$(CMSIS_MCU_LOWER).o
SYSTEM_FILE ?= lib/stm32lib/CMSIS/STM32$(MCU_SERIES_UPPER)xx/Source/Templates/system_stm32$(MCU_SERIES)xx.o

# Select the cross compile prefix
CROSS_COMPILE ?= arm-none-eabi-

Expand All @@ -59,7 +58,7 @@ INC += -I$(TOP)/lib/cmsis/inc
INC += -I$(CMSIS_DIR)/
INC += -I$(TOP)/$(HAL_DIR)/Inc
INC += -I$(USBDEV_DIR)/core/inc -I$(USBDEV_DIR)/class/inc
#INC += -I$(USBHOST_DIR)
INC += -I$(USBHOST_DIR)/Class/HID/Inc
INC += -Ilwip_inc

# Basic Cortex-M flags
Expand Down Expand Up @@ -101,7 +100,7 @@ ifeq ($(SKIP_USBINIT),1)
CFLAGS += -DSKIP_USBINIT=$(SKIP_USBINIT)
endif
CFLAGS += -DMICROPY_HW_SDCARD_MOUNT_AT_BOOT=$(MICROPY_HW_SDCARD_MOUNT_AT_BOOT)

CFLAGS += -lcrt -lc
# Configure for nan-boxing object model if requested
ifeq ($(NANBOX),1)
CFLAGS += -DMP_CONFIGFILE='"mpconfigport_nanbox.h"'
Expand Down Expand Up @@ -257,6 +256,10 @@ SRC_C = \
usbd_cdc_interface.c \
usbd_hid_interface.c \
usbd_msc_interface.c \
usbh_hid.c \
usbh_hid_keybd.c \
usbh_hid_mouse.c \
usbh_hid_parser.c \
mphalport.c \
mpthreadport.c \
irq.c \
Expand Down Expand Up @@ -364,6 +367,7 @@ SRC_HAL = $(addprefix $(HAL_DIR)/Src/stm32$(MCU_SERIES)xx_,\
hal_tim.c \
hal_tim_ex.c \
hal_uart.c \
hal_hcd.c \
)

ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 h7 l0 l4 wb))
Expand Down
20 changes: 20 additions & 0 deletions ports/stm32/Reset_Handler.cdasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
0x0807da50: 04 46 mov r4, r0
0x0807da52: df f8 30 d0 ldr.w sp, [pc, #48] ; 0x807da84 <.bss_zero_entry+14>
0x0807da56: 0c 49 ldr r1, [pc, #48] ; (0x807da88 <.bss_zero_entry+18>)
0x0807da58: 0c 4a ldr r2, [pc, #48] ; (0x807da8c <.bss_zero_entry+22>)
0x0807da5a: 0d 4b ldr r3, [pc, #52] ; (0x807da90 <.bss_zero_entry+26>)
0x0807da5c: 03 e0 b.n 0x807da66 <Reset_Handler+22>
0x0807da5e: 51 f8 04 0b ldr.w r0, [r1], #4
0x0807da62: 42 f8 04 0b str.w r0, [r2], #4
0x0807da66: 9a 42 cmp r2, r3
0x0807da68: f9 d3 bcc.n 0x807da5e <Reset_Handler+14>
0x0807da6a: 00 20 movs r0, #0
0x0807da6c: 09 49 ldr r1, [pc, #36] ; (0x807da94 <.bss_zero_entry+30>)
0x0807da6e: 0a 4a ldr r2, [pc, #40] ; (0x807da98 <.bss_zero_entry+34>)
0x0807da70: 01 e0 b.n 0x807da76 <Reset_Handler+38>
0x0807da72: 41 f8 04 0b str.w r0, [r1], #4
0x0807da76: 91 42 cmp r1, r2
0x0807da78: fb d3 bcc.n 0x807da72 <Reset_Handler+34>
0x0807da7a: ff f7 31 ff bl 0x807d8e0 <SystemInit>
0x0807da7e: 20 46 mov r0, r4
0x0807da80: eb f7 16 bd b.w 0x80694b0 <stm32_main>
6 changes: 6 additions & 0 deletions ports/stm32/boards/STM32F469DISC/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ extern struct _spi_bdev_t spi_bdev;
#ifndef MODULE_SDRAM_ENABLED
#define MODULE_SDRAM_ENABLED (1)
#endif
#ifndef MODULE_USBSCARD_ENABLED
#define MODULE_USBSCARD_ENABLED (1)
#endif
// #define MICROPY_PY_THREAD (1)

// HSE is 8MHz
Expand Down Expand Up @@ -139,4 +142,7 @@ extern struct _spi_bdev_t spi_bdev;
#define MICROPY_HW_USB_FS (1)
#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9)
#define MICROPY_HW_USB_OTG_ID_PIN (pin_A10)
#define USE_HOST_MODE (1)
//#define USB_HID_HOST_MODE (1)
#define USB_CCID_HOST_MODE (1)

8 changes: 6 additions & 2 deletions ports/stm32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@
#if MICROPY_PY_THREAD
STATIC pyb_thread_t pyb_thread_main;
#endif

#if defined(USB_HID_HOST_MODE) || defined(USB_CCID_HOST_MODE)
#define MICROPY_HW_UART_REPL PYB_UART_3
#define MICROPY_HW_UART_REPL_BAUD 115200
#endif
#if defined(MICROPY_HW_UART_REPL)
#ifndef MICROPY_HW_UART_REPL_RXBUF
#define MICROPY_HW_UART_REPL_RXBUF (260)
Expand Down Expand Up @@ -770,7 +773,7 @@ void stm32_main(uint32_t reset_mode) {
// Now we initialise sub-systems that need configuration from boot.py,
// or whose initialisation can be safely deferred until after running
// boot.py.

#ifndef USE_HOST_MODE
#ifndef SKIP_USBINIT
#if MICROPY_HW_ENABLE_USB
// init USB device to default setting if it was not already configured
Expand All @@ -786,6 +789,7 @@ void stm32_main(uint32_t reset_mode) {
}
#endif
#endif
#endif

#if MICROPY_HW_HAS_MMA7660
// MMA accel: init and reset
Expand Down
14 changes: 8 additions & 6 deletions ports/stm32/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ MP_WEAK uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {

MP_WEAK int mp_hal_stdin_rx_chr(void) {
for (;;) {
#if 0
#ifdef USE_HOST_MODE
#if defined(USE_HOST_MODE) && defined(USB_HID_HOST_MODE)
keyboardKeyCode = 0;
pyb_usb_host_process();
int c = pyb_usb_host_get_keyboard();
if (c != 0) {
return c;
if (keyboardKeyCode != 0)
{
return keyboardKeyCode;
}
#endif
#endif

if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {
return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart));
}
Expand All @@ -50,7 +50,9 @@ MP_WEAK int mp_hal_stdin_rx_chr(void) {
return dupterm_c;
}
MICROPY_EVENT_POLL_HOOK

}

}

void mp_hal_stdout_tx_str(const char *str) {
Expand Down
5 changes: 3 additions & 2 deletions ports/stm32/stm32_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extern PCD_HandleTypeDef pcd_fs_handle;
#if defined(MICROPY_HW_USB_HS)
extern PCD_HandleTypeDef pcd_hs_handle;
#endif

extern HCD_HandleTypeDef hhcd_USB_OTG_FS;
/******************************************************************************/
/* Cortex-M4 Processor Exceptions Handlers */
/******************************************************************************/
Expand Down Expand Up @@ -323,7 +323,8 @@ void USB_LP_IRQHandler(void) {
#if MICROPY_HW_USB_FS
void OTG_FS_IRQHandler(void) {
IRQ_ENTER(OTG_FS_IRQn);
HAL_PCD_IRQHandler(&pcd_fs_handle);
HAL_HCD_IRQHandler(&hhcd_USB_OTG_FS)
// HAL_PCD_IRQHandler(&pcd_fs_handle);
IRQ_EXIT(OTG_FS_IRQn);
}
#endif
Expand Down
Loading