Skip to content

Commit 4f1b7fe

Browse files
committed
Updated teensy to build.
Refactored some stmhal files which are shared with teensy.
1 parent 2547928 commit 4f1b7fe

41 files changed

Lines changed: 2542 additions & 602 deletions

Some content is hidden

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

py/mkrules.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,10 @@ print-cfg:
9797
$(ECHO) "OBJ = $(OBJ)"
9898
.PHONY: print-cfg
9999

100+
print-def:
101+
@$(ECHO) "The following defines are built into the $(CC) compiler"
102+
touch __empty__.c
103+
@$(CC) -E -Wp,-dM __empty__.c
104+
@$(RM) -f __empty__.c
105+
100106
-include $(OBJ:.o=.P)

stmhal/gccollect.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
*/
2626

2727
#include <stdio.h>
28-
29-
#include <stm32f4xx_hal.h>
28+
#include <stdint.h>
3029

3130
#include "misc.h"
3231
#include "mpconfig.h"
@@ -35,6 +34,8 @@
3534
#include "gc.h"
3635
#include "gccollect.h"
3736

37+
#include HAL_H
38+
3839
machine_uint_t gc_helper_get_regs_and_sp(machine_uint_t *regs);
3940

4041
// obsolete

stmhal/mpconfigport.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,11 @@ typedef const void *machine_const_ptr_t; // must be of pointer size
104104

105105
// We need to provide a declaration/definition of alloca()
106106
#include <alloca.h>
107+
108+
#define HAL_H <stm32f4xx_hal.h>
109+
#define PIN_DEFS_PORT_H "pin_defs_stmhal.h"
110+
111+
#define GPIO_read_pin(gpio, pin) (((gpio)->IDR >> (pin)) & 1)
112+
#define GPIO_set_pin(gpio, pin_mask) (((gpio)->BSRRL) = (pin_mask))
113+
#define GPIO_clear_pin(gpio, pin_mask) (((gpio)->BSRRH) = (pin_mask))
114+

stmhal/pin.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
#include <stdint.h>
2929
#include <string.h>
3030

31-
#include "stm32f4xx_hal.h"
32-
3331
#include "mpconfig.h"
32+
#include HAL_H
3433
#include "nlr.h"
3534
#include "misc.h"
3635
#include "qstr.h"
@@ -310,13 +309,13 @@ STATIC mp_obj_t pin_value(uint n_args, mp_obj_t *args) {
310309
pin_obj_t *self = args[0];
311310
if (n_args == 1) {
312311
// get pin
313-
return MP_OBJ_NEW_SMALL_INT((self->gpio->IDR >> self->pin) & 1);
312+
return MP_OBJ_NEW_SMALL_INT(GPIO_read_pin(self->gpio, self->pin));
314313
} else {
315314
// set pin
316315
if (mp_obj_is_true(args[1])) {
317-
self->gpio->BSRRL = self->pin_mask;
316+
GPIO_set_pin(self->gpio, self->pin_mask);
318317
} else {
319-
self->gpio->BSRRH = self->pin_mask;
318+
GPIO_clear_pin(self->gpio, self->pin_mask);
320319
}
321320
return mp_const_none;
322321
}
@@ -327,7 +326,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value);
327326
/// Set the pin to a low logic level.
328327
STATIC mp_obj_t pin_low(mp_obj_t self_in) {
329328
pin_obj_t *self = self_in;
330-
self->gpio->BSRRH = self->pin_mask;
329+
GPIO_clear_pin(self->gpio, self->pin_mask);;
331330
return mp_const_none;
332331
}
333332
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_low_obj, pin_low);
@@ -336,7 +335,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_low_obj, pin_low);
336335
/// Set the pin to a high logic level.
337336
STATIC mp_obj_t pin_high(mp_obj_t self_in) {
338337
pin_obj_t *self = self_in;
339-
self->gpio->BSRRL = self->pin_mask;
338+
GPIO_set_pin(self->gpio, self->pin_mask);;
340339
return mp_const_none;
341340
}
342341
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_high_obj, pin_high);

stmhal/pin.h

Lines changed: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -24,63 +24,10 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
enum {
28-
PORT_A,
29-
PORT_B,
30-
PORT_C,
31-
PORT_D,
32-
PORT_E,
33-
PORT_F,
34-
PORT_G,
35-
PORT_H,
36-
PORT_I,
37-
PORT_J,
38-
};
27+
// This file requires pin_defs_xxx.h (which has port specific enums and
28+
// defines, so we include it here. It should never be included directly
3929

