├── .gitignore ├── .travis.yml ├── 70-candle-usb.rules ├── CMakeLists.txt ├── LICENSE.md ├── README.md ├── cmake └── gcc-arm-none-eabi-8-2019-q3-update.cmake ├── include ├── can.h ├── config.h ├── dfu.h ├── flash.h ├── gpio.h ├── gs_usb.h ├── led.h ├── queue.h ├── timer.h ├── usbd_desc.h ├── usbd_gs_can.h └── util.h ├── ldscripts └── ldscript.ld ├── libs ├── STM32_HAL │ ├── CMakeLists.txt │ ├── config │ │ └── stm32f0xx_hal_conf.h │ ├── include │ │ ├── arm │ │ │ └── semihosting.h │ │ ├── cmsis │ │ │ ├── README_DEVICE.txt │ │ │ ├── arm_common_tables.h │ │ │ ├── arm_const_structs.h │ │ │ ├── arm_math.h │ │ │ ├── cmsis_armcc.h │ │ │ ├── cmsis_armcc_V6.h │ │ │ ├── cmsis_device.h │ │ │ ├── cmsis_gcc.h │ │ │ ├── core_cm0.h │ │ │ ├── core_cm0plus.h │ │ │ ├── core_cm3.h │ │ │ ├── core_cm4.h │ │ │ ├── core_cm7.h │ │ │ ├── core_cmFunc.h │ │ │ ├── core_cmInstr.h │ │ │ ├── core_cmSimd.h │ │ │ ├── core_sc000.h │ │ │ ├── core_sc300.h │ │ │ └── device │ │ │ │ ├── stm32f030x6.h │ │ │ │ ├── stm32f030x8.h │ │ │ │ ├── stm32f030xc.h │ │ │ │ ├── stm32f031x6.h │ │ │ │ ├── stm32f038xx.h │ │ │ │ ├── stm32f042x6.h │ │ │ │ ├── stm32f048xx.h │ │ │ │ ├── stm32f051x8.h │ │ │ │ ├── stm32f058xx.h │ │ │ │ ├── stm32f070x6.h │ │ │ │ ├── stm32f070xb.h │ │ │ │ ├── stm32f071xb.h │ │ │ │ ├── stm32f072xb.h │ │ │ │ ├── stm32f078xx.h │ │ │ │ ├── stm32f091xc.h │ │ │ │ ├── stm32f098xx.h │ │ │ │ ├── stm32f0xx.h │ │ │ │ └── system_stm32f0xx.h │ │ ├── cortexm │ │ │ └── ExceptionHandlers.h │ │ ├── diag │ │ │ └── Trace.h │ │ └── stm32f0xx │ │ │ ├── Legacy │ │ │ └── stm32_hal_legacy.h │ │ │ ├── stm32f0xx_hal.h │ │ │ ├── stm32f0xx_hal_can.h │ │ │ ├── stm32f0xx_hal_cortex.h │ │ │ ├── stm32f0xx_hal_def.h │ │ │ ├── stm32f0xx_hal_dma.h │ │ │ ├── stm32f0xx_hal_dma_ex.h │ │ │ ├── stm32f0xx_hal_flash.h │ │ │ ├── stm32f0xx_hal_flash_ex.h │ │ │ ├── stm32f0xx_hal_gpio.h │ │ │ ├── stm32f0xx_hal_gpio_ex.h │ │ │ ├── stm32f0xx_hal_i2c.h │ │ │ ├── stm32f0xx_hal_i2c_ex.h │ │ │ ├── stm32f0xx_hal_pcd.h │ │ │ ├── stm32f0xx_hal_pcd_ex.h │ │ │ ├── stm32f0xx_hal_pwr.h │ │ │ ├── stm32f0xx_hal_pwr_ex.h │ │ │ ├── stm32f0xx_hal_rcc.h │ │ │ ├── stm32f0xx_hal_rcc_ex.h │ │ │ ├── stm32f0xx_hal_tim.h │ │ │ └── stm32f0xx_hal_tim_ex.h │ └── src │ │ ├── cmsis │ │ ├── startup_stm32f042x6.S │ │ ├── startup_stm32f072xb.S │ │ └── system_stm32f0xx.c │ │ ├── cortexm │ │ ├── _initialize_hardware.c │ │ ├── _reset_hardware.c │ │ └── exception_handlers.c │ │ ├── diag │ │ ├── Trace.c │ │ └── trace_impl.c │ │ ├── newlib │ │ ├── README.txt │ │ ├── _cxx.cpp │ │ ├── _exit.c │ │ ├── _sbrk.c │ │ ├── _startup.c │ │ ├── _syscalls.c │ │ └── assert.c │ │ └── stm32f0xx │ │ ├── stm32f0xx_hal.c │ │ ├── stm32f0xx_hal_can.c │ │ ├── stm32f0xx_hal_cortex.c │ │ ├── stm32f0xx_hal_dma.c │ │ ├── stm32f0xx_hal_flash.c │ │ ├── stm32f0xx_hal_flash_ex.c │ │ ├── stm32f0xx_hal_gpio.c │ │ ├── stm32f0xx_hal_i2c.c │ │ ├── stm32f0xx_hal_i2c_ex.c │ │ ├── stm32f0xx_hal_pcd.c │ │ ├── stm32f0xx_hal_pcd_ex.c │ │ ├── stm32f0xx_hal_pwr.c │ │ ├── stm32f0xx_hal_pwr_ex.c │ │ ├── stm32f0xx_hal_rcc.c │ │ ├── stm32f0xx_hal_rcc_ex.c │ │ ├── stm32f0xx_hal_tim.c │ │ └── stm32f0xx_hal_tim_ex.c └── STM32_USB_Device_Library │ ├── CMakeLists.txt │ ├── Core │ ├── Inc │ │ ├── usbd_core.h │ │ ├── usbd_ctlreq.h │ │ ├── usbd_def.h │ │ └── usbd_ioreq.h │ └── Src │ │ ├── usbd_core.c │ │ ├── usbd_ctlreq.c │ │ └── usbd_ioreq.c │ └── config │ └── usbd_conf.h └── src ├── can.c ├── dfu.c ├── flash.c ├── gpio.c ├── interrupts.c ├── led.c ├── main.c ├── queue.c ├── timer.c ├── usbd_conf.c ├── usbd_desc.c ├── usbd_gs_can.c └── util.c /.gitignore: -------------------------------------------------------------------------------- 1 | /.vscode/ 2 | /build/ 3 | *.o 4 | *.d 5 | *.bin 6 | *.asmo 7 | *.elf 8 | *~ 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: bionic 2 | language: generic 3 | 4 | install: 5 | - wget https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5-Linux-x86_64.sh 6 | && chmod +x cmake-3.14.5-Linux-x86_64.sh 7 | - mkdir -p /opt/cmake-3.14.5 && ./cmake-3.14.5-Linux-x86_64.sh --skip-license --prefix=/opt/cmake-3.14.5 8 | - PATH=/opt/cmake-3.14.5/bin:$PATH 9 | - wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/8-2019q3/RC1.1/gcc-arm-none-eabi-8-2019-q3-update-linux.tar.bz2 10 | - tar xf gcc-arm-none-eabi-8-2019-q3-update-linux.tar.bz2 -C /opt 11 | - mkdir build && cd build 12 | - cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/gcc-arm-none-eabi-8-2019-q3-update.cmake 13 | - make 14 | 15 | before_deploy: 16 | - tar cvzf candleLight_fw_${TRAVIS_TAG}.tar.gz $(ls *_fw*) 17 | 18 | deploy: 19 | provider: releases 20 | api_key: 21 | github-token: $GITHUB_TOKEN 22 | edge: true 23 | file: 24 | - candleLight_fw_${TRAVIS_TAG}.tar.gz 25 | skip_cleanup: true 26 | on: 27 | tags: true 28 | repo: candle-usb/candleLight_fw 29 | branch: master 30 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | project(candleLightFirmware C ASM) 3 | 4 | add_compile_options( 5 | -std=gnu11 6 | -mcpu=cortex-m0 -mthumb 7 | -Wall -Wextra -Werror -Wno-deprecated 8 | -fmessage-length=0 9 | -fsigned-char 10 | -ffunction-sections -fdata-sections 11 | -ffreestanding 12 | -fno-move-loop-invariants 13 | -Os -g3 14 | ) 15 | 16 | add_link_options( 17 | -mcpu=cortex-m0 -mthumb -O 18 | -Wall -Wextra -g3 19 | -nostartfiles -Xlinker --gc-sections --specs=nano.specs 20 | -T ${CMAKE_SOURCE_DIR}/ldscripts/ldscript.ld 21 | ) 22 | 23 | 24 | add_subdirectory(libs/STM32_HAL) 25 | add_subdirectory(libs/STM32_USB_Device_Library) 26 | 27 | set( 28 | SOURCE_FILES 29 | include/config.h 30 | 31 | include/gs_usb.h 32 | include/usbd_desc.h src/usbd_desc.c 33 | include/usbd_gs_can.h src/usbd_gs_can.c 34 | src/usbd_conf.c 35 | 36 | include/can.h src/can.c 37 | include/dfu.h src/dfu.c 38 | include/flash.h src/flash.c 39 | include/gpio.h src/gpio.c 40 | include/led.h src/led.c 41 | include/queue.h src/queue.c 42 | include/timer.h src/timer.c 43 | include/util.h src/util.c 44 | 45 | src/main.c 46 | src/interrupts.c 47 | ) 48 | 49 | 50 | ####### some helpers to generate targets 51 | function(make_bin_file target) 52 | add_custom_command( 53 | TARGET ${target} POST_BUILD 54 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 55 | COMMAND ${CMAKE_OBJCOPY} -O binary ${target} ${target}.bin 56 | ) 57 | endfunction() 58 | 59 | function(show_object_size target) 60 | string(REPLACE "objcopy" "size" CMAKE_OBJSIZE "${CMAKE_OBJCOPY}") 61 | add_custom_command( 62 | TARGET ${target} POST_BUILD 63 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 64 | COMMAND ${CMAKE_OBJSIZE} ${target} 65 | ) 66 | endfunction() 67 | 68 | function(add_flash_target target) 69 | add_custom_target( 70 | flash-${target} dfu-util -d 1d50:606f -a 0 -R -s 0x08000000 -D ${target}.bin 71 | ) 72 | endfunction() 73 | 74 | ######### commands for adding each target have a lot in common: make helper func. 75 | # Split into two categories, F042-based and F072-based. 76 | 77 | function(add_f042_target TGTNAME) 78 | add_executable(${TGTNAME}_fw ${SOURCE_FILES}) 79 | target_include_directories(${TGTNAME}_fw PRIVATE include/) 80 | target_compile_definitions(${TGTNAME}_fw PRIVATE BOARD=BOARD_${TGTNAME}) 81 | target_link_libraries(${TGTNAME}_fw PRIVATE STM32_HAL_STM32F042x6 STM32_USB_Device_Library_STM32F042x6) 82 | make_bin_file(${TGTNAME}_fw) 83 | show_object_size(${TGTNAME}_fw) 84 | add_flash_target(${TGTNAME}_fw) 85 | endfunction() 86 | 87 | function(add_f072_target TGTNAME) 88 | add_executable(${TGTNAME}_fw ${SOURCE_FILES}) 89 | target_include_directories(${TGTNAME}_fw PRIVATE include/) 90 | target_compile_definitions(${TGTNAME}_fw PRIVATE BOARD=BOARD_${TGTNAME}) 91 | target_link_libraries(${TGTNAME}_fw PRIVATE STM32_HAL_STM32F072xB STM32_USB_Device_Library_STM32F072xB) 92 | make_bin_file(${TGTNAME}_fw) 93 | show_object_size(${TGTNAME}_fw) 94 | add_flash_target(${TGTNAME}_fw) 95 | endfunction() 96 | 97 | ########## generate list of targets. 98 | # the "_fw" part is appended automatically 99 | set(TGT042_LIST "cantact" "canalyze" "canable" "usb2can") 100 | set(TGT072_LIST "candleLight") 101 | 102 | 103 | foreach (TGTNAME IN LISTS TGT042_LIST) 104 | option(BUILD_${TGTNAME} "Build firmware for \"${TGTNAME}\" (default=yes)" ON) 105 | if (BUILD_${TGTNAME}) 106 | add_f042_target(${TGTNAME}) 107 | endif() 108 | endforeach() 109 | 110 | foreach (TGTNAME IN LISTS TGT072_LIST) 111 | option(BUILD_${TGTNAME} "Build firmware for \"${TGTNAME}\" (default=yes)" ON) 112 | if (BUILD_${TGTNAME}) 113 | add_f072_target(${TGTNAME}) 114 | endif() 115 | endforeach() 116 | 117 | message("*******************") 118 | message("You may now:\n\t-compile all targets ('make')\n\t-compile a single target (e.g. 'make cantact_fw'") 119 | message("\t-flash a device (e.g. 'make flash-cantact_fw'") 120 | -------------------------------------------------------------------------------- /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 under ST Micro's [Liberty V2 33 | License](http://www.st.com/software_license_agreement_liberty_v2) 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # candleLight_gsusb 2 | [![Build Status](https://travis-ci.org/candle-usb/candleLight_fw.svg?branch=master)](https://travis-ci.org/candle-usb/candleLight_fw) 3 | 4 | This is firmware for certain STM32F042x/STM32F072xB-based USB-CAN adapters, notably: 5 | - candleLight: https://github.com/HubertD/candleLight (STM32F072xB) 6 | - cantact: http://linklayer.github.io/cantact/ (STM32F042x6) 7 | - canable (cantact clone): http://canable.io/ (STM32F042x6) 8 | - USB2CAN: https://github.com/roboterclubaachen/usb2can (STM32F042x6) 9 | - CANAlyze: https://kkuchera.github.io/canalyze/ (STM32F042x6) 10 | 11 | Of important note is that the common STM32F103 will NOT work with this firmware because its hardware cannot use both USB and CAN simultaneously. 12 | 13 | This implements the interface of the mainline linux gs_usb kernel module and 14 | works out-of-the-box with linux distros packaging this module, e.g. Ubuntu. 15 | 16 | ## Known issues 17 | 18 | Be aware that there is a bug in the gs_usb module in linux<4.5 that can crash the kernel on device removal. 19 | 20 | Here is a fixed version that should also work for older kernels: 21 | https://github.com/HubertD/socketcan_gs_usb 22 | 23 | The Firmware also implements WCID USB descriptors and thus can be used on recent Windows versions without installing a driver. 24 | 25 | ## Building 26 | 27 | Building requires arm-none-eabi-gcc toolchain. 28 | 29 | ```shell 30 | sudo apt-get install gcc-arm-none-eabi 31 | 32 | mkdir build 33 | cd build 34 | cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/gcc-arm-none-eabi-8-2019-q3-update.cmake 35 | 36 | # or, 37 | # cmake-gui .. 38 | # don't forget to specify the cmake toolchain file before configuring. 39 | 40 | make canalyze_fw # one of candleLight_fw / usb2can_fw / cantact_fw / canalyze_fw / canable_fw 41 | # alternately, each board target may be disabled as cmake options 42 | 43 | ``` 44 | 45 | ## Flashing 46 | 47 | Flashing candleLight on linux: (source: [https://wiki.linklayer.com/index.php/CandleLightFirmware](https://wiki.linklayer.com/index.php/CandleLightFirmware)) 48 | - Flashing requires the dfu-util tool. On Ubuntu, this can be installed with `sudo apt install dfu-util`. 49 | - compile as above, or download the current binary release: gsusb_cantact_8b2b2b4.bin 50 | - Disconnect the USB connector from the CANtact, short the BOOT pins, then reconnect the USB connector. The device should enumerate as "STM32 BOOTLOADER". 51 | - Flash the device with: `sudo dfu-util --dfuse-address -d 0483:df11 -c 1 -i 0 -a 0 -s 0x08000000 -D CORRECT_FIRWARE.bin` where CORRECT_FIRWARE is the name of the desired .bin. 52 | - Disconnect the USB connector, un-short the BOOT pins, and reconnect. The device is now flashed! 53 | - 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. 54 | -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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 | #include "stm32f0xx_hal.h" 32 | #include 33 | 34 | typedef struct { 35 | CAN_TypeDef *instance; 36 | uint16_t brp; 37 | uint8_t phase_seg1; 38 | uint8_t phase_seg2; 39 | uint8_t sjw; 40 | } can_data_t; 41 | 42 | void can_init(can_data_t *hcan, CAN_TypeDef *instance); 43 | bool can_set_bittiming(can_data_t *hcan, uint16_t brp, uint8_t phase_seg1, uint8_t phase_seg2, uint8_t sjw); 44 | void can_enable(can_data_t *hcan, bool loop_back, bool listen_only, bool one_shot); 45 | void can_disable(can_data_t *hcan); 46 | bool can_is_enabled(can_data_t *hcan); 47 | 48 | bool can_receive(can_data_t *hcan, struct gs_host_frame *rx_frame); 49 | bool can_is_rx_pending(can_data_t *hcan); 50 | 51 | bool can_send(can_data_t *hcan, struct gs_host_frame *frame); 52 | 53 | uint32_t can_get_error_status(can_data_t *hcan); 54 | bool can_parse_error_status(uint32_t err, struct gs_host_frame *frame); 55 | -------------------------------------------------------------------------------- /include/config.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 | #define CAN_QUEUE_SIZE 64 30 | 31 | #define USBD_VID 0x1d50 32 | #define USBD_PID_FS 0x606f 33 | #define USBD_LANGID_STRING 1033 34 | #define USBD_CONFIGURATION_STRING_FS (uint8_t*) "gs_usb config" 35 | #define USBD_INTERFACE_STRING_FS (uint8_t*) "gs_usb interface" 36 | 37 | #define BOARD_candleLight 1 38 | #define BOARD_cantact 2 39 | #define BOARD_canable 3 40 | #define BOARD_usb2can 4 41 | #define BOARD_canalyze 5 42 | 43 | #if BOARD == BOARD_candleLight 44 | #define USBD_PRODUCT_STRING_FS (uint8_t*) "candleLight USB to CAN adapter" 45 | #define USBD_MANUFACTURER_STRING (uint8_t*) "bytewerk" 46 | #define DFU_INTERFACE_STRING_FS (uint8_t*) "candleLight firmware upgrade interface" 47 | #define CAN_S_Pin GPIO_PIN_13 48 | #define CAN_S_GPIO_Port GPIOC 49 | 50 | #define LED1_Pin GPIO_PIN_0 51 | #define LED1_Mode GPIO_MODE_OUTPUT_OD 52 | #define LED1_GPIO_Port GPIOA 53 | #define LED1_Active_High 0 54 | 55 | #define LED2_GPIO_Port GPIOA 56 | #define LED2_Pin GPIO_PIN_1 57 | #define LED2_Mode GPIO_MODE_OUTPUT_OD 58 | #define LED2_Active_High 0 59 | 60 | #elif BOARD == BOARD_cantact 61 | #define USBD_PRODUCT_STRING_FS (uint8_t*) "cantact gs_usb" 62 | #define USBD_MANUFACTURER_STRING (uint8_t*) "cantact.io" 63 | #define DFU_INTERFACE_STRING_FS (uint8_t*) "cantact firmware upgrade interface" 64 | 65 | // SILENT pin not connected 66 | 67 | #define LED1_GPIO_Port GPIOB 68 | #define LED1_Pin GPIO_PIN_0 /* green */ 69 | #define LED1_Mode GPIO_MODE_OUTPUT_PP 70 | #define LED1_Active_High 1 71 | 72 | #define LED2_GPIO_Port GPIOB 73 | #define LED2_Pin GPIO_PIN_1 /* red */ 74 | #define LED2_Mode GPIO_MODE_OUTPUT_PP 75 | #define LED2_Active_High 1 76 | 77 | #elif BOARD == BOARD_canable 78 | #define USBD_PRODUCT_STRING_FS (uint8_t*) "canable gs_usb" 79 | #define USBD_MANUFACTURER_STRING (uint8_t*) "canable.io" 80 | #define DFU_INTERFACE_STRING_FS (uint8_t*) "canble firmware upgrade interface" 81 | 82 | // SILENT pin not connected 83 | 84 | #define LED1_GPIO_Port GPIOB 85 | #define LED1_Pin GPIO_PIN_0 /* green */ 86 | #define LED1_Mode GPIO_MODE_OUTPUT_PP 87 | #define LED1_Active_High 1 88 | 89 | #define LED2_GPIO_Port GPIOB 90 | #define LED2_Pin GPIO_PIN_1 /* blue */ 91 | #define LED2_Mode GPIO_MODE_OUTPUT_PP 92 | #define LED2_Active_High 1 93 | 94 | #elif BOARD == BOARD_usb2can 95 | #define USBD_PRODUCT_STRING_FS (uint8_t*) "USB2CAN RCA gs_usb" 96 | #define USBD_MANUFACTURER_STRING (uint8_t*) "Roboter Club Aachen" 97 | #define DFU_INTERFACE_STRING_FS (uint8_t*) "usb2can firmware upgrade interface" 98 | 99 | // SILENT pin not connected 100 | 101 | #define LED4_GPIO_Port GPIOA 102 | #define LED4_Pin GPIO_PIN_0 /* white */ 103 | #define LED4_Mode GPIO_MODE_OUTPUT_OD 104 | #define LED4_Active_Low 105 | 106 | #define LED2_GPIO_Port GPIOA 107 | #define LED2_Pin GPIO_PIN_1 /* blue */ 108 | #define LED2_Mode GPIO_MODE_OUTPUT_OD 109 | #define LED2_Active_High 0 110 | 111 | #define LED3_GPIO_Port GPIOA 112 | #define LED3_Pin GPIO_PIN_2 /* red */ 113 | #define LED3_Mode GPIO_MODE_OUTPUT_OD 114 | #define LED3_Active_Low 115 | 116 | #define LED1_GPIO_Port GPIOB 117 | #define LED1_Pin GPIO_PIN_3 /* green */ 118 | #define LED1_Mode GPIO_MODE_OUTPUT_OD 119 | #define LED1_Active_High 0 120 | #elif BOARD == BOARD_canalyze 121 | #define USBD_PRODUCT_STRING_FS (uint8_t*) "CANAlyze gs_usb" 122 | #define USBD_MANUFACTURER_STRING (uint8_t*) "STMicroelectronics" 123 | #define DFU_INTERFACE_STRING_FS (uint8_t*) "CANAlyze firmware upgrade interface" 124 | 125 | // SILENT pin not connected 126 | 127 | #define LED1_GPIO_Port GPIOB 128 | #define LED1_Pin GPIO_PIN_0 /* green */ 129 | #define LED1_Mode GPIO_MODE_OUTPUT_PP 130 | #define LED1_Active_High 1 131 | 132 | #define LED2_GPIO_Port GPIOB 133 | #define LED2_Pin GPIO_PIN_1 /* red */ 134 | #define LED2_Mode GPIO_MODE_OUTPUT_PP 135 | #define LED2_Active_High 1 136 | #else 137 | #error please define BOARD 138 | #endif 139 | -------------------------------------------------------------------------------- /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(); 30 | -------------------------------------------------------------------------------- /include/flash.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 | void flash_load(); 33 | bool flash_set_user_id(uint8_t channel, uint32_t user_id); 34 | uint32_t flash_get_user_id(uint8_t channel); 35 | void flash_flush(); 36 | -------------------------------------------------------------------------------- /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 | void gpio_init(); 30 | -------------------------------------------------------------------------------- /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 | typedef enum { 33 | led_mode_off, 34 | led_mode_normal, 35 | led_mode_warn, 36 | led_mode_error, 37 | led_mode_sequence 38 | } led_mode_t; 39 | 40 | typedef enum { 41 | led_1, 42 | led_2 43 | } led_num_t; 44 | 45 | typedef struct { 46 | uint8_t state; 47 | uint8_t time_in_10ms; 48 | } led_seq_step_t; 49 | 50 | typedef struct { 51 | void* port; 52 | uint16_t pin; 53 | bool is_active_high; 54 | uint32_t on_until; 55 | uint32_t off_until; 56 | } led_state_t; 57 | 58 | typedef struct { 59 | led_mode_t mode; 60 | led_mode_t last_mode; 61 | 62 | led_seq_step_t *sequence; 63 | uint32_t sequence_step; 64 | uint32_t t_sequence_next; 65 | int32_t seq_num_repeat; 66 | 67 | led_state_t led_state[2]; 68 | } led_data_t; 69 | 70 | 71 | void led_init( 72 | led_data_t *leds, 73 | void* led1_port, uint16_t led1_pin, bool led1_active_high, 74 | void* led2_port, uint16_t led2_pin, bool led2_active_high 75 | ); 76 | void led_set_mode(led_data_t *leds,led_mode_t mode); 77 | void led_run_sequence(led_data_t *leds, led_seq_step_t *sequence, int32_t num_repeat); 78 | void led_indicate_trx(led_data_t *leds, led_num_t num); 79 | void led_update(led_data_t *leds); 80 | -------------------------------------------------------------------------------- /include/queue.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 | typedef struct { 33 | unsigned max_elements; 34 | unsigned first; 35 | unsigned size; 36 | void **buf; 37 | } queue_t; 38 | 39 | queue_t *queue_create(unsigned max_elements); 40 | void queue_free(queue_t *q); 41 | 42 | unsigned queue_size(queue_t *q); 43 | bool queue_is_empty(queue_t *q); 44 | bool queue_push_back(queue_t *q, void *el); 45 | bool queue_push_front(queue_t *q, void *el); 46 | void *queue_pop_front(queue_t *q); 47 | 48 | unsigned queue_size_i(queue_t *q); 49 | bool queue_is_empty_i(queue_t *q); 50 | bool queue_push_back_i(queue_t *q, void *el); 51 | bool queue_push_front_i(queue_t *q, void *el); 52 | void *queue_pop_front_i(queue_t *q); 53 | -------------------------------------------------------------------------------- /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(); 32 | uint32_t timer_get(); 33 | -------------------------------------------------------------------------------- /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 "usbd_def.h" 30 | 31 | extern USBD_DescriptorsTypeDef FS_Desc; 32 | extern uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ]; 33 | -------------------------------------------------------------------------------- /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 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | /* Define these here so they can be referenced in other files */ 37 | 38 | #define CAN_DATA_MAX_PACKET_SIZE 32 /* Endpoint IN & OUT Packet size */ 39 | #define CAN_CMD_PACKET_SIZE 64 /* Control Endpoint Packet size */ 40 | #define USB_CAN_CONFIG_DESC_SIZ 50 41 | #define NUM_CAN_CHANNEL 1 42 | #define USBD_GS_CAN_VENDOR_CODE 0x20 43 | #define DFU_INTERFACE_NUM 1 44 | #define DFU_INTERFACE_STR_INDEX 0xE0 45 | 46 | extern USBD_ClassTypeDef USBD_GS_CAN; 47 | 48 | uint8_t USBD_GS_CAN_Init(USBD_HandleTypeDef *pdev, queue_t *q_frame_pool, queue_t *q_from_host, led_data_t *leds); 49 | void USBD_GS_CAN_SetChannel(USBD_HandleTypeDef *pdev, uint8_t channel, can_data_t* handle); 50 | void USBD_GS_CAN_SuspendCallback(USBD_HandleTypeDef *pdev); 51 | bool USBD_GS_CAN_TxReady(USBD_HandleTypeDef *pdev); 52 | uint8_t USBD_GS_CAN_PrepareReceive(USBD_HandleTypeDef *pdev); 53 | bool USBD_GS_CAN_CustomDeviceRequest(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 54 | bool USBD_GS_CAN_CustomInterfaceRequest(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 55 | 56 | bool USBD_GS_CAN_DfuDetachRequested(USBD_HandleTypeDef *pdev); 57 | uint8_t USBD_GS_CAN_SendFrame(USBD_HandleTypeDef *pdev, struct gs_host_frame *frame); 58 | uint8_t USBD_GS_CAN_Transmit(USBD_HandleTypeDef *pdev, uint8_t *buf, uint16_t len); 59 | uint8_t USBD_GS_CAN_GetProtocolVersion(USBD_HandleTypeDef *pdev); 60 | uint8_t USBD_GS_CAN_GetPadPacketsToMaxPacketSize(USBD_HandleTypeDef *pdev); 61 | -------------------------------------------------------------------------------- /include/util.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 | int disable_irq(void); 32 | void enable_irq(int primask); 33 | void hex32(char *out, uint32_t val); 34 | -------------------------------------------------------------------------------- /libs/STM32_HAL/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(STM32_HAL) 2 | 3 | set(SOURCES 4 | config/stm32f0xx_hal_conf.h 5 | 6 | src/stm32f0xx/stm32f0xx_hal.c 7 | src/stm32f0xx/stm32f0xx_hal_can.c 8 | src/stm32f0xx/stm32f0xx_hal_cortex.c 9 | src/stm32f0xx/stm32f0xx_hal_dma.c 10 | src/stm32f0xx/stm32f0xx_hal_flash.c 11 | src/stm32f0xx/stm32f0xx_hal_flash_ex.c 12 | src/stm32f0xx/stm32f0xx_hal_gpio.c 13 | src/stm32f0xx/stm32f0xx_hal_i2c.c 14 | src/stm32f0xx/stm32f0xx_hal_i2c_ex.c 15 | src/stm32f0xx/stm32f0xx_hal_pcd.c 16 | src/stm32f0xx/stm32f0xx_hal_pcd_ex.c 17 | src/stm32f0xx/stm32f0xx_hal_pwr.c 18 | src/stm32f0xx/stm32f0xx_hal_pwr_ex.c 19 | src/stm32f0xx/stm32f0xx_hal_rcc.c 20 | src/stm32f0xx/stm32f0xx_hal_rcc_ex.c 21 | src/stm32f0xx/stm32f0xx_hal_tim.c 22 | src/stm32f0xx/stm32f0xx_hal_tim_ex.c 23 | 24 | src/newlib/assert.c 25 | src/newlib/_exit.c 26 | src/newlib/_sbrk.c 27 | src/newlib/_startup.c 28 | src/newlib/_syscalls.c 29 | 30 | src/cortexm/exception_handlers.c 31 | src/cortexm/_initialize_hardware.c 32 | src/cortexm/_reset_hardware.c 33 | 34 | src/cmsis/system_stm32f0xx.c 35 | 36 | include/stm32f0xx/stm32f0xx_hal_tim.h 37 | include/stm32f0xx/stm32f0xx_hal_pcd.h 38 | include/stm32f0xx/stm32f0xx_hal_gpio.h 39 | include/stm32f0xx/stm32f0xx_hal_i2c_ex.h 40 | include/stm32f0xx/stm32f0xx_hal_flash_ex.h 41 | include/stm32f0xx/stm32f0xx_hal_dma_ex.h 42 | include/stm32f0xx/stm32f0xx_hal_i2c.h 43 | include/stm32f0xx/stm32f0xx_hal_pwr.h 44 | include/stm32f0xx/stm32f0xx_hal_pwr_ex.h 45 | include/stm32f0xx/stm32f0xx_hal_dma.h 46 | include/stm32f0xx/stm32f0xx_hal_gpio_ex.h 47 | include/stm32f0xx/Legacy/stm32_hal_legacy.h 48 | include/stm32f0xx/stm32f0xx_hal_rcc_ex.h 49 | include/stm32f0xx/stm32f0xx_hal_def.h 50 | include/stm32f0xx/stm32f0xx_hal.h 51 | include/stm32f0xx/stm32f0xx_hal_rcc.h 52 | include/stm32f0xx/stm32f0xx_hal_cortex.h 53 | include/stm32f0xx/stm32f0xx_hal_flash.h 54 | include/stm32f0xx/stm32f0xx_hal_tim_ex.h 55 | include/stm32f0xx/stm32f0xx_hal_pcd_ex.h 56 | include/stm32f0xx/stm32f0xx_hal_can.h 57 | include/cmsis/cmsis_armcc.h 58 | include/cmsis/arm_math.h 59 | include/cmsis/cmsis_armcc_V6.h 60 | include/cmsis/arm_common_tables.h 61 | include/cmsis/core_cm3.h 62 | include/cmsis/core_cm0plus.h 63 | include/cmsis/core_cm7.h 64 | include/cmsis/cmsis_gcc.h 65 | include/cmsis/core_cmInstr.h 66 | include/cmsis/core_cmFunc.h 67 | include/cmsis/core_cm0.h 68 | include/cmsis/arm_const_structs.h 69 | include/cmsis/core_sc300.h 70 | include/cmsis/device/stm32f031x6.h 71 | include/cmsis/device/stm32f048xx.h 72 | include/cmsis/device/stm32f042x6.h 73 | include/cmsis/device/stm32f091xc.h 74 | include/cmsis/device/stm32f0xx.h 75 | include/cmsis/device/stm32f030x6.h 76 | include/cmsis/device/stm32f030x8.h 77 | include/cmsis/device/stm32f078xx.h 78 | include/cmsis/device/system_stm32f0xx.h 79 | include/cmsis/device/stm32f038xx.h 80 | include/cmsis/device/stm32f058xx.h 81 | include/cmsis/device/stm32f070xb.h 82 | include/cmsis/device/stm32f098xx.h 83 | include/cmsis/device/stm32f070x6.h 84 | include/cmsis/device/stm32f071xb.h 85 | include/cmsis/device/stm32f030xc.h 86 | include/cmsis/device/stm32f051x8.h 87 | include/cmsis/device/stm32f072xb.h 88 | include/cmsis/cmsis_device.h 89 | include/cmsis/core_cm4.h 90 | include/cmsis/core_sc000.h 91 | include/cmsis/core_cmSimd.h 92 | include/arm/semihosting.h 93 | include/cortexm/ExceptionHandlers.h 94 | include/diag/Trace.h 95 | ) 96 | 97 | set(INCLUDE_DIRS 98 | include/ 99 | include/cmsis 100 | include/stm32f0xx 101 | include/cmsis/device 102 | config/ 103 | ) 104 | 105 | add_library(STM32_HAL_STM32F042x6 OBJECT ${SOURCES} src/cmsis/startup_stm32f042x6.S) 106 | target_include_directories(STM32_HAL_STM32F042x6 PUBLIC ${INCLUDE_DIRS}) 107 | target_compile_options(STM32_HAL_STM32F042x6 PRIVATE -Wno-unused-parameter -Wno-deprecated) 108 | target_compile_definitions(STM32_HAL_STM32F042x6 PUBLIC STM32F042x6) 109 | 110 | add_library(STM32_HAL_STM32F072xB OBJECT ${SOURCES} src/cmsis/startup_stm32f072xb.S) 111 | target_include_directories(STM32_HAL_STM32F072xB PUBLIC ${INCLUDE_DIRS}) 112 | target_compile_options(STM32_HAL_STM32F072xB PRIVATE -Wno-unused-parameter -Wno-deprecated) 113 | target_compile_definitions(STM32_HAL_STM32F072xB PUBLIC STM32F072xB) 114 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/arm/semihosting.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file is part of the µOS++ III distribution. 3 | // Copyright (c) 2014 Liviu Ionescu. 4 | // 5 | 6 | #ifndef ARM_SEMIHOSTING_H_ 7 | #define ARM_SEMIHOSTING_H_ 8 | 9 | // ---------------------------------------------------------------------------- 10 | 11 | // Semihosting operations. 12 | enum OperationNumber 13 | { 14 | // Regular operations 15 | SEMIHOSTING_EnterSVC = 0x17, 16 | SEMIHOSTING_ReportException = 0x18, 17 | SEMIHOSTING_SYS_CLOSE = 0x02, 18 | SEMIHOSTING_SYS_CLOCK = 0x10, 19 | SEMIHOSTING_SYS_ELAPSED = 0x30, 20 | SEMIHOSTING_SYS_ERRNO = 0x13, 21 | SEMIHOSTING_SYS_FLEN = 0x0C, 22 | SEMIHOSTING_SYS_GET_CMDLINE = 0x15, 23 | SEMIHOSTING_SYS_HEAPINFO = 0x16, 24 | SEMIHOSTING_SYS_ISERROR = 0x08, 25 | SEMIHOSTING_SYS_ISTTY = 0x09, 26 | SEMIHOSTING_SYS_OPEN = 0x01, 27 | SEMIHOSTING_SYS_READ = 0x06, 28 | SEMIHOSTING_SYS_READC = 0x07, 29 | SEMIHOSTING_SYS_REMOVE = 0x0E, 30 | SEMIHOSTING_SYS_RENAME = 0x0F, 31 | SEMIHOSTING_SYS_SEEK = 0x0A, 32 | SEMIHOSTING_SYS_SYSTEM = 0x12, 33 | SEMIHOSTING_SYS_TICKFREQ = 0x31, 34 | SEMIHOSTING_SYS_TIME = 0x11, 35 | SEMIHOSTING_SYS_TMPNAM = 0x0D, 36 | SEMIHOSTING_SYS_WRITE = 0x05, 37 | SEMIHOSTING_SYS_WRITEC = 0x03, 38 | SEMIHOSTING_SYS_WRITE0 = 0x04, 39 | 40 | // Codes returned by SEMIHOSTING_ReportException 41 | ADP_Stopped_ApplicationExit = ((2 << 16) + 38), 42 | ADP_Stopped_RunTimeError = ((2 << 16) + 35), 43 | 44 | }; 45 | 46 | // ---------------------------------------------------------------------------- 47 | 48 | // SWI numbers and reason codes for RDI (Angel) monitors. 49 | #define AngelSWI_ARM 0x123456 50 | #ifdef __thumb__ 51 | #define AngelSWI 0xAB 52 | #else 53 | #define AngelSWI AngelSWI_ARM 54 | #endif 55 | // For thumb only architectures use the BKPT instruction instead of SWI. 56 | #if defined(__ARM_ARCH_7M__) \ 57 | || defined(__ARM_ARCH_7EM__) \ 58 | || defined(__ARM_ARCH_6M__) 59 | #define AngelSWIInsn "bkpt" 60 | #define AngelSWIAsm bkpt 61 | #else 62 | #define AngelSWIInsn "swi" 63 | #define AngelSWIAsm swi 64 | #endif 65 | 66 | #if defined(OS_DEBUG_SEMIHOSTING_FAULTS) 67 | // Testing the local semihosting handler cannot use another BKPT, since this 68 | // configuration cannot trigger HaedFault exceptions while the debugger is 69 | // connected, so we use an illegal op code, that will trigger an 70 | // UsageFault exception. 71 | #define AngelSWITestFault "setend be" 72 | #define AngelSWITestFaultOpCode (0xB658) 73 | #endif 74 | 75 | static inline int 76 | __attribute__ ((always_inline)) 77 | call_host (int reason, void* arg) 78 | { 79 | int value; 80 | asm volatile ( 81 | 82 | " mov r0, %[rsn] \n" 83 | " mov r1, %[arg] \n" 84 | #if defined(OS_DEBUG_SEMIHOSTING_FAULTS) 85 | " " AngelSWITestFault " \n" 86 | #else 87 | " " AngelSWIInsn " %[swi] \n" 88 | #endif 89 | " mov %[val], r0" 90 | 91 | : [val] "=r" (value) /* Outputs */ 92 | : [rsn] "r" (reason), [arg] "r" (arg), [swi] "i" (AngelSWI) /* Inputs */ 93 | : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc" 94 | // Clobbers r0 and r1, and lr if in supervisor mode 95 | ); 96 | 97 | // Accordingly to page 13-77 of ARM DUI 0040D other registers 98 | // can also be clobbered. Some memory positions may also be 99 | // changed by a system call, so they should not be kept in 100 | // registers. Note: we are assuming the manual is right and 101 | // Angel is respecting the APCS. 102 | return value; 103 | } 104 | 105 | // ---------------------------------------------------------------------------- 106 | 107 | // Function used in _exit() to return the status code as Angel exception. 108 | static inline void 109 | __attribute__ ((always_inline,noreturn)) 110 | report_exception (int reason) 111 | { 112 | call_host (SEMIHOSTING_ReportException, (void*) reason); 113 | 114 | for (;;) 115 | ; 116 | } 117 | 118 | // ---------------------------------------------------------------------------- 119 | 120 | #endif // ARM_SEMIHOSTING_H_ 121 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/README_DEVICE.txt: -------------------------------------------------------------------------------- 1 | The "stm32f0xx.h" and "system_stm32f0xx.h" files are provided 2 | only as a functional sample. 3 | 4 | For real applications they must be replaced by the vendor provided files. 5 | 6 | Extensions to the ARM CMSIS files: 7 | 8 | - the file "cmsis_device.h" was added, as a portable method to include the 9 | vendor device header file in library sources. 10 | 11 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/arm_common_tables.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 19. October 2015 5 | * $Revision: V.1.4.5 a 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_common_tables.h 9 | * 10 | * Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions 11 | * 12 | * Target Processor: Cortex-M4/Cortex-M3 13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted provided that the following conditions 16 | * are met: 17 | * - Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * - Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in 21 | * the documentation and/or other materials provided with the 22 | * distribution. 23 | * - Neither the name of ARM LIMITED nor the names of its contributors 24 | * may be used to endorse or promote products derived from this 25 | * software without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * -------------------------------------------------------------------- */ 40 | 41 | #ifndef _ARM_COMMON_TABLES_H 42 | #define _ARM_COMMON_TABLES_H 43 | 44 | #include "arm_math.h" 45 | 46 | extern const uint16_t armBitRevTable[1024]; 47 | extern const q15_t armRecipTableQ15[64]; 48 | extern const q31_t armRecipTableQ31[64]; 49 | /* extern const q31_t realCoefAQ31[1024]; */ 50 | /* extern const q31_t realCoefBQ31[1024]; */ 51 | extern const float32_t twiddleCoef_16[32]; 52 | extern const float32_t twiddleCoef_32[64]; 53 | extern const float32_t twiddleCoef_64[128]; 54 | extern const float32_t twiddleCoef_128[256]; 55 | extern const float32_t twiddleCoef_256[512]; 56 | extern const float32_t twiddleCoef_512[1024]; 57 | extern const float32_t twiddleCoef_1024[2048]; 58 | extern const float32_t twiddleCoef_2048[4096]; 59 | extern const float32_t twiddleCoef_4096[8192]; 60 | #define twiddleCoef twiddleCoef_4096 61 | extern const q31_t twiddleCoef_16_q31[24]; 62 | extern const q31_t twiddleCoef_32_q31[48]; 63 | extern const q31_t twiddleCoef_64_q31[96]; 64 | extern const q31_t twiddleCoef_128_q31[192]; 65 | extern const q31_t twiddleCoef_256_q31[384]; 66 | extern const q31_t twiddleCoef_512_q31[768]; 67 | extern const q31_t twiddleCoef_1024_q31[1536]; 68 | extern const q31_t twiddleCoef_2048_q31[3072]; 69 | extern const q31_t twiddleCoef_4096_q31[6144]; 70 | extern const q15_t twiddleCoef_16_q15[24]; 71 | extern const q15_t twiddleCoef_32_q15[48]; 72 | extern const q15_t twiddleCoef_64_q15[96]; 73 | extern const q15_t twiddleCoef_128_q15[192]; 74 | extern const q15_t twiddleCoef_256_q15[384]; 75 | extern const q15_t twiddleCoef_512_q15[768]; 76 | extern const q15_t twiddleCoef_1024_q15[1536]; 77 | extern const q15_t twiddleCoef_2048_q15[3072]; 78 | extern const q15_t twiddleCoef_4096_q15[6144]; 79 | extern const float32_t twiddleCoef_rfft_32[32]; 80 | extern const float32_t twiddleCoef_rfft_64[64]; 81 | extern const float32_t twiddleCoef_rfft_128[128]; 82 | extern const float32_t twiddleCoef_rfft_256[256]; 83 | extern const float32_t twiddleCoef_rfft_512[512]; 84 | extern const float32_t twiddleCoef_rfft_1024[1024]; 85 | extern const float32_t twiddleCoef_rfft_2048[2048]; 86 | extern const float32_t twiddleCoef_rfft_4096[4096]; 87 | 88 | 89 | /* floating-point bit reversal tables */ 90 | #define ARMBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20 ) 91 | #define ARMBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48 ) 92 | #define ARMBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56 ) 93 | #define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 ) 94 | #define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 ) 95 | #define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 ) 96 | #define ARMBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800) 97 | #define ARMBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808) 98 | #define ARMBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032) 99 | 100 | extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE__16_TABLE_LENGTH]; 101 | extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE__32_TABLE_LENGTH]; 102 | extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE__64_TABLE_LENGTH]; 103 | extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH]; 104 | extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH]; 105 | extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH]; 106 | extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE1024_TABLE_LENGTH]; 107 | extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE2048_TABLE_LENGTH]; 108 | extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE4096_TABLE_LENGTH]; 109 | 110 | /* fixed-point bit reversal tables */ 111 | #define ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH ((uint16_t)12 ) 112 | #define ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH ((uint16_t)24 ) 113 | #define ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH ((uint16_t)56 ) 114 | #define ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH ((uint16_t)112 ) 115 | #define ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH ((uint16_t)240 ) 116 | #define ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH ((uint16_t)480 ) 117 | #define ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992 ) 118 | #define ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984) 119 | #define ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032) 120 | 121 | extern const uint16_t armBitRevIndexTable_fixed_16[ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH]; 122 | extern const uint16_t armBitRevIndexTable_fixed_32[ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH]; 123 | extern const uint16_t armBitRevIndexTable_fixed_64[ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH]; 124 | extern const uint16_t armBitRevIndexTable_fixed_128[ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH]; 125 | extern const uint16_t armBitRevIndexTable_fixed_256[ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH]; 126 | extern const uint16_t armBitRevIndexTable_fixed_512[ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH]; 127 | extern const uint16_t armBitRevIndexTable_fixed_1024[ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH]; 128 | extern const uint16_t armBitRevIndexTable_fixed_2048[ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH]; 129 | extern const uint16_t armBitRevIndexTable_fixed_4096[ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH]; 130 | 131 | /* Tables for Fast Math Sine and Cosine */ 132 | extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1]; 133 | extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1]; 134 | extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1]; 135 | 136 | #endif /* ARM_COMMON_TABLES_H */ 137 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/arm_const_structs.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 19. March 2015 5 | * $Revision: V.1.4.5 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_const_structs.h 9 | * 10 | * Description: This file has constant structs that are initialized for 11 | * user convenience. For example, some can be given as 12 | * arguments to the arm_cfft_f32() function. 13 | * 14 | * Target Processor: Cortex-M4/Cortex-M3 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted provided that the following conditions 18 | * are met: 19 | * - Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * - Redistributions in binary form must reproduce the above copyright 22 | * notice, this list of conditions and the following disclaimer in 23 | * the documentation and/or other materials provided with the 24 | * distribution. 25 | * - Neither the name of ARM LIMITED nor the names of its contributors 26 | * may be used to endorse or promote products derived from this 27 | * software without specific prior written permission. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 32 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 33 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 34 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 35 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 36 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 37 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 39 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 40 | * POSSIBILITY OF SUCH DAMAGE. 41 | * -------------------------------------------------------------------- */ 42 | 43 | #ifndef _ARM_CONST_STRUCTS_H 44 | #define _ARM_CONST_STRUCTS_H 45 | 46 | #include "arm_math.h" 47 | #include "arm_common_tables.h" 48 | 49 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len16; 50 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len32; 51 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len64; 52 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len128; 53 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len256; 54 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len512; 55 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024; 56 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048; 57 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096; 58 | 59 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len16; 60 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len32; 61 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len64; 62 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len128; 63 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len256; 64 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len512; 65 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len1024; 66 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len2048; 67 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096; 68 | 69 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len16; 70 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len32; 71 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len64; 72 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len128; 73 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len256; 74 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len512; 75 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len1024; 76 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len2048; 77 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len4096; 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/cmsis_device.h: -------------------------------------------------------------------------------- 1 | #ifndef _CMSIS_H_ 2 | #define _CMSIS_H_ 3 | 4 | #include "stm32f0xx.h" 5 | 6 | #endif // _CMSIS_H_ 7 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/core_cmFunc.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file core_cmFunc.h 3 | * @brief CMSIS Cortex-M Core Function Access Header File 4 | * @version V4.30 5 | * @date 20. October 2015 6 | ******************************************************************************/ 7 | /* Copyright (c) 2009 - 2015 ARM LIMITED 8 | 9 | All rights reserved. 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | - Neither the name of ARM nor the names of its contributors may be used 18 | to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | * 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ---------------------------------------------------------------------------*/ 33 | 34 | 35 | #if defined ( __ICCARM__ ) 36 | #pragma system_include /* treat file as system include file for MISRA check */ 37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 38 | #pragma clang system_header /* treat file as system include file */ 39 | #endif 40 | 41 | #ifndef __CORE_CMFUNC_H 42 | #define __CORE_CMFUNC_H 43 | 44 | 45 | /* ########################### Core Function Access ########################### */ 46 | /** \ingroup CMSIS_Core_FunctionInterface 47 | \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions 48 | @{ 49 | */ 50 | 51 | /*------------------ RealView Compiler -----------------*/ 52 | #if defined ( __CC_ARM ) 53 | #include "cmsis_armcc.h" 54 | 55 | /*------------------ ARM Compiler V6 -------------------*/ 56 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 57 | #include "cmsis_armcc_V6.h" 58 | 59 | /*------------------ GNU Compiler ----------------------*/ 60 | #elif defined ( __GNUC__ ) 61 | #include "cmsis_gcc.h" 62 | 63 | /*------------------ ICC Compiler ----------------------*/ 64 | #elif defined ( __ICCARM__ ) 65 | #include 66 | 67 | /*------------------ TI CCS Compiler -------------------*/ 68 | #elif defined ( __TMS470__ ) 69 | #include 70 | 71 | /*------------------ TASKING Compiler ------------------*/ 72 | #elif defined ( __TASKING__ ) 73 | /* 74 | * The CMSIS functions have been implemented as intrinsics in the compiler. 75 | * Please use "carm -?i" to get an up to date list of all intrinsics, 76 | * Including the CMSIS ones. 77 | */ 78 | 79 | /*------------------ COSMIC Compiler -------------------*/ 80 | #elif defined ( __CSMC__ ) 81 | #include 82 | 83 | #endif 84 | 85 | /*@} end of CMSIS_Core_RegAccFunctions */ 86 | 87 | #endif /* __CORE_CMFUNC_H */ 88 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/core_cmInstr.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file core_cmInstr.h 3 | * @brief CMSIS Cortex-M Core Instruction Access Header File 4 | * @version V4.30 5 | * @date 20. October 2015 6 | ******************************************************************************/ 7 | /* Copyright (c) 2009 - 2015 ARM LIMITED 8 | 9 | All rights reserved. 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | - Neither the name of ARM nor the names of its contributors may be used 18 | to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | * 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ---------------------------------------------------------------------------*/ 33 | 34 | 35 | #if defined ( __ICCARM__ ) 36 | #pragma system_include /* treat file as system include file for MISRA check */ 37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 38 | #pragma clang system_header /* treat file as system include file */ 39 | #endif 40 | 41 | #ifndef __CORE_CMINSTR_H 42 | #define __CORE_CMINSTR_H 43 | 44 | 45 | /* ########################## Core Instruction Access ######################### */ 46 | /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface 47 | Access to dedicated instructions 48 | @{ 49 | */ 50 | 51 | /*------------------ RealView Compiler -----------------*/ 52 | #if defined ( __CC_ARM ) 53 | #include "cmsis_armcc.h" 54 | 55 | /*------------------ ARM Compiler V6 -------------------*/ 56 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 57 | #include "cmsis_armcc_V6.h" 58 | 59 | /*------------------ GNU Compiler ----------------------*/ 60 | #elif defined ( __GNUC__ ) 61 | #include "cmsis_gcc.h" 62 | 63 | /*------------------ ICC Compiler ----------------------*/ 64 | #elif defined ( __ICCARM__ ) 65 | #include 66 | 67 | /*------------------ TI CCS Compiler -------------------*/ 68 | #elif defined ( __TMS470__ ) 69 | #include 70 | 71 | /*------------------ TASKING Compiler ------------------*/ 72 | #elif defined ( __TASKING__ ) 73 | /* 74 | * The CMSIS functions have been implemented as intrinsics in the compiler. 75 | * Please use "carm -?i" to get an up to date list of all intrinsics, 76 | * Including the CMSIS ones. 77 | */ 78 | 79 | /*------------------ COSMIC Compiler -------------------*/ 80 | #elif defined ( __CSMC__ ) 81 | #include 82 | 83 | #endif 84 | 85 | /*@}*/ /* end of group CMSIS_Core_InstructionInterface */ 86 | 87 | #endif /* __CORE_CMINSTR_H */ 88 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/core_cmSimd.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file core_cmSimd.h 3 | * @brief CMSIS Cortex-M SIMD Header File 4 | * @version V4.30 5 | * @date 20. October 2015 6 | ******************************************************************************/ 7 | /* Copyright (c) 2009 - 2015 ARM LIMITED 8 | 9 | All rights reserved. 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | - Neither the name of ARM nor the names of its contributors may be used 18 | to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | * 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ---------------------------------------------------------------------------*/ 33 | 34 | 35 | #if defined ( __ICCARM__ ) 36 | #pragma system_include /* treat file as system include file for MISRA check */ 37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 38 | #pragma clang system_header /* treat file as system include file */ 39 | #endif 40 | 41 | #ifndef __CORE_CMSIMD_H 42 | #define __CORE_CMSIMD_H 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | 49 | /* ################### Compiler specific Intrinsics ########################### */ 50 | /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics 51 | Access to dedicated SIMD instructions 52 | @{ 53 | */ 54 | 55 | /*------------------ RealView Compiler -----------------*/ 56 | #if defined ( __CC_ARM ) 57 | #include "cmsis_armcc.h" 58 | 59 | /*------------------ ARM Compiler V6 -------------------*/ 60 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 61 | #include "cmsis_armcc_V6.h" 62 | 63 | /*------------------ GNU Compiler ----------------------*/ 64 | #elif defined ( __GNUC__ ) 65 | #include "cmsis_gcc.h" 66 | 67 | /*------------------ ICC Compiler ----------------------*/ 68 | #elif defined ( __ICCARM__ ) 69 | #include 70 | 71 | /*------------------ TI CCS Compiler -------------------*/ 72 | #elif defined ( __TMS470__ ) 73 | #include 74 | 75 | /*------------------ TASKING Compiler ------------------*/ 76 | #elif defined ( __TASKING__ ) 77 | /* 78 | * The CMSIS functions have been implemented as intrinsics in the compiler. 79 | * Please use "carm -?i" to get an up to date list of all intrinsics, 80 | * Including the CMSIS ones. 81 | */ 82 | 83 | /*------------------ COSMIC Compiler -------------------*/ 84 | #elif defined ( __CSMC__ ) 85 | #include 86 | 87 | #endif 88 | 89 | /*@} end of group CMSIS_SIMD_intrinsics */ 90 | 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /* __CORE_CMSIMD_H */ 97 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f030x6.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f030x6.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f030x8.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f030x8.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f030xc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f030xc.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f031x6.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f031x6.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f038xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f038xx.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f042x6.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f042x6.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f048xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f048xx.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f051x8.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f051x8.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f058xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f058xx.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f070x6.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f070x6.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f070xb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f070xb.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f071xb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f071xb.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f072xb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f072xb.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f078xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f078xx.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f091xc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f091xc.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f098xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f098xx.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/stm32f0xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/normaldotcom/candleLight_fw/d13b6db511d76885533c6e7e0ef22d74a5e2d817/libs/STM32_HAL/include/cmsis/device/stm32f0xx.h -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cmsis/device/system_stm32f0xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f0xx.h 4 | * @author MCD Application Team 5 | * @version V2.3.1 6 | * @date 04-November-2016 7 | * @brief CMSIS Cortex-M0 Device System Source File for STM32F0xx devices. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2016 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /** @addtogroup CMSIS 39 | * @{ 40 | */ 41 | 42 | /** @addtogroup stm32f0xx_system 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @brief Define to prevent recursive inclusion 48 | */ 49 | #ifndef __SYSTEM_STM32F0XX_H 50 | #define __SYSTEM_STM32F0XX_H 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | /** @addtogroup STM32F0xx_System_Includes 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | /** @addtogroup STM32F0xx_System_Exported_types 66 | * @{ 67 | */ 68 | /* This variable is updated in three ways: 69 | 1) by calling CMSIS function SystemCoreClockUpdate() 70 | 3) by calling HAL API function HAL_RCC_GetHCLKFreq() 71 | 3) by calling HAL API function HAL_RCC_ClockConfig() 72 | Note: If you use this function to configure the system clock; then there 73 | is no need to call the 2 first functions listed above, since SystemCoreClock 74 | variable is updated automatically. 75 | */ 76 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 77 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 78 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @addtogroup STM32F0xx_System_Exported_Constants 85 | * @{ 86 | */ 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /** @addtogroup STM32F0xx_System_Exported_Macros 93 | * @{ 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /** @addtogroup STM32F0xx_System_Exported_Functions 101 | * @{ 102 | */ 103 | 104 | extern void SystemInit(void); 105 | extern void SystemCoreClockUpdate(void); 106 | /** 107 | * @} 108 | */ 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /*__SYSTEM_STM32F0XX_H */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | /** 121 | * @} 122 | */ 123 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 124 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/cortexm/ExceptionHandlers.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file is part of the µOS++ III distribution. 3 | // Copyright (c) 2014 Liviu Ionescu. 4 | // 5 | 6 | #ifndef CORTEXM_EXCEPTION_HANDLERS_H_ 7 | #define CORTEXM_EXCEPTION_HANDLERS_H_ 8 | 9 | #include 10 | 11 | #if defined(DEBUG) 12 | #define __DEBUG_BKPT() asm volatile ("bkpt 0") 13 | #endif 14 | 15 | // ---------------------------------------------------------------------------- 16 | 17 | #if defined(__cplusplus) 18 | extern "C" 19 | { 20 | #endif 21 | 22 | // External references to cortexm_handlers.c 23 | 24 | extern void 25 | Reset_Handler (void); 26 | extern void 27 | NMI_Handler (void); 28 | extern void 29 | HardFault_Handler (void); 30 | 31 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 32 | extern void 33 | MemManage_Handler (void); 34 | extern void 35 | BusFault_Handler (void); 36 | extern void 37 | UsageFault_Handler (void); 38 | extern void 39 | DebugMon_Handler (void); 40 | #endif 41 | 42 | extern void 43 | SVC_Handler (void); 44 | 45 | extern void 46 | PendSV_Handler (void); 47 | extern void 48 | SysTick_Handler (void); 49 | 50 | // Exception Stack Frame of the Cortex-M3 or Cortex-M4 processor. 51 | typedef struct 52 | { 53 | uint32_t r0; 54 | uint32_t r1; 55 | uint32_t r2; 56 | uint32_t r3; 57 | uint32_t r12; 58 | uint32_t lr; 59 | uint32_t pc; 60 | uint32_t psr; 61 | #if defined(__ARM_ARCH_7EM__) 62 | uint32_t s[16]; 63 | #endif 64 | } ExceptionStackFrame; 65 | 66 | #if defined(TRACE) 67 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 68 | void 69 | dumpExceptionStack (ExceptionStackFrame* frame, uint32_t cfsr, uint32_t mmfar, 70 | uint32_t bfar, uint32_t lr); 71 | #endif // defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 72 | #if defined(__ARM_ARCH_6M__) 73 | void 74 | dumpExceptionStack (ExceptionStackFrame* frame, uint32_t lr); 75 | #endif // defined(__ARM_ARCH_6M__) 76 | #endif // defined(TRACE) 77 | 78 | void 79 | HardFault_Handler_C (ExceptionStackFrame* frame, uint32_t lr); 80 | 81 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 82 | void 83 | UsageFault_Handler_C (ExceptionStackFrame* frame, uint32_t lr); 84 | void 85 | BusFault_Handler_C (ExceptionStackFrame* frame, uint32_t lr); 86 | #endif // defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 87 | 88 | #if defined(__cplusplus) 89 | } 90 | #endif 91 | 92 | // ---------------------------------------------------------------------------- 93 | 94 | #endif // CORTEXM_EXCEPTION_HANDLERS_H_ 95 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/diag/Trace.h: -------------------------------------------------------------------------------- 1 | // 2 | // This file is part of the µOS++ III distribution. 3 | // Copyright (c) 2014 Liviu Ionescu. 4 | // 5 | 6 | #ifndef DIAG_TRACE_H_ 7 | #define DIAG_TRACE_H_ 8 | 9 | // ---------------------------------------------------------------------------- 10 | 11 | #include 12 | 13 | // ---------------------------------------------------------------------------- 14 | 15 | // The trace device is an independent output channel, intended for debug 16 | // purposes. 17 | // 18 | // The API is simple, and mimics the standard output calls: 19 | // - trace_printf() 20 | // - trace_puts() 21 | // - trace_putchar(); 22 | // 23 | // The implementation is done in 24 | // - trace_write() 25 | // 26 | // Trace support is enabled by adding the TRACE definition. 27 | // By default the trace messages are forwarded to the ITM output, 28 | // but can be rerouted via any device or completely suppressed by 29 | // changing the definitions required in system/src/diag/trace_impl.c 30 | // (currently OS_USE_TRACE_ITM, OS_USE_TRACE_SEMIHOSTING_DEBUG/_STDOUT). 31 | // 32 | // When TRACE is not defined, all functions are inlined to empty bodies. 33 | // This has the advantage that the trace call do not need to be conditionally 34 | // compiled with #ifdef TRACE/#endif 35 | 36 | 37 | #if defined(TRACE) 38 | 39 | #if defined(__cplusplus) 40 | extern "C" 41 | { 42 | #endif 43 | 44 | void 45 | trace_initialize(void); 46 | 47 | // Implementation dependent 48 | ssize_t 49 | trace_write(const char* buf, size_t nbyte); 50 | 51 | // ----- Portable ----- 52 | 53 | int 54 | trace_printf(const char* format, ...); 55 | 56 | int 57 | trace_puts(const char *s); 58 | 59 | int 60 | trace_putchar(int c); 61 | 62 | void 63 | trace_dump_args(int argc, char* argv[]); 64 | 65 | #if defined(__cplusplus) 66 | } 67 | #endif 68 | 69 | #else // !defined(TRACE) 70 | 71 | #if defined(__cplusplus) 72 | extern "C" 73 | { 74 | #endif 75 | 76 | inline void 77 | trace_initialize(void); 78 | 79 | // Implementation dependent 80 | inline ssize_t 81 | trace_write(const char* buf, size_t nbyte); 82 | 83 | inline int 84 | trace_printf(const char* format, ...); 85 | 86 | inline int 87 | trace_puts(const char *s); 88 | 89 | inline int 90 | trace_putchar(int c); 91 | 92 | inline void 93 | trace_dump_args(int argc, char* argv[]); 94 | 95 | #if defined(__cplusplus) 96 | } 97 | #endif 98 | 99 | inline void 100 | __attribute__((always_inline)) 101 | trace_initialize(void) 102 | { 103 | } 104 | 105 | // Empty definitions when trace is not defined 106 | inline ssize_t 107 | __attribute__((always_inline)) 108 | trace_write(const char* buf __attribute__((unused)), 109 | size_t nbyte __attribute__((unused))) 110 | { 111 | return 0; 112 | } 113 | 114 | inline int 115 | __attribute__((always_inline)) 116 | trace_printf(const char* format __attribute__((unused)), ...) 117 | { 118 | return 0; 119 | } 120 | 121 | inline int 122 | __attribute__((always_inline)) 123 | trace_puts(const char *s __attribute__((unused))) 124 | { 125 | return 0; 126 | } 127 | 128 | inline int 129 | __attribute__((always_inline)) 130 | trace_putchar(int c) 131 | { 132 | return c; 133 | } 134 | 135 | inline void 136 | __attribute__((always_inline)) 137 | trace_dump_args(int argc __attribute__((unused)), 138 | char* argv[] __attribute__((unused))) 139 | { 140 | } 141 | 142 | #endif // defined(TRACE) 143 | 144 | // ---------------------------------------------------------------------------- 145 | 146 | #endif // DIAG_TRACE_H_ 147 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/stm32f0xx/stm32f0xx_hal_cortex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_cortex.h 4 | * @author MCD Application Team 5 | * @version V1.5.0 6 | * @date 04-November-2016 7 | * @brief Header file of CORTEX HAL module. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2016 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __STM32F0xx_HAL_CORTEX_H 40 | #define __STM32F0xx_HAL_CORTEX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "stm32f0xx_hal_def.h" 48 | 49 | /** @addtogroup STM32F0xx_HAL_Driver 50 | * @{ 51 | */ 52 | 53 | /** @addtogroup CORTEX CORTEX 54 | * @{ 55 | */ 56 | /* Exported types ------------------------------------------------------------*/ 57 | /* Exported constants --------------------------------------------------------*/ 58 | 59 | /** @defgroup CORTEX_Exported_Constants CORTEX Exported Constants 60 | * @{ 61 | */ 62 | 63 | /** @defgroup CORTEX_SysTick_clock_source CORTEX SysTick clock source 64 | * @{ 65 | */ 66 | #define SYSTICK_CLKSOURCE_HCLK_DIV8 (0x00000000U) 67 | #define SYSTICK_CLKSOURCE_HCLK (0x00000004U) 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /* Exported Macros -----------------------------------------------------------*/ 78 | 79 | /* Exported functions --------------------------------------------------------*/ 80 | /** @addtogroup CORTEX_Exported_Functions CORTEX Exported Functions 81 | * @{ 82 | */ 83 | /** @addtogroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions 84 | * @brief Initialization and Configuration functions 85 | * @{ 86 | */ 87 | /* Initialization and de-initialization functions *******************************/ 88 | void HAL_NVIC_SetPriority(IRQn_Type IRQn,uint32_t PreemptPriority, uint32_t SubPriority); 89 | void HAL_NVIC_EnableIRQ(IRQn_Type IRQn); 90 | void HAL_NVIC_DisableIRQ(IRQn_Type IRQn); 91 | void HAL_NVIC_SystemReset(void); 92 | uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb); 93 | /** 94 | * @} 95 | */ 96 | 97 | /** @addtogroup CORTEX_Exported_Functions_Group2 Peripheral Control functions 98 | * @brief Cortex control functions 99 | * @{ 100 | */ 101 | 102 | /* Peripheral Control functions *************************************************/ 103 | uint32_t HAL_NVIC_GetPriority(IRQn_Type IRQn); 104 | uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn); 105 | void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn); 106 | void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn); 107 | void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource); 108 | void HAL_SYSTICK_IRQHandler(void); 109 | void HAL_SYSTICK_Callback(void); 110 | /** 111 | * @} 112 | */ 113 | 114 | /** 115 | * @} 116 | */ 117 | 118 | /* Private types -------------------------------------------------------------*/ 119 | /* Private variables ---------------------------------------------------------*/ 120 | /* Private constants ---------------------------------------------------------*/ 121 | /* Private macros ------------------------------------------------------------*/ 122 | /** @defgroup CORTEX_Private_Macros CORTEX Private Macros 123 | * @{ 124 | */ 125 | #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x4) 126 | 127 | #define IS_NVIC_DEVICE_IRQ(IRQ) ((IRQ) >= 0x00) 128 | 129 | #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SYSTICK_CLKSOURCE_HCLK) || \ 130 | ((SOURCE) == SYSTICK_CLKSOURCE_HCLK_DIV8)) 131 | /** 132 | * @} 133 | */ 134 | 135 | /** 136 | * @} 137 | */ 138 | 139 | /** 140 | * @} 141 | */ 142 | 143 | #ifdef __cplusplus 144 | } 145 | #endif 146 | 147 | #endif /* __STM32F0xx_HAL_CORTEX_H */ 148 | 149 | 150 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 151 | 152 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/stm32f0xx/stm32f0xx_hal_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_def.h 4 | * @author MCD Application Team 5 | * @version V1.5.0 6 | * @date 04-November-2016 7 | * @brief This file contains HAL common defines, enumeration, macros and 8 | * structures definitions. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT(c) 2016 STMicroelectronics

