Skip to content

Commit

Permalink
more granularity to the feature selection for small mcus
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerlz committed Jan 18, 2024
1 parent d8faa86 commit 4ac9004
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 83 deletions.
108 changes: 74 additions & 34 deletions src/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -89,51 +89,91 @@ config USB_SERIAL_NUMBER
string "USB serial number" if !USB_SERIAL_NUMBER_CHIPID
endmenu

# Optional features that can be disabled (for devices with small flash sizes)
config WANT_GPIO_BITBANGING
bool
depends on HAVE_GPIO
#
# Optional features that can be disabled (for devices with small flash sizes)
#
menu "Optional features (to reduce code size)"
depends on HAVE_LIMITED_CODE_SIZE || LOW_LEVEL_OPTIONS
config WANT_DEBUG
bool "Support MCU Debug Commands"
default y
config WANT_DISPLAYS
bool
depends on HAVE_GPIO
config WANT_GPIO_ADC
bool "Support ADCs"
depends on HAVE_GPIO_ADC
default y
config WANT_SENSORS
bool
depends on HAVE_GPIO_I2C || HAVE_GPIO_SPI

#
# I2C Devices
#
config WANT_GPIO_I2C
bool "Support I2C Devices"
depends on HAVE_GPIO_I2C
default y
config WANT_LIS2DW
bool
config WANT_SOFTWARE_I2C
bool "Support Software Based I2C \"bit-banging\""
depends on HAVE_GPIO && WANT_GPIO_I2C
default y
config WANT_MPU9250
bool "Support MPU9250 Accelerometer"
depends on WANT_GPIO_I2C
default y

#
# SPI Devices
#
config WANT_GPIO_SPI
bool "Support SPI Devices"
depends on HAVE_GPIO_SPI
default y
config WANT_SOFTWARE_I2C
bool
depends on HAVE_GPIO && HAVE_GPIO_I2C
config WANT_THERMOCOUPLE
bool "Support External Thermocouple SPI Devices"
depends on WANT_GPIO_SPI
default y
config WANT_ADXL345
bool "Support ADXL345 Accelerometer"
depends on WANT_GPIO_SPI
default y
config WANT_LIS2DW
bool "Support LIS2DW 3-axis Accelerometer"
depends on WANT_GPIO_SPI
config WANT_ANGLE_SENSOR
bool "Support Angle Sensors (A1333, AS5047D, TLE5012B)"
depends on WANT_GPIO_SPI
default y
config WANT_SOFTWARE_SPI
bool
depends on HAVE_GPIO && HAVE_GPIO_SPI
bool "Support Software Based SPI \"bit-banging\""
depends on HAVE_GPIO && WANT_GPIO_SPI
default y
menu "Optional features (to reduce code size)"
depends on HAVE_LIMITED_CODE_SIZE
config WANT_GPIO_BITBANGING
bool "Support GPIO \"bit-banging\" devices"

config WANT_GPIO_SDIO
bool "Support SDIO Devices"
depends on HAVE_GPIO_SDIO
default y
config WANT_GPIO_HARD_PWM
bool "Support Hardware PWM"
depends on HAVE_GPIO_HARD_PWM
default y
config WANT_BUTTONS
bool "Support GPIO Buttons"
depends on HAVE_GPIO
default y
config WANT_TMCUART
bool "Support TMC UART"
depends on HAVE_GPIO
default y
config WANT_NEOPIXEL
bool "Support NeoPixels"
depends on HAVE_GPIO
default y
config WANT_PULSE_COUNTER
bool "Support Pulse Counter"
depends on HAVE_GPIO
default y
config WANT_DISPLAYS
bool "Support LCD devices"
bool "Support LCD Devices"
depends on HAVE_GPIO
config WANT_SENSORS
bool "Support external sensor devices"
depends on HAVE_GPIO_I2C || HAVE_GPIO_SPI
config WANT_LIS2DW
bool "Support lis2dw 3-axis accelerometer"
depends on HAVE_GPIO_SPI
config WANT_SOFTWARE_I2C
bool "Support software based I2C \"bit-banging\""
depends on HAVE_GPIO && HAVE_GPIO_I2C
config WANT_SOFTWARE_SPI
bool "Support software based SPI \"bit-banging\""
depends on HAVE_GPIO && HAVE_GPIO_SPI
default y