40-
enum {
41-
AF_FN_TIM,
42-
AF_FN_I2C,
43-
AF_FN_USART,
44-
AF_FN_UART = AF_FN_USART,
45-
AF_FN_SPI
46-
};
47-
48-
enum {
49-
AF_PIN_TYPE_TIM_CH1 = 0,
50-
AF_PIN_TYPE_TIM_CH2,
51-
AF_PIN_TYPE_TIM_CH3,
52-
AF_PIN_TYPE_TIM_CH4,
53-
AF_PIN_TYPE_TIM_CH1N,
54-
AF_PIN_TYPE_TIM_CH2N,
55-
AF_PIN_TYPE_TIM_CH3N,
56-
AF_PIN_TYPE_TIM_CH1_ETR,
57-
AF_PIN_TYPE_TIM_ETR,
58-
AF_PIN_TYPE_TIM_BKIN,
59-
60-
AF_PIN_TYPE_I2C_SDA = 0,
61-
AF_PIN_TYPE_I2C_SCL,
62-
63-
AF_PIN_TYPE_USART_TX = 0,
64-
AF_PIN_TYPE_USART_RX,
65-
AF_PIN_TYPE_USART_CTS,
66-
AF_PIN_TYPE_USART_RTS,
67-
AF_PIN_TYPE_USART_CK,
68-
AF_PIN_TYPE_UART_TX = AF_PIN_TYPE_USART_TX,
69-
AF_PIN_TYPE_UART_RX = AF_PIN_TYPE_USART_RX,
70-
AF_PIN_TYPE_UART_CTS = AF_PIN_TYPE_USART_CTS,
71-
AF_PIN_TYPE_UART_RTS = AF_PIN_TYPE_USART_RTS,
72-
73-
AF_PIN_TYPE_SPI_MOSI = 0,
74-
AF_PIN_TYPE_SPI_MISO,
75-
AF_PIN_TYPE_SPI_SCK,
76-
AF_PIN_TYPE_SPI_NSS,
77-
};
78-
79-
enum {
80-
PIN_ADC1 = (1 << 0),
81-
PIN_ADC2 = (1 << 1),
82-
PIN_ADC3 = (1 << 2),
83-
};
30+
#include PIN_DEFS_PORT_H
8431