13 | * 14 | * Redistribution and use in source and binary forms, with or without modification, 15 | * are permitted provided that the following conditions are met: 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | * 36 | ****************************************************************************** 37 | */ 38 | 39 | /* Define to prevent recursive inclusion -------------------------------------*/ 40 | #ifndef __STM32F0xx_HAL_DEF 41 | #define __STM32F0xx_HAL_DEF 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | /* Includes ------------------------------------------------------------------*/ 48 | #include "stm32f0xx.h" 49 | #include "Legacy/stm32_hal_legacy.h" 50 | #include 51 | 52 | /* Exported types ------------------------------------------------------------*/ 53 | 54 | /** 55 | * @brief HAL Status structures definition 56 | */ 57 | typedef enum 58 | { 59 | HAL_OK = 0x00U, 60 | HAL_ERROR = 0x01U, 61 | HAL_BUSY = 0x02U, 62 | HAL_TIMEOUT = 0x03U 63 | } HAL_StatusTypeDef; 64 | 65 | /** 66 | * @brief HAL Lock structures definition 67 | */ 68 | typedef enum 69 | { 70 | HAL_UNLOCKED = 0x00U, 71 | HAL_LOCKED = 0x01U 72 | } HAL_LockTypeDef; 73 | 74 | /* Exported macro ------------------------------------------------------------*/ 75 | 76 | #define HAL_MAX_DELAY 0xFFFFFFFFU 77 | 78 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) != RESET) 79 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == RESET) 80 | 81 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD_, __DMA_HANDLE_) \ 82 | do{ \ 83 | (__HANDLE__)->__PPP_DMA_FIELD_ = &(__DMA_HANDLE_); \ 84 | (__DMA_HANDLE_).Parent = (__HANDLE__); \ 85 | } while(0) 86 | 87 | #define UNUSED(x) ((void)(x)) 88 | 89 | /** @brief Reset the Handle's State field. 90 | * @param __HANDLE__: specifies the Peripheral Handle. 91 | * @note This macro can be used for the following purpose: 92 | * - When the Handle is declared as local variable; before passing it as parameter 93 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 94 | * to set to 0 the Handle's "State" field. 95 | * Otherwise, "State" field may have any random value and the first time the function 96 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed 97 | * (i.e. HAL_PPP_MspInit() will not be executed). 98 | * - When there is a need to reconfigure the low level hardware: instead of calling 99 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 100 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function 101 | * HAL_PPP_MspInit() which will reconfigure the low level hardware. 102 | * @retval None 103 | */ 104 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0) 105 | 106 | #if (USE_RTOS == 1) 107 | #error " USE_RTOS should be 0 in the current HAL release " 108 | #else 109 | #define __HAL_LOCK(__HANDLE__) \ 110 | do{ \ 111 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 112 | { \ 113 | return HAL_BUSY; \ 114 | } \ 115 | else \ 116 | { \ 117 | (__HANDLE__)->Lock = HAL_LOCKED; \ 118 | } \ 119 | }while (0) 120 | 121 | #define __HAL_UNLOCK(__HANDLE__) \ 122 | do{ \ 123 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 124 | }while (0) 125 | #endif /* USE_RTOS */ 126 | 127 | #if defined ( __GNUC__ ) 128 | #ifndef __weak 129 | #define __weak __attribute__((weak)) 130 | #endif /* __weak */ 131 | #ifndef __packed 132 | #define __packed __attribute__((__packed__)) 133 | #endif /* __packed */ 134 | #endif /* __GNUC__ */ 135 | 136 | 137 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ 138 | #if defined (__GNUC__) /* GNU Compiler */ 139 | #ifndef __ALIGN_END 140 | #define __ALIGN_END __attribute__ ((aligned (4))) 141 | #endif /* __ALIGN_END */ 142 | #ifndef __ALIGN_BEGIN 143 | #define __ALIGN_BEGIN 144 | #endif /* __ALIGN_BEGIN */ 145 | #else 146 | #ifndef __ALIGN_END 147 | #define __ALIGN_END 148 | #endif /* __ALIGN_END */ 149 | #ifndef __ALIGN_BEGIN 150 | #if defined (__CC_ARM) /* ARM Compiler */ 151 | #define __ALIGN_BEGIN __align(4) 152 | #elif defined (__ICCARM__) /* IAR Compiler */ 153 | #define __ALIGN_BEGIN 154 | #endif /* __CC_ARM */ 155 | #endif /* __ALIGN_BEGIN */ 156 | #endif /* __GNUC__ */ 157 | 158 | /** 159 | * @brief __NOINLINE definition 160 | */ 161 | #if defined ( __CC_ARM ) || defined ( __GNUC__ ) 162 | /* ARM & GNUCompiler 163 | ---------------- 164 | */ 165 | #define __NOINLINE __attribute__ ( (noinline) ) 166 | 167 | #elif defined ( __ICCARM__ ) 168 | /* ICCARM Compiler 169 | --------------- 170 | */ 171 | #define __NOINLINE _Pragma("optimize = no_inline") 172 | 173 | #endif 174 | 175 | #ifdef __cplusplus 176 | } 177 | #endif 178 | 179 | #endif /* ___STM32F0xx_HAL_DEF */ 180 | 181 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 182 | 183 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/stm32f0xx/stm32f0xx_hal_i2c_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_i2c_ex.h 4 | * @author MCD Application Team 5 | * @version V1.5.0 6 | * @date 04-November-2016 7 | * @brief Header file of I2C HAL Extended module. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2016 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __STM32F0xx_HAL_I2C_EX_H 40 | #define __STM32F0xx_HAL_I2C_EX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "stm32f0xx_hal_def.h" 48 | 49 | /** @addtogroup STM32F0xx_HAL_Driver 50 | * @{ 51 | */ 52 | 53 | /** @addtogroup I2CEx 54 | * @{ 55 | */ 56 | 57 | /* Exported types ------------------------------------------------------------*/ 58 | /* Exported constants --------------------------------------------------------*/ 59 | 60 | /** @defgroup I2CEx_Exported_Constants I2C Extended Exported Constants 61 | * @{ 62 | */ 63 | 64 | /** @defgroup I2CEx_Analog_Filter I2C Extended Analog Filter 65 | * @{ 66 | */ 67 | #define I2C_ANALOGFILTER_ENABLE (0x00000000U) 68 | #define I2C_ANALOGFILTER_DISABLE I2C_CR1_ANFOFF 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @defgroup I2CEx_FastModePlus I2C Extended Fast Mode Plus 74 | * @{ 75 | */ 76 | #define I2C_FMP_NOT_SUPPORTED (0xAAAA0000U) /*!< Fast Mode Plus not supported */ 77 | #if defined(SYSCFG_CFGR1_I2C_FMP_PA9) 78 | #define I2C_FASTMODEPLUS_PA9 SYSCFG_CFGR1_I2C_FMP_PA9 /*!< Enable Fast Mode Plus on PA9 */ 79 | #define I2C_FASTMODEPLUS_PA10 SYSCFG_CFGR1_I2C_FMP_PA10 /*!< Enable Fast Mode Plus on PA10 */ 80 | #else 81 | #define I2C_FASTMODEPLUS_PA9 (uint32_t)(0x00000001U | I2C_FMP_NOT_SUPPORTED) /*!< Fast Mode Plus PA9 not supported */ 82 | #define I2C_FASTMODEPLUS_PA10 (uint32_t)(0x00000002U | I2C_FMP_NOT_SUPPORTED) /*!< Fast Mode Plus PA10 not supported */ 83 | #endif 84 | #define I2C_FASTMODEPLUS_PB6 SYSCFG_CFGR1_I2C_FMP_PB6 /*!< Enable Fast Mode Plus on PB6 */ 85 | #define I2C_FASTMODEPLUS_PB7 SYSCFG_CFGR1_I2C_FMP_PB7 /*!< Enable Fast Mode Plus on PB7 */ 86 | #define I2C_FASTMODEPLUS_PB8 SYSCFG_CFGR1_I2C_FMP_PB8 /*!< Enable Fast Mode Plus on PB8 */ 87 | #define I2C_FASTMODEPLUS_PB9 SYSCFG_CFGR1_I2C_FMP_PB9 /*!< Enable Fast Mode Plus on PB9 */ 88 | #if defined(SYSCFG_CFGR1_I2C_FMP_I2C1) 89 | #define I2C_FASTMODEPLUS_I2C1 SYSCFG_CFGR1_I2C_FMP_I2C1 /*!< Enable Fast Mode Plus on I2C1 pins */ 90 | #else 91 | #define I2C_FASTMODEPLUS_I2C1 (uint32_t)(0x00000100U | I2C_FMP_NOT_SUPPORTED) /*!< Fast Mode Plus I2C1 not supported */ 92 | #endif 93 | #if defined(SYSCFG_CFGR1_I2C_FMP_I2C2) 94 | #define I2C_FASTMODEPLUS_I2C2 SYSCFG_CFGR1_I2C_FMP_I2C2 /*!< Enable Fast Mode Plus on I2C2 pins */ 95 | #else 96 | #define I2C_FASTMODEPLUS_I2C2 (uint32_t)(0x00000200U | I2C_FMP_NOT_SUPPORTED) /*!< Fast Mode Plus I2C2 not supported */ 97 | #endif 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | 106 | /* Exported macro ------------------------------------------------------------*/ 107 | /* Exported functions --------------------------------------------------------*/ 108 | 109 | /** @addtogroup I2CEx_Exported_Functions I2C Extended Exported Functions 110 | * @{ 111 | */ 112 | 113 | /** @addtogroup I2CEx_Exported_Functions_Group1 Extended features functions 114 | * @brief Extended features functions 115 | * @{ 116 | */ 117 | 118 | /* Peripheral Control functions ************************************************/ 119 | HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter); 120 | HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter); 121 | #if defined(I2C_CR1_WUPEN) 122 | HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp(I2C_HandleTypeDef *hi2c); 123 | HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp(I2C_HandleTypeDef *hi2c); 124 | #endif 125 | void HAL_I2CEx_EnableFastModePlus(uint32_t ConfigFastModePlus); 126 | void HAL_I2CEx_DisableFastModePlus(uint32_t ConfigFastModePlus); 127 | 128 | /* Private constants ---------------------------------------------------------*/ 129 | /** @defgroup I2CEx_Private_Constants I2C Extended Private Constants 130 | * @{ 131 | */ 132 | 133 | /** 134 | * @} 135 | */ 136 | 137 | /* Private macros ------------------------------------------------------------*/ 138 | /** @defgroup I2CEx_Private_Macro I2C Extended Private Macros 139 | * @{ 140 | */ 141 | #define IS_I2C_ANALOG_FILTER(FILTER) (((FILTER) == I2C_ANALOGFILTER_ENABLE) || \ 142 | ((FILTER) == I2C_ANALOGFILTER_DISABLE)) 143 | 144 | #define IS_I2C_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000FU) 145 | 146 | #define IS_I2C_FASTMODEPLUS(__CONFIG__) ((((__CONFIG__) & I2C_FMP_NOT_SUPPORTED) != I2C_FMP_NOT_SUPPORTED) && \ 147 | ((((__CONFIG__) & (I2C_FASTMODEPLUS_PA9)) == I2C_FASTMODEPLUS_PA9) || \ 148 | (((__CONFIG__) & (I2C_FASTMODEPLUS_PA10)) == I2C_FASTMODEPLUS_PA10) || \ 149 | (((__CONFIG__) & (I2C_FASTMODEPLUS_PB6)) == I2C_FASTMODEPLUS_PB6) || \ 150 | (((__CONFIG__) & (I2C_FASTMODEPLUS_PB7)) == I2C_FASTMODEPLUS_PB7) || \ 151 | (((__CONFIG__) & (I2C_FASTMODEPLUS_PB8)) == I2C_FASTMODEPLUS_PB8) || \ 152 | (((__CONFIG__) & (I2C_FASTMODEPLUS_PB9)) == I2C_FASTMODEPLUS_PB9) || \ 153 | (((__CONFIG__) & (I2C_FASTMODEPLUS_I2C1)) == I2C_FASTMODEPLUS_I2C1) || \ 154 | (((__CONFIG__) & (I2C_FASTMODEPLUS_I2C2)) == I2C_FASTMODEPLUS_I2C2))) 155 | /** 156 | * @} 157 | */ 158 | 159 | /* Private Functions ---------------------------------------------------------*/ 160 | /** @defgroup I2CEx_Private_Functions I2C Extended Private Functions 161 | * @{ 162 | */ 163 | /* Private functions are defined in stm32f0xx_hal_i2c_ex.c file */ 164 | /** 165 | * @} 166 | */ 167 | 168 | /** 169 | * @} 170 | */ 171 | 172 | /** 173 | * @} 174 | */ 175 | 176 | /** 177 | * @} 178 | */ 179 | 180 | /** 181 | * @} 182 | */ 183 | 184 | #ifdef __cplusplus 185 | } 186 | #endif 187 | 188 | #endif /* __STM32F0xx_HAL_I2C_EX_H */ 189 | 190 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 191 | -------------------------------------------------------------------------------- /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 | * @version V1.5.0 6 | * @date 04-November-2016 7 | * @brief Header file of PCD HAL Extension module. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2016 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __STM32L0xx_HAL_PCD_EX_H 40 | #define __STM32L0xx_HAL_PCD_EX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB) || defined(STM32F078xx)|| defined(STM32F070xB)|| defined(STM32F070x6) 47 | 48 | /* Includes ------------------------------------------------------------------*/ 49 | #include "stm32f0xx_hal_def.h" 50 | 51 | /** @addtogroup STM32F0xx_HAL_Driver 52 | * @{ 53 | */ 54 | 55 | /** @addtogroup PCDEx 56 | * @{ 57 | */ 58 | 59 | /* Exported types ------------------------------------------------------------*/ 60 | /* Exported constants --------------------------------------------------------*/ 61 | /* Exported macros -----------------------------------------------------------*/ 62 | /* Internal macros -----------------------------------------------------------*/ 63 | /* Exported functions --------------------------------------------------------*/ 64 | /** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions 65 | * @{ 66 | */ 67 | /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 68 | * @{ 69 | */ 70 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, 71 | uint16_t ep_addr, 72 | uint16_t ep_kind, 73 | uint32_t pmaadress); 74 | /** 75 | * @} 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | /** 87 | * @} 88 | */ 89 | 90 | #endif /* STM32F042x6 || STM32F072xB || STM32F078xx || STM32F070xB || STM32F070x6*/ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | 97 | #endif /* __STM32F0xx_HAL_PCD_EX_H */ 98 | 99 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 100 | 101 | -------------------------------------------------------------------------------- /libs/STM32_HAL/include/stm32f0xx/stm32f0xx_hal_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_pwr.h 4 | * @author MCD Application Team 5 | * @version V1.5.0 6 | * @date 04-November-2016 7 | * @brief Header file of PWR HAL module. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2016 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __STM32F0xx_HAL_PWR_H 40 | #define __STM32F0xx_HAL_PWR_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "stm32f0xx_hal_def.h" 48 | 49 | /** @addtogroup STM32F0xx_HAL_Driver 50 | * @{ 51 | */ 52 | 53 | /** @addtogroup PWR PWR 54 | * @{ 55 | */ 56 | 57 | /* Exported types ------------------------------------------------------------*/ 58 | /* Exported constants --------------------------------------------------------*/ 59 | 60 | /** @defgroup PWR_Exported_Constants PWR Exported Constants 61 | * @{ 62 | */ 63 | 64 | /** @defgroup PWR_Regulator_state_in_STOP_mode PWR Regulator state in STOP mode 65 | * @{ 66 | */ 67 | #define PWR_MAINREGULATOR_ON (0x00000000U) 68 | #define PWR_LOWPOWERREGULATOR_ON PWR_CR_LPDS 69 | 70 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \ 71 | ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON)) 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry 77 | * @{ 78 | */ 79 | #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01U) 80 | #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02U) 81 | #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE)) 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry 87 | * @{ 88 | */ 89 | #define PWR_STOPENTRY_WFI ((uint8_t)0x01U) 90 | #define PWR_STOPENTRY_WFE ((uint8_t)0x02U) 91 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE)) 92 | /** 93 | * @} 94 | */ 95 | 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /* Exported macro ------------------------------------------------------------*/ 102 | /** @defgroup PWR_Exported_Macro PWR Exported Macro 103 | * @{ 104 | */ 105 | 106 | /** @brief Check PWR flag is set or not. 107 | * @param __FLAG__: specifies the flag to check. 108 | * This parameter can be one of the following values: 109 | * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event 110 | * was received from the WKUP pin or from the RTC alarm (Alarm A), 111 | * RTC Tamper event, RTC TimeStamp event or RTC Wakeup. 112 | * An additional wakeup event is detected if the WKUP pin is enabled 113 | * (by setting the EWUP bit) when the WKUP pin level is already high. 114 | * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was 115 | * resumed from StandBy mode. 116 | * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled 117 | * by the HAL_PWR_EnablePVD() function. The PVD is stopped by Standby mode 118 | * For this reason, this bit is equal to 0 after Standby or reset 119 | * until the PVDE bit is set. 120 | * Warning: this Flag is not available on STM32F030x8 products 121 | * @arg PWR_FLAG_VREFINTRDY: This flag indicates that the internal reference 122 | * voltage VREFINT is ready. 123 | * Warning: this Flag is not available on STM32F030x8 products 124 | * @retval The new state of __FLAG__ (TRUE or FALSE). 125 | */ 126 | #define __HAL_PWR_GET_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__)) 127 | 128 | /** @brief Clear the PWR's pending flags. 129 | * @param __FLAG__: specifies the flag to clear. 130 | * This parameter can be one of the following values: 131 | * @arg PWR_FLAG_WU: Wake Up flag 132 | * @arg PWR_FLAG_SB: StandBy flag 133 | */ 134 | #define __HAL_PWR_CLEAR_FLAG(__FLAG__) (PWR->CR |= (__FLAG__) << 2U) 135 | 136 | 137 | /** 138 | * @} 139 | */ 140 | 141 | /* Include PWR HAL Extension module */ 142 | #include "stm32f0xx_hal_pwr_ex.h" 143 | 144 | /* Exported functions --------------------------------------------------------*/ 145 | 146 | /** @addtogroup PWR_Exported_Functions PWR Exported Functions 147 | * @{ 148 | */ 149 | 150 | /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions 151 | * @{ 152 | */ 153 | 154 | /* Initialization and de-initialization functions *****************************/ 155 | void HAL_PWR_DeInit(void); 156 | 157 | /** 158 | * @} 159 | */ 160 | 161 | /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions 162 | * @{ 163 | */ 164 | 165 | /* Peripheral Control functions **********************************************/ 166 | void HAL_PWR_EnableBkUpAccess(void); 167 | void HAL_PWR_DisableBkUpAccess(void); 168 | 169 | /* WakeUp pins configuration functions ****************************************/ 170 | void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx); 171 | void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx); 172 | 173 | /* Low Power modes configuration functions ************************************/ 174 | void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry); 175 | void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry); 176 | void HAL_PWR_EnterSTANDBYMode(void); 177 | 178 | void HAL_PWR_EnableSleepOnExit(void); 179 | void HAL_PWR_DisableSleepOnExit(void); 180 | void HAL_PWR_EnableSEVOnPend(void); 181 | void HAL_PWR_DisableSEVOnPend(void); 182 | 183 | /** 184 | * @} 185 | */ 186 | 187 | /** 188 | * @} 189 | */ 190 | 191 | /** 192 | * @} 193 | */ 194 | 195 | /** 196 | * @} 197 | */ 198 | 199 | #ifdef __cplusplus 200 | } 201 | #endif 202 | 203 | 204 | #endif /* __STM32F0xx_HAL_PWR_H */ 205 | 206 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 207 | 208 | -------------------------------------------------------------------------------- /libs/STM32_HAL/src/cortexm/_initialize_hardware.c: -------------------------------------------------------------------------------- 1 | // 2 | // This file is part of the µOS++ III distribution. 3 | // Copyright (c) 2014 Liviu Ionescu. 4 | // 5 | 6 | // ---------------------------------------------------------------------------- 7 | 8 | #include "cmsis_device.h" 9 | 10 | // ---------------------------------------------------------------------------- 11 | 12 | extern unsigned int __vectors_start; 13 | 14 | // Forward declarations. 15 | 16 | void 17 | __initialize_hardware_early(void); 18 | 19 | void 20 | __initialize_hardware(void); 21 | 22 | // ---------------------------------------------------------------------------- 23 | 24 | // This is the early hardware initialisation routine, it can be 25 | // redefined in the application for more complex cases that 26 | // require early inits (before BSS init). 27 | // 28 | // Called early from _start(), right before data & bss init. 29 | // 30 | // After Reset the Cortex-M processor is in Thread mode, 31 | // priority is Privileged, and the Stack is set to Main. 32 | 33 | void 34 | __attribute__((weak)) 35 | __initialize_hardware_early(void) 36 | { 37 | // Call the CSMSIS system initialisation routine. 38 | SystemInit(); 39 | 40 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 41 | // Set VTOR to the actual address, provided by the linker script. 42 | // Override the manual, possibly wrong, SystemInit() setting. 43 | SCB->VTOR = (uint32_t)(&__vectors_start); 44 | #endif 45 | 46 | // The current version of SystemInit() leaves the value of the clock 47 | // in a RAM variable (SystemCoreClock), which will be cleared shortly, 48 | // so it needs to be recomputed after the RAM initialisations 49 | // are completed. 50 | 51 | #if defined(OS_INCLUDE_STARTUP_INIT_FP) || (defined (__VFP_FP__) && !defined (__SOFTFP__)) 52 | 53 | // Normally FP init is done by SystemInit(). In case this is not done 54 | // there, it is possible to force its inclusion by defining 55 | // OS_INCLUDE_STARTUP_INIT_FP. 56 | 57 | // Enable the Cortex-M4 FPU only when -mfloat-abi=hard. 58 | // Code taken from Section 7.1, Cortex-M4 TRM (DDI0439C) 59 | 60 | // Set bits 20-23 to enable CP10 and CP11 coprocessor 61 | SCB->CPACR |= (0xF << 20); 62 | 63 | #endif // (__VFP_FP__) && !(__SOFTFP__) 64 | 65 | #if defined(OS_DEBUG_SEMIHOSTING_FAULTS) 66 | SCB->SHCSR |= SCB_SHCSR_USGFAULTENA_Msk; 67 | #endif 68 | } 69 | 70 | // This is the second hardware initialisation routine, it can be 71 | // redefined in the application for more complex cases that 72 | // require custom inits (before constructors), otherwise these can 73 | // be done in main(). 74 | // 75 | // Called from _start(), right after data & bss init, before 76 | // constructors. 77 | 78 | void 79 | __attribute__((weak)) 80 | __initialize_hardware(void) 81 | { 82 | // Call the CSMSIS system clock routine to store the clock frequency 83 | // in the SystemCoreClock global RAM location. 84 | SystemCoreClockUpdate(); 85 | } 86 | 87 | // ---------------------------------------------------------------------------- 88 | -------------------------------------------------------------------------------- /libs/STM32_HAL/src/cortexm/_reset_hardware.c: -------------------------------------------------------------------------------- 1 | // 2 | // This file is part of the µOS++ III distribution. 3 | // Copyright (c) 2014 Liviu Ionescu. 4 | // 5 | 6 | // ---------------------------------------------------------------------------- 7 | 8 | #include "cmsis_device.h" 9 | 10 | // ---------------------------------------------------------------------------- 11 | 12 | extern void 13 | __attribute__((noreturn)) 14 | NVIC_SystemReset(void); 15 | 16 | // ---------------------------------------------------------------------------- 17 | 18 | // Forward declarations 19 | 20 | void 21 | __reset_hardware(void); 22 | 23 | // ---------------------------------------------------------------------------- 24 | 25 | // This is the default hardware reset routine; it can be 26 | // redefined in the application for more complex applications. 27 | // 28 | // Called from _exit(). 29 | 30 | void 31 | __attribute__((weak,noreturn)) 32 | __reset_hardware() 33 | { 34 | NVIC_SystemReset(); 35 | } 36 | 37 | // ---------------------------------------------------------------------------- 38 | -------------------------------------------------------------------------------- /libs/STM32_HAL/src/diag/Trace.c: -------------------------------------------------------------------------------- 1 | // 2 | // This file is part of the µOS++ III distribution. 3 | // Copyright (c) 2014 Liviu Ionescu. 4 | // 5 | 6 | // ---------------------------------------------------------------------------- 7 | 8 | #if defined(TRACE) 9 | 10 | #include 11 | #include 12 | #include "diag/Trace.h" 13 | #include "string.h" 14 | 15 | #ifndef OS_INTEGER_TRACE_PRINTF_TMP_ARRAY_SIZE 16 | #define OS_INTEGER_TRACE_PRINTF_TMP_ARRAY_SIZE (128) 17 | #endif 18 | 19 | // ---------------------------------------------------------------------------- 20 | 21 | int 22 | trace_printf(const char* format, ...) 23 | { 24 | int ret; 25 | va_list ap; 26 | 27 | va_start (ap, format); 28 | 29 | // TODO: rewrite it to no longer use newlib, it is way too heavy 30 | 31 | static char buf[OS_INTEGER_TRACE_PRINTF_TMP_ARRAY_SIZE]; 32 | 33 | // Print to the local buffer 34 | ret = vsnprintf (buf, sizeof(buf), format, ap); 35 | if (ret > 0) 36 | { 37 | // Transfer the buffer to the device 38 | ret = trace_write (buf, (size_t)ret); 39 | } 40 | 41 | va_end (ap); 42 | return ret; 43 | } 44 | 45 | int 46 | trace_puts(const char *s) 47 | { 48 | trace_write(s, strlen(s)); 49 | return trace_write("\n", 1); 50 | } 51 | 52 | int 53 | trace_putchar(int c) 54 | { 55 | trace_write((const char*)&c, 1); 56 | return c; 57 | } 58 | 59 | void 60 | trace_dump_args(int argc, char* argv[]) 61 | { 62 | trace_printf("main(argc=%d, argv=[", argc); 63 | for (int i = 0; i < argc; ++i) 64 | { 65 | if (i != 0) 66 | { 67 | trace_printf(", "); 68 | } 69 | trace_printf("\"%s\"", argv[i]); 70 | } 71 | trace_printf("]);\n"); 72 | } 73 | 74 | // ---------------------------------------------------------------------------- 75 | 76 | #endif // TRACE 77 | -------------------------------------------------------------------------------- /libs/STM32_HAL/src/diag/trace_impl.c: -------------------------------------------------------------------------------- 1 | // 2 | // This file is part of the µOS++ III distribution. 3 | // Copyright (c) 2014 Liviu Ionescu. 4 | // 5 | 6 | // ---------------------------------------------------------------------------- 7 | 8 | #if defined(TRACE) 9 | 10 | #include "cmsis_device.h" 11 | #include "diag/Trace.h" 12 | 13 | // ---------------------------------------------------------------------------- 14 | 15 | // One of these definitions must be passed via the compiler command line 16 | // Note: small Cortex-M0/M0+ might implement a simplified debug interface. 17 | 18 | //#define OS_USE_TRACE_ITM 19 | //#define OS_USE_TRACE_SEMIHOSTING_DEBUG 20 | //#define OS_USE_TRACE_SEMIHOSTING_STDOUT 21 | 22 | #if !(defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)) 23 | #if defined(OS_USE_TRACE_ITM) 24 | #undef OS_USE_TRACE_ITM 25 | #warning "ITM unavailable" 26 | #endif // defined(OS_USE_TRACE_ITM) 27 | #endif // !(defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)) 28 | 29 | #if defined(OS_DEBUG_SEMIHOSTING_FAULTS) 30 | #if defined(OS_USE_TRACE_SEMIHOSTING_STDOUT) || defined(OS_USE_TRACE_SEMIHOSTING_DEBUG) 31 | #error "Cannot debug semihosting using semihosting trace; use OS_USE_TRACE_ITM" 32 | #endif 33 | #endif 34 | 35 | // ---------------------------------------------------------------------------- 36 | 37 | // Forward definitions. 38 | 39 | #if defined(OS_USE_TRACE_ITM) 40 | static ssize_t 41 | _trace_write_itm (const char* buf, size_t nbyte); 42 | #endif 43 | 44 | #if defined(OS_USE_TRACE_SEMIHOSTING_STDOUT) 45 | static ssize_t 46 | _trace_write_semihosting_stdout(const char* buf, size_t nbyte); 47 | #endif 48 | 49 | #if defined(OS_USE_TRACE_SEMIHOSTING_DEBUG) 50 | static ssize_t 51 | _trace_write_semihosting_debug(const char* buf, size_t nbyte); 52 | #endif 53 | 54 | // ---------------------------------------------------------------------------- 55 | 56 | void 57 | trace_initialize(void) 58 | { 59 | // For regular ITM / semihosting, no inits required. 60 | } 61 | 62 | // ---------------------------------------------------------------------------- 63 | 64 | // This function is called from _write() for fd==1 or fd==2 and from some 65 | // of the trace_* functions. 66 | 67 | ssize_t 68 | trace_write (const char* buf __attribute__((unused)), 69 | size_t nbyte __attribute__((unused))) 70 | { 71 | #if defined(OS_USE_TRACE_ITM) 72 | return _trace_write_itm (buf, nbyte); 73 | #elif defined(OS_USE_TRACE_SEMIHOSTING_STDOUT) 74 | return _trace_write_semihosting_stdout(buf, nbyte); 75 | #elif defined(OS_USE_TRACE_SEMIHOSTING_DEBUG) 76 | return _trace_write_semihosting_debug(buf, nbyte); 77 | #endif 78 | 79 | return -1; 80 | } 81 | 82 | // ---------------------------------------------------------------------------- 83 | 84 | #if defined(OS_USE_TRACE_ITM) 85 | 86 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 87 | 88 | // ITM is the ARM standard mechanism, running over SWD/SWO on Cortex-M3/M4 89 | // devices, and is the recommended setting, if available. 90 | // 91 | // The JLink probe and the GDB server fully support SWD/SWO 92 | // and the JLink Debugging plug-in enables it by default. 93 | // The current OpenOCD does not include support to parse the SWO stream, 94 | // so this configuration will not work on OpenOCD (will not crash, but 95 | // nothing will be displayed in the output console). 96 | 97 | #if !defined(OS_INTEGER_TRACE_ITM_STIMULUS_PORT) 98 | #define OS_INTEGER_TRACE_ITM_STIMULUS_PORT (0) 99 | #endif 100 | 101 | static ssize_t 102 | _trace_write_itm (const char* buf, size_t nbyte) 103 | { 104 | for (size_t i = 0; i < nbyte; i++) 105 | { 106 | // Check if ITM or the stimulus port are not enabled 107 | if (((ITM->TCR & ITM_TCR_ITMENA_Msk) == 0) 108 | || ((ITM->TER & (1UL << OS_INTEGER_TRACE_ITM_STIMULUS_PORT)) == 0)) 109 | { 110 | return (ssize_t)i; // return the number of sent characters (may be 0) 111 | } 112 | 113 | // Wait until STIMx is ready... 114 | while (ITM->PORT[OS_INTEGER_TRACE_ITM_STIMULUS_PORT].u32 == 0) 115 | ; 116 | // then send data, one byte at a time 117 | ITM->PORT[OS_INTEGER_TRACE_ITM_STIMULUS_PORT].u8 = (uint8_t) (*buf++); 118 | } 119 | 120 | return (ssize_t)nbyte; // all characters successfully sent 121 | } 122 | 123 | #endif // defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) 124 | 125 | #endif // OS_USE_TRACE_ITM 126 | 127 | // ---------------------------------------------------------------------------- 128 | 129 | #if defined(OS_USE_TRACE_SEMIHOSTING_DEBUG) || defined(OS_USE_TRACE_SEMIHOSTING_STDOUT) 130 | 131 | #include "arm/semihosting.h" 132 | 133 | // Semihosting is the other output channel that can be used for the trace 134 | // messages. It comes in two flavours: STDOUT and DEBUG. The STDOUT channel 135 | // is the equivalent of the stdout in POSIX and in most cases it is forwarded 136 | // to the GDB server stdout stream. The debug channel is a separate 137 | // channel. STDOUT is buffered, so nothing is displayed until a \n; 138 | // DEBUG is not buffered, but can be slow. 139 | // 140 | // Choosing between semihosting stdout and debug depends on the capabilities 141 | // of your GDB server, and also on specific needs. It is recommended to test 142 | // DEBUG first, and if too slow, try STDOUT. 143 | // 144 | // The JLink GDB server fully support semihosting, and both configurations 145 | // are available; to activate it, use "monitor semihosting enable" or check 146 | // the corresponding button in the JLink Debugging plug-in. 147 | // In OpenOCD, support for semihosting can be enabled using 148 | // "monitor arm semihosting enable". 149 | // 150 | // Note: Applications built with semihosting output active normally cannot 151 | // be executed without the debugger connected and active, since they use 152 | // BKPT to communicate with the host. However, with a carefully written 153 | // HardFault_Handler, the semihosting BKPT calls can be processed, making 154 | // possible to run semihosting applications as standalone, without being 155 | // terminated with hardware faults. 156 | 157 | #endif // OS_USE_TRACE_SEMIHOSTING_DEBUG_* 158 | 159 | // ---------------------------------------------------------------------------- 160 | 161 | #if defined(OS_USE_TRACE_SEMIHOSTING_STDOUT) 162 | 163 | static ssize_t 164 | _trace_write_semihosting_stdout (const char* buf, size_t nbyte) 165 | { 166 | static int handle; 167 | void* block[3]; 168 | int ret; 169 | 170 | if (handle == 0) 171 | { 172 | // On the first call get the file handle from the host 173 | block[0] = ":tt"; // special filename to be used for stdin/out/err 174 | block[1] = (void*) 4; // mode "w" 175 | // length of ":tt", except null terminator 176 | block[2] = (void*) (sizeof(":tt") - 1); 177 | 178 | ret = call_host (SEMIHOSTING_SYS_OPEN, (void*) block); 179 | if (ret == -1) 180 | return -1; 181 | 182 | handle = ret; 183 | } 184 | 185 | block[0] = (void*) handle; 186 | block[1] = (void*) buf; 187 | block[2] = (void*) nbyte; 188 | // send character array to host file/device 189 | ret = call_host (SEMIHOSTING_SYS_WRITE, (void*) block); 190 | // this call returns the number of bytes NOT written (0 if all ok) 191 | 192 | // -1 is not a legal value, but SEGGER seems to return it 193 | if (ret == -1) 194 | return -1; 195 | 196 | // The compliant way of returning errors 197 | if (ret == (int) nbyte) 198 | return -1; 199 | 200 | // Return the number of bytes written 201 | return (ssize_t) (nbyte) - (ssize_t) ret; 202 | } 203 | 204 | #endif // OS_USE_TRACE_SEMIHOSTING_STDOUT 205 | 206 | // ---------------------------------------------------------------------------- 207 | 208 | #if defined(OS_USE_TRACE_SEMIHOSTING_DEBUG) 209 | 210 | #define OS_INTEGER_TRACE_TMP_ARRAY_SIZE (16) 211 | 212 | static ssize_t 213 | _trace_write_semihosting_debug (const char* buf, size_t nbyte) 214 | { 215 | // Since the single character debug channel is quite slow, try to 216 | // optimise and send a null terminated string, if possible. 217 | if (buf[nbyte] == '\0') 218 | { 219 | // send string 220 | call_host (SEMIHOSTING_SYS_WRITE0, (void*) buf); 221 | } 222 | else 223 | { 224 | // If not, use a local buffer to speed things up 225 | char tmp[OS_INTEGER_TRACE_TMP_ARRAY_SIZE]; 226 | size_t togo = nbyte; 227 | while (togo > 0) 228 | { 229 | unsigned int n = ((togo < sizeof(tmp)) ? togo : sizeof(tmp)); 230 | unsigned int i = 0; 231 | for (; i < n; ++i, ++buf) 232 | { 233 | tmp[i] = *buf; 234 | } 235 | tmp[i] = '\0'; 236 | 237 | call_host (SEMIHOSTING_SYS_WRITE0, (void*) tmp); 238 | 239 | togo -= n; 240 | } 241 | } 242 | 243 | // All bytes written 244 | return (ssize_t) nbyte; 245 | } 246 | 247 | #endif // OS_USE_TRACE_SEMIHOSTING_DEBUG 248 | 249 | #endif // TRACE 250 | 251 | // ---------------------------------------------------------------------------- 252 | 253 | -------------------------------------------------------------------------------- /libs/STM32_HAL/src/newlib/README.txt: -------------------------------------------------------------------------------- 1 | 2 | The following files extend or replace some of the the newlib functionality: 3 | 4 | _startup.c: a customised startup sequence, written in C 5 | 6 | _exit.c: a customised exit() implementation 7 | 8 | _syscalls.c: local versions of the libnosys/librdimon code 9 | 10 | _sbrk.c: a custom _sbrk() to match the actual linker scripts 11 | 12 | assert.c: implementation for the asserion macros 13 | 14 | _cxx.cpp: local versions of some C++ support, to avoid references to 15 | large functions. 16 | 17 | -------------------------------------------------------------------------------- /libs/STM32_HAL/src/newlib/_cxx.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // This file is part of the µOS++ III distribution. 3 | // Copyright (c) 2014 Liviu Ionescu. 4 | // 5 | 6 | // ---------------------------------------------------------------------------- 7 | 8 | // These functions are redefined locally, to avoid references to some 9 | // heavy implementations in the standard C++ library. 10 | 11 | // ---------------------------------------------------------------------------- 12 | 13 | #include 14 | #include 15 | #include "diag/Trace.h" 16 | 17 | // ---------------------------------------------------------------------------- 18 | 19 | namespace __gnu_cxx 20 | { 21 | void 22 | __attribute__((noreturn)) 23 | __verbose_terminate_handler(); 24 | 25 | void 26 | __verbose_terminate_handler() 27 | { 28 | trace_puts(__func__); 29 | abort(); 30 | } 31 | } 32 | 33 | // ---------------------------------------------------------------------------- 34 | 35 | extern "C" 36 | { 37 | void 38 | __attribute__((noreturn)) 39 | __cxa_pure_virtual(); 40 | 41 | void 42 | __cxa_pure_virtual() 43 | { 44 | trace_puts(__func__); 45 | abort(); 46 | } 47 | } 48 | 49 | // ---------------------------------------------------------------------------- 50 | 51 | -------------------------------------------------------------------------------- /libs/STM32_HAL/src/newlib/_exit.c: -------------------------------------------------------------------------------- 1 | // 2 | // This file is part of the µOS++ III distribution. 3 | // Copyright (c) 2014 Liviu Ionescu. 4 | // 5 | 6 | // ---------------------------------------------------------------------------- 7 | 8 | #include 9 | #include "diag/Trace.h" 10 | 11 | // ---------------------------------------------------------------------------- 12 | 13 | #if !defined(DEBUG) 14 | extern void 15 | __attribute__((noreturn)) 16 | __reset_hardware(void); 17 | #endif 18 | 19 | // ---------------------------------------------------------------------------- 20 | 21 | // Forward declaration 22 | 23 | void 24 | _exit(int code); 25 | 26 | // ---------------------------------------------------------------------------- 27 | 28 | // On Release, call the hardware reset procedure. 29 | // On Debug we just enter an infinite loop, to be used as landmark when halting 30 | // the debugger. 31 | // 32 | // It can be redefined in the application, if more functionality 33 | // is required. 34 | 35 | void 36 | __attribute__((weak)) 37 | _exit(int code __attribute__((unused))) 38 | { 39 | #if !defined(DEBUG) 40 | __reset_hardware(); 41 | #endif 42 | 43 | // TODO: write on trace 44 | while (1) 45 | ; 46 | } 47 | 48 | // ---------------------------------------------------------------------------- 49 | 50 | void 51 | __attribute__((weak,noreturn)) 52 | abort(void) 53 | { 54 | trace_puts("abort(), exiting..."); 55 | 56 | _exit(1); 57 | } 58 | 59 | // ---------------------------------------------------------------------------- 60 | -------------------------------------------------------------------------------- /libs/STM32_HAL/src/newlib/_sbrk.c: -------------------------------------------------------------------------------- 1 | // 2 | // This file is part of the µOS++ III distribution. 3 | // Copyright (c) 2014 Liviu Ionescu. 4 | // 5 | 6 | // ---------------------------------------------------------------------------- 7 | 8 | #include 9 | #include 10 | 11 | // ---------------------------------------------------------------------------- 12 | 13 | caddr_t 14 | _sbrk(int incr); 15 | 16 | // ---------------------------------------------------------------------------- 17 | 18 | // The definitions used here should be kept in sync with the 19 | // stack definitions in the linker script. 20 | 21 | caddr_t 22 | _sbrk(int incr) 23 | { 24 | extern char _Heap_Begin; // Defined by the linker. 25 | extern char _Heap_Limit; // Defined by the linker. 26 | 27 | static char* current_heap_end; 28 | char* current_block_address; 29 | 30 | if (current_heap_end == 0) 31 | { 32 | current_heap_end = &_Heap_Begin; 33 | } 34 | 35 | current_block_address = current_heap_end; 36 | 37 | // Need to align heap to word boundary, else will get 38 | // hard faults on Cortex-M0. So we assume that heap starts on 39 | // word boundary, hence make sure we always add a multiple of 40 | // 4 to it. 41 | incr = (incr + 3) & (~3); // align value to 4 42 | if (current_heap_end + incr > &_Heap_Limit) 43 | { 44 | // Some of the libstdc++-v3 tests rely upon detecting 45 | // out of memory errors, so do not abort here. 46 | #if 0 47 | extern void abort (void); 48 | 49 | _write (1, "_sbrk: Heap and stack collision\n", 32); 50 | 51 | abort (); 52 | #else 53 | // Heap has overflowed 54 | errno = ENOMEM; 55 | return (caddr_t) - 1; 56 | #endif 57 | } 58 | 59 | current_heap_end += incr; 60 | 61 | return (caddr_t) current_block_address; 62 | } 63 | 64 | // ---------------------------------------------------------------------------- 65 | 66 | -------------------------------------------------------------------------------- /libs/STM32_HAL/src/newlib/assert.c: -------------------------------------------------------------------------------- 1 | // 2 | // This file is part of the µOS++ III distribution. 3 | // Copyright (c) 2014 Liviu Ionescu. 4 | // 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "diag/Trace.h" 11 | 12 | // ---------------------------------------------------------------------------- 13 | 14 | void 15 | __attribute__((noreturn)) 16 | __assert_func (const char *file, int line, const char *func, 17 | const char *failedexpr) 18 | { 19 | trace_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s\n", 20 | failedexpr, file, line, func ? ", function: " : "", 21 | func ? func : ""); 22 | abort (); 23 | /* NOTREACHED */ 24 | } 25 | 26 | // ---------------------------------------------------------------------------- 27 | 28 | // This is STM32 specific, but can be used on other platforms too. 29 | // If you need it, add the following to your application header: 30 | 31 | //#ifdef USE_FULL_ASSERT 32 | //#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 33 | //void assert_failed(uint8_t* file, uint32_t line); 34 | //#else 35 | //#define assert_param(expr) ((void)0) 36 | //#endif // USE_FULL_ASSERT 37 | 38 | #if defined(USE_FULL_ASSERT) 39 | 40 | void 41 | assert_failed (uint8_t* file, uint32_t line); 42 | 43 | // Called from the assert_param() macro, usually defined in the stm32f*_conf.h 44 | void 45 | __attribute__((noreturn, weak)) 46 | assert_failed (uint8_t* file, uint32_t line) 47 | { 48 | trace_printf ("assert_param() failed: file \"%s\", line %d\n", file, line); 49 | abort (); 50 | /* NOTREACHED */ 51 | } 52 | 53 | #endif // defined(USE_FULL_ASSERT) 54 | 55 | // ---------------------------------------------------------------------------- 56 | -------------------------------------------------------------------------------- /libs/STM32_HAL/src/stm32f0xx/stm32f0xx_hal_pcd_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_pcd_ex.c 4 | * @author MCD Application Team 5 | * @version V1.5.0 6 | * @date 04-November-2016 7 | * @brief Extended PCD HAL module driver. 8 | * This file provides firmware functions to manage the following 9 | * functionalities of the USB Peripheral Controller: 10 | * + Configuration of the PMA for EP 11 | * 12 | ****************************************************************************** 13 | * @attention 14 | * 15 | *

