Skip to content

Commit e072349

Browse files
committed
Merge pull request adafruit#259 from dhylands/netduino
Initial support for Netduino
2 parents e5a15cb + 1570a96 commit e072349

7 files changed

Lines changed: 114 additions & 11 deletions

File tree

stm/lcd.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include "nlr.h"
55
#include "misc.h"
66
#include "mpconfig.h"
7+
8+
#if MICROPY_HW_HAS_LCD
9+
710
#include "qstr.h"
811
#include "parse.h"
912
#include "obj.h"
@@ -378,3 +381,5 @@ void lcd_print_strn(const char *str, unsigned int len) {
378381
sys_tick_delay_ms(50);
379382
}
380383
}
384+
385+
#endif // MICROPY_HW_HAS_LCD

stm/main.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,27 @@ int main(void) {
602602
GPIO_Init(GPIOD, &GPIO_InitStructure);
603603
}
604604
#endif
605+
#if defined(NETDUINO_PLUS_2)
606+
{
607+
GPIO_InitTypeDef GPIO_InitStructure;
608+
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
609+
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
610+
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
611+
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
612+
613+
#if MICROPY_HW_HAS_SDCARD
614+
// Turn on the power enable for the sdcard (PB1)
615+
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
616+
GPIO_Init(GPIOB, &GPIO_InitStructure);
617+
GPIO_WriteBit(GPIOB, GPIO_Pin_1, Bit_SET);
618+
#endif
619+
620+
// Turn on the power for the 5V on the expansion header (PB2)
621+
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
622+
GPIO_Init(GPIOB, &GPIO_InitStructure);
623+
GPIO_WriteBit(GPIOB, GPIO_Pin_2, Bit_SET);
624+
}
625+
#endif
605626

606627
// basic sub-system init
607628
sys_tick_init();

stm/mpconfigport.h

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ machine_float_t machine_sqrt(machine_float_t x);
2626
//#define PYBOARD3
2727
#define PYBOARD4
2828
//#define STM32F4DISC
29+
//#define NETDUINO_PLUS_2
2930

3031
#if defined (PYBOARD3)
3132
#define MICROPY_HW_BOARD_NAME "PYBv3"
@@ -90,7 +91,7 @@ machine_float_t machine_sqrt(machine_float_t x);
9091
#define USRSW_EXTI_PIN (EXTI_PinSource3)
9192
#define USRSW_EXTI_PORT (EXTI_PortSourceGPIOB)
9293
#define USRSW_EXTI_LINE (EXTI_Line3)
93-
#define USRSW_EXTI_IRQN (EXTI15_10_IRQn)
94+
#define USRSW_EXTI_IRQN (EXTI3_IRQn)
9495
#define USRSW_EXTI_EDGE (EXTI_Trigger_Rising)
9596

9697
/* LED */
@@ -153,10 +154,59 @@ machine_float_t machine_sqrt(machine_float_t x);
153154
#define PYB_LED_ON(port, pin) (port->BSRRL = pin)
154155
#define PYB_LED_OFF(port, pin) (port->BSRRH = pin)
155156

157+
#elif defined (NETDUINO_PLUS_2)
158+
#define MICROPY_HW_BOARD_NAME "NetduinoPlus2"
159+
160+
#define MICROPY_HW_HAS_SWITCH (1)
161+
162+
// On the netuino, the sdcard appears to be wired up as a 1-bit
163+
// SPI, so the driver needs to be converted to support that before
164+
// we can turn this on.
165+
#define MICROPY_HW_HAS_SDCARD (0)
166+
#define MICROPY_HW_HAS_MMA7660 (0)
167+
#define MICROPY_HW_HAS_LIS3DSH (0)
168+
#define MICROPY_HW_HAS_LCD (0)
169+
#define MICROPY_HW_HAS_WLAN (0)
170+
#define MICROPY_HW_ENABLE_RNG (1)
171+
#define MICROPY_HW_ENABLE_RTC (0)
172+
#define MICROPY_HW_ENABLE_TIMER (1)
173+
#define MICROPY_HW_ENABLE_SERVO (1)
174+
#define MICROPY_HW_ENABLE_AUDIO (0)
175+
176+
#define USRSW_PORT (GPIOB)
177+
#define USRSW_PIN (GPIO_Pin_11)
178+
#define USRSW_PUPD (GPIO_PuPd_NOPULL)
179+
#define USRSW_EXTI_PIN (EXTI_PinSource11)
180+
#define USRSW_EXTI_PORT (EXTI_PortSourceGPIOB)
181+
#define USRSW_EXTI_LINE (EXTI_Line11)
182+
#define USRSW_EXTI_IRQN (EXTI15_10_IRQn)
183+
#define USRSW_EXTI_EDGE (EXTI_Trigger_Rising)
184+
185+
/* LED */
186+
#define PYB_LED1_PORT (GPIOA) // Blue LED
187+
#define PYB_LED1_PIN (GPIO_Pin_10)
188+
189+
#define PYB_LED2_PORT (GPIOC) // White LED (aka Power)
190+
#define PYB_LED2_PIN (GPIO_Pin_13)
191+
192+
#define PYB_LED3_PORT (GPIOA) // Same as Led(1)
193+
#define PYB_LED3_PIN (GPIO_Pin_10)
194+
195+
#define PYB_LED4_PORT (GPIOC) // Same as Led(2)
196+
#define PYB_LED4_PIN (GPIO_Pin_13)
197+
198+
#define PYB_OTYPE (GPIO_OType_PP)
199+
200+
#define PYB_LED_ON(port, pin) (port->BSRRL = pin)
201+
#define PYB_LED_OFF(port, pin) (port->BSRRH = pin)
202+
203+
#define HSE_VALUE (25000000)
156204
#endif
157205

