2 , writeShellApplication
11 , flashDevice ? "/dev/null"
12 , firmwareConfig ? ./simulator.cfg
15 supportedArches = [ "avr" "stm32" "lpc176x" ];
16 matchBoard = with builtins; match ''^.*CONFIG_BOARD_DIRECTORY="([a-zA-Z0-9_]+)".*$'' (readFile firmwareConfig);
17 boardArch = if matchBoard == null then null else builtins.head matchBoard;
19 writeShellApplication {
20 name = "klipper-flash-${mcu}";
23 pkgsCross.avr.stdenv.cc
25 ] ++ lib.optionals (boardArch == "avr") [ avrdude ] ++ lib.optionals (boardArch == "stm32") [ stm32flash ];
27 if ${lib.boolToString (!builtins.elem boardArch supportedArches)}; then
28 printf "Flashing Klipper firmware to your board is not supported yet.\n"
29 printf "Please use the compiled firmware at ${klipper-firmware} and flash it using the tools provided for your microcontroller."
32 if ${lib.boolToString (boardArch == "stm32")}; then
33 make -C ${klipper.src} FLASH_DEVICE="${toString flashDevice}" OUT="${klipper-firmware}/" KCONFIG_CONFIG="${klipper-firmware}/config" serialflash
35 make -C ${klipper.src} FLASH_DEVICE="${toString flashDevice}" OUT="${klipper-firmware}/" KCONFIG_CONFIG="${klipper-firmware}/config" flash