© COPYRIGHT(c) 2016 STMicroelectronics

16 | * 17 | * Redistribution and use in source and binary forms, with or without modification, 18 | * are permitted provided that the following conditions are met: 19 | * 1. Redistributions of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 25 | * may be used to endorse or promote products derived from this software 26 | * without specific prior written permission. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | ****************************************************************************** 40 | */ 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | #include "stm32f0xx_hal.h" 44 | 45 | #ifdef HAL_PCD_MODULE_ENABLED 46 | 47 | #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F070xB)|| defined(STM32F070x6) 48 | 49 | /** @addtogroup STM32F0xx_HAL_Driver 50 | * @{ 51 | */ 52 | 53 | /** @defgroup PCDEx PCDEx 54 | * @brief PCD Extended HAL module driver 55 | * @{ 56 | */ 57 | 58 | /* Private typedef -----------------------------------------------------------*/ 59 | /* Private define ------------------------------------------------------------*/ 60 | /* Private macro -------------------------------------------------------------*/ 61 | /* Private variables ---------------------------------------------------------*/ 62 | /* Private function prototypes -----------------------------------------------*/ 63 | /* Exported functions ---------------------------------------------------------*/ 64 | /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions 65 | * @{ 66 | */ 67 | 68 | /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 69 | * @brief PCDEx control functions 70 | * 71 | @verbatim 72 | =============================================================================== 73 | ##### Extended Peripheral Control functions ##### 74 | =============================================================================== 75 | [..] This section provides functions allowing to: 76 | (+) Update PMA configuration 77 | 78 | @endverbatim 79 | * @{ 80 | */ 81 | 82 | /** 83 | * @brief Configure PMA for EP 84 | * @param hpcd: PCD handle 85 | * @param ep_addr: endpoint address 86 | * @param ep_kind: endpoint Kind 87 | * @arg USB_SNG_BUF: Single Buffer used 88 | * @arg USB_DBL_BUF: Double Buffer used 89 | * @param pmaadress: EP address in The PMA: In case of single buffer endpoint 90 | * this parameter is 16-bit value providing the address 91 | * in PMA allocated to endpoint. 92 | * In case of double buffer endpoint this parameter 93 | * is a 32-bit value providing the endpoint buffer 0 address 94 | * in the LSB part of 32-bit value and endpoint buffer 1 address 95 | * in the MSB part of 32-bit value. 96 | * @retval : status 97 | */ 98 | 99 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, 100 | uint16_t ep_addr, 101 | uint16_t ep_kind, 102 | uint32_t pmaadress) 103 | 104 | { 105 | PCD_EPTypeDef *ep; 106 | 107 | /* initialize ep structure*/ 108 | if ((0x80U & ep_addr) == 0x80U) 109 | { 110 | ep = &hpcd->IN_ep[ep_addr & 0x7FU]; 111 | } 112 | else 113 | { 114 | ep = &hpcd->OUT_ep[ep_addr]; 115 | } 116 | 117 | /* Here we check if the endpoint is single or double Buffer*/ 118 | if (ep_kind == PCD_SNG_BUF) 119 | { 120 | /*Single Buffer*/ 121 | ep->doublebuffer = 0U; 122 | /*Configure the PMA*/ 123 | ep->pmaadress = (uint16_t)pmaadress; 124 | } 125 | else /*USB_DBL_BUF*/ 126 | { 127 | /*Double Buffer Endpoint*/ 128 | ep->doublebuffer = 1U; 129 | /*Configure the PMA*/ 130 | ep->pmaaddr0 = pmaadress & 0xFFFFU; 131 | ep->pmaaddr1 = (pmaadress & 0xFFFF0000U) >> 16U; 132 | } 133 | 134 | return HAL_OK; 135 | } 136 | /** 137 | * @} 138 | */ 139 | 140 | /** 141 | * @} 142 | */ 143 | 144 | /** 145 | * @} 146 | */ 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | #endif /* STM32F042x6 || STM32F072xB || STM32F078xx || STM32F070xB || STM32F070x6 */ 153 | 154 | #endif /* HAL_PCD_MODULE_ENABLED */ 155 | 156 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 157 | -------------------------------------------------------------------------------- /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 -Wno-unused-parameter) 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 -Wno-unused-parameter) 26 | target_link_libraries(STM32_USB_Device_Library_STM32F072xB PRIVATE STM32_HAL_STM32F072xB) 27 | -------------------------------------------------------------------------------- /libs/STM32_USB_Device_Library/Core/Inc/usbd_core.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_core.h 4 | * @author MCD Application Team 5 | * @version V2.4.2 6 | * @date 11-December-2015 7 | * @brief Header file for usbd_core.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

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

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USB_REQUEST_H 30 | #define __USB_REQUEST_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_def.h" 38 | 39 | 40 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBD_REQ 45 | * @brief header file for the usbd_req.c file 46 | * @{ 47 | */ 48 | 49 | /** @defgroup USBD_REQ_Exported_Defines 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | /** @defgroup USBD_REQ_Exported_Types 58 | * @{ 59 | */ 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | 66 | /** @defgroup USBD_REQ_Exported_Macros 67 | * @{ 68 | */ 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @defgroup USBD_REQ_Exported_Variables 74 | * @{ 75 | */ 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype 81 | * @{ 82 | */ 83 | 84 | USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 85 | USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 86 | USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 87 | 88 | 89 | void USBD_CtlError (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 90 | 91 | void USBD_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata); 92 | 93 | void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len); 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /* __USB_REQUEST_H */ 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | /** 109 | * @} 110 | */ 111 | 112 | 113 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 114 | -------------------------------------------------------------------------------- /libs/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.h 4 | * @author MCD Application Team 5 | * @version V2.4.2 6 | * @date 11-December-2015 7 | * @brief Header file for the usbd_ioreq.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USBD_IOREQ_H 30 | #define __USBD_IOREQ_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_def.h" 38 | #include "usbd_core.h" 39 | 40 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBD_IOREQ 45 | * @brief header file for the usbd_ioreq.c file 46 | * @{ 47 | */ 48 | 49 | /** @defgroup USBD_IOREQ_Exported_Defines 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | /** @defgroup USBD_IOREQ_Exported_Types 58 | * @{ 59 | */ 60 | 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | 67 | 68 | /** @defgroup USBD_IOREQ_Exported_Macros 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBD_IOREQ_Exported_Variables 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype 85 | * @{ 86 | */ 87 | 88 | USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, 89 | uint8_t *buf, 90 | uint16_t len); 91 | 92 | USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, 93 | uint8_t *pbuf, 94 | uint16_t len); 95 | 96 | USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, 97 | uint8_t *pbuf, 98 | uint16_t len); 99 | 100 | USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, 101 | uint8_t *pbuf, 102 | uint16_t len); 103 | 104 | USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev); 105 | 106 | USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev); 107 | 108 | uint16_t USBD_GetRxCount (USBD_HandleTypeDef *pdev , 109 | uint8_t epnum); 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif /* __USBD_IOREQ_H */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** 126 | * @} 127 | */ 128 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 129 | -------------------------------------------------------------------------------- /libs/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.c 4 | * @author MCD Application Team 5 | * @version V2.4.2 6 | * @date 11-December-2015 7 | * @brief This file provides the IO requests APIs for control endpoints. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_ioreq.h" 30 | 31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 32 | * @{ 33 | */ 34 | 35 | 36 | /** @defgroup USBD_IOREQ 37 | * @brief control I/O requests module 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_IOREQ_Private_TypesDefinitions 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_IOREQ_Private_Defines 50 | * @{ 51 | */ 52 | 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup USBD_IOREQ_Private_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | 66 | /** @defgroup USBD_IOREQ_Private_Variables 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | 75 | /** @defgroup USBD_IOREQ_Private_FunctionPrototypes 76 | * @{ 77 | */ 78 | /** 79 | * @} 80 | */ 81 | 82 | 83 | /** @defgroup USBD_IOREQ_Private_Functions 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @brief USBD_CtlSendData 89 | * send data on the ctl pipe 90 | * @param pdev: device instance 91 | * @param buff: pointer to data buffer 92 | * @param len: length of data to be sent 93 | * @retval status 94 | */ 95 | USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, 96 | uint8_t *pbuf, 97 | uint16_t len) 98 | { 99 | /* Set EP0 State */ 100 | pdev->ep0_state = USBD_EP0_DATA_IN; 101 | pdev->ep_in[0].total_length = len; 102 | pdev->ep_in[0].rem_length = len; 103 | /* Start the transfer */ 104 | USBD_LL_Transmit (pdev, 0x00, pbuf, len); 105 | 106 | return USBD_OK; 107 | } 108 | 109 | /** 110 | * @brief USBD_CtlContinueSendData 111 | * continue sending data on the ctl pipe 112 | * @param pdev: device instance 113 | * @param buff: pointer to data buffer 114 | * @param len: length of data to be sent 115 | * @retval status 116 | */ 117 | USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, 118 | uint8_t *pbuf, 119 | uint16_t len) 120 | { 121 | /* Start the next transfer */ 122 | USBD_LL_Transmit (pdev, 0x00, pbuf, len); 123 | 124 | return USBD_OK; 125 | } 126 | 127 | /** 128 | * @brief USBD_CtlPrepareRx 129 | * receive data on the ctl pipe 130 | * @param pdev: device instance 131 | * @param buff: pointer to data buffer 132 | * @param len: length of data to be received 133 | * @retval status 134 | */ 135 | USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, 136 | uint8_t *pbuf, 137 | uint16_t len) 138 | { 139 | /* Set EP0 State */ 140 | pdev->ep0_state = USBD_EP0_DATA_OUT; 141 | pdev->ep_out[0].total_length = len; 142 | pdev->ep_out[0].rem_length = len; 143 | /* Start the transfer */ 144 | USBD_LL_PrepareReceive (pdev, 145 | 0, 146 | pbuf, 147 | len); 148 | 149 | return USBD_OK; 150 | } 151 | 152 | /** 153 | * @brief USBD_CtlContinueRx 154 | * continue receive data on the ctl pipe 155 | * @param pdev: device instance 156 | * @param buff: pointer to data buffer 157 | * @param len: length of data to be received 158 | * @retval status 159 | */ 160 | USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, 161 | uint8_t *pbuf, 162 | uint16_t len) 163 | { 164 | 165 | USBD_LL_PrepareReceive (pdev, 166 | 0, 167 | pbuf, 168 | len); 169 | return USBD_OK; 170 | } 171 | /** 172 | * @brief USBD_CtlSendStatus 173 | * send zero lzngth packet on the ctl pipe 174 | * @param pdev: device instance 175 | * @retval status 176 | */ 177 | USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev) 178 | { 179 | 180 | /* Set EP0 State */ 181 | pdev->ep0_state = USBD_EP0_STATUS_IN; 182 | 183 | /* Start the transfer */ 184 | USBD_LL_Transmit (pdev, 0x00, NULL, 0); 185 | 186 | return USBD_OK; 187 | } 188 | 189 | /** 190 | * @brief USBD_CtlReceiveStatus 191 | * receive zero lzngth packet on the ctl pipe 192 | * @param pdev: device instance 193 | * @retval status 194 | */ 195 | USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev) 196 | { 197 | /* Set EP0 State */ 198 | pdev->ep0_state = USBD_EP0_STATUS_OUT; 199 | 200 | /* Start the transfer */ 201 | USBD_LL_PrepareReceive ( pdev, 202 | 0, 203 | NULL, 204 | 0); 205 | 206 | return USBD_OK; 207 | } 208 | 209 | 210 | /** 211 | * @brief USBD_GetRxCount 212 | * returns the received data length 213 | * @param pdev: device instance 214 | * @param ep_addr: endpoint address 215 | * @retval Rx Data blength 216 | */ 217 | uint16_t USBD_GetRxCount (USBD_HandleTypeDef *pdev , uint8_t ep_addr) 218 | { 219 | return USBD_LL_GetRxDataSize(pdev, ep_addr); 220 | } 221 | 222 | /** 223 | * @} 224 | */ 225 | 226 | 227 | /** 228 | * @} 229 | */ 230 | 231 | 232 | /** 233 | * @} 234 | */ 235 | 236 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 237 | -------------------------------------------------------------------------------- /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 "stm32f0xx_hal.h" 30 | 31 | #define USBD_MAX_NUM_INTERFACES 1 32 | #define USBD_MAX_NUM_CONFIGURATION 1 33 | #define USBD_MAX_STR_DESC_SIZ 512 34 | #define USBD_SUPPORT_USER_STRING 1 35 | #define USBD_SELF_POWERED 0 36 | #define DEVICE_FS 0 37 | 38 | #define USBD_ErrLog(...) 39 | -------------------------------------------------------------------------------- /src/can.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.h" 28 | 29 | void can_init(can_data_t *hcan, CAN_TypeDef *instance) 30 | { 31 | __HAL_RCC_CAN1_CLK_ENABLE(); 32 | 33 | GPIO_InitTypeDef itd; 34 | itd.Pin = GPIO_PIN_8|GPIO_PIN_9; 35 | itd.Mode = GPIO_MODE_AF_PP; 36 | itd.Pull = GPIO_NOPULL; 37 | itd.Speed = GPIO_SPEED_FREQ_HIGH; 38 | itd.Alternate = GPIO_AF4_CAN; 39 | HAL_GPIO_Init(GPIOB, &itd); 40 | 41 | hcan->instance = instance; 42 | hcan->brp = 6; 43 | hcan->phase_seg1 = 13; 44 | hcan->phase_seg2 = 2; 45 | hcan->sjw = 1; 46 | } 47 | 48 | bool can_set_bittiming(can_data_t *hcan, uint16_t brp, uint8_t phase_seg1, uint8_t phase_seg2, uint8_t sjw) 49 | { 50 | if ( (brp>0) && (brp<=1024) 51 | && (phase_seg1>0) && (phase_seg1<=16) 52 | && (phase_seg2>0) && (phase_seg2<=8) 53 | && (sjw>0) && (sjw<=4) 54 | ) { 55 | hcan->brp = brp & 0x3FF; 56 | hcan->phase_seg1 = phase_seg1; 57 | hcan->phase_seg2 = phase_seg2; 58 | hcan->sjw = sjw; 59 | return true; 60 | } else { 61 | return false; 62 | } 63 | } 64 | 65 | void can_enable(can_data_t *hcan, bool loop_back, bool listen_only, bool one_shot) 66 | { 67 | CAN_TypeDef *can = hcan->instance; 68 | 69 | uint32_t mcr = CAN_MCR_INRQ 70 | | CAN_MCR_ABOM 71 | | CAN_MCR_TXFP 72 | | (one_shot ? CAN_MCR_NART : 0); 73 | 74 | uint32_t btr = ((uint32_t)(hcan->sjw-1)) << 24 75 | | ((uint32_t)(hcan->phase_seg1-1)) << 16 76 | | ((uint32_t)(hcan->phase_seg2-1)) << 20 77 | | (hcan->brp - 1) 78 | | (loop_back ? CAN_MODE_LOOPBACK : 0) 79 | | (listen_only ? CAN_MODE_SILENT : 0); 80 | 81 | 82 | // Reset CAN peripheral 83 | can->MCR |= CAN_MCR_RESET; 84 | while((can->MCR & CAN_MCR_RESET) != 0); // reset bit is set to zero after reset 85 | while((can->MSR & CAN_MSR_SLAK) == 0); // should be in sleep mode after reset 86 | 87 | can->MCR |= CAN_MCR_INRQ ; 88 | while((can->MSR & CAN_MSR_INAK) == 0); 89 | 90 | can->MCR = mcr; 91 | can->BTR = btr; 92 | 93 | can->MCR &= ~CAN_MCR_INRQ; 94 | while((can->MSR & CAN_MSR_INAK) != 0); 95 | 96 | uint32_t filter_bit = 0x00000001; 97 | can->FMR |= CAN_FMR_FINIT; 98 | can->FMR &= ~CAN_FMR_CAN2SB; 99 | can->FA1R &= ~filter_bit; // disable filter 100 | can->FS1R |= filter_bit; // set to single 32-bit filter mode 101 | can->FM1R &= ~filter_bit; // set filter mask mode for filter 0 102 | can->sFilterRegister[0].FR1 = 0; // filter ID = 0 103 | can->sFilterRegister[0].FR2 = 0; // filter Mask = 0 104 | can->FFA1R &= ~filter_bit; // assign filter 0 to FIFO 0 105 | can->FA1R |= filter_bit; // enable filter 106 | can->FMR &= ~CAN_FMR_FINIT; 107 | } 108 | 109 | void can_disable(can_data_t *hcan) 110 | { 111 | CAN_TypeDef *can = hcan->instance; 112 | can->MCR |= CAN_MCR_INRQ ; // send can controller into initialization mode 113 | } 114 | 115 | bool can_is_enabled(can_data_t *hcan) 116 | { 117 | CAN_TypeDef *can = hcan->instance; 118 | return (can->MCR & CAN_MCR_INRQ) == 0; 119 | } 120 | 121 | bool can_is_rx_pending(can_data_t *hcan) 122 | { 123 | CAN_TypeDef *can = hcan->instance; 124 | return ((can->RF0R & CAN_RF0R_FMP0) != 0); 125 | } 126 | 127 | bool can_receive(can_data_t *hcan, struct gs_host_frame *rx_frame) 128 | { 129 | CAN_TypeDef *can = hcan->instance; 130 | 131 | if (can_is_rx_pending(hcan)) { 132 | CAN_FIFOMailBox_TypeDef *fifo = &can->sFIFOMailBox[0]; 133 | 134 | if (fifo->RIR & CAN_RI0R_IDE) { 135 | rx_frame->can_id = CAN_EFF_FLAG | ((fifo->RIR >> 3) & 0x1FFFFFFF); 136 | } else { 137 | rx_frame->can_id = (fifo->RIR >> 21) & 0x7FF; 138 | } 139 | 140 | if (fifo->RIR & CAN_RI0R_RTR) { 141 | rx_frame->can_id |= CAN_RTR_FLAG; 142 | } 143 | 144 | rx_frame->can_dlc = fifo->RDTR & CAN_RDT0R_DLC; 145 | 146 | rx_frame->data[0] = (fifo->RDLR >> 0) & 0xFF; 147 | rx_frame->data[1] = (fifo->RDLR >> 8) & 0xFF; 148 | rx_frame->data[2] = (fifo->RDLR >> 16) & 0xFF; 149 | rx_frame->data[3] = (fifo->RDLR >> 24) & 0xFF; 150 | rx_frame->data[4] = (fifo->RDHR >> 0) & 0xFF; 151 | rx_frame->data[5] = (fifo->RDHR >> 8) & 0xFF; 152 | rx_frame->data[6] = (fifo->RDHR >> 16) & 0xFF; 153 | rx_frame->data[7] = (fifo->RDHR >> 24) & 0xFF; 154 | 155 | can->RF0R |= CAN_RF0R_RFOM0; // release FIFO 156 | 157 | return true; 158 | } else { 159 | return false; 160 | } 161 | } 162 | 163 | static CAN_TxMailBox_TypeDef *can_find_free_mailbox(can_data_t *hcan) 164 | { 165 | CAN_TypeDef *can = hcan->instance; 166 | 167 | uint32_t tsr = can->TSR; 168 | if ( tsr & CAN_TSR_TME0 ) { 169 | return &can->sTxMailBox[0]; 170 | } else if ( tsr & CAN_TSR_TME1 ) { 171 | return &can->sTxMailBox[1]; 172 | } else if ( tsr & CAN_TSR_TME2 ) { 173 | return &can->sTxMailBox[2]; 174 | } else { 175 | return 0; 176 | } 177 | } 178 | 179 | bool can_send(can_data_t *hcan, struct gs_host_frame *frame) 180 | { 181 | CAN_TxMailBox_TypeDef *mb = can_find_free_mailbox(hcan); 182 | if (mb != 0) { 183 | 184 | /* first, clear transmission request */ 185 | mb->TIR &= CAN_TI0R_TXRQ; 186 | 187 | if (frame->can_id & CAN_EFF_FLAG) { // extended id 188 | mb->TIR = CAN_ID_EXT | (frame->can_id & 0x1FFFFFFF) << 3; 189 | } else { 190 | mb->TIR = (frame->can_id & 0x7FF) << 21; 191 | } 192 | 193 | if (frame->can_id & CAN_RTR_FLAG) { 194 | mb->TIR |= CAN_RTR_REMOTE; 195 | } 196 | 197 | mb->TDTR &= 0xFFFFFFF0; 198 | mb->TDTR |= frame->can_dlc & 0x0F; 199 | 200 | mb->TDLR = 201 | ( frame->data[3] << 24 ) 202 | | ( frame->data[2] << 16 ) 203 | | ( frame->data[1] << 8 ) 204 | | ( frame->data[0] << 0 ); 205 | 206 | mb->TDHR = 207 | ( frame->data[7] << 24 ) 208 | | ( frame->data[6] << 16 ) 209 | | ( frame->data[5] << 8 ) 210 | | ( frame->data[4] << 0 ); 211 | 212 | /* request transmission */ 213 | mb->TIR |= CAN_TI0R_TXRQ; 214 | 215 | return true; 216 | } else { 217 | return false; 218 | } 219 | } 220 | 221 | uint32_t can_get_error_status(can_data_t *hcan) 222 | { 223 | CAN_TypeDef *can = hcan->instance; 224 | return can->ESR; 225 | } 226 | 227 | bool can_parse_error_status(uint32_t err, struct gs_host_frame *frame) 228 | { 229 | frame->echo_id = 0xFFFFFFFF; 230 | frame->can_id = CAN_ERR_FLAG | CAN_ERR_CRTL; 231 | frame->can_dlc = CAN_ERR_DLC; 232 | frame->data[0] = CAN_ERR_LOSTARB_UNSPEC; 233 | frame->data[1] = CAN_ERR_CRTL_UNSPEC; 234 | frame->data[2] = CAN_ERR_PROT_UNSPEC; 235 | frame->data[3] = CAN_ERR_PROT_LOC_UNSPEC; 236 | frame->data[4] = CAN_ERR_TRX_UNSPEC; 237 | frame->data[5] = 0; 238 | frame->data[6] = 0; 239 | frame->data[7] = 0; 240 | 241 | if ((err & CAN_ESR_BOFF) != 0) { 242 | frame->can_id |= CAN_ERR_BUSOFF; 243 | } 244 | 245 | /* 246 | uint8_t tx_error_cnt = (err>>16) & 0xFF; 247 | uint8_t rx_error_cnt = (err>>24) & 0xFF; 248 | */ 249 | 250 | if (err & CAN_ESR_EPVF) { 251 | frame->data[1] |= CAN_ERR_CRTL_RX_PASSIVE | CAN_ERR_CRTL_TX_PASSIVE; 252 | } else if (err & CAN_ESR_EWGF) { 253 | frame->data[1] |= CAN_ERR_CRTL_RX_WARNING | CAN_ERR_CRTL_TX_WARNING; 254 | } 255 | 256 | uint8_t lec = (err>>4) & 0x07; 257 | if (lec!=0) { /* protocol error */ 258 | switch (lec) { 259 | case 0x01: /* stuff error */ 260 | frame->can_id |= CAN_ERR_PROT; 261 | frame->data[2] |= CAN_ERR_PROT_STUFF; 262 | break; 263 | case 0x02: /* form error */ 264 | frame->can_id |= CAN_ERR_PROT; 265 | frame->data[2] |= CAN_ERR_PROT_FORM; 266 | break; 267 | case 0x03: /* ack error */ 268 | frame->can_id |= CAN_ERR_ACK; 269 | break; 270 | case 0x04: /* bit recessive error */ 271 | frame->can_id |= CAN_ERR_PROT; 272 | frame->data[2] |= CAN_ERR_PROT_BIT1; 273 | break; 274 | case 0x05: /* bit dominant error */ 275 | frame->can_id |= CAN_ERR_PROT; 276 | frame->data[2] |= CAN_ERR_PROT_BIT0; 277 | break; 278 | case 0x06: /* CRC error */ 279 | frame->can_id |= CAN_ERR_PROT; 280 | frame->data[3] |= CAN_ERR_PROT_LOC_CRC_SEQ; 281 | break; 282 | default: 283 | break; 284 | } 285 | } 286 | 287 | return true; 288 | } 289 | -------------------------------------------------------------------------------- /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 "stm32f0xx_hal.h" 30 | 31 | #define RESET_TO_BOOTLOADER_MAGIC_CODE 0xDEADBEEF 32 | 33 | #define SYSMEM_STM32F042 0x1FFFC400 34 | #define SYSMEM_STM32F072 0x1FFFC800 35 | 36 | static uint32_t dfu_reset_to_bootloader_magic; 37 | 38 | static void dfu_hack_boot_pin_f042(); 39 | static void dfu_jump_to_bootloader(); 40 | 41 | void dfu_run_bootloader() 42 | { 43 | dfu_reset_to_bootloader_magic = RESET_TO_BOOTLOADER_MAGIC_CODE; 44 | NVIC_SystemReset(); 45 | } 46 | 47 | void __initialize_hardware_early(void) 48 | { 49 | if (dfu_reset_to_bootloader_magic == RESET_TO_BOOTLOADER_MAGIC_CODE) 50 | { 51 | switch (HAL_GetDEVID()) 52 | { 53 | 54 | case 0x445: // STM32F04x 55 | dfu_hack_boot_pin_f042(); 56 | dfu_jump_to_bootloader(SYSMEM_STM32F042); 57 | break; 58 | 59 | case 0x448: // STM32F07x 60 | dfu_jump_to_bootloader(SYSMEM_STM32F072); 61 | break; 62 | 63 | } 64 | } 65 | 66 | SystemInit(); 67 | } 68 | 69 | static void dfu_hack_boot_pin_f042() 70 | { 71 | __HAL_RCC_GPIOF_CLK_ENABLE(); 72 | GPIO_InitTypeDef GPIO_InitStruct; 73 | GPIO_InitStruct.Pin = GPIO_PIN_11; 74 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 75 | GPIO_InitStruct.Pull = GPIO_PULLUP; 76 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 77 | HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); 78 | HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, 1); 79 | } 80 | 81 | static void dfu_jump_to_bootloader(uint32_t sysmem_base) 82 | { 83 | void (*bootloader)(void) = (void (*)(void)) (*((uint32_t *) (sysmem_base + 4))); 84 | 85 | __set_MSP(*(__IO uint32_t*) sysmem_base); 86 | bootloader(); 87 | 88 | while (42) 89 | { 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/flash.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 | 28 | #include "flash.h" 29 | #include 30 | #include "stm32f0xx_hal_flash.h" 31 | 32 | #define NUM_CHANNEL 1 33 | 34 | typedef struct { 35 | uint32_t user_id[NUM_CHANNEL]; 36 | } flash_data_t; 37 | 38 | static flash_data_t flash_data_ram; 39 | __attribute__((__section__(".user_data"))) const flash_data_t flash_data_rom; 40 | 41 | 42 | void flash_load() 43 | { 44 | memcpy(&flash_data_ram, &flash_data_rom, sizeof(flash_data_t)); 45 | } 46 | 47 | bool flash_set_user_id(uint8_t channel, uint32_t user_id) 48 | { 49 | if (channel 29 | #include "stm32f0xx_hal.h" 30 | #include "stm32f0xx_hal_gpio.h" 31 | 32 | void led_init( 33 | led_data_t *leds, 34 | void* led1_port, uint16_t led1_pin, bool led1_active_high, 35 | void* led2_port, uint16_t led2_pin, bool led2_active_high 36 | ) { 37 | memset(leds, 0, sizeof(led_data_t)); 38 | leds->led_state[0].port = led1_port; 39 | leds->led_state[0].pin = led1_pin; 40 | leds->led_state[0].is_active_high = led1_active_high; 41 | leds->led_state[1].port = led2_port; 42 | leds->led_state[1].pin = led2_pin; 43 | leds->led_state[1].is_active_high = led2_active_high; 44 | } 45 | 46 | void led_set_mode(led_data_t *leds,led_mode_t mode) 47 | { 48 | leds->mode = mode; 49 | led_update(leds); 50 | } 51 | 52 | static void led_set(led_state_t *led, bool state) 53 | { 54 | if (!led->is_active_high) { 55 | state = !state; 56 | } 57 | 58 | HAL_GPIO_WritePin(led->port, led->pin, state ? GPIO_PIN_SET : GPIO_PIN_RESET); 59 | } 60 | 61 | static uint32_t led_set_sequence_step(led_data_t *leds, uint32_t step_num) 62 | { 63 | led_seq_step_t *step = &leds->sequence[step_num]; 64 | leds->sequence_step = step_num; 65 | led_set(&leds->led_state[0], step->state & 0x01); 66 | led_set(&leds->led_state[1], step->state & 0x02); 67 | leds->t_sequence_next = HAL_GetTick() + 10*step->time_in_10ms; 68 | return 10 * step->time_in_10ms; 69 | } 70 | 71 | void led_run_sequence(led_data_t *leds, led_seq_step_t *sequence, int32_t num_repeat) 72 | { 73 | leds->last_mode = leds->mode; 74 | leds->mode = led_mode_sequence; 75 | leds->sequence = sequence; 76 | leds->seq_num_repeat = num_repeat; 77 | led_set_sequence_step(leds, 0); 78 | led_update(leds); 79 | } 80 | 81 | void led_indicate_trx(led_data_t *leds, led_num_t num) 82 | { 83 | uint32_t now = HAL_GetTick(); 84 | led_state_t *led = &leds->led_state[num]; 85 | 86 | if ( (led->on_until < now) && (led->off_until < now) ) { 87 | led->off_until = now + 30; 88 | led->on_until = now + 45; 89 | } 90 | 91 | led_update(leds); 92 | } 93 | 94 | static void led_update_normal_mode(led_state_t *led) 95 | { 96 | uint32_t now = HAL_GetTick(); 97 | led_set(led, led->off_until < now); 98 | } 99 | 100 | static void led_update_sequence(led_data_t *leds) 101 | { 102 | if (leds->sequence == NULL) { 103 | return; 104 | } 105 | 106 | uint32_t now = HAL_GetTick(); 107 | if (now > leds->t_sequence_next) { 108 | 109 | uint32_t t = led_set_sequence_step(leds, ++leds->sequence_step); 110 | 111 | if (t > 0) { // the saga continues 112 | 113 | leds->t_sequence_next = now + t; 114 | 115 | } else { // end of sequence 116 | 117 | if (leds->seq_num_repeat != 0) { 118 | 119 | if (leds->seq_num_repeat > 0) { 120 | leds->seq_num_repeat--; 121 | } 122 | 123 | led_set_sequence_step(leds, 0); 124 | 125 | } else { 126 | leds->sequence = NULL; 127 | } 128 | } 129 | } 130 | } 131 | 132 | void led_update(led_data_t *leds) 133 | { 134 | switch (leds->mode) { 135 | 136 | case led_mode_off: 137 | led_set(&leds->led_state[0], false); 138 | led_set(&leds->led_state[1], false); 139 | break; 140 | 141 | case led_mode_normal: 142 | led_update_normal_mode(&leds->led_state[0]); 143 | led_update_normal_mode(&leds->led_state[1]); 144 | break; 145 | 146 | case led_mode_sequence: 147 | led_update_sequence(leds); 148 | break; 149 | 150 | default: 151 | led_set(&leds->led_state[0], false); 152 | led_set(&leds->led_state[1], true); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /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 | 30 | #include "config.h" 31 | #include "stm32f0xx_hal.h" 32 | #include "usbd_def.h" 33 | #include "usbd_desc.h" 34 | #include "usbd_core.h" 35 | #include "usbd_gs_can.h" 36 | #include "gpio.h" 37 | #include "queue.h" 38 | #include "gs_usb.h" 39 | #include "can.h" 40 | #include "led.h" 41 | #include "dfu.h" 42 | #include "timer.h" 43 | #include "flash.h" 44 | 45 | void HAL_MspInit(void); 46 | void SystemClock_Config(void); 47 | static bool send_to_host_or_enqueue(struct gs_host_frame *frame); 48 | static void send_to_host(); 49 | 50 | can_data_t hCAN; 51 | USBD_HandleTypeDef hUSB; 52 | led_data_t hLED; 53 | 54 | queue_t *q_frame_pool; 55 | queue_t *q_from_host; 56 | queue_t *q_to_host; 57 | 58 | uint32_t received_count=0; 59 | 60 | 61 | int main(void) 62 | { 63 | uint32_t last_can_error_status = 0; 64 | 65 | HAL_Init(); 66 | SystemClock_Config(); 67 | 68 | flash_load(); 69 | 70 | gpio_init(); 71 | 72 | led_init(&hLED, LED1_GPIO_Port, LED1_Pin, LED1_Active_High, LED2_GPIO_Port, LED2_Pin, LED2_Active_High); 73 | led_set_mode(&hLED, led_mode_off); 74 | timer_init(); 75 | 76 | can_init(&hCAN, CAN); 77 | can_disable(&hCAN); 78 | 79 | 80 | q_frame_pool = queue_create(CAN_QUEUE_SIZE); 81 | q_from_host = queue_create(CAN_QUEUE_SIZE); 82 | q_to_host = queue_create(CAN_QUEUE_SIZE); 83 | 84 | struct gs_host_frame *msgbuf = calloc(CAN_QUEUE_SIZE, sizeof(struct gs_host_frame)); 85 | for (unsigned i=0; itimestamp_us = timer_get(); 105 | send_to_host_or_enqueue(frame); 106 | 107 | led_indicate_trx(&hLED, led_2); 108 | } else { 109 | queue_push_front(q_from_host, frame); // retry later 110 | } 111 | } 112 | 113 | if (USBD_GS_CAN_TxReady(&hUSB)) { 114 | send_to_host(); 115 | } 116 | 117 | if (can_is_rx_pending(&hCAN)) { 118 | struct gs_host_frame *frame = queue_pop_front(q_frame_pool); 119 | if (frame != 0) 120 | { 121 | if (can_receive(&hCAN, frame)) { 122 | received_count++; 123 | 124 | frame->timestamp_us = timer_get(); 125 | frame->echo_id = 0xFFFFFFFF; // not a echo frame 126 | frame->channel = 0; 127 | frame->flags = 0; 128 | frame->reserved = 0; 129 | 130 | send_to_host_or_enqueue(frame); 131 | 132 | led_indicate_trx(&hLED, led_1); 133 | } 134 | else 135 | { 136 | queue_push_back(q_frame_pool, frame); 137 | } 138 | } 139 | } 140 | 141 | uint32_t can_err = can_get_error_status(&hCAN); 142 | if (can_err != last_can_error_status) { 143 | struct gs_host_frame *frame = queue_pop_front(q_frame_pool); 144 | if (frame != 0) { 145 | frame->timestamp_us = timer_get(); 146 | if (can_parse_error_status(can_err, frame)) { 147 | send_to_host_or_enqueue(frame); 148 | last_can_error_status = can_err; 149 | } else { 150 | queue_push_back(q_frame_pool, frame); 151 | } 152 | 153 | } 154 | } 155 | 156 | led_update(&hLED); 157 | 158 | if (USBD_GS_CAN_DfuDetachRequested(&hUSB)) { 159 | dfu_run_bootloader(); 160 | } 161 | 162 | } 163 | } 164 | 165 | void HAL_MspInit(void) 166 | { 167 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 168 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 169 | } 170 | 171 | void SystemClock_Config(void) 172 | { 173 | RCC_OscInitTypeDef RCC_OscInitStruct; 174 | RCC_ClkInitTypeDef RCC_ClkInitStruct; 175 | RCC_PeriphCLKInitTypeDef PeriphClkInit; 176 | RCC_CRSInitTypeDef RCC_CRSInitStruct; 177 | 178 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48; 179 | RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; 180 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; 181 | HAL_RCC_OscConfig(&RCC_OscInitStruct); 182 | 183 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 184 | |RCC_CLOCKTYPE_PCLK1; 185 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48; 186 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 187 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 188 | HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1); 189 | 190 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; 191 | PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; 192 | HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); 193 | 194 | __HAL_RCC_CRS_CLK_ENABLE(); 195 | 196 | RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1; 197 | RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB; 198 | RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING; 199 | RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000,1000); 200 | RCC_CRSInitStruct.ErrorLimitValue = 34; 201 | RCC_CRSInitStruct.HSI48CalibrationValue = 32; 202 | HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct); 203 | 204 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); 205 | 206 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); 207 | 208 | /* SysTick_IRQn interrupt configuration */ 209 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 210 | } 211 | 212 | bool send_to_host_or_enqueue(struct gs_host_frame *frame) 213 | { 214 | if (USBD_GS_CAN_GetProtocolVersion(&hUSB) == 2) { 215 | queue_push_back(q_to_host, frame); 216 | return true; 217 | 218 | } else { 219 | bool retval = false; 220 | if ( USBD_GS_CAN_SendFrame(&hUSB, frame) == USBD_OK ) { 221 | queue_push_back(q_frame_pool, frame); 222 | retval = true; 223 | } else { 224 | queue_push_back(q_to_host, frame); 225 | } 226 | return retval; 227 | } 228 | } 229 | 230 | void send_to_host() 231 | { 232 | struct gs_host_frame *frame = queue_pop_front(q_to_host); 233 | 234 | if(!frame) 235 | return; 236 | 237 | if (USBD_GS_CAN_SendFrame(&hUSB, frame) == USBD_OK) { 238 | queue_push_back(q_frame_pool, frame); 239 | } else { 240 | queue_push_front(q_to_host, frame); 241 | } 242 | } 243 | 244 | -------------------------------------------------------------------------------- /src/queue.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 | queue_t *queue_create(unsigned max_elements){ 31 | queue_t *q = calloc(1, sizeof(queue_t)); 32 | q->buf = calloc(max_elements, sizeof(void*)); 33 | q->max_elements = max_elements; 34 | return q; 35 | } 36 | 37 | void queue_destroy(queue_t *q) 38 | { 39 | free(q->buf); 40 | free(q); 41 | } 42 | 43 | unsigned queue_size(queue_t *q) 44 | { 45 | int primask = disable_irq(); 46 | unsigned retval = q->size; 47 | enable_irq(primask); 48 | return retval; 49 | } 50 | 51 | bool queue_is_empty(queue_t *q) 52 | { 53 | return queue_size(q)==0; 54 | } 55 | 56 | bool queue_push_back(queue_t *q, void *el) 57 | { 58 | bool retval = false; 59 | int primask = disable_irq(); 60 | 61 | if (q->size < q->max_elements) { 62 | unsigned pos = (q->first + q->size) % q->max_elements; 63 | q->buf[pos] = el; 64 | q->size += 1; 65 | retval = true; 66 | } 67 | 68 | enable_irq(primask); 69 | return retval; 70 | } 71 | 72 | bool queue_push_front(queue_t *q, void *el) 73 | { 74 | bool retval = false; 75 | int primask = disable_irq(); 76 | if (q->size < q->max_elements) { 77 | if (q->first==0) { 78 | q->first = q->max_elements - 1; 79 | } else { 80 | q->first = q->first - 1; 81 | } 82 | q->buf[q->first] = el; 83 | q->size += 1; 84 | retval = true; 85 | } 86 | enable_irq(primask); 87 | return retval; 88 | } 89 | 90 | void *queue_pop_front(queue_t *q) 91 | { 92 | int primask = disable_irq(); 93 | void *el = 0; 94 | if (q->size > 0) { 95 | el = q->buf[q->first]; 96 | q->first = (q->first + 1) % q->max_elements; 97 | q->size -= 1; 98 | } 99 | enable_irq(primask); 100 | return el; 101 | } 102 | 103 | unsigned queue_size_i(queue_t *q) 104 | { 105 | return q->size; 106 | } 107 | 108 | bool queue_is_empty_i(queue_t *q) 109 | { 110 | return queue_size_i(q)==0; 111 | } 112 | 113 | bool queue_push_back_i(queue_t *q, void *el) 114 | { 115 | bool retval = false; 116 | 117 | if (q->size < q->max_elements) { 118 | unsigned pos = (q->first + q->size) % q->max_elements; 119 | q->buf[pos] = el; 120 | q->size += 1; 121 | retval = true; 122 | } 123 | 124 | return retval; 125 | } 126 | 127 | bool queue_push_front_i(queue_t *q, void *el) 128 | { 129 | bool retval = false; 130 | if (q->size < q->max_elements) { 131 | if (q->first==0) { 132 | q->first = q->max_elements - 1; 133 | } else { 134 | q->first = q->first - 1; 135 | } 136 | q->buf[q->first] = el; 137 | q->size += 1; 138 | retval = true; 139 | } 140 | return retval; 141 | } 142 | 143 | void *queue_pop_front_i(queue_t *q) 144 | { 145 | void *el = 0; 146 | if (q->size > 0) { 147 | el = q->buf[q->first]; 148 | q->first = (q->first + 1) % q->max_elements; 149 | q->size -= 1; 150 | } 151 | return el; 152 | } 153 | -------------------------------------------------------------------------------- /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 "timer.h" 28 | #include "stm32f0xx_hal.h" 29 | 30 | void timer_init() 31 | { 32 | __HAL_RCC_TIM2_CLK_ENABLE(); 33 | 34 | TIM2->CR1 = 0; 35 | TIM2->CR2 = 0; 36 | TIM2->SMCR = 0; 37 | TIM2->DIER = 0; 38 | TIM2->CCMR1 = 0; 39 | TIM2->CCMR2 = 0; 40 | TIM2->CCER = 0; 41 | TIM2->PSC = 48-1; // run @48MHz/480 = 1MHz = 1us 42 | TIM2->ARR = 0xFFFFFFFF; 43 | TIM2->CR1 |= TIM_CR1_CEN; 44 | TIM2->EGR = TIM_EGR_UG; 45 | } 46 | 47 | uint32_t timer_get() 48 | { 49 | return TIM2->CNT; 50 | } 51 | -------------------------------------------------------------------------------- /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 "usbd_core.h" 29 | #include "usbd_gs_can.h" 30 | 31 | PCD_HandleTypeDef hpcd_USB_FS; 32 | 33 | void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd) 34 | { 35 | if(hpcd->Instance==USB) { 36 | __HAL_RCC_USB_CLK_ENABLE(); 37 | HAL_NVIC_SetPriority(USB_IRQn, 1, 0); 38 | HAL_NVIC_EnableIRQ(USB_IRQn); 39 | } 40 | } 41 | 42 | void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd) 43 | { 44 | if(hpcd->Instance==USB) { 45 | __HAL_RCC_USB_CLK_DISABLE(); 46 | HAL_NVIC_DisableIRQ(USB_IRQn); 47 | } 48 | } 49 | 50 | void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) 51 | { 52 | USBD_HandleTypeDef *pdev = (USBD_HandleTypeDef*)hpcd->pData; 53 | USBD_ParseSetupRequest((USBD_SetupReqTypedef*)&pdev->request, (uint8_t*)hpcd->Setup); 54 | 55 | bool request_was_handled = false; 56 | 57 | if ((pdev->request.bmRequest & 0x1F) == USB_REQ_RECIPIENT_DEVICE ) { // device request 58 | request_was_handled = USBD_GS_CAN_CustomDeviceRequest(pdev, &pdev->request); 59 | } 60 | 61 | if ((pdev->request.bmRequest & 0x1F) == USB_REQ_RECIPIENT_INTERFACE ) { // interface request 62 | request_was_handled = USBD_GS_CAN_CustomInterfaceRequest(pdev, &pdev->request); 63 | } 64 | 65 | if (!request_was_handled) { 66 | USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); 67 | } 68 | } 69 | 70 | void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) 71 | { 72 | USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); 73 | } 74 | 75 | void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) 76 | { 77 | USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); 78 | } 79 | 80 | void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) 81 | { 82 | USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); 83 | } 84 | 85 | void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) 86 | { 87 | USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, USBD_SPEED_FULL); 88 | USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); 89 | } 90 | 91 | void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) 92 | { 93 | USBD_GS_CAN_SuspendCallback((USBD_HandleTypeDef*)hpcd->pData); 94 | USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); 95 | } 96 | 97 | void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) 98 | { 99 | USBD_LL_Resume((USBD_HandleTypeDef*) hpcd->pData); 100 | } 101 | 102 | USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) 103 | { 104 | /* Init USB_IP */ 105 | /* Link The driver to the stack */ 106 | hpcd_USB_FS.pData = pdev; 107 | pdev->pData = &hpcd_USB_FS; 108 | 109 | hpcd_USB_FS.Instance = USB; 110 | hpcd_USB_FS.Init.dev_endpoints = 5; 111 | hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; 112 | hpcd_USB_FS.Init.ep0_mps = DEP0CTL_MPS_64; 113 | hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED; 114 | hpcd_USB_FS.Init.low_power_enable = DISABLE; 115 | hpcd_USB_FS.Init.lpm_enable = DISABLE; 116 | HAL_PCD_Init(&hpcd_USB_FS); 117 | 118 | /* 119 | * PMA layout 120 | * 0x00 - 0x17 (24 bytes) metadata? 121 | * 0x18 - 0x57 (64 bytes) EP0 OUT 122 | * 0x58 - 0x97 (64 bytes) EP0 IN 123 | * 0x98 - 0xD7 (64 bytes) EP1 IN 124 | * 0xD8 - 0x157 (128 bytes) EP1 OUT (buffer 1) 125 | * 0x158 - 0x1D7 (128 bytes) EP1 OUT (buffer 2) 126 | */ 127 | HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 24); 128 | HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); 129 | HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0x98); 130 | HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x02 , PCD_DBL_BUF, 0x00D80158); 131 | 132 | return USBD_OK; 133 | } 134 | 135 | USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) 136 | { 137 | HAL_PCD_DeInit((PCD_HandleTypeDef*)pdev->pData); 138 | return USBD_OK; 139 | } 140 | 141 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) 142 | { 143 | HAL_PCD_Start((PCD_HandleTypeDef*)pdev->pData); 144 | return USBD_OK; 145 | } 146 | 147 | USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev) 148 | { 149 | HAL_PCD_Stop((PCD_HandleTypeDef*) pdev->pData); 150 | return USBD_OK; 151 | } 152 | 153 | USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) 154 | { 155 | HAL_PCD_EP_Open((PCD_HandleTypeDef*) pdev->pData, ep_addr, ep_mps, ep_type); 156 | return USBD_OK; 157 | } 158 | 159 | USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 160 | { 161 | HAL_PCD_EP_Close((PCD_HandleTypeDef*) pdev->pData, ep_addr); 162 | return USBD_OK; 163 | } 164 | 165 | USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 166 | { 167 | HAL_PCD_EP_Flush((PCD_HandleTypeDef*) pdev->pData, ep_addr); 168 | return USBD_OK; 169 | } 170 | 171 | USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 172 | { 173 | HAL_PCD_EP_SetStall((PCD_HandleTypeDef*) pdev->pData, ep_addr); 174 | return USBD_OK; 175 | } 176 | 177 | USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 178 | { 179 | HAL_PCD_EP_ClrStall((PCD_HandleTypeDef*) pdev->pData, ep_addr); 180 | return USBD_OK; 181 | } 182 | 183 | uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 184 | { 185 | PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; 186 | return ((ep_addr & 0x80) == 0x80) 187 | ? hpcd->IN_ep[ep_addr & 0x7F].is_stall 188 | : hpcd->OUT_ep[ep_addr & 0x7F].is_stall; 189 | } 190 | 191 | USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr) 192 | { 193 | HAL_PCD_SetAddress((PCD_HandleTypeDef*) pdev->pData, dev_addr); 194 | return USBD_OK; 195 | } 196 | 197 | USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) 198 | { 199 | HAL_PCD_EP_Transmit((PCD_HandleTypeDef*) pdev->pData, ep_addr, pbuf, size); 200 | return USBD_OK; 201 | } 202 | 203 | USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) 204 | { 205 | HAL_PCD_EP_Receive((PCD_HandleTypeDef*) pdev->pData, ep_addr, pbuf, size); 206 | return USBD_OK; 207 | } 208 | 209 | uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 210 | { 211 | return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr); 212 | } 213 | -------------------------------------------------------------------------------- /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 "usbd_core.h" 28 | #include "usbd_desc.h" 29 | #include "config.h" 30 | #include "util.h" 31 | 32 | uint8_t *USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 33 | uint8_t *USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 34 | uint8_t *USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 35 | uint8_t *USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 36 | uint8_t *USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 37 | uint8_t *USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 38 | uint8_t *USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); 39 | 40 | #ifdef USB_SUPPORT_USER_STRING_DESC 41 | uint8_t *USBD_FS_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); 42 | #endif /* USB_SUPPORT_USER_STRING_DESC */ 43 | 44 | USBD_DescriptorsTypeDef FS_Desc = { 45 | USBD_FS_DeviceDescriptor, 46 | USBD_FS_LangIDStrDescriptor, 47 | USBD_FS_ManufacturerStrDescriptor, 48 | USBD_FS_ProductStrDescriptor, 49 | USBD_FS_SerialStrDescriptor, 50 | USBD_FS_ConfigStrDescriptor, 51 | USBD_FS_InterfaceStrDescriptor, 52 | }; 53 | 54 | /* USB_DeviceDescriptor */ 55 | __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = { 56 | 0x12, /* bLength */ 57 | USB_DESC_TYPE_DEVICE, /* bDescriptorType */ 58 | 0x00, /* bcdUSB */ 59 | 0x02, 60 | 0x00, /* bDeviceClass */ 61 | 0x00, /* bDeviceSubClass */ 62 | 0x00, /* bDeviceProtocol */ 63 | USB_MAX_EP0_SIZE, /* bMaxPacketSize */ 64 | LOBYTE(USBD_VID), /* idVendor */ 65 | HIBYTE(USBD_VID), 66 | LOBYTE(USBD_PID_FS), /* idProduct */ 67 | HIBYTE(USBD_PID_FS), 68 | 0x00, /* bcdDevice rel. 0.00 */ 69 | 0x00, 70 | USBD_IDX_MFC_STR, /* Index of manufacturer string */ 71 | USBD_IDX_PRODUCT_STR, /* Index of product string */ 72 | USBD_IDX_SERIAL_STR, /* Index of serial number string */ 73 | USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */ 74 | } ; 75 | 76 | /* USB Standard Device Descriptor */ 77 | __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = 78 | { 79 | USB_LEN_LANGID_STR_DESC, 80 | USB_DESC_TYPE_STRING, 81 | LOBYTE(USBD_LANGID_STRING), 82 | HIBYTE(USBD_LANGID_STRING), 83 | }; 84 | 85 | __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; 86 | 87 | uint8_t *USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 88 | { 89 | UNUSED(speed); 90 | *length = sizeof(USBD_FS_DeviceDesc); 91 | return USBD_FS_DeviceDesc; 92 | } 93 | 94 | uint8_t *USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 95 | { 96 | UNUSED(speed); 97 | *length = sizeof(USBD_LangIDDesc); 98 | return USBD_LangIDDesc; 99 | } 100 | 101 | uint8_t *USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 102 | { 103 | UNUSED(speed); 104 | USBD_GetString(USBD_PRODUCT_STRING_FS, USBD_StrDesc, length); 105 | return USBD_StrDesc; 106 | } 107 | 108 | uint8_t *USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 109 | { 110 | UNUSED(speed); 111 | USBD_GetString (USBD_MANUFACTURER_STRING, USBD_StrDesc, length); 112 | return USBD_StrDesc; 113 | } 114 | 115 | uint8_t *USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 116 | { 117 | char buf[25]; 118 | 119 | UNUSED(speed); 120 | 121 | hex32(buf , *(uint32_t*)(UID_BASE )); 122 | hex32(buf + 8, *(uint32_t*)(UID_BASE + 4)); 123 | hex32(buf + 16, *(uint32_t*)(UID_BASE + 8)); 124 | 125 | USBD_GetString((uint8_t*)buf, USBD_StrDesc, length); 126 | return USBD_StrDesc; 127 | } 128 | 129 | uint8_t *USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 130 | { 131 | UNUSED(speed); 132 | USBD_GetString(USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); 133 | return USBD_StrDesc; 134 | } 135 | 136 | uint8_t *USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) 137 | { 138 | UNUSED(speed); 139 | USBD_GetString(USBD_INTERFACE_STRING_FS, USBD_StrDesc, length); 140 | return USBD_StrDesc; 141 | } 142 | -------------------------------------------------------------------------------- /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 | 29 | inline int disable_irq(void) { 30 | int primask; 31 | asm volatile("mrs %0, PRIMASK\n" 32 | "cpsid i\n" : "=r"(primask)); 33 | return primask & 1; 34 | } 35 | 36 | inline void enable_irq(int primask) { 37 | if (!primask) 38 | asm volatile("cpsie i\n"); 39 | } 40 | 41 | void hex32(char *out, uint32_t val) 42 | { 43 | char *p = out + 8; 44 | 45 | *p-- = 0; 46 | 47 | while (p >= out) { 48 | uint8_t nybble = val & 0x0F; 49 | 50 | if (nybble < 10) 51 | *p = '0' + nybble; 52 | else 53 | *p = 'A' + nybble - 10; 54 | 55 | val >>= 4; 56 | p--; 57 | } 58 | } 59 | --------------------------------------------------------------------------------