endmenu

# Generic configuration options for CANbus
Expand Down
28 changes: 15 additions & 13 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# Main code build rules

src-y += sched.c command.c basecmd.c debugcmds.c
src-y += sched.c command.c basecmd.c
src-$(CONFIG_HAVE_GPIO) += initial_pins.c gpiocmds.c stepper.c endstop.c \
trsync.c
src-$(CONFIG_HAVE_GPIO_ADC) += adccmds.c
src-$(CONFIG_HAVE_GPIO_SPI) += spicmds.c
src-$(CONFIG_HAVE_GPIO_SDIO) += sdiocmds.c
src-$(CONFIG_HAVE_GPIO_I2C) += i2ccmds.c
src-$(CONFIG_HAVE_GPIO_HARD_PWM) += pwmcmds.c

src-$(CONFIG_WANT_GPIO_BITBANGING) += buttons.c tmcuart.c neopixel.c \
pulse_counter.c
src-$(CONFIG_WANT_GPIO_ADC) += adccmds.c
src-$(CONFIG_WANT_GPIO_SPI) += spicmds.c
src-$(CONFIG_WANT_GPIO_SDIO) += sdiocmds.c
src-$(CONFIG_WANT_GPIO_I2C) += i2ccmds.c
src-$(CONFIG_WANT_GPIO_HARD_PWM) += pwmcmds.c
src-$(CONFIG_WANT_DEBUG) += debugcmds.c
src-$(CONFIG_WANT_BUTTONS) += buttons.c
src-$(CONFIG_WANT_TMCUART) += tmcuart.c
src-$(CONFIG_WANT_NEOPIXEL) += neopixel.c
src-$(CONFIG_WANT_PULSE_COUNTER) += pulse_counter.c
src-$(CONFIG_WANT_DISPLAYS) += lcd_st7920.c lcd_hd44780.c
src-$(CONFIG_WANT_SOFTWARE_SPI) += spi_software.c
src-$(CONFIG_WANT_SOFTWARE_I2C) += i2c_software.c
sensors-src-$(CONFIG_HAVE_GPIO_SPI) := thermocouple.c sensor_adxl345.c \
sensor_angle.c
src-$(CONFIG_WANT_THERMOCOUPLE) += thermocouple.c
src-$(CONFIG_WANT_ADXL345) += sensor_adxl345.c
src-$(CONFIG_WANT_MPU9250) += sensor_mpu9250.c
src-$(CONFIG_WANT_LIS2DW) += sensor_lis2dw.c
sensors-src-$(CONFIG_HAVE_GPIO_I2C) += sensor_mpu9250.c
src-$(CONFIG_WANT_SENSORS) += $(sensors-src-y)
src-$(CONFIG_WANT_ANGLE_SENSOR) += sensor_angle.c
6 changes: 3 additions & 3 deletions src/atsamd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ canbus-src-y += atsamd/fdcan.c atsamd/chipid.c
src-$(CONFIG_USBCANBUS) += $(canbus-src-y) atsamd/usbserial.c generic/usb_canbus.c
src-$(CONFIG_CANSERIAL) += $(canbus-src-y) generic/canbus.c
src-$(CONFIG_HAVE_GPIO_ADC) += atsamd/adc.c
src-$(CONFIG_HAVE_GPIO_I2C) += atsamd/i2c.c
src-$(CONFIG_HAVE_GPIO_SPI) += atsamd/spi.c
src-$(CONFIG_WANT_GPIO_I2C) += atsamd/i2c.c
src-$(CONFIG_WANT_GPIO_SPI) += atsamd/spi.c
src-$(CONFIG_HAVE_SERCOM) += atsamd/sercom.c
src-$(CONFIG_HAVE_GPIO_HARD_PWM) += atsamd/hard_pwm.c
src-$(CONFIG_WANT_GPIO_HARD_PWM) += atsamd/hard_pwm.c
src-$(CONFIG_MACH_SAMC21) += atsamd/samd51_watchdog.c
src-$(CONFIG_MACH_SAMC21) += atsamd/samc21_clock.c atsamd/timer.c generic/timer_irq.c
src-$(CONFIG_MACH_SAMD21) += atsamd/watchdog.c
Expand Down
12 changes: 9 additions & 3 deletions src/avr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ config AVR_SELECT
select HAVE_GPIO_I2C
select HAVE_GPIO_HARD_PWM
select HAVE_STRICT_TIMING
select HAVE_LIMITED_CODE_SIZE if MACH_atmega168 || MACH_atmega328 || MACH_atmega328p
select HAVE_LIMITED_CODE_SIZE if MACH_atmega168 || MACH_atmega328 || MACH_atmega328p || MACH_atmega32u4

