Commit 75abee20 authored by Damien George's avatar Damien George
Browse files

stm: USB host mode working! Restructure stm library directories.

parent 8fcf7b85
...@@ -6,18 +6,23 @@ QSTR_DEFS = qstrdefsport.h ...@@ -6,18 +6,23 @@ QSTR_DEFS = qstrdefsport.h
# include py core make definitions # include py core make definitions
include ../py/py.mk include ../py/py.mk
CMSIS=cmsis CMSIS_DIR=cmsis
STMSRC=lib STMPERIPH_DIR=stmperiph
#STMOTGSRC=usbhost STMUSB_DIR=stmusb
FATFSSRC=fatfs STMUSBD_DIR=stmusbd
CC3KSRC=cc3k STMUSBH_DIR=stmusbh
FATFS_DIR=fatfs
CC3K_DIR=cc3k
DFU=../tools/dfu.py DFU=../tools/dfu.py
CROSS_COMPILE = arm-none-eabi- CROSS_COMPILE = arm-none-eabi-
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion
CFLAGS = -I. -I$(PY_SRC) -I$(FATFSSRC) -I$(CMSIS) -I$(STMSRC) -Wall -ansi -std=gnu99 $(CFLAGS_CORTEX_M4) CFLAGS = -I. -I$(PY_SRC) -I$(CMSIS_DIR) -I$(STMPERIPH_DIR) -I$(STMUSB_DIR) -Wall -ansi -std=gnu99 $(CFLAGS_CORTEX_M4)
#CFLAGS += -I$(STMOTGSRC) -DUSE_HOST_MODE #-DUSE_OTG_MODE CFLAGS += -I$(STMUSBD_DIR)
CFLAGS += -I$(STMUSBH_DIR)
CFLAGS += -I$(FATFS_DIR)
#CFLAGS += -I$(CC3K_DIR)
#Debugging/Optimization #Debugging/Optimization
ifeq ($(DEBUG), 1) ifeq ($(DEBUG), 1)
...@@ -64,15 +69,10 @@ SRC_S = \ ...@@ -64,15 +69,10 @@ SRC_S = \
startup_stm32f40xx.s \ startup_stm32f40xx.s \
gchelper.s \ gchelper.s \
SRC_FATFS = $(addprefix $(FATFSSRC)/,\ SRC_STMPERIPH = $(addprefix $(STMPERIPH_DIR)/,\
ff.c \ stm_misc.c \
diskio.c \
)
SRC_STM = $(addprefix $(STMSRC)/,\
stm32f4xx_rcc.c \ stm32f4xx_rcc.c \
stm32f4xx_syscfg.c \ stm32f4xx_syscfg.c \
stm_misc.c \
stm32f4xx_flash.c \ stm32f4xx_flash.c \
stm32f4xx_dma.c \ stm32f4xx_dma.c \
stm32f4xx_gpio.c \ stm32f4xx_gpio.c \
...@@ -89,10 +89,19 @@ SRC_STM = $(addprefix $(STMSRC)/,\ ...@@ -89,10 +89,19 @@ SRC_STM = $(addprefix $(STMSRC)/,\
stm32f4xx_adc.c \ stm32f4xx_adc.c \
stm324x7i_eval.c \ stm324x7i_eval.c \
stm324x7i_eval_sdio_sd.c \ stm324x7i_eval_sdio_sd.c \
)
SRC_STMUSB = $(addprefix $(STMUSB_DIR)/,\
usb_core.c \ usb_core.c \
usb_bsp.c \ usb_bsp.c \
usb_dcd.c \ usb_dcd.c \
usb_dcd_int.c \ usb_dcd_int.c \
usb_hcd.c \
usb_hcd_int.c \
)
# usb_otg.c \
SRC_STMUSBD = $(addprefix $(STMUSBD_DIR)/,\
usbd_core.c \ usbd_core.c \
usbd_ioreq.c \ usbd_ioreq.c \
usbd_req.c \ usbd_req.c \
...@@ -107,9 +116,7 @@ SRC_STM = $(addprefix $(STMSRC)/,\ ...@@ -107,9 +116,7 @@ SRC_STM = $(addprefix $(STMSRC)/,\
usbd_storage_msd.c \ usbd_storage_msd.c \
) )
#SRC_STM_OTG = $(addprefix $(STMSRC)/,\ SRC_STMUSBH = $(addprefix $(STMUSBH_DIR)/,\
usb_hcd.c \
usb_hcd_int.c \
usbh_core.c \ usbh_core.c \
usbh_hcs.c \ usbh_hcs.c \
usbh_stdreq.c \ usbh_stdreq.c \
...@@ -118,10 +125,14 @@ SRC_STM = $(addprefix $(STMSRC)/,\ ...@@ -118,10 +125,14 @@ SRC_STM = $(addprefix $(STMSRC)/,\
usbh_hid_core.c \ usbh_hid_core.c \
usbh_hid_mouse.c \ usbh_hid_mouse.c \
usbh_hid_keybd.c \ usbh_hid_keybd.c \
# usb_otg.c \
) )
SRC_CC3K = $(addprefix $(CC3KSRC)/,\ SRC_FATFS = $(addprefix $(FATFS_DIR)/,\
ff.c \
diskio.c \
)
SRC_CC3K = $(addprefix $(CC3K_DIR)/,\
cc3000_common.c \ cc3000_common.c \
evnt_handler.c \ evnt_handler.c \
hci.c \ hci.c \
...@@ -134,8 +145,11 @@ SRC_CC3K = $(addprefix $(CC3KSRC)/,\ ...@@ -134,8 +145,11 @@ SRC_CC3K = $(addprefix $(CC3KSRC)/,\
pybcc3k.c \ pybcc3k.c \
) )
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(SRC_FATFS:.c=.o) $(SRC_STM:.c=.o)) # $(SRC_CC3K:.c=.o)) OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(SRC_STMPERIPH:.c=.o) $(SRC_STMUSB:.c=.o))
#OBJ += $(addprefix $(BUILD)/, $(SRC_STM_OTG:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_STMUSBD:.c=.o))
#OBJ += $(addprefix $(BUILD)/, $(SRC_STMUSBH:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_FATFS:.c=.o))
#OBJ += $(addprefix $(BUILD)/, $(SRC_CC3K:.c=.o))
all: $(BUILD) $(BUILD)/flash.dfu all: $(BUILD) $(BUILD)/flash.dfu
...@@ -155,4 +169,3 @@ $(BUILD)/flash.elf: $(OBJ) ...@@ -155,4 +169,3 @@ $(BUILD)/flash.elf: $(OBJ)
$(Q)$(SIZE) $@ $(Q)$(SIZE) $@
include ../py/mkrules.mk include ../py/mkrules.mk
...@@ -324,6 +324,12 @@ void lcd_print_strn(const char *str, unsigned int len) { ...@@ -324,6 +324,12 @@ void lcd_print_strn(const char *str, unsigned int len) {
} }
if (*str == '\n') { if (*str == '\n') {
lcd_next_line = 1; lcd_next_line = 1;
} else if (*str == '\r') {
lcd_column = 0;
} else if (*str == '\b') {
if (lcd_column > 0) {
lcd_column--;
}
} else if (lcd_column >= LCD_BUF_W) { } else if (lcd_column >= LCD_BUF_W) {
lcd_next_line = 1; lcd_next_line = 1;
str -= 1; str -= 1;
...@@ -359,6 +365,6 @@ void lcd_print_strn(const char *str, unsigned int len) { ...@@ -359,6 +365,6 @@ void lcd_print_strn(const char *str, unsigned int len) {
} }
if (did_new_line) { if (did_new_line) {
sys_tick_delay_ms(200); sys_tick_delay_ms(50);
} }
} }
...@@ -274,6 +274,9 @@ void stdout_tx_str(const char *str) { ...@@ -274,6 +274,9 @@ void stdout_tx_str(const char *str) {
if (pyb_usart_global_debug != PYB_USART_NONE) { if (pyb_usart_global_debug != PYB_USART_NONE) {
usart_tx_str(pyb_usart_global_debug, str); usart_tx_str(pyb_usart_global_debug, str);
} }
#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
lcd_print_str(str);
#endif
usb_vcp_send_str(str); usb_vcp_send_str(str);
} }
...@@ -285,6 +288,13 @@ int readline(vstr_t *line, const char *prompt) { ...@@ -285,6 +288,13 @@ int readline(vstr_t *line, const char *prompt) {
for (;;) { for (;;) {
char c; char c;
for (;;) { for (;;) {
#ifdef USE_HOST_MODE
pyb_usb_host_process();
c = pyb_usb_host_get_keyboard();
if (c != 0) {
break;
}
#endif
if (usb_vcp_rx_any() != 0) { if (usb_vcp_rx_any() != 0) {
c = usb_vcp_rx_get(); c = usb_vcp_rx_get();
break; break;
...@@ -350,6 +360,12 @@ int readline(vstr_t *line, const char *prompt) { ...@@ -350,6 +360,12 @@ int readline(vstr_t *line, const char *prompt) {
} }
void do_repl(void) { void do_repl(void) {
#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
// in host mode, we enable the LCD for the repl
mp_obj_t lcd_o = rt_call_function_0(rt_load_name(qstr_from_str("LCD")));
rt_call_function_1(rt_load_attr(lcd_o, qstr_from_str("light")), mp_const_true);
#endif
stdout_tx_str("Micro Python build <git hash> on 25/1/2014; " MICROPY_HW_BOARD_NAME " with STM32F405RG\r\n"); stdout_tx_str("Micro Python build <git hash> on 25/1/2014; " MICROPY_HW_BOARD_NAME " with STM32F405RG\r\n");
stdout_tx_str("Type \"help()\" for more information.\r\n"); stdout_tx_str("Type \"help()\" for more information.\r\n");
...@@ -532,11 +548,7 @@ int main(void) { ...@@ -532,11 +548,7 @@ int main(void) {
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
// enable the CCM RAM and the GPIO's // enable the CCM RAM and the GPIO's
RCC->AHB1ENR |= RCC_AHB1ENR_CCMDATARAMEN | RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN RCC->AHB1ENR |= RCC_AHB1ENR_CCMDATARAMEN | RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIODEN;
#if defined(STM32F4DISC)
| RCC_AHB1ENR_GPIODEN
#endif
;
#if MICROPY_HW_HAS_SDCARD #if MICROPY_HW_HAS_SDCARD
{ {
...@@ -589,7 +601,7 @@ soft_reset: ...@@ -589,7 +601,7 @@ soft_reset:
rt_init(); rt_init();
#if MICROPY_HW_HAS_LCD #if MICROPY_HW_HAS_LCD
// LCD init (create in with LCD()) // LCD init (just creates class, init hardware by calling LCD())
lcd_init(); lcd_init();
#endif #endif
...@@ -663,11 +675,6 @@ soft_reset: ...@@ -663,11 +675,6 @@ soft_reset:
rt_store_name(MP_QSTR_open, rt_make_function_n(2, pyb_io_open)); rt_store_name(MP_QSTR_open, rt_make_function_n(2, pyb_io_open));
} }
#if MICROPY_HW_HAS_LCD
// print a message to the LCD
lcd_print_str(" micro py board\n");
#endif
// check if user switch held (initiates reset of filesystem) // check if user switch held (initiates reset of filesystem)
bool reset_filesystem = false; bool reset_filesystem = false;
#if MICROPY_HW_HAS_SWITCH #if MICROPY_HW_HAS_SWITCH
...@@ -760,14 +767,13 @@ soft_reset: ...@@ -760,14 +767,13 @@ soft_reset:
flash_error(4); flash_error(4);
} }
// USB #ifdef USE_HOST_MODE
usb_init(); // USB host
pyb_usb_host_init();
// USB host; not working! #elif defined(USE_DEVICE_MODE)
//pyb_usbh_init(); // USB device
//rt_store_name(qstr_from_str("u_p"), rt_make_function_n(0, pyb_usbh_process)); pyb_usb_dev_init();
//rt_store_name(qstr_from_str("u_c"), rt_make_function_n(0, pyb_usbh_connect)); #endif
//rt_store_name(qstr_from_str("u_i"), rt_make_function_n(0, pyb_usbh_info));
if (first_soft_reset) { if (first_soft_reset) {
#if MICROPY_HW_HAS_MMA7660 #if MICROPY_HW_HAS_MMA7660
......
...@@ -23,8 +23,8 @@ machine_float_t machine_sqrt(machine_float_t x); ...@@ -23,8 +23,8 @@ machine_float_t machine_sqrt(machine_float_t x);
// board specific definitions // board specific definitions
// choose 1 of these boards // choose 1 of these boards
#define PYBOARD3 //#define PYBOARD3
//#define PYBOARD4 #define PYBOARD4
//#define STM32F4DISC //#define STM32F4DISC
#if defined (PYBOARD3) #if defined (PYBOARD3)
...@@ -76,7 +76,7 @@ machine_float_t machine_sqrt(machine_float_t x); ...@@ -76,7 +76,7 @@ machine_float_t machine_sqrt(machine_float_t x);
#define MICROPY_HW_HAS_SDCARD (1) #define MICROPY_HW_HAS_SDCARD (1)
#define MICROPY_HW_HAS_MMA7660 (1) #define MICROPY_HW_HAS_MMA7660 (1)
#define MICROPY_HW_HAS_LIS3DSH (0) #define MICROPY_HW_HAS_LIS3DSH (0)
#define MICROPY_HW_HAS_LCD (0) #define MICROPY_HW_HAS_LCD (1)
#define MICROPY_HW_HAS_WLAN (0) #define MICROPY_HW_HAS_WLAN (0)
#define MICROPY_HW_ENABLE_RNG (1) #define MICROPY_HW_ENABLE_RNG (1)
#define MICROPY_HW_ENABLE_RTC (1) #define MICROPY_HW_ENABLE_RTC (1)
...@@ -158,3 +158,5 @@ machine_float_t machine_sqrt(machine_float_t x); ...@@ -158,3 +158,5 @@ machine_float_t machine_sqrt(machine_float_t x);
#define STM32F40_41xxx #define STM32F40_41xxx
#define USE_STDPERIPH_DRIVER #define USE_STDPERIPH_DRIVER
#define HSE_VALUE (8000000) #define HSE_VALUE (8000000)
#define USE_DEVICE_MODE
//#define USE_HOST_MODE
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
/* Private define ------------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/
extern USB_OTG_CORE_HANDLE USB_OTG_dev; extern USB_OTG_CORE_HANDLE USB_OTG_Core;
/* Private function prototypes -----------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/
extern uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev); extern uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev);
...@@ -161,12 +161,12 @@ void PendSV_Handler(void) ...@@ -161,12 +161,12 @@ void PendSV_Handler(void)
#ifdef USE_USB_OTG_FS #ifdef USE_USB_OTG_FS
void OTG_FS_WKUP_IRQHandler(void) void OTG_FS_WKUP_IRQHandler(void)
{ {
if(USB_OTG_dev.cfg.low_power) if(USB_OTG_Core.cfg.low_power)
{ {
*(uint32_t *)(0xE000ED10) &= 0xFFFFFFF9 ; *(uint32_t *)(0xE000ED10) &= 0xFFFFFFF9 ;
SystemInit(); SystemInit();
#ifdef USE_DEVICE_MODE #ifdef USE_DEVICE_MODE
USB_OTG_UngateClock(&USB_OTG_dev); USB_OTG_UngateClock(&USB_OTG_Core);
#endif #endif
} }
EXTI_ClearITPendingBit(EXTI_Line18); EXTI_ClearITPendingBit(EXTI_Line18);
...@@ -181,11 +181,11 @@ void OTG_FS_WKUP_IRQHandler(void) ...@@ -181,11 +181,11 @@ void OTG_FS_WKUP_IRQHandler(void)
#ifdef USE_USB_OTG_HS #ifdef USE_USB_OTG_HS
void OTG_HS_WKUP_IRQHandler(void) void OTG_HS_WKUP_IRQHandler(void)
{ {
if(USB_OTG_dev.cfg.low_power) if(USB_OTG_Core.cfg.low_power)
{ {
*(uint32_t *)(0xE000ED10) &= 0xFFFFFFF9 ; *(uint32_t *)(0xE000ED10) &= 0xFFFFFFF9 ;
SystemInit(); SystemInit();
USB_OTG_UngateClock(&USB_OTG_dev); USB_OTG_UngateClock(&USB_OTG_Core);
} }
EXTI_ClearITPendingBit(EXTI_Line20); EXTI_ClearITPendingBit(EXTI_Line20);
} }
...@@ -202,16 +202,16 @@ void OTG_HS_IRQHandler(void) ...@@ -202,16 +202,16 @@ void OTG_HS_IRQHandler(void)
void OTG_FS_IRQHandler(void) void OTG_FS_IRQHandler(void)
#endif #endif
{ {
if (USB_OTG_IsHostMode(&USB_OTG_dev)) { if (USB_OTG_IsHostMode(&USB_OTG_Core)) {
// host mode // host mode
#ifdef USE_HOST_MODE #ifdef USE_HOST_MODE
USBH_OTG_ISR_Handler(&USB_OTG_dev); USBH_OTG_ISR_Handler(&USB_OTG_Core);
#endif #endif
//STM32_USBO_OTG_ISR_Handler(&USB_OTG_dev); // USE_OTG_MODE //STM32_USBO_OTG_ISR_Handler(&USB_OTG_Core); // USE_OTG_MODE
} else { } else {
// device mode // device mode
#ifdef USE_DEVICE_MODE #ifdef USE_DEVICE_MODE
USBD_OTG_ISR_Handler(&USB_OTG_dev); USBD_OTG_ISR_Handler(&USB_OTG_Core);
#endif #endif
} }
} }
...@@ -224,7 +224,7 @@ void OTG_FS_IRQHandler(void) ...@@ -224,7 +224,7 @@ void OTG_FS_IRQHandler(void)
*/ */
void OTG_HS_EP1_IN_IRQHandler(void) void OTG_HS_EP1_IN_IRQHandler(void)
{ {
USBD_OTG_EP1IN_ISR_Handler (&USB_OTG_dev); USBD_OTG_EP1IN_ISR_Handler (&USB_OTG_Core);
} }
/** /**
...@@ -234,7 +234,7 @@ void OTG_HS_EP1_IN_IRQHandler(void) ...@@ -234,7 +234,7 @@ void OTG_HS_EP1_IN_IRQHandler(void)
*/ */
void OTG_HS_EP1_OUT_IRQHandler(void) void OTG_HS_EP1_OUT_IRQHandler(void)
{ {
USBD_OTG_EP1OUT_ISR_Handler (&USB_OTG_dev); USBD_OTG_EP1OUT_ISR_Handler (&USB_OTG_Core);
} }
#endif #endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment