From 7c3e08d5deea04ce8b3e09165b2f6c728eea3a19 Mon Sep 17 00:00:00 2001 From: Kymkim Date: Tue, 15 Jul 2025 08:38:40 -0700 Subject: [PATCH] sample 2x2 modul --- .../canblinker/.vscode/c_cpp_properties.json | 10 +- .../canblinker/.vscode/launch.json | 6 +- .../stmf446retx/.vscode/c_cpp_properties.json | 8 +- .../mainboard/stmf446retx/.vscode/launch.json | 6 +- .../modules/sample_module/.gitignore | 1 + .../.vscode/c_cpp_properties.json | 132 ++++++ .../sample_module/.vscode/extensions.json | 10 + .../modules/sample_module/.vscode/launch.json | 47 +++ .../modules/sample_module/Inc/can.h | 52 +++ .../modules/sample_module/Inc/gpio.h | 49 +++ .../modules/sample_module/Inc/keycode.h | 135 ++++++ .../modules/sample_module/Inc/main.h | 69 ++++ .../sample_module/Inc/stm32f1xx_hal_conf.h | 391 ++++++++++++++++++ .../modules/sample_module/Inc/stm32f1xx_it.h | 67 +++ .../modules/sample_module/Src/can.c | 122 ++++++ .../modules/sample_module/Src/gpio.c | 72 ++++ .../modules/sample_module/Src/main.c | 233 +++++++++++ .../sample_module/Src/stm32f1xx_hal_msp.c | 86 ++++ .../modules/sample_module/Src/stm32f1xx_it.c | 217 ++++++++++ .../modules/sample_module/lib/README | 46 +++ .../modules/sample_module/platformio.ini | 20 + .../modules/sample_module/sample_module.ioc | 132 ++++++ .../modules/sample_module/stm32pio.ini | 19 + .../modules/sample_module/test/README | 11 + 24 files changed, 1925 insertions(+), 16 deletions(-) create mode 100644 firmware/components/modules/sample_module/.gitignore create mode 100644 firmware/components/modules/sample_module/.vscode/c_cpp_properties.json create mode 100644 firmware/components/modules/sample_module/.vscode/extensions.json create mode 100644 firmware/components/modules/sample_module/.vscode/launch.json create mode 100644 firmware/components/modules/sample_module/Inc/can.h create mode 100644 firmware/components/modules/sample_module/Inc/gpio.h create mode 100644 firmware/components/modules/sample_module/Inc/keycode.h create mode 100644 firmware/components/modules/sample_module/Inc/main.h create mode 100644 firmware/components/modules/sample_module/Inc/stm32f1xx_hal_conf.h create mode 100644 firmware/components/modules/sample_module/Inc/stm32f1xx_it.h create mode 100644 firmware/components/modules/sample_module/Src/can.c create mode 100644 firmware/components/modules/sample_module/Src/gpio.c create mode 100644 firmware/components/modules/sample_module/Src/main.c create mode 100644 firmware/components/modules/sample_module/Src/stm32f1xx_hal_msp.c create mode 100644 firmware/components/modules/sample_module/Src/stm32f1xx_it.c create mode 100644 firmware/components/modules/sample_module/lib/README create mode 100644 firmware/components/modules/sample_module/platformio.ini create mode 100644 firmware/components/modules/sample_module/sample_module.ioc create mode 100644 firmware/components/modules/sample_module/stm32pio.ini create mode 100644 firmware/components/modules/sample_module/test/README diff --git a/firmware/components/can_testing/canblinker/.vscode/c_cpp_properties.json b/firmware/components/can_testing/canblinker/.vscode/c_cpp_properties.json index 979e3255..7c97866f 100644 --- a/firmware/components/can_testing/canblinker/.vscode/c_cpp_properties.json +++ b/firmware/components/can_testing/canblinker/.vscode/c_cpp_properties.json @@ -8,14 +8,13 @@ { "name": "PlatformIO", "includePath": [ - "/home/kymkim/Projects/modular-kbd/firmware/components/can_testing/canblinker/Inc", - "/home/kymkim/Projects/modular-kbd/firmware/components/can_testing/canblinker/Src", + "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/can_testing/canblinker/Inc", + "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/can_testing/canblinker/Src", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/CMSIS/Include", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/CMSIS/Device/ST/STM32F1xx/Include", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/STM32F1xx_HAL_Driver/Inc", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/STM32F1xx_HAL_Driver/Src", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/CMSIS/DSP/Include", - "/home/kymkim/Projects/modular-kbd/firmware/components/can_testing/canblinker/.pio/libdeps/bluepill_f103c8/Unity/src", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/Common", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/ak4343", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/cs43l22", @@ -62,14 +61,13 @@ "browse": { "limitSymbolsToIncludedHeaders": true, "path": [ - "/home/kymkim/Projects/modular-kbd/firmware/components/can_testing/canblinker/Inc", - "/home/kymkim/Projects/modular-kbd/firmware/components/can_testing/canblinker/Src", + "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/can_testing/canblinker/Inc", + "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/can_testing/canblinker/Src", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/CMSIS/Include", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/CMSIS/Device/ST/STM32F1xx/Include", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/STM32F1xx_HAL_Driver/Inc", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/STM32F1xx_HAL_Driver/Src", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/CMSIS/DSP/Include", - "/home/kymkim/Projects/modular-kbd/firmware/components/can_testing/canblinker/.pio/libdeps/bluepill_f103c8/Unity/src", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/Common", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/ak4343", "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/cs43l22", diff --git a/firmware/components/can_testing/canblinker/.vscode/launch.json b/firmware/components/can_testing/canblinker/.vscode/launch.json index b32a7eba..0aecebeb 100644 --- a/firmware/components/can_testing/canblinker/.vscode/launch.json +++ b/firmware/components/can_testing/canblinker/.vscode/launch.json @@ -12,7 +12,7 @@ "type": "platformio-debug", "request": "launch", "name": "PIO Debug", - "executable": "/home/kymkim/Projects/modular-kbd/firmware/components/can_testing/canblinker/.pio/build/bluepill_f103c8/firmware.elf", + "executable": "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/can_testing/canblinker/.pio/build/bluepill_f103c8/firmware.elf", "projectEnvName": "bluepill_f103c8", "toolchainBinDir": "/home/kymkim/.platformio/packages/toolchain-gccarmnoneeabi/bin", "internalConsoleOptions": "openOnSessionStart", @@ -26,7 +26,7 @@ "type": "platformio-debug", "request": "launch", "name": "PIO Debug (skip Pre-Debug)", - "executable": "/home/kymkim/Projects/modular-kbd/firmware/components/can_testing/canblinker/.pio/build/bluepill_f103c8/firmware.elf", + "executable": "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/can_testing/canblinker/.pio/build/bluepill_f103c8/firmware.elf", "projectEnvName": "bluepill_f103c8", "toolchainBinDir": "/home/kymkim/.platformio/packages/toolchain-gccarmnoneeabi/bin", "internalConsoleOptions": "openOnSessionStart", @@ -36,7 +36,7 @@ "type": "platformio-debug", "request": "launch", "name": "PIO Debug (without uploading)", - "executable": "/home/kymkim/Projects/modular-kbd/firmware/components/can_testing/canblinker/.pio/build/bluepill_f103c8/firmware.elf", + "executable": "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/can_testing/canblinker/.pio/build/bluepill_f103c8/firmware.elf", "projectEnvName": "bluepill_f103c8", "toolchainBinDir": "/home/kymkim/.platformio/packages/toolchain-gccarmnoneeabi/bin", "internalConsoleOptions": "openOnSessionStart", diff --git a/firmware/components/mainboard/stmf446retx/.vscode/c_cpp_properties.json b/firmware/components/mainboard/stmf446retx/.vscode/c_cpp_properties.json index 69836baa..8faef710 100644 --- a/firmware/components/mainboard/stmf446retx/.vscode/c_cpp_properties.json +++ b/firmware/components/mainboard/stmf446retx/.vscode/c_cpp_properties.json @@ -36,8 +36,8 @@ "/home/kymkim/.platformio/packages/framework-stm32cubef4/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src", "/home/kymkim/.platformio/packages/framework-stm32cubef4/Middlewares/ST/STM32_USB_Device_Library/Core/Inc", "/home/kymkim/.platformio/packages/framework-stm32cubef4/Middlewares/ST/STM32_USB_Device_Library/Core/Src", - "/home/kymkim/Projects/modular-kbd/firmware/components/mainboard/stmf446retx/Src", - "/home/kymkim/Projects/modular-kbd/firmware/components/mainboard/stmf446retx/Inc", + "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/mainboard/stmf446retx/Src", + "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/mainboard/stmf446retx/Inc", "/home/kymkim/.platformio/packages/framework-stm32cubef4/Drivers/CMSIS/Include", "/home/kymkim/.platformio/packages/framework-stm32cubef4/Drivers/CMSIS/Device/ST/STM32F4xx/Include", "/home/kymkim/.platformio/packages/framework-stm32cubef4/Drivers/STM32F4xx_HAL_Driver/Inc", @@ -128,8 +128,8 @@ "/home/kymkim/.platformio/packages/framework-stm32cubef4/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src", "/home/kymkim/.platformio/packages/framework-stm32cubef4/Middlewares/ST/STM32_USB_Device_Library/Core/Inc", "/home/kymkim/.platformio/packages/framework-stm32cubef4/Middlewares/ST/STM32_USB_Device_Library/Core/Src", - "/home/kymkim/Projects/modular-kbd/firmware/components/mainboard/stmf446retx/Src", - "/home/kymkim/Projects/modular-kbd/firmware/components/mainboard/stmf446retx/Inc", + "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/mainboard/stmf446retx/Src", + "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/mainboard/stmf446retx/Inc", "/home/kymkim/.platformio/packages/framework-stm32cubef4/Drivers/CMSIS/Include", "/home/kymkim/.platformio/packages/framework-stm32cubef4/Drivers/CMSIS/Device/ST/STM32F4xx/Include", "/home/kymkim/.platformio/packages/framework-stm32cubef4/Drivers/STM32F4xx_HAL_Driver/Inc", diff --git a/firmware/components/mainboard/stmf446retx/.vscode/launch.json b/firmware/components/mainboard/stmf446retx/.vscode/launch.json index 5e2348d7..43744156 100644 --- a/firmware/components/mainboard/stmf446retx/.vscode/launch.json +++ b/firmware/components/mainboard/stmf446retx/.vscode/launch.json @@ -12,7 +12,7 @@ "type": "platformio-debug", "request": "launch", "name": "PIO Debug", - "executable": "/home/kymkim/Projects/modular-kbd/firmware/components/mainboard/stmf446retx/.pio/build/nucleo_f446re/firmware.elf", + "executable": "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/mainboard/stmf446retx/.pio/build/nucleo_f446re/firmware.elf", "projectEnvName": "nucleo_f446re", "toolchainBinDir": "/home/kymkim/.platformio/packages/toolchain-gccarmnoneeabi/bin", "internalConsoleOptions": "openOnSessionStart", @@ -26,7 +26,7 @@ "type": "platformio-debug", "request": "launch", "name": "PIO Debug (skip Pre-Debug)", - "executable": "/home/kymkim/Projects/modular-kbd/firmware/components/mainboard/stmf446retx/.pio/build/nucleo_f446re/firmware.elf", + "executable": "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/mainboard/stmf446retx/.pio/build/nucleo_f446re/firmware.elf", "projectEnvName": "nucleo_f446re", "toolchainBinDir": "/home/kymkim/.platformio/packages/toolchain-gccarmnoneeabi/bin", "internalConsoleOptions": "openOnSessionStart", @@ -36,7 +36,7 @@ "type": "platformio-debug", "request": "launch", "name": "PIO Debug (without uploading)", - "executable": "/home/kymkim/Projects/modular-kbd/firmware/components/mainboard/stmf446retx/.pio/build/nucleo_f446re/firmware.elf", + "executable": "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/mainboard/stmf446retx/.pio/build/nucleo_f446re/firmware.elf", "projectEnvName": "nucleo_f446re", "toolchainBinDir": "/home/kymkim/.platformio/packages/toolchain-gccarmnoneeabi/bin", "internalConsoleOptions": "openOnSessionStart", diff --git a/firmware/components/modules/sample_module/.gitignore b/firmware/components/modules/sample_module/.gitignore new file mode 100644 index 00000000..03f4a3c1 --- /dev/null +++ b/firmware/components/modules/sample_module/.gitignore @@ -0,0 +1 @@ +.pio diff --git a/firmware/components/modules/sample_module/.vscode/c_cpp_properties.json b/firmware/components/modules/sample_module/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..1643720a --- /dev/null +++ b/firmware/components/modules/sample_module/.vscode/c_cpp_properties.json @@ -0,0 +1,132 @@ +// +// !!! WARNING !!! AUTO-GENERATED FILE! +// PLEASE DO NOT MODIFY IT AND USE "platformio.ini": +// https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags +// +{ + "configurations": [ + { + "name": "PlatformIO", + "includePath": [ + "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/modules/sample_module/Inc", + "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/modules/sample_module/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/CMSIS/Include", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/CMSIS/Device/ST/STM32F1xx/Include", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/STM32F1xx_HAL_Driver/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/STM32F1xx_HAL_Driver/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/CMSIS/DSP/Include", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/Common", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/ak4343", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/cs43l22", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/hx8347d", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/ili9320", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/ili9325", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/lis302dl", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/spfd5408", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/st7735", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/stlm75", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/stmpe811", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Adafruit_Shield", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Utilities/CPU", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Utilities/Fonts", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Utilities/Log", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Core/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Core/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Core/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Core/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/AUDIO/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/AUDIO/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Src", + "" + ], + "browse": { + "limitSymbolsToIncludedHeaders": true, + "path": [ + "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/modules/sample_module/Inc", + "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/modules/sample_module/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/CMSIS/Include", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/CMSIS/Device/ST/STM32F1xx/Include", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/STM32F1xx_HAL_Driver/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/STM32F1xx_HAL_Driver/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/CMSIS/DSP/Include", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/Common", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/ak4343", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/cs43l22", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/hx8347d", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/ili9320", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/ili9325", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/lis302dl", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/spfd5408", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/st7735", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/stlm75", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Components/stmpe811", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Drivers/BSP/Adafruit_Shield", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Utilities/CPU", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Utilities/Fonts", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Utilities/Log", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Core/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Core/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Core/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Core/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/AUDIO/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/AUDIO/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Inc", + "/home/kymkim/.platformio/packages/framework-stm32cubef1/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Src", + "" + ] + }, + "defines": [ + "PLATFORMIO=60118", + "STM32F1", + "STM32F103xB", + "USE_HAL_DRIVER", + "F_CPU=72000000L", + "" + ], + "compilerPath": "/home/kymkim/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc", + "compilerArgs": [ + "-mthumb", + "-mcpu=cortex-m3", + "" + ] + } + ], + "version": 4 +} diff --git a/firmware/components/modules/sample_module/.vscode/extensions.json b/firmware/components/modules/sample_module/.vscode/extensions.json new file mode 100644 index 00000000..080e70d0 --- /dev/null +++ b/firmware/components/modules/sample_module/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/firmware/components/modules/sample_module/.vscode/launch.json b/firmware/components/modules/sample_module/.vscode/launch.json new file mode 100644 index 00000000..ecc313b1 --- /dev/null +++ b/firmware/components/modules/sample_module/.vscode/launch.json @@ -0,0 +1,47 @@ +// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY +// +// PlatformIO Debugging Solution +// +// Documentation: https://docs.platformio.org/en/latest/plus/debugging.html +// Configuration: https://docs.platformio.org/en/latest/projectconf/sections/env/options/debug/index.html + +{ + "version": "0.2.0", + "configurations": [ + { + "type": "platformio-debug", + "request": "launch", + "name": "PIO Debug", + "executable": "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/modules/sample_module/.pio/build/bluepill_f103c8/firmware.elf", + "projectEnvName": "bluepill_f103c8", + "toolchainBinDir": "/home/kymkim/.platformio/packages/toolchain-gccarmnoneeabi/bin", + "internalConsoleOptions": "openOnSessionStart", + "svdPath": "/home/kymkim/.platformio/platforms/ststm32/misc/svd/STM32F103xx.svd", + "preLaunchTask": { + "type": "PlatformIO", + "task": "Pre-Debug" + } + }, + { + "type": "platformio-debug", + "request": "launch", + "name": "PIO Debug (skip Pre-Debug)", + "executable": "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/modules/sample_module/.pio/build/bluepill_f103c8/firmware.elf", + "projectEnvName": "bluepill_f103c8", + "toolchainBinDir": "/home/kymkim/.platformio/packages/toolchain-gccarmnoneeabi/bin", + "internalConsoleOptions": "openOnSessionStart", + "svdPath": "/home/kymkim/.platformio/platforms/ststm32/misc/svd/STM32F103xx.svd" + }, + { + "type": "platformio-debug", + "request": "launch", + "name": "PIO Debug (without uploading)", + "executable": "/home/kymkim/Projects/CSULB/modular-kbd/firmware/components/modules/sample_module/.pio/build/bluepill_f103c8/firmware.elf", + "projectEnvName": "bluepill_f103c8", + "toolchainBinDir": "/home/kymkim/.platformio/packages/toolchain-gccarmnoneeabi/bin", + "internalConsoleOptions": "openOnSessionStart", + "svdPath": "/home/kymkim/.platformio/platforms/ststm32/misc/svd/STM32F103xx.svd", + "loadMode": "manual" + } + ] +} diff --git a/firmware/components/modules/sample_module/Inc/can.h b/firmware/components/modules/sample_module/Inc/can.h new file mode 100644 index 00000000..df48ffbd --- /dev/null +++ b/firmware/components/modules/sample_module/Inc/can.h @@ -0,0 +1,52 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file can.h + * @brief This file contains all the function prototypes for + * the can.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __CAN_H__ +#define __CAN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern CAN_HandleTypeDef hcan; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_CAN_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __CAN_H__ */ + diff --git a/firmware/components/modules/sample_module/Inc/gpio.h b/firmware/components/modules/sample_module/Inc/gpio.h new file mode 100644 index 00000000..8ba7de1e --- /dev/null +++ b/firmware/components/modules/sample_module/Inc/gpio.h @@ -0,0 +1,49 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file gpio.h + * @brief This file contains all the function prototypes for + * the gpio.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __GPIO_H__ +#define __GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_GPIO_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif +#endif /*__ GPIO_H__ */ + diff --git a/firmware/components/modules/sample_module/Inc/keycode.h b/firmware/components/modules/sample_module/Inc/keycode.h new file mode 100644 index 00000000..b619fdbd --- /dev/null +++ b/firmware/components/modules/sample_module/Inc/keycode.h @@ -0,0 +1,135 @@ +// Modifier Keys +#define KEY_LEFT_CTRL 0xE0 +#define KEY_LEFT_SHIFT 0xE1 +#define KEY_LEFT_ALT 0xE2 +#define KEY_LEFT_GUI 0xE3 +#define KEY_RIGHT_CTRL 0xE4 +#define KEY_RIGHT_SHIFT 0xE5 +#define KEY_RIGHT_ALT 0xE6 +#define KEY_RIGHT_GUI 0xE7 + +// Regular Keys (Usage ID 0x04–0x73) +#define KEY_A 0x04 +#define KEY_B 0x05 +#define KEY_C 0x06 +#define KEY_D 0x07 +#define KEY_E 0x08 +#define KEY_F 0x09 +#define KEY_G 0x0A +#define KEY_H 0x0B +#define KEY_I 0x0C +#define KEY_J 0x0D +#define KEY_K 0x0E +#define KEY_L 0x0F +#define KEY_M 0x10 +#define KEY_N 0x11 +#define KEY_O 0x12 +#define KEY_P 0x13 +#define KEY_Q 0x14 +#define KEY_R 0x15 +#define KEY_S 0x16 +#define KEY_T 0x17 +#define KEY_U 0x18 +#define KEY_V 0x19 +#define KEY_W 0x1A +#define KEY_X 0x1B +#define KEY_Y 0x1C +#define KEY_Z 0x1D + +#define KEY_1 0x1E +#define KEY_2 0x1F +#define KEY_3 0x20 +#define KEY_4 0x21 +#define KEY_5 0x22 +#define KEY_6 0x23 +#define KEY_7 0x24 +#define KEY_8 0x25 +#define KEY_9 0x26 +#define KEY_0 0x27 + +#define KEY_ENTER 0x28 +#define KEY_ESC 0x29 +#define KEY_BACKSPACE 0x2A +#define KEY_TAB 0x2B +#define KEY_SPACE 0x2C +#define KEY_MINUS 0x2D +#define KEY_EQUAL 0x2E +#define KEY_LEFT_BRACKET 0x2F +#define KEY_RIGHT_BRACKET 0x30 +#define KEY_BACKSLASH 0x31 +#define KEY_NON_US_HASH 0x32 +#define KEY_SEMICOLON 0x33 +#define KEY_APOSTROPHE 0x34 +#define KEY_GRAVE 0x35 +#define KEY_COMMA 0x36 +#define KEY_PERIOD 0x37 +#define KEY_SLASH 0x38 +#define KEY_CAPS_LOCK 0x39 + +// Function Keys +#define KEY_F1 0x3A +#define KEY_F2 0x3B +#define KEY_F3 0x3C +#define KEY_F4 0x3D +#define KEY_F5 0x3E +#define KEY_F6 0x3F +#define KEY_F7 0x40 +#define KEY_F8 0x41 +#define KEY_F9 0x42 +#define KEY_F10 0x43 +#define KEY_F11 0x44 +#define KEY_F12 0x45 + +#define KEY_PRINT_SCREEN 0x46 +#define KEY_SCROLL_LOCK 0x47 +#define KEY_PAUSE 0x48 + +// Navigation Keys +#define KEY_INSERT 0x49 +#define KEY_HOME 0x4A +#define KEY_PAGE_UP 0x4B +#define KEY_DELETE 0x4C +#define KEY_END 0x4D +#define KEY_PAGE_DOWN 0x4E + +#define KEY_RIGHT_ARROW 0x4F +#define KEY_LEFT_ARROW 0x50 +#define KEY_DOWN_ARROW 0x51 +#define KEY_UP_ARROW 0x52 + +// Keypad +#define KEY_NUM_LOCK 0x53 +#define KEYPAD_SLASH 0x54 +#define KEYPAD_ASTERISK 0x55 +#define KEYPAD_MINUS 0x56 +#define KEYPAD_PLUS 0x57 +#define KEYPAD_ENTER 0x58 +#define KEYPAD_1 0x59 +#define KEYPAD_2 0x5A +#define KEYPAD_3 0x5B +#define KEYPAD_4 0x5C +#define KEYPAD_5 0x5D +#define KEYPAD_6 0x5E +#define KEYPAD_7 0x5F +#define KEYPAD_8 0x60 +#define KEYPAD_9 0x61 +#define KEYPAD_0 0x62 +#define KEYPAD_DOT 0x63 + +// Misc/Non-US +#define KEY_NON_US_BACKSLASH 0x64 +#define KEY_APPLICATION 0x65 +#define KEY_POWER 0x66 +#define KEYPAD_EQUAL 0x67 +#define KEY_F13 0x68 +#define KEY_F14 0x69 +#define KEY_F15 0x6A +#define KEY_F16 0x6B +#define KEY_F17 0x6C +#define KEY_F18 0x6D +#define KEY_F19 0x6E +#define KEY_F20 0x6F +#define KEY_F21 0x70 +#define KEY_F22 0x71 +#define KEY_F23 0x72 +#define KEY_F24 0x73 \ No newline at end of file diff --git a/firmware/components/modules/sample_module/Inc/main.h b/firmware/components/modules/sample_module/Inc/main.h new file mode 100644 index 00000000..e371ce56 --- /dev/null +++ b/firmware/components/modules/sample_module/Inc/main.h @@ -0,0 +1,69 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.h + * @brief : Header for main.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @attention + * + * Copyright (c) 2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MAIN_H +#define __MAIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f1xx_hal.h" + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Exported types ------------------------------------------------------------*/ +/* USER CODE BEGIN ET */ + +/* USER CODE END ET */ + +/* Exported constants --------------------------------------------------------*/ +/* USER CODE BEGIN EC */ + +/* USER CODE END EC */ + +/* Exported macro ------------------------------------------------------------*/ +/* USER CODE BEGIN EM */ + +/* USER CODE END EM */ + +/* Exported functions prototypes ---------------------------------------------*/ +void Error_Handler(void); + +/* USER CODE BEGIN EFP */ + +/* USER CODE END EFP */ + +/* Private defines -----------------------------------------------------------*/ + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H */ diff --git a/firmware/components/modules/sample_module/Inc/stm32f1xx_hal_conf.h b/firmware/components/modules/sample_module/Inc/stm32f1xx_hal_conf.h new file mode 100644 index 00000000..51a5d671 --- /dev/null +++ b/firmware/components/modules/sample_module/Inc/stm32f1xx_hal_conf.h @@ -0,0 +1,391 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f1xx_hal_conf.h + * @brief HAL configuration file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2017 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F1xx_HAL_CONF_H +#define __STM32F1xx_HAL_CONF_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ + +/* ########################## Module Selection ############################## */ +/** + * @brief This is the list of modules to be used in the HAL driver + */ + +#define HAL_MODULE_ENABLED + /*#define HAL_ADC_MODULE_ENABLED */ +/*#define HAL_CRYP_MODULE_ENABLED */ +#define HAL_CAN_MODULE_ENABLED +/*#define HAL_CAN_LEGACY_MODULE_ENABLED */ +/*#define HAL_CEC_MODULE_ENABLED */ +/*#define HAL_CORTEX_MODULE_ENABLED */ +/*#define HAL_CRC_MODULE_ENABLED */ +/*#define HAL_DAC_MODULE_ENABLED */ +/*#define HAL_DMA_MODULE_ENABLED */ +/*#define HAL_ETH_MODULE_ENABLED */ +/*#define HAL_FLASH_MODULE_ENABLED */ +#define HAL_GPIO_MODULE_ENABLED +/*#define HAL_I2C_MODULE_ENABLED */ +/*#define HAL_I2S_MODULE_ENABLED */ +/*#define HAL_IRDA_MODULE_ENABLED */ +/*#define HAL_IWDG_MODULE_ENABLED */ +/*#define HAL_NOR_MODULE_ENABLED */ +/*#define HAL_NAND_MODULE_ENABLED */ +/*#define HAL_PCCARD_MODULE_ENABLED */ +/*#define HAL_PCD_MODULE_ENABLED */ +/*#define HAL_HCD_MODULE_ENABLED */ +/*#define HAL_PWR_MODULE_ENABLED */ +/*#define HAL_RCC_MODULE_ENABLED */ +/*#define HAL_RTC_MODULE_ENABLED */ +/*#define HAL_SD_MODULE_ENABLED */ +/*#define HAL_MMC_MODULE_ENABLED */ +/*#define HAL_SDRAM_MODULE_ENABLED */ +/*#define HAL_SMARTCARD_MODULE_ENABLED */ +/*#define HAL_SPI_MODULE_ENABLED */ +/*#define HAL_SRAM_MODULE_ENABLED */ +/*#define HAL_TIM_MODULE_ENABLED */ +/*#define HAL_UART_MODULE_ENABLED */ +/*#define HAL_USART_MODULE_ENABLED */ +/*#define HAL_WWDG_MODULE_ENABLED */ + +#define HAL_CORTEX_MODULE_ENABLED +#define HAL_DMA_MODULE_ENABLED +#define HAL_FLASH_MODULE_ENABLED +#define HAL_EXTI_MODULE_ENABLED +#define HAL_GPIO_MODULE_ENABLED +#define HAL_PWR_MODULE_ENABLED +#define HAL_RCC_MODULE_ENABLED + +/* ########################## Oscillator Values adaptation ####################*/ +/** + * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSE is used as system clock source, directly or through the PLL). + */ +#if !defined (HSE_VALUE) + #define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ + +/** + * @brief Internal High Speed oscillator (HSI) value. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSI is used as system clock source, directly or through the PLL). + */ +#if !defined (HSI_VALUE) + #define HSI_VALUE 8000000U /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) + #define LSI_VALUE 40000U /*!< LSI Typical Value in Hz */ +#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz + The real value may vary depending on the variations + in voltage and temperature. */ + +/** + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) + #define LSE_VALUE 32768U /*!< Value of the External oscillator in Hz*/ +#endif /* LSE_VALUE */ + +#if !defined (LSE_STARTUP_TIMEOUT) + #define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ + +/* Tip: To avoid modifying this file each time you need to use different HSE, + === you can define the HSE value in your toolchain compiler preprocessor. */ + +/* ########################### System Configuration ######################### */ +/** + * @brief This is the HAL system configuration section + */ +#define VDD_VALUE 3300U /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY 15U /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 1U + +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */ +#define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */ +#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */ +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */ +#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */ +#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */ +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */ +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */ +#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */ +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */ +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */ +#define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */ +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */ +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */ +#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */ +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */ +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */ +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */ +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */ +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */ +#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */ +#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */ +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */ + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +/* #define USE_FULL_ASSERT 1U */ + +/* ################## Ethernet peripheral configuration ##################### */ + +/* Section 1 : Ethernet peripheral configuration */ + +/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ +#define MAC_ADDR0 2U +#define MAC_ADDR1 0U +#define MAC_ADDR2 0U +#define MAC_ADDR3 0U +#define MAC_ADDR4 0U +#define MAC_ADDR5 0U + +/* Definition of the Ethernet driver buffers size and count */ +#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ +#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ +#define ETH_RXBUFNB 8U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ +#define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ + +/* Section 2: PHY configuration section */ + +/* DP83848_PHY_ADDRESS Address*/ +#define DP83848_PHY_ADDRESS 0x01U +/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ +#define PHY_RESET_DELAY 0x000000FFU +/* PHY Configuration delay */ +#define PHY_CONFIG_DELAY 0x00000FFFU + +#define PHY_READ_TO 0x0000FFFFU +#define PHY_WRITE_TO 0x0000FFFFU + +/* Section 3: Common PHY Registers */ + +#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */ +#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */ + +#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */ +#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */ +#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */ +#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */ +#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */ +#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */ +#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */ +#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */ +#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */ +#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */ + +#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */ +#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */ +#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */ + +/* Section 4: Extended PHY Registers */ +#define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */ + +#define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */ +#define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */ + +/* ################## SPI peripheral configuration ########################## */ + +/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver +* Activated: CRC code is present inside driver +* Deactivated: CRC code cleaned from driver +*/ + +#define USE_SPI_CRC 0U + +/* Includes ------------------------------------------------------------------*/ +/** + * @brief Include module's header file + */ + +#ifdef HAL_RCC_MODULE_ENABLED +#include "stm32f1xx_hal_rcc.h" +#endif /* HAL_RCC_MODULE_ENABLED */ + +#ifdef HAL_GPIO_MODULE_ENABLED +#include "stm32f1xx_hal_gpio.h" +#endif /* HAL_GPIO_MODULE_ENABLED */ + +#ifdef HAL_EXTI_MODULE_ENABLED +#include "stm32f1xx_hal_exti.h" +#endif /* HAL_EXTI_MODULE_ENABLED */ + +#ifdef HAL_DMA_MODULE_ENABLED +#include "stm32f1xx_hal_dma.h" +#endif /* HAL_DMA_MODULE_ENABLED */ + +#ifdef HAL_ETH_MODULE_ENABLED +#include "stm32f1xx_hal_eth.h" +#endif /* HAL_ETH_MODULE_ENABLED */ + +#ifdef HAL_CAN_MODULE_ENABLED +#include "stm32f1xx_hal_can.h" +#endif /* HAL_CAN_MODULE_ENABLED */ + +#ifdef HAL_CAN_LEGACY_MODULE_ENABLED + #include "Legacy/stm32f1xx_hal_can_legacy.h" +#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */ + +#ifdef HAL_CEC_MODULE_ENABLED +#include "stm32f1xx_hal_cec.h" +#endif /* HAL_CEC_MODULE_ENABLED */ + +#ifdef HAL_CORTEX_MODULE_ENABLED +#include "stm32f1xx_hal_cortex.h" +#endif /* HAL_CORTEX_MODULE_ENABLED */ + +#ifdef HAL_ADC_MODULE_ENABLED +#include "stm32f1xx_hal_adc.h" +#endif /* HAL_ADC_MODULE_ENABLED */ + +#ifdef HAL_CRC_MODULE_ENABLED +#include "stm32f1xx_hal_crc.h" +#endif /* HAL_CRC_MODULE_ENABLED */ + +#ifdef HAL_DAC_MODULE_ENABLED +#include "stm32f1xx_hal_dac.h" +#endif /* HAL_DAC_MODULE_ENABLED */ + +#ifdef HAL_FLASH_MODULE_ENABLED +#include "stm32f1xx_hal_flash.h" +#endif /* HAL_FLASH_MODULE_ENABLED */ + +#ifdef HAL_SRAM_MODULE_ENABLED +#include "stm32f1xx_hal_sram.h" +#endif /* HAL_SRAM_MODULE_ENABLED */ + +#ifdef HAL_NOR_MODULE_ENABLED +#include "stm32f1xx_hal_nor.h" +#endif /* HAL_NOR_MODULE_ENABLED */ + +#ifdef HAL_I2C_MODULE_ENABLED +#include "stm32f1xx_hal_i2c.h" +#endif /* HAL_I2C_MODULE_ENABLED */ + +#ifdef HAL_I2S_MODULE_ENABLED +#include "stm32f1xx_hal_i2s.h" +#endif /* HAL_I2S_MODULE_ENABLED */ + +#ifdef HAL_IWDG_MODULE_ENABLED +#include "stm32f1xx_hal_iwdg.h" +#endif /* HAL_IWDG_MODULE_ENABLED */ + +#ifdef HAL_PWR_MODULE_ENABLED +#include "stm32f1xx_hal_pwr.h" +#endif /* HAL_PWR_MODULE_ENABLED */ + +#ifdef HAL_RTC_MODULE_ENABLED +#include "stm32f1xx_hal_rtc.h" +#endif /* HAL_RTC_MODULE_ENABLED */ + +#ifdef HAL_PCCARD_MODULE_ENABLED +#include "stm32f1xx_hal_pccard.h" +#endif /* HAL_PCCARD_MODULE_ENABLED */ + +#ifdef HAL_SD_MODULE_ENABLED +#include "stm32f1xx_hal_sd.h" +#endif /* HAL_SD_MODULE_ENABLED */ + +#ifdef HAL_NAND_MODULE_ENABLED +#include "stm32f1xx_hal_nand.h" +#endif /* HAL_NAND_MODULE_ENABLED */ + +#ifdef HAL_SPI_MODULE_ENABLED +#include "stm32f1xx_hal_spi.h" +#endif /* HAL_SPI_MODULE_ENABLED */ + +#ifdef HAL_TIM_MODULE_ENABLED +#include "stm32f1xx_hal_tim.h" +#endif /* HAL_TIM_MODULE_ENABLED */ + +#ifdef HAL_UART_MODULE_ENABLED +#include "stm32f1xx_hal_uart.h" +#endif /* HAL_UART_MODULE_ENABLED */ + +#ifdef HAL_USART_MODULE_ENABLED +#include "stm32f1xx_hal_usart.h" +#endif /* HAL_USART_MODULE_ENABLED */ + +#ifdef HAL_IRDA_MODULE_ENABLED +#include "stm32f1xx_hal_irda.h" +#endif /* HAL_IRDA_MODULE_ENABLED */ + +#ifdef HAL_SMARTCARD_MODULE_ENABLED +#include "stm32f1xx_hal_smartcard.h" +#endif /* HAL_SMARTCARD_MODULE_ENABLED */ + +#ifdef HAL_WWDG_MODULE_ENABLED +#include "stm32f1xx_hal_wwdg.h" +#endif /* HAL_WWDG_MODULE_ENABLED */ + +#ifdef HAL_PCD_MODULE_ENABLED +#include "stm32f1xx_hal_pcd.h" +#endif /* HAL_PCD_MODULE_ENABLED */ + +#ifdef HAL_HCD_MODULE_ENABLED +#include "stm32f1xx_hal_hcd.h" +#endif /* HAL_HCD_MODULE_ENABLED */ + +#ifdef HAL_MMC_MODULE_ENABLED +#include "stm32f1xx_hal_mmc.h" +#endif /* HAL_MMC_MODULE_ENABLED */ + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr If expr is false, it calls assert_failed function + * which reports the name of the source file and the source + * line number of the call that failed. + * If expr is true, it returns no value. + * @retval None + */ +#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ +void assert_failed(uint8_t* file, uint32_t line); +#else +#define assert_param(expr) ((void)0U) +#endif /* USE_FULL_ASSERT */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F1xx_HAL_CONF_H */ + diff --git a/firmware/components/modules/sample_module/Inc/stm32f1xx_it.h b/firmware/components/modules/sample_module/Inc/stm32f1xx_it.h new file mode 100644 index 00000000..792479be --- /dev/null +++ b/firmware/components/modules/sample_module/Inc/stm32f1xx_it.h @@ -0,0 +1,67 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f1xx_it.h + * @brief This file contains the headers of the interrupt handlers. + ****************************************************************************** + * @attention + * + * Copyright (c) 2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F1xx_IT_H +#define __STM32F1xx_IT_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Exported types ------------------------------------------------------------*/ +/* USER CODE BEGIN ET */ + +/* USER CODE END ET */ + +/* Exported constants --------------------------------------------------------*/ +/* USER CODE BEGIN EC */ + +/* USER CODE END EC */ + +/* Exported macro ------------------------------------------------------------*/ +/* USER CODE BEGIN EM */ + +/* USER CODE END EM */ + +/* Exported functions prototypes ---------------------------------------------*/ +void NMI_Handler(void); +void HardFault_Handler(void); +void MemManage_Handler(void); +void BusFault_Handler(void); +void UsageFault_Handler(void); +void SVC_Handler(void); +void DebugMon_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void USB_LP_CAN1_RX0_IRQHandler(void); +/* USER CODE BEGIN EFP */ + +/* USER CODE END EFP */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F1xx_IT_H */ diff --git a/firmware/components/modules/sample_module/Src/can.c b/firmware/components/modules/sample_module/Src/can.c new file mode 100644 index 00000000..64bc0c84 --- /dev/null +++ b/firmware/components/modules/sample_module/Src/can.c @@ -0,0 +1,122 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file can.c + * @brief This file provides code for the configuration + * of the CAN instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "can.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +CAN_HandleTypeDef hcan; + +/* CAN init function */ +void MX_CAN_Init(void) +{ + + /* USER CODE BEGIN CAN_Init 0 */ + + /* USER CODE END CAN_Init 0 */ + + /* USER CODE BEGIN CAN_Init 1 */ + + /* USER CODE END CAN_Init 1 */ + hcan.Instance = CAN1; + hcan.Init.Prescaler = 18; + hcan.Init.Mode = CAN_MODE_NORMAL; + hcan.Init.SyncJumpWidth = CAN_SJW_1TQ; + hcan.Init.TimeSeg1 = CAN_BS1_13TQ; + hcan.Init.TimeSeg2 = CAN_BS2_2TQ; + hcan.Init.TimeTriggeredMode = DISABLE; + hcan.Init.AutoBusOff = DISABLE; + hcan.Init.AutoWakeUp = DISABLE; + hcan.Init.AutoRetransmission = DISABLE; + hcan.Init.ReceiveFifoLocked = DISABLE; + hcan.Init.TransmitFifoPriority = DISABLE; + if (HAL_CAN_Init(&hcan) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN CAN_Init 2 */ + /* USER CODE END CAN_Init 2 */ + +} + +void HAL_CAN_MspInit(CAN_HandleTypeDef* canHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(canHandle->Instance==CAN1) + { + /* USER CODE BEGIN CAN1_MspInit 0 */ + + /* USER CODE END CAN1_MspInit 0 */ + /* CAN1 clock enable */ + __HAL_RCC_CAN1_CLK_ENABLE(); + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**CAN GPIO Configuration + PB8 ------> CAN_RX + PB9 ------> CAN_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = GPIO_PIN_9; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + __HAL_AFIO_REMAP_CAN1_2(); + /* USER CODE BEGIN CAN1_MspInit 1 */ + + /* USER CODE END CAN1_MspInit 1 */ + } +} + +void HAL_CAN_MspDeInit(CAN_HandleTypeDef* canHandle) +{ + + if(canHandle->Instance==CAN1) + { + /* USER CODE BEGIN CAN1_MspDeInit 0 */ + + /* USER CODE END CAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_CAN1_CLK_DISABLE(); + + /**CAN GPIO Configuration + PB8 ------> CAN_RX + PB9 ------> CAN_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); + + /* CAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(CAN1_RX1_IRQn); + /* USER CODE BEGIN CAN1_MspDeInit 1 */ + + /* USER CODE END CAN1_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/firmware/components/modules/sample_module/Src/gpio.c b/firmware/components/modules/sample_module/Src/gpio.c new file mode 100644 index 00000000..8b6ba70b --- /dev/null +++ b/firmware/components/modules/sample_module/Src/gpio.c @@ -0,0 +1,72 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file gpio.c + * @brief This file provides code for the configuration + * of all used GPIO pins. + ****************************************************************************** + * @attention + * + * Copyright (c) 2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "gpio.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/*----------------------------------------------------------------------------*/ +/* Configure GPIO */ +/*----------------------------------------------------------------------------*/ +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + +/** Configure pins as + * Analog + * Input + * Output + * EVENT_OUT + * EXTI +*/ +void MX_GPIO_Init(void) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOD_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET); + + /*Configure GPIO pins : PB12 PB13 */ + GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /*Configure GPIO pins : PB14 PB15 */ + GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + +} + +/* USER CODE BEGIN 2 */ + +/* USER CODE END 2 */ diff --git a/firmware/components/modules/sample_module/Src/main.c b/firmware/components/modules/sample_module/Src/main.c new file mode 100644 index 00000000..6568dec6 --- /dev/null +++ b/firmware/components/modules/sample_module/Src/main.c @@ -0,0 +1,233 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.c + * @brief : Main program body + ****************************************************************************** + * @attention + * + * Copyright (c) 2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "main.h" +#include "can.h" +#include "gpio.h" +#include "keycode.h" +#include +#include + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN PTD */ +typedef struct{ + GPIO_TypeDef* PORT; + uint16_t PIN; +} KbdPins; +/* USER CODE END PTD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN PD */ + +/* USER CODE END PD */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN PM */ +#define COLS 2 +#define ROWS 2 +/* USER CODE END PM */ + +/* Private variables ---------------------------------------------------------*/ + +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +void SystemClock_Config(void); +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* Private user code ---------------------------------------------------------*/ +/* USER CODE BEGIN 0 */ + +CAN_TxHeaderTypeDef TxHeader; + +uint8_t TxData[8]; +uint32_t TxMailbox; + +uint8_t matrix[ROWS][COLS] = { + {KEY_M, KEY_K}, + {KEY_I, KEY_U} +}; +KbdPins row_pins[ROWS] = { + {GPIOB, GPIO_PIN_12}, + {GPIOB, GPIO_PIN_13} +}; +KbdPins col_pins[COLS] = { + {GPIOB, GPIO_PIN_14}, + {GPIOB, GPIO_PIN_15} +}; +bool matrix_state[2][2] = {false}; +bool last_state[2][2] = {false}; + +/* USER CODE END 0 */ + +/** + * @brief The application entry point. + * @retval int + */ +int main(void) +{ + + /* USER CODE BEGIN 1 */ + + /* USER CODE END 1 */ + + /* MCU Configuration--------------------------------------------------------*/ + + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); + + /* USER CODE BEGIN Init */ + + /* USER CODE END Init */ + + /* Configure the system clock */ + SystemClock_Config(); + + /* USER CODE BEGIN SysInit */ + + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_CAN_Init(); + /* USER CODE BEGIN 2 */ + HAL_CAN_Start(&hcan); + HAL_Delay(50); + + TxHeader.DLC = 2; + TxHeader.IDE = CAN_ID_STD; + TxHeader.RTR = CAN_RTR_DATA; + TxHeader.StdId = 0x100; + + TxData[0] = 0x00; + TxData[1] = 0x00; + + + /* USER CODE END 2 */ + + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ + while (1) + { + /* USER CODE END WHILE */ + + //Matrix Scan + for(int col = 0; col < COLS; col++){ + HAL_GPIO_WritePin(col_pins[col].PORT, col_pins[col].PIN, GPIO_PIN_SET); + for(int row = 0; row < ROWS; row++){ + bool pressed = HAL_GPIO_ReadPin(row_pins[row].PORT, row_pins[row].PIN); + if(pressed != last_state[row][col]){ + last_state[row][col] = pressed; + TxData[1] = pressed ? 0x01:0x00; + TxData[0] = matrix[row][col]; + HAL_CAN_AddTxMessage(&hcan, &TxHeader, TxData, &TxMailbox); + memset(TxData,0,sizeof(TxData)); + } + } + HAL_GPIO_WritePin(col_pins[col].PORT, col_pins[col].PIN, GPIO_PIN_RESET); + } + HAL_Delay(20); + /* USER CODE BEGIN 3 */ + } + /* USER CODE END 3 */ +} + +/** + * @brief System Clock Configuration + * @retval None + */ +void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { + Error_Handler(); + } + + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK + |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) + { + Error_Handler(); + } +} + +/* USER CODE BEGIN 4 */ + +/* USER CODE END 4 */ + +/** + * @brief This function is executed in case of error occurrence. + * @retval None + */ +void Error_Handler(void) +{ + /* USER CODE BEGIN Error_Handler_Debug */ + /* User can add his own implementation to report the HAL error return state */ + __disable_irq(); + while (1) + { + } + /* USER CODE END Error_Handler_Debug */ +} + +#ifdef USE_FULL_ASSERT +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ +void assert_failed(uint8_t *file, uint32_t line) +{ + /* USER CODE BEGIN 6 */ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + /* USER CODE END 6 */ +} +#endif /* USE_FULL_ASSERT */ diff --git a/firmware/components/modules/sample_module/Src/stm32f1xx_hal_msp.c b/firmware/components/modules/sample_module/Src/stm32f1xx_hal_msp.c new file mode 100644 index 00000000..bcfdc02b --- /dev/null +++ b/firmware/components/modules/sample_module/Src/stm32f1xx_hal_msp.c @@ -0,0 +1,86 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f1xx_hal_msp.c + * @brief This file provides code for the MSP Initialization + * and de-Initialization codes. + ****************************************************************************** + * @attention + * + * Copyright (c) 2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN TD */ + +/* USER CODE END TD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN Define */ + +/* USER CODE END Define */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN Macro */ + +/* USER CODE END Macro */ + +/* Private variables ---------------------------------------------------------*/ +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* External functions --------------------------------------------------------*/ +/* USER CODE BEGIN ExternalFunctions */ + +/* USER CODE END ExternalFunctions */ + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ +/** + * Initializes the Global MSP. + */ +void HAL_MspInit(void) +{ + + /* USER CODE BEGIN MspInit 0 */ + + /* USER CODE END MspInit 0 */ + + __HAL_RCC_AFIO_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); + + /* System interrupt init*/ + + /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled + */ + __HAL_AFIO_REMAP_SWJ_NOJTAG(); + + /* USER CODE BEGIN MspInit 1 */ + + /* USER CODE END MspInit 1 */ +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/firmware/components/modules/sample_module/Src/stm32f1xx_it.c b/firmware/components/modules/sample_module/Src/stm32f1xx_it.c new file mode 100644 index 00000000..c9c54c5c --- /dev/null +++ b/firmware/components/modules/sample_module/Src/stm32f1xx_it.c @@ -0,0 +1,217 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f1xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @attention + * + * Copyright (c) 2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" +#include "stm32f1xx_it.h" +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN TD */ + +/* USER CODE END TD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN PD */ + +/* USER CODE END PD */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN PM */ + +/* USER CODE END PM */ + +/* Private variables ---------------------------------------------------------*/ +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* Private user code ---------------------------------------------------------*/ +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/* External variables --------------------------------------------------------*/ +extern CAN_HandleTypeDef hcan; +/* USER CODE BEGIN EV */ + +/* USER CODE END EV */ + +/******************************************************************************/ +/* Cortex-M3 Processor Interruption and Exception Handlers */ +/******************************************************************************/ +/** + * @brief This function handles Non maskable interrupt. + */ +void NMI_Handler(void) +{ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + while (1) + { + } + /* USER CODE END NonMaskableInt_IRQn 1 */ +} + +/** + * @brief This function handles Hard fault interrupt. + */ +void HardFault_Handler(void) +{ + /* USER CODE BEGIN HardFault_IRQn 0 */ + + /* USER CODE END HardFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_HardFault_IRQn 0 */ + /* USER CODE END W1_HardFault_IRQn 0 */ + } +} + +/** + * @brief This function handles Memory management fault. + */ +void MemManage_Handler(void) +{ + /* USER CODE BEGIN MemoryManagement_IRQn 0 */ + + /* USER CODE END MemoryManagement_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ + /* USER CODE END W1_MemoryManagement_IRQn 0 */ + } +} + +/** + * @brief This function handles Prefetch fault, memory access fault. + */ +void BusFault_Handler(void) +{ + /* USER CODE BEGIN BusFault_IRQn 0 */ + + /* USER CODE END BusFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_BusFault_IRQn 0 */ + /* USER CODE END W1_BusFault_IRQn 0 */ + } +} + +/** + * @brief This function handles Undefined instruction or illegal state. + */ +void UsageFault_Handler(void) +{ + /* USER CODE BEGIN UsageFault_IRQn 0 */ + + /* USER CODE END UsageFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ + /* USER CODE END W1_UsageFault_IRQn 0 */ + } +} + +/** + * @brief This function handles System service call via SWI instruction. + */ +void SVC_Handler(void) +{ + /* USER CODE BEGIN SVCall_IRQn 0 */ + + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ + + /* USER CODE END SVCall_IRQn 1 */ +} + +/** + * @brief This function handles Debug monitor. + */ +void DebugMon_Handler(void) +{ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + + /* USER CODE END DebugMonitor_IRQn 1 */ +} + +/** + * @brief This function handles Pendable request for system service. + */ +void PendSV_Handler(void) +{ + /* USER CODE BEGIN PendSV_IRQn 0 */ + + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ + + /* USER CODE END PendSV_IRQn 1 */ +} + +/** + * @brief This function handles System tick timer. + */ +void SysTick_Handler(void) +{ + /* USER CODE BEGIN SysTick_IRQn 0 */ + + /* USER CODE END SysTick_IRQn 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ + + /* USER CODE END SysTick_IRQn 1 */ +} + +/******************************************************************************/ +/* STM32F1xx Peripheral Interrupt Handlers */ +/* Add here the Interrupt Handlers for the used peripherals. */ +/* For the available peripheral interrupt handler names, */ +/* please refer to the startup file (startup_stm32f1xx.s). */ +/******************************************************************************/ + +/** + * @brief This function handles USB low priority or CAN RX0 interrupts. + */ +void USB_LP_CAN1_RX0_IRQHandler(void) +{ + /* USER CODE BEGIN USB_LP_CAN1_RX0_IRQn 0 */ + + /* USER CODE END USB_LP_CAN1_RX0_IRQn 0 */ + HAL_CAN_IRQHandler(&hcan); + /* USER CODE BEGIN USB_LP_CAN1_RX0_IRQn 1 */ + + /* USER CODE END USB_LP_CAN1_RX0_IRQn 1 */ +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/firmware/components/modules/sample_module/lib/README b/firmware/components/modules/sample_module/lib/README new file mode 100644 index 00000000..93793971 --- /dev/null +++ b/firmware/components/modules/sample_module/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into the executable file. + +The source code of each library should be placed in a separate directory +("lib/your_library_name/[Code]"). + +For example, see the structure of the following example libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Example contents of `src/main.c` using Foo and Bar: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +The PlatformIO Library Dependency Finder will find automatically dependent +libraries by scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/firmware/components/modules/sample_module/platformio.ini b/firmware/components/modules/sample_module/platformio.ini new file mode 100644 index 00000000..5caa7100 --- /dev/null +++ b/firmware/components/modules/sample_module/platformio.ini @@ -0,0 +1,20 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:bluepill_f103c8] +platform = ststm32 +board = bluepill_f103c8 +framework = stm32cube +board_build.stm32cube.custom_config_header = yes +upload_protocol = stlink + +[platformio] +include_dir = Inc +src_dir = Src diff --git a/firmware/components/modules/sample_module/sample_module.ioc b/firmware/components/modules/sample_module/sample_module.ioc new file mode 100644 index 00000000..6e016b6d --- /dev/null +++ b/firmware/components/modules/sample_module/sample_module.ioc @@ -0,0 +1,132 @@ +#MicroXplorer Configuration settings - do not modify +CAD.formats= +CAD.pinconfig= +CAD.provider= +CAN.BS1=CAN_BS1_13TQ +CAN.BS2=CAN_BS2_2TQ +CAN.CalculateBaudRate=125000 +CAN.CalculateTimeBit=8000 +CAN.CalculateTimeQuantum=500.0 +CAN.IPParameters=CalculateTimeQuantum,CalculateTimeBit,CalculateBaudRate,Prescaler,BS1,BS2 +CAN.Prescaler=18 +File.Version=6 +GPIO.groupedBy= +KeepUserPlacement=false +Mcu.CPN=STM32F103C8T6 +Mcu.Family=STM32F1 +Mcu.IP0=CAN +Mcu.IP1=NVIC +Mcu.IP2=RCC +Mcu.IP3=SYS +Mcu.IPNb=4 +Mcu.Name=STM32F103C(8-B)Tx +Mcu.Package=LQFP48 +Mcu.Pin0=PD0-OSC_IN +Mcu.Pin1=PD1-OSC_OUT +Mcu.Pin10=VP_SYS_VS_Systick +Mcu.Pin2=PB12 +Mcu.Pin3=PB13 +Mcu.Pin4=PB14 +Mcu.Pin5=PB15 +Mcu.Pin6=PA11 +Mcu.Pin7=PA12 +Mcu.Pin8=PA13 +Mcu.Pin9=PA14 +Mcu.PinsNb=11 +Mcu.ThirdPartyNb=0 +Mcu.UserConstants= +Mcu.UserName=STM32F103C8Tx +MxCube.Version=6.13.0 +MxDb.Version=DB.6.0.130 +NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.ForceEnableDMAVector=true +NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 +NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false +NVIC.USB_LP_CAN1_RX0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true +NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +PA11.Mode=CAN_Activate +PA11.Signal=CAN_RX +PA12.Mode=CAN_Activate +PA12.Signal=CAN_TX +PA13.Mode=Serial_Wire +PA13.Signal=SYS_JTMS-SWDIO +PA14.Mode=Serial_Wire +PA14.Signal=SYS_JTCK-SWCLK +PB12.GPIOParameters=GPIO_PuPd +PB12.GPIO_PuPd=GPIO_PULLDOWN +PB12.Locked=true +PB12.Signal=GPIO_Input +PB13.GPIOParameters=GPIO_PuPd +PB13.GPIO_PuPd=GPIO_PULLDOWN +PB13.Locked=true +PB13.Signal=GPIO_Input +PB14.Locked=true +PB14.Signal=GPIO_Output +PB15.Locked=true +PB15.Signal=GPIO_Output +PD0-OSC_IN.Mode=HSE-External-Oscillator +PD0-OSC_IN.Signal=RCC_OSC_IN +PD1-OSC_OUT.Mode=HSE-External-Oscillator +PD1-OSC_OUT.Signal=RCC_OSC_OUT +PinOutPanel.RotationAngle=0 +ProjectManager.AskForMigrate=true +ProjectManager.BackupPrevious=false +ProjectManager.CompilerOptimize=6 +ProjectManager.ComputerToolchain=false +ProjectManager.CoupleFile=true +ProjectManager.CustomerFirmwarePackage= +ProjectManager.DefaultFWLocation=true +ProjectManager.DeletePrevious=true +ProjectManager.DeviceId=STM32F103C8Tx +ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.6 +ProjectManager.FreePins=false +ProjectManager.HalAssertFull=false +ProjectManager.HeapSize=0x200 +ProjectManager.KeepUserCode=true +ProjectManager.LastFirmware=true +ProjectManager.LibraryCopy=2 +ProjectManager.MainLocation=Core/Src +ProjectManager.NoMain=false +ProjectManager.PreviousToolchain= +ProjectManager.ProjectBuild=false +ProjectManager.ProjectFileName=sample_module.ioc +ProjectManager.ProjectName=sample_module +ProjectManager.ProjectStructure= +ProjectManager.RegisterCallBack= +ProjectManager.StackSize=0x400 +ProjectManager.TargetToolchain=CMake +ProjectManager.ToolChainLocation= +ProjectManager.UAScriptAfterPath= +ProjectManager.UAScriptBeforePath= +ProjectManager.UnderRoot=false +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_CAN_Init-CAN-false-HAL-true +RCC.ADCFreqValue=36000000 +RCC.AHBFreq_Value=72000000 +RCC.APB1CLKDivider=RCC_HCLK_DIV2 +RCC.APB1Freq_Value=36000000 +RCC.APB1TimFreq_Value=72000000 +RCC.APB2Freq_Value=72000000 +RCC.APB2TimFreq_Value=72000000 +RCC.FCLKCortexFreq_Value=72000000 +RCC.FamilyName=M +RCC.HCLKFreq_Value=72000000 +RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PLLSourceVirtual,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,VCOOutput2Freq_Value +RCC.MCOFreq_Value=72000000 +RCC.PLLCLKFreq_Value=72000000 +RCC.PLLMCOFreq_Value=36000000 +RCC.PLLMUL=RCC_PLL_MUL9 +RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE +RCC.SYSCLKFreq_VALUE=72000000 +RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK +RCC.TimSysFreq_Value=72000000 +RCC.USBFreq_Value=72000000 +RCC.VCOOutput2Freq_Value=8000000 +VP_SYS_VS_Systick.Mode=SysTick +VP_SYS_VS_Systick.Signal=SYS_VS_Systick +board=custom diff --git a/firmware/components/modules/sample_module/stm32pio.ini b/firmware/components/modules/sample_module/stm32pio.ini new file mode 100644 index 00000000..7f889fd4 --- /dev/null +++ b/firmware/components/modules/sample_module/stm32pio.ini @@ -0,0 +1,19 @@ +[app] +platformio_cmd = platformio +cubemx_cmd = /opt/stm32cubemx/STM32CubeMX +java_cmd = java + +[project] +cubemx_script_content = config load ${ioc_file_absolute_path} + generate code ${project_dir_absolute_path} + exit +platformio_ini_patch_content = [platformio] + include_dir = Inc + src_dir = Src +board = bluepill_f103c8 +ioc_file = sample_module.ioc +cleanup_ignore = sample_module.ioc +cleanup_use_git = False +inspect_ioc = True +last_error = + diff --git a/firmware/components/modules/sample_module/test/README b/firmware/components/modules/sample_module/test/README new file mode 100644 index 00000000..9b1e87bc --- /dev/null +++ b/firmware/components/modules/sample_module/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html