Skip to content
Snippets Groups Projects
Commit c73360bf authored by Damien George's avatar Damien George
Browse files

stm32: Allow to build a board without any hardware I2C ports defined.

This patch adds in internal config value MICROPY_HW_ENABLE_HW_I2C that is
automatically configured, and enabled only if one or more hardware I2C
ports are defined in the mpconfigboard.h file.  If none are defined then
the pyb.I2C class is excluded from the build, along with all supporting
code.  The machine.I2C class will still be available for software I2C.

Disabling all hardware I2C on an F4 board saves around 10,000 bytes of code
and 200 bytes of RAM.
parent 82dc5c1d
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,8 @@
#include "dma.h"
#include "i2c.h"
#if MICROPY_HW_ENABLE_HW_I2C
/// \moduleref pyb
/// \class I2C - a two-wire serial protocol
///
......@@ -1033,3 +1035,5 @@ const mp_obj_type_t pyb_i2c_type = {
.make_new = pyb_i2c_make_new,
.locals_dict = (mp_obj_dict_t*)&pyb_i2c_locals_dict,
};
#endif // MICROPY_HW_ENABLE_HW_I2C
......@@ -34,6 +34,8 @@
#include "genhdr/pins.h"
#include "i2c.h"
#if MICROPY_HW_ENABLE_HW_I2C
STATIC const mp_obj_type_t machine_hard_i2c_type;
#if defined(MCU_SERIES_F4)
......@@ -548,3 +550,5 @@ STATIC const mp_obj_type_t machine_hard_i2c_type = {
.protocol = &machine_hard_i2c_p,
.locals_dict = (mp_obj_dict_t*)&mp_machine_soft_i2c_locals_dict,
};
#endif // MICROPY_HW_ENABLE_HW_I2C
......@@ -556,7 +556,10 @@ soft_reset:
rng_init0();
#endif
#if MICROPY_HW_ENABLE_HW_I2C
i2c_init0();
#endif
spi_init0();
pyb_usb_init0();
......
......@@ -203,7 +203,9 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
#if defined(MICROPY_HW_LED1)
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pyb_led_type) },
#endif
#if MICROPY_HW_ENABLE_HW_I2C
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&pyb_i2c_type) },
#endif
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&pyb_spi_type) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&pyb_uart_type) },
#if MICROPY_HW_ENABLE_CAN
......
......@@ -131,7 +131,6 @@
#define MICROPY_PY_MACHINE_PULSE (1)
#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new
#define MICROPY_PY_MACHINE_I2C (1)
#define MICROPY_PY_MACHINE_I2C_MAKE_NEW machine_hard_i2c_make_new
#define MICROPY_PY_MACHINE_SPI (1)
#define MICROPY_PY_MACHINE_SPI_MSB (SPI_FIRSTBIT_MSB)
#define MICROPY_PY_MACHINE_SPI_LSB (SPI_FIRSTBIT_LSB)
......@@ -245,6 +244,17 @@ extern const struct _mp_obj_module_t mp_module_onewire;
#define MICROPY_HW_MAX_UART (6)
#endif
// enable hardware I2C if there are any peripherals defined
#define MICROPY_HW_ENABLE_HW_I2C ( \
defined(MICROPY_HW_I2C1_SCL) \
|| defined(MICROPY_HW_I2C2_SCL) \
|| defined(MICROPY_HW_I2C3_SCL) \
|| defined(MICROPY_HW_I2C4_SCL) \
)
#if MICROPY_HW_ENABLE_HW_I2C
#define MICROPY_PY_MACHINE_I2C_MAKE_NEW machine_hard_i2c_make_new
#endif
#define MP_STATE_PORT MP_STATE_VM
#define MICROPY_PORT_ROOT_POINTERS \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment