Skip to content

Initial checkin with STM HAL #339

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

Merged
merged 1 commit into from
Mar 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
233 changes: 233 additions & 0 deletions stmhal/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
include ../py/mkenv.mk

# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h

# include py core make definitions
include ../py/py.mk

CMSIS_DIR=cmsis
HAL_DIR=hal
#STMUSB_DIR=stmusb
#STMUSBD_DIR=stmusbd
#STMUSBH_DIR=stmusbh
#FATFS_DIR=fatfs
#CC3K_DIR=cc3k
DFU=../tools/dfu.py

CROSS_COMPILE = arm-none-eabi-

INC = -I.
INC += -I$(PY_SRC)
INC += -I$(CMSIS_DIR)/inc
INC += -I$(CMSIS_DIR)/devinc
INC += -I$(HAL_DIR)/inc
#INC += -I$(STMUSB_DIR)
#INC += -I$(STMUSBD_DIR)
#INC += -I$(STMUSBH_DIR)
#INC += -I$(FATFS_DIR)
#INC += -I$(CC3K_DIR)

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 = $(INC) -Wall -Werror -ansi -std=gnu99 $(CFLAGS_CORTEX_M4) $(COPT)

BOARD = STM32F4DISC
BOARD ?= PYBOARD4
ifeq ($(wildcard boards/$(BOARD)/.),)
$(error Invalid BOARD specified)
endif
CFLAGS += -Iboards/$(BOARD)

#Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -g -DPENDSV_DEBUG
COPT = -O0
else
COPT += -Os -DNDEBUG
endif

LDFLAGS = --nostdlib -T stm32f405.ld -Map=$(@:.elf=.map) --cref
LIBS =

# uncomment this if you want libgcc
#LIBS += $(shell $(CC) -print-libgcc-file-name)

SRC_C = \
main.c \
system_stm32f4xx.c \

# printf.c \
# math.c \
# stm32fxxx_it.c \
# string0.c \
# malloc0.c \
# systick.c \
# pendsv.c \
# gccollect.c \
# lexerfatfs.c \
# import.c \
# pyexec.c \
# led.c \
# gpio.c \
# lcd.c \
# servo.c \
# flash.c \
# storage.c \
# accel.c \
# usart.c \
# usb.c \
# timer.c \
# audio.c \
# sdcard.c \
# i2c.c \
# adc.c \
# rtc.c \
# file.c \
# pin.c \
# pin_named_pins.c \
# pin_map.c \
# exti.c \
# usrsw.c \
# pybmodule.c \
# pybwlan.c \

SRC_S = \
startup_stm32f40xx.s \

# gchelper.s \

SRC_HAL = $(addprefix $(HAL_DIR)/src/,\
stm32f4xx_hal.c \
stm32f4xx_hal_cortex.c \
)

SRC_STMPERIPH = $(addprefix $(STMPERIPH_DIR)/,\
stm_misc.c \
stm32f4xx_rcc.c \
stm32f4xx_syscfg.c \
stm32f4xx_flash.c \
stm32f4xx_dma.c \
stm32f4xx_gpio.c \
stm32f4xx_exti.c \
stm32f4xx_tim.c \
stm32f4xx_sdio.c \
stm32f4xx_pwr.c \
stm32f4xx_rtc.c \
stm32f4xx_usart.c \
stm32f4xx_spi.c \
stm32f4xx_dac.c \
stm32f4xx_rng.c \
stm32f4xx_i2c.c \
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 \
usbd_usr.c \
usbd_desc.c \
usbd_pyb_core.c \
usbd_pyb_core2.c \
usbd_cdc_vcp.c \
usbd_msc_bot.c \
usbd_msc_data.c \
usbd_msc_scsi.c \
usbd_storage_msd.c \
)

SRC_STMUSBH = $(addprefix $(STMUSBH_DIR)/,\
usbh_core.c \
usbh_hcs.c \
usbh_stdreq.c \
usbh_ioreq.c \
usbh_usr.c \
usbh_hid_core.c \
usbh_hid_mouse.c \
usbh_hid_keybd.c \
)

SRC_FATFS = $(addprefix $(FATFS_DIR)/,\
ff.c \
diskio.c \
ccsbcs.c \
)

SRC_CC3K = $(addprefix $(CC3K_DIR)/,\
cc3000_common.c \
evnt_handler.c \
hci.c \
netapp.c \
nvmem.c \
security.c \
socket.c \
wlan.c \
ccspi.c \
pybcc3k.c \
)

OBJ =
#OBJ += $(PY_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_HAL:.c=.o))
#OBJ += $(addprefix $(BUILD)/, $(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))
#OBJ += $(BUILD)/pins_$(BOARD).o

all: $(BUILD)/flash.dfu

$(BUILD)/flash.dfu: $(BUILD)/flash0.bin $(BUILD)/flash1.bin
$(ECHO) "Create $@"
$(Q)python $(DFU) -b 0x08000000:$(BUILD)/flash0.bin -b 0x08020000:$(BUILD)/flash1.bin $@

