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
# include py core make definitions
include ../py/py.mk
CMSIS=cmsis
STMSRC=lib
#STMOTGSRC=usbhost
FATFSSRC=fatfs
CC3KSRC=cc3k
CMSIS_DIR=cmsis
STMPERIPH_DIR=stmperiph
STMUSB_DIR=stmusb
STMUSBD_DIR=stmusbd
STMUSBH_DIR=stmusbh
FATFS_DIR=fatfs
CC3K_DIR=cc3k
DFU=../tools/dfu.py
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 = -I. -I$(PY_SRC) -I$(FATFSSRC) -I$(CMSIS) -I$(STMSRC) -Wall -ansi -std=gnu99 $(CFLAGS_CORTEX_M4)
#CFLAGS += -I$(STMOTGSRC) -DUSE_HOST_MODE #-DUSE_OTG_MODE
CFLAGS = -I. -I$(PY_SRC) -I$(CMSIS_DIR) -I$(STMPERIPH_DIR) -I$(STMUSB_DIR) -Wall -ansi -std=gnu99 $(CFLAGS_CORTEX_M4)
CFLAGS += -I$(STMUSBD_DIR)
CFLAGS += -I$(STMUSBH_DIR)
CFLAGS += -I$(FATFS_DIR)
#CFLAGS += -I$(CC3K_DIR)
#Debugging/Optimization
ifeq ($(DEBUG), 1)
......@@ -64,15 +69,10 @@ SRC_S = \
startup_stm32f40xx.s \
gchelper.s \
SRC_FATFS = $(addprefix $(FATFSSRC)/,\
ff.c \
diskio.c \
)
SRC_STM = $(addprefix $(STMSRC)/,\
SRC_STMPERIPH = $(addprefix $(STMPERIPH_DIR)/,\
stm_misc.c \
stm32f4xx_rcc.c \
stm32f4xx_syscfg.c \
stm_misc.c \
stm32f4xx_flash.c \
stm32f4xx_dma.c \
stm32f4xx_gpio.c \
......@@ -89,10 +89,19 @@ SRC_STM = $(addprefix $(STMSRC)/,\
stm32f4xx_adc.c \
stm324x7i_eval.c \
stm324x7i_eval_sdio_sd.c \
)
SRC_STMUSB = $(addprefix $(STMUSB_DIR)/,\
usb_core.c \
usb_bsp.c \
usb_dcd.c \
usb_dcd_int.c \
usb_hcd.c \
usb_hcd_int.c \
)
# usb_otg.c \
SRC_STMUSBD = $(addprefix $(STMUSBD_DIR)/,\
usbd_core.c \
usbd_ioreq.c \
usbd_req.c \
......@@ -107,9 +116,7 @@ SRC_STM = $(addprefix $(STMSRC)/,\
usbd_storage_msd.c \
)
#SRC_STM_OTG = $(addprefix $(STMSRC)/,\
usb_hcd.c \
usb_hcd_int.c \
SRC_STMUSBH = $(addprefix $(STMUSBH_DIR)/,\
usbh_core.c \
usbh_hcs.c \
usbh_stdreq.c \
......@@ -118,10 +125,14 @@ SRC_STM = $(addprefix $(STMSRC)/,\
usbh_hid_core.c \
usbh_hid_mouse.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 \
evnt_handler.c \
hci.c \
......@@ -134,8 +145,11 @@ SRC_CC3K = $(addprefix $(CC3KSRC)/,\
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 += $(addprefix $(BUILD)/, $(SRC_STM_OTG:.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_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
......@@ -155,4 +169,3 @@ $(BUILD)/flash.elf: $(OBJ)
$(Q)$(SIZE) $@
include ../py/mkrules.mk
......@@ -324,6 +324,12 @@ void lcd_print_strn(const char *str, unsigned int len) {
}
if (*str == '\n') {
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) {
lcd_next_line = 1;
str -= 1;
......@@ -359,6 +365,6 @@ void lcd_print_strn(const char *str, unsigned int len) {
}
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) {
if (pyb_usart_global_debug != PYB_USART_NONE) {
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);
}
......@@ -285,6 +288,13 @@ int readline(vstr_t *line, const char *prompt) {
for (;;) {
char c;
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) {
c = usb_vcp_rx_get();
break;
......@@ -350,6 +360,12 @@ int readline(vstr_t *line, const char *prompt) {
}
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("Type \"help()\" for more information.\r\n");
......@@ -532,11 +548,7 @@ int main(void) {
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
// enable the CCM RAM and the GPIO's
RCC->AHB1ENR |= RCC_AHB1ENR_CCMDATARAMEN | RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN
#if defined(STM32F4DISC)
| RCC_AHB1ENR_GPIODEN
#endif
;
RCC->AHB1ENR |= RCC_AHB1ENR_CCMDATARAMEN | RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIODEN;
#if MICROPY_HW_HAS_SDCARD
{
......@@ -589,7 +601,7 @@ soft_reset:
rt_init();
#if MICROPY_HW_HAS_LCD
// LCD init (create in with LCD())
// LCD init (just creates class, init hardware by calling LCD())
lcd_init();
#endif
......@@ -663,11 +675,6 @@ soft_reset:
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)
bool reset_filesystem = false;
#if MICROPY_HW_HAS_SWITCH
......@@ -760,14 +767,13 @@ soft_reset:
flash_error(4);
}
// USB
usb_init();
// USB host; not working!
//pyb_usbh_init();
//rt_store_name(qstr_from_str("u_p"), rt_make_function_n(0, pyb_usbh_process));
//rt_store_name(qstr_from_str("u_c"), rt_make_function_n(0, pyb_usbh_connect));
//rt_store_name(qstr_from_str("u_i"), rt_make_function_n(0, pyb_usbh_info));
#ifdef USE_HOST_MODE
// USB host
pyb_usb_host_init();
#elif defined(USE_DEVICE_MODE)
// USB device
pyb_usb_dev_init();
#endif
if (first_soft_reset) {
#if MICROPY_HW_HAS_MMA7660
......
......@@ -23,8 +23,8 @@ machine_float_t machine_sqrt(machine_float_t x);
// board specific definitions
// choose 1 of these boards
#define PYBOARD3
//#define PYBOARD4
//#define PYBOARD3
#define PYBOARD4
//#define STM32F4DISC
#if defined (PYBOARD3)
......@@ -76,7 +76,7 @@ machine_float_t machine_sqrt(machine_float_t x);
#define MICROPY_HW_HAS_SDCARD (1)
#define MICROPY_HW_HAS_MMA7660 (1)
#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_ENABLE_RNG (1)
#define MICROPY_HW_ENABLE_RTC (1)
......@@ -158,3 +158,5 @@ machine_float_t machine_sqrt(machine_float_t x);
#define STM32F40_41xxx
#define USE_STDPERIPH_DRIVER
#define HSE_VALUE (8000000)
#define USE_DEVICE_MODE
//#define USE_HOST_MODE
......@@ -41,7 +41,7 @@
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
extern USB_OTG_CORE_HANDLE USB_OTG_dev;
extern USB_OTG_CORE_HANDLE USB_OTG_Core;
/* Private function prototypes -----------------------------------------------*/
extern uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev);
......@@ -161,12 +161,12 @@ void PendSV_Handler(void)
#ifdef USE_USB_OTG_FS
void OTG_FS_WKUP_IRQHandler(void)
{
if(USB_OTG_dev.cfg.low_power)
if(USB_OTG_Core.cfg.low_power)
{
*(uint32_t *)(0xE000ED10) &= 0xFFFFFFF9 ;
SystemInit();
#ifdef USE_DEVICE_MODE
USB_OTG_UngateClock(&USB_OTG_dev);
USB_OTG_UngateClock(&USB_OTG_Core);
#endif
}
EXTI_ClearITPendingBit(EXTI_Line18);
......@@ -181,11 +181,11 @@ void OTG_FS_WKUP_IRQHandler(void)
#ifdef USE_USB_OTG_HS
void OTG_HS_WKUP_IRQHandler(void)
{
if(USB_OTG_dev.cfg.low_power)
if(USB_OTG_Core.cfg.low_power)
{
*(uint32_t *)(0xE000ED10) &= 0xFFFFFFF9 ;
SystemInit();
USB_OTG_UngateClock(&USB_OTG_dev);
USB_OTG_UngateClock(&USB_OTG_Core);
}
EXTI_ClearITPendingBit(EXTI_Line20);
}
......@@ -202,16 +202,16 @@ void OTG_HS_IRQHandler(void)
void OTG_FS_IRQHandler(void)
#endif
{
if (USB_OTG_IsHostMode(&USB_OTG_dev)) {
if (USB_OTG_IsHostMode(&USB_OTG_Core)) {
// host mode
#ifdef USE_HOST_MODE
USBH_OTG_ISR_Handler(&USB_OTG_dev);
USBH_OTG_ISR_Handler(&USB_OTG_Core);
#endif
//STM32_USBO_OTG_ISR_Handler(&USB_OTG_dev); // USE_OTG_MODE
//STM32_USBO_OTG_ISR_Handler(&USB_OTG_Core); // USE_OTG_MODE
} else {
// device mode
#ifdef USE_DEVICE_MODE
USBD_OTG_ISR_Handler(&USB_OTG_dev);
USBD_OTG_ISR_Handler(&USB_OTG_Core);
#endif
}
}
......@@ -224,7 +224,7 @@ void OTG_FS_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)
*/
void OTG_HS_EP1_OUT_IRQHandler(void)
{
USBD_OTG_EP1OUT_ISR_Handler (&USB_OTG_dev);
USBD_OTG_EP1OUT_ISR_Handler (&USB_OTG_Core);
}
#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