158206
#define STM32F40_41xxx
159207
#define USE_STDPERIPH_DRIVER
208+
#if !defined(HSE_VALUE)
160209
#define HSE_VALUE (8000000)
210+
#endif
161211
#define USE_DEVICE_MODE
162212
//#define USE_HOST_MODE

stm/stm32fxxx_it.c

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,21 @@ void TIM6_DAC_IRQHandler(void) {
290290
#include "qstr.h"
291291
#include "obj.h"
292292
#include "led.h"
293+
294+
void Default_Handler(void); // Found in startup_stm32f40xx.s
295+
293296
// EXTI
294-
// for USRSW on A13
297+
// for USRSW on A13 for PYBOARD3, and B11 for NETDUINO_PLUS_2
295298
// for cc3000 on A14
296299
void EXTI15_10_IRQHandler(void) {
297-
// work out if it's A13 that had the interrupt
298-
if (EXTI_GetITStatus(EXTI_Line13) != RESET) {
299-
// this is used just to wake the device
300-
EXTI_ClearITPendingBit(EXTI_Line13);
300+
// work out if it's the user switch that had the interrupt
301+
// Note that if the user switch is on a diffetent IRQ, then this code
302+
// should be optimized out.
303+
if (USRSW_EXTI_IRQN == EXTI15_10_IRQn) {
304+
if (EXTI_GetITStatus(USRSW_EXTI_LINE) != RESET) {
305+
// this is used just to wake the device
306+
EXTI_ClearITPendingBit(USRSW_EXTI_LINE);
307+
}
301308
}
302309
// work out if it's A14 that had the interrupt
303310
if (EXTI_GetITStatus(EXTI_Line14) != RESET) {
@@ -319,10 +326,24 @@ void EXTI15_10_IRQHandler(void) {
319326
}
320327
}
321328

322-
#if defined(STM32F4DISC)
329+
// STM32F4DISC is setup for A0
323330
void EXTI0_IRQHandler(void) {
324-
// clear pending interrupt bit
325-
EXTI_ClearITPendingBit(EXTI_Line0);
331+
if (USRSW_EXTI_IRQN == EXTI0_IRQn) {
332+
// this is used just to wake the device
333+
EXTI_ClearITPendingBit(USRSW_EXTI_LINE);
334+
} else {
335+
Default_Handler();
336+
}
326337
}
327-
#endif
338+
339+
// PYBOARD4 has button on PB3
340+
void EXTI3_IRQHandler(void) {
341+
if (USRSW_EXTI_IRQN == EXTI3_IRQn) {
342+
// this is used just to wake the device
343+
EXTI_ClearITPendingBit(USRSW_EXTI_LINE);
344+
} else {
345+
Default_Handler();
346+
}
347+
}
348+
328349
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

stm/stmperiph/stm324x7i_eval.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
#define SD_DETECT_PIN GPIO_Pin_15 /* PB.15 */
5555
#define SD_DETECT_GPIO_PORT GPIOB /* GPIOB */
5656
#define SD_DETECT_GPIO_CLK RCC_AHB1Periph_GPIOB
57+
#elif defined(NETDUINO_PLUS_2)
58+
#define SD_DETECT_PIN GPIO_Pin_5 /* PB.5 */
59+
#define SD_DETECT_GPIO_PORT GPIOB /* GPIOB */
60+
#define SD_DETECT_GPIO_CLK RCC_AHB1Periph_GPIOB
5761
#endif
5862

5963
#define SDIO_FIFO_ADDRESS ((uint32_t)0x40012C80)

stm/stmusb/usb_bsp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev) {
117117
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
118118
GPIO_Init(GPIOA, &GPIO_InitStructure);
119119

120+
#if !defined(NETDUINO_PLUS_2)
120121
// Configure ID pin on PA10
121122
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
122123
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
@@ -125,6 +126,7 @@ void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev) {
125126
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
126127
GPIO_Init(GPIOA, &GPIO_InitStructure);
127128
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_OTG_FS);
129+
#endif
128130

129131
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
130132
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE);

stm/usrsw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int switch_get(void) {
5252
// pulled low, so switch is pressed
5353
return 1;
5454
}
55-
#elif defined (STM32F4DISC)
55+
#elif defined (STM32F4DISC) || defined(NETDUINO_PLUS_2)
5656
/* switch pulled down */
5757
if (USRSW_PORT->IDR & USRSW_PIN) {
5858
// pulled high, so switch is pressed

0 commit comments

Comments
 (0)