config BOARD_DIRECTORY
string
default "avr"

#
# disabled due to outdated compiler but not removed from the code
# to be enabled again when/if debian updates the compiler
#
config MACH_atmega168
bool
default n

choice
prompt "Processor model"
config MACH_atmega2560
Expand All @@ -37,8 +45,6 @@ choice
bool "atmega328p"
config MACH_atmega328
bool "atmega328"
config MACH_atmega168
bool "atmega168"
endchoice

config MCU
Expand Down
8 changes: 4 additions & 4 deletions src/avr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ CFLAGS += -mmcu=$(CONFIG_MCU)
# Add avr source files
src-y += avr/main.c avr/timer.c
src-$(CONFIG_HAVE_GPIO) += avr/gpio.c
src-$(CONFIG_HAVE_GPIO_ADC) += avr/adc.c
src-$(CONFIG_HAVE_GPIO_SPI) += avr/spi.c
src-$(CONFIG_HAVE_GPIO_I2C) += avr/i2c.c
src-$(CONFIG_HAVE_GPIO_HARD_PWM) += avr/hard_pwm.c
src-$(CONFIG_WANT_GPIO_ADC) += avr/adc.c
src-$(CONFIG_WANT_GPIO_SPI) += avr/spi.c
src-$(CONFIG_WANT_GPIO_I2C) += avr/i2c.c
src-$(CONFIG_WANT_GPIO_HARD_PWM) += avr/hard_pwm.c
src-$(CONFIG_AVR_WATCHDOG) += avr/watchdog.c
src-$(CONFIG_USBSERIAL) += avr/usbserial.c generic/usb_cdc.c
src-$(CONFIG_SERIAL) += avr/serial.c generic/serial_irq.c
Expand Down
4 changes: 2 additions & 2 deletions src/hc32f460/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ src-y += ../lib/hc32f460/driver/src/hc32f460_sram.c
src-y += ../lib/hc32f460/driver/src/hc32f460_utility.c
src-y += ../lib/hc32f460/driver/src/hc32f460_gpio.c
src-y += ../lib/hc32f460/driver/src/hc32f460_pwc.c
src-$(CONFIG_HAVE_GPIO_ADC) += hc32f460/adc.c ../lib/hc32f460/driver/src/hc32f460_adc.c
src-$(CONFIG_WANT_GPIO_ADC) += hc32f460/adc.c ../lib/hc32f460/driver/src/hc32f460_adc.c
src-$(CONFIG_SERIAL) += hc32f460/serial.c generic/serial_irq.c ../lib/hc32f460/driver/src/hc32f460_usart.c
src-$(CONFIG_HAVE_GPIO_HARD_PWM) += hc32f460/hard_pwm.c ../lib/hc32f460/driver/src/hc32f460_timera.c
src-$(CONFIG_WANT_GPIO_HARD_PWM) += hc32f460/hard_pwm.c ../lib/hc32f460/driver/src/hc32f460_timera.c
src-y += generic/armcm_boot.c generic/armcm_irq.c generic/armcm_timer.c
src-y += generic/armcm_reset.c generic/crc16_ccitt.c

