├── .gitattributes ├── .gitignore ├── .gitmodules ├── .vscode ├── .cortex-debug.registers.state.json ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── Core ├── Inc │ ├── can.h │ ├── compiler.h │ ├── gs_usb.h │ ├── led.h │ ├── lin.h │ ├── main.h │ ├── usbd_conf.h │ ├── usbd_desc.h │ └── usbd_gs_can.h └── Src │ ├── app_freertos.c │ ├── can.c │ ├── led.c │ ├── lin.c │ ├── main.c │ ├── syscalls.c │ ├── sysmem.c │ ├── usbd_conf.c │ ├── usbd_desc.c │ └── usbd_gs_can.c ├── Drivers └── CMSIS │ ├── Include │ ├── cmsis_armcc.h │ ├── cmsis_armclang.h │ ├── cmsis_compiler.h │ ├── cmsis_gcc.h │ ├── cmsis_iccarm.h │ ├── cmsis_version.h │ ├── core_armv8mbl.h │ ├── core_armv8mml.h │ ├── core_cm0.h │ ├── core_cm0plus.h │ ├── core_cm1.h │ ├── core_cm23.h │ ├── core_cm3.h │ ├── core_cm33.h │ ├── core_cm4.h │ ├── core_cm7.h │ ├── core_sc000.h │ ├── core_sc300.h │ ├── mpu_armv7.h │ ├── mpu_armv8.h │ └── tz_context.h │ └── LICENSE.txt ├── LICENSE ├── Middlewares ├── ST │ └── STM32_USB_Device_Library │ │ └── Core │ │ ├── Inc │ │ ├── usbd_core.h │ │ ├── usbd_ctlreq.h │ │ ├── usbd_def.h │ │ └── usbd_ioreq.h │ │ └── Src │ │ ├── usbd_core.c │ │ ├── usbd_ctlreq.c │ │ └── usbd_ioreq.c └── Third_Party │ └── FreeRTOS │ ├── LICENSE.md │ ├── README.md │ ├── croutine.c │ ├── event_groups.c │ ├── include │ ├── FreeRTOS.h │ ├── StackMacros.h │ ├── atomic.h │ ├── croutine.h │ ├── deprecated_definitions.h │ ├── event_groups.h │ ├── list.h │ ├── message_buffer.h │ ├── mpu_prototypes.h │ ├── mpu_wrappers.h │ ├── portable.h │ ├── projdefs.h │ ├── queue.h │ ├── semphr.h │ ├── stack_macros.h │ ├── stdint.readme │ ├── stream_buffer.h │ ├── task.h │ └── timers.h │ ├── list.c │ ├── portable │ ├── GCC │ │ ├── ARM_CM0 │ │ │ ├── port.c │ │ │ └── portmacro.h │ │ └── ARM_CM4F │ │ │ ├── port.c │ │ │ └── portmacro.h │ ├── MemMang │ │ ├── ReadMe.url │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ └── heap_5.c │ └── readme.txt │ ├── queue.c │ ├── stream_buffer.c │ ├── tasks.c │ └── timers.c ├── Portable ├── board_DevEBoxH7 │ ├── Inc │ │ ├── FreeRTOSConfig.h │ │ ├── board.h │ │ ├── board_hal_config.h │ │ ├── stm32h7xx_hal_conf.h │ │ └── stm32h7xx_it.h │ ├── Makefile │ ├── STM32H743VITx_FLASH.ld │ ├── Src │ │ ├── board.c │ │ ├── stm32h7xx_hal_msp.c │ │ ├── stm32h7xx_hal_timebase_tim.c │ │ ├── stm32h7xx_it.c │ │ └── system_stm32h7xx.c │ └── startup_stm32h743xx.s ├── board_budgetcan_g0 │ ├── Inc │ │ ├── FreeRTOSConfig.h │ │ ├── board.h │ │ ├── board_hal_config.h │ │ ├── stm32g0xx_hal_conf.h │ │ └── stm32g0xx_it.h │ ├── Makefile │ ├── STM32G0B1KETX_FLASH.ld │ ├── Src │ │ ├── board.c │ │ ├── stm32g0xx_hal_msp.c │ │ ├── stm32g0xx_hal_timebase_tim.c │ │ ├── stm32g0xx_it.c │ │ └── system_stm32g0xx.c │ └── startup_stm32g0b1ketx.s ├── board_budgetcan_g4 │ ├── Inc │ │ ├── FreeRTOSConfig.h │ │ ├── board.h │ │ ├── board_hal_config.h │ │ ├── stm32g4xx_hal_conf.h │ │ └── stm32g4xx_it.h │ ├── Makefile │ ├── STM32G473CBTx_FLASH.ld │ ├── Src │ │ ├── board.c │ │ ├── stm32g4xx_hal_msp.c │ │ ├── stm32g4xx_hal_timebase_tim.c │ │ ├── stm32g4xx_it.c │ │ └── system_stm32g4xx.c │ └── startup_stm32g473xx.s ├── board_canablev1 │ ├── Inc │ │ ├── FreeRTOSConfig.h │ │ ├── board.h │ │ ├── board_hal_config.h │ │ ├── stm32f0xx_hal_conf.h │ │ └── stm32f0xx_it.h │ ├── Makefile │ ├── STM32F042C6Tx_FLASH.ld │ ├── Src │ │ ├── board.c │ │ ├── stm32f0xx_hal_msp.c │ │ ├── stm32f0xx_hal_timebase_tim.c │ │ ├── stm32f0xx_it.c │ │ └── system_stm32f0xx.c │ └── startup_stm32f042x6.s ├── board_canablev2 │ ├── Inc │ │ ├── FreeRTOSConfig.h │ │ ├── board.h │ │ ├── board_hal_config.h │ │ ├── stm32g4xx_hal_conf.h │ │ └── stm32g4xx_it.h │ ├── Makefile │ ├── STM32G431C6TX_FLASH.ld │ ├── Src │ │ ├── board.c │ │ ├── stm32g4xx_hal_msp.c │ │ ├── stm32g4xx_hal_timebase_tim.c │ │ ├── stm32g4xx_it.c │ │ └── system_stm32g4xx.c │ └── startup_stm32g431c6tx.s └── board_stm32h745i-disco │ ├── Inc │ ├── FreeRTOSConfig.h │ ├── board.h │ ├── board_hal_config.h │ ├── stm32h7xx_hal_conf.h │ └── stm32h7xx_it.h │ ├── Makefile │ ├── README.md │ ├── Src │ ├── board.c │ ├── stm32h7xx_hal_msp.c │ ├── stm32h7xx_hal_timebase_tim.c │ ├── stm32h7xx_it.c │ └── system_stm32h7xx_dualcore_boot_cm4_cm7.c │ ├── startup_stm32h745xx_CM7.s │ ├── stm32h745xx_flash_CM7.ld │ └── stm32h745xx_sram1_CM7.ld ├── README.md └── uncrustify.cfg /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.code-workspace 2 | **/build/ 3 | *.launch 4 | .settings 5 | .cproject 6 | .project 7 | .mxproject 8 | *.o 9 | *.d 10 | *.bin 11 | *.asmo 12 | *.elf 13 | *~ 14 | .cache/ 15 | compile_commands.json 16 | /Debug*/ 17 | /DEBUG_budgetcan_g0_fw/ 18 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Drivers/stm32h7xx_hal_driver"] 2 | path = Drivers/stm32h7xx_hal_driver 3 | url = https://github.com/STMicroelectronics/stm32h7xx_hal_driver.git 4 | [submodule "Drivers/cmsis_device_h7"] 5 | path = Drivers/cmsis_device_h7 6 | url = https://github.com/STMicroelectronics/cmsis_device_h7.git 7 | [submodule "Drivers/stm32f4xx_hal_driver"] 8 | path = Drivers/stm32f4xx_hal_driver 9 | url = https://github.com/STMicroelectronics/stm32f4xx_hal_driver.git 10 | [submodule "Drivers/cmsis_device_f4"] 11 | path = Drivers/cmsis_device_f4 12 | url = https://github.com/STMicroelectronics/cmsis_device_f4.git 13 | [submodule "Drivers/stm32f1xx_hal_driver"] 14 | path = Drivers/stm32f1xx_hal_driver 15 | url = https://github.com/STMicroelectronics/stm32f1xx_hal_driver.git 16 | [submodule "Drivers/stm32f2xx_hal_driver"] 17 | path = Drivers/stm32f2xx_hal_driver 18 | url = https://github.com/STMicroelectronics/stm32f2xx_hal_driver.git 19 | [submodule "Drivers/stm32f3xx_hal_driver"] 20 | path = Drivers/stm32f3xx_hal_driver 21 | url = https://github.com/STMicroelectronics/stm32f3xx_hal_driver.git 22 | [submodule "Drivers/cmsis_device_f1"] 23 | path = Drivers/cmsis_device_f1 24 | url = https://github.com/STMicroelectronics/cmsis_device_f1.git 25 | [submodule "Drivers/cmsis_device_f2"] 26 | path = Drivers/cmsis_device_f2 27 | url = https://github.com/STMicroelectronics/cmsis_device_f2.git 28 | [submodule "Drivers/cmsis_device_f3"] 29 | path = Drivers/cmsis_device_f3 30 | url = https://github.com/STMicroelectronics/cmsis_device_f3.git 31 | [submodule "Drivers/stm32f0xx_hal_driver"] 32 | path = Drivers/stm32f0xx_hal_driver 33 | url = https://github.com/STMicroelectronics/stm32f0xx_hal_driver.git 34 | [submodule "Drivers/stm32g0xx_hal_driver"] 35 | path = Drivers/stm32g0xx_hal_driver 36 | url = https://github.com/STMicroelectronics/stm32g0xx_hal_driver.git 37 | [submodule "Drivers/stm32g4xx_hal_driver"] 38 | path = Drivers/stm32g4xx_hal_driver 39 | url = https://github.com/STMicroelectronics/stm32g4xx_hal_driver.git 40 | [submodule "Drivers/cmsis_device_f0"] 41 | path = Drivers/cmsis_device_f0 42 | url = https://github.com/STMicroelectronics/cmsis_device_f0.git 43 | [submodule "Drivers/cmsis_device_g0"] 44 | path = Drivers/cmsis_device_g0 45 | url = https://github.com/STMicroelectronics/cmsis_device_g0.git 46 | [submodule "Drivers/cmsis_device_g4"] 47 | path = Drivers/cmsis_device_g4 48 | url = https://github.com/STMicroelectronics/cmsis_device_g4.git 49 | -------------------------------------------------------------------------------- /.vscode/.cortex-debug.registers.state.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "cwd": "${workspaceFolder}", 9 | "executable": "${workspaceFolder}/Portable/board_budgetcan_g0/build/budgetcan_g0_fw.elf", 10 | "name": "Debug budgetcan_g0", 11 | "request": "launch", 12 | "type": "cortex-debug", 13 | "runToEntryPoint": "main", 14 | "showDevDebugOutput": "none", 15 | "servertype": "stlink" 16 | }, 17 | { 18 | "cwd": "${workspaceFolder}", 19 | "executable": "${workspaceFolder}/Portable/board_budgetcan_g4/build/budgetcan_g4_fw.elf", 20 | "name": "Debug budgetcan_g4", 21 | "request": "launch", 22 | "type": "cortex-debug", 23 | "runToEntryPoint": "main", 24 | "showDevDebugOutput": "none", 25 | "servertype": "stlink" 26 | }, 27 | { 28 | "cwd": "${workspaceFolder}", 29 | "executable": "${workspaceFolder}/Portable/board_DevEBox/build/DevEBoxH7_fw.elf", 30 | "name": "Debug DevEbox", 31 | "request": "launch", 32 | "type": "cortex-debug", 33 | "runToEntryPoint": "main", 34 | "showDevDebugOutput": "none", 35 | "servertype": "stlink" 36 | }, 37 | { 38 | "cwd": "${workspaceFolder}", 39 | "executable": "${workspaceFolder}/Portable/board_canablev1/build/canablev1_fw.elf", 40 | "name": "Debug canablev1", 41 | "request": "launch", 42 | "type": "cortex-debug", 43 | "runToEntryPoint": "main", 44 | "showDevDebugOutput": "none", 45 | "servertype": "stlink" 46 | }, 47 | { 48 | "cwd": "${workspaceFolder}", 49 | "executable": "${workspaceFolder}/Portable/board_canablev2/build/canablev2_fw.elf", 50 | "name": "Debug canablev2", 51 | "request": "launch", 52 | "type": "cortex-debug", 53 | "runToEntryPoint": "main", 54 | "showDevDebugOutput": "none", 55 | "servertype": "stlink" 56 | }, 57 | { 58 | "cwd": "${workspaceFolder}", 59 | "executable": "${workspaceFolder}/Portable/board_cannette/build/cannette_fw.elf", 60 | "name": "Debug cannette", 61 | "request": "launch", 62 | "type": "cortex-debug", 63 | "runToEntryPoint": "main", 64 | "showDevDebugOutput": "none", 65 | "servertype": "stlink" 66 | }, 67 | { 68 | "cwd": "${workspaceFolder}", 69 | "executable": "${workspaceFolder}/Portable/board_cannette/build/cannette_fw.elf", 70 | "name": "Debug candlelight", 71 | "request": "launch", 72 | "type": "cortex-debug", 73 | "runToEntryPoint": "main", 74 | "showDevDebugOutput": "none", 75 | "servertype": "stlink" 76 | } 77 | ] 78 | } 79 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "cstdint": "c", 4 | "USBD_DEF.H": "cpp" 5 | } 6 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "Build budgetcan_g0", 8 | "type": "shell", 9 | "command": "make", 10 | "options": { 11 | "cwd": "${workspaceRoot}/Portable/board_budgetcan_g0/" 12 | }, 13 | "args": [ 14 | ], 15 | "group": "build", 16 | "presentation": { 17 | }, 18 | // Use the standard MS compiler pattern to detect errors, warnings and infos 19 | "problemMatcher": "$msCompile" 20 | }, 21 | { 22 | "label": "Build budgetcan_g4", 23 | "type": "shell", 24 | "command": "make", 25 | "options": { 26 | "cwd": "${workspaceRoot}/Portable/board_budgetcan_g4/" 27 | }, 28 | "args": [ 29 | ], 30 | "group": "build", 31 | "presentation": { 32 | }, 33 | // Use the standard MS compiler pattern to detect errors, warnings and infos 34 | "problemMatcher": "$msCompile" 35 | }, 36 | { 37 | "label": "Build canablev1", 38 | "type": "shell", 39 | "command": "make", 40 | "options": { 41 | "cwd": "${workspaceRoot}/Portable/board_canablev1/" 42 | }, 43 | "args": [ 44 | ], 45 | "group": "build", 46 | "presentation": { 47 | }, 48 | // Use the standard MS compiler pattern to detect errors, warnings and infos 49 | "problemMatcher": "$msCompile" 50 | }, 51 | { 52 | "label": "Build canablev2", 53 | "type": "shell", 54 | "command": "make", 55 | "options": { 56 | "cwd": "${workspaceRoot}/Portable/board_canablev2/" 57 | }, 58 | "args": [ 59 | ], 60 | "group": "build", 61 | "presentation": { 62 | }, 63 | // Use the standard MS compiler pattern to detect errors, warnings and infos 64 | "problemMatcher": "$msCompile" 65 | }, 66 | { 67 | "label": "Build DevEBox", 68 | "type": "shell", 69 | "command": "make", 70 | "options": { 71 | "cwd": "${workspaceRoot}/Portable/board_DevEBoxH7/" 72 | }, 73 | "args": [ 74 | ], 75 | "group": "build", 76 | "presentation": { 77 | }, 78 | // Use the standard MS compiler pattern to detect errors, warnings and infos 79 | "problemMatcher": "$msCompile" 80 | }, 81 | { 82 | "label": "Build cannette", 83 | "type": "shell", 84 | "command": "make", 85 | "options": { 86 | "cwd": "${workspaceRoot}/Portable/board_cannette/" 87 | }, 88 | "args": [ 89 | ], 90 | "group": "build", 91 | "presentation": { 92 | }, 93 | // Use the standard MS compiler pattern to detect errors, warnings and infos 94 | "problemMatcher": "$msCompile" 95 | }, 96 | { 97 | "label": "Build candlelight", 98 | "type": "shell", 99 | "command": "make", 100 | "options": { 101 | "cwd": "${workspaceRoot}/Portable/board_candlelight/" 102 | }, 103 | "args": [ 104 | ], 105 | "group": "build", 106 | "presentation": { 107 | }, 108 | // Use the standard MS compiler pattern to detect errors, warnings and infos 109 | "problemMatcher": "$msCompile" 110 | } 111 | ] 112 | } -------------------------------------------------------------------------------- /Core/Inc/can.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | Copyright (c) 2022 Ryan Edwards (changes for STM32G0/G4 and CAN-FD) 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __CAN_H 30 | #define __CAN_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include "main.h" 37 | #include 38 | #include 39 | #include "gs_usb.h" 40 | 41 | #if defined (FDCAN1) 42 | #define CAN_HANDLE_TYPEDEF FDCAN_HandleTypeDef 43 | #define CAN_TYPEDEF FDCAN_GlobalTypeDef 44 | #else 45 | #define CAN_HANDLE_TYPEDEF CAN_HandleTypeDef 46 | #define CAN_TYPEDEF CAN_TypeDef 47 | #endif 48 | 49 | /* Exported functions --------------------------------------------------------*/ 50 | void can_init(CAN_HANDLE_TYPEDEF *hcan, CAN_TYPEDEF *instance); 51 | void can_set_bittiming(CAN_HANDLE_TYPEDEF *hcan, uint16_t brp, uint8_t phase_seg1, uint8_t phase_seg2, uint8_t sjw); 52 | void can_set_data_bittiming(CAN_HANDLE_TYPEDEF *hcan, uint16_t brp, uint8_t phase_seg1, uint8_t phase_seg2, uint8_t sjw); 53 | void can_enable(CAN_HANDLE_TYPEDEF *hcan, bool loop_back, bool listen_only, bool one_shot, bool can_mode_fd); 54 | void can_disable(CAN_HANDLE_TYPEDEF *hcan); 55 | bool can_is_enabled(CAN_HANDLE_TYPEDEF *hcan); 56 | bool can_send(CAN_HANDLE_TYPEDEF *hcan, struct gs_host_frame *frame); 57 | void can_set_termination(uint8_t channel, uint8_t value); 58 | uint8_t can_get_termination(uint8_t channel); 59 | 60 | void can_on_enable_cb(uint8_t channel); 61 | void can_on_disable_cb(uint8_t channel); 62 | void can_on_tx_cb(uint8_t channel, struct gs_host_frame *frame); 63 | void can_on_rx_cb(uint8_t channel, struct gs_host_frame *frame); 64 | void can_identify_cb(uint32_t do_identify); 65 | void can_set_term_cb(uint8_t channel, GPIO_PinState state); 66 | GPIO_PinState can_get_term_cb(uint8_t channel); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif /* __CAN_H */ 73 | -------------------------------------------------------------------------------- /Core/Inc/compiler.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2010 Isilon Systems, Inc. 3 | * Copyright (c) 2010 iX Systems, Inc. 4 | * Copyright (c) 2010 Panasas, Inc. 5 | * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. 6 | * Copyright (c) 2015 François Tigeot 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice unmodified, this list of conditions, and the following 14 | * disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * $FreeBSD$ 31 | */ 32 | #ifndef _LINUXKPI_LINUX_COMPILER_H_ 33 | #define _LINUXKPI_LINUX_COMPILER_H_ 34 | 35 | #ifndef __aligned 36 | #define __aligned(x) __attribute__((__aligned__(x))) 37 | #endif 38 | 39 | #ifndef __packed 40 | #define __packed __attribute__((__packed__)) 41 | #endif 42 | 43 | #if __has_attribute(__fallthrough__) 44 | #define fallthrough __attribute__((__fallthrough__)) 45 | #else 46 | #define fallthrough do {} while (0) /* fallthrough */ 47 | #endif 48 | 49 | #define barrier() __asm__ __volatile__ ("" : : : "memory") 50 | 51 | #define ACCESS_ONCE(x) (*(volatile __typeof(x) *)&(x)) 52 | 53 | #define WRITE_ONCE(x,v) \ 54 | do { \ 55 | barrier(); \ 56 | ACCESS_ONCE(x) = (v); \ 57 | barrier(); \ 58 | } while (0) 59 | 60 | #define READ_ONCE(x) \ 61 | ({ \ 62 | __typeof(x) __var = ({ \ 63 | barrier(); \ 64 | ACCESS_ONCE(x); \ 65 | }); \ 66 | barrier(); \ 67 | __var; \ 68 | }) 69 | 70 | #define lockless_dereference(p) READ_ONCE(p) 71 | 72 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) 73 | #define __must_be_array(a) __same_type(a, &(a)[0]) 74 | 75 | #define sizeof_field(_s, _m) sizeof(((_s *)0)->_m) 76 | 77 | #define container_of(ptr, type, member) \ 78 | ({ \ 79 | __typeof(((type *)0)->member) *_p = (ptr); \ 80 | (type *)((char *)_p - offsetof(type, member)); \ 81 | }) 82 | 83 | #define struct_size(ptr, field, num) \ 84 | (offsetof(__typeof(*(ptr)), field) + sizeof((ptr)->field[0]) * (num)) 85 | 86 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 87 | 88 | #define DECLARE_FLEX_ARRAY(_t, _n) \ 89 | struct { \ 90 | struct { } __dummy_ ## _n; \ 91 | _t _n[0]; \ 92 | } 93 | 94 | /* 95 | * Checking if an option is defined would be easy if we could do CPP inside CPP. 96 | * The defined case whether -Dxxx or -Dxxx=1 are easy to deal with. In either 97 | * case the defined value is "1". A more general -Dxxx= case will require 98 | * more effort to deal with all possible "true" values. Hope we do not have 99 | * to do this as well. 100 | * The real problem is the undefined case. To avoid this problem we do the 101 | * concat/varargs trick: "yyy" ## xxx can make two arguments if xxx is "1" 102 | * by having a #define for yyy_1 which is "ignore,". 103 | * Otherwise we will just get "yyy". 104 | * Need to be careful about variable substitutions in macros though. 105 | * This way we make a (true, false) problem a (don't care, true, false) or a 106 | * (don't care true, false). Then we can use a variadic macro to only select 107 | * the always well known and defined argument #2. And that seems to be 108 | * exactly what we need. Use 1 for true and 0 for false to also allow 109 | * #if IS_*() checks pre-compiler checks which do not like #if true. 110 | */ 111 | #define ___XAB_1 dontcare, 112 | #define ___IS_XAB(_ignore, _x, ...) (_x) 113 | #define __IS_XAB(_x) ___IS_XAB(_x 1, 0) 114 | #define _IS_XAB(_x) __IS_XAB(__CONCAT(___XAB_, _x)) 115 | 116 | /* This is if CONFIG_ccc=y. */ 117 | #define IS_BUILTIN(_x) _IS_XAB(_x) 118 | /* This is if CONFIG_ccc=m. */ 119 | #define IS_MODULE(_x) _IS_XAB(_x ## _MODULE) 120 | /* This is if CONFIG_ccc is compiled in(=y) or a module(=m). */ 121 | #define IS_ENABLED(_x) (IS_BUILTIN(_x) || IS_MODULE(_x)) 122 | 123 | #endif /* _LINUXKPI_LINUX_COMPILER_H_ */ 124 | -------------------------------------------------------------------------------- /Core/Inc/led.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2022 Ryan Edwards 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #ifndef __LED_H 28 | #define __LED_H 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* Exported defines -----------------------------------------------------------*/ 35 | #if !defined (LED_RXTX_ACTIVE_TIME_MS) 36 | #define LED_RXTX_ACTIVE_TIME_MS 50U 37 | #endif 38 | #if !defined (LED_RXTX_INACTIVE_TIME_MS) 39 | #define LED_RXTX_INACTIVE_TIME_MS 50U 40 | #endif 41 | 42 | #define LED_ACTIVE_LOW 0U 43 | #define LED_ACTIVE_HIGH 1U 44 | 45 | /* Exported types ------------------------------------------------------------*/ 46 | typedef enum { 47 | LED_MODE_INACTIVE = 0, 48 | LED_MODE_ACTIVE, 49 | LED_MODE_RXTX_ACTIVE, 50 | LED_MODE_RXTX_HOLDOFF, 51 | LED_MODE_BLINK 52 | } led_mode_t; 53 | 54 | typedef struct { 55 | GPIO_TypeDef *GPIOx; 56 | uint16_t GPIO_Pin; 57 | GPIO_PinState initial_state; 58 | led_mode_t led_mode; 59 | led_mode_t prev_led_mode; 60 | uint8_t led_active_level; 61 | uint32_t led_rxtx_start_tick; 62 | uint32_t blink_period_ms; 63 | uint32_t blink_toggle_start_tick; 64 | } LED_HandleTypeDef; 65 | 66 | /* Exported functions --------------------------------------------------------*/ 67 | void led_init(LED_HandleTypeDef* hled, GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, led_mode_t led_mode, uint8_t led_active_level); 68 | void led_update(LED_HandleTypeDef* hled); 69 | led_mode_t led_get_mode(LED_HandleTypeDef* hled); 70 | void led_set_active(LED_HandleTypeDef* hled); 71 | void led_set_inactive(LED_HandleTypeDef* hled); 72 | void led_indicate_rxtx(LED_HandleTypeDef* hled); 73 | void led_blink_start(LED_HandleTypeDef* hled, uint32_t period_ms); 74 | void led_blink_stop(LED_HandleTypeDef* hled); 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif /* __LED_H */ 81 | -------------------------------------------------------------------------------- /Core/Inc/lin.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2022 R. Edwards 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | /** 28 | ****************************************************************************** 29 | * @file : lin.h 30 | * @brief : LIN driver to interface with the STM32 31 | ****************************************************************************** 32 | */ 33 | #ifndef __LIN_H 34 | #define __LIN_H 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #include "main.h" 41 | #include "board.h" 42 | #include "gs_usb.h" 43 | 44 | #if defined(LIN_FEATURE_ENABLED) 45 | /* Exported defines -----------------------------------------------------------*/ 46 | #define LIN_SYNC_BYTE 0x55u 47 | #define LIN_GET_PID_BIT(x,y) (((x) >> (y)) & 0x01u) 48 | #define LIN_ID_MASK 0x3Fu 49 | #define LIN_RX_TIMEOUT_VALUE 3 50 | #define LIN_MAX_MSG_BYTES 9 51 | 52 | #if !defined(LIN_MAX_DATA_BYTES) 53 | #define LIN_MAX_DATA_BYTES 8U 54 | #endif 55 | #if !defined(LIN_MAX_SLOTS) 56 | #define LIN_MAX_SLOTS 10U 57 | #endif 58 | #if !defined(LIN_CONFIG_MSG_ID_CMD) 59 | #define LIN_CONFIG_MSG_ID_CMD 0x1FFFFE80 60 | #endif 61 | #if !defined(LIN_CONFIG_MSG_ID_DATA) 62 | #define LIN_CONFIG_MSG_ID_DATA 0x1FFFFE81 63 | #endif 64 | #if !defined(LIN_MASTER_HEADER_FRAME) 65 | #define LIN_MASTER_HEADER_FRAME 0x1FFFFE8A 66 | #endif 67 | #if !defined(LIN_MASTER_FRAME) 68 | #define LIN_MASTER_FRAME 0x1FFFFE8B 69 | #endif 70 | 71 | #define IS_LIN_FRAME(can_id) ((can_id & 0x1FFFFE00) == 0x1FFFFE00) 72 | 73 | 74 | #define IS_LIN_CONFIG_FRAME(can_id) ((can_id == LIN_CONFIG_MSG_ID_CMD) \ 75 | || (can_id == LIN_CONFIG_MSG_ID_DATA)) 76 | 77 | #define IS_LIN_MASTER_HEADER_FRAME(can_id) ((can_id == LIN_MASTER_HEADER_FRAME)) 78 | #define IS_LIN_MASTER_FRAME(can_id) ((can_id == LIN_MASTER_FRAME)) 79 | 80 | /* Exported types ------------------------------------------------------------*/ 81 | typedef enum { 82 | LIN_SLAVE, 83 | LIN_MONITOR, 84 | LIN_MASTER 85 | } lin_type_t; 86 | 87 | typedef enum { 88 | LIN_MASTER_REQ_BREAK_ONLY, 89 | LIN_MASTER_REQ_HEADER_ONLY, 90 | LIN_MASTER_REQ_MASTER_FRAME_TX 91 | } lin_master_req_type_t; 92 | 93 | typedef enum { 94 | LIN_IDLE_AWAIT_BREAK, 95 | LIN_PID_RX, 96 | LIN_MASTER_RX_PID, 97 | LIN_MASTER_RX_DATA, 98 | LIN_MASTER_TX_HEADER, 99 | LIN_SLAVE_RX_DATA, 100 | LIN_SLAVE_TX_DATA, 101 | LIN_MONITOR_RX_DATA 102 | } lin_state_t; 103 | 104 | typedef enum { 105 | LIN_CMD_LOAD_SLOT, 106 | LIN_CMD_READ_SLOT, 107 | LIN_CMD_ENABLE_SLOT, 108 | LIN_CMD_DISABLE_SLOT, 109 | LIN_CMD_DISABLE_ALL_SLOTS, 110 | LIN_CMD_ERASE_ALL_SLOTS, 111 | LIN_CMD_ENABLE_LIN, 112 | LIN_CMD_DISABLE_LIN 113 | } lin_command_type_t; 114 | 115 | typedef union 116 | { 117 | struct __attribute__((packed)) 118 | { 119 | uint8_t PID; 120 | uint8_t len; 121 | uint8_t data[8]; 122 | } lin_slot_data; 123 | uint32_t lin_baud_rate; 124 | uint8_t checksum_type; 125 | } lin_data_t; 126 | 127 | typedef struct 128 | { 129 | uint8_t lin_rx_data_available : 1; 130 | lin_master_req_type_t lin_master_req_type; 131 | } lin_flags_t; 132 | 133 | typedef struct 134 | { 135 | uint8_t pid; 136 | uint8_t lin_data_buffer[9]; 137 | uint8_t data_index; 138 | uint8_t tx_msg_len; 139 | uint8_t checksum; 140 | } lin_data_frame_t; 141 | 142 | typedef struct __attribute__((packed)) 143 | { 144 | uint8_t is_active : 1; 145 | uint8_t lin_node_action : 2; 146 | } lin_slot_flags_t; 147 | 148 | typedef struct __attribute__((packed)) 149 | { 150 | lin_slot_flags_t lin_slot_flags; 151 | uint8_t PID; 152 | uint8_t len; 153 | uint8_t data[LIN_MAX_DATA_BYTES]; 154 | } lin_slot_data_t; 155 | 156 | typedef struct { 157 | 158 | uint8_t lin_cmd_type; 159 | uint8_t lin_channel; 160 | uint8_t lin_table_index; 161 | lin_slot_data_t lin_data; 162 | } lin_config_t; 163 | 164 | 165 | typedef struct { 166 | uint8_t lin_instance; 167 | uint8_t lin_slot_table_index; 168 | UART_HandleTypeDef* huart; 169 | lin_flags_t lin_flags; 170 | uint8_t UartRxBuffer[1]; 171 | uint8_t UartTxBuffer[LIN_MAX_MSG_BYTES]; 172 | lin_state_t lin_state; 173 | lin_type_t lin_type; 174 | lin_data_frame_t lin_data_frame; 175 | uint32_t lin_rx_timeout_starttick; 176 | uint8_t lin_classicChecksum; 177 | uint32_t lin_baud_rate; 178 | lin_config_t lin_config_data; 179 | lin_slot_data_t lin_slot_table[LIN_MAX_SLOTS]; 180 | } LIN_HandleTypeDef; 181 | 182 | 183 | /* Exported functions --------------------------------------------------------*/ 184 | void lin_init(LIN_HandleTypeDef* hlin, uint8_t lin_instance, UART_HandleTypeDef* huart); 185 | void lin_process_frame(struct gs_host_frame* frame); 186 | void lin_handler_task(LIN_HandleTypeDef* hlin); 187 | void lin_rx_IRQ_handler(LIN_HandleTypeDef* hlin); 188 | LIN_HandleTypeDef* lin_get_handle(uint32_t msg_id); 189 | 190 | #endif /* LIN_FEATURE_ENABLED */ 191 | 192 | #ifdef __cplusplus 193 | } 194 | #endif 195 | 196 | #endif /* __LIN_H */ 197 | -------------------------------------------------------------------------------- /Core/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __MAIN_H 23 | #define __MAIN_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "board_hal_config.h" 31 | 32 | /* Private includes ----------------------------------------------------------*/ 33 | /* USER CODE BEGIN Includes */ 34 | 35 | /* USER CODE END Includes */ 36 | 37 | /* Exported types ------------------------------------------------------------*/ 38 | /* USER CODE BEGIN ET */ 39 | 40 | /* USER CODE END ET */ 41 | 42 | /* Exported constants --------------------------------------------------------*/ 43 | /* USER CODE BEGIN EC */ 44 | 45 | /* USER CODE END EC */ 46 | 47 | /* Exported macro ------------------------------------------------------------*/ 48 | /* USER CODE BEGIN EM */ 49 | 50 | /* USER CODE END EM */ 51 | 52 | /* Exported functions prototypes ---------------------------------------------*/ 53 | void Error_Handler(void); 54 | 55 | /* USER CODE BEGIN EFP */ 56 | void main_init_cb(void); 57 | void main_rtos_init_cb(void); 58 | void main_task_cb(void); 59 | /* USER CODE END EFP */ 60 | 61 | /* Private defines -----------------------------------------------------------*/ 62 | /* USER CODE BEGIN Private defines */ 63 | 64 | /* USER CODE END Private defines */ 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif /* __MAIN_H */ 71 | -------------------------------------------------------------------------------- /Core/Inc/usbd_conf.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_conf.h 5 | * @version : v2.0_Cube 6 | * @brief : Header for usbd_conf.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __USBD_CONF__H__ 23 | #define __USBD_CONF__H__ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include 31 | #include 32 | #include 33 | #include "main.h" 34 | //#include "board.h" 35 | 36 | /* USER CODE BEGIN INCLUDE */ 37 | 38 | /* USER CODE END INCLUDE */ 39 | 40 | /** @addtogroup USBD_OTG_DRIVER 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBD_CONF USBD_CONF 45 | * @brief Configuration file for Usb otg low level driver. 46 | * @{ 47 | */ 48 | 49 | /** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables 50 | * @brief Public variables. 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines 59 | * @brief Defines for configuration of the Usb device. 60 | * @{ 61 | */ 62 | 63 | /*---------- -----------*/ 64 | #define USBD_MAX_NUM_INTERFACES 1 65 | /*---------- -----------*/ 66 | #define USBD_MAX_NUM_CONFIGURATION 1 67 | /*---------- -----------*/ 68 | #define USBD_MAX_STR_DESC_SIZ 192 69 | /*---------- -----------*/ 70 | #define USBD_DEBUG_LEVEL 0 71 | /*---------- -----------*/ 72 | #define USBD_SELF_POWERED 1 73 | /*---------- -----------*/ 74 | #define MAX_STATIC_ALLOC_SIZE 512 75 | 76 | /****************************************/ 77 | /* #define for FS and HS identification */ 78 | #define DEVICE_FS 0 79 | 80 | #define USBD_SUPPORT_USER_STRING_DESC 1U 81 | /** 82 | * @} 83 | */ 84 | 85 | /** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros 86 | * @brief Aliases. 87 | * @{ 88 | */ 89 | 90 | /* Memory management macros */ 91 | 92 | /** Alias for memory allocation. */ 93 | #define USBD_malloc (uint32_t *)USBD_static_malloc 94 | 95 | /** Alias for memory release. */ 96 | #define USBD_free USBD_static_free 97 | 98 | /** Alias for memory set. */ 99 | #define USBD_memset /* Not used */ 100 | 101 | /** Alias for memory copy. */ 102 | #define USBD_memcpy /* Not used */ 103 | 104 | /** Alias for delay. */ 105 | #define USBD_Delay HAL_Delay 106 | 107 | /* DEBUG macros */ 108 | 109 | #if (USBD_DEBUG_LEVEL > 0) 110 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\ 111 | printf("\n"); 112 | #else 113 | #define USBD_UsrLog(...) 114 | #endif 115 | 116 | #if (USBD_DEBUG_LEVEL > 1) 117 | 118 | #define USBD_ErrLog(...) printf("ERROR: ") ;\ 119 | printf(__VA_ARGS__);\ 120 | printf("\n"); 121 | #else 122 | #define USBD_ErrLog(...) 123 | #endif 124 | 125 | #if (USBD_DEBUG_LEVEL > 2) 126 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\ 127 | printf(__VA_ARGS__);\ 128 | printf("\n"); 129 | #else 130 | #define USBD_DbgLog(...) 131 | #endif 132 | 133 | /** 134 | * @} 135 | */ 136 | 137 | /** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types 138 | * @brief Types. 139 | * @{ 140 | */ 141 | 142 | /** 143 | * @} 144 | */ 145 | 146 | /** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype 147 | * @brief Declaration of public functions for Usb device. 148 | * @{ 149 | */ 150 | 151 | /* Exported functions -------------------------------------------------------*/ 152 | void *USBD_static_malloc(uint32_t size); 153 | void USBD_static_free(void *p); 154 | /** 155 | * @} 156 | */ 157 | 158 | /** 159 | * @} 160 | */ 161 | 162 | /** 163 | * @} 164 | */ 165 | 166 | #ifdef __cplusplus 167 | } 168 | #endif 169 | 170 | #endif /* __USBD_CONF__H__ */ 171 | -------------------------------------------------------------------------------- /Core/Inc/usbd_desc.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_desc.c 5 | * @version : v2.0_Cube 6 | * @brief : Header for usbd_conf.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_DESC__C__ 22 | #define __USBD_DESC__C__ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | 31 | /* USER CODE BEGIN INCLUDE */ 32 | 33 | /* USER CODE END INCLUDE */ 34 | 35 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 36 | * @{ 37 | */ 38 | 39 | /** @defgroup USBD_DESC USBD_DESC 40 | * @brief Usb device descriptors module. 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants 45 | * @brief Constants. 46 | * @{ 47 | */ 48 | #define DEVICE_ID1 (UID_BASE) 49 | #define DEVICE_ID2 (UID_BASE + 0x4) 50 | #define DEVICE_ID3 (UID_BASE + 0x8) 51 | 52 | #define USB_SIZ_STRING_SERIAL 0x1A 53 | 54 | /* USER CODE BEGIN EXPORTED_CONSTANTS */ 55 | 56 | /* USER CODE END EXPORTED_CONSTANTS */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | /** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines 63 | * @brief Defines. 64 | * @{ 65 | */ 66 | 67 | /* USER CODE BEGIN EXPORTED_DEFINES */ 68 | 69 | /* USER CODE END EXPORTED_DEFINES */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions 76 | * @brief Types. 77 | * @{ 78 | */ 79 | 80 | /* USER CODE BEGIN EXPORTED_TYPES */ 81 | 82 | /* USER CODE END EXPORTED_TYPES */ 83 | 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros 89 | * @brief Aliases. 90 | * @{ 91 | */ 92 | 93 | /* USER CODE BEGIN EXPORTED_MACRO */ 94 | 95 | /* USER CODE END EXPORTED_MACRO */ 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables 102 | * @brief Public variables. 103 | * @{ 104 | */ 105 | 106 | /** Descriptor for the Usb device. */ 107 | extern USBD_DescriptorsTypeDef FS_Desc; 108 | 109 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 110 | 111 | /* USER CODE END EXPORTED_VARIABLES */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype 118 | * @brief Public functions declaration. 119 | * @{ 120 | */ 121 | 122 | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ 123 | 124 | /* USER CODE END EXPORTED_FUNCTIONS */ 125 | 126 | /** 127 | * @} 128 | */ 129 | 130 | /** 131 | * @} 132 | */ 133 | 134 | /** 135 | * @} 136 | */ 137 | 138 | #ifdef __cplusplus 139 | } 140 | #endif 141 | 142 | #endif /* __USBD_DESC__C__ */ 143 | 144 | -------------------------------------------------------------------------------- /Core/Inc/usbd_gs_can.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016 Hubert Denkmair 6 | Copyright (c) 2022 Ryan Edwards (changes for STM32G0/G4 and CAN-FD) 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USBD_GS_CAN_H 30 | #define __USBD_GS_CAN_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | 37 | #include 38 | #include "main.h" 39 | #include "board.h" 40 | #include "FreeRTOS.h" 41 | #include "queue.h" 42 | #include "usbd_def.h" 43 | #include "gs_usb.h" 44 | #include "can.h" 45 | 46 | /* Exported defines -----------------------------------------------------------*/ 47 | #define CAN_DATA_MAX_PACKET_SIZE 64 /* Endpoint IN & OUT Packet size */ 48 | #define CAN_CMD_PACKET_SIZE 72 /* Control Endpoint Packet size */ 49 | #define USB_CAN_CONFIG_DESC_SIZ 50 50 | #define USBD_GS_CAN_VENDOR_CODE 0x20 51 | #define DFU_INTERFACE_NUM 1 52 | #define DFU_INTERFACE_STR_INDEX 0xE0 53 | 54 | extern USBD_ClassTypeDef USBD_GS_CAN; 55 | 56 | 57 | #if defined(CANFD_FEATURE_ENABLED) 58 | #if !defined(FDCAN1) 59 | #error This CAN type does not support CANFD!!! 60 | #endif 61 | #define GS_HOST_FRAME_SIZE struct_size((struct gs_host_frame *)NULL, canfd_ts, 1) 62 | #define GS_HOST_CLASSIC_FRAME_SIZE struct_size((struct gs_host_frame *)NULL, classic_can_ts, 1) 63 | #else 64 | #define GS_HOST_FRAME_SIZE struct_size((struct gs_host_frame *)NULL, classic_can_ts, 1) 65 | #endif 66 | 67 | struct gs_host_frame_object { 68 | union { 69 | uint8_t _buf[GS_HOST_FRAME_SIZE]; 70 | struct gs_host_frame frame; 71 | }; 72 | }; 73 | 74 | /* Exported types ------------------------------------------------------------*/ 75 | typedef struct { 76 | uint8_t ep0_buf[CAN_CMD_PACKET_SIZE]; 77 | __IO uint32_t TxState; 78 | USBD_SetupReqTypedef last_setup_request; 79 | struct gs_host_frame_object from_host_frame; 80 | CAN_HANDLE_TYPEDEF *channels[CAN_NUM_CHANNELS]; 81 | #if defined (USE_MULTICHANNEL_QUEUE) 82 | QueueHandle_t queue_from_hostHandle[CAN_NUM_CHANNELS]; 83 | #else 84 | QueueHandle_t queue_from_hostHandle; 85 | #endif 86 | QueueHandle_t queue_to_hostHandle; 87 | bool dfu_detach_requested; 88 | bool pad_pkts_to_max_pkt_size; 89 | bool timestamps_enabled; 90 | uint32_t sof_timestamp_us; 91 | } USBD_GS_CAN_HandleTypeDef __attribute__ ((aligned (4))); 92 | 93 | /* Exported functions --------------------------------------------------------*/ 94 | uint8_t USBD_GS_CAN_Init(USBD_HandleTypeDef *pdev, USBD_GS_CAN_HandleTypeDef *hcan); 95 | uint8_t USBD_GS_CAN_GetChannelNumber(USBD_HandleTypeDef *pdev, CAN_HANDLE_TYPEDEF* handle); 96 | bool USBD_GS_CAN_CustomDeviceRequest(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 97 | bool USBD_GS_CAN_CustomInterfaceRequest(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 98 | bool USBD_GS_CAN_DfuDetachRequested(USBD_HandleTypeDef *pdev); 99 | uint8_t USBD_GS_CAN_SendFrame(USBD_HandleTypeDef *pdev, struct gs_host_frame *frame); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /* __USBD_GS_CAN_H */ 106 | -------------------------------------------------------------------------------- /Core/Src/app_freertos.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file app_freertos.c 5 | * @author MCD Application Team 6 | * @brief Code for freertos applications 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2020 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "FreeRTOS.h" 23 | #include "task.h" 24 | #include "main.h" 25 | 26 | /* Private includes ----------------------------------------------------------*/ 27 | /* USER CODE BEGIN Includes */ 28 | 29 | /* USER CODE END Includes */ 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* USER CODE BEGIN PTD */ 33 | 34 | /* USER CODE END PTD */ 35 | 36 | /* Private define ------------------------------------------------------------*/ 37 | /* USER CODE BEGIN PD */ 38 | 39 | /* USER CODE END PD */ 40 | 41 | /* Private macro -------------------------------------------------------------*/ 42 | /* USER CODE BEGIN PM */ 43 | 44 | /* USER CODE END PM */ 45 | 46 | /* Private variables ---------------------------------------------------------*/ 47 | /* USER CODE BEGIN Variables */ 48 | 49 | /* USER CODE END Variables */ 50 | 51 | /* Private function prototypes -----------------------------------------------*/ 52 | /* USER CODE BEGIN FunctionPrototypes */ 53 | 54 | /* USER CODE END FunctionPrototypes */ 55 | 56 | /* Private application code --------------------------------------------------*/ 57 | /* USER CODE BEGIN Application */ 58 | /* configSUPPORT_STATIC_ALLOCATION is set to 1, so the application must provide an 59 | * implementation of vApplicationGetIdleTaskMemory() to provide the memory that is 60 | * used by the Idle task. */ 61 | void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) 62 | { 63 | /* If the buffers to be provided to the Idle task are declared inside this 64 | * function then they must be declared static - otherwise they will be allocated on 65 | * the stack and so not exists after this function exits. */ 66 | static StaticTask_t xIdleTaskTCB; 67 | static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ]; 68 | 69 | /* Pass out a pointer to the StaticTask_t structure in which the Idle task's 70 | state will be stored. */ 71 | *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; 72 | 73 | /* Pass out the array that will be used as the Idle task's stack. */ 74 | *ppxIdleTaskStackBuffer = uxIdleTaskStack; 75 | 76 | /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer. 77 | Note that, as the array is necessarily of type StackType_t, 78 | configMINIMAL_STACK_SIZE is specified in words, not bytes. */ 79 | *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; 80 | } 81 | 82 | /* configSUPPORT_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the 83 | * application must provide an implementation of vApplicationGetTimerTaskMemory() 84 | * to provide the memory that is used by the Timer service task. */ 85 | void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ) 86 | { 87 | /* If the buffers to be provided to the Timer task are declared inside this 88 | * function then they must be declared static - otherwise they will be allocated on 89 | * the stack and so not exists after this function exits. */ 90 | static StaticTask_t xTimerTaskTCB; 91 | static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; 92 | 93 | /* Pass out a pointer to the StaticTask_t structure in which the Timer 94 | task's state will be stored. */ 95 | *ppxTimerTaskTCBBuffer = &xTimerTaskTCB; 96 | 97 | /* Pass out the array that will be used as the Timer task's stack. */ 98 | *ppxTimerTaskStackBuffer = uxTimerTaskStack; 99 | 100 | /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer. 101 | Note that, as the array is necessarily of type StackType_t, 102 | configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */ 103 | *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; 104 | } 105 | /* USER CODE END Application */ 106 | 107 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 108 | -------------------------------------------------------------------------------- /Core/Src/led.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2022 Ryan Edwards 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | #include "main.h" 28 | #include "board.h" 29 | #include "led.h" 30 | 31 | /** @brief Function to initialize the LED handle 32 | * @param LED_HandleTypeDef* hled - The pointer to the handle. 33 | * @param GPIO_TypeDef *GPIOx - The pointer to the GPIO port. 34 | * @param uint16_t GPIO_Pin - The pin number. 35 | * @param led_mode_t led_mode - The desired initial mode. 36 | * @param uint8_t led_active_level - Define if the LED is active HIGH or LOW. 37 | * @retval None 38 | */ 39 | void led_init(LED_HandleTypeDef* hled, GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, led_mode_t led_mode, uint8_t led_active_level) 40 | { 41 | hled->GPIOx = GPIOx; 42 | hled->GPIO_Pin = GPIO_Pin; 43 | hled->led_mode = led_mode; 44 | hled->prev_led_mode = led_mode; 45 | hled->led_active_level = led_active_level; 46 | /* start with the LED inactive at init */ 47 | HAL_GPIO_WritePin(hled->GPIOx, hled->GPIO_Pin, !led_active_level); 48 | 49 | } 50 | 51 | /** @brief Function to be called periodically to update the specific handle 52 | * @param LED_HandleTypeDef* hled - The pointer to the handle. 53 | * @retval None 54 | */ 55 | void led_update(LED_HandleTypeDef* hled) 56 | { 57 | 58 | /* check this handle for it's current mode and update the output accordingly */ 59 | switch (hled->led_mode) { 60 | case LED_MODE_INACTIVE: 61 | HAL_GPIO_WritePin(hled->GPIOx, hled->GPIO_Pin, !hled->led_active_level); 62 | break; 63 | case LED_MODE_ACTIVE: 64 | HAL_GPIO_WritePin(hled->GPIOx, hled->GPIO_Pin, hled->led_active_level); 65 | break; 66 | case LED_MODE_RXTX_ACTIVE: 67 | if ((HAL_GetTick() - hled->led_rxtx_start_tick) > LED_RXTX_ACTIVE_TIME_MS) { 68 | /* Turn off LED and change the mode to OFF */ 69 | HAL_GPIO_WritePin(hled->GPIOx, hled->GPIO_Pin, !hled->led_active_level); 70 | hled->led_mode = LED_MODE_RXTX_HOLDOFF; 71 | hled->led_rxtx_start_tick = HAL_GetTick(); 72 | } 73 | break; 74 | case LED_MODE_RXTX_HOLDOFF: 75 | /* prevent LED from going solid ON for high traffic */ 76 | if ((HAL_GetTick() - hled->led_rxtx_start_tick) > LED_RXTX_INACTIVE_TIME_MS) { 77 | /* Return the LED to it's previous state */ 78 | hled->led_mode = hled->prev_led_mode; 79 | } 80 | break; 81 | case LED_MODE_BLINK: 82 | if ((HAL_GetTick() - hled->blink_toggle_start_tick) > (hled->blink_period_ms/2)) { 83 | HAL_GPIO_TogglePin(hled->GPIOx, hled->GPIO_Pin); 84 | hled->blink_toggle_start_tick = HAL_GetTick(); 85 | } 86 | default: 87 | break; 88 | } 89 | } 90 | 91 | /** @brief Function to read the LED current mode 92 | * @param LED_HandleTypeDef* hled - The pointer to the handle. 93 | * @retval led_mode_t - the enumeratred led mode 94 | */ 95 | led_mode_t led_get_mode(LED_HandleTypeDef* hled) 96 | { 97 | return hled->led_mode; 98 | } 99 | 100 | /** @brief Function to set the LED into it's active mode 101 | * @param LED_HandleTypeDef* hled - The pointer to the handle. 102 | * @retval None 103 | */ 104 | void led_set_active(LED_HandleTypeDef* hled) 105 | { 106 | /* set the mode flag - the handler will update the GPIO */ 107 | hled->prev_led_mode = LED_MODE_ACTIVE; 108 | hled->led_mode = LED_MODE_ACTIVE; 109 | } 110 | 111 | /** @brief Function to set the LED into it's inactive mode 112 | * @param LED_HandleTypeDef* hled - The pointer to the handle. 113 | * @retval None 114 | */ 115 | void led_set_inactive(LED_HandleTypeDef* hled) 116 | { 117 | /* set the mode flag - the handler will update the GPIO */ 118 | hled->prev_led_mode = LED_MODE_INACTIVE; 119 | hled->led_mode = LED_MODE_INACTIVE; 120 | } 121 | 122 | /** @brief Function to indicate to the LED handler that an RX or TX event took place to pulse the output 123 | * @param LED_HandleTypeDef* hled - The pointer to the handle. 124 | * @retval None 125 | */ 126 | void led_indicate_rxtx(LED_HandleTypeDef* hled) 127 | { 128 | /* check to see if we have already started to indicate an RXTX to prevent steady state LED on high message rates */ 129 | if ((hled->led_mode != LED_MODE_RXTX_ACTIVE) && (hled->led_mode != LED_MODE_RXTX_HOLDOFF)) { 130 | /* turn on the LED for a brief period of time to indicate a message was sent */ 131 | HAL_GPIO_WritePin(hled->GPIOx, hled->GPIO_Pin, hled->led_active_level); 132 | hled->led_mode = LED_MODE_RXTX_ACTIVE; 133 | hled->led_rxtx_start_tick = HAL_GetTick(); 134 | } 135 | } 136 | 137 | /** @brief Function to initiate a blink pattern on the LED 138 | * @param LED_HandleTypeDef* hled - The pointer to the handle. 139 | * @param uint32_t period_ms - The period in ms that the LED should blink. 140 | * @retval None 141 | */ 142 | void led_blink_start(LED_HandleTypeDef* hled, uint32_t period_ms) 143 | { 144 | hled->blink_period_ms = period_ms; 145 | hled->led_mode = LED_MODE_BLINK; 146 | hled->blink_toggle_start_tick = HAL_GetTick(); 147 | } 148 | 149 | /** @brief Function to stop a blink pattern on the LED 150 | * @param LED_HandleTypeDef* hled - The pointer to the handle. 151 | * @retval None 152 | */ 153 | void led_blink_stop(LED_HandleTypeDef* hled) 154 | { 155 | hled->led_mode = hled->prev_led_mode; 156 | } 157 | -------------------------------------------------------------------------------- /Core/Src/syscalls.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file syscalls.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @brief STM32CubeIDE Minimal System calls file 6 | * 7 | * For more information about which c-functions 8 | * need which of these lowlevel functions 9 | * please consult the Newlib libc-manual 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | * Copyright (c) 2022 STMicroelectronics. 14 | * All rights reserved. 15 | * 16 | * This software is licensed under terms that can be found in the LICENSE file 17 | * in the root directory of this software component. 18 | * If no LICENSE file comes with this software, it is provided AS-IS. 19 | * 20 | ****************************************************************************** 21 | */ 22 | 23 | /* Includes */ 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | 34 | /* Variables */ 35 | extern int __io_putchar(int ch) __attribute__((weak)); 36 | extern int __io_getchar(void) __attribute__((weak)); 37 | 38 | 39 | char *__env[1] = { 0 }; 40 | char **environ = __env; 41 | 42 | 43 | /* Functions */ 44 | void initialise_monitor_handles() 45 | { 46 | } 47 | 48 | int _getpid(void) 49 | { 50 | return 1; 51 | } 52 | 53 | int _kill(int pid, int sig) 54 | { 55 | errno = EINVAL; 56 | return -1; 57 | } 58 | 59 | void _exit (int status) 60 | { 61 | _kill(status, -1); 62 | while (1) {} /* Make sure we hang here */ 63 | } 64 | 65 | __attribute__((weak)) int _read(int file, char *ptr, int len) 66 | { 67 | int DataIdx; 68 | 69 | for (DataIdx = 0; DataIdx < len; DataIdx++) 70 | { 71 | *ptr++ = __io_getchar(); 72 | } 73 | 74 | return len; 75 | } 76 | 77 | __attribute__((weak)) int _write(int file, char *ptr, int len) 78 | { 79 | int DataIdx; 80 | 81 | for (DataIdx = 0; DataIdx < len; DataIdx++) 82 | { 83 | __io_putchar(*ptr++); 84 | } 85 | return len; 86 | } 87 | 88 | int _close(int file) 89 | { 90 | return -1; 91 | } 92 | 93 | 94 | int _fstat(int file, struct stat *st) 95 | { 96 | st->st_mode = S_IFCHR; 97 | return 0; 98 | } 99 | 100 | int _isatty(int file) 101 | { 102 | return 1; 103 | } 104 | 105 | int _lseek(int file, int ptr, int dir) 106 | { 107 | return 0; 108 | } 109 | 110 | int _open(char *path, int flags, ...) 111 | { 112 | /* Pretend like we always fail */ 113 | return -1; 114 | } 115 | 116 | int _wait(int *status) 117 | { 118 | errno = ECHILD; 119 | return -1; 120 | } 121 | 122 | int _unlink(char *name) 123 | { 124 | errno = ENOENT; 125 | return -1; 126 | } 127 | 128 | int _times(struct tms *buf) 129 | { 130 | return -1; 131 | } 132 | 133 | int _stat(char *file, struct stat *st) 134 | { 135 | st->st_mode = S_IFCHR; 136 | return 0; 137 | } 138 | 139 | int _link(char *old, char *new) 140 | { 141 | errno = EMLINK; 142 | return -1; 143 | } 144 | 145 | int _fork(void) 146 | { 147 | errno = EAGAIN; 148 | return -1; 149 | } 150 | 151 | int _execve(char *name, char **argv, char **env) 152 | { 153 | errno = ENOMEM; 154 | return -1; 155 | } 156 | -------------------------------------------------------------------------------- /Core/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file sysmem.c 4 | * @author Generated by STM32CubeIDE 5 | * @brief STM32CubeIDE System Memory calls file 6 | * 7 | * For more information about which C functions 8 | * need which of these lowlevel functions 9 | * please consult the newlib libc manual 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | * Copyright (c) 2022 STMicroelectronics. 14 | * All rights reserved. 15 | * 16 | * This software is licensed under terms that can be found in the LICENSE file 17 | * in the root directory of this software component. 18 | * If no LICENSE file comes with this software, it is provided AS-IS. 19 | * 20 | ****************************************************************************** 21 | */ 22 | 23 | /* Includes */ 24 | #include 25 | #include 26 | 27 | /** 28 | * Pointer to the current high watermark of the heap usage 29 | */ 30 | static uint8_t *__sbrk_heap_end = NULL; 31 | 32 | /** 33 | * @brief _sbrk() allocates memory to the newlib heap and is used by malloc 34 | * and others from the C library 35 | * 36 | * @verbatim 37 | * ############################################################################ 38 | * # .data # .bss # newlib heap # MSP stack # 39 | * # # # # Reserved by _Min_Stack_Size # 40 | * ############################################################################ 41 | * ^-- RAM start ^-- _end _estack, RAM end --^ 42 | * @endverbatim 43 | * 44 | * This implementation starts allocating at the '_end' linker symbol 45 | * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack 46 | * The implementation considers '_estack' linker symbol to be RAM end 47 | * NOTE: If the MSP stack, at any point during execution, grows larger than the 48 | * reserved size, please increase the '_Min_Stack_Size'. 49 | * 50 | * @param incr Memory size 51 | * @return Pointer to allocated memory 52 | */ 53 | void *_sbrk(ptrdiff_t incr) 54 | { 55 | extern uint8_t _end; /* Symbol defined in the linker script */ 56 | extern uint8_t _estack; /* Symbol defined in the linker script */ 57 | extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */ 58 | const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; 59 | const uint8_t *max_heap = (uint8_t *)stack_limit; 60 | uint8_t *prev_heap_end; 61 | 62 | /* Initialize heap end at first call */ 63 | if (NULL == __sbrk_heap_end) 64 | { 65 | __sbrk_heap_end = &_end; 66 | } 67 | 68 | /* Protect heap from growing into the reserved MSP stack */ 69 | if (__sbrk_heap_end + incr > max_heap) 70 | { 71 | errno = ENOMEM; 72 | return (void *)-1; 73 | } 74 | 75 | prev_heap_end = __sbrk_heap_end; 76 | __sbrk_heap_end += incr; 77 | 78 | return (void *)prev_heap_end; 79 | } 80 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ryan Edwards 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_req.h 4 | * @author MCD Application Team 5 | * @brief Header file for the usbd_req.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __USB_REQUEST_H 21 | #define __USB_REQUEST_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbd_def.h" 29 | 30 | 31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 32 | * @{ 33 | */ 34 | 35 | /** @defgroup USBD_REQ 36 | * @brief header file for the usbd_req.c file 37 | * @{ 38 | */ 39 | 40 | /** @defgroup USBD_REQ_Exported_Defines 41 | * @{ 42 | */ 43 | /** 44 | * @} 45 | */ 46 | 47 | 48 | /** @defgroup USBD_REQ_Exported_Types 49 | * @{ 50 | */ 51 | /** 52 | * @} 53 | */ 54 | 55 | 56 | 57 | /** @defgroup USBD_REQ_Exported_Macros 58 | * @{ 59 | */ 60 | /** 61 | * @} 62 | */ 63 | 64 | /** @defgroup USBD_REQ_Exported_Variables 65 | * @{ 66 | */ 67 | /** 68 | * @} 69 | */ 70 | 71 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype 72 | * @{ 73 | */ 74 | 75 | USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 76 | USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 77 | USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 78 | 79 | void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 80 | void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata); 81 | void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len); 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif /* __USB_REQUEST_H */ 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | 102 | -------------------------------------------------------------------------------- /Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.h 4 | * @author MCD Application Team 5 | * @brief Header file for the usbd_ioreq.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __USBD_IOREQ_H 21 | #define __USBD_IOREQ_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usbd_def.h" 29 | #include "usbd_core.h" 30 | 31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 32 | * @{ 33 | */ 34 | 35 | /** @defgroup USBD_IOREQ 36 | * @brief header file for the usbd_ioreq.c file 37 | * @{ 38 | */ 39 | 40 | /** @defgroup USBD_IOREQ_Exported_Defines 41 | * @{ 42 | */ 43 | /** 44 | * @} 45 | */ 46 | 47 | 48 | /** @defgroup USBD_IOREQ_Exported_Types 49 | * @{ 50 | */ 51 | 52 | 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | 59 | /** @defgroup USBD_IOREQ_Exported_Macros 60 | * @{ 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @defgroup USBD_IOREQ_Exported_Variables 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype 76 | * @{ 77 | */ 78 | 79 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, 80 | uint8_t *pbuf, uint32_t len); 81 | 82 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, 83 | uint8_t *pbuf, uint32_t len); 84 | 85 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, 86 | uint8_t *pbuf, uint32_t len); 87 | 88 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, 89 | uint8_t *pbuf, uint32_t len); 90 | 91 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev); 92 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev); 93 | 94 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | #ifdef __cplusplus 101 | } 102 | #endif 103 | 104 | #endif /* __USBD_IOREQ_H */ 105 | 106 | /** 107 | * @} 108 | */ 109 | 110 | /** 111 | * @} 112 | */ 113 | 114 | -------------------------------------------------------------------------------- /Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.c 4 | * @author MCD Application Team 5 | * @brief This file provides the IO requests APIs for control endpoints. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "usbd_ioreq.h" 21 | 22 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 23 | * @{ 24 | */ 25 | 26 | 27 | /** @defgroup USBD_IOREQ 28 | * @brief control I/O requests module 29 | * @{ 30 | */ 31 | 32 | /** @defgroup USBD_IOREQ_Private_TypesDefinitions 33 | * @{ 34 | */ 35 | /** 36 | * @} 37 | */ 38 | 39 | 40 | /** @defgroup USBD_IOREQ_Private_Defines 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_IOREQ_Private_Macros 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | /** @defgroup USBD_IOREQ_Private_Variables 58 | * @{ 59 | */ 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | 66 | /** @defgroup USBD_IOREQ_Private_FunctionPrototypes 67 | * @{ 68 | */ 69 | /** 70 | * @} 71 | */ 72 | 73 | 74 | /** @defgroup USBD_IOREQ_Private_Functions 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @brief USBD_CtlSendData 80 | * send data on the ctl pipe 81 | * @param pdev: device instance 82 | * @param buff: pointer to data buffer 83 | * @param len: length of data to be sent 84 | * @retval status 85 | */ 86 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, 87 | uint8_t *pbuf, uint32_t len) 88 | { 89 | /* Set EP0 State */ 90 | pdev->ep0_state = USBD_EP0_DATA_IN; 91 | pdev->ep_in[0].total_length = len; 92 | 93 | #ifdef USBD_AVOID_PACKET_SPLIT_MPS 94 | pdev->ep_in[0].rem_length = 0U; 95 | #else 96 | pdev->ep_in[0].rem_length = len; 97 | #endif /* USBD_AVOID_PACKET_SPLIT_MPS */ 98 | 99 | /* Start the transfer */ 100 | (void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len); 101 | 102 | return USBD_OK; 103 | } 104 | 105 | /** 106 | * @brief USBD_CtlContinueSendData 107 | * continue sending data on the ctl pipe 108 | * @param pdev: device instance 109 | * @param buff: pointer to data buffer 110 | * @param len: length of data to be sent 111 | * @retval status 112 | */ 113 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, 114 | uint8_t *pbuf, uint32_t len) 115 | { 116 | /* Start the next transfer */ 117 | (void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len); 118 | 119 | return USBD_OK; 120 | } 121 | 122 | /** 123 | * @brief USBD_CtlPrepareRx 124 | * receive data on the ctl pipe 125 | * @param pdev: device instance 126 | * @param buff: pointer to data buffer 127 | * @param len: length of data to be received 128 | * @retval status 129 | */ 130 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, 131 | uint8_t *pbuf, uint32_t len) 132 | { 133 | /* Set EP0 State */ 134 | pdev->ep0_state = USBD_EP0_DATA_OUT; 135 | pdev->ep_out[0].total_length = len; 136 | 137 | #ifdef USBD_AVOID_PACKET_SPLIT_MPS 138 | pdev->ep_out[0].rem_length = 0U; 139 | #else 140 | pdev->ep_out[0].rem_length = len; 141 | #endif /* USBD_AVOID_PACKET_SPLIT_MPS */ 142 | 143 | /* Start the transfer */ 144 | (void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 145 | 146 | return USBD_OK; 147 | } 148 | 149 | /** 150 | * @brief USBD_CtlContinueRx 151 | * continue receive data on the ctl pipe 152 | * @param pdev: device instance 153 | * @param buff: pointer to data buffer 154 | * @param len: length of data to be received 155 | * @retval status 156 | */ 157 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, 158 | uint8_t *pbuf, uint32_t len) 159 | { 160 | (void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 161 | 162 | return USBD_OK; 163 | } 164 | 165 | /** 166 | * @brief USBD_CtlSendStatus 167 | * send zero lzngth packet on the ctl pipe 168 | * @param pdev: device instance 169 | * @retval status 170 | */ 171 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev) 172 | { 173 | /* Set EP0 State */ 174 | pdev->ep0_state = USBD_EP0_STATUS_IN; 175 | 176 | /* Start the transfer */ 177 | (void)USBD_LL_Transmit(pdev, 0x00U, NULL, 0U); 178 | 179 | return USBD_OK; 180 | } 181 | 182 | /** 183 | * @brief USBD_CtlReceiveStatus 184 | * receive zero lzngth packet on the ctl pipe 185 | * @param pdev: device instance 186 | * @retval status 187 | */ 188 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev) 189 | { 190 | /* Set EP0 State */ 191 | pdev->ep0_state = USBD_EP0_STATUS_OUT; 192 | 193 | /* Start the transfer */ 194 | (void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); 195 | 196 | return USBD_OK; 197 | } 198 | 199 | /** 200 | * @brief USBD_GetRxCount 201 | * returns the received data length 202 | * @param pdev: device instance 203 | * @param ep_addr: endpoint address 204 | * @retval Rx Data blength 205 | */ 206 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 207 | { 208 | return USBD_LL_GetRxDataSize(pdev, ep_addr); 209 | } 210 | 211 | /** 212 | * @} 213 | */ 214 | 215 | 216 | /** 217 | * @} 218 | */ 219 | 220 | 221 | /** 222 | * @} 223 | */ 224 | 225 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/README.md: -------------------------------------------------------------------------------- 1 | ## Getting started 2 | This repository contains FreeRTOS kernel source/header files and kernel ports only. This repository is referenced as a submodule in [FreeRTOS/FreeRTOS](https://github.com/FreeRTOS/FreeRTOS) repository, which contains pre-configured demo application projects under ```FreeRTOS/Demo``` directory. 3 | 4 | The easiest way to use FreeRTOS is to start with one of the pre-configured demo application projects. That way you will have the correct FreeRTOS source files included, and the correct include paths configured. Once a demo application is building and executing you can remove the demo application files, and start to add in your own application source files. See the [FreeRTOS Kernel Quick Start Guide](https://www.FreeRTOS.org/FreeRTOS-quick-start-guide.html) for detailed instructions and other useful links. 5 | 6 | Additionally, for FreeRTOS kernel feature information refer to the [Developer Documentation](https://www.FreeRTOS.org/features.html), and [API Reference](https://www.FreeRTOS.org/a00106.html). 7 | 8 | ### Getting help 9 | If you have any questions or need assistance troubleshooting your FreeRTOS project, we have an active community that can help on the [FreeRTOS Community Support Forum](https://forums.freertos.org). 10 | 11 | ## Cloning this repository 12 | 13 | To clone using HTTPS: 14 | ``` 15 | git clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git 16 | ``` 17 | Using SSH: 18 | ``` 19 | git clone git@github.com:FreeRTOS/FreeRTOS-Kernel.git 20 | ``` 21 | 22 | ## Repository structure 23 | - The root of this repository contains the three files that are common to 24 | every port - list.c, queue.c and tasks.c. The kernel is contained within these 25 | three files. croutine.c implements the optional co-routine functionality - which 26 | is normally only used on very memory limited systems. 27 | 28 | - The ```./portable``` directory contains the files that are specific to a particular microcontroller and/or compiler. 29 | See the readme file in the ```./portable``` directory for more information. 30 | 31 | - The ```./include``` directory contains the real time kernel header files. 32 | 33 | ### Code Formatting 34 | FreeRTOS files are formatted using the "uncrustify" tool. The configuration file used by uncrustify can be found in the [FreeRTOS/FreeRTOS repository](https://github.com/FreeRTOS/FreeRTOS/blob/main/tools/uncrustify.cfg). 35 | 36 | ### Spelling 37 | *lexicon.txt* contains words that are not traditionally found in an English dictionary. It is used by the spellchecker to verify the various jargon, variable names, and other odd words used in the FreeRTOS code base. If your pull request fails to pass the spelling and you believe this is a mistake, then add the word to *lexicon.txt*. 38 | Note that only the FreeRTOS Kernel source files are checked for proper spelling, the portable section is ignored. 39 | 40 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/include/StackMacros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.5.0 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * 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, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | * 24 | * https://www.FreeRTOS.org 25 | * https://github.com/FreeRTOS 26 | * 27 | */ 28 | 29 | 30 | #ifndef _MSC_VER /* Visual Studio doesn't support #warning. */ 31 | #warning The name of this file has changed to stack_macros.h. Please update your code accordingly. This source file (which has the original name) will be removed in a future release. 32 | #endif 33 | 34 | #include "stack_macros.h" 35 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/include/stdint.readme: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.5.0 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * 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, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | * 24 | * https://www.FreeRTOS.org 25 | * https://github.com/FreeRTOS 26 | * 27 | */ 28 | 29 | #ifndef FREERTOS_STDINT 30 | #define FREERTOS_STDINT 31 | 32 | /******************************************************************************* 33 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 34 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 35 | * built using compilers that do not provide their own stdint.h definition. 36 | * 37 | * To use this file: 38 | * 39 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 40 | * header file, as that directory will already be in the compiler's include 41 | * path. 42 | * 43 | * 2) Rename the copied file stdint.h. 44 | * 45 | */ 46 | 47 | typedef signed char int8_t; 48 | typedef unsigned char uint8_t; 49 | typedef short int16_t; 50 | typedef unsigned short uint16_t; 51 | typedef long int32_t; 52 | typedef unsigned long uint32_t; 53 | 54 | #ifndef SIZE_MAX 55 | #define SIZE_MAX ( ( size_t ) -1 ) 56 | #endif 57 | 58 | #endif /* FREERTOS_STDINT */ 59 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/portable/GCC/ARM_CM0/portmacro.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.5.0 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * 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, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | * 24 | * https://www.FreeRTOS.org 25 | * https://github.com/FreeRTOS 26 | * 27 | */ 28 | 29 | 30 | #ifndef PORTMACRO_H 31 | #define PORTMACRO_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /*----------------------------------------------------------- 38 | * Port specific definitions. 39 | * 40 | * The settings in this file configure FreeRTOS correctly for the 41 | * given hardware and compiler. 42 | * 43 | * These settings should not be altered. 44 | *----------------------------------------------------------- 45 | */ 46 | 47 | /* Type definitions. */ 48 | #define portCHAR char 49 | #define portFLOAT float 50 | #define portDOUBLE double 51 | #define portLONG long 52 | #define portSHORT short 53 | #define portSTACK_TYPE uint32_t 54 | #define portBASE_TYPE long 55 | 56 | typedef portSTACK_TYPE StackType_t; 57 | typedef long BaseType_t; 58 | typedef unsigned long UBaseType_t; 59 | 60 | #if ( configUSE_16_BIT_TICKS == 1 ) 61 | typedef uint16_t TickType_t; 62 | #define portMAX_DELAY ( TickType_t ) 0xffff 63 | #else 64 | typedef uint32_t TickType_t; 65 | #define portMAX_DELAY ( TickType_t ) 0xffffffffUL 66 | 67 | /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do 68 | * not need to be guarded with a critical section. */ 69 | #define portTICK_TYPE_IS_ATOMIC 1 70 | #endif 71 | /*-----------------------------------------------------------*/ 72 | 73 | /* Architecture specifics. */ 74 | #define portSTACK_GROWTH ( -1 ) 75 | #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) 76 | #define portBYTE_ALIGNMENT 8 77 | #define portDONT_DISCARD __attribute__( ( used ) ) 78 | /*-----------------------------------------------------------*/ 79 | 80 | 81 | /* Scheduler utilities. */ 82 | extern void vPortYield( void ); 83 | #define portNVIC_INT_CTRL_REG ( *( ( volatile uint32_t * ) 0xe000ed04 ) ) 84 | #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) 85 | #define portYIELD() vPortYield() 86 | #define portEND_SWITCHING_ISR( xSwitchRequired ) do { if( xSwitchRequired ) portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; } while( 0 ) 87 | #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) 88 | /*-----------------------------------------------------------*/ 89 | 90 | 91 | /* Critical section management. */ 92 | extern void vPortEnterCritical( void ); 93 | extern void vPortExitCritical( void ); 94 | extern uint32_t ulSetInterruptMaskFromISR( void ) __attribute__( ( naked ) ); 95 | extern void vClearInterruptMaskFromISR( uint32_t ulMask ) __attribute__( ( naked ) ); 96 | 97 | #define portSET_INTERRUPT_MASK_FROM_ISR() ulSetInterruptMaskFromISR() 98 | #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) vClearInterruptMaskFromISR( x ) 99 | #define portDISABLE_INTERRUPTS() __asm volatile ( " cpsid i " ::: "memory" ) 100 | #define portENABLE_INTERRUPTS() __asm volatile ( " cpsie i " ::: "memory" ) 101 | #define portENTER_CRITICAL() vPortEnterCritical() 102 | #define portEXIT_CRITICAL() vPortExitCritical() 103 | 104 | /*-----------------------------------------------------------*/ 105 | 106 | /* Tickless idle/low power functionality. */ 107 | #ifndef portSUPPRESS_TICKS_AND_SLEEP 108 | extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ); 109 | #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) vPortSuppressTicksAndSleep( xExpectedIdleTime ) 110 | #endif 111 | /*-----------------------------------------------------------*/ 112 | 113 | /* Task function macros as described on the FreeRTOS.org WEB site. */ 114 | #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) 115 | #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters ) 116 | 117 | #define portNOP() 118 | 119 | #define portMEMORY_BARRIER() __asm volatile ( "" ::: "memory" ) 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | 125 | #endif /* PORTMACRO_H */ 126 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/portable/MemMang/ReadMe.url: -------------------------------------------------------------------------------- 1 | [{000214A0-0000-0000-C000-000000000046}] 2 | Prop3=19,2 3 | [InternetShortcut] 4 | URL=https://www.FreeRTOS.org/a00111.html 5 | IDList= 6 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/portable/MemMang/heap_1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.5.0 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * 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, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | * 24 | * https://www.FreeRTOS.org 25 | * https://github.com/FreeRTOS 26 | * 27 | */ 28 | 29 | 30 | /* 31 | * The simplest possible implementation of pvPortMalloc(). Note that this 32 | * implementation does NOT allow allocated memory to be freed again. 33 | * 34 | * See heap_2.c, heap_3.c and heap_4.c for alternative implementations, and the 35 | * memory management pages of https://www.FreeRTOS.org for more information. 36 | */ 37 | #include 38 | 39 | /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining 40 | * all the API functions to use the MPU wrappers. That should only be done when 41 | * task.h is included from an application file. */ 42 | #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE 43 | 44 | #include "FreeRTOS.h" 45 | #include "task.h" 46 | 47 | #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 48 | 49 | #if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) 50 | #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 51 | #endif 52 | 53 | /* A few bytes might be lost to byte aligning the heap start address. */ 54 | #define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT ) 55 | 56 | /* Allocate the memory for the heap. */ 57 | #if ( configAPPLICATION_ALLOCATED_HEAP == 1 ) 58 | 59 | /* The application writer has already defined the array used for the RTOS 60 | * heap - probably so it can be placed in a special segment or address. */ 61 | extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; 62 | #else 63 | static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; 64 | #endif /* configAPPLICATION_ALLOCATED_HEAP */ 65 | 66 | /* Index into the ucHeap array. */ 67 | static size_t xNextFreeByte = ( size_t ) 0; 68 | 69 | /*-----------------------------------------------------------*/ 70 | 71 | void * pvPortMalloc( size_t xWantedSize ) 72 | { 73 | void * pvReturn = NULL; 74 | static uint8_t * pucAlignedHeap = NULL; 75 | 76 | /* Ensure that blocks are always aligned. */ 77 | #if ( portBYTE_ALIGNMENT != 1 ) 78 | { 79 | if( xWantedSize & portBYTE_ALIGNMENT_MASK ) 80 | { 81 | /* Byte alignment required. Check for overflow. */ 82 | if( ( xWantedSize + ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ) ) > xWantedSize ) 83 | { 84 | xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); 85 | } 86 | else 87 | { 88 | xWantedSize = 0; 89 | } 90 | } 91 | } 92 | #endif /* if ( portBYTE_ALIGNMENT != 1 ) */ 93 | 94 | vTaskSuspendAll(); 95 | { 96 | if( pucAlignedHeap == NULL ) 97 | { 98 | /* Ensure the heap starts on a correctly aligned boundary. */ 99 | pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT - 1 ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); 100 | } 101 | 102 | /* Check there is enough room left for the allocation and. */ 103 | if( ( xWantedSize > 0 ) && /* valid size */ 104 | ( ( xNextFreeByte + xWantedSize ) < configADJUSTED_HEAP_SIZE ) && 105 | ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) ) /* Check for overflow. */ 106 | { 107 | /* Return the next free byte then increment the index past this 108 | * block. */ 109 | pvReturn = pucAlignedHeap + xNextFreeByte; 110 | xNextFreeByte += xWantedSize; 111 | } 112 | 113 | traceMALLOC( pvReturn, xWantedSize ); 114 | } 115 | ( void ) xTaskResumeAll(); 116 | 117 | #if ( configUSE_MALLOC_FAILED_HOOK == 1 ) 118 | { 119 | if( pvReturn == NULL ) 120 | { 121 | vApplicationMallocFailedHook(); 122 | } 123 | } 124 | #endif 125 | 126 | return pvReturn; 127 | } 128 | /*-----------------------------------------------------------*/ 129 | 130 | void vPortFree( void * pv ) 131 | { 132 | /* Memory cannot be freed using this scheme. See heap_2.c, heap_3.c and 133 | * heap_4.c for alternative implementations, and the memory management pages of 134 | * https://www.FreeRTOS.org for more information. */ 135 | ( void ) pv; 136 | 137 | /* Force an assert as it is invalid to call this function. */ 138 | configASSERT( pv == NULL ); 139 | } 140 | /*-----------------------------------------------------------*/ 141 | 142 | void vPortInitialiseBlocks( void ) 143 | { 144 | /* Only required when static memory is not cleared. */ 145 | xNextFreeByte = ( size_t ) 0; 146 | } 147 | /*-----------------------------------------------------------*/ 148 | 149 | size_t xPortGetFreeHeapSize( void ) 150 | { 151 | return( configADJUSTED_HEAP_SIZE - xNextFreeByte ); 152 | } 153 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/portable/MemMang/heap_3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.5.0 3 | * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * 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, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | * 24 | * https://www.FreeRTOS.org 25 | * https://github.com/FreeRTOS 26 | * 27 | */ 28 | 29 | 30 | /* 31 | * Implementation of pvPortMalloc() and vPortFree() that relies on the 32 | * compilers own malloc() and free() implementations. 33 | * 34 | * This file can only be used if the linker is configured to to generate 35 | * a heap memory area. 36 | * 37 | * See heap_1.c, heap_2.c and heap_4.c for alternative implementations, and the 38 | * memory management pages of https://www.FreeRTOS.org for more information. 39 | */ 40 | 41 | #include 42 | 43 | /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining 44 | * all the API functions to use the MPU wrappers. That should only be done when 45 | * task.h is included from an application file. */ 46 | #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE 47 | 48 | #include "FreeRTOS.h" 49 | #include "task.h" 50 | 51 | #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 52 | 53 | #if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) 54 | #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 55 | #endif 56 | 57 | /*-----------------------------------------------------------*/ 58 | 59 | void * pvPortMalloc( size_t xWantedSize ) 60 | { 61 | void * pvReturn; 62 | 63 | vTaskSuspendAll(); 64 | { 65 | pvReturn = malloc( xWantedSize ); 66 | traceMALLOC( pvReturn, xWantedSize ); 67 | } 68 | ( void ) xTaskResumeAll(); 69 | 70 | #if ( configUSE_MALLOC_FAILED_HOOK == 1 ) 71 | { 72 | if( pvReturn == NULL ) 73 | { 74 | vApplicationMallocFailedHook(); 75 | } 76 | } 77 | #endif 78 | 79 | return pvReturn; 80 | } 81 | /*-----------------------------------------------------------*/ 82 | 83 | void vPortFree( void * pv ) 84 | { 85 | if( pv != NULL ) 86 | { 87 | vTaskSuspendAll(); 88 | { 89 | free( pv ); 90 | traceFREE( pv, 0 ); 91 | } 92 | ( void ) xTaskResumeAll(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/portable/readme.txt: -------------------------------------------------------------------------------- 1 | Each real time kernel port consists of three files that contain the core kernel 2 | components and are common to every port, and one or more files that are 3 | specific to a particular microcontroller and/or compiler. 4 | 5 | 6 | + The FreeRTOS/Source/Portable/MemMang directory contains the five sample 7 | memory allocators as described on the https://www.FreeRTOS.org WEB site. 8 | 9 | + The other directories each contain files specific to a particular 10 | microcontroller or compiler, where the directory name denotes the compiler 11 | specific files the directory contains. 12 | 13 | 14 | 15 | For example, if you are interested in the [compiler] port for the [architecture] 16 | microcontroller, then the port specific files are contained in 17 | FreeRTOS/Source/Portable/[compiler]/[architecture] directory. If this is the 18 | only port you are interested in then all the other directories can be 19 | ignored. 20 | 21 | -------------------------------------------------------------------------------- /Portable/board_DevEBoxH7/Inc/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2022 Ryan Edwards 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __BOARD_H__ 29 | #define __BOARD_H__ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /* Includes ------------------------------------------------------------------*/ 36 | #include "usbd_def.h" 37 | 38 | #define BOARD_SYSMEM_RESET_VECTOR 0x1FFF0000 39 | 40 | #define USBD_VID 0x1D50 41 | #define USBD_LANGID_STRING 1033 42 | #define USBD_MANUFACTURER_STRING (uint8_t*) "budgetcan.io" 43 | #define USBD_PID_FS 0x606F 44 | #define USBD_PRODUCT_STRING_FS (uint8_t*) "budgetcan_h7" 45 | #define USBD_CONFIGURATION_STRING (uint8_t*) "gs_usb" 46 | #define USBD_INTERFACE_STRING (uint8_t*) "gs_usb interface" 47 | #define DFU_INTERFACE_STRING (uint8_t*) "budgetcan_h7 DFU interface" 48 | 49 | #define FDCAN_SJW_INIT 1 50 | #define FDCAN_BRP_INIT 8 51 | #define FDCAN_TS1_INIT 13 52 | #define FDCAN_TS2_INIT 2 53 | 54 | #define FDCAN_DATA_SJW_INIT 4 55 | #define FDCAN_DATA_BRP_INIT 2 56 | #define FDCAN_DATA_TS1_INIT 15 57 | #define FDCAN_DATA_TS2_INIT 4 58 | 59 | #define FDCAN_FRAME_FMT_INIT FDCAN_FRAME_FD_BRS 60 | #define FDCAN_MODE_INIT FDCAN_MODE_NORMAL 61 | #define FDCAN_AUTO_RETX_INIT DISABLE 62 | #define FDCAN_AUTO_TX_PAUSE_INIT DISABLE 63 | #define FDCAN_PROT_EXCPTN_INIT ENABLE 64 | #define FDCAN_STD_FLTR_NUM_INIT 0 65 | #define FDCAN_EXT_FLTR_NUM_INIT 0 66 | 67 | #define FDCAN_TX_FIFO_OPERATION_INIT FDCAN_TX_FIFO_OPERATION 68 | #define FDCAN_MSG_RAM_OFST_INIT 0 69 | #define FDCAN_RX_FIFO0_ELEM_NUM_INIT 64 70 | #define FDCAN_RX_FIFO0_ELEM_SZ_INIT FDCAN_DATA_BYTES_64 71 | #define FDCAN_RX_FIFO1_ELEM_NUM_INIT 64 72 | #define FDCAN_RX_FIFO1_ELEM_SZ_INIT FDCAN_DATA_BYTES_64 73 | #define FDCAN_RX_BUFF_NUM_INIT 64 74 | #define FDCAN_RX_BUFF_SZ_INIT FDCAN_DATA_BYTES_64 75 | #define FDCAN_TX_EVNT_NUM_INIT 32 76 | #define FDCAN_TX_BUFF_NUM_INIT 32 77 | #define FDCAN_TX_FIFO_ELEM_NUM_INIT 32 78 | #define FDCAN_TX_FIFO_ELEM_SZ_INIT FDCAN_DATA_BYTES_64 79 | 80 | #define CAN_NUM_CHANNELS 2 81 | #define CAN_CLOCK_SPEED 40000000 82 | #define CANFD_FEATURE_ENABLED 83 | 84 | #define BOARD_TIM2_PRESCALER 64-1 85 | 86 | #define QUEUE_SIZE_HOST_TO_DEV 32 87 | #define QUEUE_SIZE_DEV_TO_HOST 32 88 | 89 | #define USER_BTN_K1_Pin GPIO_PIN_3 90 | #define USER_BTN_K1_GPIO_Port GPIOE 91 | #define LED1_Pin GPIO_PIN_1 92 | #define LED1_GPIO_Port GPIOA 93 | #define USER_BTN_K2_Pin GPIO_PIN_5 94 | #define USER_BTN_K2_GPIO_Port GPIOC 95 | 96 | void SystemClock_Config(void); 97 | void MX_GPIO_Init(void); 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | #endif /*__ BOARD_H__ */ 103 | 104 | -------------------------------------------------------------------------------- /Portable/board_DevEBoxH7/Inc/board_hal_config.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32_hal_config.h 5 | * @brief This file contains the define to select the correct 6 | * HAL for this board 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32_HAL_CONFIG_H__ 22 | #define __STM32_HAL_CONFIG_H__ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32h7xx_hal.h" 30 | 31 | 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | #endif /*__STM32_HAL_CONFIG_H__ */ 37 | 38 | -------------------------------------------------------------------------------- /Portable/board_DevEBoxH7/Inc/stm32h7xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32h7xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32H7xx_IT_H 22 | #define __STM32H7xx_IT_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Private includes ----------------------------------------------------------*/ 29 | /* USER CODE BEGIN Includes */ 30 | 31 | /* USER CODE END Includes */ 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN ET */ 35 | 36 | /* USER CODE END ET */ 37 | 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* USER CODE BEGIN EC */ 40 | 41 | /* USER CODE END EC */ 42 | 43 | /* Exported macro ------------------------------------------------------------*/ 44 | /* USER CODE BEGIN EM */ 45 | 46 | /* USER CODE END EM */ 47 | 48 | /* Exported functions prototypes ---------------------------------------------*/ 49 | void NMI_Handler(void); 50 | void HardFault_Handler(void); 51 | void MemManage_Handler(void); 52 | void BusFault_Handler(void); 53 | void UsageFault_Handler(void); 54 | void DebugMon_Handler(void); 55 | void FDCAN1_IT0_IRQHandler(void); 56 | void FDCAN1_IT1_IRQHandler(void); 57 | void TIM1_UP_IRQHandler(void); 58 | void OTG_FS_IRQHandler(void); 59 | /* USER CODE BEGIN EFP */ 60 | 61 | /* USER CODE END EFP */ 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /* __STM32H7xx_IT_H */ 68 | -------------------------------------------------------------------------------- /Portable/board_DevEBoxH7/Src/stm32h7xx_hal_timebase_tim.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32h7xx_hal_timebase_TIM.c 5 | * @brief HAL time base based on the hardware TIM. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "stm32h7xx_hal.h" 22 | #include "stm32h7xx_hal_tim.h" 23 | 24 | /* Private typedef -----------------------------------------------------------*/ 25 | /* Private define ------------------------------------------------------------*/ 26 | /* Private macro -------------------------------------------------------------*/ 27 | /* Private variables ---------------------------------------------------------*/ 28 | TIM_HandleTypeDef htim1; 29 | /* Private function prototypes -----------------------------------------------*/ 30 | /* Private functions ---------------------------------------------------------*/ 31 | 32 | /** 33 | * @brief This function configures the TIM1 as a time base source. 34 | * The time source is configured to have 1ms time base with a dedicated 35 | * Tick interrupt priority. 36 | * @note This function is called automatically at the beginning of program after 37 | * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). 38 | * @param TickPriority: Tick interrupt priority. 39 | * @retval HAL status 40 | */ 41 | HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) 42 | { 43 | RCC_ClkInitTypeDef clkconfig; 44 | uint32_t uwTimclock; 45 | 46 | uint32_t uwPrescalerValue; 47 | uint32_t pFLatency; 48 | /*Configure the TIM1 IRQ priority */ 49 | if (TickPriority < (1UL << __NVIC_PRIO_BITS)) 50 | { 51 | HAL_NVIC_SetPriority(TIM1_UP_IRQn, TickPriority ,0U); 52 | 53 | /* Enable the TIM1 global Interrupt */ 54 | HAL_NVIC_EnableIRQ(TIM1_UP_IRQn); 55 | uwTickPrio = TickPriority; 56 | } 57 | else 58 | { 59 | return HAL_ERROR; 60 | } 61 | 62 | /* Enable TIM1 clock */ 63 | __HAL_RCC_TIM1_CLK_ENABLE(); 64 | 65 | /* Get clock configuration */ 66 | HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); 67 | 68 | /* Compute TIM1 clock */ 69 | uwTimclock = 2*HAL_RCC_GetPCLK2Freq(); 70 | 71 | /* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */ 72 | uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); 73 | 74 | /* Initialize TIM1 */ 75 | htim1.Instance = TIM1; 76 | 77 | /* Initialize TIMx peripheral as follow: 78 | + Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base. 79 | + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. 80 | + ClockDivision = 0 81 | + Counter direction = Up 82 | */ 83 | htim1.Init.Period = (1000000U / 1000U) - 1U; 84 | htim1.Init.Prescaler = uwPrescalerValue; 85 | htim1.Init.ClockDivision = 0; 86 | htim1.Init.CounterMode = TIM_COUNTERMODE_UP; 87 | 88 | if(HAL_TIM_Base_Init(&htim1) == HAL_OK) 89 | { 90 | /* Start the TIM time Base generation in interrupt mode */ 91 | return HAL_TIM_Base_Start_IT(&htim1); 92 | } 93 | 94 | /* Return function status */ 95 | return HAL_ERROR; 96 | } 97 | 98 | /** 99 | * @brief Suspend Tick increment. 100 | * @note Disable the tick increment by disabling TIM1 update interrupt. 101 | * @param None 102 | * @retval None 103 | */ 104 | void HAL_SuspendTick(void) 105 | { 106 | /* Disable TIM1 update Interrupt */ 107 | __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE); 108 | } 109 | 110 | /** 111 | * @brief Resume Tick increment. 112 | * @note Enable the tick increment by Enabling TIM1 update interrupt. 113 | * @param None 114 | * @retval None 115 | */ 116 | void HAL_ResumeTick(void) 117 | { 118 | /* Enable TIM1 Update interrupt */ 119 | __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE); 120 | } 121 | 122 | -------------------------------------------------------------------------------- /Portable/board_budgetcan_g0/Inc/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202112.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * http://www.FreeRTOS.org 23 | * http://aws.amazon.com/freertos 24 | * 25 | * 1 tab == 4 spaces! 26 | */ 27 | 28 | #ifndef FREERTOS_CONFIG_H 29 | #define FREERTOS_CONFIG_H 30 | 31 | /*----------------------------------------------------------- 32 | * Application specific definitions. 33 | * 34 | * These definitions should be adjusted for your particular hardware and 35 | * application requirements. 36 | * 37 | * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE 38 | * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 39 | * 40 | * See http://www.freertos.org/a00110.html 41 | *----------------------------------------------------------*/ 42 | 43 | /* Ensure definitions are only used by the compiler, and not by the assembler. */ 44 | #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) 45 | #include 46 | extern uint32_t SystemCoreClock; 47 | #endif 48 | 49 | #define configUSE_PREEMPTION 1 50 | #define configSUPPORT_STATIC_ALLOCATION 0 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configUSE_IDLE_HOOK 0 53 | #define configUSE_TICK_HOOK 0 54 | #define configCPU_CLOCK_HZ ( SystemCoreClock ) 55 | #define configTICK_RATE_HZ ((TickType_t) 1000 ) 56 | #define configMAX_PRIORITIES ( 5 ) 57 | #define configMINIMAL_STACK_SIZE ((unsigned short) 130 ) 58 | #define configTOTAL_HEAP_SIZE ((size_t) (75 * 1024) ) 59 | #define configMAX_TASK_NAME_LEN ( 5 ) 60 | #define configUSE_TRACE_FACILITY 1 61 | #define configUSE_16_BIT_TICKS 0 62 | #define configUSE_MUTEXES 1 63 | #define configQUEUE_REGISTRY_SIZE 8 64 | #define configUSE_RECURSIVE_MUTEXES 1 65 | #define configUSE_COUNTING_SEMAPHORES 1 66 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 67 | 68 | /* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */ 69 | /* Defaults to size_t for backward compatibility, but can be changed 70 | if lengths will always be less than the number of bytes in a size_t. */ 71 | #define configMESSAGE_BUFFER_LENGTH_TYPE size_t 72 | /* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */ 73 | 74 | /* Co-routine definitions. */ 75 | #define configUSE_CO_ROUTINES 0 76 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 77 | 78 | /* Software timer definitions. */ 79 | #define configUSE_TIMERS 0 80 | #define configTIMER_TASK_PRIORITY ( 2 ) 81 | #define configTIMER_QUEUE_LENGTH 10 82 | #define configTIMER_TASK_STACK_DEPTH 256 83 | 84 | /* The following flag must be enabled only when using newlib */ 85 | #define configUSE_NEWLIB_REENTRANT 0 86 | 87 | /* Set the following definitions to 1 to include the API function, or zero 88 | to exclude the API function. */ 89 | #define INCLUDE_vTaskPrioritySet 0 90 | #define INCLUDE_uxTaskPriorityGet 0 91 | #define INCLUDE_vTaskDelete 0 92 | #define INCLUDE_vTaskCleanUpResources 0 93 | #define INCLUDE_vTaskSuspend 0 94 | #define INCLUDE_vTaskDelayUntil 0 95 | #define INCLUDE_vTaskDelay 1 96 | #define INCLUDE_xTaskGetSchedulerState 0 97 | #define INCLUDE_xTimerPendFunctionCall 0 98 | #define INCLUDE_xQueueGetMutexHolder 0 99 | #define INCLUDE_uxTaskGetStackHighWaterMark 0 100 | #define INCLUDE_xTaskGetCurrentTaskHandle 1 101 | #define INCLUDE_eTaskGetState 1 102 | 103 | /* Normal assert() semantics without relying on the provision of an assert.h 104 | header file. */ 105 | #define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );} 106 | 107 | 108 | /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS 109 | standard names. */ 110 | #define vPortSVCHandler SVC_Handler 111 | #define xPortPendSVHandler PendSV_Handler 112 | #define xPortSysTickHandler SysTick_Handler 113 | 114 | #endif /* FREERTOS_CONFIG_H */ 115 | -------------------------------------------------------------------------------- /Portable/board_budgetcan_g0/Inc/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2022 Ryan Edwards 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __BOARD_H__ 29 | #define __BOARD_H__ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /* Includes ------------------------------------------------------------------*/ 36 | #include "usbd_def.h" 37 | 38 | #define BOARD_SYSMEM_RESET_VECTOR 0x1FFF0000 39 | 40 | #define USBD_VID 0x1D50 41 | #define USBD_LANGID_STRING 1033 42 | #define USBD_MANUFACTURER_STRING (uint8_t*) "budgetcan.io" 43 | #define USBD_PID_FS 0x606F 44 | #define USBD_PRODUCT_STRING_FS (uint8_t*) "budgetcan_g0" 45 | #define USBD_CONFIGURATION_STRING (uint8_t*) "gs_usb" 46 | #define USBD_INTERFACE_STRING (uint8_t*) "gs_usb interface" 47 | #define DFU_INTERFACE_STRING (uint8_t*) "budgetcan_g0 DFU interface" 48 | 49 | /* FDCAN init values for this board */ 50 | #define FDCAN_SJW_INIT 1 51 | #define FDCAN_BRP_INIT 8 52 | #define FDCAN_TS1_INIT 13 53 | #define FDCAN_TS2_INIT 2 54 | 55 | #define FDCAN_DATA_SJW_INIT 4 56 | #define FDCAN_DATA_BRP_INIT 2 57 | #define FDCAN_DATA_TS1_INIT 15 58 | #define FDCAN_DATA_TS2_INIT 4 59 | 60 | #define FDCAN_CLOCK_DIV_INIT FDCAN_CLOCK_DIV1 61 | #define FDCAN_FRAME_FMT_INIT FDCAN_FRAME_FD_BRS 62 | #define FDCAN_MODE_INIT FDCAN_MODE_NORMAL 63 | #define FDCAN_AUTO_RETX_INIT DISABLE 64 | #define FDCAN_AUTO_TX_PAUSE_INIT DISABLE 65 | #define FDCAN_PROT_EXCPTN_INIT ENABLE 66 | #define FDCAN_STD_FLTR_NUM_INIT 0 67 | #define FDCAN_EXT_FLTR_NUM_INIT 0 68 | #define FDCAN_TX_FIFO_OPERATION_INIT FDCAN_TX_FIFO_OPERATION 69 | 70 | #define CAN_NUM_CHANNELS 2 71 | #define CAN_CLOCK_SPEED 80000000 72 | #define CAN_TERM_FEATURE_ENABLED 73 | #define CANFD_FEATURE_ENABLED 74 | 75 | #define LIN_FEATURE_ENABLED 76 | #define LIN1_UART UART1 77 | #define LIN1_CHANNEL 0 78 | #define LIN_MAX_DATA_BYTES 8U 79 | #define LIN_CONFIG_MSG_ID_CMD 0x1FFFFE80 80 | #define LIN_CONFIG_MSG_ID_DATA 0x1FFFFE81 81 | #define LIN_GATEWAY_MSG_ID 0x1FFFFE82 82 | #define LIN_GATEWAY_CAN_CH hfdcan1 83 | 84 | #define QUEUE_SIZE_HOST_TO_DEV 32 85 | #define QUEUE_SIZE_DEV_TO_HOST 32 86 | 87 | #define FDCAN1_nSTANDBY_Pin GPIO_PIN_0 88 | #define FDCAN1_nSTANDBY_GPIO_Port GPIOA 89 | #define FDCAN1_TERM_EN_Pin GPIO_PIN_1 90 | #define FDCAN1_TERM_EN_GPIO_Port GPIOA 91 | #define FDCAN2_nSTANDBY_Pin GPIO_PIN_4 92 | #define FDCAN2_nSTANDBY_GPIO_Port GPIOA 93 | #define FDCAN2_TERM_EN_Pin GPIO_PIN_5 94 | #define FDCAN2_TERM_EN_GPIO_Port GPIOA 95 | #define SWCAN_M0_Pin GPIO_PIN_6 96 | #define SWCAN_M0_GPIO_Port GPIOA 97 | #define SWCAN_M1_Pin GPIO_PIN_7 98 | #define SWCAN_M1_GPIO_Port GPIOA 99 | #define LIN1_NSLP_Pin GPIO_PIN_6 100 | #define LIN1_NSLP_GPIO_Port GPIOC 101 | #define LED3_Pin GPIO_PIN_3 102 | #define LED3_GPIO_Port GPIOB 103 | #define LED2_Pin GPIO_PIN_4 104 | #define LED2_GPIO_Port GPIOB 105 | #define LED1_Pin GPIO_PIN_5 106 | #define LED1_GPIO_Port GPIOB 107 | 108 | void SystemClock_Config(void); 109 | void MX_GPIO_Init(void); 110 | 111 | #ifdef __cplusplus 112 | } 113 | #endif 114 | #endif /*__ BOARD_H__ */ 115 | 116 | -------------------------------------------------------------------------------- /Portable/board_budgetcan_g0/Inc/board_hal_config.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32_hal_config.h 5 | * @brief This file contains the define to select the correct 6 | * HAL for this board 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32_HAL_CONFIG_H__ 22 | #define __STM32_HAL_CONFIG_H__ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32g0xx_hal.h" 30 | 31 | 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | #endif /*__STM32_HAL_CONFIG_H__ */ 37 | 38 | -------------------------------------------------------------------------------- /Portable/board_budgetcan_g0/Inc/stm32g0xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32g0xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32G0xx_IT_H 22 | #define __STM32G0xx_IT_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Private includes ----------------------------------------------------------*/ 29 | /* USER CODE BEGIN Includes */ 30 | 31 | /* USER CODE END Includes */ 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN ET */ 35 | 36 | /* USER CODE END ET */ 37 | 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* USER CODE BEGIN EC */ 40 | 41 | /* USER CODE END EC */ 42 | 43 | /* Exported macro ------------------------------------------------------------*/ 44 | /* USER CODE BEGIN EM */ 45 | 46 | /* USER CODE END EM */ 47 | 48 | /* Exported functions prototypes ---------------------------------------------*/ 49 | void NMI_Handler(void); 50 | void HardFault_Handler(void); 51 | void USB_UCPD1_2_IRQHandler(void); 52 | void TIM1_BRK_UP_TRG_COM_IRQHandler(void); 53 | void TIM16_FDCAN_IT0_IRQHandler(void); 54 | void TIM17_FDCAN_IT1_IRQHandler(void); 55 | void USART1_IRQHandler(void); 56 | /* USER CODE BEGIN EFP */ 57 | 58 | /* USER CODE END EFP */ 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif /* __STM32G0xx_IT_H */ 65 | -------------------------------------------------------------------------------- /Portable/board_budgetcan_g0/STM32G0B1KETX_FLASH.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | ** 4 | ** @file : LinkerScript.ld 5 | ** 6 | ** @author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** @brief : Linker script for STM32G0B1KETx Device from STM32G0 series 9 | ** 512Kbytes FLASH 10 | ** 144Kbytes RAM 11 | ** 12 | ** Set heap size, stack size and stack location according 13 | ** to application requirements. 14 | ** 15 | ** Set memory bank area and size if external memory is used 16 | ** 17 | ** Target : STMicroelectronics STM32 18 | ** 19 | ** Distribution: The file is distributed as is, without any warranty 20 | ** of any kind. 21 | ** 22 | ****************************************************************************** 23 | ** @attention 24 | ** 25 | ** Copyright (c) 2022 STMicroelectronics. 26 | ** All rights reserved. 27 | ** 28 | ** This software is licensed under terms that can be found in the LICENSE file 29 | ** in the root directory of this software component. 30 | ** If no LICENSE file comes with this software, it is provided AS-IS. 31 | ** 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Entry Point */ 36 | ENTRY(Reset_Handler) 37 | 38 | /* Highest address of the user mode stack */ 39 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ 40 | 41 | _Min_Heap_Size = 1K; /* required amount of heap */ 42 | _Min_Stack_Size = 2K; /* required amount of stack */ 43 | 44 | /* Memories definition */ 45 | MEMORY 46 | { 47 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 144K 48 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K 49 | } 50 | 51 | /* Sections */ 52 | SECTIONS 53 | { 54 | /* The startup code into "FLASH" Rom type memory */ 55 | .isr_vector : 56 | { 57 | . = ALIGN(4); 58 | KEEP(*(.isr_vector)) /* Startup code */ 59 | . = ALIGN(4); 60 | } >FLASH 61 | 62 | /* The program code and other data into "FLASH" Rom type memory */ 63 | .text : 64 | { 65 | . = ALIGN(4); 66 | *(.text) /* .text sections (code) */ 67 | *(.text*) /* .text* sections (code) */ 68 | *(.glue_7) /* glue arm to thumb code */ 69 | *(.glue_7t) /* glue thumb to arm code */ 70 | *(.eh_frame) 71 | 72 | KEEP (*(.init)) 73 | KEEP (*(.fini)) 74 | 75 | . = ALIGN(4); 76 | _etext = .; /* define a global symbols at end of code */ 77 | } >FLASH 78 | 79 | /* Constant data into "FLASH" Rom type memory */ 80 | .rodata : 81 | { 82 | . = ALIGN(4); 83 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 84 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 85 | . = ALIGN(4); 86 | } >FLASH 87 | 88 | .ARM.extab : { 89 | . = ALIGN(4); 90 | *(.ARM.extab* .gnu.linkonce.armextab.*) 91 | . = ALIGN(4); 92 | } >FLASH 93 | 94 | .ARM : { 95 | . = ALIGN(4); 96 | __exidx_start = .; 97 | *(.ARM.exidx*) 98 | __exidx_end = .; 99 | . = ALIGN(4); 100 | } >FLASH 101 | 102 | .preinit_array : 103 | { 104 | . = ALIGN(4); 105 | PROVIDE_HIDDEN (__preinit_array_start = .); 106 | KEEP (*(.preinit_array*)) 107 | PROVIDE_HIDDEN (__preinit_array_end = .); 108 | . = ALIGN(4); 109 | } >FLASH 110 | 111 | .init_array : 112 | { 113 | . = ALIGN(4); 114 | PROVIDE_HIDDEN (__init_array_start = .); 115 | KEEP (*(SORT(.init_array.*))) 116 | KEEP (*(.init_array*)) 117 | PROVIDE_HIDDEN (__init_array_end = .); 118 | . = ALIGN(4); 119 | } >FLASH 120 | 121 | .fini_array : 122 | { 123 | . = ALIGN(4); 124 | PROVIDE_HIDDEN (__fini_array_start = .); 125 | KEEP (*(SORT(.fini_array.*))) 126 | KEEP (*(.fini_array*)) 127 | PROVIDE_HIDDEN (__fini_array_end = .); 128 | . = ALIGN(4); 129 | } >FLASH 130 | 131 | /* Used by the startup to initialize data */ 132 | _sidata = LOADADDR(.data); 133 | 134 | /* Initialized data sections into "RAM" Ram type memory */ 135 | .data : 136 | { 137 | . = ALIGN(4); 138 | _sdata = .; /* create a global symbol at data start */ 139 | *(.data) /* .data sections */ 140 | *(.data*) /* .data* sections */ 141 | *(.RamFunc) /* .RamFunc sections */ 142 | *(.RamFunc*) /* .RamFunc* sections */ 143 | 144 | . = ALIGN(4); 145 | _edata = .; /* define a global symbol at data end */ 146 | 147 | } >RAM AT> FLASH 148 | 149 | /* Uninitialized data section into "RAM" Ram type memory */ 150 | . = ALIGN(4); 151 | .bss : 152 | { 153 | /* This is used by the startup in order to initialize the .bss section */ 154 | _sbss = .; /* define a global symbol at bss start */ 155 | __bss_start__ = _sbss; 156 | *(.bss) 157 | *(.bss*) 158 | *(COMMON) 159 | 160 | . = ALIGN(4); 161 | _ebss = .; /* define a global symbol at bss end */ 162 | __bss_end__ = _ebss; 163 | } >RAM 164 | 165 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ 166 | ._user_heap_stack : 167 | { 168 | . = ALIGN(8); 169 | PROVIDE ( end = . ); 170 | PROVIDE ( _end = . ); 171 | . = . + _Min_Heap_Size; 172 | . = . + _Min_Stack_Size; 173 | . = ALIGN(8); 174 | } >RAM 175 | 176 | /* Remove information from the compiler libraries */ 177 | /DISCARD/ : 178 | { 179 | libc.a ( * ) 180 | libm.a ( * ) 181 | libgcc.a ( * ) 182 | } 183 | 184 | .ARM.attributes 0 : { *(.ARM.attributes) } 185 | } 186 | -------------------------------------------------------------------------------- /Portable/board_budgetcan_g0/Src/stm32g0xx_hal_timebase_tim.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32g0xx_hal_timebase_TIM.c 5 | * @brief HAL time base based on the hardware TIM. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "stm32g0xx_hal.h" 22 | #include "stm32g0xx_hal_tim.h" 23 | 24 | /* Private typedef -----------------------------------------------------------*/ 25 | /* Private define ------------------------------------------------------------*/ 26 | /* Private macro -------------------------------------------------------------*/ 27 | /* Private variables ---------------------------------------------------------*/ 28 | TIM_HandleTypeDef htim1; 29 | /* Private function prototypes -----------------------------------------------*/ 30 | /* Private functions ---------------------------------------------------------*/ 31 | 32 | /** 33 | * @brief This function configures the TIM1 as a time base source. 34 | * The time source is configured to have 1ms time base with a dedicated 35 | * Tick interrupt priority. 36 | * @note This function is called automatically at the beginning of program after 37 | * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). 38 | * @param TickPriority: Tick interrupt priority. 39 | * @retval HAL status 40 | */ 41 | HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) 42 | { 43 | RCC_ClkInitTypeDef clkconfig; 44 | uint32_t uwTimclock = 0; 45 | uint32_t uwPrescalerValue = 0; 46 | uint32_t pFLatency; 47 | /*Configure the TIM1 IRQ priority */ 48 | HAL_NVIC_SetPriority(TIM1_BRK_UP_TRG_COM_IRQn, TickPriority ,0); 49 | 50 | /* Enable the TIM1 global Interrupt */ 51 | HAL_NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn); 52 | 53 | /* Enable TIM1 clock */ 54 | __HAL_RCC_TIM1_CLK_ENABLE(); 55 | 56 | /* Get clock configuration */ 57 | HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); 58 | 59 | /* Compute TIM1 clock */ 60 | uwTimclock = HAL_RCC_GetPCLK1Freq(); 61 | /* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */ 62 | uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); 63 | 64 | /* Initialize TIM1 */ 65 | htim1.Instance = TIM1; 66 | 67 | /* Initialize TIMx peripheral as follow: 68 | + Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base. 69 | + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. 70 | + ClockDivision = 0 71 | + Counter direction = Up 72 | */ 73 | htim1.Init.Period = (1000000U / 1000U) - 1U; 74 | htim1.Init.Prescaler = uwPrescalerValue; 75 | htim1.Init.ClockDivision = 0; 76 | htim1.Init.CounterMode = TIM_COUNTERMODE_UP; 77 | 78 | if(HAL_TIM_Base_Init(&htim1) == HAL_OK) 79 | { 80 | /* Start the TIM time Base generation in interrupt mode */ 81 | return HAL_TIM_Base_Start_IT(&htim1); 82 | } 83 | 84 | /* Return function status */ 85 | return HAL_ERROR; 86 | } 87 | 88 | /** 89 | * @brief Suspend Tick increment. 90 | * @note Disable the tick increment by disabling TIM1 update interrupt. 91 | * @param None 92 | * @retval None 93 | */ 94 | void HAL_SuspendTick(void) 95 | { 96 | /* Disable TIM1 update Interrupt */ 97 | __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE); 98 | } 99 | 100 | /** 101 | * @brief Resume Tick increment. 102 | * @note Enable the tick increment by Enabling TIM1 update interrupt. 103 | * @param None 104 | * @retval None 105 | */ 106 | void HAL_ResumeTick(void) 107 | { 108 | /* Enable TIM1 Update interrupt */ 109 | __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE); 110 | } 111 | 112 | -------------------------------------------------------------------------------- /Portable/board_budgetcan_g0/Src/stm32g0xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32g0xx_it.c 5 | * @brief Interrupt Service Routines. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "main.h" 22 | #include "stm32g0xx_it.h" 23 | /* Private includes ----------------------------------------------------------*/ 24 | /* USER CODE BEGIN Includes */ 25 | /* USER CODE END Includes */ 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* USER CODE BEGIN TD */ 29 | 30 | /* USER CODE END TD */ 31 | 32 | /* Private define ------------------------------------------------------------*/ 33 | /* USER CODE BEGIN PD */ 34 | 35 | /* USER CODE END PD */ 36 | 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* USER CODE BEGIN PM */ 39 | 40 | /* USER CODE END PM */ 41 | 42 | /* Private variables ---------------------------------------------------------*/ 43 | /* USER CODE BEGIN PV */ 44 | 45 | /* USER CODE END PV */ 46 | 47 | /* Private function prototypes -----------------------------------------------*/ 48 | /* USER CODE BEGIN PFP */ 49 | 50 | /* USER CODE END PFP */ 51 | 52 | /* Private user code ---------------------------------------------------------*/ 53 | /* USER CODE BEGIN 0 */ 54 | 55 | /* USER CODE END 0 */ 56 | 57 | /* External variables --------------------------------------------------------*/ 58 | extern FDCAN_HandleTypeDef hfdcan1; 59 | extern FDCAN_HandleTypeDef hfdcan2; 60 | extern UART_HandleTypeDef huart1; 61 | extern PCD_HandleTypeDef hpcd_USB_DRD_FS; 62 | extern TIM_HandleTypeDef htim1; 63 | 64 | /* USER CODE BEGIN EV */ 65 | 66 | /* USER CODE END EV */ 67 | 68 | /******************************************************************************/ 69 | /* Cortex-M0+ Processor Interruption and Exception Handlers */ 70 | /******************************************************************************/ 71 | /** 72 | * @brief This function handles Non maskable interrupt. 73 | */ 74 | void NMI_Handler(void) 75 | { 76 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 77 | 78 | /* USER CODE END NonMaskableInt_IRQn 0 */ 79 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 80 | while (1) 81 | { 82 | } 83 | /* USER CODE END NonMaskableInt_IRQn 1 */ 84 | } 85 | 86 | /** 87 | * @brief This function handles Hard fault interrupt. 88 | */ 89 | void HardFault_Handler(void) 90 | { 91 | /* USER CODE BEGIN HardFault_IRQn 0 */ 92 | 93 | /* USER CODE END HardFault_IRQn 0 */ 94 | while (1) 95 | { 96 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */ 97 | /* USER CODE END W1_HardFault_IRQn 0 */ 98 | } 99 | } 100 | 101 | /******************************************************************************/ 102 | /* STM32G0xx Peripheral Interrupt Handlers */ 103 | /* Add here the Interrupt Handlers for the used peripherals. */ 104 | /* For the available peripheral interrupt handler names, */ 105 | /* please refer to the startup file (startup_stm32g0xx.s). */ 106 | /******************************************************************************/ 107 | 108 | /** 109 | * @brief This function handles USB, UCPD1 and UCPD2 global interrupts. 110 | */ 111 | void USB_UCPD1_2_IRQHandler(void) 112 | { 113 | /* USER CODE BEGIN USB_UCPD1_2_IRQn 0 */ 114 | 115 | /* USER CODE END USB_UCPD1_2_IRQn 0 */ 116 | HAL_PCD_IRQHandler(&hpcd_USB_DRD_FS); 117 | /* USER CODE BEGIN USB_UCPD1_2_IRQn 1 */ 118 | 119 | /* USER CODE END USB_UCPD1_2_IRQn 1 */ 120 | } 121 | 122 | /** 123 | * @brief This function handles TIM1 break, update, trigger and commutation interrupts. 124 | */ 125 | void TIM1_BRK_UP_TRG_COM_IRQHandler(void) 126 | { 127 | /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 0 */ 128 | 129 | /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 0 */ 130 | HAL_TIM_IRQHandler(&htim1); 131 | /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 1 */ 132 | 133 | /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 1 */ 134 | } 135 | 136 | /** 137 | * @brief This function handles TIM16, FDCAN1_IT0 and FDCAN2_IT0 Interrupt. 138 | */ 139 | void TIM16_FDCAN_IT0_IRQHandler(void) 140 | { 141 | /* USER CODE BEGIN TIM16_FDCAN_IT0_IRQn 0 */ 142 | 143 | /* USER CODE END TIM16_FDCAN_IT0_IRQn 0 */ 144 | HAL_FDCAN_IRQHandler(&hfdcan1); 145 | HAL_FDCAN_IRQHandler(&hfdcan2); 146 | /* USER CODE BEGIN TIM16_FDCAN_IT0_IRQn 1 */ 147 | 148 | /* USER CODE END TIM16_FDCAN_IT0_IRQn 1 */ 149 | } 150 | 151 | /** 152 | * @brief This function handles TIM17, FDCAN1_IT1 and FDCAN2_IT1 Interrupt. 153 | */ 154 | void TIM17_FDCAN_IT1_IRQHandler(void) 155 | { 156 | /* USER CODE BEGIN TIM17_FDCAN_IT1_IRQn 0 */ 157 | 158 | /* USER CODE END TIM17_FDCAN_IT1_IRQn 0 */ 159 | HAL_FDCAN_IRQHandler(&hfdcan1); 160 | HAL_FDCAN_IRQHandler(&hfdcan2); 161 | /* USER CODE BEGIN TIM17_FDCAN_IT1_IRQn 1 */ 162 | 163 | /* USER CODE END TIM17_FDCAN_IT1_IRQn 1 */ 164 | } 165 | 166 | /** 167 | * @brief This function handles USART1 global interrupt / USART1 wake-up interrupt through EXTI line 25. 168 | */ 169 | void USART1_IRQHandler(void) 170 | { 171 | /* USER CODE BEGIN USART1_IRQn 0 */ 172 | 173 | /* USER CODE END USART1_IRQn 0 */ 174 | HAL_UART_IRQHandler(&huart1); 175 | /* USER CODE BEGIN USART1_IRQn 1 */ 176 | 177 | /* USER CODE END USART1_IRQn 1 */ 178 | } 179 | 180 | /* USER CODE BEGIN 1 */ 181 | 182 | /* USER CODE END 1 */ 183 | 184 | -------------------------------------------------------------------------------- /Portable/board_budgetcan_g4/Inc/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2022 Ryan Edwards 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __BOARD_H__ 29 | #define __BOARD_H__ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /* Includes ------------------------------------------------------------------*/ 36 | #include "usbd_def.h" 37 | 38 | #define BOARD_SYSMEM_RESET_VECTOR 0x1FFF0000 39 | 40 | #define BOARD_TIM2_PRESCALER 160-1 41 | #define BOARD_TIM3_PRESCALER 160-1 42 | 43 | #define USBD_VID 0x1D50 44 | #define USBD_LANGID_STRING 1033 45 | #define USBD_MANUFACTURER_STRING (uint8_t*) "budgetcan.io" 46 | #define USBD_PID_FS 0x606F 47 | #define USBD_PRODUCT_STRING_FS (uint8_t*) "budgetcan_g4" 48 | #define USBD_CONFIGURATION_STRING (uint8_t*) "gs_usb" 49 | #define USBD_INTERFACE_STRING (uint8_t*) "gs_usb interface" 50 | #define DFU_INTERFACE_STRING (uint8_t*) "budgetcan_g4 DFU interface" 51 | 52 | /* FDCAN init values for this board */ 53 | #define FDCAN_SJW_INIT 1 54 | #define FDCAN_BRP_INIT 8 55 | #define FDCAN_TS1_INIT 13 56 | #define FDCAN_TS2_INIT 2 57 | 58 | #define FDCAN_DATA_SJW_INIT 4 59 | #define FDCAN_DATA_BRP_INIT 2 60 | #define FDCAN_DATA_TS1_INIT 15 61 | #define FDCAN_DATA_TS2_INIT 4 62 | 63 | #define FDCAN_CLOCK_DIV_INIT FDCAN_CLOCK_DIV1 64 | #define FDCAN_FRAME_FMT_INIT FDCAN_FRAME_FD_BRS 65 | #define FDCAN_MODE_INIT FDCAN_MODE_NORMAL 66 | #define FDCAN_AUTO_RETX_INIT DISABLE 67 | #define FDCAN_AUTO_TX_PAUSE_INIT DISABLE 68 | #define FDCAN_PROT_EXCPTN_INIT ENABLE 69 | #define FDCAN_STD_FLTR_NUM_INIT 0 70 | #define FDCAN_EXT_FLTR_NUM_INIT 0 71 | #define FDCAN_TX_FIFO_OPERATION_INIT FDCAN_TX_FIFO_OPERATION 72 | 73 | #define CAN_NUM_CHANNELS 3 74 | #define CAN_CLOCK_SPEED 80000000 75 | #define CAN_TERM_FEATURE_ENABLED 76 | #define CANFD_FEATURE_ENABLED 77 | 78 | #define LIN_FEATURE_ENABLED 79 | #define LIN1_UART UART1 80 | #define LIN1_CHANNEL 0 81 | #define LIN_MAX_DATA_BYTES 8U 82 | #define LIN_CONFIG_MSG_ID_CMD 0x1FFFFE80 83 | #define LIN_CONFIG_MSG_ID_DATA 0x1FFFFE81 84 | #define LIN_GATEWAY_MSG_ID 0x1FFFFE82 85 | #define LIN_GATEWAY_CAN_CH hfdcan1 86 | 87 | #define QUEUE_SIZE_HOST_TO_DEV 32 88 | #define QUEUE_SIZE_DEV_TO_HOST 32 89 | 90 | #define LED1_Pin GPIO_PIN_13 91 | #define LED1_GPIO_Port GPIOC 92 | #define LED2_Pin GPIO_PIN_14 93 | #define LED2_GPIO_Port GPIOC 94 | #define LED3_Pin GPIO_PIN_15 95 | #define LED3_GPIO_Port GPIOC 96 | #define FDCAN1_SLEEP_EN_Pin GPIO_PIN_0 97 | #define FDCAN1_SLEEP_EN_GPIO_Port GPIOA 98 | #define FDCAN1_TERM_EN_Pin GPIO_PIN_1 99 | #define FDCAN1_TERM_EN_GPIO_Port GPIOA 100 | #define FDCAN2_SLEEP_EN_Pin GPIO_PIN_2 101 | #define FDCAN2_SLEEP_EN_GPIO_Port GPIOA 102 | #define FDCAN2_TERM_EN_Pin GPIO_PIN_3 103 | #define FDCAN2_TERM_EN_GPIO_Port GPIOA 104 | #define FDCAN3_SLEEP_EN_Pin GPIO_PIN_4 105 | #define FDCAN3_SLEEP_EN_GPIO_Port GPIOA 106 | #define FDCAN3_TERM_EN_Pin GPIO_PIN_5 107 | #define FDCAN3_TERM_EN_GPIO_Port GPIOA 108 | #define TPS2116_STAT_Pin GPIO_PIN_6 109 | #define TPS2116_STAT_GPIO_Port GPIOA 110 | #define LIN1_MASTER_EN_Pin GPIO_PIN_7 111 | #define LIN1_MASTER_EN_GPIO_Port GPIOA 112 | #define FDCAN1_VIO_EN_Pin GPIO_PIN_10 113 | #define FDCAN1_VIO_EN_GPIO_Port GPIOA 114 | #define LIN1_nSLEEP_Pin GPIO_PIN_5 115 | #define LIN1_nSLEEP_GPIO_Port GPIOB 116 | 117 | void SystemClock_Config(void); 118 | void MX_GPIO_Init(void); 119 | 120 | #ifdef __cplusplus 121 | } 122 | #endif 123 | #endif /*__ BOARD_H__ */ 124 | 125 | -------------------------------------------------------------------------------- /Portable/board_budgetcan_g4/Inc/board_hal_config.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32_hal_config.h 5 | * @brief This file contains the define to select the correct 6 | * HAL for this board 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32_HAL_CONFIG_H__ 22 | #define __STM32_HAL_CONFIG_H__ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32g4xx_hal.h" 30 | 31 | 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | #endif /*__STM32_HAL_CONFIG_H__ */ 37 | 38 | -------------------------------------------------------------------------------- /Portable/board_budgetcan_g4/Inc/stm32g4xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32g4xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2024 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32G4xx_IT_H 22 | #define __STM32G4xx_IT_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Private includes ----------------------------------------------------------*/ 29 | /* USER CODE BEGIN Includes */ 30 | 31 | /* USER CODE END Includes */ 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN ET */ 35 | 36 | /* USER CODE END ET */ 37 | 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* USER CODE BEGIN EC */ 40 | 41 | /* USER CODE END EC */ 42 | 43 | /* Exported macro ------------------------------------------------------------*/ 44 | /* USER CODE BEGIN EM */ 45 | 46 | /* USER CODE END EM */ 47 | 48 | /* Exported functions prototypes ---------------------------------------------*/ 49 | void NMI_Handler(void); 50 | void HardFault_Handler(void); 51 | void MemManage_Handler(void); 52 | void BusFault_Handler(void); 53 | void UsageFault_Handler(void); 54 | void DebugMon_Handler(void); 55 | void USB_HP_IRQHandler(void); 56 | void USB_LP_IRQHandler(void); 57 | void FDCAN1_IT0_IRQHandler(void); 58 | void TIM1_UP_TIM16_IRQHandler(void); 59 | void USART1_IRQHandler(void); 60 | void USART2_IRQHandler(void); 61 | void FDCAN2_IT0_IRQHandler(void); 62 | void FDCAN3_IT0_IRQHandler(void); 63 | /* USER CODE BEGIN EFP */ 64 | 65 | /* USER CODE END EFP */ 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* __STM32G4xx_IT_H */ 72 | -------------------------------------------------------------------------------- /Portable/board_budgetcan_g4/Src/stm32g4xx_hal_timebase_tim.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32g4xx_hal_timebase_TIM.c 5 | * @brief HAL time base based on the hardware TIM. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2024 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "stm32g4xx_hal.h" 22 | #include "stm32g4xx_hal_tim.h" 23 | 24 | /* Private typedef -----------------------------------------------------------*/ 25 | /* Private define ------------------------------------------------------------*/ 26 | /* Private macro -------------------------------------------------------------*/ 27 | /* Private variables ---------------------------------------------------------*/ 28 | TIM_HandleTypeDef htim1; 29 | /* Private function prototypes -----------------------------------------------*/ 30 | /* Private functions ---------------------------------------------------------*/ 31 | 32 | /** 33 | * @brief This function configures the TIM1 as a time base source. 34 | * The time source is configured to have 1ms time base with a dedicated 35 | * Tick interrupt priority. 36 | * @note This function is called automatically at the beginning of program after 37 | * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). 38 | * @param TickPriority: Tick interrupt priority. 39 | * @retval HAL status 40 | */ 41 | HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) 42 | { 43 | RCC_ClkInitTypeDef clkconfig; 44 | uint32_t uwTimclock = 0; 45 | uint32_t uwPrescalerValue = 0; 46 | uint32_t pFLatency; 47 | HAL_StatusTypeDef status = HAL_OK; 48 | 49 | /* Enable TIM1 clock */ 50 | __HAL_RCC_TIM1_CLK_ENABLE(); 51 | 52 | /* Get clock configuration */ 53 | HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); 54 | 55 | /* Compute TIM1 clock */ 56 | uwTimclock = HAL_RCC_GetPCLK2Freq(); 57 | /* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */ 58 | uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); 59 | 60 | /* Initialize TIM1 */ 61 | htim1.Instance = TIM1; 62 | 63 | /* Initialize TIMx peripheral as follow: 64 | + Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base. 65 | + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. 66 | + ClockDivision = 0 67 | + Counter direction = Up 68 | */ 69 | htim1.Init.Period = (1000000U / 1000U) - 1U; 70 | htim1.Init.Prescaler = uwPrescalerValue; 71 | htim1.Init.ClockDivision = 0; 72 | htim1.Init.CounterMode = TIM_COUNTERMODE_UP; 73 | 74 | status = HAL_TIM_Base_Init(&htim1); 75 | if (status == HAL_OK) 76 | { 77 | /* Start the TIM time Base generation in interrupt mode */ 78 | status = HAL_TIM_Base_Start_IT(&htim1); 79 | if (status == HAL_OK) 80 | { 81 | /* Enable the TIM1 global Interrupt */ 82 | HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn); 83 | /* Configure the SysTick IRQ priority */ 84 | if (TickPriority < (1UL << __NVIC_PRIO_BITS)) 85 | { 86 | /* Configure the TIM IRQ priority */ 87 | HAL_NVIC_SetPriority(TIM1_UP_TIM16_IRQn, TickPriority, 0U); 88 | uwTickPrio = TickPriority; 89 | } 90 | else 91 | { 92 | status = HAL_ERROR; 93 | } 94 | } 95 | } 96 | 97 | /* Return function status */ 98 | return status; 99 | } 100 | 101 | /** 102 | * @brief Suspend Tick increment. 103 | * @note Disable the tick increment by disabling TIM1 update interrupt. 104 | * @param None 105 | * @retval None 106 | */ 107 | void HAL_SuspendTick(void) 108 | { 109 | /* Disable TIM1 update Interrupt */ 110 | __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE); 111 | } 112 | 113 | /** 114 | * @brief Resume Tick increment. 115 | * @note Enable the tick increment by Enabling TIM1 update interrupt. 116 | * @param None 117 | * @retval None 118 | */ 119 | void HAL_ResumeTick(void) 120 | { 121 | /* Enable TIM1 Update interrupt */ 122 | __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE); 123 | } 124 | 125 | -------------------------------------------------------------------------------- /Portable/board_canablev1/Inc/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202112.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * http://www.FreeRTOS.org 23 | * http://aws.amazon.com/freertos 24 | * 25 | * 1 tab == 4 spaces! 26 | */ 27 | 28 | #ifndef FREERTOS_CONFIG_H 29 | #define FREERTOS_CONFIG_H 30 | 31 | /*----------------------------------------------------------- 32 | * Application specific definitions. 33 | * 34 | * These definitions should be adjusted for your particular hardware and 35 | * application requirements. 36 | * 37 | * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE 38 | * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 39 | * 40 | * See http://www.freertos.org/a00110.html 41 | *----------------------------------------------------------*/ 42 | 43 | /* Ensure definitions are only used by the compiler, and not by the assembler. */ 44 | #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) 45 | #include 46 | extern uint32_t SystemCoreClock; 47 | #endif 48 | 49 | #define configUSE_PREEMPTION 1 50 | #define configSUPPORT_STATIC_ALLOCATION 0 51 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 52 | #define configUSE_IDLE_HOOK 0 53 | #define configUSE_TICK_HOOK 0 54 | #define configCPU_CLOCK_HZ ( SystemCoreClock ) 55 | #define configTICK_RATE_HZ ((TickType_t) 1000 ) 56 | #define configMAX_PRIORITIES ( 5 ) 57 | #define configMINIMAL_STACK_SIZE ((unsigned short) 60 ) 58 | #define configTOTAL_HEAP_SIZE ((size_t) (3 * 1024) ) 59 | #define configMAX_TASK_NAME_LEN ( 5 ) 60 | #define configUSE_TRACE_FACILITY 1 61 | #define configUSE_16_BIT_TICKS 0 62 | #define configUSE_MUTEXES 1 63 | #define configQUEUE_REGISTRY_SIZE 8 64 | #define configUSE_RECURSIVE_MUTEXES 1 65 | #define configUSE_COUNTING_SEMAPHORES 1 66 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 67 | 68 | /* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */ 69 | /* Defaults to size_t for backward compatibility, but can be changed 70 | if lengths will always be less than the number of bytes in a size_t. */ 71 | #define configMESSAGE_BUFFER_LENGTH_TYPE size_t 72 | /* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */ 73 | 74 | /* Co-routine definitions. */ 75 | #define configUSE_CO_ROUTINES 0 76 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 77 | 78 | /* Software timer definitions. */ 79 | #define configUSE_TIMERS 0 80 | #define configTIMER_TASK_PRIORITY ( 2 ) 81 | #define configTIMER_QUEUE_LENGTH 10 82 | #define configTIMER_TASK_STACK_DEPTH 256 83 | 84 | /* The following flag must be enabled only when using newlib */ 85 | #define configUSE_NEWLIB_REENTRANT 0 86 | 87 | /* Set the following definitions to 1 to include the API function, or zero 88 | to exclude the API function. */ 89 | #define INCLUDE_vTaskPrioritySet 0 90 | #define INCLUDE_uxTaskPriorityGet 0 91 | #define INCLUDE_vTaskDelete 0 92 | #define INCLUDE_vTaskCleanUpResources 0 93 | #define INCLUDE_vTaskSuspend 0 94 | #define INCLUDE_vTaskDelayUntil 0 95 | #define INCLUDE_vTaskDelay 1 96 | #define INCLUDE_xTaskGetSchedulerState 0 97 | #define INCLUDE_xTimerPendFunctionCall 0 98 | #define INCLUDE_xQueueGetMutexHolder 0 99 | #define INCLUDE_uxTaskGetStackHighWaterMark 0 100 | #define INCLUDE_xTaskGetCurrentTaskHandle 1 101 | #define INCLUDE_eTaskGetState 1 102 | 103 | /* Normal assert() semantics without relying on the provision of an assert.h 104 | header file. */ 105 | #define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );} 106 | 107 | 108 | /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS 109 | standard names. */ 110 | #define vPortSVCHandler SVC_Handler 111 | #define xPortPendSVHandler PendSV_Handler 112 | #define xPortSysTickHandler SysTick_Handler 113 | 114 | #endif /* FREERTOS_CONFIG_H */ 115 | -------------------------------------------------------------------------------- /Portable/board_canablev1/Inc/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2022 Ryan Edwards 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __BOARD_H__ 29 | #define __BOARD_H__ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /* Includes ------------------------------------------------------------------*/ 36 | #include "usbd_def.h" 37 | 38 | #define BOARD_SYSMEM_RESET_VECTOR 0x1FFFC400 39 | 40 | #define USBD_VID 0x1D50 41 | #define USBD_LANGID_STRING 1033 42 | #define USBD_MANUFACTURER_STRING (uint8_t*) "canable.io" 43 | #define USBD_PID_FS 0x606F 44 | #define USBD_PRODUCT_STRING_FS (uint8_t*) "canable" 45 | #define USBD_CONFIGURATION_STRING (uint8_t*) "gs_usb" 46 | #define USBD_INTERFACE_STRING (uint8_t*) "gs_usb interface" 47 | #define DFU_INTERFACE_STRING (uint8_t*) "canable DFU interface" 48 | 49 | #define CAN_SJW_INIT 1 50 | #define CAN_BRP_INIT 6 51 | #define CAN_TS1_INIT 13 52 | #define CAN_TS2_INIT 2 53 | 54 | #define CAN_TIME_TRG_MODE_INIT DISABLE 55 | #define CAN_AUTO_BUS_OFF_INIT ENABLE 56 | #define CAN_AUTO_WAKE_UP_INIT DISABLE 57 | #define CAN_AUTO_RETX_INIT ENABLE 58 | #define CAN_RX_FIFO_LCKD_INIT DISABLE 59 | #define CAN_TX_FIFO_PRI_INIT ENABLE 60 | #define CAN_MODE_INIT CAN_MODE_NORMAL 61 | 62 | #define CAN_NUM_CHANNELS 1 63 | #define CAN_CLOCK_SPEED 48000000 64 | 65 | #define QUEUE_SIZE_HOST_TO_DEV 32 66 | #define QUEUE_SIZE_DEV_TO_HOST 32 67 | 68 | #define LED_RXTX_ACTIVE_TIME_MS 30U 69 | #define LED_RXTX_INACTIVE_TIME_MS 30U 70 | 71 | #define LED1_Pin GPIO_PIN_0 72 | #define LED1_GPIO_Port GPIOB 73 | #define LED2_Pin GPIO_PIN_1 74 | #define LED2_GPIO_Port GPIOB 75 | 76 | void SystemClock_Config(void); 77 | void MX_GPIO_Init(void); 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | #endif /*__ BOARD_H__ */ 83 | 84 | -------------------------------------------------------------------------------- /Portable/board_canablev1/Inc/board_hal_config.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32_hal_config.h 5 | * @brief This file contains the define to select the correct 6 | * HAL for this board 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32_HAL_CONFIG_H__ 22 | #define __STM32_HAL_CONFIG_H__ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f0xx_hal.h" 30 | 31 | 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | #endif /*__STM32_HAL_CONFIG_H__ */ 37 | 38 | -------------------------------------------------------------------------------- /Portable/board_canablev1/Inc/stm32f0xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f0xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F0xx_IT_H 22 | #define __STM32F0xx_IT_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Private includes ----------------------------------------------------------*/ 29 | /* USER CODE BEGIN Includes */ 30 | 31 | /* USER CODE END Includes */ 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN ET */ 35 | 36 | /* USER CODE END ET */ 37 | 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* USER CODE BEGIN EC */ 40 | 41 | /* USER CODE END EC */ 42 | 43 | /* Exported macro ------------------------------------------------------------*/ 44 | /* USER CODE BEGIN EM */ 45 | 46 | /* USER CODE END EM */ 47 | 48 | /* Exported functions prototypes ---------------------------------------------*/ 49 | void NMI_Handler(void); 50 | void HardFault_Handler(void); 51 | void TIM1_BRK_UP_TRG_COM_IRQHandler(void); 52 | void CEC_CAN_IRQHandler(void); 53 | void USB_IRQHandler(void); 54 | /* USER CODE BEGIN EFP */ 55 | 56 | /* USER CODE END EFP */ 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* __STM32F0xx_IT_H */ 63 | -------------------------------------------------------------------------------- /Portable/board_canablev1/Src/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2022 Ryan Edwards 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "board.h" 29 | #include "usbd_gs_can.h" 30 | #include "can.h" 31 | #include "led.h" 32 | 33 | LED_HandleTypeDef hled1; 34 | LED_HandleTypeDef hled2; 35 | 36 | CAN_HandleTypeDef hcan; 37 | 38 | extern USBD_GS_CAN_HandleTypeDef hGS_CAN; 39 | 40 | /** 41 | * @brief System Clock Configuration 42 | * @retval None 43 | */ 44 | void SystemClock_Config(void) 45 | { 46 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 47 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 48 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; 49 | 50 | /** Initializes the RCC Oscillators according to the specified parameters 51 | * in the RCC_OscInitTypeDef structure. 52 | */ 53 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48; 54 | RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; 55 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; 56 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 57 | { 58 | Error_Handler(); 59 | } 60 | 61 | /** Initializes the CPU, AHB and APB buses clocks 62 | */ 63 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 64 | |RCC_CLOCKTYPE_PCLK1; 65 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48; 66 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 67 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 68 | 69 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) 70 | { 71 | Error_Handler(); 72 | } 73 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; 74 | PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; 75 | 76 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) 77 | { 78 | Error_Handler(); 79 | } 80 | } 81 | 82 | /** Configure pins 83 | */ 84 | void MX_GPIO_Init(void) 85 | { 86 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 87 | 88 | /* GPIO Ports Clock Enable */ 89 | __HAL_RCC_GPIOB_CLK_ENABLE(); 90 | __HAL_RCC_GPIOA_CLK_ENABLE(); 91 | 92 | /*Configure GPIO pin Output Level */ 93 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0|GPIO_PIN_1, GPIO_PIN_RESET); 94 | 95 | /*Configure GPIO pins : PB0 PB1 */ 96 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; 97 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 98 | GPIO_InitStruct.Pull = GPIO_NOPULL; 99 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 100 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 101 | 102 | } 103 | 104 | void main_init_cb(void) 105 | { 106 | /* carry over the LED blink from original firmware */ 107 | for (uint8_t i=0; i<10; i++) 108 | { 109 | HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin); 110 | HAL_Delay(50); 111 | HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin); 112 | } 113 | 114 | hGS_CAN.channels[0] = &hcan; 115 | can_init(hGS_CAN.channels[0], CAN); 116 | 117 | led_init(&hled1, LED1_GPIO_Port, LED1_Pin, LED_MODE_INACTIVE, LED_ACTIVE_HIGH); 118 | led_init(&hled2, LED2_GPIO_Port, LED2_Pin, LED_MODE_ACTIVE, LED_ACTIVE_HIGH); 119 | 120 | } 121 | 122 | void main_task_cb(void) 123 | { 124 | /* update all the LEDs */ 125 | led_update(&hled1); 126 | led_update(&hled2); 127 | } 128 | 129 | void can_on_enable_cb(uint8_t channel) 130 | { 131 | UNUSED(channel); 132 | led_set_inactive(&hled2); 133 | led_set_active(&hled1); 134 | } 135 | 136 | void can_on_disable_cb(uint8_t channel) 137 | { 138 | UNUSED(channel); 139 | led_set_active(&hled2); 140 | led_set_inactive(&hled1); 141 | } 142 | 143 | void can_on_tx_cb(uint8_t channel, struct gs_host_frame *frame) 144 | { 145 | UNUSED(channel); 146 | UNUSED(frame); 147 | led_indicate_rxtx(&hled2); 148 | } 149 | 150 | void can_on_rx_cb(uint8_t channel, struct gs_host_frame *frame) 151 | { 152 | UNUSED(channel); 153 | UNUSED(frame); 154 | led_indicate_rxtx(&hled1); 155 | } 156 | 157 | void can_identify_cb(uint32_t do_identify) 158 | { 159 | if (do_identify) { 160 | led_blink_start(&hled1, 250); 161 | } 162 | else { 163 | led_blink_stop(&hled1); 164 | } 165 | } -------------------------------------------------------------------------------- /Portable/board_canablev1/Src/stm32f0xx_hal_timebase_tim.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f0xx_hal_timebase_TIM.c 5 | * @brief HAL time base based on the hardware TIM. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "stm32f0xx_hal.h" 22 | #include "stm32f0xx_hal_tim.h" 23 | 24 | /* Private typedef -----------------------------------------------------------*/ 25 | /* Private define ------------------------------------------------------------*/ 26 | /* Private macro -------------------------------------------------------------*/ 27 | /* Private variables ---------------------------------------------------------*/ 28 | TIM_HandleTypeDef htim1; 29 | /* Private function prototypes -----------------------------------------------*/ 30 | /* Private functions ---------------------------------------------------------*/ 31 | 32 | /** 33 | * @brief This function configures the TIM1 as a time base source. 34 | * The time source is configured to have 1ms time base with a dedicated 35 | * Tick interrupt priority. 36 | * @note This function is called automatically at the beginning of program after 37 | * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). 38 | * @param TickPriority: Tick interrupt priority. 39 | * @retval HAL status 40 | */ 41 | HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) 42 | { 43 | RCC_ClkInitTypeDef clkconfig; 44 | uint32_t uwTimclock, uwAPB1Prescaler = 0U; 45 | 46 | uint32_t uwPrescalerValue = 0U; 47 | uint32_t pFLatency; 48 | HAL_StatusTypeDef status; 49 | 50 | /* Enable TIM1 clock */ 51 | __HAL_RCC_TIM1_CLK_ENABLE(); 52 | 53 | /* Get clock configuration */ 54 | HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); 55 | 56 | /* Get APB1 prescaler */ 57 | uwAPB1Prescaler = clkconfig.APB1CLKDivider; 58 | /* Compute TIM1 clock */ 59 | if (uwAPB1Prescaler == RCC_HCLK_DIV1) 60 | { 61 | uwTimclock = HAL_RCC_GetPCLK1Freq(); 62 | } 63 | else 64 | { 65 | uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq(); 66 | } 67 | 68 | /* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */ 69 | uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); 70 | 71 | /* Initialize TIM1 */ 72 | htim1.Instance = TIM1; 73 | 74 | /* Initialize TIMx peripheral as follow: 75 | + Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base. 76 | + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. 77 | + ClockDivision = 0 78 | + Counter direction = Up 79 | */ 80 | htim1.Init.Period = (1000000U / 1000U) - 1U; 81 | htim1.Init.Prescaler = uwPrescalerValue; 82 | htim1.Init.ClockDivision = 0; 83 | htim1.Init.CounterMode = TIM_COUNTERMODE_UP; 84 | htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; 85 | 86 | status = HAL_TIM_Base_Init(&htim1); 87 | if (status == HAL_OK) 88 | { 89 | /* Start the TIM time Base generation in interrupt mode */ 90 | status = HAL_TIM_Base_Start_IT(&htim1); 91 | if (status == HAL_OK) 92 | { 93 | /* Enable the TIM1 global Interrupt */ 94 | HAL_NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn); 95 | /* Configure the SysTick IRQ priority */ 96 | if (TickPriority < (1UL << __NVIC_PRIO_BITS)) 97 | { 98 | /* Configure the TIM IRQ priority */ 99 | HAL_NVIC_SetPriority(TIM1_BRK_UP_TRG_COM_IRQn, TickPriority, 0U); 100 | uwTickPrio = TickPriority; 101 | } 102 | else 103 | { 104 | status = HAL_ERROR; 105 | } 106 | } 107 | } 108 | 109 | /* Return function status */ 110 | return status; 111 | } 112 | 113 | /** 114 | * @brief Suspend Tick increment. 115 | * @note Disable the tick increment by disabling TIM1 update interrupt. 116 | * @param None 117 | * @retval None 118 | */ 119 | void HAL_SuspendTick(void) 120 | { 121 | /* Disable TIM1 update Interrupt */ 122 | __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE); 123 | } 124 | 125 | /** 126 | * @brief Resume Tick increment. 127 | * @note Enable the tick increment by Enabling TIM1 update interrupt. 128 | * @param None 129 | * @retval None 130 | */ 131 | void HAL_ResumeTick(void) 132 | { 133 | /* Enable TIM1 Update interrupt */ 134 | __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE); 135 | } 136 | 137 | -------------------------------------------------------------------------------- /Portable/board_canablev1/Src/stm32f0xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f0xx_it.c 5 | * @brief Interrupt Service Routines. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "main.h" 22 | #include "stm32f0xx_it.h" 23 | /* Private includes ----------------------------------------------------------*/ 24 | /* USER CODE BEGIN Includes */ 25 | /* USER CODE END Includes */ 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* USER CODE BEGIN TD */ 29 | 30 | /* USER CODE END TD */ 31 | 32 | /* Private define ------------------------------------------------------------*/ 33 | /* USER CODE BEGIN PD */ 34 | 35 | /* USER CODE END PD */ 36 | 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* USER CODE BEGIN PM */ 39 | 40 | /* USER CODE END PM */ 41 | 42 | /* Private variables ---------------------------------------------------------*/ 43 | /* USER CODE BEGIN PV */ 44 | 45 | /* USER CODE END PV */ 46 | 47 | /* Private function prototypes -----------------------------------------------*/ 48 | /* USER CODE BEGIN PFP */ 49 | 50 | /* USER CODE END PFP */ 51 | 52 | /* Private user code ---------------------------------------------------------*/ 53 | /* USER CODE BEGIN 0 */ 54 | 55 | /* USER CODE END 0 */ 56 | 57 | /* External variables --------------------------------------------------------*/ 58 | extern CAN_HandleTypeDef hcan; 59 | extern PCD_HandleTypeDef hpcd_USB_FS; 60 | extern TIM_HandleTypeDef htim1; 61 | 62 | /* USER CODE BEGIN EV */ 63 | 64 | /* USER CODE END EV */ 65 | 66 | /******************************************************************************/ 67 | /* Cortex-M0 Processor Interruption and Exception Handlers */ 68 | /******************************************************************************/ 69 | /** 70 | * @brief This function handles Non maskable interrupt. 71 | */ 72 | void NMI_Handler(void) 73 | { 74 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 75 | 76 | /* USER CODE END NonMaskableInt_IRQn 0 */ 77 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 78 | while (1) 79 | { 80 | } 81 | /* USER CODE END NonMaskableInt_IRQn 1 */ 82 | } 83 | 84 | /** 85 | * @brief This function handles Hard fault interrupt. 86 | */ 87 | void HardFault_Handler(void) 88 | { 89 | /* USER CODE BEGIN HardFault_IRQn 0 */ 90 | 91 | /* USER CODE END HardFault_IRQn 0 */ 92 | while (1) 93 | { 94 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */ 95 | /* USER CODE END W1_HardFault_IRQn 0 */ 96 | } 97 | } 98 | 99 | /******************************************************************************/ 100 | /* STM32F0xx Peripheral Interrupt Handlers */ 101 | /* Add here the Interrupt Handlers for the used peripherals. */ 102 | /* For the available peripheral interrupt handler names, */ 103 | /* please refer to the startup file (startup_stm32f0xx.s). */ 104 | /******************************************************************************/ 105 | 106 | /** 107 | * @brief This function handles TIM1 break, update, trigger and commutation interrupts. 108 | */ 109 | void TIM1_BRK_UP_TRG_COM_IRQHandler(void) 110 | { 111 | /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 0 */ 112 | 113 | /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 0 */ 114 | HAL_TIM_IRQHandler(&htim1); 115 | /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 1 */ 116 | 117 | /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 1 */ 118 | } 119 | 120 | /** 121 | * @brief This function handles HDMI-CEC and CAN global interrupts / HDMI-CEC wake-up interrupt through EXTI line 27. 122 | */ 123 | void CEC_CAN_IRQHandler(void) 124 | { 125 | /* USER CODE BEGIN CEC_CAN_IRQn 0 */ 126 | 127 | /* USER CODE END CEC_CAN_IRQn 0 */ 128 | HAL_CAN_IRQHandler(&hcan); 129 | /* USER CODE BEGIN CEC_CAN_IRQn 1 */ 130 | 131 | /* USER CODE END CEC_CAN_IRQn 1 */ 132 | } 133 | 134 | /** 135 | * @brief This function handles USB global Interrupt / USB wake-up interrupt through EXTI line 18. 136 | */ 137 | void USB_IRQHandler(void) 138 | { 139 | /* USER CODE BEGIN USB_IRQn 0 */ 140 | 141 | /* USER CODE END USB_IRQn 0 */ 142 | HAL_PCD_IRQHandler(&hpcd_USB_FS); 143 | /* USER CODE BEGIN USB_IRQn 1 */ 144 | 145 | /* USER CODE END USB_IRQn 1 */ 146 | } 147 | 148 | /* USER CODE BEGIN 1 */ 149 | 150 | /* USER CODE END 1 */ 151 | -------------------------------------------------------------------------------- /Portable/board_canablev2/Inc/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2022 Ryan Edwards 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __BOARD_H__ 29 | #define __BOARD_H__ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /* Includes ------------------------------------------------------------------*/ 36 | #include "usbd_def.h" 37 | 38 | #define BOARD_SYSMEM_RESET_VECTOR 0x1FFF0000 39 | 40 | #define USBD_VID 0x1D50 41 | #define USBD_LANGID_STRING 1033 42 | #define USBD_MANUFACTURER_STRING (uint8_t*) "canable.io" 43 | #define USBD_PID_FS 0x606F 44 | #define USBD_PRODUCT_STRING_FS (uint8_t*) "canablev2" 45 | #define USBD_CONFIGURATION_STRING (uint8_t*) "gs_usb" 46 | #define USBD_INTERFACE_STRING (uint8_t*) "gs_usb interface" 47 | #define DFU_INTERFACE_STRING (uint8_t*) "canablev2 DFU interface" 48 | 49 | #define FDCAN_SJW_INIT 1 50 | #define FDCAN_BRP_INIT 10 51 | #define FDCAN_TS1_INIT 13 52 | #define FDCAN_TS2_INIT 2 53 | 54 | #define FDCAN_DATA_SJW_INIT 1 55 | #define FDCAN_DATA_BRP_INIT 2 56 | #define FDCAN_DATA_TS1_INIT 14 57 | #define FDCAN_DATA_TS2_INIT 5 58 | 59 | #define FDCAN_CLOCK_DIV_INIT FDCAN_CLOCK_DIV1 60 | #define FDCAN_FRAME_FMT_INIT FDCAN_FRAME_FD_BRS 61 | #define FDCAN_MODE_INIT FDCAN_MODE_NORMAL 62 | #define FDCAN_AUTO_RETX_INIT DISABLE 63 | #define FDCAN_AUTO_TX_PAUSE_INIT DISABLE 64 | #define FDCAN_PROT_EXCPTN_INIT ENABLE 65 | #define FDCAN_STD_FLTR_NUM_INIT 0 66 | #define FDCAN_EXT_FLTR_NUM_INIT 0 67 | #define FDCAN_TX_FIFO_OPERATION_INIT FDCAN_TX_FIFO_OPERATION 68 | 69 | #define CAN_NUM_CHANNELS 1 70 | #define CAN_CLOCK_SPEED 80000000 71 | #define CANFD_FEATURE_ENABLED 72 | 73 | #define QUEUE_SIZE_HOST_TO_DEV 32 74 | #define QUEUE_SIZE_DEV_TO_HOST 32 75 | 76 | #define FDCAN1_3V3_EN_Pin GPIO_PIN_13 77 | #define FDCAN1_3V3_EN_GPIO_Port GPIOC 78 | #define FDCAN1_nSTANDBY_Pin GPIO_PIN_0 79 | #define FDCAN1_nSTANDBY_GPIO_Port GPIOA 80 | #define LED2_Pin GPIO_PIN_11 81 | #define LED2_GPIO_Port GPIOB 82 | #define LED1_Pin GPIO_PIN_15 83 | #define LED1_GPIO_Port GPIOA 84 | 85 | void SystemClock_Config(void); 86 | void MX_GPIO_Init(void); 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | #endif /*__ BOARD_H__ */ 92 | 93 | -------------------------------------------------------------------------------- /Portable/board_canablev2/Inc/board_hal_config.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32_hal_config.h 5 | * @brief This file contains the define to select the correct 6 | * HAL for this board 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32_HAL_CONFIG_H__ 22 | #define __STM32_HAL_CONFIG_H__ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32g4xx_hal.h" 30 | 31 | 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | #endif /*__STM32_HAL_CONFIG_H__ */ 37 | 38 | -------------------------------------------------------------------------------- /Portable/board_canablev2/Inc/stm32g4xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32g4xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32G4xx_IT_H 22 | #define __STM32G4xx_IT_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Private includes ----------------------------------------------------------*/ 29 | /* USER CODE BEGIN Includes */ 30 | 31 | /* USER CODE END Includes */ 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN ET */ 35 | 36 | /* USER CODE END ET */ 37 | 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* USER CODE BEGIN EC */ 40 | 41 | /* USER CODE END EC */ 42 | 43 | /* Exported macro ------------------------------------------------------------*/ 44 | /* USER CODE BEGIN EM */ 45 | 46 | /* USER CODE END EM */ 47 | 48 | /* Exported functions prototypes ---------------------------------------------*/ 49 | void NMI_Handler(void); 50 | void HardFault_Handler(void); 51 | void MemManage_Handler(void); 52 | void BusFault_Handler(void); 53 | void UsageFault_Handler(void); 54 | void DebugMon_Handler(void); 55 | void USB_LP_IRQHandler(void); 56 | void FDCAN1_IT0_IRQHandler(void); 57 | void TIM1_UP_TIM16_IRQHandler(void); 58 | /* USER CODE BEGIN EFP */ 59 | 60 | /* USER CODE END EFP */ 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* __STM32G4xx_IT_H */ 67 | -------------------------------------------------------------------------------- /Portable/board_canablev2/Src/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2022 Ryan Edwards 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "board.h" 29 | #include "usbd_gs_can.h" 30 | #include "can.h" 31 | #include "led.h" 32 | 33 | FDCAN_HandleTypeDef hfdcan1; 34 | LED_HandleTypeDef hled1; 35 | LED_HandleTypeDef hled2; 36 | 37 | extern USBD_GS_CAN_HandleTypeDef hGS_CAN; 38 | 39 | /** 40 | * @brief System Clock Configuration 41 | * @retval None 42 | */ 43 | void SystemClock_Config(void) 44 | { 45 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 46 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 47 | 48 | /** Configure the main internal regulator output voltage 49 | */ 50 | HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); 51 | 52 | /** Initializes the RCC Oscillators according to the specified parameters 53 | * in the RCC_OscInitTypeDef structure. 54 | */ 55 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48; 56 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 57 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 58 | RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; 59 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 60 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; 61 | RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1; 62 | RCC_OscInitStruct.PLL.PLLN = 10; 63 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; 64 | RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; 65 | RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; 66 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 67 | { 68 | Error_Handler(); 69 | } 70 | 71 | /** Initializes the CPU, AHB and APB buses clocks 72 | */ 73 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 74 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; 75 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 76 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 77 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; 78 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 79 | 80 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) 81 | { 82 | Error_Handler(); 83 | } 84 | } 85 | 86 | /** Configure pins 87 | */ 88 | void MX_GPIO_Init(void) 89 | { 90 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 91 | 92 | /* GPIO Ports Clock Enable */ 93 | __HAL_RCC_GPIOC_CLK_ENABLE(); 94 | __HAL_RCC_GPIOA_CLK_ENABLE(); 95 | __HAL_RCC_GPIOB_CLK_ENABLE(); 96 | 97 | /*Configure GPIO pin Output Level */ 98 | HAL_GPIO_WritePin(FDCAN1_3V3_EN_GPIO_Port, FDCAN1_3V3_EN_Pin, GPIO_PIN_RESET); 99 | 100 | /*Configure GPIO pin Output Level */ 101 | HAL_GPIO_WritePin(GPIOA, FDCAN1_nSTANDBY_Pin|LED1_Pin, GPIO_PIN_RESET); 102 | 103 | /*Configure GPIO pin Output Level */ 104 | HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET); 105 | 106 | /*Configure GPIO pin : FDCAN1_3V3_EN_Pin */ 107 | GPIO_InitStruct.Pin = FDCAN1_3V3_EN_Pin; 108 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 109 | GPIO_InitStruct.Pull = GPIO_NOPULL; 110 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 111 | HAL_GPIO_Init(FDCAN1_3V3_EN_GPIO_Port, &GPIO_InitStruct); 112 | 113 | /*Configure GPIO pins : FDCAN1_nSTANDBY_Pin LED1_Pin */ 114 | GPIO_InitStruct.Pin = FDCAN1_nSTANDBY_Pin|LED1_Pin; 115 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 116 | GPIO_InitStruct.Pull = GPIO_NOPULL; 117 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 118 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 119 | 120 | /*Configure GPIO pin : LED2_Pin */ 121 | GPIO_InitStruct.Pin = LED2_Pin; 122 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 123 | GPIO_InitStruct.Pull = GPIO_NOPULL; 124 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 125 | HAL_GPIO_Init(LED2_GPIO_Port, &GPIO_InitStruct); 126 | 127 | } 128 | 129 | void main_init_cb(void) 130 | { 131 | /* carry over the LED blink from original firmware */ 132 | for (uint8_t i=0; i<10; i++) 133 | { 134 | HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin); 135 | HAL_Delay(50); 136 | HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin); 137 | } 138 | 139 | HAL_GPIO_WritePin(FDCAN1_nSTANDBY_GPIO_Port, FDCAN1_nSTANDBY_Pin, GPIO_PIN_RESET); 140 | HAL_GPIO_WritePin(FDCAN1_3V3_EN_GPIO_Port, FDCAN1_3V3_EN_Pin, GPIO_PIN_SET); 141 | hGS_CAN.channels[0] = &hfdcan1; 142 | can_init(hGS_CAN.channels[0], FDCAN1); 143 | led_init(&hled1, LED1_GPIO_Port, LED1_Pin, LED_MODE_ACTIVE, LED_ACTIVE_HIGH); 144 | led_init(&hled2, LED2_GPIO_Port, LED2_Pin, LED_MODE_INACTIVE, LED_ACTIVE_HIGH); 145 | } 146 | 147 | void main_task_cb(void) 148 | { 149 | /* update all the LEDs */ 150 | led_update(&hled1); 151 | led_update(&hled2); 152 | } 153 | 154 | void can_on_tx_cb(uint8_t channel, struct gs_host_frame *frame) 155 | { 156 | UNUSED(channel); 157 | UNUSED(frame); 158 | led_indicate_rxtx(&hled2); 159 | } 160 | 161 | void can_on_rx_cb(uint8_t channel, struct gs_host_frame *frame) 162 | { 163 | UNUSED(channel); 164 | UNUSED(frame); 165 | led_indicate_rxtx(&hled2); 166 | } 167 | 168 | void can_identify_cb(uint32_t do_identify) 169 | { 170 | if (do_identify) { 171 | led_blink_start(&hled1, 250); 172 | } 173 | else { 174 | led_blink_stop(&hled1); 175 | } 176 | } -------------------------------------------------------------------------------- /Portable/board_canablev2/Src/stm32g4xx_hal_timebase_tim.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32g4xx_hal_timebase_TIM.c 5 | * @brief HAL time base based on the hardware TIM. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "stm32g4xx_hal.h" 22 | #include "stm32g4xx_hal_tim.h" 23 | 24 | /* Private typedef -----------------------------------------------------------*/ 25 | /* Private define ------------------------------------------------------------*/ 26 | /* Private macro -------------------------------------------------------------*/ 27 | /* Private variables ---------------------------------------------------------*/ 28 | TIM_HandleTypeDef htim1; 29 | /* Private function prototypes -----------------------------------------------*/ 30 | /* Private functions ---------------------------------------------------------*/ 31 | 32 | /** 33 | * @brief This function configures the TIM1 as a time base source. 34 | * The time source is configured to have 1ms time base with a dedicated 35 | * Tick interrupt priority. 36 | * @note This function is called automatically at the beginning of program after 37 | * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). 38 | * @param TickPriority: Tick interrupt priority. 39 | * @retval HAL status 40 | */ 41 | HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) 42 | { 43 | RCC_ClkInitTypeDef clkconfig; 44 | uint32_t uwTimclock = 0; 45 | uint32_t uwPrescalerValue = 0; 46 | uint32_t pFLatency; 47 | HAL_StatusTypeDef status = HAL_OK; 48 | 49 | /* Enable TIM1 clock */ 50 | __HAL_RCC_TIM1_CLK_ENABLE(); 51 | 52 | /* Get clock configuration */ 53 | HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); 54 | 55 | /* Compute TIM1 clock */ 56 | uwTimclock = HAL_RCC_GetPCLK2Freq(); 57 | /* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */ 58 | uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); 59 | 60 | /* Initialize TIM1 */ 61 | htim1.Instance = TIM1; 62 | 63 | /* Initialize TIMx peripheral as follow: 64 | + Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base. 65 | + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. 66 | + ClockDivision = 0 67 | + Counter direction = Up 68 | */ 69 | htim1.Init.Period = (1000000U / 1000U) - 1U; 70 | htim1.Init.Prescaler = uwPrescalerValue; 71 | htim1.Init.ClockDivision = 0; 72 | htim1.Init.CounterMode = TIM_COUNTERMODE_UP; 73 | 74 | status = HAL_TIM_Base_Init(&htim1); 75 | if (status == HAL_OK) 76 | { 77 | /* Start the TIM time Base generation in interrupt mode */ 78 | status = HAL_TIM_Base_Start_IT(&htim1); 79 | if (status == HAL_OK) 80 | { 81 | /* Enable the TIM1 global Interrupt */ 82 | HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn); 83 | /* Configure the SysTick IRQ priority */ 84 | if (TickPriority < (1UL << __NVIC_PRIO_BITS)) 85 | { 86 | /* Configure the TIM IRQ priority */ 87 | HAL_NVIC_SetPriority(TIM1_UP_TIM16_IRQn, TickPriority, 0U); 88 | uwTickPrio = TickPriority; 89 | } 90 | else 91 | { 92 | status = HAL_ERROR; 93 | } 94 | } 95 | } 96 | 97 | /* Return function status */ 98 | return status; 99 | } 100 | 101 | /** 102 | * @brief Suspend Tick increment. 103 | * @note Disable the tick increment by disabling TIM1 update interrupt. 104 | * @param None 105 | * @retval None 106 | */ 107 | void HAL_SuspendTick(void) 108 | { 109 | /* Disable TIM1 update Interrupt */ 110 | __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE); 111 | } 112 | 113 | /** 114 | * @brief Resume Tick increment. 115 | * @note Enable the tick increment by Enabling TIM1 update interrupt. 116 | * @param None 117 | * @retval None 118 | */ 119 | void HAL_ResumeTick(void) 120 | { 121 | /* Enable TIM1 Update interrupt */ 122 | __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE); 123 | } 124 | 125 | -------------------------------------------------------------------------------- /Portable/board_stm32h745i-disco/Inc/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2022 Ryan Edwards 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | */ 26 | 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __BOARD_H__ 29 | #define __BOARD_H__ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /* Includes ------------------------------------------------------------------*/ 36 | #include "usbd_def.h" 37 | 38 | #define BOARD_SYSMEM_RESET_VECTOR 0x1FF09800 39 | 40 | #define USBD_VID 0x1D50 41 | #define USBD_LANGID_STRING 1033 42 | #define USBD_MANUFACTURER_STRING (uint8_t*) "budgetcan.io" 43 | #define USBD_PID_FS 0x606F 44 | #define USBD_PRODUCT_STRING_FS (uint8_t*) "budgetcan_h7" 45 | #define USBD_CONFIGURATION_STRING (uint8_t*) "gs_usb" 46 | #define USBD_INTERFACE_STRING (uint8_t*) "gs_usb interface" 47 | #define DFU_INTERFACE_STRING (uint8_t*) "budgetcan_h7 DFU interface" 48 | 49 | #define FDCAN_SJW_INIT 1 50 | #define FDCAN_BRP_INIT 8 51 | #define FDCAN_TS1_INIT 13 52 | #define FDCAN_TS2_INIT 2 53 | 54 | #define FDCAN_DATA_SJW_INIT 4 55 | #define FDCAN_DATA_BRP_INIT 2 56 | #define FDCAN_DATA_TS1_INIT 15 57 | #define FDCAN_DATA_TS2_INIT 4 58 | 59 | #define FDCAN_FRAME_FMT_INIT FDCAN_FRAME_FD_BRS 60 | #define FDCAN_MODE_INIT FDCAN_MODE_NORMAL 61 | #define FDCAN_AUTO_RETX_INIT DISABLE 62 | #define FDCAN_AUTO_TX_PAUSE_INIT DISABLE 63 | #define FDCAN_PROT_EXCPTN_INIT ENABLE 64 | #define FDCAN_STD_FLTR_NUM_INIT 0 65 | #define FDCAN_EXT_FLTR_NUM_INIT 0 66 | 67 | #define FDCAN_TX_FIFO_OPERATION_INIT FDCAN_TX_FIFO_OPERATION 68 | #define FDCAN_MSG_RAM_OFST_INIT 0 69 | #define FDCAN_RX_FIFO0_ELEM_NUM_INIT 16 70 | #define FDCAN_RX_FIFO0_ELEM_SZ_INIT FDCAN_DATA_BYTES_64 71 | #define FDCAN_RX_FIFO1_ELEM_NUM_INIT 16 72 | #define FDCAN_RX_FIFO1_ELEM_SZ_INIT FDCAN_DATA_BYTES_64 73 | #define FDCAN_RX_BUFF_NUM_INIT 64 74 | #define FDCAN_RX_BUFF_SZ_INIT FDCAN_DATA_BYTES_64 75 | #define FDCAN_TX_EVNT_NUM_INIT 16 76 | #define FDCAN_TX_BUFF_NUM_INIT 16 77 | #define FDCAN_TX_FIFO_ELEM_NUM_INIT 16 78 | #define FDCAN_TX_FIFO_ELEM_SZ_INIT FDCAN_DATA_BYTES_64 79 | 80 | #define CAN_NUM_CHANNELS 2 81 | #define CAN_CLOCK_SPEED 120000000 82 | #define CANFD_FEATURE_ENABLED 83 | 84 | #define BOARD_TIM2_PRESCALER 240-1 85 | 86 | #define QUEUE_SIZE_HOST_TO_DEV 32 87 | #define QUEUE_SIZE_DEV_TO_HOST 32 88 | 89 | #define LED1_Pin GPIO_PIN_2 90 | #define LED1_GPIO_Port GPIOJ 91 | #define LED2_Pin GPIO_PIN_13 92 | #define LED2_GPIO_Port GPIOI 93 | #define LED3_Pin GPIO_PIN_3 94 | #define LED3_GPIO_Port GPIOD 95 | 96 | void SystemClock_Config(void); 97 | void MX_GPIO_Init(void); 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | #endif /*__ BOARD_H__ */ 103 | 104 | -------------------------------------------------------------------------------- /Portable/board_stm32h745i-disco/Inc/board_hal_config.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32_hal_config.h 5 | * @brief This file contains the define to select the correct 6 | * HAL for this board 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32_HAL_CONFIG_H__ 22 | #define __STM32_HAL_CONFIG_H__ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32h7xx_hal.h" 30 | 31 | 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | #endif /*__STM32_HAL_CONFIG_H__ */ 37 | 38 | -------------------------------------------------------------------------------- /Portable/board_stm32h745i-disco/Inc/stm32h7xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32h7xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2024 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32H7xx_IT_H 22 | #define __STM32H7xx_IT_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Private includes ----------------------------------------------------------*/ 29 | /* USER CODE BEGIN Includes */ 30 | 31 | /* USER CODE END Includes */ 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN ET */ 35 | 36 | /* USER CODE END ET */ 37 | 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* USER CODE BEGIN EC */ 40 | 41 | /* USER CODE END EC */ 42 | 43 | /* Exported macro ------------------------------------------------------------*/ 44 | /* USER CODE BEGIN EM */ 45 | 46 | /* USER CODE END EM */ 47 | 48 | /* Exported functions prototypes ---------------------------------------------*/ 49 | void NMI_Handler(void); 50 | void HardFault_Handler(void); 51 | void MemManage_Handler(void); 52 | void BusFault_Handler(void); 53 | void UsageFault_Handler(void); 54 | void DebugMon_Handler(void); 55 | void FDCAN1_IT0_IRQHandler(void); 56 | void FDCAN2_IT0_IRQHandler(void); 57 | void FDCAN1_IT1_IRQHandler(void); 58 | void FDCAN2_IT1_IRQHandler(void); 59 | void TIM1_UP_IRQHandler(void); 60 | void FDCAN_CAL_IRQHandler(void); 61 | void OTG_FS_EP1_OUT_IRQHandler(void); 62 | void OTG_FS_EP1_IN_IRQHandler(void); 63 | void OTG_FS_IRQHandler(void); 64 | /* USER CODE BEGIN EFP */ 65 | 66 | /* USER CODE END EFP */ 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif /* __STM32H7xx_IT_H */ 73 | -------------------------------------------------------------------------------- /Portable/board_stm32h745i-disco/README.md: -------------------------------------------------------------------------------- 1 | # Develop with STM32CubeIDE 2 | 3 | 1. This project can be imported to the STM32CubeIDE. Create new project (CTRL+N) and select **Makefile Project with Existing Code** 4 | 2. Enter the name, and location of this directory, and select MCU ARM GCC 5 | 3. Click **Finish** 6 | 7 | The project should be loaded and able to compile. Then you can use it as usual. 8 | 9 | ## Basic interaction from Linux 10 | 11 | The basic configuration of the CAN interface in Linux is done by `ip` command. We need to bring the interface down, then configure it and then bring it up. 12 | This can be done by following the code: 13 | 14 | ``` 15 | dbitrate=2000000 16 | bitrate=1000000 17 | sudo ip link set can0 down 18 | sudo ip link set can1 down 19 | sudo ip link set can0 type can bitrate ${bitrate} fd on dbitrate ${dbitrate} 20 | sudo ip link set can1 type can bitrate ${bitrate} fd on dbitrate ${dbitrate} 21 | sudo ip link set can0 up 22 | sudo ip link set can1 up 23 | ``` 24 | 25 | Then we should be able to send/receive data so we can simulate the traffic by sending custom frames using `cansend` utility, 26 | or by replaying the log using `canplayer`, or generating random traffic using `cangen`. 27 | 28 | Some examples of sending data are below: 29 | 30 | - `cansend can0 213##311223344` 31 | - `canplayer -I candump.log` 32 | - `cangen can0 -f -b -g 5` or `cangen can0 -c 10 -g 1` 33 | 34 | To analyze the bus load we can use `canbusload can0@1000000 can1@1000000 -r -t -b -c` which will each second will compute statistics per interface. 35 | This however works only with standard CAN 2.0 and the CAN FD is not supported. 36 | 37 | To display sent data use `candump can0` (it can contain more than one interface so we can use `candump can0 can1` and track the traffic of two interfaces). 38 | 39 | ## STM32H745I-DISCO issues 40 | 41 | After flashing the board may not be able to connect with the ST-Link GDB server from the IDE. To resolve this we need to delete the firmware from FLASH memory. 42 | This can be done using *STM32CubeProgrammer* by using the GUI or CLI interface. The CLI command looks like this `STM32_Programmer_CLI -c port=SWD mode=POWERDOWN -e All`. 43 | The **POWERDOWN** option is crucial here. Sometimes deleting only the first sector is enough so in the command replace `All` with `0` and the flashing should be fixed too. 44 | -------------------------------------------------------------------------------- /Portable/board_stm32h745i-disco/Src/stm32h7xx_hal_timebase_tim.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32h7xx_hal_timebase_tim.c 5 | * @brief HAL time base based on the hardware TIM. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2024 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "stm32h7xx_hal.h" 22 | #include "stm32h7xx_hal_tim.h" 23 | 24 | /* Private typedef -----------------------------------------------------------*/ 25 | /* Private define ------------------------------------------------------------*/ 26 | /* Private macro -------------------------------------------------------------*/ 27 | /* Private variables ---------------------------------------------------------*/ 28 | TIM_HandleTypeDef htim1; 29 | /* Private function prototypes -----------------------------------------------*/ 30 | /* Private functions ---------------------------------------------------------*/ 31 | 32 | /** 33 | * @brief This function configures the TIM1 as a time base source. 34 | * The time source is configured to have 1ms time base with a dedicated 35 | * Tick interrupt priority. 36 | * @note This function is called automatically at the beginning of program after 37 | * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). 38 | * @param TickPriority: Tick interrupt priority. 39 | * @retval HAL status 40 | */ 41 | HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) 42 | { 43 | RCC_ClkInitTypeDef clkconfig; 44 | uint32_t uwTimclock; 45 | 46 | uint32_t uwPrescalerValue; 47 | uint32_t pFLatency; 48 | /*Configure the TIM1 IRQ priority */ 49 | if (TickPriority < (1UL << __NVIC_PRIO_BITS)) 50 | { 51 | HAL_NVIC_SetPriority(TIM1_UP_IRQn, TickPriority ,0U); 52 | 53 | /* Enable the TIM1 global Interrupt */ 54 | HAL_NVIC_EnableIRQ(TIM1_UP_IRQn); 55 | uwTickPrio = TickPriority; 56 | } 57 | else 58 | { 59 | return HAL_ERROR; 60 | } 61 | 62 | /* Enable TIM1 clock */ 63 | __HAL_RCC_TIM1_CLK_ENABLE(); 64 | 65 | /* Get clock configuration */ 66 | HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); 67 | 68 | /* Compute TIM1 clock */ 69 | uwTimclock = 2*HAL_RCC_GetPCLK2Freq(); 70 | 71 | /* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */ 72 | uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); 73 | 74 | /* Initialize TIM1 */ 75 | htim1.Instance = TIM1; 76 | 77 | /* Initialize TIMx peripheral as follow: 78 | 79 | + Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base. 80 | + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. 81 | + ClockDivision = 0 82 | + Counter direction = Up 83 | */ 84 | htim1.Init.Period = (1000000U / 1000U) - 1U; 85 | htim1.Init.Prescaler = uwPrescalerValue; 86 | htim1.Init.ClockDivision = 0; 87 | htim1.Init.CounterMode = TIM_COUNTERMODE_UP; 88 | 89 | if(HAL_TIM_Base_Init(&htim1) == HAL_OK) 90 | { 91 | /* Start the TIM time Base generation in interrupt mode */ 92 | return HAL_TIM_Base_Start_IT(&htim1); 93 | } 94 | 95 | /* Return function status */ 96 | return HAL_ERROR; 97 | } 98 | 99 | /** 100 | * @brief Suspend Tick increment. 101 | * @note Disable the tick increment by disabling TIM1 update interrupt. 102 | * @param None 103 | * @retval None 104 | */ 105 | void HAL_SuspendTick(void) 106 | { 107 | /* Disable TIM1 update Interrupt */ 108 | __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE); 109 | } 110 | 111 | /** 112 | * @brief Resume Tick increment. 113 | * @note Enable the tick increment by Enabling TIM1 update interrupt. 114 | * @param None 115 | * @retval None 116 | */ 117 | void HAL_ResumeTick(void) 118 | { 119 | /* Enable TIM1 Update interrupt */ 120 | __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE); 121 | } 122 | 123 | -------------------------------------------------------------------------------- /Portable/board_stm32h745i-disco/stm32h745xx_flash_CM7.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | ** 4 | 5 | ** File : LinkerScript.ld 6 | ** 7 | ** 8 | ** Abstract : Linker script for STM32H7 series 9 | ** 1024Kbytes FLASH and 192Kbytes RAM 10 | ** 11 | ** Set heap size, stack size and stack location according 12 | ** to application requirements. 13 | ** 14 | ** Set memory bank area and size if external memory is used. 15 | ** 16 | ** Target : STMicroelectronics STM32 17 | ** 18 | ** Distribution: The file is distributed �as is,� without any warranty 19 | ** of any kind. 20 | ** 21 | ***************************************************************************** 22 | ** @attention 23 | ** 24 | ** Copyright (c) 2019 STMicroelectronics. 25 | ** All rights reserved. 26 | ** 27 | ** This software is licensed under terms that can be found in the LICENSE file 28 | ** in the root directory of this software component. 29 | ** If no LICENSE file comes with this software, it is provided AS-IS. 30 | ** 31 | ****************************************************************************** 32 | */ 33 | 34 | /* Entry Point */ 35 | ENTRY(Reset_Handler) 36 | 37 | /* Highest address of the user mode stack */ 38 | _estack = 0x20020000; /* end of RAM */ 39 | /* Generate a link error if heap and stack don't fit into RAM */ 40 | _Min_Heap_Size = 0x200; /* required amount of heap */ 41 | _Min_Stack_Size = 0x400; /* required amount of stack */ 42 | 43 | /* Specify the memory areas */ 44 | MEMORY 45 | { 46 | FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K 47 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K 48 | ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K 49 | } 50 | 51 | /* Define output sections */ 52 | SECTIONS 53 | { 54 | /* The startup code goes first into FLASH */ 55 | .isr_vector : 56 | { 57 | . = ALIGN(4); 58 | KEEP(*(.isr_vector)) /* Startup code */ 59 | . = ALIGN(4); 60 | } >FLASH 61 | 62 | /* The program code and other data goes into FLASH */ 63 | .text : 64 | { 65 | . = ALIGN(4); 66 | *(.text) /* .text sections (code) */ 67 | *(.text*) /* .text* sections (code) */ 68 | *(.glue_7) /* glue arm to thumb code */ 69 | *(.glue_7t) /* glue thumb to arm code */ 70 | *(.eh_frame) 71 | 72 | KEEP (*(.init)) 73 | KEEP (*(.fini)) 74 | 75 | . = ALIGN(4); 76 | _etext = .; /* define a global symbols at end of code */ 77 | } >FLASH 78 | 79 | /* Constant data goes into FLASH */ 80 | .rodata : 81 | { 82 | . = ALIGN(4); 83 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 84 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 85 | . = ALIGN(4); 86 | } >FLASH 87 | 88 | .ARM.extab (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 89 | { 90 | *(.ARM.extab* .gnu.linkonce.armextab.*) 91 | } >FLASH 92 | .ARM (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 93 | { 94 | __exidx_start = .; 95 | *(.ARM.exidx*) 96 | __exidx_end = .; 97 | } >FLASH 98 | 99 | .preinit_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 100 | { 101 | PROVIDE_HIDDEN (__preinit_array_start = .); 102 | KEEP (*(.preinit_array*)) 103 | PROVIDE_HIDDEN (__preinit_array_end = .); 104 | } >FLASH 105 | .init_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 106 | { 107 | PROVIDE_HIDDEN (__init_array_start = .); 108 | KEEP (*(SORT(.init_array.*))) 109 | KEEP (*(.init_array*)) 110 | PROVIDE_HIDDEN (__init_array_end = .); 111 | } >FLASH 112 | .fini_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 113 | { 114 | PROVIDE_HIDDEN (__fini_array_start = .); 115 | KEEP (*(SORT(.fini_array.*))) 116 | KEEP (*(.fini_array*)) 117 | PROVIDE_HIDDEN (__fini_array_end = .); 118 | } >FLASH 119 | 120 | /* used by the startup to initialize data */ 121 | _sidata = LOADADDR(.data); 122 | 123 | /* Initialized data sections goes into RAM, load LMA copy after code */ 124 | .data : 125 | { 126 | . = ALIGN(4); 127 | _sdata = .; /* create a global symbol at data start */ 128 | *(.data) /* .data sections */ 129 | *(.data*) /* .data* sections */ 130 | 131 | . = ALIGN(4); 132 | _edata = .; /* define a global symbol at data end */ 133 | } >RAM AT> FLASH 134 | 135 | 136 | /* Uninitialized data section */ 137 | . = ALIGN(4); 138 | .bss : 139 | { 140 | /* This is used by the startup in order to initialize the .bss secion */ 141 | _sbss = .; /* define a global symbol at bss start */ 142 | __bss_start__ = _sbss; 143 | *(.bss) 144 | *(.bss*) 145 | *(COMMON) 146 | 147 | . = ALIGN(4); 148 | _ebss = .; /* define a global symbol at bss end */ 149 | __bss_end__ = _ebss; 150 | } >RAM 151 | 152 | /* User_heap_stack section, used to check that there is enough RAM left */ 153 | ._user_heap_stack : 154 | { 155 | . = ALIGN(8); 156 | PROVIDE ( end = . ); 157 | PROVIDE ( _end = . ); 158 | . = . + _Min_Heap_Size; 159 | . = . + _Min_Stack_Size; 160 | . = ALIGN(8); 161 | } >RAM 162 | 163 | 164 | 165 | /* Remove information from the standard libraries */ 166 | /DISCARD/ : 167 | { 168 | libc.a ( * ) 169 | libm.a ( * ) 170 | libgcc.a ( * ) 171 | } 172 | 173 | .ARM.attributes 0 : { *(.ARM.attributes) } 174 | } 175 | 176 | 177 | -------------------------------------------------------------------------------- /Portable/board_stm32h745i-disco/stm32h745xx_sram1_CM7.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | ** 4 | 5 | ** File : LinkerScript.ld 6 | ** 7 | ** 8 | ** Abstract : Linker script for STM32H7 series 9 | ** 256Kbytes RAM_EXEC and 256Kbytes RAM 10 | ** 11 | ** Set heap size, stack size and stack location according 12 | ** to application requirements. 13 | ** 14 | ** Set memory bank area and size if external memory is used. 15 | ** 16 | ** Target : STMicroelectronics STM32 17 | ** 18 | ** Distribution: The file is distributed �as is,� without any warranty 19 | ** of any kind. 20 | ** 21 | ***************************************************************************** 22 | ** @attention 23 | ** 24 | ** Copyright (c) 2019 STMicroelectronics. 25 | ** All rights reserved. 26 | ** 27 | ** This software is licensed under terms that can be found in the LICENSE file 28 | ** in the root directory of this software component. 29 | ** If no LICENSE file comes with this software, it is provided AS-IS. 30 | ** 31 | ****************************************************************************** 32 | */ 33 | 34 | /* Entry Point */ 35 | ENTRY(Reset_Handler) 36 | 37 | /* Highest address of the user mode stack */ 38 | _estack = 0x24080000; /* end of RAM */ 39 | /* Generate a link error if heap and stack don't fit into RAM */ 40 | _Min_Heap_Size = 0x200; /* required amount of heap */ 41 | _Min_Stack_Size = 0x400; /* required amount of stack */ 42 | 43 | /* Specify the memory areas */ 44 | MEMORY 45 | { 46 | RAM_EXEC (rx) : ORIGIN = 0x24000000, LENGTH = 256K 47 | RAM (xrw) : ORIGIN = 0x24040000, LENGTH = 256K 48 | } 49 | 50 | /* Define output sections */ 51 | SECTIONS 52 | { 53 | /* The startup code goes first into RAM_EXEC */ 54 | .isr_vector : 55 | { 56 | . = ALIGN(4); 57 | KEEP(*(.isr_vector)) /* Startup code */ 58 | . = ALIGN(4); 59 | } >RAM_EXEC 60 | 61 | /* The program code and other data goes into RAM_EXEC */ 62 | .text : 63 | { 64 | . = ALIGN(4); 65 | *(.text) /* .text sections (code) */ 66 | *(.text*) /* .text* sections (code) */ 67 | *(.glue_7) /* glue arm to thumb code */ 68 | *(.glue_7t) /* glue thumb to arm code */ 69 | *(.eh_frame) 70 | 71 | KEEP (*(.init)) 72 | KEEP (*(.fini)) 73 | 74 | . = ALIGN(4); 75 | _etext = .; /* define a global symbols at end of code */ 76 | } >RAM_EXEC 77 | 78 | /* Constant data goes into RAM_EXEC */ 79 | .rodata : 80 | { 81 | . = ALIGN(4); 82 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 83 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 84 | . = ALIGN(4); 85 | } >RAM_EXEC 86 | 87 | .ARM.extab (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 88 | { 89 | *(.ARM.extab* .gnu.linkonce.armextab.*) 90 | } >RAM_EXEC 91 | .ARM (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 92 | { 93 | __exidx_start = .; 94 | *(.ARM.exidx*) 95 | __exidx_end = .; 96 | } >RAM_EXEC 97 | 98 | .preinit_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 99 | { 100 | PROVIDE_HIDDEN (__preinit_array_start = .); 101 | KEEP (*(.preinit_array*)) 102 | PROVIDE_HIDDEN (__preinit_array_end = .); 103 | } >RAM_EXEC 104 | .init_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 105 | { 106 | PROVIDE_HIDDEN (__init_array_start = .); 107 | KEEP (*(SORT(.init_array.*))) 108 | KEEP (*(.init_array*)) 109 | PROVIDE_HIDDEN (__init_array_end = .); 110 | } >RAM_EXEC 111 | .fini_array (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ 112 | { 113 | PROVIDE_HIDDEN (__fini_array_start = .); 114 | KEEP (*(SORT(.fini_array.*))) 115 | KEEP (*(.fini_array*)) 116 | PROVIDE_HIDDEN (__fini_array_end = .); 117 | } >RAM_EXEC 118 | 119 | /* used by the startup to initialize data */ 120 | _sidata = LOADADDR(.data); 121 | 122 | /* Initialized data sections goes into RAM, load LMA copy after code */ 123 | .data : 124 | { 125 | . = ALIGN(4); 126 | _sdata = .; /* create a global symbol at data start */ 127 | *(.data) /* .data sections */ 128 | *(.data*) /* .data* sections */ 129 | 130 | . = ALIGN(4); 131 | _edata = .; /* define a global symbol at data end */ 132 | } >RAM AT> RAM_EXEC 133 | 134 | 135 | /* Uninitialized data section */ 136 | . = ALIGN(4); 137 | .bss : 138 | { 139 | /* This is used by the startup in order to initialize the .bss secion */ 140 | _sbss = .; /* define a global symbol at bss start */ 141 | __bss_start__ = _sbss; 142 | *(.bss) 143 | *(.bss*) 144 | *(COMMON) 145 | 146 | . = ALIGN(4); 147 | _ebss = .; /* define a global symbol at bss end */ 148 | __bss_end__ = _ebss; 149 | } >RAM 150 | 151 | /* User_heap_stack section, used to check that there is enough RAM left */ 152 | ._user_heap_stack : 153 | { 154 | . = ALIGN(8); 155 | PROVIDE ( end = . ); 156 | PROVIDE ( _end = . ); 157 | . = . + _Min_Heap_Size; 158 | . = . + _Min_Stack_Size; 159 | . = ALIGN(8); 160 | } >RAM 161 | 162 | 163 | 164 | /* Remove information from the standard libraries */ 165 | /DISCARD/ : 166 | { 167 | libc.a ( * ) 168 | libm.a ( * ) 169 | libgcc.a ( * ) 170 | } 171 | 172 | .ARM.attributes 0 : { *(.ARM.attributes) } 173 | } 174 | 175 | 176 | --------------------------------------------------------------------------------