$(BUILD)/flash0.bin: $(BUILD)/flash.elf
$(Q)$(OBJCOPY) -O binary -j .isr_vector $^ $@

$(BUILD)/flash1.bin: $(BUILD)/flash.elf
$(Q)$(OBJCOPY) -O binary -j .text -j .data $^ $@

$(BUILD)/flash.elf: $(OBJ)
$(ECHO) "LINK $@"
$(Q)$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
$(Q)$(SIZE) $@

MAKE_PINS = boards/make-pins.py
BOARD_PINS = boards/$(BOARD)/pins.csv
AF_FILE = boards/stm32f4xx-af.csv
PREFIX_FILE = boards/stm32f4xx-prefix.c
GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c
GEN_PINS_HDR = $(BUILD)/pins.h

# Making OBJ use an order-only depenedency on the generated pins.h file
# has the side effect of making the pins.h file before we actually compile
# any of the objects. The normal dependency generation will deal with the
# case when pins.h is modified. But when it doesn't exist, we don't know
# which source files might need it.
#$(OBJ): | $(BUILD)/pins.h

# Use a pattern rule here so that make will only call make-pins.py once to make
# both pins_$(BOARD).c and pins.h
$(BUILD)/%_$(BOARD).c $(BUILD)/%.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE)
$(ECHO) "Create $@"
$(Q)python $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) > $(GEN_PINS_SRC)

$(BUILD)/pins_$(BOARD).o: $(BUILD)/pins_$(BOARD).c
$(call compile_c)

include ../py/mkrules.mk
38 changes: 38 additions & 0 deletions stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#define 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)

// USRSW is pulled low. Pressing the button makes the input go high.
#define USRSW_PIN (pin_B11)
#define USRSW_PUPD (GPIO_PuPd_NOPULL)
#define USRSW_EXTI_EDGE (EXTI_Trigger_Rising)
#define USRSW_PRESSED (1)

/* LED */
#define PYB_LED1 (pin_A10) // Blue LED
#define PYB_LED2 (pin_C13) // White LED (aka Power)
#define PYB_LED3 (pin_A10) // Same as Led(1)
#define PYB_LED4 (pin_C13) // Same as Led(2)

#define PYB_OTYPE (GPIO_OType_PP)

#define PYB_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
#define PYB_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)

#define HSE_VALUE (25000000)
28 changes: 28 additions & 0 deletions stmhal/boards/NETDUINO_PLUS_2/pins.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
D0,PC7
D1,PC6
D2,PA3
D3,PA2
D4,PB12
D5,PB8
D6,PB9
D7,PA1
D8,PA0
D9,PA6
D10,PB10
D11,PB15
D12,PB14
D13,PB13
A0,PC0
A1,PC1
A2,PC2
A3,PC3
A4,PC4
A5,PC5
LED,PA10
SW,PB11
PWR_LED,PC13
PWR_SD,PB1
PWR_HDR,PB2
PWR_ETH,PC15
RST_ETH,PD2

32 changes: 32 additions & 0 deletions stmhal/boards/PYBOARD3/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#define PYBOARD3

#define MICROPY_HW_BOARD_NAME "PYBv3"

#define MICROPY_HW_HAS_SWITCH (1)
#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_WLAN (0)
#define MICROPY_HW_ENABLE_RNG (1)
#define MICROPY_HW_ENABLE_RTC (1)
#define MICROPY_HW_ENABLE_TIMER (1)
#define MICROPY_HW_ENABLE_SERVO (1)
#define MICROPY_HW_ENABLE_AUDIO (0)

// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
#define USRSW_PIN (pin_A13)
#define USRSW_PUPD (GPIO_PuPd_UP)
#define USRSW_EXTI_EDGE (EXTI_Trigger_Falling)
#define USRSW_PRESSED (0)

/* LED */
#define PYB_LED1 (pin_A8) // R1 - red
#define PYB_LED2 (pin_A10) // R2 - red
#define PYB_LED3 (pin_C4) // G1 - green
#define PYB_LED4 (pin_C5) // G2 - green

#define PYB_OTYPE (GPIO_OType_PP)

#define PYB_LED_ON(pin) (pin->gpio->BSRRH = pin->pin_mask)
#define PYB_LED_OFF(pin) (pin->gpio->BSRRL = pin->pin_mask)
37 changes: 37 additions & 0 deletions stmhal/boards/PYBOARD3/pins.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
B13,PB13
B14,PB14
B15,PB15
C6,PC6
C7,PC7
A13,PA13
A14,PA14
A15,PA15
B3,PB3
B4,PB4
B6,PB6
B7,PB7
B8,PB8
B9,PB9
C0,PC0
C1,PC1
C2,PC2
C3,PC3
A0,PA0
A1,PA1
A2,PA2
A3,PA3
A4,PA4
A5,PA5
A6,PA6
A7,PA7
B0,PB0
B1,PB1
B10,PB10
B11,PB11
B12,PB12
LED_R1,PA8
LED_R2,PA10
LED_G1,PC4
LED_G2,PC5
SW,PA13

Loading