Expand Down
6 changes: 3 additions & 3 deletions src/lpc176x/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ src-y += generic/armcm_boot.c generic/armcm_irq.c generic/armcm_timer.c
src-y += generic/armcm_reset.c generic/crc16_ccitt.c
src-y += ../lib/lpc176x/device/system_LPC17xx.c
src-$(CONFIG_HAVE_GPIO_ADC) += lpc176x/adc.c
src-$(CONFIG_HAVE_GPIO_I2C) += lpc176x/i2c.c
src-$(CONFIG_HAVE_GPIO_SPI) += lpc176x/spi.c
src-$(CONFIG_WANT_GPIO_I2C) += lpc176x/i2c.c
src-$(CONFIG_WANT_GPIO_SPI) += lpc176x/spi.c
src-$(CONFIG_USBSERIAL) += lpc176x/usbserial.c lpc176x/chipid.c
src-$(CONFIG_USBSERIAL) += generic/usb_cdc.c
src-$(CONFIG_SERIAL) += lpc176x/serial.c generic/serial_irq.c
src-$(CONFIG_HAVE_GPIO_HARD_PWM) += lpc176x/hard_pwm.c
src-$(CONFIG_WANT_GPIO_HARD_PWM) += lpc176x/hard_pwm.c

# Build the additional bin output file
target-y += $(OUT)klipper.bin
Expand Down
2 changes: 1 addition & 1 deletion src/pru/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CFLAGS_pru1.elf := $(CFLAGS)

# Add source files
src-y += pru/main.c pru/gpio.c generic/timer_irq.c
src-$(CONFIG_HAVE_GPIO_ADC) += pru/adc.c
src-$(CONFIG_WANT_GPIO_ADC) += pru/adc.c

pru0-y := pru/pru0.c generic/crc16_ccitt.c command.c
pru0-y += ../lib/pru_rpmsg/pru_rpmsg.c ../lib/pru_rpmsg/pru_virtqueue.c
Expand Down
6 changes: 3 additions & 3 deletions src/rp2040/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ src-$(CONFIG_CANSERIAL) += ../lib/fast-hash/fasthash.c
src-$(CONFIG_USBCANBUS) += rp2040/can.c rp2040/chipid.c ../lib/can2040/can2040.c
src-$(CONFIG_USBCANBUS) += generic/canserial.c generic/usb_canbus.c
src-$(CONFIG_USBCANBUS) += ../lib/fast-hash/fasthash.c rp2040/usbserial.c
src-$(CONFIG_HAVE_GPIO_HARD_PWM) += rp2040/hard_pwm.c
src-$(CONFIG_HAVE_GPIO_SPI) += rp2040/spi.c
src-$(CONFIG_HAVE_GPIO_I2C) += rp2040/i2c.c
src-$(CONFIG_WANT_GPIO_HARD_PWM) += rp2040/hard_pwm.c
src-$(CONFIG_WANT_GPIO_SPI) += rp2040/spi.c
src-$(CONFIG_WANT_GPIO_I2C) += rp2040/i2c.c

