├── .mailmap ├── gdb_oocd.cmds ├── libs ├── STM32_HAL │ ├── include │ │ ├── cmsis │ │ │ ├── device │ │ │ │ ├── stm32f0xx.h │ │ │ │ ├── stm32f4xx.h │ │ │ │ ├── stm32f042x6.h │ │ │ │ ├── stm32f072xb.h │ │ │ │ ├── system_stm32g0xx.h │ │ │ │ ├── system_stm32f0xx.h │ │ │ │ ├── system_stm32f4xx.h │ │ │ │ └── stm32g0xx.h │ │ │ ├── cmsis_device.h │ │ │ ├── cmsis_version.h │ │ │ └── cmsis_compiler.h │ │ ├── stm32f4xx │ │ │ ├── stm32f4xx_hal_flash_ramfunc.h │ │ │ ├── stm32f4xx_hal_pcd_ex.h │ │ │ └── stm32f4xx_hal_def.h │ │ ├── stm32g0xx │ │ │ ├── stm32g0xx_hal_pcd_ex.h │ │ │ ├── stm32g0xx_hal_flash_ex.h │ │ │ └── stm32g0xx_hal_def.h │ │ └── stm32f0xx │ │ │ ├── stm32f0xx_hal_pcd_ex.h │ │ │ ├── stm32f0xx_hal_cortex.h │ │ │ ├── stm32f0xx_hal_def.h │ │ │ └── stm32f0xx_ll_usb.h │ ├── config │ │ └── hal_include.h │ └── CMakeLists.txt └── STM32_USB_Device_Library │ ├── config │ └── usbd_conf.h │ ├── CMakeLists.txt │ └── Core │ ├── Inc │ ├── usbd_ctlreq.h │ ├── usbd_ioreq.h │ └── usbd_core.h │ └── Src │ └── usbd_ioreq.c ├── 70-candle-usb.rules ├── cmake ├── FindDFUSuffix.cmake ├── arm-none-eabi-clang.cmake ├── arm-none-eabi-gcc.cmake ├── gcc-arm-none-eabi-8-2019-q3-update.cmake └── gitversion.cmake ├── .gitignore ├── openocd.cfg ├── .github └── workflows │ ├── pr.yml │ ├── ci.yml │ └── compile.yml ├── .editorconfig ├── src ├── startup.c ├── util.c ├── timer.c ├── dfu.c ├── device │ ├── device_f4.c │ ├── device_g0.c │ └── device_f0.c ├── main.c ├── led.c ├── usbd_desc.c ├── gpio.c ├── can_common.c └── usbd_conf.c ├── include ├── dfu.h ├── timer.h ├── device.h ├── usbd_desc.h ├── util_internal.h ├── can_common.h ├── util_macro.h ├── gpio.h ├── led.h ├── can.h ├── util.h ├── compiler.h └── usbd_gs_can.h ├── LICENSE.md ├── ldscripts └── ldscript_base.inc └── README.md /.mailmap: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /gdb_oocd.cmds: -------------------------------------------------------------------------------- 1 | set remotetimeout 5 2 | target extended-remote | openocd -f openocd.cfg -c "gdb_port pipe; log_output oocd.log" 3 | break main -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f0xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candle-usb/candleLight_fw/HEAD/libs/STM32_HAL/include/cmsis/device/stm32f0xx.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candle-usb/candleLight_fw/HEAD/libs/STM32_HAL/include/cmsis/device/stm32f4xx.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f042x6.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candle-usb/candleLight_fw/HEAD/libs/STM32_HAL/include/cmsis/device/stm32f042x6.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f072xb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/candle-usb/candleLight_fw/HEAD/libs/STM32_HAL/include/cmsis/device/stm32f072xb.h -------------------------------------------------------------------------------- /70-candle-usb.rules: -------------------------------------------------------------------------------- 1 | # Copy this file to /etc/udev/rules.d/ 2 | 3 | # uses OpenMoko VID 4 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="606f", MODE="660", GROUP="users", TAG+="uaccess" 5 | 6 | -------------------------------------------------------------------------------- /cmake/FindDFUSuffix.cmake: -------------------------------------------------------------------------------- 1 | # find and set DFU_SUFFIX_EXECUTABLE 2 | 3 | find_program(DFU_SUFFIX_EXECUTABLE 4 | NAMES dfu-suffix 5 | DOC "dfu-suffix executable" 6 | ) 7 | 8 | mark_as_advanced(DFU_SUFFIX_EXECUTABLE) 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.ccls-cache/ 2 | /.idea/ 3 | /.vscode/ 4 | /Debug/ 5 | /build/ 6 | *.asmo 7 | *.bin 8 | *.d 9 | *.elf 10 | *.launch 11 | *.o 12 | *~ 13 | .cache/ 14 | .cproject 15 | .project 16 | .settings 17 | compile_commands.json 18 | -------------------------------------------------------------------------------- /cmake/arm-none-eabi-clang.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Generic) 2 | set(CMAKE_SYSTEM_PROCESSOR arm) 3 | 4 | set(CMAKE_C_COMPILER clang) 5 | set(CMAKE_C_COMPILER_TARGET arm-none-eabi) 6 | 7 | SET (CMAKE_C_COMPILER_WORKS 1) 8 | SET (CMAKE_CXX_COMPILER_WORKS 1) 9 | -------------------------------------------------------------------------------- /cmake/arm-none-eabi-gcc.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Generic) 2 | set(CMAKE_SYSTEM_PROCESSOR arm) 3 | 4 | set(CMAKE_C_COMPILER arm-none-eabi-gcc) 5 | set(CMAKE_C_COMPILER_TARGET arm-none-eabi) 6 | 7 | SET (CMAKE_C_COMPILER_WORKS 1) 8 | SET (CMAKE_CXX_COMPILER_WORKS 1) 9 | -------------------------------------------------------------------------------- /openocd.cfg: -------------------------------------------------------------------------------- 1 | 2 | #source [find board/stm32f0discovery.cfg] 3 | 4 | source [find interface/stlink-v2.cfg] 5 | transport select hla_swd 6 | source [find target/stm32f0x.cfg] 7 | 8 | set WORKAREASIZE 0x2000 9 | 10 | reset_config srst_only 11 | 12 | #init 13 | #reset init 14 | 15 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/cmsis_device.h: -------------------------------------------------------------------------------- 1 | #ifdef STM32F042x6 2 | #include 3 | #endif 4 | 5 | #ifdef STM32F072xB 6 | #include 7 | #endif 8 | 9 | #ifdef STM32F407xx 10 | #include 11 | #endif 12 | 13 | #ifdef STM32G0B1xx 14 | #include 15 | #endif -------------------------------------------------------------------------------- /.github/workflows/pr.yml: -------------------------------------------------------------------------------- 1 | name: PR 2 | 3 | on: [ pull_request ] 4 | 5 | jobs: 6 | cpp_style_check: 7 | runs-on: ubuntu-latest 8 | name: Check C Styling 9 | steps: 10 | - name: Checkout this commit 11 | uses: actions/checkout@v4 12 | with: 13 | fetch-depth: 2 14 | - name: uncrustify check 15 | uses: Daniel-Trevitz/uncrustify-check@v1 16 | with: 17 | configFile: 'uncrustify.cfg' 18 | checkedPaths: 'src;include' 19 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # Extras : to configure git's pager for tab with of 4: 4 | # $ git config core.pager 'less -x1,5' 5 | # 6 | # to configure optional text mode interface tig: 7 | # $ git config tig.tab-size '4' 8 | 9 | # top-most EditorConfig file 10 | root = true 11 | 12 | # Unix-style newlines with a newline ending every file 13 | [*] 14 | end_of_line = lf 15 | indent_size = 4 16 | indent_style = tab 17 | insert_final_newline = true 18 | trim_trailing_whitespace = true 19 | 20 | [*.yml] 21 | indent_size = 2 22 | indent_style = space 23 | 24 | [lib/**] 25 | indent_size = 2 26 | indent_style = space 27 | -------------------------------------------------------------------------------- /src/startup.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef struct _copy_table_t 6 | { 7 | uint32_t const* src; 8 | uint32_t* dest; 9 | uint32_t wlen; 10 | } copy_table_t; 11 | 12 | extern const copy_table_t __copy_table_start__; 13 | extern const copy_table_t __copy_table_end__; 14 | 15 | void __initialize_hardware_early(void); 16 | void _start(void) __attribute__((noreturn)); 17 | 18 | void Reset_Handler(void) 19 | { 20 | __initialize_hardware_early(); 21 | 22 | for (copy_table_t const* table = &__copy_table_start__; table < &__copy_table_end__; ++table) { 23 | memcpy(table->dest, table->src, table->wlen); 24 | } 25 | 26 | _start(); 27 | } 28 | 29 | void __register_exitproc(void) { 30 | return; 31 | } 32 | 33 | void _exit(int code) 34 | { 35 | (void) code; 36 | __asm__ ("BKPT"); 37 | while (1); 38 | } 39 | -------------------------------------------------------------------------------- /cmake/gcc-arm-none-eabi-8-2019-q3-update.cmake: -------------------------------------------------------------------------------- 1 | set(TOOLCHAIN gcc-arm-none-eabi-8-2019-q3-update) 2 | find_path( 3 | TOOLCHAIN_BIN_DIR 4 | arm-none-eabi-gcc 5 | HINTS 6 | $ENV{HOME}/bin/${TOOLCHAIN}/bin 7 | $ENV{HOME}/opt/${TOOLCHAIN}/bin 8 | /opt/${TOOLCHAIN}/bin 9 | /srv/${TOOLCHAIN}/bin 10 | /usr/local/${TOOLCHAIN}/bin 11 | ENV TOOLCHAIN_BIN_DIR 12 | ) 13 | 14 | set(CMAKE_SYSTEM_NAME Generic) 15 | set(CMAKE_SYSTEM_PROCESSOR arm) 16 | 17 | set(CMAKE_C_COMPILER "${TOOLCHAIN_BIN_DIR}/arm-none-eabi-gcc" CACHE INTERNAL "") 18 | set(CMAKE_CXX_COMPILER "${TOOLCHAIN_BIN_DIR}/arm-none-eabi-g++" CACHE INTERNAL "") 19 | set(CMAKE_EXE_LINKER_FLAGS "" CACHE INTERNAL "") 20 | 21 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 22 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 25 | 26 | SET (CMAKE_C_COMPILER_WORKS 1) 27 | SET (CMAKE_CXX_COMPILER_WORKS 1) 28 | -------------------------------------------------------------------------------- /include/dfu.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | void dfu_run_bootloader(void); 30 | -------------------------------------------------------------------------------- /include/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | void timer_init(void); 32 | uint32_t timer_get(void); 33 | -------------------------------------------------------------------------------- /include/device.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2022 fenugrec 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | */ 28 | 29 | #include "can.h" 30 | #include "hal_include.h" 31 | 32 | void device_can_init(can_data_t *channel, CAN_TypeDef *instance); 33 | 34 | void device_sysclock_config(void); 35 | -------------------------------------------------------------------------------- /include/usbd_desc.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | #include "usbd_conf.h" 31 | #include "usbd_def.h" 32 | 33 | extern const USBD_DescriptorsTypeDef FS_Desc; 34 | extern uint8_t USBD_DescBuf[USBD_DESC_BUF_SIZE]; 35 | -------------------------------------------------------------------------------- /libs/STM32_HAL/config/hal_include.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #if defined(STM32F0) 30 | # include "stm32f0xx_hal.h" 31 | #elif defined(STM32F4) 32 | # include "stm32f4xx_hal.h" 33 | #elif defined(STM32G0) 34 | # include "stm32g0xx_hal.h" 35 | #endif -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | pull_request: 6 | branches: [ master ] 7 | 8 | env: 9 | BUILD_TYPE: Release 10 | CMAKE_TOOLCHAIN_FILE: cmake/gcc-arm-none-eabi-8-2019-q3-update.cmake 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v3 18 | 19 | - name: Install toolchain 20 | run: sudo apt-get -yq install gcc-arm-none-eabi 21 | 22 | - name: Configure CMake 23 | run: | 24 | cmake -B ${{github.workspace}}/build \ 25 | -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \ 26 | -DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/${{env.CMAKE_TOOLCHAIN_FILE}} 27 | 28 | - name: Build 29 | env: 30 | MAKEFLAGS: "-j" 31 | run: | 32 | cmake --build ${{github.workspace}}/build \ 33 | --config ${{env.BUILD_TYPE}} 34 | 35 | - name: Get current date 36 | id: date 37 | run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT 38 | 39 | - name: generate short hash 40 | id: vars 41 | run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT 42 | 43 | - name: Upload dev snapshot 44 | uses: actions/upload-artifact@v4 45 | if: ${{ github.event_name != 'schedule'}} 46 | with: 47 | name: build_${{steps.date.outputs.date}}_${{steps.vars.outputs.sha_short}} 48 | path: ${{github.workspace}}/build/*_fw.bin 49 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # Licenses 2 | 3 | ## candleLight Firmware Sources 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2016 Hubert Denkmair 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ## STM32 HAL 28 | The HAL is distributed under a non-restrictive BSD (Berkeley Software 29 | Distribution) license. 30 | 31 | ## STM32 USB Library 32 | Code from the STM32 USB library is licensed 33 | under ST STMicroelectronics 34 | [Ultimate Liberty license SLA0044] (www.st.com/SLA0044) 35 | -------------------------------------------------------------------------------- /libs/STM32_USB_Device_Library/config/usbd_conf.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "hal_include.h" 30 | 31 | #define USBD_MAX_NUM_INTERFACES 1 32 | #define USBD_MAX_NUM_CONFIGURATION 1 33 | #define USBD_DESC_BUF_SIZE 192 34 | #define USBD_SUPPORT_USER_STRING_DESC 1 35 | #define USBD_SELF_POWERED 0 36 | #define DEVICE_FS 0 37 | 38 | #define USBD_ErrLog(...) 39 | -------------------------------------------------------------------------------- /cmake/gitversion.cmake: -------------------------------------------------------------------------------- 1 | # source: adapted from 2 | # https://www.mattkeeter.com/blog/2018-01-06-versioning/ 3 | 4 | find_package(Git) 5 | 6 | # quoting in execute_process is fragile... cmake encloses every arg with ' ' , but adding any kind of quoting to 7 | # e.g. add spaces in the format string, will not work easily. 8 | 9 | if (Git_FOUND) 10 | execute_process(COMMAND ${GIT_EXECUTABLE} log --pretty=format:fw_%h_%as -n 1 11 | OUTPUT_VARIABLE GIT_REV 12 | ERROR_QUIET 13 | WORKING_DIRECTORY ${SRCDIR} 14 | ) 15 | endif() 16 | 17 | # Check whether we got any revision (which isn't 18 | # always the case, e.g. when someone downloaded a zip 19 | # file from Github instead of a checkout) 20 | if ("${GIT_REV}" STREQUAL "") 21 | set(GIT_REV "N/A") 22 | set(GIT_DIFF "") 23 | set(GIT_TAG "N/A") 24 | else() 25 | execute_process( 26 | COMMAND ${GIT_EXECUTABLE} diff --quiet --exit-code 27 | RESULT_VARIABLE GIT_DIRTY 28 | WORKING_DIRECTORY ${SRCDIR}) 29 | execute_process( 30 | COMMAND git describe --exact-match --tags 31 | OUTPUT_VARIABLE GIT_TAG 32 | ERROR_QUIET 33 | WORKING_DIRECTORY ${SRCDIR}) 34 | if (NOT "${GIT_DIRTY}" EQUAL 0) 35 | #append '+' if unclean tree 36 | set(GIT_DIFF "+") 37 | endif() 38 | 39 | string(STRIP "${GIT_REV}" GIT_REV) 40 | endif() 41 | 42 | set(VERSION "#define GIT_HASH \"${GIT_REV}${GIT_DIFF}\"\n") 43 | 44 | if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version.h) 45 | file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.h VERSION_) 46 | else() 47 | set(VERSION_ "") 48 | endif() 49 | 50 | if (NOT "${VERSION}" STREQUAL "${VERSION_}") 51 | file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/version.h "${VERSION}") 52 | endif() 53 | -------------------------------------------------------------------------------- /src/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | void hex32(char *out, uint32_t val) 31 | { 32 | char *p = out + 8; 33 | 34 | *p-- = 0; 35 | 36 | while (p >= out) { 37 | uint8_t nybble = val & 0x0F; 38 | 39 | if (nybble < 10) 40 | *p = '0' + nybble; 41 | else 42 | *p = 'A' + nybble - 10; 43 | 44 | val >>= 4; 45 | p--; 46 | } 47 | } 48 | 49 | void assert_failed(void) { 50 | /* for now, just halt and trigger debugger (if attached) */ 51 | __BKPT(0); 52 | } 53 | -------------------------------------------------------------------------------- /src/timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include "config.h" 28 | #include "hal_include.h" 29 | #include "timer.h" 30 | 31 | void timer_init(void) 32 | { 33 | __HAL_RCC_TIM2_CLK_ENABLE(); 34 | 35 | TIM2->CR1 = 0; 36 | TIM2->CR2 = 0; 37 | TIM2->SMCR = 0; 38 | TIM2->DIER = 0; 39 | TIM2->CCMR1 = 0; 40 | TIM2->CCMR2 = 0; 41 | TIM2->CCER = 0; 42 | TIM2->PSC = (TIM2_CLOCK_SPEED / 1000000) - 1; // run @1MHz = 1us 43 | TIM2->ARR = 0xFFFFFFFF; 44 | TIM2->CR1 |= TIM_CR1_CEN; 45 | TIM2->EGR = TIM_EGR_UG; 46 | } 47 | 48 | uint32_t timer_get(void) 49 | { 50 | return TIM2->CNT; 51 | } 52 | -------------------------------------------------------------------------------- /include/util_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2014, Wind River Systems, Inc. 3 | * Copyright (c) 2020, Nordic Semiconductor ASA 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | /** 9 | * @file 10 | * @brief Misc utilities 11 | * 12 | * Repetitive or obscure helper macros needed by sys/util.h. 13 | */ 14 | 15 | #ifndef ZEPHYR_INCLUDE_SYS_UTIL_INTERNAL_H_ 16 | #define ZEPHYR_INCLUDE_SYS_UTIL_INTERNAL_H_ 17 | 18 | /* IS_ENABLED() helpers */ 19 | 20 | /* This is called from IS_ENABLED(), and sticks on a "_XXXX" prefix, 21 | * it will now be "_XXXX1" if config_macro is "1", or just "_XXXX" if it's 22 | * undefined. 23 | * ENABLED: Z_IS_ENABLED2(_XXXX1) 24 | * DISABLED Z_IS_ENABLED2(_XXXX) 25 | */ 26 | #define Z_IS_ENABLED1(config_macro) Z_IS_ENABLED2(_XXXX ## config_macro) 27 | 28 | /* Here's the core trick, we map "_XXXX1" to "_YYYY," (i.e. a string 29 | * with a trailing comma), so it has the effect of making this a 30 | * two-argument tuple to the preprocessor only in the case where the 31 | * value is defined to "1" 32 | * ENABLED: _YYYY, <--- note comma! 33 | * DISABLED: _XXXX 34 | */ 35 | #define _XXXX1 _YYYY, 36 | 37 | /* Then we append an extra argument to fool the gcc preprocessor into 38 | * accepting it as a varargs macro. 39 | * arg1 arg2 arg3 40 | * ENABLED: Z_IS_ENABLED3(_YYYY, 1, 0) 41 | * DISABLED Z_IS_ENABLED3(_XXXX 1, 0) 42 | */ 43 | #define Z_IS_ENABLED2(one_or_two_args) Z_IS_ENABLED3(one_or_two_args 1, 0) 44 | 45 | /* And our second argument is thus now cooked to be 1 in the case 46 | * where the value is defined to 1, and 0 if not: 47 | */ 48 | #define Z_IS_ENABLED3(ignore_this, val, ...) val 49 | 50 | #endif /* ZEPHYR_INCLUDE_SYS_UTIL_INTERNAL_H_ */ 51 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /.github/workflows/compile.yml: -------------------------------------------------------------------------------- 1 | name: compile 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-24.04 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | release: 12 | - "ubuntu:20.04" 13 | - "ubuntu:22.04" 14 | - "ubuntu:24.04" 15 | - "ubuntu:rolling" 16 | - "debian:oldstable-slim" 17 | - "debian:stable-slim" 18 | - "debian:testing-slim" 19 | - "debian:unstable-slim" 20 | 21 | steps: 22 | - uses: actions/checkout@v4 23 | 24 | - name: Prepare ${{ matrix.release }} container 25 | run: | 26 | podman version 27 | podman run --name stable -di --userns=keep-id:uid=1000,gid=1000 -v "$PWD":/home -w /home ${{ matrix.release }} bash 28 | podman exec -i stable uname -a 29 | podman exec -i stable id 30 | podman exec -i -u root stable apt update 31 | podman exec -e DEBIAN_FRONTEND='noninteractive' -i -u root stable apt install -o APT::Install-Suggests=false -qy \ 32 | clang \ 33 | cmake \ 34 | gcc-arm-none-eabi \ 35 | git \ 36 | make 37 | 38 | - name: Configure & Build with arm-none-eabi-gcc 39 | env: 40 | toolchain: arm-none-eabi-gcc 41 | run: | 42 | podman exec -i stable cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=cmake/${toolchain}.cmake -B build-${toolchain} 43 | podman exec -i stable cmake --build build-${toolchain} 44 | 45 | - name: Show logs 46 | if: ${{ failure() }} 47 | run: | 48 | for log in build-*/CMakeFiles/{CMakeOutput.log,CMakeConfigureLog.yaml}; do \ 49 | if [ -e ${log} ]; then \ 50 | echo "---------------- ${log} ----------------"; \ 51 | cat ${log}; \ 52 | fi; \ 53 | done 54 | -------------------------------------------------------------------------------- /include/can_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | #include "can.h" 32 | #include "usbd_gs_can.h" 33 | 34 | bool can_check_bittiming_ok(const struct can_bittiming_const *btc, const struct gs_device_bittiming *timing); 35 | #ifdef CONFIG_CAN_FILTER 36 | bool can_check_filter_ok(const struct gs_device_filter *filter); 37 | #else 38 | static inline bool can_check_filter_ok(const struct gs_device_filter *filter) 39 | { 40 | (void)filter; 41 | 42 | return false; 43 | } 44 | #endif 45 | void CAN_SendFrame(USBD_GS_CAN_HandleTypeDef *hcan, can_data_t *channel); 46 | void CAN_ReceiveFrame(USBD_GS_CAN_HandleTypeDef *hcan, can_data_t *channel); 47 | void CAN_HandleError(USBD_GS_CAN_HandleTypeDef *hcan, can_data_t *channel); 48 | -------------------------------------------------------------------------------- /libs/STM32_USB_Device_Library/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(STM32_USB_Device_Library) 2 | 3 | set(SOURCES 4 | Core/Inc/usbd_def.h 5 | Core/Inc/usbd_ctlreq.h 6 | Core/Src/usbd_ctlreq.c 7 | Core/Inc/usbd_ioreq.h 8 | Core/Src/usbd_ioreq.c 9 | Core/Inc/usbd_core.h 10 | Core/Src/usbd_core.c 11 | ) 12 | 13 | set(INCLUDE_DIRS 14 | Core/Inc/ 15 | config/ 16 | ) 17 | 18 | add_library(STM32_USB_Device_Library_STM32F042x6 STATIC ${SOURCES}) 19 | target_include_directories(STM32_USB_Device_Library_STM32F042x6 PUBLIC ${INCLUDE_DIRS}) 20 | target_compile_options(STM32_USB_Device_Library_STM32F042x6 PRIVATE ${CPUFLAGS_F0} -Wno-unused-parameter -DSTM32F0) 21 | target_link_libraries(STM32_USB_Device_Library_STM32F042x6 PRIVATE STM32_HAL_STM32F042x6) 22 | 23 | add_library(STM32_USB_Device_Library_STM32F072xB STATIC ${SOURCES}) 24 | target_include_directories(STM32_USB_Device_Library_STM32F072xB PUBLIC ${INCLUDE_DIRS}) 25 | target_compile_options(STM32_USB_Device_Library_STM32F072xB PRIVATE ${CPUFLAGS_F0} -Wno-unused-parameter -DSTM32F0) 26 | target_link_libraries(STM32_USB_Device_Library_STM32F072xB PRIVATE STM32_HAL_STM32F072xB) 27 | 28 | add_library(STM32_USB_Device_Library_STM32F407xE STATIC ${SOURCES}) 29 | target_include_directories(STM32_USB_Device_Library_STM32F407xE PUBLIC ${INCLUDE_DIRS}) 30 | target_compile_options(STM32_USB_Device_Library_STM32F407xE PRIVATE ${CPUFLAGS_F4} -Wno-unused-parameter -DSTM32F4) 31 | target_link_libraries(STM32_USB_Device_Library_STM32F407xE PRIVATE STM32_HAL_STM32F407xE) 32 | 33 | add_library(STM32_USB_Device_Library_STM32G0B1xx STATIC ${SOURCES}) 34 | target_include_directories(STM32_USB_Device_Library_STM32G0B1xx PUBLIC ${INCLUDE_DIRS}) 35 | target_compile_options(STM32_USB_Device_Library_STM32G0B1xx PRIVATE ${CPUFLAGS_G0} -Wno-unused-parameter -DSTM32G0) 36 | target_link_libraries(STM32_USB_Device_Library_STM32G0B1xx PRIVATE STM32_HAL_STM32G0B1xx) 37 | -------------------------------------------------------------------------------- /include/util_macro.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2014, Wind River Systems, Inc. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #ifndef ZEPHYR_INCLUDE_SYS_UTIL_MACROS_H_ 8 | #define ZEPHYR_INCLUDE_SYS_UTIL_MACROS_H_ 9 | 10 | /* 11 | * Most of the eldritch implementation details for all the macrobatics 12 | * below (APIs like IS_ENABLED(), COND_CODE_1(), etc.) are hidden away 13 | * in this file. 14 | */ 15 | #include "util_internal.h" 16 | 17 | /** 18 | * @brief Check for macro definition in compiler-visible expressions 19 | * 20 | * This trick was pioneered in Linux as the config_enabled() macro. It 21 | * has the effect of taking a macro value that may be defined to "1" 22 | * or may not be defined at all and turning it into a literal 23 | * expression that can be handled by the C compiler instead of just 24 | * the preprocessor. It is often used with a @p CONFIG_FOO macro which 25 | * may be defined to 1 via Kconfig, or left undefined. 26 | * 27 | * That is, it works similarly to \#if defined(CONFIG_FOO) 28 | * except that its expansion is a C expression. Thus, much \#ifdef 29 | * usage can be replaced with equivalents like: 30 | * 31 | * if (IS_ENABLED(CONFIG_FOO)) { 32 | * do_something_with_foo 33 | * } 34 | * 35 | * This is cleaner since the compiler can generate errors and warnings 36 | * for @p do_something_with_foo even when @p CONFIG_FOO is undefined. 37 | * 38 | * @param config_macro Macro to check 39 | * @return 1 if @p config_macro is defined to 1, 0 otherwise (including 40 | * if @p config_macro is not defined) 41 | */ 42 | #define IS_ENABLED(config_macro) Z_IS_ENABLED1(config_macro) 43 | /* INTERNAL: the first pass above is just to expand any existing 44 | * macros, we need the macro value to be e.g. a literal "1" at 45 | * expansion time in the next macro, not "(1)", etc... Standard 46 | * recursive expansion does not work. 47 | */ 48 | 49 | #endif /* ZEPHYR_INCLUDE_SYS_UTIL_MACROS_H_ */ 50 | -------------------------------------------------------------------------------- /include/gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "config.h" 30 | #include "gs_usb.h" 31 | 32 | void gpio_init(void); 33 | 34 | /* macro to define init (i.e. reset) state of a pin */ 35 | #define GPIO_INIT_STATE(active_high) (((active_high) == 1) ? GPIO_PIN_RESET : GPIO_PIN_SET) 36 | 37 | #ifdef TERM_Pin 38 | enum gs_can_termination_state set_term(unsigned int channel, enum gs_can_termination_state state); 39 | enum gs_can_termination_state get_term(unsigned int channel); 40 | 41 | #else 42 | static inline enum gs_can_termination_state set_term(unsigned int channel, enum gs_can_termination_state state) 43 | { 44 | (void)channel; 45 | (void)state; 46 | return GS_CAN_TERMINATION_UNSUPPORTED; 47 | } 48 | 49 | static inline enum gs_can_termination_state get_term(unsigned int channel) 50 | { 51 | (void)channel; 52 | return GS_CAN_TERMINATION_UNSUPPORTED; 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /include/led.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | #include 31 | 32 | 33 | #define LED_UPDATE_INTERVAL 10 // number of ticks from HAL_GetTick 34 | 35 | typedef enum { 36 | LED_MODE_OFF, 37 | LED_MODE_NORMAL, 38 | LED_MODE_WARN, 39 | LED_MODE_ERROR, 40 | LED_MODE_SEQUENCE 41 | } led_mode_t; 42 | 43 | typedef enum { 44 | LED_RX = 0, //will also index into array led_state[] 45 | LED_TX, 46 | LED_MAX 47 | } led_num_t; 48 | 49 | typedef struct { 50 | uint8_t state; 51 | uint8_t time_in_10ms; 52 | } led_seq_step_t; 53 | 54 | typedef struct { 55 | void* port; 56 | uint16_t pin; 57 | bool is_active_high; 58 | 59 | bool blink_request; 60 | uint32_t on_until; 61 | uint32_t off_until; 62 | } led_state_t; 63 | 64 | typedef struct { 65 | led_mode_t mode; 66 | 67 | const led_seq_step_t *sequence; 68 | uint32_t sequence_step; 69 | uint32_t t_sequence_next; 70 | int32_t seq_num_repeat; 71 | 72 | led_state_t led_state[LED_MAX]; 73 | } led_data_t; 74 | 75 | 76 | void led_init( 77 | led_data_t *leds, 78 | void* led_rx_port, uint16_t led_rx_pin, bool led_rx_active_high, 79 | void* led_tx_port, uint16_t led_tx_pin, bool led_tx_active_high 80 | ); 81 | void led_set_mode(led_data_t *leds,led_mode_t mode); 82 | void led_run_sequence(led_data_t *leds, const led_seq_step_t *sequence, int32_t num_repeat); 83 | void led_indicate_trx(led_data_t *leds, led_num_t num); 84 | void led_update(led_data_t *leds); 85 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/stm32f4xx/stm32f4xx_hal_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH RAMFUNC driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 22 | #define __STM32F4xx_FLASH_RAMFUNC_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\ 28 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal_def.h" 32 | 33 | /** @addtogroup STM32F4xx_HAL_Driver 34 | * @{ 35 | */ 36 | 37 | /** @addtogroup FLASH_RAMFUNC 38 | * @{ 39 | */ 40 | 41 | /* Exported types ------------------------------------------------------------*/ 42 | /* Exported macro ------------------------------------------------------------*/ 43 | /* Exported functions --------------------------------------------------------*/ 44 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions 45 | * @{ 46 | */ 47 | 48 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1 49 | * @{ 50 | */ 51 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void); 52 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void); 53 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void); 54 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void); 55 | /** 56 | * @} 57 | */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | 77 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 78 | 79 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 80 | -------------------------------------------------------------------------------- /libs/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_req.h 4 | * @author MCD Application Team 5 | * @brief Header file for the usbd_req.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USB_REQUEST_H 22 | #define __USB_REQUEST_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBD_REQ 37 | * @brief header file for the usbd_req.c file 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_REQ_Exported_Defines 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_REQ_Exported_Types 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | 58 | /** @defgroup USBD_REQ_Exported_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @defgroup USBD_REQ_Exported_Variables 66 | * @{ 67 | */ 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype 73 | * @{ 74 | */ 75 | 76 | USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 77 | USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 78 | USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 79 | 80 | 81 | void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 82 | 83 | void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata); 84 | 85 | void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len); 86 | /** 87 | * @} 88 | */ 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* __USB_REQUEST_H */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/system_stm32g0xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32g0xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M0+ Device System Source File for STM32G0xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2018-2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /** @addtogroup CMSIS 19 | * @{ 20 | */ 21 | 22 | /** @addtogroup stm32g0xx_system 23 | * @{ 24 | */ 25 | 26 | /** 27 | * @brief Define to prevent recursive inclusion 28 | */ 29 | #ifndef SYSTEM_STM32G0XX_H 30 | #define SYSTEM_STM32G0XX_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /** @addtogroup STM32G0xx_System_Includes 37 | * @{ 38 | */ 39 | 40 | /** 41 | * @} 42 | */ 43 | 44 | 45 | /** @addtogroup STM32G0xx_System_Exported_types 46 | * @{ 47 | */ 48 | /* This variable is updated in three ways: 49 | 1) by calling CMSIS function SystemCoreClockUpdate() 50 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 51 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 52 | Note: If you use this function to configure the system clock; then there 53 | is no need to call the 2 first functions listed above, since SystemCoreClock 54 | variable is updated automatically. 55 | */ 56 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 57 | 58 | extern const uint32_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 59 | extern const uint32_t APBPrescTable[8]; /*!< APB prescalers table values */ 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @addtogroup STM32G0xx_System_Exported_Constants 66 | * @{ 67 | */ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @addtogroup STM32G0xx_System_Exported_Macros 74 | * @{ 75 | */ 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /** @addtogroup STM32G0xx_System_Exported_Functions 82 | * @{ 83 | */ 84 | 85 | extern void SystemInit(void); 86 | extern void SystemCoreClockUpdate(void); 87 | /** 88 | * @} 89 | */ 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | #endif /*SYSTEM_STM32G0XX_H */ 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /** 102 | * @} 103 | */ 104 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/stm32g0xx/stm32g0xx_hal_pcd_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32g0xx_hal_pcd_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of PCD HAL Extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2018 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef STM32G0xx_HAL_PCD_EX_H 21 | #define STM32G0xx_HAL_PCD_EX_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif /* __cplusplus */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "stm32g0xx_hal_def.h" 29 | 30 | #if defined (USB_DRD_FS) 31 | /** @addtogroup STM32G0xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup PCDEx 36 | * @{ 37 | */ 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* Exported macros -----------------------------------------------------------*/ 41 | /* Exported functions --------------------------------------------------------*/ 42 | /** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions 43 | * @{ 44 | */ 45 | /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 46 | * @{ 47 | */ 48 | 49 | 50 | 51 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, uint16_t ep_addr, 52 | uint16_t ep_kind, uint32_t pmaadress); 53 | 54 | 55 | HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd); 56 | HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd); 57 | 58 | 59 | HAL_StatusTypeDef HAL_PCDEx_ActivateBCD(PCD_HandleTypeDef *hpcd); 60 | HAL_StatusTypeDef HAL_PCDEx_DeActivateBCD(PCD_HandleTypeDef *hpcd); 61 | void HAL_PCDEx_BCD_VBUSDetect(PCD_HandleTypeDef *hpcd); 62 | 63 | void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); 64 | void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | #endif /* defined (USB_DRD_FS) */ 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif /* __cplusplus */ 86 | 87 | 88 | #endif /* STM32G0xx_HAL_PCD_EX_H */ 89 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/system_stm32f0xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f0xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M0 Device System Source File for STM32F0xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /** @addtogroup CMSIS 21 | * @{ 22 | */ 23 | 24 | /** @addtogroup stm32f0xx_system 25 | * @{ 26 | */ 27 | 28 | /** 29 | * @brief Define to prevent recursive inclusion 30 | */ 31 | #ifndef __SYSTEM_STM32F0XX_H 32 | #define __SYSTEM_STM32F0XX_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /** @addtogroup STM32F0xx_System_Includes 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @} 44 | */ 45 | 46 | 47 | /** @addtogroup STM32F0xx_System_Exported_types 48 | * @{ 49 | */ 50 | /* This variable is updated in three ways: 51 | 1) by calling CMSIS function SystemCoreClockUpdate() 52 | 3) by calling HAL API function HAL_RCC_GetHCLKFreq() 53 | 3) by calling HAL API function HAL_RCC_ClockConfig() 54 | Note: If you use this function to configure the system clock; then there 55 | is no need to call the 2 first functions listed above, since SystemCoreClock 56 | variable is updated automatically. 57 | */ 58 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 59 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 60 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup STM32F0xx_System_Exported_Constants 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @addtogroup STM32F0xx_System_Exported_Macros 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @addtogroup STM32F0xx_System_Exported_Functions 83 | * @{ 84 | */ 85 | 86 | extern void SystemInit(void); 87 | extern void SystemCoreClockUpdate(void); 88 | /** 89 | * @} 90 | */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /*__SYSTEM_STM32F0XX_H */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/stm32f0xx/stm32f0xx_hal_pcd_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_pcd_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of PCD HAL Extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F0xx_HAL_PCD_EX_H 22 | #define STM32F0xx_HAL_PCD_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f0xx_hal_def.h" 30 | 31 | #if defined (USB) 32 | /** @addtogroup STM32F0xx_HAL_Driver 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup PCDEx 37 | * @{ 38 | */ 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macros -----------------------------------------------------------*/ 42 | /* Exported functions --------------------------------------------------------*/ 43 | /** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions 44 | * @{ 45 | */ 46 | /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 47 | * @{ 48 | */ 49 | 50 | 51 | 52 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, uint16_t ep_addr, 53 | uint16_t ep_kind, uint32_t pmaadress); 54 | 55 | 56 | HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd); 57 | HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd); 58 | 59 | 60 | HAL_StatusTypeDef HAL_PCDEx_ActivateBCD(PCD_HandleTypeDef *hpcd); 61 | HAL_StatusTypeDef HAL_PCDEx_DeActivateBCD(PCD_HandleTypeDef *hpcd); 62 | void HAL_PCDEx_BCD_VBUSDetect(PCD_HandleTypeDef *hpcd); 63 | 64 | void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); 65 | void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | #endif /* defined (USB) */ 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | 89 | #endif /* STM32F0xx_HAL_PCD_EX_H */ 90 | 91 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 92 | -------------------------------------------------------------------------------- /src/dfu.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include "dfu.h" 28 | #include 29 | #include "hal_include.h" 30 | 31 | #define RESET_TO_BOOTLOADER_MAGIC_CODE 0xDEADBEEF 32 | 33 | #define SYSMEM_STM32F042 0x1FFFC400 34 | #define SYSMEM_STM32F072 0x1FFFC800 35 | #define SYSMEM_STM32G0B1 0x1FFF0000 36 | 37 | static uint32_t dfu_reset_to_bootloader_magic; 38 | 39 | static void dfu_hack_boot_pin_f042(void); 40 | static void dfu_jump_to_bootloader(uint32_t sysmem_base); 41 | 42 | void dfu_run_bootloader(void) 43 | { 44 | dfu_reset_to_bootloader_magic = RESET_TO_BOOTLOADER_MAGIC_CODE; 45 | NVIC_SystemReset(); 46 | } 47 | 48 | void __initialize_hardware_early(void) 49 | { 50 | if (dfu_reset_to_bootloader_magic == RESET_TO_BOOTLOADER_MAGIC_CODE) 51 | { 52 | switch (HAL_GetDEVID()) 53 | { 54 | 55 | case 0x445: // STM32F04x 56 | dfu_hack_boot_pin_f042(); 57 | dfu_jump_to_bootloader(SYSMEM_STM32F042); 58 | break; 59 | 60 | case 0x448: // STM32F07x 61 | dfu_jump_to_bootloader(SYSMEM_STM32F072); 62 | break; 63 | 64 | case 0x467: 65 | dfu_jump_to_bootloader(SYSMEM_STM32G0B1); 66 | break; 67 | } 68 | } 69 | 70 | SystemInit(); 71 | } 72 | 73 | static void dfu_hack_boot_pin_f042(void) 74 | { 75 | __HAL_RCC_GPIOF_CLK_ENABLE(); 76 | GPIO_InitTypeDef GPIO_InitStruct; 77 | GPIO_InitStruct.Pin = GPIO_PIN_11; 78 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 79 | GPIO_InitStruct.Pull = GPIO_PULLUP; 80 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 81 | HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); 82 | HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, 1); 83 | } 84 | 85 | static void dfu_jump_to_bootloader(uint32_t sysmem_base) 86 | { 87 | void (*bootloader)(void) = (void (*)(void))(*((uint32_t *) (sysmem_base + 4))); 88 | 89 | __set_MSP(*(__IO uint32_t*) sysmem_base); 90 | bootloader(); 91 | 92 | while (42) 93 | { 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/device/device_f4.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2022 Ricky Lopez 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | /* F4-specific code */ 27 | 28 | #include "can.h" 29 | #include "device.h" 30 | #include "hal_include.h" 31 | 32 | void device_can_init(can_data_t *channel, CAN_TypeDef *instance) { 33 | __HAL_RCC_CAN1_CLK_ENABLE(); 34 | 35 | GPIO_InitTypeDef itd; 36 | 37 | itd.Pin = GPIO_PIN_0|GPIO_PIN_1; 38 | itd.Mode = GPIO_MODE_AF_PP; 39 | itd.Pull = GPIO_NOPULL; 40 | itd.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 41 | itd.Alternate = GPIO_AF9_CAN1; 42 | HAL_GPIO_Init(GPIOD, &itd); 43 | 44 | channel->instance = instance; 45 | channel->brp = 6; 46 | channel->sjw = 1; 47 | channel->phase_seg1 = 12; 48 | channel->phase_seg2 = 1; 49 | return; 50 | } 51 | 52 | void device_sysclock_config(void) { 53 | RCC_OscInitTypeDef RCC_OscInitStruct; 54 | RCC_ClkInitTypeDef RCC_ClkInitStruct; 55 | 56 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 57 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; 58 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 59 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 60 | RCC_OscInitStruct.PLL.PLLM = 4; 61 | RCC_OscInitStruct.PLL.PLLN = 168; 62 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; 63 | RCC_OscInitStruct.PLL.PLLQ = 7; 64 | HAL_RCC_OscConfig(&RCC_OscInitStruct); 65 | 66 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | 67 | RCC_CLOCKTYPE_SYSCLK | 68 | RCC_CLOCKTYPE_PCLK1 | 69 | RCC_CLOCKTYPE_PCLK2; 70 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 71 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 72 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; 73 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; 74 | HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5); 75 | 76 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); 77 | 78 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); 79 | 80 | /* SysTick_IRQn interrupt configuration */ 81 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 82 | } 83 | -------------------------------------------------------------------------------- /libs/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.h 4 | * @author MCD Application Team 5 | * @brief Header file for the usbd_ioreq.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_IOREQ_H 22 | #define __USBD_IOREQ_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | #include "usbd_core.h" 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBD_IOREQ 37 | * @brief header file for the usbd_ioreq.c file 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_IOREQ_Exported_Defines 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_IOREQ_Exported_Types 50 | * @{ 51 | */ 52 | 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | 59 | 60 | /** @defgroup USBD_IOREQ_Exported_Macros 61 | * @{ 62 | */ 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup USBD_IOREQ_Exported_Variables 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype 77 | * @{ 78 | */ 79 | 80 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, 81 | uint8_t *pbuf, 82 | uint16_t len); 83 | 84 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, 85 | uint8_t *pbuf, 86 | uint16_t len); 87 | 88 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, 89 | uint8_t *pbuf, 90 | uint16_t len); 91 | 92 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, 93 | uint8_t *pbuf, 94 | uint16_t len); 95 | 96 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev); 97 | 98 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev); 99 | 100 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 101 | 102 | /** 103 | * @} 104 | */ 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif /* __USBD_IOREQ_H */ 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | /** 117 | * @} 118 | */ 119 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /src/device/device_g0.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2022 Ryan Edwards 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | /* 27 | * G0 device-specific code 28 | */ 29 | 30 | #include "can.h" 31 | #include "device.h" 32 | #include "hal_include.h" 33 | 34 | void device_can_init(can_data_t *channel, CAN_TypeDef *instance) { 35 | // XXX TODO 36 | while (1); 37 | return; 38 | } 39 | 40 | void device_sysclock_config(void) { 41 | RCC_OscInitTypeDef RCC_OscInitStruct; 42 | RCC_ClkInitTypeDef RCC_ClkInitStruct; 43 | 44 | /** Configure the main internal regulator output voltage 45 | */ 46 | HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); 47 | /** Initializes the RCC Oscillators according to the specified parameters 48 | * in the RCC_OscInitTypeDef structure. 49 | */ 50 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48; 51 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 52 | RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; 53 | RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; 54 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 55 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 56 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; 57 | RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1; 58 | RCC_OscInitStruct.PLL.PLLN = 8; 59 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; 60 | RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; 61 | RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; 62 | HAL_RCC_OscConfig(&RCC_OscInitStruct); 63 | /** Initializes the CPU, AHB and APB buses clocks 64 | */ 65 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 66 | |RCC_CLOCKTYPE_PCLK1; 67 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 68 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 69 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 70 | 71 | HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); 72 | 73 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; 74 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; 75 | PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; 76 | HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); 77 | 78 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); 79 | 80 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); 81 | 82 | /* SysTick_IRQn interrupt configuration */ 83 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 84 | } 85 | -------------------------------------------------------------------------------- /src/device/device_f0.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | /* 27 | * F0 device-specific code 28 | */ 29 | 30 | #include "can.h" 31 | #include "device.h" 32 | #include "hal_include.h" 33 | 34 | void device_can_init(can_data_t *channel, CAN_TypeDef *instance) { 35 | __HAL_RCC_CAN1_CLK_ENABLE(); 36 | 37 | GPIO_InitTypeDef itd; 38 | 39 | itd.Pin = GPIO_PIN_8|GPIO_PIN_9; 40 | itd.Mode = GPIO_MODE_AF_PP; 41 | itd.Pull = GPIO_NOPULL; 42 | itd.Speed = GPIO_SPEED_FREQ_HIGH; 43 | itd.Alternate = GPIO_AF4_CAN; 44 | HAL_GPIO_Init(GPIOB, &itd); 45 | 46 | channel->instance = instance; 47 | channel->brp = 6; 48 | channel->sjw = 1; 49 | channel->phase_seg1 = 13; 50 | channel->phase_seg2 = 2; 51 | return; 52 | } 53 | 54 | void device_sysclock_config(void) { 55 | RCC_OscInitTypeDef RCC_OscInitStruct; 56 | RCC_ClkInitTypeDef RCC_ClkInitStruct; 57 | 58 | RCC_PeriphCLKInitTypeDef PeriphClkInit; 59 | RCC_CRSInitTypeDef RCC_CRSInitStruct; 60 | 61 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48; 62 | RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; 63 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; 64 | HAL_RCC_OscConfig(&RCC_OscInitStruct); 65 | 66 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | 67 | RCC_CLOCKTYPE_SYSCLK | 68 | RCC_CLOCKTYPE_PCLK1; 69 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48; 70 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 71 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 72 | HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1); 73 | 74 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; 75 | PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; 76 | HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); 77 | 78 | __HAL_RCC_CRS_CLK_ENABLE(); 79 | RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1; 80 | RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB; 81 | RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING; 82 | RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000,1000); 83 | RCC_CRSInitStruct.ErrorLimitValue = 34; 84 | RCC_CRSInitStruct.HSI48CalibrationValue = 32; 85 | HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct); 86 | 87 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); 88 | 89 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); 90 | 91 | /* SysTick_IRQn interrupt configuration */ 92 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 93 | } 94 | -------------------------------------------------------------------------------- /include/can.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | #include 31 | 32 | #include "config.h" 33 | #include "gs_usb.h" 34 | #include "hal_include.h" 35 | #include "led.h" 36 | #include "list.h" 37 | 38 | typedef struct { 39 | CAN_TypeDef *instance; 40 | struct list_head list_from_host; 41 | led_data_t leds; 42 | struct gs_device_filter filter; 43 | uint32_t reg_esr_old; 44 | uint16_t brp; 45 | uint8_t phase_seg1; 46 | uint8_t phase_seg2; 47 | uint8_t sjw; 48 | uint8_t nr; 49 | } can_data_t; 50 | 51 | extern const struct gs_device_bt_const CAN_btconst; 52 | extern const struct gs_device_bt_const_extended CAN_btconst_ext; 53 | extern const struct gs_device_filter_info CAN_filter_info; 54 | 55 | void can_init(can_data_t *channel, CAN_TypeDef *instance); 56 | void can_set_bittiming(can_data_t *channel, const struct gs_device_bittiming *timing); 57 | 58 | #ifdef CONFIG_CANFD 59 | void can_set_data_bittiming(can_data_t *channel, const struct gs_device_bittiming *timing); 60 | #else 61 | static inline bool can_set_data_bittiming(can_data_t *channel, 62 | const struct gs_device_bittiming *timing) 63 | { 64 | (void)channel; 65 | (void)timing; 66 | 67 | return false; 68 | } 69 | #endif 70 | 71 | #ifdef CONFIG_CAN_FILTER 72 | void can_set_filter(can_data_t *channel, const struct gs_device_filter *filter); 73 | #else 74 | static inline void can_set_filter(can_data_t *channel, const struct gs_device_filter *filter) 75 | { 76 | (void)channel; 77 | (void)filter; 78 | } 79 | #endif 80 | 81 | void can_enable(can_data_t *channel, uint32_t mode); 82 | void can_disable(can_data_t *channel); 83 | bool can_is_enabled(can_data_t *channel); 84 | 85 | bool can_receive(can_data_t *channel, struct gs_host_frame *rx_frame); 86 | bool can_is_rx_pending(can_data_t *channel); 87 | 88 | bool can_send(can_data_t *channel, struct gs_host_frame *frame); 89 | 90 | /** return CAN->ESR register which contains tx/rx error counters and 91 | * LEC (last error code). 92 | */ 93 | uint32_t can_get_error_status(can_data_t *channel); 94 | 95 | /** parse status value returned by can_get_error_status(). 96 | * @param frame : will hold the generated error frame 97 | * @param err : holds the contents of the ESR register 98 | * @return 1 when status changes (if any) need a new error frame sent 99 | */ 100 | bool can_parse_error_status(can_data_t *channel, struct gs_host_frame *frame, uint32_t err); 101 | -------------------------------------------------------------------------------- /include/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016, 2019 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | void hex32(char *out, uint32_t val); 34 | 35 | // ARM's 36 | // "Application Note 321 ARM Cortex-M Programming Guide to Memory Barrier Instructions" 37 | // (from https://developer.arm.com/documentation/dai0321/latest) says that 38 | // the ISBs are actually necessary on Cortex-M0 to avoid a 2-instruction 39 | // delay in the effect of enabling and disabling interrupts. 40 | // That probably doesn't matter here, but it's hard to say what the compiler 41 | // will put in those 2 instructions so it's safer to leave it. The DSB isn't 42 | // necessary on Cortex-M0, but it's architecturally required so we'll 43 | // include it to be safe. 44 | // 45 | // The "memory" and "cc" clobbers tell GCC to avoid moving memory loads or 46 | // stores across the instructions. This is important when an interrupt and the 47 | // code calling disable_irq/enable_irq share memory. The fact that these are 48 | // non-inlined functions probably forces GCC to flush everything to memory 49 | // anyways, but trying to outsmart the compiler is a bad strategy (you never 50 | // know when somebody will turn on LTO or something). 51 | 52 | static inline bool is_irq_enabled(void) 53 | { 54 | return (__get_PRIMASK() & 1u) == 0u; // interrupts not prevented 55 | } 56 | 57 | static inline bool disable_irq(void) 58 | { 59 | bool was_enabled = is_irq_enabled(); 60 | __disable_irq(); 61 | __ISB(); 62 | return was_enabled; 63 | } 64 | 65 | static inline void enable_irq(void) 66 | { 67 | __enable_irq(); 68 | __ISB(); 69 | } 70 | 71 | static inline void restore_irq(bool was_enabled) 72 | { 73 | if (was_enabled) { 74 | enable_irq(); 75 | } 76 | } 77 | 78 | /* Lightweight assert macro to replace standard assert() 79 | * 80 | * Standard assert() needs fprint, __FILE__ , __LINE__ string consts etc. 81 | * 82 | * stm32's library has "USE_FULL_ASSERT" to enable some checks, but they have 83 | * their own assert_param() macro that also passes in __FILE__, __LINE__ so 84 | * I'm not sure if (and how) it'll be possible to combine both. 85 | * 86 | * Interesting notes on 87 | * https://barrgroup.com/embedded-systems/how-to/define-assert-macro 88 | * 89 | */ 90 | #define assert_basic(exp) \ 91 | if (exp) { \ 92 | } else \ 93 | assert_failed() 94 | 95 | /** halt / set core to debug state with BKPT. 96 | * 97 | * TODO : save extra info somewhere in RAM, and let WDT auto-reset ? 98 | */ 99 | void assert_failed(void); 100 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/stm32f4xx/stm32f4xx_hal_pcd_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_pcd_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of PCD HAL Extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F4xx_HAL_PCD_EX_H 22 | #define STM32F4xx_HAL_PCD_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx_hal_def.h" 30 | 31 | #if defined (USB_OTG_FS) || defined (USB_OTG_HS) 32 | /** @addtogroup STM32F4xx_HAL_Driver 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup PCDEx 37 | * @{ 38 | */ 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macros -----------------------------------------------------------*/ 42 | /* Exported functions --------------------------------------------------------*/ 43 | /** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions 44 | * @{ 45 | */ 46 | /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 47 | * @{ 48 | */ 49 | 50 | #if defined (USB_OTG_FS) || defined (USB_OTG_HS) 51 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size); 52 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size); 53 | #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */ 54 | 55 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) 56 | HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd); 57 | HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd); 58 | #endif /* defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) */ 59 | #if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) 60 | HAL_StatusTypeDef HAL_PCDEx_ActivateBCD(PCD_HandleTypeDef *hpcd); 61 | HAL_StatusTypeDef HAL_PCDEx_DeActivateBCD(PCD_HandleTypeDef *hpcd); 62 | void HAL_PCDEx_BCD_VBUSDetect(PCD_HandleTypeDef *hpcd); 63 | #endif /* defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) */ 64 | void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); 65 | void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */ 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | 89 | #endif /* STM32F4xx_HAL_PCD_EX_H */ 90 | 91 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 92 | -------------------------------------------------------------------------------- /ldscripts/ldscript_base.inc: -------------------------------------------------------------------------------- 1 | /** 2 | * The following is a template linker script since most of this is identical accross targets. 3 | * 4 | * the cmake build sys will process this with 'configure_file()' into a cpu-specific header. 5 | * 6 | * It would be possible to use gcc to preprocess a common .ld file (and therefore leverage 7 | * #ifdef and other mechanisms), but has certain limitations and challenges that I decided to avoid. 8 | * 9 | * 10 | * fenugrec 2022 11 | */ 12 | 13 | __STACK_SIZE = @LDV_STACK_SIZE@; 14 | __HEAP_SIZE = @LDV_HEAP_SIZE@; 15 | 16 | __FLASH_SIZE = @LDV_FLASH_SIZE@; 17 | __RAM_SIZE = @LDV_RAM_SIZE@; 18 | 19 | MEMORY 20 | { 21 | FLASH (rx) : ORIGIN = @LDV_FLASH_START@, LENGTH = __FLASH_SIZE 22 | RAM (rw) : ORIGIN = @LDV_RAM_START@, LENGTH = __RAM_SIZE 23 | } 24 | 25 | ENTRY(Reset_Handler) 26 | 27 | SECTIONS 28 | { 29 | .text : 30 | { 31 | KEEP(*(.vectors)) 32 | *(.text*) 33 | 34 | KEEP(*(.init)) 35 | KEEP(*(.fini)) 36 | 37 | /* .ctors */ 38 | *crtbegin.o(.ctors) 39 | *crtbegin?.o(.ctors) 40 | *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) 41 | *(SORT(.ctors.*)) 42 | *(.ctors) 43 | 44 | /* .dtors */ 45 | *crtbegin.o(.dtors) 46 | *crtbegin?.o(.dtors) 47 | *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) 48 | *(SORT(.dtors.*)) 49 | *(.dtors) 50 | 51 | *(.rodata*) 52 | 53 | KEEP(*(.eh_frame*)) 54 | } > FLASH 55 | 56 | .ARM.extab : 57 | { 58 | *(.ARM.extab* .gnu.linkonce.armextab.*) 59 | } > FLASH 60 | 61 | __exidx_start = .; 62 | .ARM.exidx : 63 | { 64 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 65 | } > FLASH 66 | __exidx_end = .; 67 | 68 | .copy.table : 69 | { 70 | . = ALIGN(4); 71 | __copy_table_start__ = .; 72 | LONG (__etext) 73 | LONG (__data_start__) 74 | LONG (__data_end__ - __data_start__) 75 | __copy_table_end__ = .; 76 | } > FLASH 77 | 78 | 79 | .preinit_array : 80 | { 81 | . = ALIGN(4); 82 | /* preinit data */ 83 | PROVIDE_HIDDEN (__preinit_array_start = .); 84 | KEEP(*(.preinit_array)) 85 | PROVIDE_HIDDEN (__preinit_array_end = .); 86 | . = ALIGN(4); 87 | } >FLASH 88 | 89 | .init_array : 90 | { 91 | . = ALIGN(4); 92 | /* init data */ 93 | PROVIDE_HIDDEN (__init_array_start = .); 94 | KEEP(*(SORT(.init_array.*))) 95 | KEEP(*(.init_array)) 96 | PROVIDE_HIDDEN (__init_array_end = .); 97 | . = ALIGN(4); 98 | } >FLASH 99 | 100 | .fini_array : 101 | { 102 | . = ALIGN(4); 103 | PROVIDE_HIDDEN (__fini_array_start = .); 104 | KEEP (*(SORT(.fini_array.*))) 105 | KEEP (*(.fini_array*)) 106 | PROVIDE_HIDDEN (__fini_array_end = .); 107 | . = ALIGN(4); 108 | } >FLASH 109 | 110 | __etext = ALIGN (4); 111 | 112 | .data : AT (__etext) 113 | { 114 | __data_start__ = .; 115 | *(vtable) 116 | *(.data) 117 | *(.data.*) 118 | 119 | 120 | . = ALIGN(4); 121 | /* All data end */ 122 | __data_end__ = .; 123 | 124 | } > RAM 125 | 126 | .bss : 127 | { 128 | . = ALIGN(4); 129 | __bss_start__ = .; 130 | *(.bss) 131 | *(.bss.*) 132 | *(COMMON) 133 | . = ALIGN(4); 134 | __bss_end__ = .; 135 | } > RAM AT > RAM 136 | 137 | .heap (COPY) : 138 | { 139 | . = ALIGN(8); 140 | __end__ = .; 141 | PROVIDE(end = .); 142 | . = . + __HEAP_SIZE; 143 | . = ALIGN(8); 144 | __HeapLimit = .; 145 | } > RAM 146 | 147 | .stack (ORIGIN(RAM) + LENGTH(RAM) - __STACK_SIZE) (COPY) : 148 | { 149 | . = ALIGN(8); 150 | __StackLimit = .; 151 | . = . + __STACK_SIZE; 152 | . = ALIGN(8); 153 | __StackTop = .; 154 | } > RAM 155 | PROVIDE(__stack = __StackTop); 156 | 157 | ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") 158 | } 159 | -------------------------------------------------------------------------------- /include/compiler.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2010 Isilon Systems, Inc. 3 | * Copyright (c) 2010 iX Systems, Inc. 4 | * Copyright (c) 2010 Panasas, Inc. 5 | * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. 6 | * Copyright (c) 2015 François Tigeot 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice unmodified, this list of conditions, and the following 14 | * disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * $FreeBSD$ 31 | */ 32 | #ifndef _LINUXKPI_LINUX_COMPILER_H_ 33 | #define _LINUXKPI_LINUX_COMPILER_H_ 34 | 35 | #include "util_macro.h" 36 | 37 | #ifndef __aligned 38 | #define __aligned(x) __attribute__((__aligned__(x))) 39 | #endif 40 | 41 | #ifndef __packed 42 | #define __packed __attribute__((__packed__)) 43 | #endif 44 | 45 | #if __has_attribute(__fallthrough__) 46 | #define fallthrough __attribute__((__fallthrough__)) 47 | #else 48 | #define fallthrough do {} while (0) /* fallthrough */ 49 | #endif 50 | 51 | #define barrier() __asm__ __volatile__ ("" : : : "memory") 52 | 53 | #define ACCESS_ONCE(x) (*(volatile __typeof(x) *)&(x)) 54 | 55 | #define WRITE_ONCE(x,v) \ 56 | do { \ 57 | barrier(); \ 58 | ACCESS_ONCE(x) = (v); \ 59 | barrier(); \ 60 | } while (0) 61 | 62 | #define READ_ONCE(x) \ 63 | ({ \ 64 | __typeof(x) __var = ({ \ 65 | barrier(); \ 66 | ACCESS_ONCE(x); \ 67 | }); \ 68 | barrier(); \ 69 | __var; \ 70 | }) 71 | 72 | #define lockless_dereference(p) READ_ONCE(p) 73 | 74 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) 75 | #define __must_be_array(a) __same_type(a, &(a)[0]) 76 | 77 | #define sizeof_field(_s, _m) sizeof(((_s *)0)->_m) 78 | 79 | #define container_of(ptr, type, member) \ 80 | ({ \ 81 | __typeof(((type *)0)->member) *_p = (ptr); \ 82 | (type *)((char *)_p - offsetof(type, member)); \ 83 | }) 84 | 85 | #define struct_size(ptr, field, num) \ 86 | (offsetof(__typeof(*(ptr)), field) + sizeof((ptr)->field[0]) * (num)) 87 | 88 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 89 | 90 | #define DECLARE_FLEX_ARRAY(_t, _n) \ 91 | struct { \ 92 | struct { } __dummy_ ## _n; \ 93 | _t _n[0]; \ 94 | } 95 | 96 | #define min(x, y) ((x) < (y) ? (x) : (y)) 97 | #define max(x, y) ((x) > (y) ? (x) : (y)) 98 | 99 | #define min3(a, b, c) min(a, min(b, c)) 100 | #define max3(a, b, c) max(a, max(b, c)) 101 | 102 | #define min4(a, b, c, d) min(min(a, b), min(c, d)) 103 | #define max4(a, b, c, d) max(max(a, b), max(b, d)) 104 | 105 | #define min5(a, b, c, d, e) min3(min(a, b), min(c, d), e) 106 | #define max5(a, b, c, d, e) max3(max(a, b), max(b, d), e) 107 | 108 | #define min6(a, b, c, d, e, f) min3(min(a, b), min(c, d), min(e, f)) 109 | #define max6(a, b, c, d, e, f) max3(max(a, b), max(b, d), max(e, f)) 110 | 111 | #endif /* _LINUXKPI_LINUX_COMPILER_H_ */ 112 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/stm32g0xx/stm32g0xx_hal_flash_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32g0xx_hal_flash_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH HAL Extended module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2018 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file in 13 | * the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | ****************************************************************************** 16 | */ 17 | 18 | /* Define to prevent recursive inclusion -------------------------------------*/ 19 | #ifndef STM32G0xx_HAL_FLASH_EX_H 20 | #define STM32G0xx_HAL_FLASH_EX_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "stm32g0xx_hal_def.h" 28 | 29 | /** @addtogroup STM32G0xx_HAL_Driver 30 | * @{ 31 | */ 32 | 33 | /** @addtogroup FLASHEx 34 | * @{ 35 | */ 36 | 37 | /* Exported types ------------------------------------------------------------*/ 38 | /* Exported constants --------------------------------------------------------*/ 39 | /** @defgroup FLASHEx_Exported_Constants FLASH Exported Constants 40 | * @{ 41 | */ 42 | /** @defgroup FLASHEx_Empty_Check FLASHEx Empty Check 43 | * @{ 44 | */ 45 | #define FLASH_PROG_NOT_EMPTY 0x00000000u /*!< 1st location in Flash is programmed */ 46 | #define FLASH_PROG_EMPTY FLASH_ACR_PROGEMPTY /*!< 1st location in Flash is empty */ 47 | /** 48 | * @} 49 | */ 50 | /** 51 | * @} 52 | */ 53 | 54 | /* Exported macro ------------------------------------------------------------*/ 55 | /* Exported functions --------------------------------------------------------*/ 56 | /** @addtogroup FLASHEx_Exported_Functions 57 | * @{ 58 | */ 59 | 60 | /* Extended Program operation functions *************************************/ 61 | /** @addtogroup FLASHEx_Exported_Functions_Group1 62 | * @{ 63 | */ 64 | HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError); 65 | HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit); 66 | void HAL_FLASHEx_EnableDebugger(void); 67 | void HAL_FLASHEx_DisableDebugger(void); 68 | uint32_t HAL_FLASHEx_FlashEmptyCheck(void); 69 | void HAL_FLASHEx_ForceFlashEmpty(uint32_t FlashEmpty); 70 | #if defined(FLASH_SECURABLE_MEMORY_SUPPORT) 71 | void HAL_FLASHEx_EnableSecMemProtection(uint32_t Banks); 72 | #endif /* FLASH_SECURABLE_MEMORY_SUPPORT */ 73 | HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit); 74 | void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit); 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /* Private macros ------------------------------------------------------------*/ 84 | /** @defgroup FLASHEx_Private_Constants FLASHEx Private Constants 85 | * @{ 86 | */ 87 | #define FLASH_PCROP_GRANULARITY_OFFSET 9u /*!< FLASH Code Readout Protection granularity offset */ 88 | #define FLASH_PCROP_GRANULARITY (1UL << FLASH_PCROP_GRANULARITY_OFFSET) /*!< FLASH Code Readout Protection granularity, 512 Bytes */ 89 | /** 90 | * @} 91 | */ 92 | 93 | 94 | /** @defgroup FLASHEx_Private_Macros FLASHEx Private Macros 95 | * @{ 96 | */ 97 | #define IS_FLASH_EMPTY_CHECK(__VALUE__) (((__VALUE__) == FLASH_PROG_EMPTY) || ((__VALUE__) == FLASH_PROG_NOT_EMPTY)) 98 | void FLASH_PageErase(uint32_t Banks, uint32_t Page); 99 | /** 100 | * @} 101 | */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | #ifdef __cplusplus 112 | } 113 | #endif 114 | 115 | #endif /* STM32G0xx_HAL_FLASH_EX_H */ 116 | 117 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2017 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /** @addtogroup CMSIS 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup stm32f4xx_system 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief Define to prevent recursive inclusion 46 | */ 47 | #ifndef __SYSTEM_STM32F4XX_H 48 | #define __SYSTEM_STM32F4XX_H 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | /** @addtogroup STM32F4xx_System_Includes 55 | * @{ 56 | */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | 63 | /** @addtogroup STM32F4xx_System_Exported_types 64 | * @{ 65 | */ 66 | /* This variable is updated in three ways: 67 | 1) by calling CMSIS function SystemCoreClockUpdate() 68 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 69 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 70 | Note: If you use this function to configure the system clock; then there 71 | is no need to call the 2 first functions listed above, since SystemCoreClock 72 | variable is updated automatically. 73 | */ 74 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 75 | 76 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 77 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @addtogroup STM32F4xx_System_Exported_Constants 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @addtogroup STM32F4xx_System_Exported_Macros 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @addtogroup STM32F4xx_System_Exported_Functions 100 | * @{ 101 | */ 102 | 103 | extern void SystemInit(void); 104 | extern void SystemCoreClockUpdate(void); 105 | /** 106 | * @} 107 | */ 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif /*__SYSTEM_STM32F4XX_H */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /** 120 | * @} 121 | */ 122 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 123 | -------------------------------------------------------------------------------- /include/usbd_gs_can.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | #include 31 | 32 | #include "can.h" 33 | #include "compiler.h" 34 | #include "config.h" 35 | #include "gs_usb.h" 36 | #include "led.h" 37 | #include "list.h" 38 | #include "usbd_def.h" 39 | 40 | /* Define these here so they can be referenced in other files */ 41 | 42 | #define GS_CAN_EP0_BUF_SIZE \ 43 | max6(sizeof(struct gs_host_config), \ 44 | sizeof(struct gs_device_bittiming), \ 45 | sizeof(struct gs_device_mode), \ 46 | sizeof(struct gs_identify_mode), \ 47 | sizeof(struct gs_device_termination_state), \ 48 | sizeof(struct gs_device_filter)) 49 | 50 | #ifdef CONFIG_CANFD 51 | #define CAN_DATA_MAX_PACKET_SIZE 64 /* Endpoint IN & OUT Packet size */ 52 | #else 53 | #define CAN_DATA_MAX_PACKET_SIZE 32 /* Endpoint IN & OUT Packet size */ 54 | #endif 55 | #define USB_CAN_CONFIG_DESC_SIZ 50 56 | #define USBD_GS_CAN_VENDOR_CODE 0x20 57 | #define DFU_INTERFACE_NUM 1 58 | #define DFU_INTERFACE_STR_INDEX 0xE0 59 | 60 | extern USBD_ClassTypeDef USBD_GS_CAN; 61 | 62 | #ifdef CONFIG_CANFD 63 | #define GS_HOST_FRAME_SIZE struct_size((struct gs_host_frame *)NULL, canfd_ts, 1) 64 | #else 65 | #define GS_HOST_FRAME_SIZE struct_size((struct gs_host_frame *)NULL, classic_can_ts, 1) 66 | #endif 67 | 68 | struct gs_host_frame_object { 69 | struct list_head list; 70 | union { 71 | uint8_t _buf[GS_HOST_FRAME_SIZE]; 72 | struct gs_host_frame frame; 73 | }; 74 | }; 75 | 76 | typedef struct { 77 | uint8_t __aligned(4) ep0_buf[GS_CAN_EP0_BUF_SIZE]; 78 | 79 | USBD_SetupReqTypedef last_setup_request; 80 | 81 | struct list_head list_frame_pool; 82 | struct list_head list_to_host; 83 | 84 | struct gs_host_frame_object *from_host_buf; 85 | struct gs_host_frame_object *to_host_buf; 86 | 87 | can_data_t channels[NUM_CAN_CHANNEL]; 88 | 89 | bool dfu_detach_requested; 90 | 91 | bool timestamps_enabled; 92 | uint32_t sof_timestamp_us; 93 | 94 | bool pad_pkts_to_max_pkt_size; 95 | 96 | struct gs_host_frame_object msgbuf[CAN_QUEUE_SIZE]; 97 | } USBD_GS_CAN_HandleTypeDef __attribute__ ((aligned (4))); 98 | 99 | #if defined(STM32F0) 100 | # define USB_INTERFACE USB 101 | # define USB_INTERRUPT USB_IRQn 102 | #elif defined(STM32F4) 103 | # define USB_INTERFACE USB_OTG_FS 104 | # define USB_INTERRUPT OTG_FS_IRQn 105 | 106 | // RX FIFO is defined in words, so divide bytes by 4 107 | // RX FIFO size chosen according to reference manual RM0368 which suggests 108 | // using (largest packet size / 4) + 1 109 | # define USB_RX_FIFO_SIZE ((256U / 4U) + 1U) 110 | #elif defined(STM32G0) 111 | # define USB_INTERFACE USB_DRD_FS 112 | # define USB_INTERRUPT USB_UCPD1_2_IRQn 113 | #endif 114 | 115 | uint8_t USBD_GS_CAN_Init(USBD_GS_CAN_HandleTypeDef *hcan, USBD_HandleTypeDef *pdev); 116 | void USBD_GS_CAN_SuspendCallback(USBD_HandleTypeDef *pdev); 117 | void USBD_GS_CAN_ResumeCallback(USBD_HandleTypeDef *pdev); 118 | void USBD_GS_CAN_ReceiveFromHost(USBD_HandleTypeDef *pdev); 119 | void USBD_GS_CAN_SendToHost(USBD_HandleTypeDef *pdev); 120 | bool USBD_GS_CAN_CustomDeviceRequest(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 121 | bool USBD_GS_CAN_CustomInterfaceRequest(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 122 | 123 | bool USBD_GS_CAN_DfuDetachRequested(USBD_HandleTypeDef *pdev); 124 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/stm32f0xx/stm32f0xx_hal_cortex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_cortex.h 4 | * @author MCD Application Team 5 | * @brief Header file of CORTEX HAL module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F0xx_HAL_CORTEX_H 22 | #define __STM32F0xx_HAL_CORTEX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f0xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F0xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup CORTEX CORTEX 36 | * @{ 37 | */ 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* Exported constants --------------------------------------------------------*/ 40 | 41 | /** @defgroup CORTEX_Exported_Constants CORTEX Exported Constants 42 | * @{ 43 | */ 44 | 45 | /** @defgroup CORTEX_SysTick_clock_source CORTEX SysTick clock source 46 | * @{ 47 | */ 48 | #define SYSTICK_CLKSOURCE_HCLK_DIV8 (0x00000000U) 49 | #define SYSTICK_CLKSOURCE_HCLK (0x00000004U) 50 | 51 | /** 52 | * @} 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /* Exported Macros -----------------------------------------------------------*/ 60 | 61 | /* Exported functions --------------------------------------------------------*/ 62 | /** @addtogroup CORTEX_Exported_Functions CORTEX Exported Functions 63 | * @{ 64 | */ 65 | /** @addtogroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions 66 | * @brief Initialization and Configuration functions 67 | * @{ 68 | */ 69 | /* Initialization and de-initialization functions *******************************/ 70 | void HAL_NVIC_SetPriority(IRQn_Type IRQn,uint32_t PreemptPriority, uint32_t SubPriority); 71 | void HAL_NVIC_EnableIRQ(IRQn_Type IRQn); 72 | void HAL_NVIC_DisableIRQ(IRQn_Type IRQn); 73 | void HAL_NVIC_SystemReset(void); 74 | uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb); 75 | /** 76 | * @} 77 | */ 78 | 79 | /** @addtogroup CORTEX_Exported_Functions_Group2 Peripheral Control functions 80 | * @brief Cortex control functions 81 | * @{ 82 | */ 83 | 84 | /* Peripheral Control functions *************************************************/ 85 | uint32_t HAL_NVIC_GetPriority(IRQn_Type IRQn); 86 | uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn); 87 | void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn); 88 | void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn); 89 | void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource); 90 | void HAL_SYSTICK_IRQHandler(void); 91 | void HAL_SYSTICK_Callback(void); 92 | /** 93 | * @} 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /* Private types -------------------------------------------------------------*/ 101 | /* Private variables ---------------------------------------------------------*/ 102 | /* Private constants ---------------------------------------------------------*/ 103 | /* Private macros ------------------------------------------------------------*/ 104 | /** @defgroup CORTEX_Private_Macros CORTEX Private Macros 105 | * @{ 106 | */ 107 | #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x4) 108 | 109 | #define IS_NVIC_DEVICE_IRQ(IRQ) ((IRQ) >= 0x00) 110 | 111 | #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SYSTICK_CLKSOURCE_HCLK) || \ 112 | ((SOURCE) == SYSTICK_CLKSOURCE_HCLK_DIV8)) 113 | /** 114 | * @} 115 | */ 116 | 117 | /** 118 | * @} 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | #ifdef __cplusplus 126 | } 127 | #endif 128 | 129 | #endif /* __STM32F0xx_HAL_CORTEX_H */ 130 | 131 | 132 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 133 | 134 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include "can.h" 32 | #include "can_common.h" 33 | #include "config.h" 34 | #include "device.h" 35 | #include "dfu.h" 36 | #include "gpio.h" 37 | #include "gs_usb.h" 38 | #include "hal_include.h" 39 | #include "led.h" 40 | #include "timer.h" 41 | #include "usbd_conf.h" 42 | #include "usbd_core.h" 43 | #include "usbd_def.h" 44 | #include "usbd_desc.h" 45 | #include "usbd_gs_can.h" 46 | #include "util.h" 47 | 48 | void HAL_MspInit(void); 49 | static void SystemClock_Config(void); 50 | 51 | static USBD_GS_CAN_HandleTypeDef hGS_CAN; 52 | static USBD_HandleTypeDef hUSB = {0}; 53 | 54 | void __weak _close(void) { 55 | } 56 | void __weak _lseek(void) { 57 | } 58 | void __weak _read(void) { 59 | } 60 | void __weak _write(void) { 61 | } 62 | 63 | int main(void) 64 | { 65 | HAL_Init(); 66 | SystemClock_Config(); 67 | 68 | gpio_init(); 69 | timer_init(); 70 | 71 | INIT_LIST_HEAD(&hGS_CAN.list_frame_pool); 72 | INIT_LIST_HEAD(&hGS_CAN.list_to_host); 73 | 74 | for (unsigned i = 0; i < ARRAY_SIZE(hGS_CAN.msgbuf); i++) { 75 | list_add_tail(&hGS_CAN.msgbuf[i].list, &hGS_CAN.list_frame_pool); 76 | } 77 | 78 | for (unsigned int i = 0; i < ARRAY_SIZE(hGS_CAN.channels); i++) { 79 | can_data_t *channel = &hGS_CAN.channels[i]; 80 | 81 | channel->nr = i; 82 | 83 | INIT_LIST_HEAD(&channel->list_from_host); 84 | 85 | led_init(&channel->leds, 86 | LEDRX_GPIO_Port, LEDRX_Pin, LEDRX_Active_High, 87 | LEDTX_GPIO_Port, LEDTX_Pin, LEDTX_Active_High); 88 | 89 | /* nice wake-up pattern */ 90 | for (uint8_t j = 0; j < 10; j++) { 91 | HAL_GPIO_TogglePin(LEDRX_GPIO_Port, LEDRX_Pin); 92 | HAL_Delay(50); 93 | HAL_GPIO_TogglePin(LEDTX_GPIO_Port, LEDTX_Pin); 94 | } 95 | 96 | led_set_mode(&channel->leds, LED_MODE_OFF); 97 | 98 | can_init(channel, CAN_INTERFACE); 99 | can_disable(channel); 100 | 101 | #ifdef CAN_S_GPIO_Port 102 | HAL_GPIO_WritePin(CAN_S_GPIO_Port, CAN_S_Pin, GPIO_PIN_RESET); 103 | #endif 104 | } 105 | 106 | USBD_Init(&hUSB, (USBD_DescriptorsTypeDef*)&FS_Desc, DEVICE_FS); 107 | USBD_RegisterClass(&hUSB, &USBD_GS_CAN); 108 | USBD_GS_CAN_Init(&hGS_CAN, &hUSB); 109 | USBD_Start(&hUSB); 110 | 111 | while (1) { 112 | for (unsigned int i = 0; i < ARRAY_SIZE(hGS_CAN.channels); i++) { 113 | can_data_t *channel = &hGS_CAN.channels[i]; 114 | 115 | CAN_SendFrame(&hGS_CAN, channel); 116 | } 117 | 118 | USBD_GS_CAN_ReceiveFromHost(&hUSB); 119 | USBD_GS_CAN_SendToHost(&hUSB); 120 | 121 | for (unsigned int i = 0; i < ARRAY_SIZE(hGS_CAN.channels); i++) { 122 | can_data_t *channel = &hGS_CAN.channels[i]; 123 | 124 | CAN_ReceiveFrame(&hGS_CAN, channel); 125 | CAN_HandleError(&hGS_CAN, channel); 126 | 127 | led_update(&channel->leds); 128 | } 129 | 130 | if (USBD_GS_CAN_DfuDetachRequested(&hUSB)) { 131 | dfu_run_bootloader(); 132 | } 133 | } 134 | } 135 | 136 | void HAL_MspInit(void) 137 | { 138 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 139 | #if defined(STM32F4) 140 | __HAL_RCC_PWR_CLK_ENABLE(); 141 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); 142 | #elif defined(STM32G0) 143 | __HAL_RCC_PWR_CLK_ENABLE(); 144 | HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); 145 | #endif 146 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 147 | } 148 | 149 | void SystemClock_Config(void) 150 | { 151 | device_sysclock_config(); 152 | } 153 | -------------------------------------------------------------------------------- /src/led.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include 28 | 29 | #include "led.h" 30 | #include "hal_include.h" 31 | #include "util.h" 32 | 33 | #define SEQ_ISPASSED(now, target) ((int32_t) ((now) - (target)) >= 0) 34 | 35 | void led_init( 36 | led_data_t *leds, 37 | void* led_rx_port, uint16_t led_rx_pin, bool led_rx_active_high, 38 | void* led_tx_port, uint16_t led_tx_pin, bool led_tx_active_high 39 | ) { 40 | memset(leds, 0, sizeof(led_data_t)); 41 | leds->led_state[LED_RX].port = led_rx_port; 42 | leds->led_state[LED_RX].pin = led_rx_pin; 43 | leds->led_state[LED_RX].is_active_high = led_rx_active_high; 44 | leds->led_state[LED_TX].port = led_tx_port; 45 | leds->led_state[LED_TX].pin = led_tx_pin; 46 | leds->led_state[LED_TX].is_active_high = led_tx_active_high; 47 | } 48 | 49 | void led_set_mode(led_data_t *leds,led_mode_t mode) 50 | { 51 | leds->mode = mode; 52 | led_update(leds); 53 | } 54 | 55 | static void led_set(led_state_t *led, bool state) 56 | { 57 | if (!led->is_active_high) { 58 | state = !state; 59 | } 60 | 61 | HAL_GPIO_WritePin(led->port, led->pin, state ? GPIO_PIN_SET : GPIO_PIN_RESET); 62 | } 63 | 64 | static uint32_t led_set_sequence_step(led_data_t *leds, uint32_t step_num) 65 | { 66 | const led_seq_step_t *step = &leds->sequence[step_num]; 67 | leds->sequence_step = step_num; 68 | led_set(&leds->led_state[LED_RX], step->state & 0x01); 69 | led_set(&leds->led_state[LED_TX], step->state & 0x02); 70 | uint32_t delta = 10 * step->time_in_10ms; 71 | if (delta > INT32_MAX) { 72 | delta = INT32_MAX; //clamp 73 | } 74 | leds->t_sequence_next = HAL_GetTick() + delta; 75 | return delta; 76 | } 77 | 78 | void led_run_sequence(led_data_t *leds, const led_seq_step_t *sequence, int32_t num_repeat) 79 | { 80 | leds->mode = LED_MODE_SEQUENCE; 81 | leds->sequence = sequence; 82 | leds->seq_num_repeat = num_repeat; 83 | led_set_sequence_step(leds, 0); 84 | led_update(leds); 85 | } 86 | 87 | void led_indicate_trx(led_data_t *leds, led_num_t num) { 88 | leds->led_state[num].blink_request = 1; 89 | } 90 | 91 | static void led_trx_blinker(led_state_t *ledstate, uint32_t now) { 92 | if ( SEQ_ISPASSED(now, ledstate->on_until) && 93 | SEQ_ISPASSED(now, ledstate->off_until) ) { 94 | ledstate->off_until = now + 30; 95 | ledstate->on_until = now + 45; 96 | } 97 | } 98 | 99 | static void led_update_normal_mode(led_state_t *led, uint32_t now) 100 | { 101 | if (led->blink_request) { 102 | led->blink_request = 0; 103 | led_trx_blinker(led, now); 104 | } 105 | 106 | led_set(led, SEQ_ISPASSED(now, led->off_until)); 107 | } 108 | 109 | static void led_update_sequence(led_data_t *leds) 110 | { 111 | if (leds->sequence == NULL) { 112 | return; 113 | } 114 | 115 | uint32_t now = HAL_GetTick(); 116 | if (SEQ_ISPASSED(now, leds->t_sequence_next)) { 117 | 118 | uint32_t t = led_set_sequence_step(leds, ++leds->sequence_step); 119 | 120 | if (t > 0) { // the saga continues 121 | 122 | leds->t_sequence_next = now + t; 123 | 124 | } else { // end of sequence 125 | 126 | if (leds->seq_num_repeat != 0) { 127 | 128 | if (leds->seq_num_repeat > 0) { 129 | leds->seq_num_repeat--; 130 | } 131 | 132 | led_set_sequence_step(leds, 0); 133 | 134 | } else { 135 | leds->sequence = NULL; 136 | } 137 | } 138 | } 139 | } 140 | 141 | void led_update(led_data_t *leds) 142 | { 143 | static uint32_t next_update = 0; 144 | uint32_t now = HAL_GetTick(); 145 | if (!SEQ_ISPASSED(now, next_update)) { 146 | return; 147 | } 148 | next_update = now + LED_UPDATE_INTERVAL; 149 | 150 | switch (leds->mode) { 151 | 152 | case LED_MODE_OFF: 153 | led_set(&leds->led_state[LED_RX], false); 154 | led_set(&leds->led_state[LED_TX], false); 155 | break; 156 | 157 | case LED_MODE_NORMAL: 158 | led_update_normal_mode(&leds->led_state[LED_RX], now); 159 | led_update_normal_mode(&leds->led_state[LED_TX], now); 160 | break; 161 | 162 | case LED_MODE_SEQUENCE: 163 | led_update_sequence(leds); 164 | break; 165 | 166 | default: 167 | assert_failed(); 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /src/usbd_desc.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #include "config.h" 31 | #include "usbd_ctlreq.h" 32 | #include "usbd_desc.h" 33 | #include "util.h" 34 | 35 | static uint8_t *USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 36 | static uint8_t *USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 37 | static uint8_t *USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 38 | static uint8_t *USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 39 | static uint8_t *USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 40 | static uint8_t *USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 41 | static uint8_t *USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 42 | 43 | const USBD_DescriptorsTypeDef FS_Desc = { 44 | USBD_FS_DeviceDescriptor, 45 | USBD_FS_LangIDStrDescriptor, 46 | USBD_FS_ManufacturerStrDescriptor, 47 | USBD_FS_ProductStrDescriptor, 48 | USBD_FS_SerialStrDescriptor, 49 | USBD_FS_ConfigStrDescriptor, 50 | USBD_FS_InterfaceStrDescriptor, 51 | }; 52 | 53 | __ALIGN_BEGIN uint8_t USBD_DescBuf[USBD_DESC_BUF_SIZE] __ALIGN_END; 54 | 55 | /* USB_DeviceDescriptor */ 56 | static const uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] = { 57 | 0x12, /* bLength */ 58 | USB_DESC_TYPE_DEVICE, /* bDescriptorType */ 59 | 0x00, /* bcdUSB */ 60 | 0x02, 61 | 0x00, /* bDeviceClass */ 62 | 0x00, /* bDeviceSubClass */ 63 | 0x00, /* bDeviceProtocol */ 64 | USB_MAX_EP0_SIZE, /* bMaxPacketSize */ 65 | LOBYTE(USBD_VID), /* idVendor */ 66 | HIBYTE(USBD_VID), 67 | LOBYTE(USBD_PID_FS), /* idProduct */ 68 | HIBYTE(USBD_PID_FS), 69 | 0x00, /* bcdDevice rel. 0.00 */ 70 | 0x00, 71 | USBD_IDX_MFC_STR, /* Index of manufacturer string */ 72 | USBD_IDX_PRODUCT_STR, /* Index of product string */ 73 | USBD_IDX_SERIAL_STR, /* Index of serial number string */ 74 | USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */ 75 | }; 76 | 77 | /* USB Standard Device Descriptor */ 78 | static const uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] = 79 | { 80 | USB_LEN_LANGID_STR_DESC, 81 | USB_DESC_TYPE_STRING, 82 | LOBYTE(USBD_LANGID_STRING), 83 | HIBYTE(USBD_LANGID_STRING), 84 | }; 85 | 86 | uint8_t *USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 87 | { 88 | UNUSED(speed); 89 | *length = sizeof(USBD_FS_DeviceDesc); 90 | memcpy(USBD_DescBuf, USBD_FS_DeviceDesc, sizeof(USBD_FS_DeviceDesc)); 91 | return USBD_DescBuf; 92 | } 93 | 94 | uint8_t *USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 95 | { 96 | UNUSED(speed); 97 | *length = sizeof(USBD_LangIDDesc); 98 | memcpy(USBD_DescBuf, USBD_LangIDDesc, sizeof(USBD_LangIDDesc)); 99 | return USBD_DescBuf; 100 | } 101 | 102 | uint8_t *USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 103 | { 104 | UNUSED(speed); 105 | USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_DescBuf, length); 106 | return USBD_DescBuf; 107 | } 108 | 109 | uint8_t *USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 110 | { 111 | UNUSED(speed); 112 | USBD_GetString ((uint8_t *)USBD_MANUFACTURER_STRING, USBD_DescBuf, length); 113 | return USBD_DescBuf; 114 | } 115 | 116 | uint8_t *USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 117 | { 118 | char buf[25]; 119 | 120 | UNUSED(speed); 121 | 122 | hex32(buf, *(uint32_t*)(UID_BASE )); 123 | hex32(buf + 8, *(uint32_t*)(UID_BASE + 4)); 124 | hex32(buf + 16, *(uint32_t*)(UID_BASE + 8)); 125 | 126 | USBD_GetString((uint8_t*)buf, USBD_DescBuf, length); 127 | return USBD_DescBuf; 128 | } 129 | 130 | uint8_t *USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 131 | { 132 | UNUSED(speed); 133 | USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_DescBuf, length); 134 | return USBD_DescBuf; 135 | } 136 | 137 | uint8_t *USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 138 | { 139 | UNUSED(speed); 140 | USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_DescBuf, length); 141 | return USBD_DescBuf; 142 | } 143 | -------------------------------------------------------------------------------- /src/gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include "gpio.h" 28 | #include "hal_include.h" 29 | 30 | #ifdef TERM_Pin 31 | static int term_state = 0; 32 | 33 | enum gs_can_termination_state get_term(unsigned int channel) 34 | { 35 | if (term_state & (1 << channel)) { 36 | return GS_CAN_TERMINATION_STATE_ON; 37 | } else { 38 | return GS_CAN_TERMINATION_STATE_OFF; 39 | } 40 | } 41 | 42 | enum gs_can_termination_state set_term(unsigned int channel, enum gs_can_termination_state state) 43 | { 44 | if (state == GS_CAN_TERMINATION_STATE_ON) { 45 | term_state |= 1 << channel; 46 | } else { 47 | term_state &= ~(1 << channel); 48 | } 49 | 50 | #if (TERM_Active_High == 1) 51 | #define TERM_ON GPIO_PIN_SET 52 | #define TERM_OFF GPIO_PIN_RESET 53 | #else 54 | #define TERM_ON GPIO_PIN_RESET 55 | #define TERM_OFF GPIO_PIN_SET 56 | #endif 57 | 58 | HAL_GPIO_WritePin(TERM_GPIO_Port, TERM_Pin, (state ? TERM_ON : TERM_OFF)); 59 | 60 | return state; 61 | } 62 | 63 | static inline void gpio_init_term(void) 64 | { 65 | HAL_GPIO_WritePin(TERM_GPIO_Port, TERM_Pin, GPIO_INIT_STATE(TERM_Active_High)); 66 | 67 | GPIO_InitTypeDef GPIO_InitStruct = { 68 | .Pin = TERM_Pin, 69 | .Mode = TERM_Mode, 70 | .Pull = GPIO_NOPULL, 71 | .Speed = GPIO_SPEED_FREQ_LOW, 72 | .Alternate = 0 73 | }; 74 | HAL_GPIO_Init(TERM_GPIO_Port, &GPIO_InitStruct); 75 | } 76 | 77 | #else 78 | 79 | static inline void gpio_init_term(void) 80 | { 81 | } 82 | 83 | #endif 84 | 85 | // must run before can_init 86 | void gpio_init(void) 87 | { 88 | GPIO_InitTypeDef GPIO_InitStruct; 89 | 90 | __HAL_RCC_GPIOA_CLK_ENABLE(); 91 | __HAL_RCC_GPIOB_CLK_ENABLE(); 92 | __HAL_RCC_GPIOC_CLK_ENABLE(); 93 | #if defined(STM32F4) 94 | __HAL_RCC_GPIOD_CLK_ENABLE(); 95 | #endif 96 | 97 | #ifdef CAN_S_Pin 98 | HAL_GPIO_WritePin(CAN_S_GPIO_Port, CAN_S_Pin, GPIO_PIN_SET); 99 | GPIO_InitStruct.Pin = CAN_S_Pin; 100 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 101 | GPIO_InitStruct.Pull = GPIO_NOPULL; 102 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 103 | HAL_GPIO_Init(CAN_S_GPIO_Port, &GPIO_InitStruct); 104 | #endif 105 | 106 | #ifdef LEDRX_Pin 107 | HAL_GPIO_WritePin(LEDRX_GPIO_Port, LEDRX_Pin, GPIO_INIT_STATE(LEDRX_Active_High)); 108 | GPIO_InitStruct.Pin = LEDRX_Pin; 109 | GPIO_InitStruct.Mode = LEDRX_Mode; 110 | GPIO_InitStruct.Pull = GPIO_NOPULL; 111 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 112 | HAL_GPIO_Init(LEDRX_GPIO_Port, &GPIO_InitStruct); 113 | #endif 114 | 115 | #ifdef LEDTX_Pin 116 | HAL_GPIO_WritePin(LEDTX_GPIO_Port, LEDTX_Pin, GPIO_INIT_STATE(LEDTX_Active_High)); 117 | GPIO_InitStruct.Pin = LEDTX_Pin; 118 | GPIO_InitStruct.Mode = LEDTX_Mode; 119 | GPIO_InitStruct.Pull = GPIO_NOPULL; 120 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 121 | HAL_GPIO_Init(LEDTX_GPIO_Port, &GPIO_InitStruct); 122 | #endif 123 | 124 | #ifdef nCANSTBY_Pin 125 | HAL_GPIO_WritePin(nCANSTBY_Port, nCANSTBY_Pin, GPIO_INIT_STATE(nCANSTBY_Active_High)); 126 | GPIO_InitStruct.Pin = nCANSTBY_Pin; 127 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 128 | GPIO_InitStruct.Pull = GPIO_NOPULL; 129 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 130 | HAL_GPIO_Init(nCANSTBY_Port, &GPIO_InitStruct); //xceiver standby. 131 | #endif 132 | 133 | #ifdef DCDCEN_Pin 134 | HAL_GPIO_WritePin(DCDCEN_Port, DCDCEN_Pin, GPIO_PIN_SET); 135 | GPIO_InitStruct.Pin = DCDCEN_Pin; 136 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 137 | GPIO_InitStruct.Pull = GPIO_NOPULL; 138 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 139 | HAL_GPIO_Init(DCDCEN_Port, &GPIO_InitStruct); //start DCDC (TODO : wait until enumerated) 140 | #endif 141 | 142 | #ifdef nSI86EN_Pin 143 | HAL_GPIO_WritePin(nSI86EN_Port, nSI86EN_Pin, GPIO_PIN_RESET); 144 | GPIO_InitStruct.Pin = nSI86EN_Pin; 145 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 146 | GPIO_InitStruct.Pull = GPIO_NOPULL; 147 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 148 | HAL_GPIO_Init(nSI86EN_Port, &GPIO_InitStruct); //enable si86 149 | #endif 150 | 151 | 152 | #if defined(BOARD_STM32F4_DevBoard) 153 | // initialize USB pins 154 | GPIO_InitStruct.Pin = USB_Pin_DM | USB_Pin_DP; 155 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 156 | GPIO_InitStruct.Pull = GPIO_NOPULL; 157 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 158 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; 159 | HAL_GPIO_Init(USB_GPIO_Port, &GPIO_InitStruct); 160 | #endif 161 | 162 | gpio_init_term(); 163 | } 164 | -------------------------------------------------------------------------------- /src/can_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include "can_common.h" 28 | #include "led.h" 29 | #include "timer.h" 30 | #include "usbd_gs_can.h" 31 | 32 | #ifndef CONFIG_CANFD 33 | const struct gs_device_bt_const_extended CAN_btconst_ext; 34 | #endif 35 | 36 | #ifndef CONFIG_CAN_FILTER 37 | const struct gs_device_filter_info CAN_filter_info; 38 | #endif 39 | 40 | bool can_check_bittiming_ok(const struct can_bittiming_const *btc, 41 | const struct gs_device_bittiming *timing) 42 | { 43 | const uint32_t tseg1 = timing->prop_seg + timing->phase_seg1; 44 | 45 | if (tseg1 < btc->tseg1_min || 46 | tseg1 > btc->tseg1_max || 47 | timing->phase_seg2 < btc->tseg2_min || 48 | timing->phase_seg2 > btc->tseg2_max || 49 | timing->sjw > btc->sjw_max || 50 | timing->brp < btc->brp_min || 51 | timing->brp > btc->brp_max) 52 | return false; 53 | 54 | return true; 55 | } 56 | 57 | #ifdef CONFIG_CAN_FILTER 58 | bool can_check_filter_ok(const struct gs_device_filter *filter) 59 | { 60 | return filter->info.dev == CAN_filter_info.dev; 61 | } 62 | #endif 63 | 64 | void CAN_SendFrame(USBD_GS_CAN_HandleTypeDef *hcan, can_data_t *channel) 65 | { 66 | struct gs_host_frame_object *frame_object; 67 | 68 | bool was_irq_enabled = disable_irq(); 69 | frame_object = list_first_entry_or_null(&channel->list_from_host, 70 | struct gs_host_frame_object, 71 | list); 72 | if (!frame_object) { 73 | restore_irq(was_irq_enabled); 74 | return; 75 | } 76 | 77 | list_del(&frame_object->list); 78 | restore_irq(was_irq_enabled); 79 | 80 | struct gs_host_frame *frame = &frame_object->frame; 81 | 82 | if (!can_send(channel, frame)) { 83 | list_add_locked(&frame_object->list, &channel->list_from_host); 84 | return; 85 | } 86 | 87 | // Echo sent frame back to host 88 | frame->reserved = 0x0; 89 | if (IS_ENABLED(CONFIG_CANFD) && frame->flags & GS_CAN_FLAG_FD) 90 | frame->canfd_ts->timestamp_us = timer_get(); 91 | else 92 | frame->classic_can_ts->timestamp_us = timer_get(); 93 | 94 | list_add_tail_locked(&frame_object->list, &hcan->list_to_host); 95 | 96 | led_indicate_trx(&channel->leds, LED_TX); 97 | } 98 | 99 | void CAN_ReceiveFrame(USBD_GS_CAN_HandleTypeDef *hcan, can_data_t *channel) 100 | { 101 | struct gs_host_frame_object *frame_object; 102 | 103 | if (!can_is_rx_pending(channel)) { 104 | return; 105 | } 106 | 107 | bool was_irq_enabled = disable_irq(); 108 | frame_object = list_first_entry_or_null(&hcan->list_frame_pool, 109 | struct gs_host_frame_object, 110 | list); 111 | if (!frame_object) { 112 | restore_irq(was_irq_enabled); 113 | return; 114 | } 115 | 116 | list_del(&frame_object->list); 117 | restore_irq(was_irq_enabled); 118 | 119 | struct gs_host_frame *frame = &frame_object->frame; 120 | 121 | if (!can_receive(channel, frame)) { 122 | list_add_tail_locked(&frame_object->list, &hcan->list_frame_pool); 123 | return; 124 | } 125 | 126 | frame->echo_id = 0xFFFFFFFF; // not an echo frame 127 | frame->reserved = 0; 128 | 129 | list_add_tail_locked(&frame_object->list, &hcan->list_to_host); 130 | 131 | led_indicate_trx(&channel->leds, LED_RX); 132 | } 133 | 134 | // If there are frames to receive, don't report any error frames. The 135 | // best we can localize the errors to is "after the last successfully 136 | // received frame", so wait until we get there. LEC will hold some error 137 | // to report even if multiple pass by. 138 | void CAN_HandleError(USBD_GS_CAN_HandleTypeDef *hcan, can_data_t *channel) 139 | { 140 | struct gs_host_frame_object *frame_object; 141 | 142 | if (can_is_rx_pending(channel)) { 143 | return; 144 | } 145 | 146 | uint32_t can_err = can_get_error_status(channel); 147 | 148 | bool was_irq_enabled = disable_irq(); 149 | frame_object = list_first_entry_or_null(&hcan->list_frame_pool, 150 | struct gs_host_frame_object, 151 | list); 152 | if (!frame_object) { 153 | restore_irq(was_irq_enabled); 154 | return; 155 | } 156 | 157 | list_del(&frame_object->list); 158 | restore_irq(was_irq_enabled); 159 | 160 | struct gs_host_frame *frame = &frame_object->frame; 161 | frame->classic_can_ts->timestamp_us = timer_get(); 162 | frame->channel = channel->nr; 163 | 164 | if (can_parse_error_status(channel, frame, can_err)) { 165 | list_add_tail_locked(&frame_object->list, &hcan->list_to_host); 166 | } else { 167 | list_add_tail_locked(&frame_object->list, &hcan->list_frame_pool); 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /libs/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.c 4 | * @author MCD Application Team 5 | * @brief This file provides the IO requests APIs for control endpoints. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "usbd_ioreq.h" 22 | 23 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 24 | * @{ 25 | */ 26 | 27 | 28 | /** @defgroup USBD_IOREQ 29 | * @brief control I/O requests module 30 | * @{ 31 | */ 32 | 33 | /** @defgroup USBD_IOREQ_Private_TypesDefinitions 34 | * @{ 35 | */ 36 | /** 37 | * @} 38 | */ 39 | 40 | 41 | /** @defgroup USBD_IOREQ_Private_Defines 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @} 47 | */ 48 | 49 | 50 | /** @defgroup USBD_IOREQ_Private_Macros 51 | * @{ 52 | */ 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup USBD_IOREQ_Private_Variables 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | 67 | /** @defgroup USBD_IOREQ_Private_FunctionPrototypes 68 | * @{ 69 | */ 70 | /** 71 | * @} 72 | */ 73 | 74 | 75 | /** @defgroup USBD_IOREQ_Private_Functions 76 | * @{ 77 | */ 78 | 79 | /** 80 | * @brief USBD_CtlSendData 81 | * send data on the ctl pipe 82 | * @param pdev: device instance 83 | * @param buff: pointer to data buffer 84 | * @param len: length of data to be sent 85 | * @retval status 86 | */ 87 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, 88 | uint8_t *pbuf, uint16_t len) 89 | { 90 | /* Set EP0 State */ 91 | pdev->ep0_state = USBD_EP0_DATA_IN; 92 | pdev->ep_in[0].total_length = len; 93 | pdev->ep_in[0].rem_length = len; 94 | 95 | /* Start the transfer */ 96 | USBD_LL_Transmit(pdev, 0x00U, pbuf, len); 97 | 98 | return USBD_OK; 99 | } 100 | 101 | /** 102 | * @brief USBD_CtlContinueSendData 103 | * continue sending data on the ctl pipe 104 | * @param pdev: device instance 105 | * @param buff: pointer to data buffer 106 | * @param len: length of data to be sent 107 | * @retval status 108 | */ 109 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, 110 | uint8_t *pbuf, uint16_t len) 111 | { 112 | /* Start the next transfer */ 113 | USBD_LL_Transmit(pdev, 0x00U, pbuf, len); 114 | 115 | return USBD_OK; 116 | } 117 | 118 | /** 119 | * @brief USBD_CtlPrepareRx 120 | * receive data on the ctl pipe 121 | * @param pdev: device instance 122 | * @param buff: pointer to data buffer 123 | * @param len: length of data to be received 124 | * @retval status 125 | */ 126 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, 127 | uint8_t *pbuf, uint16_t len) 128 | { 129 | /* Set EP0 State */ 130 | pdev->ep0_state = USBD_EP0_DATA_OUT; 131 | pdev->ep_out[0].total_length = len; 132 | pdev->ep_out[0].rem_length = len; 133 | 134 | /* Start the transfer */ 135 | USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 136 | 137 | return USBD_OK; 138 | } 139 | 140 | /** 141 | * @brief USBD_CtlContinueRx 142 | * continue receive data on the ctl pipe 143 | * @param pdev: device instance 144 | * @param buff: pointer to data buffer 145 | * @param len: length of data to be received 146 | * @retval status 147 | */ 148 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, 149 | uint8_t *pbuf, uint16_t len) 150 | { 151 | USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 152 | 153 | return USBD_OK; 154 | } 155 | 156 | /** 157 | * @brief USBD_CtlSendStatus 158 | * send zero lzngth packet on the ctl pipe 159 | * @param pdev: device instance 160 | * @retval status 161 | */ 162 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev) 163 | { 164 | /* Set EP0 State */ 165 | pdev->ep0_state = USBD_EP0_STATUS_IN; 166 | 167 | /* Start the transfer */ 168 | USBD_LL_Transmit(pdev, 0x00U, NULL, 0U); 169 | 170 | return USBD_OK; 171 | } 172 | 173 | /** 174 | * @brief USBD_CtlReceiveStatus 175 | * receive zero lzngth packet on the ctl pipe 176 | * @param pdev: device instance 177 | * @retval status 178 | */ 179 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev) 180 | { 181 | /* Set EP0 State */ 182 | pdev->ep0_state = USBD_EP0_STATUS_OUT; 183 | 184 | /* Start the transfer */ 185 | USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); 186 | 187 | return USBD_OK; 188 | } 189 | 190 | /** 191 | * @brief USBD_GetRxCount 192 | * returns the received data length 193 | * @param pdev: device instance 194 | * @param ep_addr: endpoint address 195 | * @retval Rx Data blength 196 | */ 197 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 198 | { 199 | return USBD_LL_GetRxDataSize(pdev, ep_addr); 200 | } 201 | 202 | /** 203 | * @} 204 | */ 205 | 206 | 207 | /** 208 | * @} 209 | */ 210 | 211 | 212 | /** 213 | * @} 214 | */ 215 | 216 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 217 | -------------------------------------------------------------------------------- /libs/STM32_USB_Device_Library/Core/Inc/usbd_core.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_core.h 4 | * @author MCD Application Team 5 | * @brief Header file for usbd_core.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_CORE_H 22 | #define __USBD_CORE_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_conf.h" 30 | #include "usbd_def.h" 31 | #include "usbd_ioreq.h" 32 | #include "usbd_ctlreq.h" 33 | 34 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 35 | * @{ 36 | */ 37 | 38 | /** @defgroup USBD_CORE 39 | * @brief This file is the Header file for usbd_core.c file 40 | * @{ 41 | */ 42 | 43 | 44 | /** @defgroup USBD_CORE_Exported_Defines 45 | * @{ 46 | */ 47 | #ifndef USBD_DEBUG_LEVEL 48 | #define USBD_DEBUG_LEVEL 0U 49 | #endif /* USBD_DEBUG_LEVEL */ 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 56 | * @{ 57 | */ 58 | 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | 66 | /** @defgroup USBD_CORE_Exported_Macros 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup USBD_CORE_Exported_Variables 75 | * @{ 76 | */ 77 | #define USBD_SOF USBD_LL_SOF 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @defgroup USBD_CORE_Exported_FunctionsPrototype 83 | * @{ 84 | */ 85 | USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id); 86 | USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev); 87 | USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev); 88 | USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev); 89 | USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass); 90 | 91 | USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev); 92 | USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 93 | USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 94 | 95 | USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup); 96 | USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); 97 | USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); 98 | 99 | USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev); 100 | USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed); 101 | USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev); 102 | USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev); 103 | 104 | USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev); 105 | USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 106 | USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 107 | 108 | USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev); 109 | USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev); 110 | 111 | /* USBD Low Level Driver */ 112 | USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev); 113 | USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev); 114 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev); 115 | USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev); 116 | USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, 117 | uint8_t ep_addr, 118 | uint8_t ep_type, 119 | uint16_t ep_mps); 120 | 121 | USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 122 | USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 123 | USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 124 | USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 125 | uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 126 | USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr); 127 | USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, 128 | uint8_t ep_addr, 129 | uint8_t *pbuf, 130 | uint16_t size); 131 | 132 | USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, 133 | uint8_t ep_addr, 134 | uint8_t *pbuf, 135 | uint16_t size); 136 | 137 | uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 138 | void USBD_LL_Delay(uint32_t Delay); 139 | 140 | /** 141 | * @} 142 | */ 143 | 144 | #ifdef __cplusplus 145 | } 146 | #endif 147 | 148 | #endif /* __USBD_CORE_H */ 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | /** 155 | * @} 156 | */ 157 | 158 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/stm32f0xx/stm32f0xx_hal_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_def.h 4 | * @author MCD Application Team 5 | * @brief This file contains HAL common defines, enumeration, macros and 6 | * structures definitions. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2016 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F0xx_HAL_DEF 23 | #define __STM32F0xx_HAL_DEF 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32f0xx.h" 31 | #include "Legacy/stm32_hal_legacy.h" 32 | #include 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | 36 | /** 37 | * @brief HAL Status structures definition 38 | */ 39 | typedef enum 40 | { 41 | HAL_OK = 0x00U, 42 | HAL_ERROR = 0x01U, 43 | HAL_BUSY = 0x02U, 44 | HAL_TIMEOUT = 0x03U 45 | } HAL_StatusTypeDef; 46 | 47 | /** 48 | * @brief HAL Lock structures definition 49 | */ 50 | typedef enum 51 | { 52 | HAL_UNLOCKED = 0x00U, 53 | HAL_LOCKED = 0x01U 54 | } HAL_LockTypeDef; 55 | 56 | /* Exported macro ------------------------------------------------------------*/ 57 | 58 | #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */ 59 | 60 | #define HAL_MAX_DELAY 0xFFFFFFFFU 61 | 62 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) == (BIT)) 63 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U) 64 | 65 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \ 66 | do{ \ 67 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \ 68 | (__DMA_HANDLE__).Parent = (__HANDLE__); \ 69 | } while(0U) 70 | 71 | /** @brief Reset the Handle's State field. 72 | * @param __HANDLE__ specifies the Peripheral Handle. 73 | * @note This macro can be used for the following purpose: 74 | * - When the Handle is declared as local variable; before passing it as parameter 75 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 76 | * to set to 0 the Handle's "State" field. 77 | * Otherwise, "State" field may have any random value and the first time the function 78 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed 79 | * (i.e. HAL_PPP_MspInit() will not be executed). 80 | * - When there is a need to reconfigure the low level hardware: instead of calling 81 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 82 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function 83 | * HAL_PPP_MspInit() which will reconfigure the low level hardware. 84 | * @retval None 85 | */ 86 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U) 87 | 88 | #if (USE_RTOS == 1U) 89 | /* Reserved for future use */ 90 | #error " USE_RTOS should be 0 in the current HAL release " 91 | #else 92 | #define __HAL_LOCK(__HANDLE__) \ 93 | do{ \ 94 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 95 | { \ 96 | return HAL_BUSY; \ 97 | } \ 98 | else \ 99 | { \ 100 | (__HANDLE__)->Lock = HAL_LOCKED; \ 101 | } \ 102 | }while (0U) 103 | 104 | #define __HAL_UNLOCK(__HANDLE__) \ 105 | do{ \ 106 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 107 | }while (0U) 108 | #endif /* USE_RTOS */ 109 | 110 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */ 111 | #ifndef __weak 112 | #define __weak __attribute__((weak)) 113 | #endif 114 | #ifndef __packed 115 | #define __packed __attribute__((packed)) 116 | #endif 117 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 118 | #ifndef __weak 119 | #define __weak __attribute__((weak)) 120 | #endif /* __weak */ 121 | #ifndef __packed 122 | #define __packed __attribute__((__packed__)) 123 | #endif /* __packed */ 124 | #endif /* __GNUC__ */ 125 | 126 | 127 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ 128 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */ 129 | #ifndef __ALIGN_BEGIN 130 | #define __ALIGN_BEGIN 131 | #endif 132 | #ifndef __ALIGN_END 133 | #define __ALIGN_END __attribute__ ((aligned (4))) 134 | #endif 135 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 136 | #ifndef __ALIGN_END 137 | #define __ALIGN_END __attribute__ ((aligned (4))) 138 | #endif /* __ALIGN_END */ 139 | #ifndef __ALIGN_BEGIN 140 | #define __ALIGN_BEGIN 141 | #endif /* __ALIGN_BEGIN */ 142 | #else 143 | #ifndef __ALIGN_END 144 | #define __ALIGN_END 145 | #endif /* __ALIGN_END */ 146 | #ifndef __ALIGN_BEGIN 147 | #if defined (__CC_ARM) /* ARM Compiler V5*/ 148 | #define __ALIGN_BEGIN __align(4) 149 | #elif defined (__ICCARM__) /* IAR Compiler */ 150 | #define __ALIGN_BEGIN 151 | #endif /* __CC_ARM */ 152 | #endif /* __ALIGN_BEGIN */ 153 | #endif /* __GNUC__ */ 154 | 155 | /** 156 | * @brief __NOINLINE definition 157 | */ 158 | #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined ( __GNUC__ ) 159 | /* ARM V4/V5 and V6 & GNU Compiler 160 | ------------------------------- 161 | */ 162 | #define __NOINLINE __attribute__ ( (noinline) ) 163 | 164 | #elif defined ( __ICCARM__ ) 165 | /* ICCARM Compiler 166 | --------------- 167 | */ 168 | #define __NOINLINE _Pragma("optimize = no_inline") 169 | 170 | #endif 171 | 172 | #ifdef __cplusplus 173 | } 174 | #endif 175 | 176 | #endif /* ___STM32F0xx_HAL_DEF */ 177 | 178 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 179 | -------------------------------------------------------------------------------- /libs/STM32_HAL/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(STM32_HAL) 2 | 3 | set(STM32F0_SOURCES 4 | config/stm32f0xx_hal_conf.h 5 | 6 | include/stm32f0xx/stm32f0xx_hal_def.h 7 | include/stm32f0xx/stm32f0xx_hal.h 8 | src/stm32f0xx/stm32f0xx_hal.c 9 | 10 | include/stm32f0xx/stm32f0xx_hal_can.h 11 | src/stm32f0xx/stm32f0xx_hal_can.c 12 | 13 | include/stm32f0xx/stm32f0xx_hal_cortex.h 14 | src/stm32f0xx/stm32f0xx_hal_cortex.c 15 | 16 | include/stm32f0xx/stm32f0xx_hal_flash_ex.h 17 | src/stm32f0xx/stm32f0xx_hal_flash_ex.c 18 | include/stm32f0xx/stm32f0xx_hal_flash.h 19 | src/stm32f0xx/stm32f0xx_hal_flash.c 20 | 21 | include/stm32f0xx/stm32f0xx_hal_gpio_ex.h 22 | include/stm32f0xx/stm32f0xx_hal_gpio.h 23 | src/stm32f0xx/stm32f0xx_hal_gpio.c 24 | 25 | include/stm32f0xx/stm32f0xx_hal_pcd_ex.h 26 | src/stm32f0xx/stm32f0xx_hal_pcd_ex.c 27 | include/stm32f0xx/stm32f0xx_hal_pcd.h 28 | src/stm32f0xx/stm32f0xx_hal_pcd.c 29 | 30 | include/stm32f0xx/stm32f0xx_hal_rcc.h 31 | src/stm32f0xx/stm32f0xx_hal_rcc.c 32 | include/stm32f0xx/stm32f0xx_hal_rcc_ex.h 33 | src/stm32f0xx/stm32f0xx_hal_rcc_ex.c 34 | 35 | include/stm32f0xx/stm32f0xx_hal_tim_ex.h 36 | src/stm32f0xx/stm32f0xx_hal_tim_ex.c 37 | include/stm32f0xx/stm32f0xx_hal_tim.h 38 | src/stm32f0xx/stm32f0xx_hal_tim.c 39 | 40 | include/stm32f0xx/stm32f0xx_ll_usb.h 41 | src/stm32f0xx/stm32f0xx_ll_usb.c 42 | 43 | src/cmsis/system_stm32f0xx.c 44 | include/stm32f0xx/Legacy/stm32_hal_legacy.h 45 | 46 | include/cmsis/cmsis_compiler.h 47 | include/cmsis/cmsis_device.h 48 | include/cmsis/cmsis_gcc.h 49 | include/cmsis/cmsis_version.h 50 | include/cmsis/core_cm0.h 51 | include/cmsis/device/stm32f0xx.h 52 | include/cmsis/device/stm32f042x6.h 53 | include/cmsis/device/stm32f072xb.h 54 | include/cmsis/device/system_stm32f0xx.h 55 | ) 56 | 57 | 58 | set(STM32F4_SOURCES 59 | config/stm32f4xx_hal_conf.h 60 | 61 | include/stm32f4xx/stm32f4xx_hal_def.h 62 | include/stm32f4xx/stm32f4xx_hal.h 63 | src/stm32f4xx/stm32f4xx_hal.c 64 | 65 | include/stm32f4xx/stm32f4xx_hal_can.h 66 | src/stm32f4xx/stm32f4xx_hal_can.c 67 | 68 | include/stm32f4xx/stm32f4xx_hal_cortex.h 69 | src/stm32f4xx/stm32f4xx_hal_cortex.c 70 | 71 | include/stm32f4xx/stm32f4xx_hal_flash_ex.h 72 | src/stm32f4xx/stm32f4xx_hal_flash_ex.c 73 | include/stm32f4xx/stm32f4xx_hal_flash.h 74 | src/stm32f4xx/stm32f4xx_hal_flash.c 75 | 76 | include/stm32f4xx/stm32f4xx_hal_gpio_ex.h 77 | include/stm32f4xx/stm32f4xx_hal_gpio.h 78 | src/stm32f4xx/stm32f4xx_hal_gpio.c 79 | 80 | include/stm32f4xx/stm32f4xx_hal_pcd_ex.h 81 | src/stm32f4xx/stm32f4xx_hal_pcd_ex.c 82 | include/stm32f4xx/stm32f4xx_hal_pcd.h 83 | src/stm32f4xx/stm32f4xx_hal_pcd.c 84 | 85 | include/stm32f4xx/stm32f4xx_hal_rcc.h 86 | src/stm32f4xx/stm32f4xx_hal_rcc.c 87 | include/stm32f4xx/stm32f4xx_hal_rcc_ex.h 88 | src/stm32f4xx/stm32f4xx_hal_rcc_ex.c 89 | 90 | include/stm32f4xx/stm32f4xx_hal_pwr.h 91 | src/stm32f4xx/stm32f4xx_hal_pwr.c 92 | include/stm32f4xx/stm32f4xx_hal_pwr_ex.h 93 | src/stm32f4xx/stm32f4xx_hal_pwr_ex.c 94 | 95 | include/stm32f4xx/stm32f4xx_hal_tim_ex.h 96 | src/stm32f4xx/stm32f4xx_hal_tim_ex.c 97 | include/stm32f4xx/stm32f4xx_hal_tim.h 98 | src/stm32f4xx/stm32f4xx_hal_tim.c 99 | 100 | include/stm32f4xx/stm32f4xx_ll_usb.h 101 | src/stm32f4xx/stm32f4xx_ll_usb.c 102 | 103 | src/cmsis/system_stm32f4xx.c 104 | include/stm32f4xx/Legacy/stm32_hal_legacy.h 105 | 106 | include/cmsis/cmsis_compiler.h 107 | include/cmsis/cmsis_device.h 108 | include/cmsis/cmsis_gcc.h 109 | include/cmsis/cmsis_version.h 110 | include/cmsis/core_cm4.h 111 | include/cmsis/device/stm32f4xx.h 112 | include/cmsis/device/stm32f407xx.h 113 | include/cmsis/device/system_stm32f4xx.h 114 | ) 115 | 116 | set(STM32G0_SOURCES 117 | config/stm32g0xx_hal_conf.h 118 | 119 | include/stm32g0xx/stm32g0xx_hal_def.h 120 | include/stm32g0xx/stm32g0xx_hal.h 121 | src/stm32g0xx/stm32g0xx_hal.c 122 | 123 | include/stm32g0xx/stm32g0xx_hal_fdcan.h 124 | src/stm32g0xx/stm32g0xx_hal_fdcan.c 125 | 126 | include/stm32g0xx/stm32g0xx_hal_cortex.h 127 | src/stm32g0xx/stm32g0xx_hal_cortex.c 128 | 129 | include/stm32g0xx/stm32g0xx_hal_flash_ex.h 130 | src/stm32g0xx/stm32g0xx_hal_flash_ex.c 131 | include/stm32g0xx/stm32g0xx_hal_flash.h 132 | src/stm32g0xx/stm32g0xx_hal_flash.c 133 | 134 | include/stm32g0xx/stm32g0xx_hal_gpio_ex.h 135 | include/stm32g0xx/stm32g0xx_hal_gpio.h 136 | src/stm32g0xx/stm32g0xx_hal_gpio.c 137 | 138 | include/stm32g0xx/stm32g0xx_hal_pcd_ex.h 139 | src/stm32g0xx/stm32g0xx_hal_pcd_ex.c 140 | include/stm32g0xx/stm32g0xx_hal_pcd.h 141 | src/stm32g0xx/stm32g0xx_hal_pcd.c 142 | 143 | include/stm32g0xx/stm32g0xx_hal_rcc.h 144 | src/stm32g0xx/stm32g0xx_hal_rcc.c 145 | include/stm32g0xx/stm32g0xx_hal_rcc_ex.h 146 | src/stm32g0xx/stm32g0xx_hal_rcc_ex.c 147 | 148 | include/stm32g0xx/stm32g0xx_hal_pwr.h 149 | src/stm32g0xx/stm32g0xx_hal_pwr.c 150 | include/stm32g0xx/stm32g0xx_hal_pwr_ex.h 151 | src/stm32g0xx/stm32g0xx_hal_pwr_ex.c 152 | 153 | include/stm32g0xx/stm32g0xx_hal_tim_ex.h 154 | src/stm32g0xx/stm32g0xx_hal_tim_ex.c 155 | include/stm32g0xx/stm32g0xx_hal_tim.h 156 | src/stm32g0xx/stm32g0xx_hal_tim.c 157 | 158 | include/stm32g0xx/stm32g0xx_ll_usb.h 159 | src/stm32g0xx/stm32g0xx_ll_usb.c 160 | 161 | src/cmsis/system_stm32g0xx.c 162 | include/stm32g0xx/Legacy/stm32_hal_legacy.h 163 | 164 | include/cmsis/cmsis_compiler.h 165 | include/cmsis/cmsis_device.h 166 | include/cmsis/cmsis_gcc.h 167 | include/cmsis/cmsis_version.h 168 | include/cmsis/core_cm0plus.h 169 | include/cmsis/device/stm32g0xx.h 170 | include/cmsis/device/stm32g0b1xx.h 171 | include/cmsis/device/system_stm32g0xx.h 172 | ) 173 | 174 | set(INCLUDE_DIRS 175 | include/ 176 | include/cmsis 177 | include/cmsis/device 178 | config/ 179 | ) 180 | 181 | add_library(STM32_HAL_STM32F042x6 STATIC ${STM32F0_SOURCES}) 182 | target_include_directories(STM32_HAL_STM32F042x6 PUBLIC ${INCLUDE_DIRS} include/stm32f0xx) 183 | target_compile_options(STM32_HAL_STM32F042x6 PRIVATE ${CPUFLAGS_F0} -Wno-unused-parameter) 184 | target_compile_definitions(STM32_HAL_STM32F042x6 PUBLIC STM32F042x6 HAL_TARGET_PREFIX=stm32f0xx) 185 | 186 | add_library(STM32_HAL_STM32F072xB STATIC ${STM32F0_SOURCES}) 187 | target_include_directories(STM32_HAL_STM32F072xB PUBLIC ${INCLUDE_DIRS} include/stm32f0xx) 188 | target_compile_options(STM32_HAL_STM32F072xB PRIVATE ${CPUFLAGS_F0} -Wno-unused-parameter) 189 | target_compile_definitions(STM32_HAL_STM32F072xB PUBLIC STM32F072xB HAL_TARGET_PREFIX=stm32f0xx) 190 | 191 | add_library(STM32_HAL_STM32F407xE STATIC ${STM32F4_SOURCES}) 192 | target_include_directories(STM32_HAL_STM32F407xE PUBLIC ${INCLUDE_DIRS} include/stm32f4xx) 193 | target_compile_options(STM32_HAL_STM32F407xE PRIVATE ${CPUFLAGS_F4} -Wno-unused-parameter) 194 | target_compile_definitions(STM32_HAL_STM32F407xE PUBLIC STM32F407xx HAL_TARGET_PREFIX=stm32f4xx) 195 | 196 | add_library(STM32_HAL_STM32G0B1xx STATIC ${STM32G0_SOURCES}) 197 | target_include_directories(STM32_HAL_STM32G0B1xx PUBLIC ${INCLUDE_DIRS} include/stm32g0xx) 198 | target_compile_options(STM32_HAL_STM32G0B1xx PRIVATE ${CPUFLAGS_G0} -Wno-unused-parameter) 199 | target_compile_definitions(STM32_HAL_STM32G0B1xx PUBLIC STM32G0B1xx HAL_TARGET_PREFIX=stm32g0xx) 200 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # candleLight_gsusb 2 | [![Build](https://github.com/candle-usb/candleLight_fw/actions/workflows/ci.yml/badge.svg)](https://github.com/candle-usb/candleLight_fw/actions) 3 | 4 | This is firmware for certain STM32F042x/STM32F072xB-based USB-CAN adapters, notably: 5 | - candleLight: (STM32F072xB) 6 | - candleLight FD: (STM32G0B1CBT) 7 | - candleLight: (STM32F072xB) 8 | - cantact: (STM32F042C6) 9 | - canable (cantact clone): (STM32F042C6) 10 | - USB2CAN: (STM32F042x6) 11 | - CANAlyze: (STM32F042C6) 12 | - VulCAN Gen1: (STM32F042x6) 13 | - Entreé: (STM32F042x6) 14 | - CANable-MKS 1.0: (STM32F072xB) 15 | - ConvertDevice-xCAN: (STM32F072xB) 16 | - ConvertDevice-xCANFD: (STM32G0B1CBT6) 17 | - DSD TECH SH-C30A: (STM32F072xB) 18 | - FYSETC UCAN: (STM32F072xB) 19 | 20 | Of important note is that the common STM32F103 will NOT work with this firmware because its hardware cannot use both USB and CAN simultaneously. 21 | Beware also the smaller packages in the F042 series which map a USB and CAN_TX signal on the same pin and are therefore unusable ! 22 | 23 | This implements the interface of the mainline linux gs_usb kernel module and 24 | works out-of-the-box with linux distros packaging this module, e.g. Ubuntu. 25 | 26 | ## Limitations 27 | 28 | STM32G0B1-based devices are not yet supported by the mainline 29 | firmware. Support for these devices is discussed in 30 | https://github.com/candle-usb/candleLight_fw/pull/139 and 31 | https://github.com/candle-usb/candleLight_fw/pull/176. 32 | 33 | STM32G431-based devices (e.g. CANable-MKS 2.0) are not supported by this project yet. 34 | 35 | Currently, the firmware sends back an echo frame to the host when the frame is written to the CAN peripheral, and not when the frame is actually sent successfully on the bus. This affects timestamps, one-shot mode, and other edge cases. 36 | 37 | ## Known issues 38 | 39 | Be aware that there is a bug in the gs_usb module in linux<4.5 that can crash the kernel on device removal. 40 | 41 | Here is a fixed version that should also work for older kernels: 42 | https://github.com/HubertD/socketcan_gs_usb 43 | 44 | The Firmware also implements WCID USB descriptors and thus can be used on recent Windows versions without installing a driver. 45 | 46 | ## Building 47 | 48 | Building requires arm-none-eabi-gcc toolchain. 49 | 50 | ```shell 51 | sudo apt-get install gcc-arm-none-eabi 52 | 53 | mkdir build 54 | cd build 55 | cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/gcc-arm-none-eabi-8-2019-q3-update.cmake 56 | 57 | # or, 58 | # cmake-gui .. 59 | # don't forget to specify the cmake toolchain file before configuring. 60 | # 61 | # compile all targets : 62 | 63 | make 64 | 65 | # OR, each board target is a cmake option and can be disabled before running 'make'; 66 | # OR, compile a single target , e.g. 67 | make cantact_fw 68 | 69 | # 70 | # to list possible targets : 71 | make help 72 | 73 | ``` 74 | 75 | ## Download Binaries 76 | Prebuilt binaries can be downloaded by clicking [![CI](https://github.com/candle-usb/candleLight_fw/actions/workflows/ci.yml/badge.svg)](https://github.com/candle-usb/candleLight_fw/actions). On the workflow overview page, select the latest workflow that ran on master branch. The firmware artifacts can downloaded by clicking them at the bottom of the page. 77 | 78 | ## Flashing 79 | 80 | Flashing candleLight on linux: (source: [https://cantact.io/cantact/users-guide.html](https://cantact.io/cantact/users-guide.html)) 81 | - Flashing requires the dfu-util tool. On Ubuntu, this can be installed with `sudo apt install dfu-util`. 82 | - compile as above, or download the current binary release: gsusb_cantact_8b2b2b4.bin 83 | - If dfu-util fails due to permission issues on Linux, you may need additional udev rules. Consult your distro's documentation and see `70-candle-usb.rules` provided here. 84 | 85 | ### recommended simple method 86 | - If compiling with cmake, `make flash-`, e.g. `make flash-canable_fw`, to invoke dfu-util. 87 | 88 | ### method for reflashing a specific device by serial 89 | - when multiple devices are connected, dfu-util may be unable to choose which one to flash. 90 | - Obtain device's serial # by looking at `dfu-util -l` 91 | - adapt the following command accordingly : 92 | `dfu-util -D CORRECT_FIRMWARE.bin -S "serial_number_here", -a 0 -s 0x08000000:leave` 93 | - note, the `:leave` suffix above may not be supported by older builds of dfu-util and is simply a convenient way to reboot into the normal firmware. 94 | 95 | ### fail-safe method (or if flashing a blank device) 96 | - Disconnect the USB connector from the CANtact, short the BOOT pins, then reconnect the USB connector. The device should enumerate as "STM32 BOOTLOADER". 97 | 98 | - invoke dfu-util manually with: `sudo dfu-util --dfuse-address -d 0483:df11 -c 1 -i 0 -a 0 -s 0x08000000 -D CORRECT_FIRMWARE.bin` where CORRECT_FIRMWARE is the name of the desired .bin. 99 | - Disconnect the USB connector, un-short the BOOT pins, and reconnect. 100 | 101 | 102 | 103 | ## Associating persistent device names 104 | With udev on linux, it is possible to assign a device name to a certain serial number (see udev manpages and [systemd.link](https://www.freedesktop.org/software/systemd/man/systemd.link.html)). 105 | This can be useful when multiple devices are connected at the same time. 106 | 107 | An example configuration : 108 | 109 | ``` 110 | $ cat /etc/systemd/network/60-persistent-candev.link 111 | [Match] 112 | Property=ID_MODEL=cannette_gs_usb ID_SERIAL_SHORT="003800254250431420363230" 113 | 114 | [Link] 115 | # from systemd.link manpage: 116 | # Note that specifying a name that the kernel might use for another interface (for example "eth0") is dangerous because the name assignment done by udev will race with the assignment done by the kernel, and only one 117 | # interface may use the name. Depending on the order of operations, either udev or the kernel will win, making the naming unpredictable. It is best to use some different prefix 118 | 119 | Name=cannette99 120 | ``` 121 | 122 | ( The serial number can be found with the `lsusb` utility). After reloading systemd units and resetting this board : 123 | 124 | ``` 125 | $ ip a 126 | .... 127 | 59: cannette99: mtu 16 qdisc noop state DOWN group default qlen 10 128 | link/can 129 | $ 130 | ``` 131 | 132 | 133 | ## Hacking 134 | ### Submitting pull requests 135 | - Each commit must not contain unrelated changes (e.g. functional and whitespace changes) 136 | - Project must be compilable (with default options) and functional, at each commit. 137 | - Squash any "WIP" or other temporary commits. 138 | - Make sure your editor is not messing up whitespace or line-ends. 139 | - We include both a `.editorconfig` and `uncrustify.cfg` which should help with whitespace. 140 | 141 | Typical command to run uncrustify on all source files (ignoring HAL and third-party libs): 142 | `uncrustify -c ./uncrustify.cfg --replace --no-backup $(find include src -name "*.[ch]")` 143 | 144 | ### Profiling 145 | Not great on cortex-M0 cores (F042, F072 targets etc) since they lack hardware support (ITM and SWO). However, it's possible to randomly sample the program counter and get some coarse profiling info. 146 | 147 | For example, openocd has the `profile` command (see https://openocd.org/doc/html/General-Commands.html#Misc-Commands), e.g. 148 | 149 | ```profile 5 test.out 0x8000000 0x8100000``` 150 | 151 | (from inside gdb, the command needs to be prefixed with `monitor` to forward it to openocd, i.e. `monitor profile 5 .....`. 152 | 153 | The .out file can then be processed with `gprof -l test.out` 154 | 155 | 156 | 157 | ## Links to related projects 158 | * [Cangaroo](https://github.com/HubertD/cangaroo) open source can bus analyzer software 159 | * [Candle.NET](https://github.com/elliotwoods/Candle.NET) .NET wrapper for the candle API 160 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/stm32g0xx/stm32g0xx_hal_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32g0xx_hal_def.h 4 | * @author MCD Application Team 5 | * @brief This file contains HAL common defines, enumeration, macros and 6 | * structures definitions. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2018 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32G0xx_HAL_DEF 22 | #define STM32G0xx_HAL_DEF 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32g0xx.h" 30 | #include "Legacy/stm32_hal_legacy.h" /* Aliases file for old names compatibility */ 31 | #include 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | 35 | /** 36 | * @brief HAL Status structures definition 37 | */ 38 | typedef enum 39 | { 40 | HAL_OK = 0x00U, 41 | HAL_ERROR = 0x01U, 42 | HAL_BUSY = 0x02U, 43 | HAL_TIMEOUT = 0x03U 44 | } HAL_StatusTypeDef; 45 | 46 | /** 47 | * @brief HAL Lock structures definition 48 | */ 49 | typedef enum 50 | { 51 | HAL_UNLOCKED = 0x00U, 52 | HAL_LOCKED = 0x01U 53 | } HAL_LockTypeDef; 54 | 55 | /* Exported macros -----------------------------------------------------------*/ 56 | 57 | #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */ 58 | 59 | #define HAL_MAX_DELAY 0xFFFFFFFFU 60 | 61 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) == (BIT)) 62 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U) 63 | 64 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \ 65 | do{ \ 66 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \ 67 | (__DMA_HANDLE__).Parent = (__HANDLE__); \ 68 | } while(0U) 69 | 70 | /** @brief Reset the Handles State field. 71 | * @param __HANDLE__ specifies the Peripheral Handle. 72 | * @note This macro can be used for the following purpose: 73 | * - When the Handle is declared as local variable; before passing it as parameter 74 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 75 | * to set to 0 the Handles "State" field. 76 | * Otherwise, "State" field may have any random value and the first time the function 77 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed 78 | * (i.e. HAL_PPP_MspInit() will not be executed). 79 | * - When there is a need to reconfigure the low level hardware: instead of calling 80 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 81 | * In this later function, when the Handles "State" field is set to 0, it will execute the function 82 | * HAL_PPP_MspInit() which will reconfigure the low level hardware. 83 | * @retval None 84 | */ 85 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U) 86 | 87 | #if (USE_RTOS == 1U) 88 | /* Reserved for future use */ 89 | #error " USE_RTOS should be 0 in the current HAL release " 90 | #else 91 | #define __HAL_LOCK(__HANDLE__) \ 92 | do{ \ 93 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 94 | { \ 95 | return HAL_BUSY; \ 96 | } \ 97 | else \ 98 | { \ 99 | (__HANDLE__)->Lock = HAL_LOCKED; \ 100 | } \ 101 | }while (0U) 102 | 103 | #define __HAL_UNLOCK(__HANDLE__) \ 104 | do{ \ 105 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 106 | }while (0U) 107 | #endif /* USE_RTOS */ 108 | 109 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 110 | #ifndef __weak 111 | #define __weak __attribute__((weak)) 112 | #endif /* __weak */ 113 | #ifndef __packed 114 | #define __packed __attribute__((packed)) 115 | #endif /* __packed */ 116 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 117 | #ifndef __weak 118 | #define __weak __attribute__((weak)) 119 | #endif /* __weak */ 120 | #ifndef __packed 121 | #define __packed __attribute__((__packed__)) 122 | #endif /* __packed */ 123 | #endif /* __GNUC__ */ 124 | 125 | 126 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ 127 | /* GNU Compiler */ 128 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */ 129 | #ifndef __ALIGN_BEGIN 130 | #define __ALIGN_BEGIN 131 | #endif /* __ALIGN_BEGIN */ 132 | #ifndef __ALIGN_END 133 | #define __ALIGN_END __attribute__ ((aligned (4))) 134 | #endif /* __ALIGN_END */ 135 | #elif defined (__GNUC__) && !defined (__CC_ARM) /* GNU Compiler */ 136 | #ifndef __ALIGN_END 137 | #define __ALIGN_END __attribute__ ((aligned (4U))) 138 | #endif /* __ALIGN_END */ 139 | #ifndef __ALIGN_BEGIN 140 | #define __ALIGN_BEGIN 141 | #endif /* __ALIGN_BEGIN */ 142 | #else 143 | #ifndef __ALIGN_END 144 | #define __ALIGN_END 145 | #endif /* __ALIGN_END */ 146 | #ifndef __ALIGN_BEGIN 147 | /* ARM Compiler */ 148 | #if defined (__CC_ARM) /* ARM Compiler V5 */ 149 | #define __ALIGN_BEGIN __align(4U) 150 | /* IAR Compiler */ 151 | #elif defined (__ICCARM__) 152 | #define __ALIGN_BEGIN 153 | #endif /* __CC_ARM */ 154 | #endif /* __ALIGN_BEGIN */ 155 | #endif /* __GNUC__ */ 156 | 157 | /** 158 | * @brief __RAM_FUNC definition 159 | */ 160 | #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) 161 | /* ARM Compiler V4/V5 and V6 162 | -------------------------- 163 | RAM functions are defined using the toolchain options. 164 | Functions that are executed in RAM should reside in a separate source module. 165 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 166 | area of a module to a memory space in physical RAM. 167 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 168 | dialog. 169 | */ 170 | #define __RAM_FUNC 171 | 172 | #elif defined ( __ICCARM__ ) 173 | /* ICCARM Compiler 174 | --------------- 175 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 176 | */ 177 | #define __RAM_FUNC __ramfunc 178 | 179 | #elif defined ( __GNUC__ ) 180 | /* GNU Compiler 181 | ------------ 182 | RAM functions are defined using a specific toolchain attribute 183 | "__attribute__((section(".RamFunc")))". 184 | */ 185 | #define __RAM_FUNC __attribute__((section(".RamFunc"))) 186 | 187 | #endif /* __CC_ARM || __ARMCC_VERSION */ 188 | 189 | /** 190 | * @brief __NOINLINE definition 191 | */ 192 | #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined ( __GNUC__ ) 193 | /* ARM V4/V5 and V6 & GNU Compiler 194 | ------------------------------- 195 | */ 196 | #define __NOINLINE __attribute__ ( (noinline) ) 197 | 198 | #elif defined ( __ICCARM__ ) 199 | /* ICCARM Compiler 200 | --------------- 201 | */ 202 | #define __NOINLINE _Pragma("optimize = no_inline") 203 | 204 | #endif /* __CC_ARM || __ARMCC_VERSION */ 205 | 206 | 207 | #ifdef __cplusplus 208 | } 209 | #endif 210 | 211 | #endif /* STM32G0xx_HAL_DEF */ 212 | 213 | 214 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/stm32f4xx/stm32f4xx_hal_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_def.h 4 | * @author MCD Application Team 5 | * @brief This file contains HAL common defines, enumeration, macros and 6 | * structures definitions. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2017 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F4xx_HAL_DEF 23 | #define __STM32F4xx_HAL_DEF 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32f4xx.h" 31 | #include "Legacy/stm32_hal_legacy.h" 32 | #include 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | 36 | /** 37 | * @brief HAL Status structures definition 38 | */ 39 | typedef enum 40 | { 41 | HAL_OK = 0x00U, 42 | HAL_ERROR = 0x01U, 43 | HAL_BUSY = 0x02U, 44 | HAL_TIMEOUT = 0x03U 45 | } HAL_StatusTypeDef; 46 | 47 | /** 48 | * @brief HAL Lock structures definition 49 | */ 50 | typedef enum 51 | { 52 | HAL_UNLOCKED = 0x00U, 53 | HAL_LOCKED = 0x01U 54 | } HAL_LockTypeDef; 55 | 56 | /* Exported macro ------------------------------------------------------------*/ 57 | 58 | #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */ 59 | 60 | #define HAL_MAX_DELAY 0xFFFFFFFFU 61 | 62 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) == (BIT)) 63 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U) 64 | 65 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \ 66 | do{ \ 67 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \ 68 | (__DMA_HANDLE__).Parent = (__HANDLE__); \ 69 | } while(0U) 70 | 71 | /** @brief Reset the Handle's State field. 72 | * @param __HANDLE__ specifies the Peripheral Handle. 73 | * @note This macro can be used for the following purpose: 74 | * - When the Handle is declared as local variable; before passing it as parameter 75 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 76 | * to set to 0 the Handle's "State" field. 77 | * Otherwise, "State" field may have any random value and the first time the function 78 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed 79 | * (i.e. HAL_PPP_MspInit() will not be executed). 80 | * - When there is a need to reconfigure the low level hardware: instead of calling 81 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 82 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function 83 | * HAL_PPP_MspInit() which will reconfigure the low level hardware. 84 | * @retval None 85 | */ 86 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U) 87 | 88 | #if (USE_RTOS == 1U) 89 | /* Reserved for future use */ 90 | #error "USE_RTOS should be 0 in the current HAL release" 91 | #else 92 | #define __HAL_LOCK(__HANDLE__) \ 93 | do{ \ 94 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 95 | { \ 96 | return HAL_BUSY; \ 97 | } \ 98 | else \ 99 | { \ 100 | (__HANDLE__)->Lock = HAL_LOCKED; \ 101 | } \ 102 | }while (0U) 103 | 104 | #define __HAL_UNLOCK(__HANDLE__) \ 105 | do{ \ 106 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 107 | }while (0U) 108 | #endif /* USE_RTOS */ 109 | 110 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */ 111 | #ifndef __weak 112 | #define __weak __attribute__((weak)) 113 | #endif 114 | #ifndef __packed 115 | #define __packed __attribute__((packed)) 116 | #endif 117 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 118 | #ifndef __weak 119 | #define __weak __attribute__((weak)) 120 | #endif /* __weak */ 121 | #ifndef __packed 122 | #define __packed __attribute__((__packed__)) 123 | #endif /* __packed */ 124 | #endif /* __GNUC__ */ 125 | 126 | 127 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ 128 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */ 129 | #ifndef __ALIGN_BEGIN 130 | #define __ALIGN_BEGIN 131 | #endif 132 | #ifndef __ALIGN_END 133 | #define __ALIGN_END __attribute__ ((aligned (4))) 134 | #endif 135 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 136 | #ifndef __ALIGN_END 137 | #define __ALIGN_END __attribute__ ((aligned (4))) 138 | #endif /* __ALIGN_END */ 139 | #ifndef __ALIGN_BEGIN 140 | #define __ALIGN_BEGIN 141 | #endif /* __ALIGN_BEGIN */ 142 | #else 143 | #ifndef __ALIGN_END 144 | #define __ALIGN_END 145 | #endif /* __ALIGN_END */ 146 | #ifndef __ALIGN_BEGIN 147 | #if defined (__CC_ARM) /* ARM Compiler V5*/ 148 | #define __ALIGN_BEGIN __align(4) 149 | #elif defined (__ICCARM__) /* IAR Compiler */ 150 | #define __ALIGN_BEGIN 151 | #endif /* __CC_ARM */ 152 | #endif /* __ALIGN_BEGIN */ 153 | #endif /* __GNUC__ */ 154 | 155 | 156 | /** 157 | * @brief __RAM_FUNC definition 158 | */ 159 | #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) 160 | /* ARM Compiler V4/V5 and V6 161 | -------------------------- 162 | RAM functions are defined using the toolchain options. 163 | Functions that are executed in RAM should reside in a separate source module. 164 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 165 | area of a module to a memory space in physical RAM. 166 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 167 | dialog. 168 | */ 169 | #define __RAM_FUNC 170 | 171 | #elif defined ( __ICCARM__ ) 172 | /* ICCARM Compiler 173 | --------------- 174 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 175 | */ 176 | #define __RAM_FUNC __ramfunc 177 | 178 | #elif defined ( __GNUC__ ) 179 | /* GNU Compiler 180 | ------------ 181 | RAM functions are defined using a specific toolchain attribute 182 | "__attribute__((section(".RamFunc")))". 183 | */ 184 | #define __RAM_FUNC __attribute__((section(".RamFunc"))) 185 | 186 | #endif 187 | 188 | /** 189 | * @brief __NOINLINE definition 190 | */ 191 | #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined ( __GNUC__ ) 192 | /* ARM V4/V5 and V6 & GNU Compiler 193 | ------------------------------- 194 | */ 195 | #define __NOINLINE __attribute__ ( (noinline) ) 196 | 197 | #elif defined ( __ICCARM__ ) 198 | /* ICCARM Compiler 199 | --------------- 200 | */ 201 | #define __NOINLINE _Pragma("optimize = no_inline") 202 | 203 | #endif 204 | 205 | #ifdef __cplusplus 206 | } 207 | #endif 208 | 209 | #endif /* ___STM32F4xx_HAL_DEF */ 210 | 211 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 212 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32g0xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32g0xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS STM32G0xx Device Peripheral Access Layer Header File. 6 | * 7 | * The file is the unique include file that the application programmer 8 | * is using in the C source code, usually in main.c. This file contains: 9 | * - Configuration section that allows to select: 10 | * - The STM32G0xx device used in the target application 11 | * - To use or not the peripherals drivers in application code(i.e. 12 | * code will be based on direct access to peripherals registers 13 | * rather than drivers API), this option is controlled by 14 | * "#define USE_HAL_DRIVER" 15 | * 16 | ****************************************************************************** 17 | * @attention 18 | * 19 | * Copyright (c) 2018-2021 STMicroelectronics. 20 | * All rights reserved. 21 | * 22 | * This software is licensed under terms that can be found in the LICENSE file 23 | * in the root directory of this software component. 24 | * If no LICENSE file comes with this software, it is provided AS-IS. 25 | * 26 | ****************************************************************************** 27 | */ 28 | /** @addtogroup CMSIS 29 | * @{ 30 | */ 31 | 32 | /** @addtogroup stm32g0xx 33 | * @{ 34 | */ 35 | 36 | #ifndef STM32G0xx_H 37 | #define STM32G0xx_H 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif /* __cplusplus */ 42 | 43 | /** @addtogroup Library_configuration_section 44 | * @{ 45 | */ 46 | 47 | /** 48 | * @brief STM32 Family 49 | */ 50 | #if !defined (STM32G0) 51 | #define STM32G0 52 | #endif /* STM32G0 */ 53 | 54 | /* Uncomment the line below according to the target STM32G0 device used in your 55 | application 56 | */ 57 | 58 | #if !defined (STM32G071xx) && !defined (STM32G081xx) && !defined (STM32G070xx) \ 59 | && !defined (STM32G030xx) && !defined (STM32G031xx) && !defined (STM32G041xx) \ 60 | && !defined (STM32G0B0xx) && !defined (STM32G0B1xx) && !defined (STM32G0C1xx) \ 61 | && !defined (STM32G050xx) && !defined (STM32G051xx) && !defined (STM32G061xx) 62 | /* #define STM32G0B0xx */ /*!< STM32G0B0xx Devices */ 63 | /* #define STM32G0B1xx */ /*!< STM32G0B1xx Devices */ 64 | /* #define STM32G0C1xx */ /*!< STM32G0C1xx Devices */ 65 | /* #define STM32G070xx */ /*!< STM32G070xx Devices */ 66 | /* #define STM32G071xx */ /*!< STM32G071xx Devices */ 67 | /* #define STM32G081xx */ /*!< STM32G081xx Devices */ 68 | /* #define STM32G050xx */ /*!< STM32G050xx Devices */ 69 | /* #define STM32G051xx */ /*!< STM32G051xx Devices */ 70 | /* #define STM32G061xx */ /*!< STM32G061xx Devices */ 71 | /* #define STM32G030xx */ /*!< STM32G030xx Devices */ 72 | /* #define STM32G031xx */ /*!< STM32G031xx Devices */ 73 | /* #define STM32G041xx */ /*!< STM32G041xx Devices */ 74 | #endif 75 | 76 | /* Tip: To avoid modifying this file each time you need to switch between these 77 | devices, you can define the device in your toolchain compiler preprocessor. 78 | */ 79 | #if !defined (USE_HAL_DRIVER) 80 | /** 81 | * @brief Comment the line below if you will not use the peripherals drivers. 82 | In this case, these drivers will not be included and the application code will 83 | be based on direct access to peripherals registers 84 | */ 85 | /*#define USE_HAL_DRIVER */ 86 | #endif /* USE_HAL_DRIVER */ 87 | 88 | /** 89 | * @brief CMSIS Device version number $VERSION$ 90 | */ 91 | #define __STM32G0_CMSIS_VERSION_MAIN (0x01U) /*!< [31:24] main version */ 92 | #define __STM32G0_CMSIS_VERSION_SUB1 (0x04U) /*!< [23:16] sub1 version */ 93 | #define __STM32G0_CMSIS_VERSION_SUB2 (0x03U) /*!< [15:8] sub2 version */ 94 | #define __STM32G0_CMSIS_VERSION_RC (0x00U) /*!< [7:0] release candidate */ 95 | #define __STM32G0_CMSIS_VERSION ((__STM32G0_CMSIS_VERSION_MAIN << 24)\ 96 | |(__STM32G0_CMSIS_VERSION_SUB1 << 16)\ 97 | |(__STM32G0_CMSIS_VERSION_SUB2 << 8 )\ 98 | |(__STM32G0_CMSIS_VERSION_RC)) 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | /** @addtogroup Device_Included 105 | * @{ 106 | */ 107 | 108 | #if defined(STM32G0B1xx) 109 | #include "stm32g0b1xx.h" 110 | #elif defined(STM32G0C1xx) 111 | #include "stm32g0c1xx.h" 112 | #elif defined(STM32G0B0xx) 113 | #include "stm32g0b0xx.h" 114 | #elif defined(STM32G071xx) 115 | #include "stm32g071xx.h" 116 | #elif defined(STM32G081xx) 117 | #include "stm32g081xx.h" 118 | #elif defined(STM32G070xx) 119 | #include "stm32g070xx.h" 120 | #elif defined(STM32G031xx) 121 | #include "stm32g031xx.h" 122 | #elif defined(STM32G041xx) 123 | #include "stm32g041xx.h" 124 | #elif defined(STM32G030xx) 125 | #include "stm32g030xx.h" 126 | #elif defined(STM32G051xx) 127 | #include "stm32g051xx.h" 128 | #elif defined(STM32G061xx) 129 | #include "stm32g061xx.h" 130 | #elif defined(STM32G050xx) 131 | #include "stm32g050xx.h" 132 | #else 133 | #error "Please select first the target STM32G0xx device used in your application (in stm32g0xx.h file)" 134 | #endif 135 | 136 | /** 137 | * @} 138 | */ 139 | 140 | /** @addtogroup Exported_types 141 | * @{ 142 | */ 143 | typedef enum 144 | { 145 | RESET = 0, 146 | SET = !RESET 147 | } FlagStatus, ITStatus; 148 | 149 | typedef enum 150 | { 151 | DISABLE = 0, 152 | ENABLE = !DISABLE 153 | } FunctionalState; 154 | #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE)) 155 | 156 | typedef enum 157 | { 158 | SUCCESS = 0, 159 | ERROR = !SUCCESS 160 | } ErrorStatus; 161 | 162 | /** 163 | * @} 164 | */ 165 | 166 | 167 | /** @addtogroup Exported_macros 168 | * @{ 169 | */ 170 | #define SET_BIT(REG, BIT) ((REG) |= (BIT)) 171 | 172 | #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT)) 173 | 174 | #define READ_BIT(REG, BIT) ((REG) & (BIT)) 175 | 176 | #define CLEAR_REG(REG) ((REG) = (0x0)) 177 | 178 | #define WRITE_REG(REG, VAL) ((REG) = (VAL)) 179 | 180 | #define READ_REG(REG) ((REG)) 181 | 182 | #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK))) 183 | 184 | /* Use of interrupt control for register exclusive access */ 185 | /* Atomic 32-bit register access macro to set one or several bits */ 186 | #define ATOMIC_SET_BIT(REG, BIT) \ 187 | do { \ 188 | uint32_t primask; \ 189 | primask = __get_PRIMASK(); \ 190 | __set_PRIMASK(1); \ 191 | SET_BIT((REG), (BIT)); \ 192 | __set_PRIMASK(primask); \ 193 | } while(0) 194 | 195 | /* Atomic 32-bit register access macro to clear one or several bits */ 196 | #define ATOMIC_CLEAR_BIT(REG, BIT) \ 197 | do { \ 198 | uint32_t primask; \ 199 | primask = __get_PRIMASK(); \ 200 | __set_PRIMASK(1); \ 201 | CLEAR_BIT((REG), (BIT)); \ 202 | __set_PRIMASK(primask); \ 203 | } while(0) 204 | 205 | /* Atomic 32-bit register access macro to clear and set one or several bits */ 206 | #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \ 207 | do { \ 208 | uint32_t primask; \ 209 | primask = __get_PRIMASK(); \ 210 | __set_PRIMASK(1); \ 211 | MODIFY_REG((REG), (CLEARMSK), (SETMASK)); \ 212 | __set_PRIMASK(primask); \ 213 | } while(0) 214 | 215 | /* Atomic 16-bit register access macro to set one or several bits */ 216 | #define ATOMIC_SETH_BIT(REG, BIT) ATOMIC_SET_BIT(REG, BIT) \ 217 | 218 | /* Atomic 16-bit register access macro to clear one or several bits */ 219 | #define ATOMIC_CLEARH_BIT(REG, BIT) ATOMIC_CLEAR_BIT(REG, BIT) \ 220 | 221 | /* Atomic 16-bit register access macro to clear and set one or several bits */ 222 | #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK) ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \ 223 | 224 | /*#define POSITION_VAL(VAL) (__CLZ(__RBIT(VAL)))*/ 225 | /** 226 | * @} 227 | */ 228 | 229 | #if defined (USE_HAL_DRIVER) 230 | #include "stm32g0xx_hal.h" 231 | #endif /* USE_HAL_DRIVER */ 232 | 233 | #ifdef __cplusplus 234 | } 235 | #endif /* __cplusplus */ 236 | 237 | #endif /* STM32G0xx_H */ 238 | /** 239 | * @} 240 | */ 241 | 242 | /** 243 | * @} 244 | */ 245 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/stm32f0xx/stm32f0xx_ll_usb.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_ll_usb.h 4 | * @author MCD Application Team 5 | * @brief Header file of USB Low Layer HAL module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F0xx_LL_USB_H 22 | #define STM32F0xx_LL_USB_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f0xx_hal_def.h" 30 | 31 | #if defined (USB) 32 | /** @addtogroup STM32F0xx_HAL_Driver 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup USB_LL 37 | * @{ 38 | */ 39 | 40 | /* Exported types ------------------------------------------------------------*/ 41 | 42 | /** 43 | * @brief USB Mode definition 44 | */ 45 | 46 | 47 | 48 | typedef enum 49 | { 50 | USB_DEVICE_MODE = 0 51 | } USB_ModeTypeDef; 52 | 53 | /** 54 | * @brief USB Initialization Structure definition 55 | */ 56 | typedef struct 57 | { 58 | uint32_t dev_endpoints; /*!< Device Endpoints number. 59 | This parameter depends on the used USB core. 60 | This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ 61 | 62 | uint32_t speed; /*!< USB Core speed. 63 | This parameter can be any value of @ref USB_Core_Speed */ 64 | 65 | uint32_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size. */ 66 | 67 | uint32_t phy_itface; /*!< Select the used PHY interface. 68 | This parameter can be any value of @ref USB_Core_PHY */ 69 | 70 | uint32_t Sof_enable; /*!< Enable or disable the output of the SOF signal. */ 71 | 72 | uint32_t low_power_enable; /*!< Enable or disable Low Power mode */ 73 | 74 | uint32_t lpm_enable; /*!< Enable or disable Battery charging. */ 75 | 76 | uint32_t battery_charging_enable; /*!< Enable or disable Battery charging. */ 77 | } USB_CfgTypeDef; 78 | 79 | typedef struct 80 | { 81 | uint8_t num; /*!< Endpoint number 82 | This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ 83 | 84 | uint8_t is_in; /*!< Endpoint direction 85 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ 86 | 87 | uint8_t is_stall; /*!< Endpoint stall condition 88 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ 89 | 90 | uint8_t type; /*!< Endpoint type 91 | This parameter can be any value of @ref USB_EP_Type */ 92 | 93 | uint8_t data_pid_start; /*!< Initial data PID 94 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ 95 | 96 | uint16_t pmaadress; /*!< PMA Address 97 | This parameter can be any value between Min_addr = 0 and Max_addr = 1K */ 98 | 99 | uint16_t pmaaddr0; /*!< PMA Address0 100 | This parameter can be any value between Min_addr = 0 and Max_addr = 1K */ 101 | 102 | uint16_t pmaaddr1; /*!< PMA Address1 103 | This parameter can be any value between Min_addr = 0 and Max_addr = 1K */ 104 | 105 | uint8_t doublebuffer; /*!< Double buffer enable 106 | This parameter can be 0 or 1 */ 107 | 108 | uint16_t tx_fifo_num; /*!< This parameter is not required by USB Device FS peripheral, it is used 109 | only by USB OTG FS peripheral 110 | This parameter is added to ensure compatibility across USB peripherals */ 111 | 112 | uint32_t maxpacket; /*!< Endpoint Max packet size 113 | This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */ 114 | 115 | uint8_t *xfer_buff; /*!< Pointer to transfer buffer */ 116 | 117 | uint32_t xfer_len; /*!< Current transfer length */ 118 | 119 | uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */ 120 | 121 | uint32_t xfer_len_db; /*!< double buffer transfer length used with bulk double buffer in */ 122 | 123 | uint8_t xfer_fill_db; /*!< double buffer Need to Fill new buffer used with bulk_in */ 124 | 125 | } USB_EPTypeDef; 126 | 127 | 128 | /* Exported constants --------------------------------------------------------*/ 129 | 130 | /** @defgroup PCD_Exported_Constants PCD Exported Constants 131 | * @{ 132 | */ 133 | 134 | 135 | /** @defgroup USB_LL_EP0_MPS USB Low Layer EP0 MPS 136 | * @{ 137 | */ 138 | #define EP_MPS_64 0U 139 | #define EP_MPS_32 1U 140 | #define EP_MPS_16 2U 141 | #define EP_MPS_8 3U 142 | /** 143 | * @} 144 | */ 145 | 146 | /** @defgroup USB_LL_EP_Type USB Low Layer EP Type 147 | * @{ 148 | */ 149 | #define EP_TYPE_CTRL 0U 150 | #define EP_TYPE_ISOC 1U 151 | #define EP_TYPE_BULK 2U 152 | #define EP_TYPE_INTR 3U 153 | #define EP_TYPE_MSK 3U 154 | /** 155 | * @} 156 | */ 157 | 158 | /** @defgroup USB_LL Device Speed 159 | * @{ 160 | */ 161 | #define USBD_FS_SPEED 2U 162 | /** 163 | * @} 164 | */ 165 | 166 | #define BTABLE_ADDRESS 0x000U 167 | #define PMA_ACCESS 1U 168 | 169 | #define EP_ADDR_MSK 0x7U 170 | /** 171 | * @} 172 | */ 173 | 174 | /* Exported macro ------------------------------------------------------------*/ 175 | /** 176 | * @} 177 | */ 178 | 179 | /* Exported functions --------------------------------------------------------*/ 180 | /** @addtogroup USB_LL_Exported_Functions USB Low Layer Exported Functions 181 | * @{ 182 | */ 183 | 184 | 185 | HAL_StatusTypeDef USB_CoreInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg); 186 | HAL_StatusTypeDef USB_DevInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg); 187 | HAL_StatusTypeDef USB_EnableGlobalInt(USB_TypeDef *USBx); 188 | HAL_StatusTypeDef USB_DisableGlobalInt(USB_TypeDef *USBx); 189 | HAL_StatusTypeDef USB_SetCurrentMode(USB_TypeDef *USBx, USB_ModeTypeDef mode); 190 | HAL_StatusTypeDef USB_ActivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep); 191 | HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep); 192 | HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx, USB_EPTypeDef *ep); 193 | HAL_StatusTypeDef USB_EPSetStall(USB_TypeDef *USBx, USB_EPTypeDef *ep); 194 | HAL_StatusTypeDef USB_EPClearStall(USB_TypeDef *USBx, USB_EPTypeDef *ep); 195 | HAL_StatusTypeDef USB_SetDevAddress(USB_TypeDef *USBx, uint8_t address); 196 | HAL_StatusTypeDef USB_DevConnect(USB_TypeDef *USBx); 197 | HAL_StatusTypeDef USB_DevDisconnect(USB_TypeDef *USBx); 198 | HAL_StatusTypeDef USB_StopDevice(USB_TypeDef *USBx); 199 | uint32_t USB_ReadInterrupts(USB_TypeDef *USBx); 200 | HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_TypeDef *USBx); 201 | HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_TypeDef *USBx); 202 | 203 | void USB_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, 204 | uint16_t wPMABufAddr, uint16_t wNBytes); 205 | 206 | void USB_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, 207 | uint16_t wPMABufAddr, uint16_t wNBytes); 208 | 209 | /** 210 | * @} 211 | */ 212 | 213 | /** 214 | * @} 215 | */ 216 | 217 | /** 218 | * @} 219 | */ 220 | 221 | /** 222 | * @} 223 | */ 224 | #endif /* defined (USB) */ 225 | 226 | #ifdef __cplusplus 227 | } 228 | #endif 229 | 230 | 231 | #endif /* STM32F0xx_LL_USB_H */ 232 | 233 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 234 | -------------------------------------------------------------------------------- /src/usbd_conf.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include 28 | #include 29 | #include "usbd_core.h" 30 | #include "usbd_ctlreq.h" 31 | #include "usbd_def.h" 32 | #include "usbd_gs_can.h" 33 | 34 | PCD_HandleTypeDef hpcd_USB_FS; 35 | 36 | void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd) 37 | { 38 | if (hpcd->Instance==USB_INTERFACE) { 39 | 40 | #if defined(USB) 41 | __HAL_RCC_USB_CLK_ENABLE(); 42 | #elif defined(USB_OTG_FS) 43 | __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); 44 | #elif defined(USB_DRD_FS) 45 | __HAL_RCC_USB_CLK_ENABLE(); 46 | HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE); 47 | /* Enable VDDUSB */ 48 | if (__HAL_RCC_PWR_IS_CLK_DISABLED()) 49 | { 50 | __HAL_RCC_PWR_CLK_ENABLE(); 51 | HAL_PWREx_EnableVddUSB(); 52 | __HAL_RCC_PWR_CLK_DISABLE(); 53 | } 54 | else 55 | { 56 | HAL_PWREx_EnableVddUSB(); 57 | } 58 | #endif 59 | HAL_NVIC_SetPriority(USB_INTERRUPT, 1, 0); 60 | HAL_NVIC_EnableIRQ(USB_INTERRUPT); 61 | } 62 | } 63 | 64 | void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd) 65 | { 66 | if (hpcd->Instance==USB_INTERFACE) { 67 | #if defined(USB) || defined(USB_DRD_FS) 68 | __HAL_RCC_USB_CLK_DISABLE(); 69 | #elif defined(USB_OTG_FS) 70 | __HAL_RCC_USB_OTG_FS_CLK_DISABLE(); 71 | #endif 72 | HAL_NVIC_DisableIRQ(USB_INTERRUPT); 73 | } 74 | } 75 | 76 | void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) 77 | { 78 | USBD_HandleTypeDef *pdev = (USBD_HandleTypeDef*)hpcd->pData; 79 | USBD_ParseSetupRequest((USBD_SetupReqTypedef*)&pdev->request, (uint8_t*)hpcd->Setup); 80 | 81 | bool request_was_handled = false; 82 | 83 | if ((pdev->request.bmRequest & 0x1F) == USB_REQ_RECIPIENT_DEVICE ) { // device request 84 | request_was_handled = USBD_GS_CAN_CustomDeviceRequest(pdev, &pdev->request); 85 | } 86 | 87 | if ((pdev->request.bmRequest & 0x1F) == USB_REQ_RECIPIENT_INTERFACE ) { // interface request 88 | request_was_handled = USBD_GS_CAN_CustomInterfaceRequest(pdev, &pdev->request); 89 | } 90 | 91 | if (!request_was_handled) { 92 | USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); 93 | } 94 | } 95 | 96 | void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) 97 | { 98 | USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); 99 | } 100 | 101 | void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) 102 | { 103 | USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); 104 | } 105 | 106 | void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) 107 | { 108 | USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); 109 | } 110 | 111 | void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) 112 | { 113 | USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, USBD_SPEED_FULL); 114 | USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); 115 | } 116 | 117 | void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) 118 | { 119 | USBD_GS_CAN_SuspendCallback((USBD_HandleTypeDef*)hpcd->pData); 120 | USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); 121 | } 122 | 123 | void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) 124 | { 125 | USBD_LL_Resume((USBD_HandleTypeDef*) hpcd->pData); 126 | USBD_GS_CAN_ResumeCallback((USBD_HandleTypeDef*)hpcd->pData); 127 | } 128 | 129 | USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) 130 | { 131 | /* Init USB_IP */ 132 | /* Link The driver to the stack */ 133 | hpcd_USB_FS.pData = pdev; 134 | pdev->pData = &hpcd_USB_FS; 135 | 136 | hpcd_USB_FS.Instance = USB_INTERFACE; 137 | hpcd_USB_FS.Init.dev_endpoints = 5U; 138 | hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; 139 | hpcd_USB_FS.Init.ep0_mps = EP_MPS_64; 140 | hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED; 141 | hpcd_USB_FS.Init.low_power_enable = DISABLE; 142 | hpcd_USB_FS.Init.lpm_enable = DISABLE; 143 | #if defined(STM32F4) 144 | hpcd_USB_FS.Init.dma_enable = DISABLE; 145 | hpcd_USB_FS.Init.Sof_enable = DISABLE; 146 | hpcd_USB_FS.Init.vbus_sensing_enable = DISABLE; 147 | hpcd_USB_FS.Init.use_dedicated_ep1 = DISABLE; 148 | #elif defined(STM32G0) 149 | hpcd_USB_FS.Init.Sof_enable = DISABLE; 150 | hpcd_USB_FS.Init.battery_charging_enable = DISABLE; 151 | hpcd_USB_FS.Init.vbus_sensing_enable = DISABLE; 152 | hpcd_USB_FS.Init.bulk_doublebuffer_enable = ENABLE; 153 | hpcd_USB_FS.Init.iso_singlebuffer_enable = DISABLE; 154 | #endif 155 | HAL_PCD_Init(&hpcd_USB_FS); 156 | /* 157 | * PMA layout 158 | * 0x00 - 0x17 (24 bytes) metadata? 159 | * 0x18 - 0x57 (64 bytes) EP0 OUT 160 | * 0x58 - 0x97 (64 bytes) EP0 IN 161 | * 0x98 - 0xD7 (64 bytes) EP1 IN 162 | * 0xD8 - 0x157 (128 bytes) EP1 OUT (buffer 1) 163 | * 0x158 - 0x1D7 (128 bytes) EP1 OUT (buffer 2) 164 | */ 165 | #if defined(USB) || defined(USB_DRD_FS) 166 | HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x00, PCD_SNG_BUF, 0x18); 167 | HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x80, PCD_SNG_BUF, 0x58); 168 | HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x81, PCD_SNG_BUF, 0x98); 169 | HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x02, PCD_DBL_BUF, 0x00D80158); 170 | #elif defined(USB_OTG_FS) 171 | HAL_PCDEx_SetRxFiFo((PCD_HandleTypeDef*)pdev->pData, USB_RX_FIFO_SIZE); // shared RX FIFO 172 | HAL_PCDEx_SetTxFiFo((PCD_HandleTypeDef*)pdev->pData, 0U, 64U / 4U); // 0x80, 64 bytes (div by 4 for words) 173 | HAL_PCDEx_SetTxFiFo((PCD_HandleTypeDef*)pdev->pData, 1U, 64U / 4U); // 0x81, 64 bytes (div by 4 for words) 174 | #endif 175 | 176 | return USBD_OK; 177 | } 178 | 179 | USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) 180 | { 181 | HAL_PCD_DeInit((PCD_HandleTypeDef*)pdev->pData); 182 | return USBD_OK; 183 | } 184 | 185 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) 186 | { 187 | HAL_PCD_Start((PCD_HandleTypeDef*)pdev->pData); 188 | return USBD_OK; 189 | } 190 | 191 | USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev) 192 | { 193 | HAL_PCD_Stop((PCD_HandleTypeDef*) pdev->pData); 194 | return USBD_OK; 195 | } 196 | 197 | USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) 198 | { 199 | HAL_PCD_EP_Open((PCD_HandleTypeDef*) pdev->pData, ep_addr, ep_mps, ep_type); 200 | return USBD_OK; 201 | } 202 | 203 | USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 204 | { 205 | HAL_PCD_EP_Close((PCD_HandleTypeDef*) pdev->pData, ep_addr); 206 | return USBD_OK; 207 | } 208 | 209 | USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 210 | { 211 | HAL_PCD_EP_Flush((PCD_HandleTypeDef*) pdev->pData, ep_addr); 212 | return USBD_OK; 213 | } 214 | 215 | USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 216 | { 217 | HAL_PCD_EP_SetStall((PCD_HandleTypeDef*) pdev->pData, ep_addr); 218 | return USBD_OK; 219 | } 220 | 221 | USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 222 | { 223 | HAL_PCD_EP_ClrStall((PCD_HandleTypeDef*) pdev->pData, ep_addr); 224 | return USBD_OK; 225 | } 226 | 227 | uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 228 | { 229 | PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; 230 | return ((ep_addr & 0x80) == 0x80) 231 | ? hpcd->IN_ep[ep_addr & 0x7F].is_stall 232 | : hpcd->OUT_ep[ep_addr & 0x7F].is_stall; 233 | } 234 | 235 | USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr) 236 | { 237 | HAL_PCD_SetAddress((PCD_HandleTypeDef*) pdev->pData, dev_addr); 238 | return USBD_OK; 239 | } 240 | 241 | USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) 242 | { 243 | HAL_PCD_EP_Transmit((PCD_HandleTypeDef*) pdev->pData, ep_addr, pbuf, size); 244 | return USBD_OK; 245 | } 246 | 247 | USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) 248 | { 249 | HAL_PCD_EP_Receive((PCD_HandleTypeDef*) pdev->pData, ep_addr, pbuf, size); 250 | return USBD_OK; 251 | } 252 | 253 | uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 254 | { 255 | return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr); 256 | } 257 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/cmsis_compiler.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_compiler.h 3 | * @brief CMSIS compiler generic header file 4 | * @version V5.0.4 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #ifndef __CMSIS_COMPILER_H 26 | #define __CMSIS_COMPILER_H 27 | 28 | #include 29 | 30 | /* 31 | * Arm Compiler 4/5 32 | */ 33 | #if defined ( __CC_ARM ) 34 | #include "cmsis_armcc.h" 35 | 36 | 37 | /* 38 | * Arm Compiler 6 (armclang) 39 | */ 40 | #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 41 | #include "cmsis_armclang.h" 42 | 43 | 44 | /* 45 | * GNU Compiler 46 | */ 47 | #elif defined ( __GNUC__ ) 48 | #include "cmsis_gcc.h" 49 | 50 | 51 | /* 52 | * IAR Compiler 53 | */ 54 | #elif defined ( __ICCARM__ ) 55 | #include 56 | 57 | 58 | /* 59 | * TI Arm Compiler 60 | */ 61 | #elif defined ( __TI_ARM__ ) 62 | #include 63 | 64 | #ifndef __ASM 65 | #define __ASM __asm 66 | #endif 67 | #ifndef __INLINE 68 | #define __INLINE inline 69 | #endif 70 | #ifndef __STATIC_INLINE 71 | #define __STATIC_INLINE static inline 72 | #endif 73 | #ifndef __STATIC_FORCEINLINE 74 | #define __STATIC_FORCEINLINE __STATIC_INLINE 75 | #endif 76 | #ifndef __NO_RETURN 77 | #define __NO_RETURN __attribute__((noreturn)) 78 | #endif 79 | #ifndef __USED 80 | #define __USED __attribute__((used)) 81 | #endif 82 | #ifndef __WEAK 83 | #define __WEAK __attribute__((weak)) 84 | #endif 85 | #ifndef __PACKED 86 | #define __PACKED __attribute__((packed)) 87 | #endif 88 | #ifndef __PACKED_STRUCT 89 | #define __PACKED_STRUCT struct __attribute__((packed)) 90 | #endif 91 | #ifndef __PACKED_UNION 92 | #define __PACKED_UNION union __attribute__((packed)) 93 | #endif 94 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 95 | struct __attribute__((packed)) T_UINT32 { uint32_t v; }; 96 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 97 | #endif 98 | #ifndef __UNALIGNED_UINT16_WRITE 99 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 100 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) 101 | #endif 102 | #ifndef __UNALIGNED_UINT16_READ 103 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 104 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 105 | #endif 106 | #ifndef __UNALIGNED_UINT32_WRITE 107 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 108 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 109 | #endif 110 | #ifndef __UNALIGNED_UINT32_READ 111 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 112 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 113 | #endif 114 | #ifndef __ALIGNED 115 | #define __ALIGNED(x) __attribute__((aligned(x))) 116 | #endif 117 | #ifndef __RESTRICT 118 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 119 | #define __RESTRICT 120 | #endif 121 | 122 | 123 | /* 124 | * TASKING Compiler 125 | */ 126 | #elif defined ( __TASKING__ ) 127 | /* 128 | * The CMSIS functions have been implemented as intrinsics in the compiler. 129 | * Please use "carm -?i" to get an up to date list of all intrinsics, 130 | * Including the CMSIS ones. 131 | */ 132 | 133 | #ifndef __ASM 134 | #define __ASM __asm 135 | #endif 136 | #ifndef __INLINE 137 | #define __INLINE inline 138 | #endif 139 | #ifndef __STATIC_INLINE 140 | #define __STATIC_INLINE static inline 141 | #endif 142 | #ifndef __STATIC_FORCEINLINE 143 | #define __STATIC_FORCEINLINE __STATIC_INLINE 144 | #endif 145 | #ifndef __NO_RETURN 146 | #define __NO_RETURN __attribute__((noreturn)) 147 | #endif 148 | #ifndef __USED 149 | #define __USED __attribute__((used)) 150 | #endif 151 | #ifndef __WEAK 152 | #define __WEAK __attribute__((weak)) 153 | #endif 154 | #ifndef __PACKED 155 | #define __PACKED __packed__ 156 | #endif 157 | #ifndef __PACKED_STRUCT 158 | #define __PACKED_STRUCT struct __packed__ 159 | #endif 160 | #ifndef __PACKED_UNION 161 | #define __PACKED_UNION union __packed__ 162 | #endif 163 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 164 | struct __packed__ T_UINT32 { uint32_t v; }; 165 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 166 | #endif 167 | #ifndef __UNALIGNED_UINT16_WRITE 168 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 169 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 170 | #endif 171 | #ifndef __UNALIGNED_UINT16_READ 172 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 173 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 174 | #endif 175 | #ifndef __UNALIGNED_UINT32_WRITE 176 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 177 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 178 | #endif 179 | #ifndef __UNALIGNED_UINT32_READ 180 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 181 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 182 | #endif 183 | #ifndef __ALIGNED 184 | #define __ALIGNED(x) __align(x) 185 | #endif 186 | #ifndef __RESTRICT 187 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 188 | #define __RESTRICT 189 | #endif 190 | 191 | 192 | /* 193 | * COSMIC Compiler 194 | */ 195 | #elif defined ( __CSMC__ ) 196 | #include 197 | 198 | #ifndef __ASM 199 | #define __ASM _asm 200 | #endif 201 | #ifndef __INLINE 202 | #define __INLINE inline 203 | #endif 204 | #ifndef __STATIC_INLINE 205 | #define __STATIC_INLINE static inline 206 | #endif 207 | #ifndef __STATIC_FORCEINLINE 208 | #define __STATIC_FORCEINLINE __STATIC_INLINE 209 | #endif 210 | #ifndef __NO_RETURN 211 | // NO RETURN is automatically detected hence no warning here 212 | #define __NO_RETURN 213 | #endif 214 | #ifndef __USED 215 | #warning No compiler specific solution for __USED. __USED is ignored. 216 | #define __USED 217 | #endif 218 | #ifndef __WEAK 219 | #define __WEAK __weak 220 | #endif 221 | #ifndef __PACKED 222 | #define __PACKED @packed 223 | #endif 224 | #ifndef __PACKED_STRUCT 225 | #define __PACKED_STRUCT @packed struct 226 | #endif 227 | #ifndef __PACKED_UNION 228 | #define __PACKED_UNION @packed union 229 | #endif 230 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 231 | @packed struct T_UINT32 { uint32_t v; }; 232 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 233 | #endif 234 | #ifndef __UNALIGNED_UINT16_WRITE 235 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 236 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 237 | #endif 238 | #ifndef __UNALIGNED_UINT16_READ 239 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 240 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 241 | #endif 242 | #ifndef __UNALIGNED_UINT32_WRITE 243 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 244 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 245 | #endif 246 | #ifndef __UNALIGNED_UINT32_READ 247 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 248 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 249 | #endif 250 | #ifndef __ALIGNED 251 | #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. 252 | #define __ALIGNED(x) 253 | #endif 254 | #ifndef __RESTRICT 255 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 256 | #define __RESTRICT 257 | #endif 258 | 259 | 260 | #else 261 | #error Unknown compiler. 262 | #endif 263 | 264 | 265 | #endif /* __CMSIS_COMPILER_H */ 266 | 267 | --------------------------------------------------------------------------------