Skip to content

Commit dd38d90

Browse files
committed
Initial checkin with STM HAL
This compiles and links, but hasn't been tested on a board yet and even if it was run, it doesn't currently do anything.
1 parent 8bfec2b commit dd38d90

File tree

368 files changed

+269214
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

368 files changed

+269214
-0
lines changed

stmhal/Makefile

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
include ../py/mkenv.mk
2+
3+
# qstr definitions (must come before including py.mk)
4+
QSTR_DEFS = qstrdefsport.h
5+
6+
# include py core make definitions
7+
include ../py/py.mk
8+
9+
CMSIS_DIR=cmsis
10+
HAL_DIR=hal
11+
#STMUSB_DIR=stmusb
12+
#STMUSBD_DIR=stmusbd
13+
#STMUSBH_DIR=stmusbh
14+
#FATFS_DIR=fatfs
15+
#CC3K_DIR=cc3k
16+
DFU=../tools/dfu.py
17+
18+
CROSS_COMPILE = arm-none-eabi-
19+
20+
INC = -I.
21+
INC += -I$(PY_SRC)
22+
INC += -I$(CMSIS_DIR)/inc
23+
INC += -I$(CMSIS_DIR)/devinc
24+
INC += -I$(HAL_DIR)/inc
25+
#INC += -I$(STMUSB_DIR)
26+
#INC += -I$(STMUSBD_DIR)
27+
#INC += -I$(STMUSBH_DIR)
28+
#INC += -I$(FATFS_DIR)
29+
#INC += -I$(CC3K_DIR)
30+
31+
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
32+
CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 $(CFLAGS_CORTEX_M4) $(COPT)
33+
34+
BOARD = STM32F4DISC
35+
BOARD ?= PYBOARD4
36+
ifeq ($(wildcard boards/$(BOARD)/.),)
37+
$(error Invalid BOARD specified)
38+
endif
39+
CFLAGS += -Iboards/$(BOARD)
40+
41+
#Debugging/Optimization
42+
ifeq ($(DEBUG), 1)
43+
CFLAGS += -g -DPENDSV_DEBUG
44+
COPT = -O0
45+
else
46+
COPT += -Os -DNDEBUG
47+
endif
48+
49+
LDFLAGS = --nostdlib -T stm32f405.ld -Map=$(@:.elf=.map) --cref
50+
LIBS =
51+
52+
# uncomment this if you want libgcc
53+
#LIBS += $(shell $(CC) -print-libgcc-file-name)
54+
55+
SRC_C = \
56+
main.c \
57+
system_stm32f4xx.c \
58+
59+
# printf.c \
60+
# math.c \
61+
# stm32fxxx_it.c \
62+
# string0.c \
63+
# malloc0.c \
64+
# systick.c \
65+
# pendsv.c \
66+
# gccollect.c \
67+
# lexerfatfs.c \
68+
# import.c \
69+
# pyexec.c \
70+
# led.c \
71+
# gpio.c \
72+
# lcd.c \
73+
# servo.c \
74+
# flash.c \
75+
# storage.c \
76+
# accel.c \
77+
# usart.c \
78+
# usb.c \
79+
# timer.c \
80+
# audio.c \
81+
# sdcard.c \
82+
# i2c.c \
83+
# adc.c \
84+
# rtc.c \
85+
# file.c \
86+
# pin.c \
87+
# pin_named_pins.c \
88+
# pin_map.c \
89+
# exti.c \
90+
# usrsw.c \
91+
# pybmodule.c \
92+
# pybwlan.c \
93+
94+
SRC_S = \
95+
startup_stm32f40xx.s \
96+
97+
# gchelper.s \
98+
99+
SRC_HAL = $(addprefix $(HAL_DIR)/src/,\
100+
stm32f4xx_hal.c \
101+
stm32f4xx_hal_cortex.c \
102+
)
103+
104+
SRC_STMPERIPH = $(addprefix $(STMPERIPH_DIR)/,\
105+
stm_misc.c \
106+
stm32f4xx_rcc.c \
107+
stm32f4xx_syscfg.c \
108+
stm32f4xx_flash.c \
109+
stm32f4xx_dma.c \
110+
stm32f4xx_gpio.c \
111+
stm32f4xx_exti.c \
112+
stm32f4xx_tim.c \
113+
stm32f4xx_sdio.c \
114+
stm32f4xx_pwr.c \
115+
stm32f4xx_rtc.c \
116+
stm32f4xx_usart.c \
117+
stm32f4xx_spi.c \
118+
stm32f4xx_dac.c \
119+
stm32f4xx_rng.c \
120+
stm32f4xx_i2c.c \
121+
stm32f4xx_adc.c \
122+
stm324x7i_eval.c \
123+
stm324x7i_eval_sdio_sd.c \
124+
)
125+
126+
SRC_STMUSB = $(addprefix $(STMUSB_DIR)/,\
127+
usb_core.c \
128+
usb_bsp.c \
129+
usb_dcd.c \
130+
usb_dcd_int.c \
131+
usb_hcd.c \
132+
usb_hcd_int.c \
133+
)
134+
# usb_otg.c \
135+
136+
SRC_STMUSBD = $(addprefix $(STMUSBD_DIR)/,\
137+
usbd_core.c \
138+
usbd_ioreq.c \
139+
usbd_req.c \
140+
usbd_usr.c \
141+
usbd_desc.c \
142+
usbd_pyb_core.c \
143+
usbd_pyb_core2.c \
144+
usbd_cdc_vcp.c \
145+
usbd_msc_bot.c \
146+
usbd_msc_data.c \
147+
usbd_msc_scsi.c \
148+
usbd_storage_msd.c \
149+
)
150+
151+
SRC_STMUSBH = $(addprefix $(STMUSBH_DIR)/,\
152+
usbh_core.c \
153+
usbh_hcs.c \
154+
usbh_stdreq.c \
155+
usbh_ioreq.c \
156+
usbh_usr.c \
157+
usbh_hid_core.c \
158+
usbh_hid_mouse.c \
159+
usbh_hid_keybd.c \
160+
)
161+
162+
SRC_FATFS = $(addprefix $(FATFS_DIR)/,\
163+
ff.c \
164+
diskio.c \
165+
ccsbcs.c \
166+
)
167+
168+
SRC_CC3K = $(addprefix $(CC3K_DIR)/,\
169+
cc3000_common.c \
170+
evnt_handler.c \
171+
hci.c \
172+
netapp.c \
173+
nvmem.c \
174+
security.c \
175+
socket.c \
176+
wlan.c \
177+
ccspi.c \
178+
pybcc3k.c \
179+
)
180+
181+
OBJ =
182+
#OBJ += $(PY_O)
183+
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
184+
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
185+
OBJ += $(addprefix $(BUILD)/, $(SRC_HAL:.c=.o))
186+
#OBJ += $(addprefix $(BUILD)/, $(SRC_STMUSB:.c=.o))
187+
#OBJ += $(addprefix $(BUILD)/, $(SRC_STMUSBD:.c=.o))
188+
#OBJ += $(addprefix $(BUILD)/, $(SRC_STMUSBH:.c=.o))
189+
#OBJ += $(addprefix $(BUILD)/, $(SRC_FATFS:.c=.o))
190+
#OBJ += $(addprefix $(BUILD)/, $(SRC_CC3K:.c=.o))
191+
#OBJ += $(BUILD)/pins_$(BOARD).o
192+
193+
all: $(BUILD)/flash.dfu
194+
195+
$(BUILD)/flash.dfu: $(BUILD)/flash0.bin $(BUILD)/flash1.bin
196+
$(ECHO) "Create $@"
197+
$(Q)python $(DFU) -b 0x08000000:$(BUILD)/flash0.bin -b 0x08020000:$(BUILD)/flash1.bin $@
198+
199+
$(BUILD)/flash0.bin: $(BUILD)/flash.elf
200+
$(Q)$(OBJCOPY) -O binary -j .isr_vector $^ $@
201+
202+
$(BUILD)/flash1.bin: $(BUILD)/flash.elf
203+
$(Q)$(OBJCOPY) -O binary -j .text -j .data $^ $@
204+
205+
$(BUILD)/flash.elf: $(OBJ)
206+
$(ECHO) "LINK $@"
207+
$(Q)$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
208+
$(Q)$(SIZE) $@
209+
210+
MAKE_PINS = boards/make-pins.py
211+
BOARD_PINS = boards/$(BOARD)/pins.csv
212+
AF_FILE = boards/stm32f4xx-af.csv
213+
PREFIX_FILE = boards/stm32f4xx-prefix.c
214+
GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c
215+
GEN_PINS_HDR = $(BUILD)/pins.h
216+
217+
# Making OBJ use an order-only depenedency on the generated pins.h file
218+
# has the side effect of making the pins.h file before we actually compile
219+
# any of the objects. The normal dependency generation will deal with the
220+
# case when pins.h is modified. But when it doesn't exist, we don't know
221+
# which source files might need it.
222+
#$(OBJ): | $(BUILD)/pins.h
223+
224+
# Use a pattern rule here so that make will only call make-pins.py once to make
225+
# both pins_$(BOARD).c and pins.h
226+
$(BUILD)/%_$(BOARD).c $(BUILD)/%.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE)
227+
$(ECHO) "Create $@"
228+
$(Q)python $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) > $(GEN_PINS_SRC)
229+
230+
$(BUILD)/pins_$(BOARD).o: $(BUILD)/pins_$(BOARD).c
231+
$(call compile_c)
232+
233+
include ../py/mkrules.mk
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#define NETDUINO_PLUS_2
2+
3+
#define MICROPY_HW_BOARD_NAME "NetduinoPlus2"
4+
5+
#define MICROPY_HW_HAS_SWITCH (1)
6+
7+
// On the netuino, the sdcard appears to be wired up as a 1-bit
8+
// SPI, so the driver needs to be converted to support that before
9+
// we can turn this on.
10+
#define MICROPY_HW_HAS_SDCARD (0)
11+
#define MICROPY_HW_HAS_MMA7660 (0)
12+
#define MICROPY_HW_HAS_LIS3DSH (0)
13+
#define MICROPY_HW_HAS_LCD (0)
14+
#define MICROPY_HW_HAS_WLAN (0)
15+
#define MICROPY_HW_ENABLE_RNG (1)
16+
#define MICROPY_HW_ENABLE_RTC (0)
17+
#define MICROPY_HW_ENABLE_TIMER (1)
18+
#define MICROPY_HW_ENABLE_SERVO (1)
19+
#define MICROPY_HW_ENABLE_AUDIO (0)
20+
21+
// USRSW is pulled low. Pressing the button makes the input go high.
22+
#define USRSW_PIN (pin_B11)
23+
#define USRSW_PUPD (GPIO_PuPd_NOPULL)
24+
#define USRSW_EXTI_EDGE (EXTI_Trigger_Rising)
25+
#define USRSW_PRESSED (1)
26+
27+
/* LED */
28+
#define PYB_LED1 (pin_A10) // Blue LED
29+
#define PYB_LED2 (pin_C13) // White LED (aka Power)
30+
#define PYB_LED3 (pin_A10) // Same as Led(1)
31+
#define PYB_LED4 (pin_C13) // Same as Led(2)
32+
33+
#define PYB_OTYPE (GPIO_OType_PP)
34+
35+
#define PYB_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
36+
#define PYB_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
37+
38+
#define HSE_VALUE (25000000)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
D0,PC7
2+
D1,PC6
3+
D2,PA3
4+
D3,PA2
5+
D4,PB12
6+
D5,PB8
7+
D6,PB9
8+
D7,PA1
9+
D8,PA0
10+
D9,PA6
11+
D10,PB10
12+
D11,PB15
13+
D12,PB14
14+
D13,PB13
15+
A0,PC0
16+
A1,PC1
17+
A2,PC2
18+
A3,PC3
19+
A4,PC4
20+
A5,PC5
21+
LED,PA10
22+
SW,PB11
23+
PWR_LED,PC13
24+
PWR_SD,PB1
25+
PWR_HDR,PB2
26+
PWR_ETH,PC15
27+
RST_ETH,PD2
28+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#define PYBOARD3
2+
3+
#define MICROPY_HW_BOARD_NAME "PYBv3"
4+
5+
#define MICROPY_HW_HAS_SWITCH (1)
6+
#define MICROPY_HW_HAS_SDCARD (1)
7+
#define MICROPY_HW_HAS_MMA7660 (1)
8+
#define MICROPY_HW_HAS_LIS3DSH (0)
9+
#define MICROPY_HW_HAS_LCD (0)
10+
#define MICROPY_HW_HAS_WLAN (0)
11+
#define MICROPY_HW_ENABLE_RNG (1)
12+
#define MICROPY_HW_ENABLE_RTC (1)
13+
#define MICROPY_HW_ENABLE_TIMER (1)
14+
#define MICROPY_HW_ENABLE_SERVO (1)
15+
#define MICROPY_HW_ENABLE_AUDIO (0)
16+
17+
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
18+
#define USRSW_PIN (pin_A13)
19+
#define USRSW_PUPD (GPIO_PuPd_UP)
20+
#define USRSW_EXTI_EDGE (EXTI_Trigger_Falling)
21+
#define USRSW_PRESSED (0)
22+
23+
/* LED */
24+
#define PYB_LED1 (pin_A8) // R1 - red
25+
#define PYB_LED2 (pin_A10) // R2 - red
26+
#define PYB_LED3 (pin_C4) // G1 - green
27+
#define PYB_LED4 (pin_C5) // G2 - green
28+
29+
#define PYB_OTYPE (GPIO_OType_PP)
30+
31+
#define PYB_LED_ON(pin) (pin->gpio->BSRRH = pin->pin_mask)
32+
#define PYB_LED_OFF(pin) (pin->gpio->BSRRL = pin->pin_mask)

stmhal/boards/PYBOARD3/pins.csv

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
B13,PB13
2+
B14,PB14
3+
B15,PB15
4+
C6,PC6
5+
C7,PC7
6+
A13,PA13
7+
A14,PA14
8+
A15,PA15
9+
B3,PB3
10+
B4,PB4
11+
B6,PB6
12+
B7,PB7
13+
B8,PB8
14+
B9,PB9
15+
C0,PC0
16+
C1,PC1
17+
C2,PC2
18+
C3,PC3
19+
A0,PA0
20+
A1,PA1
21+
A2,PA2
22+
A3,PA3
23+
A4,PA4
24+
A5,PA5
25+
A6,PA6
26+
A7,PA7
27+
B0,PB0
28+
B1,PB1
29+
B10,PB10
30+
B11,PB11
31+
B12,PB12
32+
LED_R1,PA8
33+
LED_R2,PA10
34+
LED_G1,PC4
35+
LED_G2,PC5
36+
SW,PA13
37+

0 commit comments

Comments
 (0)