From 1570a96cad0b886f21a07eb13c3377a0f79abc1e Mon Sep 17 00:00:00 2001 From: Dave Hylands Date: Mon, 3 Feb 2014 21:11:48 -0800 Subject: [PATCH] Initial support for Netduino This also fixes up the IRQ for the PYBOARD4 USERSW although I was unable to test that functionality. --- stm/lcd.c | 5 ++++ stm/main.c | 21 ++++++++++++++ stm/mpconfigport.h | 52 +++++++++++++++++++++++++++++++++- stm/stm32fxxx_it.c | 39 +++++++++++++++++++------ stm/stmperiph/stm324x7i_eval.h | 4 +++ stm/stmusb/usb_bsp.c | 2 ++ stm/usrsw.c | 2 +- 7 files changed, 114 insertions(+), 11 deletions(-) diff --git a/stm/lcd.c b/stm/lcd.c index 6f5019db1b..01ef1c154b 100644 --- a/stm/lcd.c +++ b/stm/lcd.c @@ -4,6 +4,9 @@ #include "nlr.h" #include "misc.h" #include "mpconfig.h" + +#if MICROPY_HW_HAS_LCD + #include "qstr.h" #include "parse.h" #include "obj.h" @@ -378,3 +381,5 @@ void lcd_print_strn(const char *str, unsigned int len) { sys_tick_delay_ms(50); } } + +#endif // MICROPY_HW_HAS_LCD diff --git a/stm/main.c b/stm/main.c index b7d201cf02..5e2a3966d2 100644 --- a/stm/main.c +++ b/stm/main.c @@ -602,6 +602,27 @@ int main(void) { GPIO_Init(GPIOD, &GPIO_InitStructure); } #endif +#if defined(NETDUINO_PLUS_2) + { + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; + +#if MICROPY_HW_HAS_SDCARD + // Turn on the power enable for the sdcard (PB1) + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; + GPIO_Init(GPIOB, &GPIO_InitStructure); + GPIO_WriteBit(GPIOB, GPIO_Pin_1, Bit_SET); +#endif + + // Turn on the power for the 5V on the expansion header (PB2) + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; + GPIO_Init(GPIOB, &GPIO_InitStructure); + GPIO_WriteBit(GPIOB, GPIO_Pin_2, Bit_SET); + } +#endif // basic sub-system init sys_tick_init(); diff --git a/stm/mpconfigport.h b/stm/mpconfigport.h index adf72a4d43..d6a7f697b2 100644 --- a/stm/mpconfigport.h +++ b/stm/mpconfigport.h @@ -26,6 +26,7 @@ machine_float_t machine_sqrt(machine_float_t x); //#define PYBOARD3 #define PYBOARD4 //#define STM32F4DISC +//#define NETDUINO_PLUS_2 #if defined (PYBOARD3) #define MICROPY_HW_BOARD_NAME "PYBv3" @@ -90,7 +91,7 @@ machine_float_t machine_sqrt(machine_float_t x); #define USRSW_EXTI_PIN (EXTI_PinSource3) #define USRSW_EXTI_PORT (EXTI_PortSourceGPIOB) #define USRSW_EXTI_LINE (EXTI_Line3) - #define USRSW_EXTI_IRQN (EXTI15_10_IRQn) + #define USRSW_EXTI_IRQN (EXTI3_IRQn) #define USRSW_EXTI_EDGE (EXTI_Trigger_Rising) /* LED */ @@ -153,10 +154,59 @@ machine_float_t machine_sqrt(machine_float_t x); #define PYB_LED_ON(port, pin) (port->BSRRL = pin) #define PYB_LED_OFF(port, pin) (port->BSRRH = pin) +#elif defined (NETDUINO_PLUS_2) + #define MICROPY_HW_BOARD_NAME "NetduinoPlus2" + + #define MICROPY_HW_HAS_SWITCH (1) + + // On the netuino, the sdcard appears to be wired up as a 1-bit + // SPI, so the driver needs to be converted to support that before + // we can turn this on. + #define MICROPY_HW_HAS_SDCARD (0) + #define MICROPY_HW_HAS_MMA7660 (0) + #define MICROPY_HW_HAS_LIS3DSH (0) + #define MICROPY_HW_HAS_LCD (0) + #define MICROPY_HW_HAS_WLAN (0) + #define MICROPY_HW_ENABLE_RNG (1) + #define MICROPY_HW_ENABLE_RTC (0) + #define MICROPY_HW_ENABLE_TIMER (1) + #define MICROPY_HW_ENABLE_SERVO (1) + #define MICROPY_HW_ENABLE_AUDIO (0) + + #define USRSW_PORT (GPIOB) + #define USRSW_PIN (GPIO_Pin_11) + #define USRSW_PUPD (GPIO_PuPd_NOPULL) + #define USRSW_EXTI_PIN (EXTI_PinSource11) + #define USRSW_EXTI_PORT (EXTI_PortSourceGPIOB) + #define USRSW_EXTI_LINE (EXTI_Line11) + #define USRSW_EXTI_IRQN (EXTI15_10_IRQn) + #define USRSW_EXTI_EDGE (EXTI_Trigger_Rising) + + /* LED */ + #define PYB_LED1_PORT (GPIOA) // Blue LED + #define PYB_LED1_PIN (GPIO_Pin_10) + + #define PYB_LED2_PORT (GPIOC) // White LED (aka Power) + #define PYB_LED2_PIN (GPIO_Pin_13) + + #define PYB_LED3_PORT (GPIOA) // Same as Led(1) + #define PYB_LED3_PIN (GPIO_Pin_10) + + #define PYB_LED4_PORT (GPIOC) // Same as Led(2) + #define PYB_LED4_PIN (GPIO_Pin_13) + + #define PYB_OTYPE (GPIO_OType_PP) + + #define PYB_LED_ON(port, pin) (port->BSRRL = pin) + #define PYB_LED_OFF(port, pin) (port->BSRRH = pin) + + #define HSE_VALUE (25000000) #endif #define STM32F40_41xxx #define USE_STDPERIPH_DRIVER +#if !defined(HSE_VALUE) #define HSE_VALUE (8000000) +#endif #define USE_DEVICE_MODE //#define USE_HOST_MODE diff --git a/stm/stm32fxxx_it.c b/stm/stm32fxxx_it.c index 97cdee6a84..1a6862bbd1 100644 --- a/stm/stm32fxxx_it.c +++ b/stm/stm32fxxx_it.c @@ -290,14 +290,21 @@ void TIM6_DAC_IRQHandler(void) { #include "qstr.h" #include "obj.h" #include "led.h" + +void Default_Handler(void); // Found in startup_stm32f40xx.s + // EXTI -// for USRSW on A13 +// for USRSW on A13 for PYBOARD3, and B11 for NETDUINO_PLUS_2 // for cc3000 on A14 void EXTI15_10_IRQHandler(void) { - // work out if it's A13 that had the interrupt - if (EXTI_GetITStatus(EXTI_Line13) != RESET) { - // this is used just to wake the device - EXTI_ClearITPendingBit(EXTI_Line13); + // work out if it's the user switch that had the interrupt + // Note that if the user switch is on a diffetent IRQ, then this code + // should be optimized out. + if (USRSW_EXTI_IRQN == EXTI15_10_IRQn) { + if (EXTI_GetITStatus(USRSW_EXTI_LINE) != RESET) { + // this is used just to wake the device + EXTI_ClearITPendingBit(USRSW_EXTI_LINE); + } } // work out if it's A14 that had the interrupt if (EXTI_GetITStatus(EXTI_Line14) != RESET) { @@ -319,10 +326,24 @@ void EXTI15_10_IRQHandler(void) { } } -#if defined(STM32F4DISC) +// STM32F4DISC is setup for A0 void EXTI0_IRQHandler(void) { - // clear pending interrupt bit - EXTI_ClearITPendingBit(EXTI_Line0); + if (USRSW_EXTI_IRQN == EXTI0_IRQn) { + // this is used just to wake the device + EXTI_ClearITPendingBit(USRSW_EXTI_LINE); + } else { + Default_Handler(); + } } -#endif + +// PYBOARD4 has button on PB3 +void EXTI3_IRQHandler(void) { + if (USRSW_EXTI_IRQN == EXTI3_IRQn) { + // this is used just to wake the device + EXTI_ClearITPendingBit(USRSW_EXTI_LINE); + } else { + Default_Handler(); + } +} + /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/stm/stmperiph/stm324x7i_eval.h b/stm/stmperiph/stm324x7i_eval.h index 9adeecb16e..1549093b32 100644 --- a/stm/stmperiph/stm324x7i_eval.h +++ b/stm/stmperiph/stm324x7i_eval.h @@ -54,6 +54,10 @@ #define SD_DETECT_PIN GPIO_Pin_15 /* PB.15 */ #define SD_DETECT_GPIO_PORT GPIOB /* GPIOB */ #define SD_DETECT_GPIO_CLK RCC_AHB1Periph_GPIOB +#elif defined(NETDUINO_PLUS_2) +#define SD_DETECT_PIN GPIO_Pin_5 /* PB.5 */ +#define SD_DETECT_GPIO_PORT GPIOB /* GPIOB */ +#define SD_DETECT_GPIO_CLK RCC_AHB1Periph_GPIOB #endif #define SDIO_FIFO_ADDRESS ((uint32_t)0x40012C80) diff --git a/stm/stmusb/usb_bsp.c b/stm/stmusb/usb_bsp.c index cf9d667c69..0cd5146a27 100644 --- a/stm/stmusb/usb_bsp.c +++ b/stm/stmusb/usb_bsp.c @@ -117,6 +117,7 @@ void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev) { GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOA, &GPIO_InitStructure); +#if !defined(NETDUINO_PLUS_2) // Configure ID pin on PA10 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; @@ -125,6 +126,7 @@ void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev) { GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_OTG_FS); +#endif RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE); diff --git a/stm/usrsw.c b/stm/usrsw.c index c3374b847e..528c57e80d 100644 --- a/stm/usrsw.c +++ b/stm/usrsw.c @@ -52,7 +52,7 @@ int switch_get(void) { // pulled low, so switch is pressed return 1; } -#elif defined (STM32F4DISC) +#elif defined (STM32F4DISC) || defined(NETDUINO_PLUS_2) /* switch pulled down */ if (USRSW_PORT->IDR & USRSW_PIN) { // pulled high, so switch is pressed