8532
typedef struct {
8633
mp_obj_base_t base;
@@ -91,24 +38,21 @@ typedef struct {
9138

9239
union {
9340
void *reg;
94-
TIM_TypeDef *TIM;
95-
I2C_TypeDef *I2C;
96-
USART_TypeDef *USART;
97-
USART_TypeDef *UART;
98-
SPI_TypeDef *SPI;
41+
42+
PIN_DEFS_PORT_AF_UNION
9943
};
10044
} pin_af_obj_t;
10145

10246
typedef struct {
10347
mp_obj_base_t base;
10448
const char *name;
105-
uint16_t port : 4;
106-
uint16_t pin : 4;
107-
uint16_t num_af : 4;
108-
uint16_t adc_channel : 4;
109-
uint16_t adc_num : 3; // 1 bit per ADC
110-
uint16_t pin_mask;
111-
GPIO_TypeDef *gpio;
49+
uint32_t port : 4;
50+
uint32_t pin : 5; // Some ARM processors use 32 bits/PORT
51+
uint32_t num_af : 4;
52+
uint32_t adc_channel : 5; // Some ARM processors use 32 bits/PORT
53+
uint32_t adc_num : 3; // 1 bit per ADC
54+
uint32_t pin_mask;
55+
pin_gpio_t *gpio;
11256
const pin_af_obj_t *af;
11357
} pin_obj_t;
11458

stmhal/pin_defs_stmhal.h

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013, 2014 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
// This file contains pin definitions that are specific to the stmhal port.
28+
// This file should only ever be #included by pin.h and not directly.
29+
30+
enum {
31+
PORT_A,
32+
PORT_B,
33+
PORT_C,
34+
PORT_D,
35+
PORT_E,
36+
PORT_F,
37+
PORT_G,
38+
PORT_H,
39+
PORT_I,
40+
PORT_J,
41+
};
42+
43+
enum {
44+
AF_FN_TIM,
45+
AF_FN_I2C,
46+
AF_FN_USART,
47+
AF_FN_UART = AF_FN_USART,
48+
AF_FN_SPI
49+
};
50+
51+
enum {
52+
AF_PIN_TYPE_TIM_CH1 = 0,
53+
AF_PIN_TYPE_TIM_CH2,
54+
AF_PIN_TYPE_TIM_CH3,
55+
AF_PIN_TYPE_TIM_CH4,
56+
AF_PIN_TYPE_TIM_CH1N,
57+
AF_PIN_TYPE_TIM_CH2N,
58+
AF_PIN_TYPE_TIM_CH3N,
59+
AF_PIN_TYPE_TIM_CH1_ETR,
60+
AF_PIN_TYPE_TIM_ETR,
61+
AF_PIN_TYPE_TIM_BKIN,
62+
63+
AF_PIN_TYPE_I2C_SDA = 0,
64+
AF_PIN_TYPE_I2C_SCL,
65+
66+
AF_PIN_TYPE_USART_TX = 0,
67+
AF_PIN_TYPE_USART_RX,
68+
AF_PIN_TYPE_USART_CTS,
69+
AF_PIN_TYPE_USART_RTS,
70+
AF_PIN_TYPE_USART_CK,
71+
AF_PIN_TYPE_UART_TX = AF_PIN_TYPE_USART_TX,
72+
AF_PIN_TYPE_UART_RX = AF_PIN_TYPE_USART_RX,
73+
AF_PIN_TYPE_UART_CTS = AF_PIN_TYPE_USART_CTS,
74+
AF_PIN_TYPE_UART_RTS = AF_PIN_TYPE_USART_RTS,
75+
76+
AF_PIN_TYPE_SPI_MOSI = 0,
77+
AF_PIN_TYPE_SPI_MISO,
78+
AF_PIN_TYPE_SPI_SCK,
79+
AF_PIN_TYPE_SPI_NSS,
80+
};
81+
82+
enum {
83+
PIN_ADC1 = (1 << 0),
84+
PIN_ADC2 = (1 << 1),
85+
PIN_ADC3 = (1 << 2),
86+
};
87+
88+
#define PIN_DEFS_PORT_AF_UNION \
89+
TIM_TypeDef *TIM; \
90+
I2C_TypeDef *I2C; \
91+
USART_TypeDef *USART; \
92+
USART_TypeDef *UART; \
93+
SPI_TypeDef *SPI;
94+
95+
typedef GPIO_TypeDef pin_gpio_t;
96+

stmhal/pin_named_pins.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
#include <stdint.h>
2929
#include <string.h>
3030

31-
#include "stm32f4xx_hal.h"
32-
3331
#include "misc.h"
3432
#include "mpconfig.h"
33+
34+
#include HAL_H
35+
3536
#include "qstr.h"
3637
#include "obj.h"
3738
#include "runtime.h"

stmhal/pybstdio.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
*/
2626

2727
#include <stdio.h>
28-
29-
#include <stm32f4xx_hal.h>
28+
#include <stdint.h>
3029

3130
#include "misc.h"
3231
#include "mpconfig.h"
@@ -38,6 +37,8 @@
3837
#include "usb.h"
3938
#include "uart.h"
4039

40+
#include HAL_H
41+
4142
// TODO make stdin, stdout and stderr writable objects so they can
4243
// be changed by Python code.
4344

stmhal/pyexec.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626

2727
#include <stdlib.h>
2828
#include <stdio.h>
29-
30-
#include <stm32f4xx_hal.h>
29+
#include <stdint.h>
3130

3231
#include "mpconfig.h"
3332
#include "nlr.h"
@@ -50,6 +49,8 @@
5049
#include "usb.h"
5150
#include "genhdr/py-version.h"
5251

52+
#include HAL_H
53+
5354
pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL;
5455
STATIC bool repl_display_debugging_info = 0;
5556

stmhal/readline.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525
*/
2626

2727
#include <stdio.h>
28+
#include <stdint.h>
2829
#include <string.h>
2930

30-
#include <stm32f4xx_hal.h>
31-
3231
#include "misc.h"
3332
#include "mpconfig.h"
3433
#include "qstr.h"
@@ -38,6 +37,8 @@
3837
#include "readline.h"
3938
#include "usb.h"
4039

40+
#include HAL_H
41+
4142
#if 0 // print debugging info
4243
#define DEBUG_PRINT (1)
4344
#define DEBUG_printf printf

0 commit comments

Comments
 (0)