# rp2040 stage2 building
STAGE2_FILE := $(shell echo $(CONFIG_RP2040_STAGE2_FILE))
Expand Down
46 changes: 30 additions & 16 deletions src/stm32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,41 +42,55 @@ src-y += generic/armcm_boot.c generic/armcm_irq.c generic/armcm_reset.c
src-$(CONFIG_MACH_STM32F0) += ../lib/stm32f0/system_stm32f0xx.c
src-$(CONFIG_MACH_STM32F0) += generic/timer_irq.c stm32/stm32f0_timer.c
src-$(CONFIG_MACH_STM32F0) += stm32/stm32f0.c stm32/gpioperiph.c
src-$(CONFIG_MACH_STM32F0) += stm32/stm32f0_adc.c stm32/stm32f0_i2c.c
src-$(CONFIG_MACH_STM32F103) += ../lib/stm32f1/system_stm32f1xx.c
src-$(CONFIG_MACH_STM32F103) += stm32/adc.c
src-$(CONFIG_MACH_N32G45x) += ../lib/stm32f1/system_stm32f1xx.c
src-$(CONFIG_MACH_N32G45x) += ../lib/n32g45x/n32g45x_adc.c stm32/n32g45x_adc.c
src-$(CONFIG_MACH_STM32F1) += stm32/stm32f1.c generic/armcm_timer.c stm32/i2c.c
src-$(CONFIG_MACH_STM32F1) += stm32/stm32f1.c generic/armcm_timer.c
src-$(CONFIG_MACH_STM32F2) += ../lib/stm32f2/system_stm32f2xx.c
src-$(CONFIG_MACH_STM32F2) += stm32/stm32f4.c generic/armcm_timer.c
src-$(CONFIG_MACH_STM32F2) += stm32/gpioperiph.c stm32/adc.c stm32/i2c.c
src-$(CONFIG_MACH_STM32F2) += stm32/gpioperiph.c
src-$(CONFIG_MACH_STM32F4) += ../lib/stm32f4/system_stm32f4xx.c
src-$(CONFIG_MACH_STM32F4) += stm32/stm32f4.c generic/armcm_timer.c
src-$(CONFIG_MACH_STM32F4) += stm32/gpioperiph.c stm32/adc.c stm32/i2c.c
src-$(CONFIG_MACH_STM32F4) += stm32/gpioperiph.c
src-$(CONFIG_MACH_STM32F7) += ../lib/stm32f7/system_stm32f7xx.c
src-$(CONFIG_MACH_STM32F7) += stm32/stm32f7.c generic/armcm_timer.c
src-$(CONFIG_MACH_STM32F7) += stm32/gpioperiph.c stm32/adc.c stm32/stm32f0_i2c.c
src-$(CONFIG_MACH_STM32F7) += stm32/gpioperiph.c
src-$(CONFIG_MACH_STM32G0) += generic/timer_irq.c stm32/stm32f0_timer.c
src-$(CONFIG_MACH_STM32G0) += stm32/stm32g0.c stm32/gpioperiph.c
src-$(CONFIG_MACH_STM32G0) += stm32/stm32f0_adc.c stm32/stm32f0_i2c.c
src-$(CONFIG_MACH_STM32G4) += ../lib/stm32g4/system_stm32g4xx.c
src-$(CONFIG_MACH_STM32G4) += stm32/stm32g4.c generic/armcm_timer.c
src-$(CONFIG_MACH_STM32G4) += stm32/gpioperiph.c stm32/stm32h7_adc.c
src-$(CONFIG_MACH_STM32G4) += stm32/stm32f0_i2c.c
src-$(CONFIG_MACH_STM32G4) += stm32/gpioperiph.c
src-$(CONFIG_MACH_STM32H7) += ../lib/stm32h7/system_stm32h7xx.c
src-$(CONFIG_MACH_STM32H7) += stm32/stm32h7.c generic/armcm_timer.c
src-$(CONFIG_MACH_STM32H7) += stm32/gpioperiph.c stm32/stm32h7_adc.c
src-$(CONFIG_MACH_STM32H7) += stm32/stm32f0_i2c.c
src-$(CONFIG_MACH_STM32H7) += stm32/gpioperiph.c
src-$(CONFIG_MACH_STM32L4) += ../lib/stm32l4/system_stm32l4xx.c
src-$(CONFIG_MACH_STM32L4) += stm32/stm32l4.c generic/armcm_timer.c
src-$(CONFIG_MACH_STM32L4) += stm32/gpioperiph.c
src-$(CONFIG_MACH_STM32L4) += stm32/stm32h7_adc.c stm32/stm32f0_i2c.c
adc-src-$(CONFIG_MACH_STM32F103) += stm32/adc.c
adc-src-$(CONFIG_MACH_STM32F2) += stm32/adc.c
adc-src-$(CONFIG_MACH_STM32F4) += stm32/adc.c
adc-src-$(CONFIG_MACH_STM32F7) += stm32/adc.c
adc-src-$(CONFIG_MACH_STM32F0) += stm32/stm32f0_adc.c
adc-src-$(CONFIG_MACH_STM32G0) += stm32/stm32f0_adc.c
adc-src-$(CONFIG_MACH_STM32G4) += stm32/stm32h7_adc.c
adc-src-$(CONFIG_MACH_STM32H7) += stm32/stm32h7_adc.c
adc-src-$(CONFIG_MACH_STM32L4) += stm32/stm32h7_adc.c
adc-src-$(CONFIG_MACH_N32G45x) += ../lib/n32g45x/n32g45x_adc.c stm32/n32g45x_adc.c
src-$(CONFIG_WANT_GPIO_ADC) += $(adc-src-y)
i2c-src-$(CONFIG_MACH_STM32F1) += stm32/i2c.c
i2c-src-$(CONFIG_MACH_STM32F2) += stm32/i2c.c
i2c-src-$(CONFIG_MACH_STM32F4) += stm32/i2c.c
i2c-src-$(CONFIG_MACH_STM32F0) += stm32/stm32f0_i2c.c
i2c-src-$(CONFIG_MACH_STM32F7) += stm32/stm32f0_i2c.c
i2c-src-$(CONFIG_MACH_STM32G0) += stm32/stm32f0_i2c.c
i2c-src-$(CONFIG_MACH_STM32G4) += stm32/stm32f0_i2c.c
i2c-src-$(CONFIG_MACH_STM32H7) += stm32/stm32f0_i2c.c
i2c-src-$(CONFIG_MACH_STM32L4) += stm32/stm32f0_i2c.c
src-$(CONFIG_WANT_GPIO_I2C) += $(i2c-src-y)
spi-src-y := stm32/spi.c
spi-src-$(CONFIG_MACH_STM32H7) := stm32/stm32h7_spi.c
src-$(CONFIG_HAVE_GPIO_SPI) += $(spi-src-y)
src-$(CONFIG_WANT_GPIO_SPI) += $(spi-src-y)
sdio-src-y := stm32/sdio.c
src-$(CONFIG_HAVE_GPIO_SDIO) += $(sdio-src-y)
src-$(CONFIG_WANT_GPIO_SDIO) += $(sdio-src-y)
usb-src-$(CONFIG_HAVE_STM32_USBFS) := stm32/usbfs.c
usb-src-$(CONFIG_HAVE_STM32_USBOTG) := stm32/usbotg.c
src-$(CONFIG_USBSERIAL) += $(usb-src-y) stm32/chipid.c generic/usb_cdc.c
Expand All @@ -92,7 +106,7 @@ canbus-src-$(CONFIG_HAVE_STM32_FDCANBUS) += stm32/fdcan.c
src-$(CONFIG_CANSERIAL) += $(canbus-src-y) generic/canbus.c stm32/chipid.c
src-$(CONFIG_USBCANBUS) += $(usb-src-y) $(canbus-src-y)
src-$(CONFIG_USBCANBUS) += stm32/chipid.c generic/usb_canbus.c
src-$(CONFIG_HAVE_GPIO_HARD_PWM) += stm32/hard_pwm.c
src-$(CONFIG_WANT_GPIO_HARD_PWM) += stm32/hard_pwm.c

# Binary output file rules
target-y += $(OUT)klipper.bin
Expand Down
6 changes: 5 additions & 1 deletion test/configs/stm32f031.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Base config file for STM32F031 boards
CONFIG_MACH_STM32=y
CONFIG_MACH_STM32F031=y
CONFIG_WANT_GPIO_BITBANGING=n
CONFIG_WANT_DEBUG=n
CONFIG_WANT_DISPLAYS=n
CONFIG_WANT_NEOPIXEL=n
CONFIG_WANT_BUTTONS=n
CONFIG_WANT_TMCUART=n
CONFIG_WANT_PULSE_COUNTER=n

0 comments on commit 4ac9004

Please sign in to comment.