├── .cproject ├── .gitignore ├── .project ├── Core ├── Inc │ ├── FreeRTOSConfig.h │ ├── jk_bms_485.h │ ├── jk_bms_pylon.h │ ├── main.h │ ├── pylon_can_210124.h │ ├── stm32f4xx_hal_conf.h │ └── stm32f4xx_it.h ├── Src │ ├── freertos.c │ ├── jk_bms_485.c │ ├── jk_bms_pylon.c │ ├── main.c │ ├── pylon_can_210124.c │ ├── stm32f4xx_hal_msp.c │ ├── stm32f4xx_hal_timebase_tim.c │ ├── stm32f4xx_it.c │ ├── syscalls.c │ ├── sysmem.c │ └── system_stm32f4xx.c └── Startup │ └── startup_stm32f407vgtx.s ├── Docs └── CAN-Bus-protocol-PYLON-low-voltage-V1.2-20180408.pdf ├── Drivers ├── CMSIS │ ├── Device │ │ └── ST │ │ │ └── STM32F4xx │ │ │ ├── Include │ │ │ ├── stm32f407xx.h │ │ │ ├── stm32f4xx.h │ │ │ └── system_stm32f4xx.h │ │ │ └── License.md │ ├── 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 └── STM32F4xx_HAL_Driver │ ├── Inc │ ├── Legacy │ │ └── stm32_hal_legacy.h │ ├── stm32f4xx_hal.h │ ├── stm32f4xx_hal_can.h │ ├── stm32f4xx_hal_cortex.h │ ├── stm32f4xx_hal_def.h │ ├── stm32f4xx_hal_dma.h │ ├── stm32f4xx_hal_dma_ex.h │ ├── stm32f4xx_hal_exti.h │ ├── stm32f4xx_hal_flash.h │ ├── stm32f4xx_hal_flash_ex.h │ ├── stm32f4xx_hal_flash_ramfunc.h │ ├── stm32f4xx_hal_gpio.h │ ├── stm32f4xx_hal_gpio_ex.h │ ├── stm32f4xx_hal_pcd.h │ ├── stm32f4xx_hal_pcd_ex.h │ ├── stm32f4xx_hal_pwr.h │ ├── stm32f4xx_hal_pwr_ex.h │ ├── stm32f4xx_hal_rcc.h │ ├── stm32f4xx_hal_rcc_ex.h │ ├── stm32f4xx_hal_spi.h │ ├── stm32f4xx_hal_tim.h │ ├── stm32f4xx_hal_tim_ex.h │ ├── stm32f4xx_hal_uart.h │ └── stm32f4xx_ll_usb.h │ ├── License.md │ └── Src │ ├── stm32f4xx_hal.c │ ├── stm32f4xx_hal_can.c │ ├── stm32f4xx_hal_cortex.c │ ├── stm32f4xx_hal_dma.c │ ├── stm32f4xx_hal_dma_ex.c │ ├── stm32f4xx_hal_exti.c │ ├── stm32f4xx_hal_flash.c │ ├── stm32f4xx_hal_flash_ex.c │ ├── stm32f4xx_hal_flash_ramfunc.c │ ├── stm32f4xx_hal_gpio.c │ ├── stm32f4xx_hal_pcd.c │ ├── stm32f4xx_hal_pcd_ex.c │ ├── stm32f4xx_hal_pwr.c │ ├── stm32f4xx_hal_pwr_ex.c │ ├── stm32f4xx_hal_rcc.c │ ├── stm32f4xx_hal_rcc_ex.c │ ├── stm32f4xx_hal_spi.c │ ├── stm32f4xx_hal_tim.c │ ├── stm32f4xx_hal_tim_ex.c │ ├── stm32f4xx_hal_uart.c │ └── stm32f4xx_ll_usb.c ├── LICENSE.md ├── Lib └── ili9341 │ ├── ILI9341_GFX.c │ ├── ILI9341_GFX.h │ ├── ILI9341_STM32_Driver.c │ ├── ILI9341_STM32_Driver.h │ ├── fonts.c │ └── fonts.h ├── Middlewares ├── ST │ └── STM32_USB_Device_Library │ │ ├── Class │ │ └── CDC │ │ │ ├── Inc │ │ │ └── usbd_cdc.h │ │ │ └── Src │ │ │ └── usbd_cdc.c │ │ └── 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 │ └── Source │ ├── CMSIS_RTOS_V2 │ ├── cmsis_os.h │ ├── cmsis_os2.c │ ├── cmsis_os2.h │ ├── freertos_mpool.h │ └── freertos_os2.h │ ├── LICENSE │ ├── 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 │ ├── stream_buffer.h │ ├── task.h │ └── timers.h │ ├── list.c │ ├── portable │ ├── GCC │ │ └── ARM_CM4F │ │ │ ├── port.c │ │ │ └── portmacro.h │ └── MemMang │ │ └── heap_1.c │ ├── queue.c │ ├── stream_buffer.c │ ├── tasks.c │ └── timers.c ├── README.md ├── STM32F407VGTX_FLASH.ld ├── STM32F407VGTX_RAM.ld ├── USB_DEVICE ├── App │ ├── usb_device.c │ ├── usb_device.h │ ├── usbd_cdc_if.c │ ├── usbd_cdc_if.h │ ├── usbd_desc.c │ └── usbd_desc.h └── Target │ ├── usbd_conf.c │ └── usbd_conf.h └── jk-bms2pylontech.ioc /.gitignore: -------------------------------------------------------------------------------- 1 | /Release 2 | /Debug 3 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jk-bms2pylontech 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | com.st.stm32cube.ide.mcu.MCUCubeProjectNature 24 | org.eclipse.cdt.core.cnature 25 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAev2ProjectNature 26 | com.st.stm32cube.ide.mcu.MCUAdvancedStructureProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Core/Inc/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /* 3 | * FreeRTOS Kernel V10.3.1 4 | * Portion Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 5 | * Portion Copyright (C) 2019 StMicroelectronics, Inc. All Rights Reserved. 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 | * http://www.FreeRTOS.org 25 | * http://aws.amazon.com/freertos 26 | * 27 | * 1 tab == 4 spaces! 28 | */ 29 | /* USER CODE END Header */ 30 | 31 | #ifndef FREERTOS_CONFIG_H 32 | #define FREERTOS_CONFIG_H 33 | 34 | /*----------------------------------------------------------- 35 | * Application specific definitions. 36 | * 37 | * These definitions should be adjusted for your particular hardware and 38 | * application requirements. 39 | * 40 | * These parameters and more are described within the 'configuration' section of the 41 | * FreeRTOS API documentation available on the FreeRTOS.org web site. 42 | * 43 | * See http://www.freertos.org/a00110.html 44 | *----------------------------------------------------------*/ 45 | 46 | /* USER CODE BEGIN Includes */ 47 | /* Section where include file can be added */ 48 | /* USER CODE END Includes */ 49 | 50 | /* Ensure definitions are only used by the compiler, and not by the assembler. */ 51 | #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) 52 | #include 53 | extern uint32_t SystemCoreClock; 54 | #endif 55 | #ifndef CMSIS_device_header 56 | #define CMSIS_device_header "stm32f4xx.h" 57 | #endif /* CMSIS_device_header */ 58 | 59 | #define configENABLE_FPU 0 60 | #define configENABLE_MPU 0 61 | 62 | #define configUSE_PREEMPTION 1 63 | #define configSUPPORT_STATIC_ALLOCATION 1 64 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 65 | #define configUSE_IDLE_HOOK 0 66 | #define configUSE_TICK_HOOK 0 67 | #define configCPU_CLOCK_HZ ( SystemCoreClock ) 68 | #define configTICK_RATE_HZ ((TickType_t)1000) 69 | #define configMAX_PRIORITIES ( 56 ) 70 | #define configMINIMAL_STACK_SIZE ((uint16_t)128) 71 | #define configTOTAL_HEAP_SIZE ((size_t)15360) 72 | #define configMAX_TASK_NAME_LEN ( 16 ) 73 | #define configUSE_TRACE_FACILITY 1 74 | #define configUSE_16_BIT_TICKS 0 75 | #define configUSE_MUTEXES 1 76 | #define configQUEUE_REGISTRY_SIZE 8 77 | #define configUSE_RECURSIVE_MUTEXES 1 78 | #define configUSE_COUNTING_SEMAPHORES 1 79 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 80 | /* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */ 81 | /* Defaults to size_t for backward compatibility, but can be changed 82 | if lengths will always be less than the number of bytes in a size_t. */ 83 | #define configMESSAGE_BUFFER_LENGTH_TYPE size_t 84 | /* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */ 85 | 86 | /* Co-routine definitions. */ 87 | #define configUSE_CO_ROUTINES 0 88 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 89 | 90 | /* Software timer definitions. */ 91 | #define configUSE_TIMERS 1 92 | #define configTIMER_TASK_PRIORITY ( 2 ) 93 | #define configTIMER_QUEUE_LENGTH 10 94 | #define configTIMER_TASK_STACK_DEPTH 256 95 | 96 | /* The following flag must be enabled only when using newlib */ 97 | #define configUSE_NEWLIB_REENTRANT 1 98 | 99 | /* CMSIS-RTOS V2 flags */ 100 | #define configUSE_OS2_THREAD_SUSPEND_RESUME 1 101 | #define configUSE_OS2_THREAD_ENUMERATE 1 102 | #define configUSE_OS2_EVENTFLAGS_FROM_ISR 1 103 | #define configUSE_OS2_THREAD_FLAGS 1 104 | #define configUSE_OS2_TIMER 1 105 | #define configUSE_OS2_MUTEX 1 106 | 107 | /* Set the following definitions to 1 to include the API function, or zero 108 | to exclude the API function. */ 109 | #define INCLUDE_vTaskPrioritySet 1 110 | #define INCLUDE_uxTaskPriorityGet 1 111 | #define INCLUDE_vTaskDelete 1 112 | #define INCLUDE_vTaskCleanUpResources 0 113 | #define INCLUDE_vTaskSuspend 1 114 | #define INCLUDE_vTaskDelayUntil 1 115 | #define INCLUDE_vTaskDelay 1 116 | #define INCLUDE_xTaskGetSchedulerState 1 117 | #define INCLUDE_xTimerPendFunctionCall 1 118 | #define INCLUDE_xQueueGetMutexHolder 1 119 | #define INCLUDE_uxTaskGetStackHighWaterMark 1 120 | #define INCLUDE_xTaskGetCurrentTaskHandle 1 121 | #define INCLUDE_eTaskGetState 1 122 | 123 | /* 124 | * The CMSIS-RTOS V2 FreeRTOS wrapper is dependent on the heap implementation used 125 | * by the application thus the correct define need to be enabled below 126 | */ 127 | #define USE_FreeRTOS_HEAP_1 128 | 129 | /* Cortex-M specific definitions. */ 130 | #ifdef __NVIC_PRIO_BITS 131 | /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ 132 | #define configPRIO_BITS __NVIC_PRIO_BITS 133 | #else 134 | #define configPRIO_BITS 4 135 | #endif 136 | 137 | /* The lowest interrupt priority that can be used in a call to a "set priority" 138 | function. */ 139 | #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15 140 | 141 | /* The highest interrupt priority that can be used by any interrupt service 142 | routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL 143 | INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER 144 | PRIORITY THAN THIS! (higher priorities are lower numeric values. */ 145 | #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 146 | 147 | /* Interrupt priorities used by the kernel port layer itself. These are generic 148 | to all Cortex-M ports, and do not rely on any particular library functions. */ 149 | #define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) 150 | /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! 151 | See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ 152 | #define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) 153 | 154 | /* Normal assert() semantics without relying on the provision of an assert.h 155 | header file. */ 156 | /* USER CODE BEGIN 1 */ 157 | #define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );} 158 | /* USER CODE END 1 */ 159 | 160 | /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS 161 | standard names. */ 162 | #define vPortSVCHandler SVC_Handler 163 | #define xPortPendSVHandler PendSV_Handler 164 | 165 | /* IMPORTANT: After 10.3.1 update, Systick_Handler comes from NVIC (if SYS timebase = systick), otherwise from cmsis_os2.c */ 166 | 167 | #define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 0 168 | 169 | /* USER CODE BEGIN Defines */ 170 | /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */ 171 | /* USER CODE END Defines */ 172 | 173 | #endif /* FREERTOS_CONFIG_H */ 174 | -------------------------------------------------------------------------------- /Core/Inc/jk_bms_485.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jk_bms_485.h 3 | * 4 | * Created on: Mar 4, 2022 5 | * Author: maxx 6 | */ 7 | 8 | #ifndef INC_JK_BMS_485_H_ 9 | #define INC_JK_BMS_485_H_ 10 | 11 | #include "stm32f4xx_hal.h" 12 | #include 13 | 14 | typedef enum { 15 | v0 = 0, 16 | v1 = 1 17 | } bms_type; 18 | 19 | struct jk_bms_cell_voltage { 20 | uint8_t cell_number; 21 | uint16_t cell_voltage; 22 | }; 23 | 24 | struct jk_bms_limits { 25 | uint16_t battery_charge_voltage; 26 | uint16_t battery_charge_current_limit; 27 | uint16_t battery_discharge_current_limit; 28 | uint16_t battery_discharge_voltage; 29 | }; 30 | 31 | struct jk_bms_alarms { 32 | uint16_t alarm_data; 33 | bool low_capacity; 34 | bool power_tube_overtemperature; 35 | bool charging_overvoltage; 36 | bool discharging_undervoltage; 37 | bool battery_over_temperature; 38 | bool charging_overcurrent; 39 | bool discharging_overcurrent; 40 | bool cell_pressure_difference; 41 | bool overtemperature_alarm_battery_box; 42 | bool battery_low_temperature; 43 | bool cell_overvoltage; 44 | bool cell_undervoltage; 45 | bool a_protection_309_1; 46 | bool a_protection_309_2; 47 | }; 48 | 49 | struct jk_bms_battery_status { 50 | int8_t power_tube_temperature; 51 | int8_t sensor_temperature_1; 52 | int8_t sensor_temperature_2; 53 | int8_t temperature_sensor_count; 54 | uint16_t battery_voltage; 55 | int16_t battery_current; 56 | uint8_t battery_soc; 57 | uint16_t battery_cycles; 58 | uint32_t battery_cycle_capacity; 59 | 60 | uint8_t current_low_byte; 61 | uint8_t current_hi_byte; 62 | }; 63 | 64 | struct jk_bms_battery_info { 65 | uint8_t cells_number; 66 | struct jk_bms_cell_voltage cells_voltage[24]; 67 | struct jk_bms_battery_status battery_status; 68 | struct jk_bms_alarms battery_alarms; 69 | struct jk_bms_limits battery_limits; 70 | }; 71 | 72 | extern struct jk_bms_battery_info jk_bms_battery_info; 73 | 74 | void Request_JK_Battery_485_Status_Frame(UART_HandleTypeDef uart, bms_type type); 75 | bool JK_Battery_485_Check_Frame_CRC(uint8_t *data, uint16_t frame_size, bms_type type); 76 | void Parse_JK_Battery_485_Status_Frame(uint8_t *data, bms_type type); 77 | 78 | #endif /* INC_JK_BMS_485_H_ */ 79 | -------------------------------------------------------------------------------- /Core/Inc/jk_bms_pylon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jk_bms_pylon.h 3 | * 4 | * Created on: Mar 5, 2022 5 | * Author: maxx 6 | */ 7 | 8 | #ifndef INC_JK_BMS_PYLON_H_ 9 | #define INC_JK_BMS_PYLON_H_ 10 | 11 | #include "stm32f4xx_hal.h" 12 | #include "pylon_can_210124.h" 13 | 14 | void Tx_JK_BMS_Status_via_CAN(CAN_HandleTypeDef hcan1); 15 | void Create_Limits_Frame(CAN_TxHeaderTypeDef *TxHeader, uint8_t *dst_p, const struct pylon_can_210124_battery_limits_t *battery_limits); 16 | void Create_SOH_SOC_Frame(CAN_TxHeaderTypeDef *TxHeader, uint8_t *dst_p, const struct pylon_can_210124_battery_so_c_so_h_t *battery_soc_soh); 17 | void Create_Actual_Values_Frame(CAN_TxHeaderTypeDef *TxHeader, uint8_t *dst_p, const struct pylon_can_210124_battery_actual_values_u_it_t *actual_values); 18 | void Create_Manufacturer_Frame(CAN_TxHeaderTypeDef *TxHeader, uint8_t *dst_p); 19 | void Create_Battery_Request_Frame(CAN_TxHeaderTypeDef *TxHeader, uint8_t *dst_p, const struct pylon_can_210124_battery_request_t *battery_request); 20 | void Create_Alive_Msg_Frame(CAN_TxHeaderTypeDef *TxHeader, uint8_t *dst_p); 21 | void Create_Errors_Warnings_Frame(CAN_TxHeaderTypeDef *TxHeader, uint8_t *dst_p, const struct pylon_can_210124_battery_error_warnings_t *errors_warnings); 22 | 23 | #endif /* INC_JK_BMS_PYLON_H_ */ 24 | -------------------------------------------------------------------------------- /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 "stm32f4xx_hal.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 | 57 | /* USER CODE END EFP */ 58 | 59 | /* Private defines -----------------------------------------------------------*/ 60 | #define LED_D2_Pin GPIO_PIN_1 61 | #define LED_D2_GPIO_Port GPIOA 62 | #define TFT_DC_Pin GPIO_PIN_5 63 | #define TFT_DC_GPIO_Port GPIOC 64 | #define TFT_RST_Pin GPIO_PIN_1 65 | #define TFT_RST_GPIO_Port GPIOB 66 | #define TFT_CS_Pin GPIO_PIN_12 67 | #define TFT_CS_GPIO_Port GPIOB 68 | #define BMS_TYPE_SWITCH_Pin GPIO_PIN_0 69 | #define BMS_TYPE_SWITCH_GPIO_Port GPIOE 70 | /* USER CODE BEGIN Private defines */ 71 | 72 | #define ENABLE_LCD 73 | 74 | #ifdef ENABLE_LCD 75 | 76 | extern SPI_HandleTypeDef lcd_spi; 77 | 78 | #define LCD_BL_Pin GPIO_PIN_12 79 | #define LCD_BL_GPIO_Port GPIOB 80 | 81 | #endif /* ENABLE_LCD */ 82 | 83 | /* USER CODE END Private defines */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /* __MAIN_H */ 90 | -------------------------------------------------------------------------------- /Core/Inc/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_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 __STM32F4xx_IT_H 22 | #define __STM32F4xx_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 TIM1_UP_TIM10_IRQHandler(void); 56 | void USART1_IRQHandler(void); 57 | void OTG_FS_IRQHandler(void); 58 | /* USER CODE BEGIN EFP */ 59 | 60 | /* USER CODE END EFP */ 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* __STM32F4xx_IT_H */ 67 | -------------------------------------------------------------------------------- /Core/Src/freertos.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * File Name : freertos.c 5 | * Description : Code for freertos applications 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 "FreeRTOS.h" 22 | #include "task.h" 23 | #include "main.h" 24 | 25 | /* Private includes ----------------------------------------------------------*/ 26 | /* USER CODE BEGIN Includes */ 27 | 28 | /* USER CODE END Includes */ 29 | 30 | /* Private typedef -----------------------------------------------------------*/ 31 | /* USER CODE BEGIN PTD */ 32 | 33 | /* USER CODE END PTD */ 34 | 35 | /* Private define ------------------------------------------------------------*/ 36 | /* USER CODE BEGIN PD */ 37 | 38 | /* USER CODE END PD */ 39 | 40 | /* Private macro -------------------------------------------------------------*/ 41 | /* USER CODE BEGIN PM */ 42 | 43 | /* USER CODE END PM */ 44 | 45 | /* Private variables ---------------------------------------------------------*/ 46 | /* USER CODE BEGIN Variables */ 47 | 48 | /* USER CODE END Variables */ 49 | 50 | /* Private function prototypes -----------------------------------------------*/ 51 | /* USER CODE BEGIN FunctionPrototypes */ 52 | 53 | /* USER CODE END FunctionPrototypes */ 54 | 55 | /* Private application code --------------------------------------------------*/ 56 | /* USER CODE BEGIN Application */ 57 | 58 | /* USER CODE END Application */ 59 | 60 | -------------------------------------------------------------------------------- /Core/Src/jk_bms_pylon.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jk_bms_pylon.c 3 | * 4 | * Created on: Mar 5, 2022 5 | * Author: maxx 6 | */ 7 | #include "jk_bms_pylon.h" 8 | #include "jk_bms_485.h" 9 | #include "pylon_can_210124.h" 10 | #include "stm32f4xx_hal.h" 11 | #define LED_D2_Pin GPIO_PIN_1 12 | #define LED_D2_GPIO_Port GPIOA 13 | 14 | CAN_TxHeaderTypeDef TxHeader; 15 | uint8_t TxData[8]; 16 | uint32_t TxMailbox; 17 | 18 | void TX_CAN_Message(CAN_HandleTypeDef hcan) { 19 | 20 | //HAL_GPIO_WritePin(LED_D2_GPIO_Port, LED_D2_Pin, GPIO_PIN_SET); 21 | while(HAL_CAN_GetTxMailboxesFreeLevel(&hcan) < 1) {}; 22 | if (HAL_CAN_AddTxMessage(&hcan, &TxHeader, TxData, &TxMailbox) != HAL_OK) { 23 | //printf("TX error: %ld\r\n", TxHeader.StdId); 24 | } 25 | //HAL_GPIO_TogglePin(LED_D2_GPIO_Port, LED_D2_Pin); //Toggle the state of pin 26 | //waiting for message to leave 27 | while(HAL_CAN_IsTxMessagePending(&hcan, TxMailbox)) {} 28 | //HAL_GPIO_WritePin(LED_D2_GPIO_Port, LED_D2_Pin, GPIO_PIN_RESET); 29 | } 30 | 31 | void Tx_JK_BMS_Status_via_CAN(CAN_HandleTypeDef hcan) { 32 | struct pylon_can_210124_battery_limits_t battery_limits = { 33 | // JK <= 6720 = 67.20V = 672 => PYLON 34 | .battery_charge_voltage = jk_bms_battery_info.battery_limits.battery_charge_voltage / 10, 35 | // JK <= 25 = 25A = 250 => PYLON 36 | .battery_charge_current_limit = jk_bms_battery_info.battery_limits.battery_charge_current_limit * 10, 37 | // JK <= 300 = 300A = -3000 => PYLON 38 | .battery_discharge_current_limit = jk_bms_battery_info.battery_limits.battery_discharge_current_limit * 10, 39 | // JK <= 4512 = 45.12V = 451 => PYLON 40 | .battery_discharge_voltage = jk_bms_battery_info.battery_limits.battery_discharge_voltage / 10 41 | }; 42 | Create_Limits_Frame(&TxHeader, TxData, &battery_limits); //0x351 43 | TX_CAN_Message(hcan); 44 | struct pylon_can_210124_battery_so_c_so_h_t battery_soc_soh = { .so_c = 45 | jk_bms_battery_info.battery_status.battery_soc, .so_h = 95 }; 46 | Create_SOH_SOC_Frame(&TxHeader, TxData, &battery_soc_soh); //0x355 47 | TX_CAN_Message(hcan); 48 | 49 | int16_t temperature = jk_bms_battery_info.battery_status.power_tube_temperature; 50 | if (jk_bms_battery_info.battery_status.sensor_temperature_1 > temperature) { 51 | temperature = jk_bms_battery_info.battery_status.sensor_temperature_1; 52 | } 53 | if (jk_bms_battery_info.battery_status.sensor_temperature_2 > temperature) { 54 | temperature = jk_bms_battery_info.battery_status.sensor_temperature_2; 55 | } 56 | 57 | struct pylon_can_210124_battery_actual_values_u_it_t actual_values = { 58 | // JK <= 6267 = 62.67V = 6267 => PYLON 59 | .battery_voltage = jk_bms_battery_info.battery_status.battery_voltage, 60 | // JK <= 2974 = 29.74А = 297 => PYLON 61 | .battery_current = jk_bms_battery_info.battery_status.battery_current / 10, 62 | // JK <= 10 = 10 C = 100 => PYLON 63 | .battery_temperature = temperature * 10 64 | }; 65 | Create_Actual_Values_Frame(&TxHeader, TxData, &actual_values); //0x356 66 | TX_CAN_Message(hcan); 67 | Create_Manufacturer_Frame(&TxHeader, TxData); //0x35e 68 | TX_CAN_Message(hcan); 69 | bool request_charge = 0; 70 | if (battery_soc_soh.so_c < 20) { 71 | request_charge = 1; 72 | } 73 | struct pylon_can_210124_battery_request_t battery_request = { 74 | .full_charge_req = 0, .force_charge_req_ii = 0, 75 | .force_charge_req_i = request_charge, .discharge_enable = 1, 76 | .charge_enable = 1 }; 77 | Create_Battery_Request_Frame(&TxHeader, TxData, &battery_request); //0x35c 78 | TX_CAN_Message(hcan); 79 | 80 | Create_Alive_Msg_Frame(&TxHeader, TxData); //0x305 81 | TX_CAN_Message(hcan); 82 | if (jk_bms_battery_info.battery_alarms.alarm_data > 0) { 83 | struct pylon_can_210124_battery_error_warnings_t errors_warnings = { 84 | .overvoltage_err = jk_bms_battery_info.battery_alarms.charging_overvoltage, 85 | .undervoltage_err = jk_bms_battery_info.battery_alarms.discharging_undervoltage, 86 | .overtemperature_err = jk_bms_battery_info.battery_alarms.battery_over_temperature, 87 | .undertemperature_err = jk_bms_battery_info.battery_alarms.battery_low_temperature, 88 | .overcurrent_discharge_err = jk_bms_battery_info.battery_alarms.discharging_overcurrent, 89 | .charge_overcurrent_err = jk_bms_battery_info.battery_alarms.charging_overcurrent, 90 | .system_error = 0, 91 | .voltage_high_warn = jk_bms_battery_info.battery_alarms.cell_overvoltage, 92 | .voltage_low_warn = jk_bms_battery_info.battery_alarms.cell_undervoltage, 93 | .temperature_high_warn = jk_bms_battery_info.battery_alarms.power_tube_overtemperature, 94 | .temperature_low_warn = jk_bms_battery_info.battery_alarms.battery_low_temperature, 95 | .discharge_current_high_warn = 0, 96 | .charge_current_high_warn = 0, .internal_error_warn = 0, 97 | .module_numbers = 1 98 | }; 99 | Create_Errors_Warnings_Frame(&TxHeader, TxData, &errors_warnings); //0x359 100 | TX_CAN_Message(hcan); 101 | } 102 | 103 | } 104 | 105 | //https://www.setfirelabs.com/green-energy/pylontech-can-reading-can-replication 106 | 107 | //0x351 – 14 02 74 0E 74 0E CC 01 – Battery voltage + current limits 108 | void Create_Limits_Frame(CAN_TxHeaderTypeDef *TxHeader, uint8_t *dst_p, const struct pylon_can_210124_battery_limits_t *battery_limits) { 109 | TxHeader->IDE = CAN_ID_STD; 110 | TxHeader->StdId = PYLON_CAN_210124_BATTERY_LIMITS_FRAME_ID; 111 | TxHeader->RTR = CAN_RTR_DATA; 112 | TxHeader->DLC = pylon_can_210124_battery_limits_pack(dst_p, battery_limits, PYLON_CAN_210124_BATTERY_LIMITS_LENGTH); 113 | } 114 | 115 | //0x355 – 1A 00 64 00 – State of Health (SOH) / State of Charge (SOC) 116 | void Create_SOH_SOC_Frame(CAN_TxHeaderTypeDef *TxHeader, uint8_t *dst_p, const struct pylon_can_210124_battery_so_c_so_h_t *battery_soc_soh) { 117 | TxHeader->IDE = CAN_ID_STD; 118 | TxHeader->StdId = PYLON_CAN_210124_BATTERY_SO_C_SO_H_FRAME_ID; 119 | TxHeader->RTR = CAN_RTR_DATA; 120 | TxHeader->DLC = pylon_can_210124_battery_so_c_so_h_pack(dst_p, battery_soc_soh, PYLON_CAN_210124_BATTERY_SO_C_SO_H_LENGTH); 121 | } 122 | 123 | //0x356 – 4e 13 02 03 04 05 – Voltage / Current / Temp 124 | void Create_Actual_Values_Frame(CAN_TxHeaderTypeDef *TxHeader, uint8_t *dst_p, const struct pylon_can_210124_battery_actual_values_u_it_t *actual_values) { 125 | TxHeader->IDE = CAN_ID_STD; 126 | TxHeader->StdId = PYLON_CAN_210124_BATTERY_ACTUAL_VALUES_U_IT_FRAME_ID; 127 | TxHeader->RTR = CAN_RTR_DATA; 128 | TxHeader->DLC = pylon_can_210124_battery_actual_values_u_it_pack(dst_p, actual_values, PYLON_CAN_210124_BATTERY_ACTUAL_VALUES_U_IT_LENGTH); 129 | } 130 | 131 | //0x35E – 50 59 4C 4F 4E 20 20 20 – Manufacturer name (“PYLON “) 132 | void Create_Manufacturer_Frame(CAN_TxHeaderTypeDef *TxHeader, uint8_t *dst_p) { 133 | struct pylon_can_210124_battery_manufacturer_t manufacturer = { 134 | .manufaturer_string = 0x50594C4F4E202020 135 | }; 136 | 137 | TxHeader->IDE = CAN_ID_STD; 138 | TxHeader->StdId = PYLON_CAN_210124_BATTERY_MANUFACTURER_FRAME_ID; 139 | TxHeader->RTR = CAN_RTR_DATA; 140 | TxHeader->DLC = pylon_can_210124_battery_manufacturer_pack(dst_p, &manufacturer, PYLON_CAN_210124_BATTERY_MANUFACTURER_LENGTH); 141 | } 142 | 143 | //0x35C – C0 00 – Battery charge request flags 144 | void Create_Battery_Request_Frame(CAN_TxHeaderTypeDef *TxHeader, uint8_t *dst_p, const struct pylon_can_210124_battery_request_t *battery_request) { 145 | TxHeader->IDE = CAN_ID_STD; 146 | TxHeader->StdId = PYLON_CAN_210124_BATTERY_REQUEST_FRAME_ID; 147 | TxHeader->RTR = CAN_RTR_DATA; 148 | TxHeader->DLC = pylon_can_210124_battery_request_pack(dst_p, battery_request, PYLON_CAN_210124_BATTERY_REQUEST_LENGTH); 149 | } 150 | 151 | //0x305 – alive message 152 | void Create_Alive_Msg_Frame(CAN_TxHeaderTypeDef *TxHeader, uint8_t *dst_p) { 153 | struct pylon_can_210124_network_alive_msg_t alive_message = { 154 | .alive_packet = 33 155 | }; 156 | 157 | TxHeader->IDE = CAN_ID_STD; 158 | TxHeader->StdId = PYLON_CAN_210124_NETWORK_ALIVE_MSG_FRAME_ID; 159 | TxHeader->RTR = CAN_RTR_DATA; 160 | TxHeader->DLC = pylon_can_210124_network_alive_msg_pack(dst_p, &alive_message, PYLON_CAN_210124_NETWORK_ALIVE_MSG_LENGTH); 161 | } 162 | 163 | //0x359 – 00 00 00 00 0A 50 4E – Protection & Alarm flags 164 | void Create_Errors_Warnings_Frame(CAN_TxHeaderTypeDef *TxHeader, uint8_t *dst_p, const struct pylon_can_210124_battery_error_warnings_t *errors_warnings) { 165 | TxHeader->IDE = CAN_ID_STD; 166 | TxHeader->StdId = PYLON_CAN_210124_BATTERY_ERROR_WARNINGS_FRAME_ID; 167 | TxHeader->RTR = CAN_RTR_DATA; 168 | TxHeader->DLC = pylon_can_210124_battery_error_warnings_pack(dst_p, errors_warnings, PYLON_CAN_210124_BATTERY_ERROR_WARNINGS_LENGTH); 169 | } 170 | -------------------------------------------------------------------------------- /Core/Src/stm32f4xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_hal_msp.c 5 | * @brief This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 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 | /* Includes ------------------------------------------------------------------*/ 22 | #include "main.h" 23 | /* USER CODE BEGIN Includes */ 24 | 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 Define */ 34 | 35 | /* USER CODE END Define */ 36 | 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* USER CODE BEGIN Macro */ 39 | 40 | /* USER CODE END Macro */ 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 | /* External functions --------------------------------------------------------*/ 53 | /* USER CODE BEGIN ExternalFunctions */ 54 | 55 | /* USER CODE END ExternalFunctions */ 56 | 57 | /* USER CODE BEGIN 0 */ 58 | 59 | /* USER CODE END 0 */ 60 | /** 61 | * Initializes the Global MSP. 62 | */ 63 | void HAL_MspInit(void) 64 | { 65 | /* USER CODE BEGIN MspInit 0 */ 66 | 67 | /* USER CODE END MspInit 0 */ 68 | 69 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 70 | __HAL_RCC_PWR_CLK_ENABLE(); 71 | 72 | /* System interrupt init*/ 73 | /* PendSV_IRQn interrupt configuration */ 74 | HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0); 75 | 76 | /* USER CODE BEGIN MspInit 1 */ 77 | 78 | /* USER CODE END MspInit 1 */ 79 | } 80 | 81 | /** 82 | * @brief CAN MSP Initialization 83 | * This function configures the hardware resources used in this example 84 | * @param hcan: CAN handle pointer 85 | * @retval None 86 | */ 87 | void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan) 88 | { 89 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 90 | if(hcan->Instance==CAN1) 91 | { 92 | /* USER CODE BEGIN CAN1_MspInit 0 */ 93 | 94 | /* USER CODE END CAN1_MspInit 0 */ 95 | /* Peripheral clock enable */ 96 | __HAL_RCC_CAN1_CLK_ENABLE(); 97 | 98 | __HAL_RCC_GPIOD_CLK_ENABLE(); 99 | /**CAN1 GPIO Configuration 100 | PD0 ------> CAN1_RX 101 | PD1 ------> CAN1_TX 102 | */ 103 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; 104 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 105 | GPIO_InitStruct.Pull = GPIO_NOPULL; 106 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 107 | GPIO_InitStruct.Alternate = GPIO_AF9_CAN1; 108 | HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); 109 | 110 | /* USER CODE BEGIN CAN1_MspInit 1 */ 111 | 112 | /* USER CODE END CAN1_MspInit 1 */ 113 | } 114 | 115 | } 116 | 117 | /** 118 | * @brief CAN MSP De-Initialization 119 | * This function freeze the hardware resources used in this example 120 | * @param hcan: CAN handle pointer 121 | * @retval None 122 | */ 123 | void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan) 124 | { 125 | if(hcan->Instance==CAN1) 126 | { 127 | /* USER CODE BEGIN CAN1_MspDeInit 0 */ 128 | 129 | /* USER CODE END CAN1_MspDeInit 0 */ 130 | /* Peripheral clock disable */ 131 | __HAL_RCC_CAN1_CLK_DISABLE(); 132 | 133 | /**CAN1 GPIO Configuration 134 | PD0 ------> CAN1_RX 135 | PD1 ------> CAN1_TX 136 | */ 137 | HAL_GPIO_DeInit(GPIOD, GPIO_PIN_0|GPIO_PIN_1); 138 | 139 | /* USER CODE BEGIN CAN1_MspDeInit 1 */ 140 | 141 | /* USER CODE END CAN1_MspDeInit 1 */ 142 | } 143 | 144 | } 145 | 146 | /** 147 | * @brief SPI MSP Initialization 148 | * This function configures the hardware resources used in this example 149 | * @param hspi: SPI handle pointer 150 | * @retval None 151 | */ 152 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) 153 | { 154 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 155 | if(hspi->Instance==SPI2) 156 | { 157 | /* USER CODE BEGIN SPI2_MspInit 0 */ 158 | 159 | /* USER CODE END SPI2_MspInit 0 */ 160 | /* Peripheral clock enable */ 161 | __HAL_RCC_SPI2_CLK_ENABLE(); 162 | 163 | __HAL_RCC_GPIOB_CLK_ENABLE(); 164 | /**SPI2 GPIO Configuration 165 | PB13 ------> SPI2_SCK 166 | PB14 ------> SPI2_MISO 167 | PB15 ------> SPI2_MOSI 168 | */ 169 | GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; 170 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 171 | GPIO_InitStruct.Pull = GPIO_NOPULL; 172 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 173 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; 174 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 175 | 176 | /* USER CODE BEGIN SPI2_MspInit 1 */ 177 | 178 | /* USER CODE END SPI2_MspInit 1 */ 179 | } 180 | 181 | } 182 | 183 | /** 184 | * @brief SPI MSP De-Initialization 185 | * This function freeze the hardware resources used in this example 186 | * @param hspi: SPI handle pointer 187 | * @retval None 188 | */ 189 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) 190 | { 191 | if(hspi->Instance==SPI2) 192 | { 193 | /* USER CODE BEGIN SPI2_MspDeInit 0 */ 194 | 195 | /* USER CODE END SPI2_MspDeInit 0 */ 196 | /* Peripheral clock disable */ 197 | __HAL_RCC_SPI2_CLK_DISABLE(); 198 | 199 | /**SPI2 GPIO Configuration 200 | PB13 ------> SPI2_SCK 201 | PB14 ------> SPI2_MISO 202 | PB15 ------> SPI2_MOSI 203 | */ 204 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15); 205 | 206 | /* USER CODE BEGIN SPI2_MspDeInit 1 */ 207 | 208 | /* USER CODE END SPI2_MspDeInit 1 */ 209 | } 210 | 211 | } 212 | 213 | /** 214 | * @brief UART MSP Initialization 215 | * This function configures the hardware resources used in this example 216 | * @param huart: UART handle pointer 217 | * @retval None 218 | */ 219 | void HAL_UART_MspInit(UART_HandleTypeDef* huart) 220 | { 221 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 222 | if(huart->Instance==USART1) 223 | { 224 | /* USER CODE BEGIN USART1_MspInit 0 */ 225 | 226 | /* USER CODE END USART1_MspInit 0 */ 227 | /* Peripheral clock enable */ 228 | __HAL_RCC_USART1_CLK_ENABLE(); 229 | 230 | __HAL_RCC_GPIOA_CLK_ENABLE(); 231 | /**USART1 GPIO Configuration 232 | PA9 ------> USART1_TX 233 | PA10 ------> USART1_RX 234 | */ 235 | GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10; 236 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 237 | GPIO_InitStruct.Pull = GPIO_NOPULL; 238 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 239 | GPIO_InitStruct.Alternate = GPIO_AF7_USART1; 240 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 241 | 242 | /* USART1 interrupt Init */ 243 | HAL_NVIC_SetPriority(USART1_IRQn, 5, 0); 244 | HAL_NVIC_EnableIRQ(USART1_IRQn); 245 | /* USER CODE BEGIN USART1_MspInit 1 */ 246 | 247 | /* USER CODE END USART1_MspInit 1 */ 248 | } 249 | 250 | } 251 | 252 | /** 253 | * @brief UART MSP De-Initialization 254 | * This function freeze the hardware resources used in this example 255 | * @param huart: UART handle pointer 256 | * @retval None 257 | */ 258 | void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) 259 | { 260 | if(huart->Instance==USART1) 261 | { 262 | /* USER CODE BEGIN USART1_MspDeInit 0 */ 263 | 264 | /* USER CODE END USART1_MspDeInit 0 */ 265 | /* Peripheral clock disable */ 266 | __HAL_RCC_USART1_CLK_DISABLE(); 267 | 268 | /**USART1 GPIO Configuration 269 | PA9 ------> USART1_TX 270 | PA10 ------> USART1_RX 271 | */ 272 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); 273 | 274 | /* USART1 interrupt DeInit */ 275 | HAL_NVIC_DisableIRQ(USART1_IRQn); 276 | /* USER CODE BEGIN USART1_MspDeInit 1 */ 277 | 278 | /* USER CODE END USART1_MspDeInit 1 */ 279 | } 280 | 281 | } 282 | 283 | /* USER CODE BEGIN 1 */ 284 | 285 | /* USER CODE END 1 */ 286 | 287 | -------------------------------------------------------------------------------- /Core/Src/stm32f4xx_hal_timebase_tim.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_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 "stm32f4xx_hal.h" 22 | #include "stm32f4xx_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_UP_TIM10_IRQn, TickPriority ,0); 49 | 50 | /* Enable the TIM1 global Interrupt */ 51 | HAL_NVIC_EnableIRQ(TIM1_UP_TIM10_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_GetPCLK2Freq(); 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 | -------------------------------------------------------------------------------- /Core/Src/stm32f4xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_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 "stm32f4xx_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 PCD_HandleTypeDef hpcd_USB_OTG_FS; 59 | extern UART_HandleTypeDef huart1; 60 | extern TIM_HandleTypeDef htim1; 61 | 62 | /* USER CODE BEGIN EV */ 63 | 64 | /* USER CODE END EV */ 65 | 66 | /******************************************************************************/ 67 | /* Cortex-M4 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 | * @brief This function handles Memory management fault. 101 | */ 102 | void MemManage_Handler(void) 103 | { 104 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */ 105 | 106 | /* USER CODE END MemoryManagement_IRQn 0 */ 107 | while (1) 108 | { 109 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ 110 | /* USER CODE END W1_MemoryManagement_IRQn 0 */ 111 | } 112 | } 113 | 114 | /** 115 | * @brief This function handles Pre-fetch fault, memory access fault. 116 | */ 117 | void BusFault_Handler(void) 118 | { 119 | /* USER CODE BEGIN BusFault_IRQn 0 */ 120 | 121 | /* USER CODE END BusFault_IRQn 0 */ 122 | while (1) 123 | { 124 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */ 125 | /* USER CODE END W1_BusFault_IRQn 0 */ 126 | } 127 | } 128 | 129 | /** 130 | * @brief This function handles Undefined instruction or illegal state. 131 | */ 132 | void UsageFault_Handler(void) 133 | { 134 | /* USER CODE BEGIN UsageFault_IRQn 0 */ 135 | 136 | /* USER CODE END UsageFault_IRQn 0 */ 137 | while (1) 138 | { 139 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ 140 | /* USER CODE END W1_UsageFault_IRQn 0 */ 141 | } 142 | } 143 | 144 | /** 145 | * @brief This function handles Debug monitor. 146 | */ 147 | void DebugMon_Handler(void) 148 | { 149 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */ 150 | 151 | /* USER CODE END DebugMonitor_IRQn 0 */ 152 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */ 153 | 154 | /* USER CODE END DebugMonitor_IRQn 1 */ 155 | } 156 | 157 | /******************************************************************************/ 158 | /* STM32F4xx Peripheral Interrupt Handlers */ 159 | /* Add here the Interrupt Handlers for the used peripherals. */ 160 | /* For the available peripheral interrupt handler names, */ 161 | /* please refer to the startup file (startup_stm32f4xx.s). */ 162 | /******************************************************************************/ 163 | 164 | /** 165 | * @brief This function handles TIM1 update interrupt and TIM10 global interrupt. 166 | */ 167 | void TIM1_UP_TIM10_IRQHandler(void) 168 | { 169 | /* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */ 170 | 171 | /* USER CODE END TIM1_UP_TIM10_IRQn 0 */ 172 | HAL_TIM_IRQHandler(&htim1); 173 | /* USER CODE BEGIN TIM1_UP_TIM10_IRQn 1 */ 174 | 175 | /* USER CODE END TIM1_UP_TIM10_IRQn 1 */ 176 | } 177 | 178 | /** 179 | * @brief This function handles USART1 global interrupt. 180 | */ 181 | void USART1_IRQHandler(void) 182 | { 183 | /* USER CODE BEGIN USART1_IRQn 0 */ 184 | 185 | /* USER CODE END USART1_IRQn 0 */ 186 | HAL_UART_IRQHandler(&huart1); 187 | /* USER CODE BEGIN USART1_IRQn 1 */ 188 | 189 | /* USER CODE END USART1_IRQn 1 */ 190 | } 191 | 192 | /** 193 | * @brief This function handles USB On The Go FS global interrupt. 194 | */ 195 | void OTG_FS_IRQHandler(void) 196 | { 197 | /* USER CODE BEGIN OTG_FS_IRQn 0 */ 198 | 199 | /* USER CODE END OTG_FS_IRQn 0 */ 200 | HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS); 201 | /* USER CODE BEGIN OTG_FS_IRQn 1 */ 202 | 203 | /* USER CODE END OTG_FS_IRQn 1 */ 204 | } 205 | 206 | /* USER CODE BEGIN 1 */ 207 | 208 | /* USER CODE END 1 */ 209 | 210 | -------------------------------------------------------------------------------- /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) 2021 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) 2021 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 | -------------------------------------------------------------------------------- /Docs/CAN-Bus-protocol-PYLON-low-voltage-V1.2-20180408.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maxx-ukoo/jk-bms2pylontech/86d712058a226dbd808ffe4ce43e8775b10dd7e3/Docs/CAN-Bus-protocol-PYLON-low-voltage-V1.2-20180408.pdf -------------------------------------------------------------------------------- /Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maxx-ukoo/jk-bms2pylontech/86d712058a226dbd808ffe4ce43e8775b10dd7e3/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h -------------------------------------------------------------------------------- /Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2017 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /** @addtogroup CMSIS 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup stm32f4xx_system 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief Define to prevent recursive inclusion 46 | */ 47 | #ifndef __SYSTEM_STM32F4XX_H 48 | #define __SYSTEM_STM32F4XX_H 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | /** @addtogroup STM32F4xx_System_Includes 55 | * @{ 56 | */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | 63 | /** @addtogroup STM32F4xx_System_Exported_types 64 | * @{ 65 | */ 66 | /* This variable is updated in three ways: 67 | 1) by calling CMSIS function SystemCoreClockUpdate() 68 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 69 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 70 | Note: If you use this function to configure the system clock; then there 71 | is no need to call the 2 first functions listed above, since SystemCoreClock 72 | variable is updated automatically. 73 | */ 74 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 75 | 76 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 77 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @addtogroup STM32F4xx_System_Exported_Constants 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @addtogroup STM32F4xx_System_Exported_Macros 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @addtogroup STM32F4xx_System_Exported_Functions 100 | * @{ 101 | */ 102 | 103 | extern void SystemInit(void); 104 | extern void SystemCoreClockUpdate(void); 105 | /** 106 | * @} 107 | */ 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif /*__SYSTEM_STM32F4XX_H */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /** 120 | * @} 121 | */ 122 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 123 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_def.h 4 | * @author MCD Application Team 5 | * @brief This file contains HAL common defines, enumeration, macros and 6 | * structures definitions. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

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

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F4xx_HAL_DEF 23 | #define __STM32F4xx_HAL_DEF 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32f4xx.h" 31 | #include "Legacy/stm32_hal_legacy.h" 32 | #include 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | 36 | /** 37 | * @brief HAL Status structures definition 38 | */ 39 | typedef enum 40 | { 41 | HAL_OK = 0x00U, 42 | HAL_ERROR = 0x01U, 43 | HAL_BUSY = 0x02U, 44 | HAL_TIMEOUT = 0x03U 45 | } HAL_StatusTypeDef; 46 | 47 | /** 48 | * @brief HAL Lock structures definition 49 | */ 50 | typedef enum 51 | { 52 | HAL_UNLOCKED = 0x00U, 53 | HAL_LOCKED = 0x01U 54 | } HAL_LockTypeDef; 55 | 56 | /* Exported macro ------------------------------------------------------------*/ 57 | 58 | #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */ 59 | 60 | #define HAL_MAX_DELAY 0xFFFFFFFFU 61 | 62 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) == (BIT)) 63 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U) 64 | 65 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \ 66 | do{ \ 67 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \ 68 | (__DMA_HANDLE__).Parent = (__HANDLE__); \ 69 | } while(0U) 70 | 71 | /** @brief Reset the Handle's State field. 72 | * @param __HANDLE__ specifies the Peripheral Handle. 73 | * @note This macro can be used for the following purpose: 74 | * - When the Handle is declared as local variable; before passing it as parameter 75 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 76 | * to set to 0 the Handle's "State" field. 77 | * Otherwise, "State" field may have any random value and the first time the function 78 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed 79 | * (i.e. HAL_PPP_MspInit() will not be executed). 80 | * - When there is a need to reconfigure the low level hardware: instead of calling 81 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 82 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function 83 | * HAL_PPP_MspInit() which will reconfigure the low level hardware. 84 | * @retval None 85 | */ 86 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U) 87 | 88 | #if (USE_RTOS == 1U) 89 | /* Reserved for future use */ 90 | #error "USE_RTOS should be 0 in the current HAL release" 91 | #else 92 | #define __HAL_LOCK(__HANDLE__) \ 93 | do{ \ 94 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 95 | { \ 96 | return HAL_BUSY; \ 97 | } \ 98 | else \ 99 | { \ 100 | (__HANDLE__)->Lock = HAL_LOCKED; \ 101 | } \ 102 | }while (0U) 103 | 104 | #define __HAL_UNLOCK(__HANDLE__) \ 105 | do{ \ 106 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 107 | }while (0U) 108 | #endif /* USE_RTOS */ 109 | 110 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */ 111 | #ifndef __weak 112 | #define __weak __attribute__((weak)) 113 | #endif 114 | #ifndef __packed 115 | #define __packed __attribute__((packed)) 116 | #endif 117 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 118 | #ifndef __weak 119 | #define __weak __attribute__((weak)) 120 | #endif /* __weak */ 121 | #ifndef __packed 122 | #define __packed __attribute__((__packed__)) 123 | #endif /* __packed */ 124 | #endif /* __GNUC__ */ 125 | 126 | 127 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ 128 | #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */ 129 | #ifndef __ALIGN_BEGIN 130 | #define __ALIGN_BEGIN 131 | #endif 132 | #ifndef __ALIGN_END 133 | #define __ALIGN_END __attribute__ ((aligned (4))) 134 | #endif 135 | #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 136 | #ifndef __ALIGN_END 137 | #define __ALIGN_END __attribute__ ((aligned (4))) 138 | #endif /* __ALIGN_END */ 139 | #ifndef __ALIGN_BEGIN 140 | #define __ALIGN_BEGIN 141 | #endif /* __ALIGN_BEGIN */ 142 | #else 143 | #ifndef __ALIGN_END 144 | #define __ALIGN_END 145 | #endif /* __ALIGN_END */ 146 | #ifndef __ALIGN_BEGIN 147 | #if defined (__CC_ARM) /* ARM Compiler V5*/ 148 | #define __ALIGN_BEGIN __align(4) 149 | #elif defined (__ICCARM__) /* IAR Compiler */ 150 | #define __ALIGN_BEGIN 151 | #endif /* __CC_ARM */ 152 | #endif /* __ALIGN_BEGIN */ 153 | #endif /* __GNUC__ */ 154 | 155 | 156 | /** 157 | * @brief __RAM_FUNC definition 158 | */ 159 | #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) 160 | /* ARM Compiler V4/V5 and V6 161 | -------------------------- 162 | RAM functions are defined using the toolchain options. 163 | Functions that are executed in RAM should reside in a separate source module. 164 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 165 | area of a module to a memory space in physical RAM. 166 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 167 | dialog. 168 | */ 169 | #define __RAM_FUNC 170 | 171 | #elif defined ( __ICCARM__ ) 172 | /* ICCARM Compiler 173 | --------------- 174 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 175 | */ 176 | #define __RAM_FUNC __ramfunc 177 | 178 | #elif defined ( __GNUC__ ) 179 | /* GNU Compiler 180 | ------------ 181 | RAM functions are defined using a specific toolchain attribute 182 | "__attribute__((section(".RamFunc")))". 183 | */ 184 | #define __RAM_FUNC __attribute__((section(".RamFunc"))) 185 | 186 | #endif 187 | 188 | /** 189 | * @brief __NOINLINE definition 190 | */ 191 | #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined ( __GNUC__ ) 192 | /* ARM V4/V5 and V6 & GNU Compiler 193 | ------------------------------- 194 | */ 195 | #define __NOINLINE __attribute__ ( (noinline) ) 196 | 197 | #elif defined ( __ICCARM__ ) 198 | /* ICCARM Compiler 199 | --------------- 200 | */ 201 | #define __NOINLINE _Pragma("optimize = no_inline") 202 | 203 | #endif 204 | 205 | #ifdef __cplusplus 206 | } 207 | #endif 208 | 209 | #endif /* ___STM32F4xx_HAL_DEF */ 210 | 211 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 212 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dma_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of DMA HAL extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_HAL_DMA_EX_H 22 | #define __STM32F4xx_HAL_DMA_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F4xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup DMAEx 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /** @defgroup DMAEx_Exported_Types DMAEx Exported Types 41 | * @brief DMAEx Exported types 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @brief HAL DMA Memory definition 47 | */ 48 | typedef enum 49 | { 50 | MEMORY0 = 0x00U, /*!< Memory 0 */ 51 | MEMORY1 = 0x01U /*!< Memory 1 */ 52 | }HAL_DMA_MemoryTypeDef; 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /* Exported functions --------------------------------------------------------*/ 59 | /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions 60 | * @brief DMAEx Exported functions 61 | * @{ 62 | */ 63 | 64 | /** @defgroup DMAEx_Exported_Functions_Group1 Extended features functions 65 | * @brief Extended features functions 66 | * @{ 67 | */ 68 | 69 | /* IO operation functions *******************************************************/ 70 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 71 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 72 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory); 73 | 74 | /** 75 | * @} 76 | */ 77 | /** 78 | * @} 79 | */ 80 | 81 | /* Private functions ---------------------------------------------------------*/ 82 | /** @defgroup DMAEx_Private_Functions DMAEx Private Functions 83 | * @brief DMAEx Private functions 84 | * @{ 85 | */ 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /*__STM32F4xx_HAL_DMA_EX_H*/ 103 | 104 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 105 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH RAMFUNC driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

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

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

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F4xx_HAL_PCD_EX_H 22 | #define STM32F4xx_HAL_PCD_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx_hal_def.h" 30 | 31 | #if defined (USB_OTG_FS) || defined (USB_OTG_HS) 32 | /** @addtogroup STM32F4xx_HAL_Driver 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup PCDEx 37 | * @{ 38 | */ 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macros -----------------------------------------------------------*/ 42 | /* Exported functions --------------------------------------------------------*/ 43 | /** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions 44 | * @{ 45 | */ 46 | /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 47 | * @{ 48 | */ 49 | 50 | #if defined (USB_OTG_FS) || defined (USB_OTG_HS) 51 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size); 52 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size); 53 | #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */ 54 | 55 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) 56 | HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd); 57 | HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd); 58 | #endif /* defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) */ 59 | #if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) 60 | HAL_StatusTypeDef HAL_PCDEx_ActivateBCD(PCD_HandleTypeDef *hpcd); 61 | HAL_StatusTypeDef HAL_PCDEx_DeActivateBCD(PCD_HandleTypeDef *hpcd); 62 | void HAL_PCDEx_BCD_VBUSDetect(PCD_HandleTypeDef *hpcd); 63 | #endif /* defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) */ 64 | void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); 65 | void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */ 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | 89 | #endif /* STM32F4xx_HAL_PCD_EX_H */ 90 | 91 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 92 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/License.md: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 STMicroelectronics 2 | 3 | This software component is licensed by STMicroelectronics under the **BSD-3-Clause** license. You may not use this file except in compliance with this license. You may obtain a copy of the license [here](https://opensource.org/licenses/BSD-3-Clause). -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.c 4 | * @author MCD Application Team 5 | * @brief FLASH RAMFUNC module driver. 6 | * This file provides a FLASH firmware functions which should be 7 | * executed from internal SRAM 8 | * + Stop/Start the flash interface while System Run 9 | * + Enable/Disable the flash sleep while System Run 10 | @verbatim 11 | ============================================================================== 12 | ##### APIs executed from Internal RAM ##### 13 | ============================================================================== 14 | [..] 15 | *** ARM Compiler *** 16 | -------------------- 17 | [..] RAM functions are defined using the toolchain options. 18 | Functions that are be executed in RAM should reside in a separate 19 | source module. Using the 'Options for File' dialog you can simply change 20 | the 'Code / Const' area of a module to a memory space in physical RAM. 21 | Available memory areas are declared in the 'Target' tab of the 22 | Options for Target' dialog. 23 | 24 | *** ICCARM Compiler *** 25 | ----------------------- 26 | [..] RAM functions are defined using a specific toolchain keyword "__ramfunc". 27 | 28 | *** GNU Compiler *** 29 | -------------------- 30 | [..] RAM functions are defined using a specific toolchain attribute 31 | "__attribute__((section(".RamFunc")))". 32 | 33 | @endverbatim 34 | ****************************************************************************** 35 | * @attention 36 | * 37 | *

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

39 | * 40 | * This software component is licensed by ST under BSD 3-Clause license, 41 | * the "License"; You may not use this file except in compliance with the 42 | * License. You may obtain a copy of the License at: 43 | * opensource.org/licenses/BSD-3-Clause 44 | * 45 | ****************************************************************************** 46 | */ 47 | 48 | /* Includes ------------------------------------------------------------------*/ 49 | #include "stm32f4xx_hal.h" 50 | 51 | /** @addtogroup STM32F4xx_HAL_Driver 52 | * @{ 53 | */ 54 | 55 | /** @defgroup FLASH_RAMFUNC FLASH RAMFUNC 56 | * @brief FLASH functions executed from RAM 57 | * @{ 58 | */ 59 | #ifdef HAL_FLASH_MODULE_ENABLED 60 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \ 61 | defined(STM32F412Rx) || defined(STM32F412Cx) 62 | 63 | /* Private typedef -----------------------------------------------------------*/ 64 | /* Private define ------------------------------------------------------------*/ 65 | /* Private macro -------------------------------------------------------------*/ 66 | /* Private variables ---------------------------------------------------------*/ 67 | /* Private function prototypes -----------------------------------------------*/ 68 | /* Exported functions --------------------------------------------------------*/ 69 | /** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH RAMFUNC Exported Functions 70 | * @{ 71 | */ 72 | 73 | /** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions executed from internal RAM 74 | * @brief Peripheral Extended features functions 75 | * 76 | @verbatim 77 | 78 | =============================================================================== 79 | ##### ramfunc functions ##### 80 | =============================================================================== 81 | [..] 82 | This subsection provides a set of functions that should be executed from RAM 83 | transfers. 84 | 85 | @endverbatim 86 | * @{ 87 | */ 88 | 89 | /** 90 | * @brief Stop the flash interface while System Run 91 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 92 | * @note This mode couldn't be set while executing with the flash itself. 93 | * It should be done with specific routine executed from RAM. 94 | * @retval HAL status 95 | */ 96 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void) 97 | { 98 | /* Enable Power ctrl clock */ 99 | __HAL_RCC_PWR_CLK_ENABLE(); 100 | /* Stop the flash interface while System Run */ 101 | SET_BIT(PWR->CR, PWR_CR_FISSR); 102 | 103 | return HAL_OK; 104 | } 105 | 106 | /** 107 | * @brief Start the flash interface while System Run 108 | * @note This mode is only available for STM32F411xx/STM32F446xx devices. 109 | * @note This mode couldn't be set while executing with the flash itself. 110 | * It should be done with specific routine executed from RAM. 111 | * @retval HAL status 112 | */ 113 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void) 114 | { 115 | /* Enable Power ctrl clock */ 116 | __HAL_RCC_PWR_CLK_ENABLE(); 117 | /* Start the flash interface while System Run */ 118 | CLEAR_BIT(PWR->CR, PWR_CR_FISSR); 119 | 120 | return HAL_OK; 121 | } 122 | 123 | /** 124 | * @brief Enable the flash sleep while System Run 125 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 126 | * @note This mode could n't be set while executing with the flash itself. 127 | * It should be done with specific routine executed from RAM. 128 | * @retval HAL status 129 | */ 130 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void) 131 | { 132 | /* Enable Power ctrl clock */ 133 | __HAL_RCC_PWR_CLK_ENABLE(); 134 | /* Enable the flash sleep while System Run */ 135 | SET_BIT(PWR->CR, PWR_CR_FMSSR); 136 | 137 | return HAL_OK; 138 | } 139 | 140 | /** 141 | * @brief Disable the flash sleep while System Run 142 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 143 | * @note This mode couldn't be set while executing with the flash itself. 144 | * It should be done with specific routine executed from RAM. 145 | * @retval HAL status 146 | */ 147 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void) 148 | { 149 | /* Enable Power ctrl clock */ 150 | __HAL_RCC_PWR_CLK_ENABLE(); 151 | /* Disable the flash sleep while System Run */ 152 | CLEAR_BIT(PWR->CR, PWR_CR_FMSSR); 153 | 154 | return HAL_OK; 155 | } 156 | 157 | /** 158 | * @} 159 | */ 160 | 161 | /** 162 | * @} 163 | */ 164 | 165 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 166 | #endif /* HAL_FLASH_MODULE_ENABLED */ 167 | /** 168 | * @} 169 | */ 170 | 171 | /** 172 | * @} 173 | */ 174 | 175 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 176 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2022 Maksym Krasovskyi 2 | 3 | Using this software you agree that putin is huilo, russian federation is a terrorist state. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /Lib/ili9341/ILI9341_GFX.h: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017 Matej Artnak 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 | // 23 | // 24 | // 25 | //----------------------------------- 26 | // ILI9341 GFX library for STM32 27 | //----------------------------------- 28 | // 29 | // Very simple GFX library built upon ILI9342_STM32_Driver library. 30 | // Adds basic shapes, image and font drawing capabilities to ILI9341 31 | // 32 | // Library is written for STM32 HAL library and supports STM32CUBEMX. To use the library with Cube software 33 | // you need to tick the box that generates peripheral initialization code in their own respective .c and .h file 34 | // 35 | // 36 | //----------------------------------- 37 | // How to use this library 38 | //----------------------------------- 39 | // 40 | // -If using MCUs other than STM32F7 you will have to change the #include "stm32f7xx_hal.h" in the ILI9341_GFX.h to your respective .h file 41 | // 42 | // If using "ILI9341_STM32_Driver" then all other prequisites to use the library have allready been met 43 | // Simply include the library and it is ready to be used 44 | // 45 | //----------------------------------- 46 | 47 | #ifndef ILI9341_GFX_H 48 | #define ILI9341_GFX_H 49 | 50 | #include "stm32f4xx_hal.h" 51 | #include "fonts.h" 52 | 53 | #define HORIZONTAL_IMAGE 0 54 | #define VERTICAL_IMAGE 1 55 | 56 | void ILI9341_Draw_Hollow_Circle(uint16_t X, uint16_t Y, uint16_t Radius, uint16_t Colour); 57 | void ILI9341_Draw_Filled_Circle(uint16_t X, uint16_t Y, uint16_t Radius, uint16_t Colour); 58 | void ILI9341_Draw_Hollow_Rectangle_Coord(uint16_t X0, uint16_t Y0, uint16_t X1, uint16_t Y1, uint16_t Colour); 59 | void ILI9341_Draw_Filled_Rectangle_Coord(uint16_t X0, uint16_t Y0, uint16_t X1, uint16_t Y1, uint16_t Colour); 60 | void ILI9341_Draw_Char(char Character, uint16_t X, uint16_t Y, uint16_t Colour, FontDef font, uint16_t Background_Colour); 61 | void ILI9341_Draw_Text(const char* Text, uint16_t X, uint16_t Y, uint16_t Colour, FontDef font, uint16_t Background_Colour); 62 | void ILI9341_Draw_Text_Space(const char* Text, uint16_t X, uint16_t Y, uint16_t Colour, FontDef font, uint16_t Background_Colour, uint8_t Space); 63 | void ILI9341_Draw_Filled_Rectangle_Size_Text(uint16_t X0, uint16_t Y0, uint16_t Size_X, uint16_t Size_Y, uint16_t Colour); 64 | 65 | //USING CONVERTER: http://www.digole.com/tools/PicturetoC_Hex_converter.php 66 | //65K colour (2Bytes / Pixel) 67 | void ILI9341_Draw_Image(const char* Image_Array, uint8_t Orientation); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /Lib/ili9341/ILI9341_STM32_Driver.h: -------------------------------------------------------------------------------- 1 | 2 | // MIT License 3 | // 4 | // Copyright (c) 2017 Matej Artnak 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | // SOFTWARE. 23 | // 24 | // 25 | // 26 | //----------------------------------- 27 | // ILI9341 Driver library for STM32 28 | //----------------------------------- 29 | // 30 | // While there are other libraries for ILI9341 they mostly require either interrupts, DMA or both for fast drawing 31 | // The intent of this library is to offer a simple yet still reasonably fast alternatives for those that 32 | // do not wish to use interrupts or DMA in their projects. 33 | // 34 | // Library is written for STM32 HAL library and supports STM32CUBEMX. To use the library with Cube software 35 | // you need to tick the box that generates peripheral initialization code in their own respective .c and .h file 36 | // 37 | // 38 | //----------------------------------- 39 | // Performance 40 | //----------------------------------- 41 | // Settings: 42 | // --SPI @ 50MHz 43 | // --STM32F746ZG Nucleo board 44 | // --Redraw entire screen 45 | // 46 | // ++ Theoretical maximum FPS with 50Mhz SPI calculated to be 40.69 FPS 47 | // ++ 320*240 = 76800 pixels, each pixel contains 16bit colour information (2x8) 48 | // ++ Theoretical Max FPS: 1/((320*240*16)/50000000) 49 | // 50 | // With ART Accelerator, instruction prefetch, CPI ICACHE and CPU DCACHE enabled: 51 | // 52 | // -FPS: 39.62 53 | // -SPI utilization: 97.37% 54 | // -MB/Second: 6.09 55 | // 56 | // With ART Accelerator, instruction prefetch, CPI ICACHE and CPU DCACHE disabled: 57 | // 58 | // -FPS: 35.45 59 | // -SPI utilization: 87.12% 60 | // -MB/Second: 5.44 61 | // 62 | // ART Accelerator, instruction prefetch, CPI ICACHE and CPU DCACHE settings found in MXCUBE under "System-> CORTEX M7 button" 63 | // 64 | // 65 | // 66 | //----------------------------------- 67 | // How to use this library 68 | //----------------------------------- 69 | // 70 | // -generate SPI peripheral and 3 GPIO_SPEED_FREQ_VERY_HIGH GPIO outputs 71 | // ++Library reinitializes GPIOs and SPIs generated by gpio.c/.h and spi.c/.h using MX_X_Init(); calls 72 | // ++reinitialization will not clash with previous initialization so generated initializations can be laft as they are 73 | // -If using MCUs other than STM32F7 you will have to change the #include "stm32f7xx_hal.h" in the ILI9341_STM32_Driver.h to your respective .h file 74 | // -define your HSPI_INSTANCE in ILI9341_STM32_Driver.h 75 | // -define your CS, DC and RST outputs in ILI9341_STM32_Driver.h 76 | // -check if ILI9341_SCREEN_HEIGHT and ILI9341_SCREEN_WIDTH match your LCD size 77 | // ++Library was written and tested for 320x240 screen size. Other sizes might have issues** 78 | // -in your main program initialize LCD with ILI9341_Init(); 79 | // -library is now ready to be used. Driver library has only basic functions, for more advanced functions see ILI9341_GFX library 80 | // 81 | //----------------------------------- 82 | 83 | 84 | #ifndef ILI9341_STM32_DRIVER_H 85 | #define ILI9341_STM32_DRIVER_H 86 | 87 | #include "stm32f4xx_hal.h" 88 | #include "main.h" 89 | 90 | 91 | #define ILI9341_SCREEN_HEIGHT 240 92 | #define ILI9341_SCREEN_WIDTH 320 93 | 94 | //SPI INSTANCE 95 | #define HSPI_INSTANCE &lcd_spi 96 | 97 | //CHIP SELECT PIN AND PORT, STANDARD GPIO 98 | #define LCD_CS_PORT TFT_CS_GPIO_Port 99 | #define LCD_CS_PIN TFT_CS_Pin 100 | 101 | //DATA COMMAND PIN AND PORT, STANDARD GPIO 102 | #define LCD_DC_PORT TFT_DC_GPIO_Port 103 | #define LCD_DC_PIN TFT_DC_Pin 104 | 105 | //RESET PIN AND PORT, STANDARD GPIO 106 | #define LCD_RST_PORT TFT_RST_GPIO_Port 107 | #define LCD_RST_PIN TFT_RST_Pin 108 | 109 | 110 | #define BURST_MAX_SIZE 500 111 | 112 | #define BLACK 0x0000 113 | #define NAVY 0x000F 114 | #define DARKGREEN 0x03E0 115 | #define DARKCYAN 0x03EF 116 | #define MAROON 0x7800 117 | #define PURPLE 0x780F 118 | #define OLIVE 0x7BE0 119 | #define LIGHTGREY 0xC618 120 | #define DARKGREY 0x7BEF 121 | #define BLUE 0x001F 122 | #define GREEN 0x07E0 123 | #define CYAN 0x07FF 124 | #define RED 0xF800 125 | #define MAGENTA 0xF81F 126 | #define YELLOW 0xFFE0 127 | #define WHITE 0xFFFF 128 | #define ORANGE 0xFD20 129 | #define GREENYELLOW 0xAFE5 130 | #define PINK 0xF81F 131 | 132 | #define SCREEN_VERTICAL_1 0 133 | #define SCREEN_HORIZONTAL_1 1 134 | #define SCREEN_VERTICAL_2 2 135 | #define SCREEN_HORIZONTAL_2 3 136 | 137 | void ILI9341_SPI_Init(void); 138 | void ILI9341_SPI_Send(unsigned char SPI_Data); 139 | void ILI9341_Write_Command(uint8_t Command); 140 | void ILI9341_Write_Data(uint8_t Data); 141 | void ILI9341_Set_Address(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2); 142 | void ILI9341_Reset(void); 143 | void ILI9341_Set_Rotation(uint8_t Rotation); 144 | void ILI9341_Enable(void); 145 | void ILI9341_Init(void); 146 | void ILI9341_Fill_Screen(uint16_t Colour); 147 | void ILI9341_Draw_Colour(uint16_t Colour); 148 | void ILI9341_Draw_Pixel(uint16_t X,uint16_t Y,uint16_t Colour); 149 | void ILI9341_Draw_Colour_Burst(uint16_t Colour, uint32_t Size); 150 | 151 | 152 | void ILI9341_Draw_Rectangle(uint16_t X, uint16_t Y, uint16_t Width, uint16_t Height, uint16_t Colour); 153 | void ILI9341_Draw_Horizontal_Line(uint16_t X, uint16_t Y, uint16_t Width, uint16_t Colour); 154 | void ILI9341_Draw_Vertical_Line(uint16_t X, uint16_t Y, uint16_t Height, uint16_t Colour); 155 | 156 | #endif 157 | 158 | -------------------------------------------------------------------------------- /Lib/ili9341/fonts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * fonts.h 3 | * 4 | * Created on: Mar 12, 2022 5 | * Author: maxx 6 | */ 7 | 8 | #ifndef FONTS_H_ 9 | #define FONTS_H_ 10 | 11 | 12 | #include 13 | 14 | typedef struct { 15 | uint8_t start_char; 16 | uint8_t offset; 17 | uint8_t width; 18 | uint8_t height; 19 | uint8_t bpl; 20 | const uint8_t *data; 21 | } FontDef; 22 | 23 | extern FontDef Font_8x12; 24 | extern FontDef Font_10x13; 25 | extern FontDef Font_34x36; 26 | extern FontDef Font_37x47; 27 | extern FontDef Font_26_B; 28 | 29 | #endif /* FONTS_H_ */ 30 | -------------------------------------------------------------------------------- /Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_cdc.h 4 | * @author MCD Application Team 5 | * @brief header file for the usbd_cdc.c file. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USB_CDC_H 22 | #define __USB_CDC_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_ioreq.h" 30 | 31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 32 | * @{ 33 | */ 34 | 35 | /** @defgroup usbd_cdc 36 | * @brief This file is the Header file for usbd_cdc.c 37 | * @{ 38 | */ 39 | 40 | 41 | /** @defgroup usbd_cdc_Exported_Defines 42 | * @{ 43 | */ 44 | #define CDC_IN_EP 0x81U /* EP1 for data IN */ 45 | #define CDC_OUT_EP 0x01U /* EP1 for data OUT */ 46 | #define CDC_CMD_EP 0x82U /* EP2 for CDC commands */ 47 | 48 | #ifndef CDC_HS_BINTERVAL 49 | #define CDC_HS_BINTERVAL 0x10U 50 | #endif /* CDC_HS_BINTERVAL */ 51 | 52 | #ifndef CDC_FS_BINTERVAL 53 | #define CDC_FS_BINTERVAL 0x10U 54 | #endif /* CDC_FS_BINTERVAL */ 55 | 56 | /* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */ 57 | #define CDC_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */ 58 | #define CDC_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */ 59 | #define CDC_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */ 60 | 61 | #define USB_CDC_CONFIG_DESC_SIZ 67U 62 | #define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE 63 | #define CDC_DATA_HS_OUT_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE 64 | 65 | #define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE 66 | #define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE 67 | 68 | #define CDC_REQ_MAX_DATA_SIZE 0x7U 69 | /*---------------------------------------------------------------------*/ 70 | /* CDC definitions */ 71 | /*---------------------------------------------------------------------*/ 72 | #define CDC_SEND_ENCAPSULATED_COMMAND 0x00U 73 | #define CDC_GET_ENCAPSULATED_RESPONSE 0x01U 74 | #define CDC_SET_COMM_FEATURE 0x02U 75 | #define CDC_GET_COMM_FEATURE 0x03U 76 | #define CDC_CLEAR_COMM_FEATURE 0x04U 77 | #define CDC_SET_LINE_CODING 0x20U 78 | #define CDC_GET_LINE_CODING 0x21U 79 | #define CDC_SET_CONTROL_LINE_STATE 0x22U 80 | #define CDC_SEND_BREAK 0x23U 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | 87 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 88 | * @{ 89 | */ 90 | 91 | /** 92 | * @} 93 | */ 94 | typedef struct 95 | { 96 | uint32_t bitrate; 97 | uint8_t format; 98 | uint8_t paritytype; 99 | uint8_t datatype; 100 | } USBD_CDC_LineCodingTypeDef; 101 | 102 | typedef struct _USBD_CDC_Itf 103 | { 104 | int8_t (* Init)(void); 105 | int8_t (* DeInit)(void); 106 | int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length); 107 | int8_t (* Receive)(uint8_t *Buf, uint32_t *Len); 108 | int8_t (* TransmitCplt)(uint8_t *Buf, uint32_t *Len, uint8_t epnum); 109 | } USBD_CDC_ItfTypeDef; 110 | 111 | 112 | typedef struct 113 | { 114 | uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32bits alignment */ 115 | uint8_t CmdOpCode; 116 | uint8_t CmdLength; 117 | uint8_t *RxBuffer; 118 | uint8_t *TxBuffer; 119 | uint32_t RxLength; 120 | uint32_t TxLength; 121 | 122 | __IO uint32_t TxState; 123 | __IO uint32_t RxState; 124 | } USBD_CDC_HandleTypeDef; 125 | 126 | 127 | 128 | /** @defgroup USBD_CORE_Exported_Macros 129 | * @{ 130 | */ 131 | 132 | /** 133 | * @} 134 | */ 135 | 136 | /** @defgroup USBD_CORE_Exported_Variables 137 | * @{ 138 | */ 139 | 140 | extern USBD_ClassTypeDef USBD_CDC; 141 | #define USBD_CDC_CLASS &USBD_CDC 142 | /** 143 | * @} 144 | */ 145 | 146 | /** @defgroup USB_CORE_Exported_Functions 147 | * @{ 148 | */ 149 | uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev, 150 | USBD_CDC_ItfTypeDef *fops); 151 | 152 | uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, 153 | uint32_t length); 154 | 155 | uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff); 156 | uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev); 157 | uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev); 158 | /** 159 | * @} 160 | */ 161 | 162 | #ifdef __cplusplus 163 | } 164 | #endif 165 | 166 | #endif /* __USB_CDC_H */ 167 | /** 168 | * @} 169 | */ 170 | 171 | /** 172 | * @} 173 | */ 174 | 175 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 176 | -------------------------------------------------------------------------------- /Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_core.h 4 | * @author MCD Application Team 5 | * @brief Header file for usbd_core.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_CORE_H 22 | #define __USBD_CORE_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_conf.h" 30 | #include "usbd_def.h" 31 | #include "usbd_ioreq.h" 32 | #include "usbd_ctlreq.h" 33 | 34 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 35 | * @{ 36 | */ 37 | 38 | /** @defgroup USBD_CORE 39 | * @brief This file is the Header file for usbd_core.c file 40 | * @{ 41 | */ 42 | 43 | 44 | /** @defgroup USBD_CORE_Exported_Defines 45 | * @{ 46 | */ 47 | #ifndef USBD_DEBUG_LEVEL 48 | #define USBD_DEBUG_LEVEL 0U 49 | #endif /* USBD_DEBUG_LEVEL */ 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 56 | * @{ 57 | */ 58 | 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | 66 | /** @defgroup USBD_CORE_Exported_Macros 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup USBD_CORE_Exported_Variables 75 | * @{ 76 | */ 77 | #define USBD_SOF USBD_LL_SOF 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @defgroup USBD_CORE_Exported_FunctionsPrototype 83 | * @{ 84 | */ 85 | USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id); 86 | USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev); 87 | USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev); 88 | USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev); 89 | USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass); 90 | 91 | USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev); 92 | USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 93 | USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 94 | 95 | USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup); 96 | USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); 97 | USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); 98 | 99 | USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev); 100 | USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed); 101 | USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev); 102 | USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev); 103 | 104 | USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev); 105 | USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 106 | USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 107 | 108 | USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev); 109 | USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev); 110 | 111 | /* USBD Low Level Driver */ 112 | USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev); 113 | USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev); 114 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev); 115 | USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev); 116 | 117 | USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, 118 | uint8_t ep_type, uint16_t ep_mps); 119 | 120 | USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 121 | USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 122 | USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 123 | USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 124 | USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr); 125 | 126 | USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, 127 | uint8_t *pbuf, uint32_t size); 128 | 129 | USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, 130 | uint8_t *pbuf, uint32_t size); 131 | 132 | uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 133 | uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 134 | 135 | void USBD_LL_Delay(uint32_t Delay); 136 | 137 | /** 138 | * @} 139 | */ 140 | 141 | #ifdef __cplusplus 142 | } 143 | #endif 144 | 145 | #endif /* __USBD_CORE_H */ 146 | 147 | /** 148 | * @} 149 | */ 150 | 151 | /** 152 | * @} 153 | */ 154 | 155 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /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 component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USB_REQUEST_H 22 | #define __USB_REQUEST_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBD_REQ 37 | * @brief header file for the usbd_req.c file 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_REQ_Exported_Defines 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_REQ_Exported_Types 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | 58 | /** @defgroup USBD_REQ_Exported_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @defgroup USBD_REQ_Exported_Variables 66 | * @{ 67 | */ 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype 73 | * @{ 74 | */ 75 | 76 | USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 77 | USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 78 | USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 79 | 80 | void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 81 | void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata); 82 | void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len); 83 | 84 | /** 85 | * @} 86 | */ 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif /* __USB_REQUEST_H */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | 103 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 104 | -------------------------------------------------------------------------------- /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 component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_IOREQ_H 22 | #define __USBD_IOREQ_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | #include "usbd_core.h" 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBD_IOREQ 37 | * @brief header file for the usbd_ioreq.c file 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_IOREQ_Exported_Defines 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_IOREQ_Exported_Types 50 | * @{ 51 | */ 52 | 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | 59 | 60 | /** @defgroup USBD_IOREQ_Exported_Macros 61 | * @{ 62 | */ 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup USBD_IOREQ_Exported_Variables 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype 77 | * @{ 78 | */ 79 | 80 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, 81 | uint8_t *pbuf, uint32_t len); 82 | 83 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, 84 | uint8_t *pbuf, uint32_t len); 85 | 86 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, 87 | uint8_t *pbuf, uint32_t len); 88 | 89 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, 90 | uint8_t *pbuf, uint32_t len); 91 | 92 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev); 93 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev); 94 | 95 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /* __USBD_IOREQ_H */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 115 | -------------------------------------------------------------------------------- /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 component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "usbd_ioreq.h" 22 | 23 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 24 | * @{ 25 | */ 26 | 27 | 28 | /** @defgroup USBD_IOREQ 29 | * @brief control I/O requests module 30 | * @{ 31 | */ 32 | 33 | /** @defgroup USBD_IOREQ_Private_TypesDefinitions 34 | * @{ 35 | */ 36 | /** 37 | * @} 38 | */ 39 | 40 | 41 | /** @defgroup USBD_IOREQ_Private_Defines 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @} 47 | */ 48 | 49 | 50 | /** @defgroup USBD_IOREQ_Private_Macros 51 | * @{ 52 | */ 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup USBD_IOREQ_Private_Variables 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | 67 | /** @defgroup USBD_IOREQ_Private_FunctionPrototypes 68 | * @{ 69 | */ 70 | /** 71 | * @} 72 | */ 73 | 74 | 75 | /** @defgroup USBD_IOREQ_Private_Functions 76 | * @{ 77 | */ 78 | 79 | /** 80 | * @brief USBD_CtlSendData 81 | * send data on the ctl pipe 82 | * @param pdev: device instance 83 | * @param buff: pointer to data buffer 84 | * @param len: length of data to be sent 85 | * @retval status 86 | */ 87 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, 88 | uint8_t *pbuf, uint32_t len) 89 | { 90 | /* Set EP0 State */ 91 | pdev->ep0_state = USBD_EP0_DATA_IN; 92 | pdev->ep_in[0].total_length = len; 93 | 94 | #ifdef USBD_AVOID_PACKET_SPLIT_MPS 95 | pdev->ep_in[0].rem_length = 0U; 96 | #else 97 | pdev->ep_in[0].rem_length = len; 98 | #endif 99 | 100 | /* Start the transfer */ 101 | (void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len); 102 | 103 | return USBD_OK; 104 | } 105 | 106 | /** 107 | * @brief USBD_CtlContinueSendData 108 | * continue sending data on the ctl pipe 109 | * @param pdev: device instance 110 | * @param buff: pointer to data buffer 111 | * @param len: length of data to be sent 112 | * @retval status 113 | */ 114 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, 115 | uint8_t *pbuf, uint32_t len) 116 | { 117 | /* Start the next transfer */ 118 | (void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len); 119 | 120 | return USBD_OK; 121 | } 122 | 123 | /** 124 | * @brief USBD_CtlPrepareRx 125 | * receive data on the ctl pipe 126 | * @param pdev: device instance 127 | * @param buff: pointer to data buffer 128 | * @param len: length of data to be received 129 | * @retval status 130 | */ 131 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, 132 | uint8_t *pbuf, uint32_t len) 133 | { 134 | /* Set EP0 State */ 135 | pdev->ep0_state = USBD_EP0_DATA_OUT; 136 | pdev->ep_out[0].total_length = len; 137 | 138 | #ifdef USBD_AVOID_PACKET_SPLIT_MPS 139 | pdev->ep_out[0].rem_length = 0U; 140 | #else 141 | pdev->ep_out[0].rem_length = len; 142 | #endif 143 | 144 | /* Start the transfer */ 145 | (void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 146 | 147 | return USBD_OK; 148 | } 149 | 150 | /** 151 | * @brief USBD_CtlContinueRx 152 | * continue receive data on the ctl pipe 153 | * @param pdev: device instance 154 | * @param buff: pointer to data buffer 155 | * @param len: length of data to be received 156 | * @retval status 157 | */ 158 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, 159 | uint8_t *pbuf, uint32_t len) 160 | { 161 | (void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 162 | 163 | return USBD_OK; 164 | } 165 | 166 | /** 167 | * @brief USBD_CtlSendStatus 168 | * send zero lzngth packet on the ctl pipe 169 | * @param pdev: device instance 170 | * @retval status 171 | */ 172 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev) 173 | { 174 | /* Set EP0 State */ 175 | pdev->ep0_state = USBD_EP0_STATUS_IN; 176 | 177 | /* Start the transfer */ 178 | (void)USBD_LL_Transmit(pdev, 0x00U, NULL, 0U); 179 | 180 | return USBD_OK; 181 | } 182 | 183 | /** 184 | * @brief USBD_CtlReceiveStatus 185 | * receive zero lzngth packet on the ctl pipe 186 | * @param pdev: device instance 187 | * @retval status 188 | */ 189 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev) 190 | { 191 | /* Set EP0 State */ 192 | pdev->ep0_state = USBD_EP0_STATUS_OUT; 193 | 194 | /* Start the transfer */ 195 | (void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); 196 | 197 | return USBD_OK; 198 | } 199 | 200 | /** 201 | * @brief USBD_GetRxCount 202 | * returns the received data length 203 | * @param pdev: device instance 204 | * @param ep_addr: endpoint address 205 | * @retval Rx Data blength 206 | */ 207 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 208 | { 209 | return USBD_LL_GetRxDataSize(pdev, ep_addr); 210 | } 211 | 212 | /** 213 | * @} 214 | */ 215 | 216 | 217 | /** 218 | * @} 219 | */ 220 | 221 | 222 | /** 223 | * @} 224 | */ 225 | 226 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 227 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/freertos_mpool.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- 2 | * Copyright (c) 2013-2020 Arm Limited. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the License); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | * Name: freertos_mpool.h 19 | * Purpose: CMSIS RTOS2 wrapper for FreeRTOS 20 | * 21 | *---------------------------------------------------------------------------*/ 22 | 23 | #ifndef FREERTOS_MPOOL_H_ 24 | #define FREERTOS_MPOOL_H_ 25 | 26 | #include 27 | #include "FreeRTOS.h" 28 | #include "semphr.h" 29 | 30 | /* Memory Pool implementation definitions */ 31 | #define MPOOL_STATUS 0x5EED0000U 32 | 33 | /* Memory Block header */ 34 | typedef struct { 35 | void *next; /* Pointer to next block */ 36 | } MemPoolBlock_t; 37 | 38 | /* Memory Pool control block */ 39 | typedef struct MemPoolDef_t { 40 | MemPoolBlock_t *head; /* Pointer to head block */ 41 | SemaphoreHandle_t sem; /* Pool semaphore handle */ 42 | uint8_t *mem_arr; /* Pool memory array */ 43 | uint32_t mem_sz; /* Pool memory array size */ 44 | const char *name; /* Pointer to name string */ 45 | uint32_t bl_sz; /* Size of a single block */ 46 | uint32_t bl_cnt; /* Number of blocks */ 47 | uint32_t n; /* Block allocation index */ 48 | volatile uint32_t status; /* Object status flags */ 49 | #if (configSUPPORT_STATIC_ALLOCATION == 1) 50 | StaticSemaphore_t mem_sem; /* Semaphore object memory */ 51 | #endif 52 | } MemPool_t; 53 | 54 | /* No need to hide static object type, just align to coding style */ 55 | #define StaticMemPool_t MemPool_t 56 | 57 | /* Define memory pool control block size */ 58 | #define MEMPOOL_CB_SIZE (sizeof(StaticMemPool_t)) 59 | 60 | /* Define size of the byte array required to create count of blocks of given size */ 61 | #define MEMPOOL_ARR_SIZE(bl_count, bl_size) (((((bl_size) + (4 - 1)) / 4) * 4)*(bl_count)) 62 | 63 | #endif /* FREERTOS_MPOOL_H_ */ 64 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/Source/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | Permission is hereby granted, free of charge, to any person obtaining a copy of 3 | this software and associated documentation files (the "Software"), to deal in 4 | the Software without restriction, including without limitation the rights to 5 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 6 | the Software, and to permit persons to whom the Software is furnished to do so, 7 | subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all 10 | copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 14 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 16 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 17 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/Source/include/StackMacros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.3.1 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 STACK_MACROS_H 29 | #define STACK_MACROS_H 30 | 31 | #ifndef _MSC_VER /* Visual Studio doesn't support #warning. */ 32 | #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 future released. 33 | #endif 34 | 35 | /* 36 | * Call the stack overflow hook function if the stack of the task being swapped 37 | * out is currently overflowed, or looks like it might have overflowed in the 38 | * past. 39 | * 40 | * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check 41 | * the current stack state only - comparing the current top of stack value to 42 | * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1 43 | * will also cause the last few stack bytes to be checked to ensure the value 44 | * to which the bytes were set when the task was created have not been 45 | * overwritten. Note this second test does not guarantee that an overflowed 46 | * stack will always be recognised. 47 | */ 48 | 49 | /*-----------------------------------------------------------*/ 50 | 51 | #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) ) 52 | 53 | /* Only the current stack state is to be checked. */ 54 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 55 | { \ 56 | /* Is the currently saved stack pointer within the stack limit? */ \ 57 | if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \ 58 | { \ 59 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 60 | } \ 61 | } 62 | 63 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 64 | /*-----------------------------------------------------------*/ 65 | 66 | #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) ) 67 | 68 | /* Only the current stack state is to be checked. */ 69 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 70 | { \ 71 | \ 72 | /* Is the currently saved stack pointer within the stack limit? */ \ 73 | if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \ 74 | { \ 75 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 76 | } \ 77 | } 78 | 79 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 80 | /*-----------------------------------------------------------*/ 81 | 82 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) 83 | 84 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 85 | { \ 86 | const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ 87 | const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5; \ 88 | \ 89 | if( ( pulStack[ 0 ] != ulCheckValue ) || \ 90 | ( pulStack[ 1 ] != ulCheckValue ) || \ 91 | ( pulStack[ 2 ] != ulCheckValue ) || \ 92 | ( pulStack[ 3 ] != ulCheckValue ) ) \ 93 | { \ 94 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 95 | } \ 96 | } 97 | 98 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 99 | /*-----------------------------------------------------------*/ 100 | 101 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) ) 102 | 103 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 104 | { \ 105 | int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ 106 | static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 107 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 108 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 109 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 110 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ 111 | \ 112 | \ 113 | pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ 114 | \ 115 | /* Has the extremity of the task stack ever been written over? */ \ 116 | if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ 117 | { \ 118 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 119 | } \ 120 | } 121 | 122 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 123 | /*-----------------------------------------------------------*/ 124 | 125 | /* Remove stack overflow macro if not being used. */ 126 | #ifndef taskCHECK_FOR_STACK_OVERFLOW 127 | #define taskCHECK_FOR_STACK_OVERFLOW() 128 | #endif 129 | 130 | 131 | 132 | #endif /* STACK_MACROS_H */ 133 | 134 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/Source/include/deprecated_definitions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.3.1 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 DEPRECATED_DEFINITIONS_H 29 | #define DEPRECATED_DEFINITIONS_H 30 | 31 | 32 | /* Each FreeRTOS port has a unique portmacro.h header file. Originally a 33 | pre-processor definition was used to ensure the pre-processor found the correct 34 | portmacro.h file for the port being used. That scheme was deprecated in favour 35 | of setting the compiler's include path such that it found the correct 36 | portmacro.h file - removing the need for the constant and allowing the 37 | portmacro.h file to be located anywhere in relation to the port being used. The 38 | definitions below remain in the code for backward compatibility only. New 39 | projects should not use them. */ 40 | 41 | #ifdef OPEN_WATCOM_INDUSTRIAL_PC_PORT 42 | #include "..\..\Source\portable\owatcom\16bitdos\pc\portmacro.h" 43 | typedef void ( __interrupt __far *pxISR )(); 44 | #endif 45 | 46 | #ifdef OPEN_WATCOM_FLASH_LITE_186_PORT 47 | #include "..\..\Source\portable\owatcom\16bitdos\flsh186\portmacro.h" 48 | typedef void ( __interrupt __far *pxISR )(); 49 | #endif 50 | 51 | #ifdef GCC_MEGA_AVR 52 | #include "../portable/GCC/ATMega323/portmacro.h" 53 | #endif 54 | 55 | #ifdef IAR_MEGA_AVR 56 | #include "../portable/IAR/ATMega323/portmacro.h" 57 | #endif 58 | 59 | #ifdef MPLAB_PIC24_PORT 60 | #include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h" 61 | #endif 62 | 63 | #ifdef MPLAB_DSPIC_PORT 64 | #include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h" 65 | #endif 66 | 67 | #ifdef MPLAB_PIC18F_PORT 68 | #include "../../Source/portable/MPLAB/PIC18F/portmacro.h" 69 | #endif 70 | 71 | #ifdef MPLAB_PIC32MX_PORT 72 | #include "../../Source/portable/MPLAB/PIC32MX/portmacro.h" 73 | #endif 74 | 75 | #ifdef _FEDPICC 76 | #include "libFreeRTOS/Include/portmacro.h" 77 | #endif 78 | 79 | #ifdef SDCC_CYGNAL 80 | #include "../../Source/portable/SDCC/Cygnal/portmacro.h" 81 | #endif 82 | 83 | #ifdef GCC_ARM7 84 | #include "../../Source/portable/GCC/ARM7_LPC2000/portmacro.h" 85 | #endif 86 | 87 | #ifdef GCC_ARM7_ECLIPSE 88 | #include "portmacro.h" 89 | #endif 90 | 91 | #ifdef ROWLEY_LPC23xx 92 | #include "../../Source/portable/GCC/ARM7_LPC23xx/portmacro.h" 93 | #endif 94 | 95 | #ifdef IAR_MSP430 96 | #include "..\..\Source\portable\IAR\MSP430\portmacro.h" 97 | #endif 98 | 99 | #ifdef GCC_MSP430 100 | #include "../../Source/portable/GCC/MSP430F449/portmacro.h" 101 | #endif 102 | 103 | #ifdef ROWLEY_MSP430 104 | #include "../../Source/portable/Rowley/MSP430F449/portmacro.h" 105 | #endif 106 | 107 | #ifdef ARM7_LPC21xx_KEIL_RVDS 108 | #include "..\..\Source\portable\RVDS\ARM7_LPC21xx\portmacro.h" 109 | #endif 110 | 111 | #ifdef SAM7_GCC 112 | #include "../../Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h" 113 | #endif 114 | 115 | #ifdef SAM7_IAR 116 | #include "..\..\Source\portable\IAR\AtmelSAM7S64\portmacro.h" 117 | #endif 118 | 119 | #ifdef SAM9XE_IAR 120 | #include "..\..\Source\portable\IAR\AtmelSAM9XE\portmacro.h" 121 | #endif 122 | 123 | #ifdef LPC2000_IAR 124 | #include "..\..\Source\portable\IAR\LPC2000\portmacro.h" 125 | #endif 126 | 127 | #ifdef STR71X_IAR 128 | #include "..\..\Source\portable\IAR\STR71x\portmacro.h" 129 | #endif 130 | 131 | #ifdef STR75X_IAR 132 | #include "..\..\Source\portable\IAR\STR75x\portmacro.h" 133 | #endif 134 | 135 | #ifdef STR75X_GCC 136 | #include "..\..\Source\portable\GCC\STR75x\portmacro.h" 137 | #endif 138 | 139 | #ifdef STR91X_IAR 140 | #include "..\..\Source\portable\IAR\STR91x\portmacro.h" 141 | #endif 142 | 143 | #ifdef GCC_H8S 144 | #include "../../Source/portable/GCC/H8S2329/portmacro.h" 145 | #endif 146 | 147 | #ifdef GCC_AT91FR40008 148 | #include "../../Source/portable/GCC/ARM7_AT91FR40008/portmacro.h" 149 | #endif 150 | 151 | #ifdef RVDS_ARMCM3_LM3S102 152 | #include "../../Source/portable/RVDS/ARM_CM3/portmacro.h" 153 | #endif 154 | 155 | #ifdef GCC_ARMCM3_LM3S102 156 | #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" 157 | #endif 158 | 159 | #ifdef GCC_ARMCM3 160 | #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" 161 | #endif 162 | 163 | #ifdef IAR_ARM_CM3 164 | #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" 165 | #endif 166 | 167 | #ifdef IAR_ARMCM3_LM 168 | #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" 169 | #endif 170 | 171 | #ifdef HCS12_CODE_WARRIOR 172 | #include "../../Source/portable/CodeWarrior/HCS12/portmacro.h" 173 | #endif 174 | 175 | #ifdef MICROBLAZE_GCC 176 | #include "../../Source/portable/GCC/MicroBlaze/portmacro.h" 177 | #endif 178 | 179 | #ifdef TERN_EE 180 | #include "..\..\Source\portable\Paradigm\Tern_EE\small\portmacro.h" 181 | #endif 182 | 183 | #ifdef GCC_HCS12 184 | #include "../../Source/portable/GCC/HCS12/portmacro.h" 185 | #endif 186 | 187 | #ifdef GCC_MCF5235 188 | #include "../../Source/portable/GCC/MCF5235/portmacro.h" 189 | #endif 190 | 191 | #ifdef COLDFIRE_V2_GCC 192 | #include "../../../Source/portable/GCC/ColdFire_V2/portmacro.h" 193 | #endif 194 | 195 | #ifdef COLDFIRE_V2_CODEWARRIOR 196 | #include "../../Source/portable/CodeWarrior/ColdFire_V2/portmacro.h" 197 | #endif 198 | 199 | #ifdef GCC_PPC405 200 | #include "../../Source/portable/GCC/PPC405_Xilinx/portmacro.h" 201 | #endif 202 | 203 | #ifdef GCC_PPC440 204 | #include "../../Source/portable/GCC/PPC440_Xilinx/portmacro.h" 205 | #endif 206 | 207 | #ifdef _16FX_SOFTUNE 208 | #include "..\..\Source\portable\Softune\MB96340\portmacro.h" 209 | #endif 210 | 211 | #ifdef BCC_INDUSTRIAL_PC_PORT 212 | /* A short file name has to be used in place of the normal 213 | FreeRTOSConfig.h when using the Borland compiler. */ 214 | #include "frconfig.h" 215 | #include "..\portable\BCC\16BitDOS\PC\prtmacro.h" 216 | typedef void ( __interrupt __far *pxISR )(); 217 | #endif 218 | 219 | #ifdef BCC_FLASH_LITE_186_PORT 220 | /* A short file name has to be used in place of the normal 221 | FreeRTOSConfig.h when using the Borland compiler. */ 222 | #include "frconfig.h" 223 | #include "..\portable\BCC\16BitDOS\flsh186\prtmacro.h" 224 | typedef void ( __interrupt __far *pxISR )(); 225 | #endif 226 | 227 | #ifdef __GNUC__ 228 | #ifdef __AVR32_AVR32A__ 229 | #include "portmacro.h" 230 | #endif 231 | #endif 232 | 233 | #ifdef __ICCAVR32__ 234 | #ifdef __CORE__ 235 | #if __CORE__ == __AVR32A__ 236 | #include "portmacro.h" 237 | #endif 238 | #endif 239 | #endif 240 | 241 | #ifdef __91467D 242 | #include "portmacro.h" 243 | #endif 244 | 245 | #ifdef __96340 246 | #include "portmacro.h" 247 | #endif 248 | 249 | 250 | #ifdef __IAR_V850ES_Fx3__ 251 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 252 | #endif 253 | 254 | #ifdef __IAR_V850ES_Jx3__ 255 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 256 | #endif 257 | 258 | #ifdef __IAR_V850ES_Jx3_L__ 259 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 260 | #endif 261 | 262 | #ifdef __IAR_V850ES_Jx2__ 263 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 264 | #endif 265 | 266 | #ifdef __IAR_V850ES_Hx2__ 267 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 268 | #endif 269 | 270 | #ifdef __IAR_78K0R_Kx3__ 271 | #include "../../Source/portable/IAR/78K0R/portmacro.h" 272 | #endif 273 | 274 | #ifdef __IAR_78K0R_Kx3L__ 275 | #include "../../Source/portable/IAR/78K0R/portmacro.h" 276 | #endif 277 | 278 | #endif /* DEPRECATED_DEFINITIONS_H */ 279 | 280 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/Source/include/portable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.3.1 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 | /*----------------------------------------------------------- 29 | * Portable layer API. Each function must be defined for each port. 30 | *----------------------------------------------------------*/ 31 | 32 | #ifndef PORTABLE_H 33 | #define PORTABLE_H 34 | 35 | /* Each FreeRTOS port has a unique portmacro.h header file. Originally a 36 | pre-processor definition was used to ensure the pre-processor found the correct 37 | portmacro.h file for the port being used. That scheme was deprecated in favour 38 | of setting the compiler's include path such that it found the correct 39 | portmacro.h file - removing the need for the constant and allowing the 40 | portmacro.h file to be located anywhere in relation to the port being used. 41 | Purely for reasons of backward compatibility the old method is still valid, but 42 | to make it clear that new projects should not use it, support for the port 43 | specific constants has been moved into the deprecated_definitions.h header 44 | file. */ 45 | #include "deprecated_definitions.h" 46 | 47 | /* If portENTER_CRITICAL is not defined then including deprecated_definitions.h 48 | did not result in a portmacro.h header file being included - and it should be 49 | included here. In this case the path to the correct portmacro.h header file 50 | must be set in the compiler's include path. */ 51 | #ifndef portENTER_CRITICAL 52 | #include "portmacro.h" 53 | #endif 54 | 55 | #if portBYTE_ALIGNMENT == 32 56 | #define portBYTE_ALIGNMENT_MASK ( 0x001f ) 57 | #endif 58 | 59 | #if portBYTE_ALIGNMENT == 16 60 | #define portBYTE_ALIGNMENT_MASK ( 0x000f ) 61 | #endif 62 | 63 | #if portBYTE_ALIGNMENT == 8 64 | #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) 65 | #endif 66 | 67 | #if portBYTE_ALIGNMENT == 4 68 | #define portBYTE_ALIGNMENT_MASK ( 0x0003 ) 69 | #endif 70 | 71 | #if portBYTE_ALIGNMENT == 2 72 | #define portBYTE_ALIGNMENT_MASK ( 0x0001 ) 73 | #endif 74 | 75 | #if portBYTE_ALIGNMENT == 1 76 | #define portBYTE_ALIGNMENT_MASK ( 0x0000 ) 77 | #endif 78 | 79 | #ifndef portBYTE_ALIGNMENT_MASK 80 | #error "Invalid portBYTE_ALIGNMENT definition" 81 | #endif 82 | 83 | #ifndef portNUM_CONFIGURABLE_REGIONS 84 | #define portNUM_CONFIGURABLE_REGIONS 1 85 | #endif 86 | 87 | #ifndef portHAS_STACK_OVERFLOW_CHECKING 88 | #define portHAS_STACK_OVERFLOW_CHECKING 0 89 | #endif 90 | 91 | #ifndef portARCH_NAME 92 | #define portARCH_NAME NULL 93 | #endif 94 | 95 | #ifdef __cplusplus 96 | extern "C" { 97 | #endif 98 | 99 | #include "mpu_wrappers.h" 100 | 101 | /* 102 | * Setup the stack of a new task so it is ready to be placed under the 103 | * scheduler control. The registers have to be placed on the stack in 104 | * the order that the port expects to find them. 105 | * 106 | */ 107 | #if( portUSING_MPU_WRAPPERS == 1 ) 108 | #if( portHAS_STACK_OVERFLOW_CHECKING == 1 ) 109 | StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, StackType_t *pxEndOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION; 110 | #else 111 | StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION; 112 | #endif 113 | #else 114 | #if( portHAS_STACK_OVERFLOW_CHECKING == 1 ) 115 | StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, StackType_t *pxEndOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION; 116 | #else 117 | StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION; 118 | #endif 119 | #endif 120 | 121 | /* Used by heap_5.c to define the start address and size of each memory region 122 | that together comprise the total FreeRTOS heap space. */ 123 | typedef struct HeapRegion 124 | { 125 | uint8_t *pucStartAddress; 126 | size_t xSizeInBytes; 127 | } HeapRegion_t; 128 | 129 | /* Used to pass information about the heap out of vPortGetHeapStats(). */ 130 | typedef struct xHeapStats 131 | { 132 | size_t xAvailableHeapSpaceInBytes; /* The total heap size currently available - this is the sum of all the free blocks, not the largest block that can be allocated. */ 133 | size_t xSizeOfLargestFreeBlockInBytes; /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */ 134 | size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */ 135 | size_t xNumberOfFreeBlocks; /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */ 136 | size_t xMinimumEverFreeBytesRemaining; /* The minimum amount of total free memory (sum of all free blocks) there has been in the heap since the system booted. */ 137 | size_t xNumberOfSuccessfulAllocations; /* The number of calls to pvPortMalloc() that have returned a valid memory block. */ 138 | size_t xNumberOfSuccessfulFrees; /* The number of calls to vPortFree() that has successfully freed a block of memory. */ 139 | } HeapStats_t; 140 | 141 | /* 142 | * Used to define multiple heap regions for use by heap_5.c. This function 143 | * must be called before any calls to pvPortMalloc() - not creating a task, 144 | * queue, semaphore, mutex, software timer, event group, etc. will result in 145 | * pvPortMalloc being called. 146 | * 147 | * pxHeapRegions passes in an array of HeapRegion_t structures - each of which 148 | * defines a region of memory that can be used as the heap. The array is 149 | * terminated by a HeapRegions_t structure that has a size of 0. The region 150 | * with the lowest start address must appear first in the array. 151 | */ 152 | void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION; 153 | 154 | /* 155 | * Returns a HeapStats_t structure filled with information about the current 156 | * heap state. 157 | */ 158 | void vPortGetHeapStats( HeapStats_t *pxHeapStats ); 159 | 160 | /* 161 | * Map to the memory management routines required for the port. 162 | */ 163 | void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION; 164 | void vPortFree( void *pv ) PRIVILEGED_FUNCTION; 165 | void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION; 166 | size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION; 167 | size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION; 168 | 169 | /* 170 | * Setup the hardware ready for the scheduler to take control. This generally 171 | * sets up a tick interrupt and sets timers for the correct tick frequency. 172 | */ 173 | BaseType_t xPortStartScheduler( void ) PRIVILEGED_FUNCTION; 174 | 175 | /* 176 | * Undo any hardware/ISR setup that was performed by xPortStartScheduler() so 177 | * the hardware is left in its original condition after the scheduler stops 178 | * executing. 179 | */ 180 | void vPortEndScheduler( void ) PRIVILEGED_FUNCTION; 181 | 182 | /* 183 | * The structures and methods of manipulating the MPU are contained within the 184 | * port layer. 185 | * 186 | * Fills the xMPUSettings structure with the memory region information 187 | * contained in xRegions. 188 | */ 189 | #if( portUSING_MPU_WRAPPERS == 1 ) 190 | struct xMEMORY_REGION; 191 | void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, StackType_t *pxBottomOfStack, uint32_t ulStackDepth ) PRIVILEGED_FUNCTION; 192 | #endif 193 | 194 | #ifdef __cplusplus 195 | } 196 | #endif 197 | 198 | #endif /* PORTABLE_H */ 199 | 200 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/Source/include/projdefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.3.1 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 PROJDEFS_H 29 | #define PROJDEFS_H 30 | 31 | /* 32 | * Defines the prototype to which task functions must conform. Defined in this 33 | * file to ensure the type is known before portable.h is included. 34 | */ 35 | typedef void (*TaskFunction_t)( void * ); 36 | 37 | /* Converts a time in milliseconds to a time in ticks. This macro can be 38 | overridden by a macro of the same name defined in FreeRTOSConfig.h in case the 39 | definition here is not suitable for your application. */ 40 | #ifndef pdMS_TO_TICKS 41 | #define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) ( ( ( TickType_t ) ( xTimeInMs ) * ( TickType_t ) configTICK_RATE_HZ ) / ( TickType_t ) 1000 ) ) 42 | #endif 43 | 44 | #define pdFALSE ( ( BaseType_t ) 0 ) 45 | #define pdTRUE ( ( BaseType_t ) 1 ) 46 | 47 | #define pdPASS ( pdTRUE ) 48 | #define pdFAIL ( pdFALSE ) 49 | #define errQUEUE_EMPTY ( ( BaseType_t ) 0 ) 50 | #define errQUEUE_FULL ( ( BaseType_t ) 0 ) 51 | 52 | /* FreeRTOS error definitions. */ 53 | #define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ( -1 ) 54 | #define errQUEUE_BLOCKED ( -4 ) 55 | #define errQUEUE_YIELD ( -5 ) 56 | 57 | /* Macros used for basic data corruption checks. */ 58 | #ifndef configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 59 | #define configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 0 60 | #endif 61 | 62 | #if( configUSE_16_BIT_TICKS == 1 ) 63 | #define pdINTEGRITY_CHECK_VALUE 0x5a5a 64 | #else 65 | #define pdINTEGRITY_CHECK_VALUE 0x5a5a5a5aUL 66 | #endif 67 | 68 | /* The following errno values are used by FreeRTOS+ components, not FreeRTOS 69 | itself. */ 70 | #define pdFREERTOS_ERRNO_NONE 0 /* No errors */ 71 | #define pdFREERTOS_ERRNO_ENOENT 2 /* No such file or directory */ 72 | #define pdFREERTOS_ERRNO_EINTR 4 /* Interrupted system call */ 73 | #define pdFREERTOS_ERRNO_EIO 5 /* I/O error */ 74 | #define pdFREERTOS_ERRNO_ENXIO 6 /* No such device or address */ 75 | #define pdFREERTOS_ERRNO_EBADF 9 /* Bad file number */ 76 | #define pdFREERTOS_ERRNO_EAGAIN 11 /* No more processes */ 77 | #define pdFREERTOS_ERRNO_EWOULDBLOCK 11 /* Operation would block */ 78 | #define pdFREERTOS_ERRNO_ENOMEM 12 /* Not enough memory */ 79 | #define pdFREERTOS_ERRNO_EACCES 13 /* Permission denied */ 80 | #define pdFREERTOS_ERRNO_EFAULT 14 /* Bad address */ 81 | #define pdFREERTOS_ERRNO_EBUSY 16 /* Mount device busy */ 82 | #define pdFREERTOS_ERRNO_EEXIST 17 /* File exists */ 83 | #define pdFREERTOS_ERRNO_EXDEV 18 /* Cross-device link */ 84 | #define pdFREERTOS_ERRNO_ENODEV 19 /* No such device */ 85 | #define pdFREERTOS_ERRNO_ENOTDIR 20 /* Not a directory */ 86 | #define pdFREERTOS_ERRNO_EISDIR 21 /* Is a directory */ 87 | #define pdFREERTOS_ERRNO_EINVAL 22 /* Invalid argument */ 88 | #define pdFREERTOS_ERRNO_ENOSPC 28 /* No space left on device */ 89 | #define pdFREERTOS_ERRNO_ESPIPE 29 /* Illegal seek */ 90 | #define pdFREERTOS_ERRNO_EROFS 30 /* Read only file system */ 91 | #define pdFREERTOS_ERRNO_EUNATCH 42 /* Protocol driver not attached */ 92 | #define pdFREERTOS_ERRNO_EBADE 50 /* Invalid exchange */ 93 | #define pdFREERTOS_ERRNO_EFTYPE 79 /* Inappropriate file type or format */ 94 | #define pdFREERTOS_ERRNO_ENMFILE 89 /* No more files */ 95 | #define pdFREERTOS_ERRNO_ENOTEMPTY 90 /* Directory not empty */ 96 | #define pdFREERTOS_ERRNO_ENAMETOOLONG 91 /* File or path name too long */ 97 | #define pdFREERTOS_ERRNO_EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ 98 | #define pdFREERTOS_ERRNO_ENOBUFS 105 /* No buffer space available */ 99 | #define pdFREERTOS_ERRNO_ENOPROTOOPT 109 /* Protocol not available */ 100 | #define pdFREERTOS_ERRNO_EADDRINUSE 112 /* Address already in use */ 101 | #define pdFREERTOS_ERRNO_ETIMEDOUT 116 /* Connection timed out */ 102 | #define pdFREERTOS_ERRNO_EINPROGRESS 119 /* Connection already in progress */ 103 | #define pdFREERTOS_ERRNO_EALREADY 120 /* Socket already connected */ 104 | #define pdFREERTOS_ERRNO_EADDRNOTAVAIL 125 /* Address not available */ 105 | #define pdFREERTOS_ERRNO_EISCONN 127 /* Socket is already connected */ 106 | #define pdFREERTOS_ERRNO_ENOTCONN 128 /* Socket is not connected */ 107 | #define pdFREERTOS_ERRNO_ENOMEDIUM 135 /* No medium inserted */ 108 | #define pdFREERTOS_ERRNO_EILSEQ 138 /* An invalid UTF-16 sequence was encountered. */ 109 | #define pdFREERTOS_ERRNO_ECANCELED 140 /* Operation canceled. */ 110 | 111 | /* The following endian values are used by FreeRTOS+ components, not FreeRTOS 112 | itself. */ 113 | #define pdFREERTOS_LITTLE_ENDIAN 0 114 | #define pdFREERTOS_BIG_ENDIAN 1 115 | 116 | /* Re-defining endian values for generic naming. */ 117 | #define pdLITTLE_ENDIAN pdFREERTOS_LITTLE_ENDIAN 118 | #define pdBIG_ENDIAN pdFREERTOS_BIG_ENDIAN 119 | 120 | 121 | #endif /* PROJDEFS_H */ 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/Source/include/stack_macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.3.1 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 STACK_MACROS_H 29 | #define STACK_MACROS_H 30 | 31 | /* 32 | * Call the stack overflow hook function if the stack of the task being swapped 33 | * out is currently overflowed, or looks like it might have overflowed in the 34 | * past. 35 | * 36 | * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check 37 | * the current stack state only - comparing the current top of stack value to 38 | * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1 39 | * will also cause the last few stack bytes to be checked to ensure the value 40 | * to which the bytes were set when the task was created have not been 41 | * overwritten. Note this second test does not guarantee that an overflowed 42 | * stack will always be recognised. 43 | */ 44 | 45 | /*-----------------------------------------------------------*/ 46 | 47 | #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) ) 48 | 49 | /* Only the current stack state is to be checked. */ 50 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 51 | { \ 52 | /* Is the currently saved stack pointer within the stack limit? */ \ 53 | if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \ 54 | { \ 55 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 56 | } \ 57 | } 58 | 59 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 60 | /*-----------------------------------------------------------*/ 61 | 62 | #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) ) 63 | 64 | /* Only the current stack state is to be checked. */ 65 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 66 | { \ 67 | \ 68 | /* Is the currently saved stack pointer within the stack limit? */ \ 69 | if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \ 70 | { \ 71 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 72 | } \ 73 | } 74 | 75 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 76 | /*-----------------------------------------------------------*/ 77 | 78 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) 79 | 80 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 81 | { \ 82 | const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ 83 | const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5; \ 84 | \ 85 | if( ( pulStack[ 0 ] != ulCheckValue ) || \ 86 | ( pulStack[ 1 ] != ulCheckValue ) || \ 87 | ( pulStack[ 2 ] != ulCheckValue ) || \ 88 | ( pulStack[ 3 ] != ulCheckValue ) ) \ 89 | { \ 90 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 91 | } \ 92 | } 93 | 94 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 95 | /*-----------------------------------------------------------*/ 96 | 97 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) ) 98 | 99 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 100 | { \ 101 | int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ 102 | static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 103 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 104 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 105 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 106 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ 107 | \ 108 | \ 109 | pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ 110 | \ 111 | /* Has the extremity of the task stack ever been written over? */ \ 112 | if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ 113 | { \ 114 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 115 | } \ 116 | } 117 | 118 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 119 | /*-----------------------------------------------------------*/ 120 | 121 | /* Remove stack overflow macro if not being used. */ 122 | #ifndef taskCHECK_FOR_STACK_OVERFLOW 123 | #define taskCHECK_FOR_STACK_OVERFLOW() 124 | #endif 125 | 126 | 127 | 128 | #endif /* STACK_MACROS_H */ 129 | 130 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/Source/list.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.3.1 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 | 29 | #include 30 | #include "FreeRTOS.h" 31 | #include "list.h" 32 | 33 | /*----------------------------------------------------------- 34 | * PUBLIC LIST API documented in list.h 35 | *----------------------------------------------------------*/ 36 | 37 | void vListInitialise( List_t * const pxList ) 38 | { 39 | /* The list structure contains a list item which is used to mark the 40 | end of the list. To initialise the list the list end is inserted 41 | as the only list entry. */ 42 | pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */ 43 | 44 | /* The list end value is the highest possible value in the list to 45 | ensure it remains at the end of the list. */ 46 | pxList->xListEnd.xItemValue = portMAX_DELAY; 47 | 48 | /* The list end next and previous pointers point to itself so we know 49 | when the list is empty. */ 50 | pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */ 51 | pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd );/*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */ 52 | 53 | pxList->uxNumberOfItems = ( UBaseType_t ) 0U; 54 | 55 | /* Write known values into the list if 56 | configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ 57 | listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ); 58 | listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ); 59 | } 60 | /*-----------------------------------------------------------*/ 61 | 62 | void vListInitialiseItem( ListItem_t * const pxItem ) 63 | { 64 | /* Make sure the list item is not recorded as being on a list. */ 65 | pxItem->pxContainer = NULL; 66 | 67 | /* Write known values into the list item if 68 | configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ 69 | listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ); 70 | listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ); 71 | } 72 | /*-----------------------------------------------------------*/ 73 | 74 | void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem ) 75 | { 76 | ListItem_t * const pxIndex = pxList->pxIndex; 77 | 78 | /* Only effective when configASSERT() is also defined, these tests may catch 79 | the list data structures being overwritten in memory. They will not catch 80 | data errors caused by incorrect configuration or use of FreeRTOS. */ 81 | listTEST_LIST_INTEGRITY( pxList ); 82 | listTEST_LIST_ITEM_INTEGRITY( pxNewListItem ); 83 | 84 | /* Insert a new list item into pxList, but rather than sort the list, 85 | makes the new list item the last item to be removed by a call to 86 | listGET_OWNER_OF_NEXT_ENTRY(). */ 87 | pxNewListItem->pxNext = pxIndex; 88 | pxNewListItem->pxPrevious = pxIndex->pxPrevious; 89 | 90 | /* Only used during decision coverage testing. */ 91 | mtCOVERAGE_TEST_DELAY(); 92 | 93 | pxIndex->pxPrevious->pxNext = pxNewListItem; 94 | pxIndex->pxPrevious = pxNewListItem; 95 | 96 | /* Remember which list the item is in. */ 97 | pxNewListItem->pxContainer = pxList; 98 | 99 | ( pxList->uxNumberOfItems )++; 100 | } 101 | /*-----------------------------------------------------------*/ 102 | 103 | void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem ) 104 | { 105 | ListItem_t *pxIterator; 106 | const TickType_t xValueOfInsertion = pxNewListItem->xItemValue; 107 | 108 | /* Only effective when configASSERT() is also defined, these tests may catch 109 | the list data structures being overwritten in memory. They will not catch 110 | data errors caused by incorrect configuration or use of FreeRTOS. */ 111 | listTEST_LIST_INTEGRITY( pxList ); 112 | listTEST_LIST_ITEM_INTEGRITY( pxNewListItem ); 113 | 114 | /* Insert the new list item into the list, sorted in xItemValue order. 115 | 116 | If the list already contains a list item with the same item value then the 117 | new list item should be placed after it. This ensures that TCBs which are 118 | stored in ready lists (all of which have the same xItemValue value) get a 119 | share of the CPU. However, if the xItemValue is the same as the back marker 120 | the iteration loop below will not end. Therefore the value is checked 121 | first, and the algorithm slightly modified if necessary. */ 122 | if( xValueOfInsertion == portMAX_DELAY ) 123 | { 124 | pxIterator = pxList->xListEnd.pxPrevious; 125 | } 126 | else 127 | { 128 | /* *** NOTE *********************************************************** 129 | If you find your application is crashing here then likely causes are 130 | listed below. In addition see https://www.freertos.org/FAQHelp.html for 131 | more tips, and ensure configASSERT() is defined! 132 | https://www.freertos.org/a00110.html#configASSERT 133 | 134 | 1) Stack overflow - 135 | see https://www.freertos.org/Stacks-and-stack-overflow-checking.html 136 | 2) Incorrect interrupt priority assignment, especially on Cortex-M 137 | parts where numerically high priority values denote low actual 138 | interrupt priorities, which can seem counter intuitive. See 139 | https://www.freertos.org/RTOS-Cortex-M3-M4.html and the definition 140 | of configMAX_SYSCALL_INTERRUPT_PRIORITY on 141 | https://www.freertos.org/a00110.html 142 | 3) Calling an API function from within a critical section or when 143 | the scheduler is suspended, or calling an API function that does 144 | not end in "FromISR" from an interrupt. 145 | 4) Using a queue or semaphore before it has been initialised or 146 | before the scheduler has been started (are interrupts firing 147 | before vTaskStartScheduler() has been called?). 148 | **********************************************************************/ 149 | 150 | for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. *//*lint !e440 The iterator moves to a different value, not xValueOfInsertion. */ 151 | { 152 | /* There is nothing to do here, just iterating to the wanted 153 | insertion position. */ 154 | } 155 | } 156 | 157 | pxNewListItem->pxNext = pxIterator->pxNext; 158 | pxNewListItem->pxNext->pxPrevious = pxNewListItem; 159 | pxNewListItem->pxPrevious = pxIterator; 160 | pxIterator->pxNext = pxNewListItem; 161 | 162 | /* Remember which list the item is in. This allows fast removal of the 163 | item later. */ 164 | pxNewListItem->pxContainer = pxList; 165 | 166 | ( pxList->uxNumberOfItems )++; 167 | } 168 | /*-----------------------------------------------------------*/ 169 | 170 | UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove ) 171 | { 172 | /* The list item knows which list it is in. Obtain the list from the list 173 | item. */ 174 | List_t * const pxList = pxItemToRemove->pxContainer; 175 | 176 | pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious; 177 | pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext; 178 | 179 | /* Only used during decision coverage testing. */ 180 | mtCOVERAGE_TEST_DELAY(); 181 | 182 | /* Make sure the index is left pointing to a valid item. */ 183 | if( pxList->pxIndex == pxItemToRemove ) 184 | { 185 | pxList->pxIndex = pxItemToRemove->pxPrevious; 186 | } 187 | else 188 | { 189 | mtCOVERAGE_TEST_MARKER(); 190 | } 191 | 192 | pxItemToRemove->pxContainer = NULL; 193 | ( pxList->uxNumberOfItems )--; 194 | 195 | return pxList->uxNumberOfItems; 196 | } 197 | /*-----------------------------------------------------------*/ 198 | 199 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/portmacro.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.3.1 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 | 29 | #ifndef PORTMACRO_H 30 | #define PORTMACRO_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /*----------------------------------------------------------- 37 | * Port specific definitions. 38 | * 39 | * The settings in this file configure FreeRTOS correctly for the 40 | * given hardware and compiler. 41 | * 42 | * These settings should not be altered. 43 | *----------------------------------------------------------- 44 | */ 45 | 46 | /* Type definitions. */ 47 | #define portCHAR char 48 | #define portFLOAT float 49 | #define portDOUBLE double 50 | #define portLONG long 51 | #define portSHORT short 52 | #define portSTACK_TYPE uint32_t 53 | #define portBASE_TYPE long 54 | 55 | typedef portSTACK_TYPE StackType_t; 56 | typedef long BaseType_t; 57 | typedef unsigned long UBaseType_t; 58 | 59 | #if( configUSE_16_BIT_TICKS == 1 ) 60 | typedef uint16_t TickType_t; 61 | #define portMAX_DELAY ( TickType_t ) 0xffff 62 | #else 63 | typedef uint32_t TickType_t; 64 | #define portMAX_DELAY ( TickType_t ) 0xffffffffUL 65 | 66 | /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do 67 | not need to be guarded with a critical section. */ 68 | #define portTICK_TYPE_IS_ATOMIC 1 69 | #endif 70 | /*-----------------------------------------------------------*/ 71 | 72 | /* Architecture specifics. */ 73 | #define portSTACK_GROWTH ( -1 ) 74 | #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) 75 | #define portBYTE_ALIGNMENT 8 76 | /*-----------------------------------------------------------*/ 77 | 78 | /* Scheduler utilities. */ 79 | #define portYIELD() \ 80 | { \ 81 | /* Set a PendSV to request a context switch. */ \ 82 | portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; \ 83 | \ 84 | /* Barriers are normally not required but do ensure the code is completely \ 85 | within the specified behaviour for the architecture. */ \ 86 | __asm volatile( "dsb" ::: "memory" ); \ 87 | __asm volatile( "isb" ); \ 88 | } 89 | 90 | #define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) ) 91 | #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) 92 | #define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) portYIELD() 93 | #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) 94 | /*-----------------------------------------------------------*/ 95 | 96 | /* Critical section management. */ 97 | extern void vPortEnterCritical( void ); 98 | extern void vPortExitCritical( void ); 99 | #define portSET_INTERRUPT_MASK_FROM_ISR() ulPortRaiseBASEPRI() 100 | #define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vPortSetBASEPRI(x) 101 | #define portDISABLE_INTERRUPTS() vPortRaiseBASEPRI() 102 | #define portENABLE_INTERRUPTS() vPortSetBASEPRI(0) 103 | #define portENTER_CRITICAL() vPortEnterCritical() 104 | #define portEXIT_CRITICAL() vPortExitCritical() 105 | 106 | /*-----------------------------------------------------------*/ 107 | 108 | /* Task function macros as described on the FreeRTOS.org WEB site. These are 109 | not necessary for to use this port. They are defined so the common demo files 110 | (which build with all the ports) will build. */ 111 | #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) 112 | #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) 113 | /*-----------------------------------------------------------*/ 114 | 115 | /* Tickless idle/low power functionality. */ 116 | #ifndef portSUPPRESS_TICKS_AND_SLEEP 117 | extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ); 118 | #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) vPortSuppressTicksAndSleep( xExpectedIdleTime ) 119 | #endif 120 | /*-----------------------------------------------------------*/ 121 | 122 | /* Architecture specific optimisations. */ 123 | #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION 124 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 125 | #endif 126 | 127 | #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 128 | 129 | /* Generic helper function. */ 130 | __attribute__( ( always_inline ) ) static inline uint8_t ucPortCountLeadingZeros( uint32_t ulBitmap ) 131 | { 132 | uint8_t ucReturn; 133 | 134 | __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) : "memory" ); 135 | return ucReturn; 136 | } 137 | 138 | /* Check the configuration. */ 139 | #if( configMAX_PRIORITIES > 32 ) 140 | #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice. 141 | #endif 142 | 143 | /* Store/clear the ready priorities in a bit map. */ 144 | #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) ) 145 | #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) ) 146 | 147 | /*-----------------------------------------------------------*/ 148 | 149 | #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) ucPortCountLeadingZeros( ( uxReadyPriorities ) ) ) 150 | 151 | #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ 152 | 153 | /*-----------------------------------------------------------*/ 154 | 155 | #ifdef configASSERT 156 | void vPortValidateInterruptPriority( void ); 157 | #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() vPortValidateInterruptPriority() 158 | #endif 159 | 160 | /* portNOP() is not required by this port. */ 161 | #define portNOP() 162 | 163 | #define portINLINE __inline 164 | 165 | #ifndef portFORCE_INLINE 166 | #define portFORCE_INLINE inline __attribute__(( always_inline)) 167 | #endif 168 | 169 | portFORCE_INLINE static BaseType_t xPortIsInsideInterrupt( void ) 170 | { 171 | uint32_t ulCurrentInterrupt; 172 | BaseType_t xReturn; 173 | 174 | /* Obtain the number of the currently executing interrupt. */ 175 | __asm volatile( "mrs %0, ipsr" : "=r"( ulCurrentInterrupt ) :: "memory" ); 176 | 177 | if( ulCurrentInterrupt == 0 ) 178 | { 179 | xReturn = pdFALSE; 180 | } 181 | else 182 | { 183 | xReturn = pdTRUE; 184 | } 185 | 186 | return xReturn; 187 | } 188 | 189 | /*-----------------------------------------------------------*/ 190 | 191 | portFORCE_INLINE static void vPortRaiseBASEPRI( void ) 192 | { 193 | uint32_t ulNewBASEPRI; 194 | 195 | __asm volatile 196 | ( 197 | " mov %0, %1 \n" \ 198 | " msr basepri, %0 \n" \ 199 | " isb \n" \ 200 | " dsb \n" \ 201 | :"=r" (ulNewBASEPRI) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory" 202 | ); 203 | } 204 | 205 | /*-----------------------------------------------------------*/ 206 | 207 | portFORCE_INLINE static uint32_t ulPortRaiseBASEPRI( void ) 208 | { 209 | uint32_t ulOriginalBASEPRI, ulNewBASEPRI; 210 | 211 | __asm volatile 212 | ( 213 | " mrs %0, basepri \n" \ 214 | " mov %1, %2 \n" \ 215 | " msr basepri, %1 \n" \ 216 | " isb \n" \ 217 | " dsb \n" \ 218 | :"=r" (ulOriginalBASEPRI), "=r" (ulNewBASEPRI) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory" 219 | ); 220 | 221 | /* This return will not be reached but is necessary to prevent compiler 222 | warnings. */ 223 | return ulOriginalBASEPRI; 224 | } 225 | /*-----------------------------------------------------------*/ 226 | 227 | portFORCE_INLINE static void vPortSetBASEPRI( uint32_t ulNewMaskValue ) 228 | { 229 | __asm volatile 230 | ( 231 | " msr basepri, %0 " :: "r" ( ulNewMaskValue ) : "memory" 232 | ); 233 | } 234 | /*-----------------------------------------------------------*/ 235 | 236 | #define portMEMORY_BARRIER() __asm volatile( "" ::: "memory" ) 237 | 238 | #ifdef __cplusplus 239 | } 240 | #endif 241 | 242 | #endif /* PORTMACRO_H */ 243 | 244 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.3.1 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 | 29 | /* 30 | * The simplest possible implementation of pvPortMalloc(). Note that this 31 | * implementation does NOT allow allocated memory to be freed again. 32 | * 33 | * See heap_2.c, heap_3.c and heap_4.c for alternative implementations, and the 34 | * memory management pages of http://www.FreeRTOS.org for more information. 35 | */ 36 | #include 37 | 38 | /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining 39 | all the API functions to use the MPU wrappers. That should only be done when 40 | task.h is included from an application file. */ 41 | #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE 42 | 43 | #include "FreeRTOS.h" 44 | #include "task.h" 45 | 46 | #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 47 | 48 | #if( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) 49 | #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 50 | #endif 51 | 52 | /* A few bytes might be lost to byte aligning the heap start address. */ 53 | #define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT ) 54 | 55 | /* Allocate the memory for the heap. */ 56 | #if( configAPPLICATION_ALLOCATED_HEAP == 1 ) 57 | /* The application writer has already defined the array used for the RTOS 58 | heap - probably so it can be placed in a special segment or address. */ 59 | extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; 60 | #else 61 | static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; 62 | #endif /* configAPPLICATION_ALLOCATED_HEAP */ 63 | 64 | /* Index into the ucHeap array. */ 65 | static size_t xNextFreeByte = ( size_t ) 0; 66 | 67 | /*-----------------------------------------------------------*/ 68 | 69 | void *pvPortMalloc( size_t xWantedSize ) 70 | { 71 | void *pvReturn = NULL; 72 | static uint8_t *pucAlignedHeap = NULL; 73 | 74 | /* Ensure that blocks are always aligned to the required number of bytes. */ 75 | #if( portBYTE_ALIGNMENT != 1 ) 76 | { 77 | if( xWantedSize & portBYTE_ALIGNMENT_MASK ) 78 | { 79 | /* Byte alignment required. */ 80 | xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); 81 | } 82 | } 83 | #endif 84 | 85 | vTaskSuspendAll(); 86 | { 87 | if( pucAlignedHeap == NULL ) 88 | { 89 | /* Ensure the heap starts on a correctly aligned boundary. */ 90 | pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ portBYTE_ALIGNMENT ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); 91 | } 92 | 93 | /* Check there is enough room left for the allocation. */ 94 | if( ( ( xNextFreeByte + xWantedSize ) < configADJUSTED_HEAP_SIZE ) && 95 | ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) )/* Check for overflow. */ 96 | { 97 | /* Return the next free byte then increment the index past this 98 | block. */ 99 | pvReturn = pucAlignedHeap + xNextFreeByte; 100 | xNextFreeByte += xWantedSize; 101 | } 102 | 103 | traceMALLOC( pvReturn, xWantedSize ); 104 | } 105 | ( void ) xTaskResumeAll(); 106 | 107 | #if( configUSE_MALLOC_FAILED_HOOK == 1 ) 108 | { 109 | if( pvReturn == NULL ) 110 | { 111 | extern void vApplicationMallocFailedHook( void ); 112 | vApplicationMallocFailedHook(); 113 | } 114 | } 115 | #endif 116 | 117 | return pvReturn; 118 | } 119 | /*-----------------------------------------------------------*/ 120 | 121 | void vPortFree( void *pv ) 122 | { 123 | /* Memory cannot be freed using this scheme. See heap_2.c, heap_3.c and 124 | heap_4.c for alternative implementations, and the memory management pages of 125 | http://www.FreeRTOS.org for more information. */ 126 | ( void ) pv; 127 | 128 | /* Force an assert as it is invalid to call this function. */ 129 | configASSERT( pv == NULL ); 130 | } 131 | /*-----------------------------------------------------------*/ 132 | 133 | void vPortInitialiseBlocks( void ) 134 | { 135 | /* Only required when static memory is not cleared. */ 136 | xNextFreeByte = ( size_t ) 0; 137 | } 138 | /*-----------------------------------------------------------*/ 139 | 140 | size_t xPortGetFreeHeapSize( void ) 141 | { 142 | return ( configADJUSTED_HEAP_SIZE - xNextFreeByte ); 143 | } 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # JKBMS to Pylontech protocol converter 3 | 4 | Read data from JK BMS via RS485 protocol and send updates to solar inverter via Pylontech low voltage US2000 battery protocol 5 | 6 | # TODO 7 | 8 | * Test current sensor on charge and discharde 9 | * Check converting alarms from JK BMS to Pytontech 10 | 11 | # Current state 12 | Tested with Deye 3 phase hybrid inverter but only with CAN connection. Battery configured but not enabled 13 | Inverter show battery information: 14 | * current battery voltage 15 | * current battery temperature 16 | * SOC/SOH 17 | * battery charge voltage 18 | * charge current limit 19 | * discharge current limit 20 | 21 | # Old BMS support 22 | Support BMS with request 0xDD, 0xA5, 0x03, 0x00, 0xFF, 0xFD, 0x77. o enable this mode set jumper between PE0 and GND before board start. 23 | 24 | # Hardware 25 | 26 | Tested on [STM32F4XX_M](https://stm32-base.org/boards/STM32F407VGT6-STM32F4XX-M.html) board 27 | 28 | 1. PD0/PD1 CAN interface to inverter 29 | 2. PA11/PA12 - serial output to USB for logs 30 | 3. PA9/PA10 - RS485 interface to JKBMS 31 | 4. Support ILI9341 LCD via SPI. (can be disabled) 32 | 33 | See details at [Wiki page](https://github.com/maxx-ukoo/jk-bms2pylontech/wiki/Modeling-result) 34 | 35 | 36 | ## Disable LCD 37 | 38 | * to disable LCD comment line #define ENABLE_LCD in main.h 39 | 40 | 41 | # Useful links 42 | 43 | [STM32F4xx board description](https://stm32-base.org/boards/STM32F407VGT6-STM32F4XX-M.html) 44 | [Pylon battery real data](https://www.setfirelabs.com/green-energy/pylontech-can-reading-can-replication) 45 | [ESPHome component for parse JKBMS response](https://github.com/syssi/esphome-jk-bms/) -------------------------------------------------------------------------------- /STM32F407VGTX_FLASH.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | ** 4 | ** @file : LinkerScript.ld 5 | ** 6 | ** @author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** @brief : Linker script for STM32F407VGTx Device from STM32F4 series 9 | ** 1024Kbytes FLASH 10 | ** 64Kbytes CCMRAM 11 | ** 128Kbytes RAM 12 | ** 13 | ** Set heap size, stack size and stack location according 14 | ** to application requirements. 15 | ** 16 | ** Set memory bank area and size if external memory is used 17 | ** 18 | ** Target : STMicroelectronics STM32 19 | ** 20 | ** Distribution: The file is distributed as is, without any warranty 21 | ** of any kind. 22 | ** 23 | ****************************************************************************** 24 | ** @attention 25 | ** 26 | ** Copyright (c) 2022 STMicroelectronics. 27 | ** All rights reserved. 28 | ** 29 | ** This software is licensed under terms that can be found in the LICENSE file 30 | ** in the root directory of this software component. 31 | ** If no LICENSE file comes with this software, it is provided AS-IS. 32 | ** 33 | ****************************************************************************** 34 | */ 35 | 36 | /* Entry Point */ 37 | ENTRY(Reset_Handler) 38 | 39 | /* Highest address of the user mode stack */ 40 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ 41 | 42 | _Min_Heap_Size = 0x200 ; /* required amount of heap */ 43 | _Min_Stack_Size = 0x400 ; /* required amount of stack */ 44 | 45 | /* Memories definition */ 46 | MEMORY 47 | { 48 | CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K 49 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K 50 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K 51 | } 52 | 53 | /* Sections */ 54 | SECTIONS 55 | { 56 | /* The startup code into "FLASH" Rom type memory */ 57 | .isr_vector : 58 | { 59 | . = ALIGN(4); 60 | KEEP(*(.isr_vector)) /* Startup code */ 61 | . = ALIGN(4); 62 | } >FLASH 63 | 64 | /* The program code and other data into "FLASH" Rom type memory */ 65 | .text : 66 | { 67 | . = ALIGN(4); 68 | *(.text) /* .text sections (code) */ 69 | *(.text*) /* .text* sections (code) */ 70 | *(.glue_7) /* glue arm to thumb code */ 71 | *(.glue_7t) /* glue thumb to arm code */ 72 | *(.eh_frame) 73 | 74 | KEEP (*(.init)) 75 | KEEP (*(.fini)) 76 | 77 | . = ALIGN(4); 78 | _etext = .; /* define a global symbols at end of code */ 79 | } >FLASH 80 | 81 | /* Constant data into "FLASH" Rom type memory */ 82 | .rodata : 83 | { 84 | . = ALIGN(4); 85 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 86 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 87 | . = ALIGN(4); 88 | } >FLASH 89 | 90 | .ARM.extab : { 91 | . = ALIGN(4); 92 | *(.ARM.extab* .gnu.linkonce.armextab.*) 93 | . = ALIGN(4); 94 | } >FLASH 95 | 96 | .ARM : { 97 | . = ALIGN(4); 98 | __exidx_start = .; 99 | *(.ARM.exidx*) 100 | __exidx_end = .; 101 | . = ALIGN(4); 102 | } >FLASH 103 | 104 | .preinit_array : 105 | { 106 | . = ALIGN(4); 107 | PROVIDE_HIDDEN (__preinit_array_start = .); 108 | KEEP (*(.preinit_array*)) 109 | PROVIDE_HIDDEN (__preinit_array_end = .); 110 | . = ALIGN(4); 111 | } >FLASH 112 | 113 | .init_array : 114 | { 115 | . = ALIGN(4); 116 | PROVIDE_HIDDEN (__init_array_start = .); 117 | KEEP (*(SORT(.init_array.*))) 118 | KEEP (*(.init_array*)) 119 | PROVIDE_HIDDEN (__init_array_end = .); 120 | . = ALIGN(4); 121 | } >FLASH 122 | 123 | .fini_array : 124 | { 125 | . = ALIGN(4); 126 | PROVIDE_HIDDEN (__fini_array_start = .); 127 | KEEP (*(SORT(.fini_array.*))) 128 | KEEP (*(.fini_array*)) 129 | PROVIDE_HIDDEN (__fini_array_end = .); 130 | . = ALIGN(4); 131 | } >FLASH 132 | 133 | /* Used by the startup to initialize data */ 134 | _sidata = LOADADDR(.data); 135 | 136 | /* Initialized data sections into "RAM" Ram type memory */ 137 | .data : 138 | { 139 | . = ALIGN(4); 140 | _sdata = .; /* create a global symbol at data start */ 141 | *(.data) /* .data sections */ 142 | *(.data*) /* .data* sections */ 143 | *(.RamFunc) /* .RamFunc sections */ 144 | *(.RamFunc*) /* .RamFunc* sections */ 145 | 146 | . = ALIGN(4); 147 | _edata = .; /* define a global symbol at data end */ 148 | 149 | } >RAM AT> FLASH 150 | 151 | _siccmram = LOADADDR(.ccmram); 152 | 153 | /* CCM-RAM section 154 | * 155 | * IMPORTANT NOTE! 156 | * If initialized variables will be placed in this section, 157 | * the startup code needs to be modified to copy the init-values. 158 | */ 159 | .ccmram : 160 | { 161 | . = ALIGN(4); 162 | _sccmram = .; /* create a global symbol at ccmram start */ 163 | *(.ccmram) 164 | *(.ccmram*) 165 | 166 | . = ALIGN(4); 167 | _eccmram = .; /* create a global symbol at ccmram end */ 168 | } >CCMRAM AT> FLASH 169 | 170 | /* Uninitialized data section into "RAM" Ram type memory */ 171 | . = ALIGN(4); 172 | .bss : 173 | { 174 | /* This is used by the startup in order to initialize the .bss section */ 175 | _sbss = .; /* define a global symbol at bss start */ 176 | __bss_start__ = _sbss; 177 | *(.bss) 178 | *(.bss*) 179 | *(COMMON) 180 | 181 | . = ALIGN(4); 182 | _ebss = .; /* define a global symbol at bss end */ 183 | __bss_end__ = _ebss; 184 | } >RAM 185 | 186 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ 187 | ._user_heap_stack : 188 | { 189 | . = ALIGN(8); 190 | PROVIDE ( end = . ); 191 | PROVIDE ( _end = . ); 192 | . = . + _Min_Heap_Size; 193 | . = . + _Min_Stack_Size; 194 | . = ALIGN(8); 195 | } >RAM 196 | 197 | /* Remove information from the compiler libraries */ 198 | /DISCARD/ : 199 | { 200 | libc.a ( * ) 201 | libm.a ( * ) 202 | libgcc.a ( * ) 203 | } 204 | 205 | .ARM.attributes 0 : { *(.ARM.attributes) } 206 | } 207 | -------------------------------------------------------------------------------- /STM32F407VGTX_RAM.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | ** 4 | ** @file : LinkerScript.ld (debug in RAM dedicated) 5 | ** 6 | ** @author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** @brief : Linker script for STM32F407VGTx Device from STM32F4 series 9 | ** 1024Kbytes FLASH 10 | ** 64Kbytes CCMRAM 11 | ** 128Kbytes RAM 12 | ** 13 | ** Set heap size, stack size and stack location according 14 | ** to application requirements. 15 | ** 16 | ** Set memory bank area and size if external memory is used 17 | ** 18 | ** Target : STMicroelectronics STM32 19 | ** 20 | ** Distribution: The file is distributed as is, without any warranty 21 | ** of any kind. 22 | ** 23 | ****************************************************************************** 24 | ** @attention 25 | ** 26 | ** Copyright (c) 2022 STMicroelectronics. 27 | ** All rights reserved. 28 | ** 29 | ** This software is licensed under terms that can be found in the LICENSE file 30 | ** in the root directory of this software component. 31 | ** If no LICENSE file comes with this software, it is provided AS-IS. 32 | ** 33 | ****************************************************************************** 34 | */ 35 | 36 | /* Entry Point */ 37 | ENTRY(Reset_Handler) 38 | 39 | /* Highest address of the user mode stack */ 40 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ 41 | 42 | _Min_Heap_Size = 0x200; /* required amount of heap */ 43 | _Min_Stack_Size = 0x400; /* required amount of stack */ 44 | 45 | /* Memories definition */ 46 | MEMORY 47 | { 48 | CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K 49 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K 50 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K 51 | } 52 | 53 | /* Sections */ 54 | SECTIONS 55 | { 56 | /* The startup code into "RAM" Ram type memory */ 57 | .isr_vector : 58 | { 59 | . = ALIGN(4); 60 | KEEP(*(.isr_vector)) /* Startup code */ 61 | . = ALIGN(4); 62 | } >RAM 63 | 64 | /* The program code and other data into "RAM" Ram type memory */ 65 | .text : 66 | { 67 | . = ALIGN(4); 68 | *(.text) /* .text sections (code) */ 69 | *(.text*) /* .text* sections (code) */ 70 | *(.glue_7) /* glue arm to thumb code */ 71 | *(.glue_7t) /* glue thumb to arm code */ 72 | *(.eh_frame) 73 | *(.RamFunc) /* .RamFunc sections */ 74 | *(.RamFunc*) /* .RamFunc* sections */ 75 | 76 | KEEP (*(.init)) 77 | KEEP (*(.fini)) 78 | 79 | . = ALIGN(4); 80 | _etext = .; /* define a global symbols at end of code */ 81 | } >RAM 82 | 83 | /* Constant data into "RAM" Ram type memory */ 84 | .rodata : 85 | { 86 | . = ALIGN(4); 87 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 88 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 89 | . = ALIGN(4); 90 | } >RAM 91 | 92 | .ARM.extab : { 93 | . = ALIGN(4); 94 | *(.ARM.extab* .gnu.linkonce.armextab.*) 95 | . = ALIGN(4); 96 | } >RAM 97 | 98 | .ARM : { 99 | . = ALIGN(4); 100 | __exidx_start = .; 101 | *(.ARM.exidx*) 102 | __exidx_end = .; 103 | . = ALIGN(4); 104 | } >RAM 105 | 106 | .preinit_array : 107 | { 108 | . = ALIGN(4); 109 | PROVIDE_HIDDEN (__preinit_array_start = .); 110 | KEEP (*(.preinit_array*)) 111 | PROVIDE_HIDDEN (__preinit_array_end = .); 112 | . = ALIGN(4); 113 | } >RAM 114 | 115 | .init_array : 116 | { 117 | . = ALIGN(4); 118 | PROVIDE_HIDDEN (__init_array_start = .); 119 | KEEP (*(SORT(.init_array.*))) 120 | KEEP (*(.init_array*)) 121 | PROVIDE_HIDDEN (__init_array_end = .); 122 | . = ALIGN(4); 123 | } >RAM 124 | 125 | .fini_array : 126 | { 127 | . = ALIGN(4); 128 | PROVIDE_HIDDEN (__fini_array_start = .); 129 | KEEP (*(SORT(.fini_array.*))) 130 | KEEP (*(.fini_array*)) 131 | PROVIDE_HIDDEN (__fini_array_end = .); 132 | . = ALIGN(4); 133 | } >RAM 134 | 135 | /* Used by the startup to initialize data */ 136 | _sidata = LOADADDR(.data); 137 | 138 | /* Initialized data sections into "RAM" Ram type memory */ 139 | .data : 140 | { 141 | . = ALIGN(4); 142 | _sdata = .; /* create a global symbol at data start */ 143 | *(.data) /* .data sections */ 144 | *(.data*) /* .data* sections */ 145 | 146 | . = ALIGN(4); 147 | _edata = .; /* define a global symbol at data end */ 148 | 149 | } >RAM 150 | 151 | _siccmram = LOADADDR(.ccmram); 152 | 153 | /* CCM-RAM section 154 | * 155 | * IMPORTANT NOTE! 156 | * If initialized variables will be placed in this section, 157 | * the startup code needs to be modified to copy the init-values. 158 | */ 159 | .ccmram : 160 | { 161 | . = ALIGN(4); 162 | _sccmram = .; /* create a global symbol at ccmram start */ 163 | *(.ccmram) 164 | *(.ccmram*) 165 | 166 | . = ALIGN(4); 167 | _eccmram = .; /* create a global symbol at ccmram end */ 168 | } >CCMRAM AT> RAM 169 | 170 | /* Uninitialized data section into "RAM" Ram type memory */ 171 | . = ALIGN(4); 172 | .bss : 173 | { 174 | /* This is used by the startup in order to initialize the .bss section */ 175 | _sbss = .; /* define a global symbol at bss start */ 176 | __bss_start__ = _sbss; 177 | *(.bss) 178 | *(.bss*) 179 | *(COMMON) 180 | 181 | . = ALIGN(4); 182 | _ebss = .; /* define a global symbol at bss end */ 183 | __bss_end__ = _ebss; 184 | } >RAM 185 | 186 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ 187 | ._user_heap_stack : 188 | { 189 | . = ALIGN(8); 190 | PROVIDE ( end = . ); 191 | PROVIDE ( _end = . ); 192 | . = . + _Min_Heap_Size; 193 | . = . + _Min_Stack_Size; 194 | . = ALIGN(8); 195 | } >RAM 196 | 197 | /* Remove information from the compiler libraries */ 198 | /DISCARD/ : 199 | { 200 | libc.a ( * ) 201 | libm.a ( * ) 202 | libgcc.a ( * ) 203 | } 204 | 205 | .ARM.attributes 0 : { *(.ARM.attributes) } 206 | } 207 | -------------------------------------------------------------------------------- /USB_DEVICE/App/usb_device.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usb_device.c 5 | * @version : v1.0_Cube 6 | * @brief : This file implements the USB Device 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 | /* Includes ------------------------------------------------------------------*/ 22 | 23 | #include "usb_device.h" 24 | #include "usbd_core.h" 25 | #include "usbd_desc.h" 26 | #include "usbd_cdc.h" 27 | #include "usbd_cdc_if.h" 28 | 29 | /* USER CODE BEGIN Includes */ 30 | 31 | /* USER CODE END Includes */ 32 | 33 | /* USER CODE BEGIN PV */ 34 | /* Private variables ---------------------------------------------------------*/ 35 | 36 | /* USER CODE END PV */ 37 | 38 | /* USER CODE BEGIN PFP */ 39 | /* Private function prototypes -----------------------------------------------*/ 40 | 41 | /* USER CODE END PFP */ 42 | 43 | /* USB Device Core handle declaration. */ 44 | USBD_HandleTypeDef hUsbDeviceFS; 45 | 46 | /* 47 | * -- Insert your variables declaration here -- 48 | */ 49 | /* USER CODE BEGIN 0 */ 50 | 51 | /* USER CODE END 0 */ 52 | 53 | /* 54 | * -- Insert your external function declaration here -- 55 | */ 56 | /* USER CODE BEGIN 1 */ 57 | 58 | /* USER CODE END 1 */ 59 | 60 | /** 61 | * Init USB device Library, add supported class and start the library 62 | * @retval None 63 | */ 64 | void MX_USB_DEVICE_Init(void) 65 | { 66 | /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */ 67 | 68 | /* USER CODE END USB_DEVICE_Init_PreTreatment */ 69 | 70 | /* Init Device Library, add supported class and start the library. */ 71 | if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK) 72 | { 73 | Error_Handler(); 74 | } 75 | if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) 76 | { 77 | Error_Handler(); 78 | } 79 | if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) 80 | { 81 | Error_Handler(); 82 | } 83 | if (USBD_Start(&hUsbDeviceFS) != USBD_OK) 84 | { 85 | Error_Handler(); 86 | } 87 | 88 | /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ 89 | 90 | /* USER CODE END USB_DEVICE_Init_PostTreatment */ 91 | } 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | -------------------------------------------------------------------------------- /USB_DEVICE/App/usb_device.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usb_device.h 5 | * @version : v1.0_Cube 6 | * @brief : Header for usb_device.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 __USB_DEVICE__H__ 23 | #define __USB_DEVICE__H__ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32f4xx.h" 31 | #include "stm32f4xx_hal.h" 32 | #include "usbd_def.h" 33 | 34 | /* USER CODE BEGIN INCLUDE */ 35 | 36 | /* USER CODE END INCLUDE */ 37 | 38 | /** @addtogroup USBD_OTG_DRIVER 39 | * @{ 40 | */ 41 | 42 | /** @defgroup USBD_DEVICE USBD_DEVICE 43 | * @brief Device file for Usb otg low level driver. 44 | * @{ 45 | */ 46 | 47 | /** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables 48 | * @brief Public variables. 49 | * @{ 50 | */ 51 | 52 | /* Private variables ---------------------------------------------------------*/ 53 | /* USER CODE BEGIN PV */ 54 | 55 | /* USER CODE END PV */ 56 | 57 | /* Private function prototypes -----------------------------------------------*/ 58 | /* USER CODE BEGIN PFP */ 59 | 60 | /* USER CODE END PFP */ 61 | 62 | /* 63 | * -- Insert your variables declaration here -- 64 | */ 65 | /* USER CODE BEGIN VARIABLES */ 66 | 67 | /* USER CODE END VARIABLES */ 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype 73 | * @brief Declaration of public functions for Usb device. 74 | * @{ 75 | */ 76 | 77 | /** USB Device initialization function. */ 78 | void MX_USB_DEVICE_Init(void); 79 | 80 | /* 81 | * -- Insert functions declaration here -- 82 | */ 83 | /* USER CODE BEGIN FD */ 84 | 85 | /* USER CODE END FD */ 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /* __USB_DEVICE__H__ */ 103 | -------------------------------------------------------------------------------- /USB_DEVICE/App/usbd_cdc_if.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_cdc_if.h 5 | * @version : v1.0_Cube 6 | * @brief : Header for usbd_cdc_if.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_CDC_IF_H__ 23 | #define __USBD_CDC_IF_H__ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usbd_cdc.h" 31 | 32 | /* USER CODE BEGIN INCLUDE */ 33 | 34 | /* USER CODE END INCLUDE */ 35 | 36 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 37 | * @brief For Usb device. 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_CDC_IF USBD_CDC_IF 42 | * @brief Usb VCP device module 43 | * @{ 44 | */ 45 | 46 | /** @defgroup USBD_CDC_IF_Exported_Defines USBD_CDC_IF_Exported_Defines 47 | * @brief Defines. 48 | * @{ 49 | */ 50 | /* Define size for the receive and transmit buffer over CDC */ 51 | #define APP_RX_DATA_SIZE 2048 52 | #define APP_TX_DATA_SIZE 2048 53 | /* USER CODE BEGIN EXPORTED_DEFINES */ 54 | 55 | /* USER CODE END EXPORTED_DEFINES */ 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /** @defgroup USBD_CDC_IF_Exported_Types USBD_CDC_IF_Exported_Types 62 | * @brief Types. 63 | * @{ 64 | */ 65 | 66 | /* USER CODE BEGIN EXPORTED_TYPES */ 67 | 68 | /* USER CODE END EXPORTED_TYPES */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup USBD_CDC_IF_Exported_Macros USBD_CDC_IF_Exported_Macros 75 | * @brief Aliases. 76 | * @{ 77 | */ 78 | 79 | /* USER CODE BEGIN EXPORTED_MACRO */ 80 | 81 | /* USER CODE END EXPORTED_MACRO */ 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | /** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables 88 | * @brief Public variables. 89 | * @{ 90 | */ 91 | 92 | /** CDC Interface callback. */ 93 | extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS; 94 | 95 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 96 | 97 | /* USER CODE END EXPORTED_VARIABLES */ 98 | 99 | /** 100 | * @} 101 | */ 102 | 103 | /** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype USBD_CDC_IF_Exported_FunctionsPrototype 104 | * @brief Public functions declaration. 105 | * @{ 106 | */ 107 | 108 | uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len); 109 | 110 | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ 111 | 112 | /* USER CODE END EXPORTED_FUNCTIONS */ 113 | 114 | /** 115 | * @} 116 | */ 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | /** 123 | * @} 124 | */ 125 | 126 | #ifdef __cplusplus 127 | } 128 | #endif 129 | 130 | #endif /* __USBD_CDC_IF_H__ */ 131 | 132 | -------------------------------------------------------------------------------- /USB_DEVICE/App/usbd_desc.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_desc.c 5 | * @version : v1.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 | -------------------------------------------------------------------------------- /USB_DEVICE/Target/usbd_conf.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_conf.h 5 | * @version : v1.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 "stm32f4xx.h" 35 | #include "stm32f4xx_hal.h" 36 | 37 | /* USER CODE BEGIN INCLUDE */ 38 | 39 | /* USER CODE END INCLUDE */ 40 | 41 | /** @addtogroup USBD_OTG_DRIVER 42 | * @brief Driver for Usb device. 43 | * @{ 44 | */ 45 | 46 | /** @defgroup USBD_CONF USBD_CONF 47 | * @brief Configuration file for Usb otg low level driver. 48 | * @{ 49 | */ 50 | 51 | /** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables 52 | * @brief Public variables. 53 | * @{ 54 | */ 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | /** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines 61 | * @brief Defines for configuration of the Usb device. 62 | * @{ 63 | */ 64 | 65 | /*---------- -----------*/ 66 | #define USBD_MAX_NUM_INTERFACES 1U 67 | /*---------- -----------*/ 68 | #define USBD_MAX_NUM_CONFIGURATION 1U 69 | /*---------- -----------*/ 70 | #define USBD_MAX_STR_DESC_SIZ 512U 71 | /*---------- -----------*/ 72 | #define USBD_DEBUG_LEVEL 0U 73 | /*---------- -----------*/ 74 | #define USBD_LPM_ENABLED 0U 75 | /*---------- -----------*/ 76 | #define USBD_SELF_POWERED 1U 77 | 78 | /****************************************/ 79 | /* #define for FS and HS identification */ 80 | #define DEVICE_FS 0 81 | #define DEVICE_HS 1 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | /** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros 88 | * @brief Aliases. 89 | * @{ 90 | */ 91 | /* Memory management macros make sure to use static memory allocation */ 92 | /** Alias for memory allocation. */ 93 | 94 | #define USBD_malloc (void *)USBD_static_malloc 95 | 96 | /** Alias for memory release. */ 97 | #define USBD_free USBD_static_free 98 | 99 | /** Alias for memory set. */ 100 | #define USBD_memset memset 101 | 102 | /** Alias for memory copy. */ 103 | #define USBD_memcpy memcpy 104 | 105 | /** Alias for delay. */ 106 | #define USBD_Delay HAL_Delay 107 | 108 | /* DEBUG macros */ 109 | 110 | #if (USBD_DEBUG_LEVEL > 0) 111 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\ 112 | printf("\n"); 113 | #else 114 | #define USBD_UsrLog(...) 115 | #endif 116 | 117 | #if (USBD_DEBUG_LEVEL > 1) 118 | 119 | #define USBD_ErrLog(...) printf("ERROR: ") ;\ 120 | printf(__VA_ARGS__);\ 121 | printf("\n"); 122 | #else 123 | #define USBD_ErrLog(...) 124 | #endif 125 | 126 | #if (USBD_DEBUG_LEVEL > 2) 127 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\ 128 | printf(__VA_ARGS__);\ 129 | printf("\n"); 130 | #else 131 | #define USBD_DbgLog(...) 132 | #endif 133 | 134 | /** 135 | * @} 136 | */ 137 | 138 | /** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types 139 | * @brief Types. 140 | * @{ 141 | */ 142 | 143 | /** 144 | * @} 145 | */ 146 | 147 | /** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype 148 | * @brief Declaration of public functions for Usb device. 149 | * @{ 150 | */ 151 | 152 | /* Exported functions -------------------------------------------------------*/ 153 | void *USBD_static_malloc(uint32_t size); 154 | void USBD_static_free(void *p); 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /** 161 | * @} 162 | */ 163 | 164 | /** 165 | * @} 166 | */ 167 | 168 | #ifdef __cplusplus 169 | } 170 | #endif 171 | 172 | #endif /* __USBD_CONF__H__ */ 173 | 174 | -------------------------------------------------------------------------------- /jk-bms2pylontech.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | CAN1.BS1=CAN_BS1_9TQ 3 | CAN1.BS2=CAN_BS2_8TQ 4 | CAN1.CalculateBaudRate=500000 5 | CAN1.CalculateTimeBit=2000 6 | CAN1.CalculateTimeQuantum=111.11111111111111 7 | CAN1.IPParameters=CalculateTimeQuantum,CalculateTimeBit,CalculateBaudRate,BS1,BS2,Prescaler,Mode 8 | CAN1.Mode=CAN_MODE_NORMAL 9 | CAN1.Prescaler=4 10 | FREERTOS.FootprintOK=true 11 | FREERTOS.HEAP_NUMBER=1 12 | FREERTOS.IPParameters=Tasks01,FootprintOK,configMINIMAL_STACK_SIZE,configCHECK_FOR_STACK_OVERFLOW,HEAP_NUMBER,Queues01,configUSE_NEWLIB_REENTRANT 13 | FREERTOS.Queues01=consoleOutputQueue,32,uint8_t,0,Dynamic,NULL,NULL 14 | FREERTOS.Tasks01=getBMSDataTask,24,128,startGetBMSDataTask,Default,NULL,Dynamic,NULL,NULL;every10msTask,24,128,startEvery10msTask,Default,NULL,Dynamic,NULL,NULL;consoleOutputTa,8,128,startConsoleOutputTask,Default,NULL,Dynamic,NULL,NULL 15 | FREERTOS.configCHECK_FOR_STACK_OVERFLOW=0 16 | FREERTOS.configMINIMAL_STACK_SIZE=128 17 | FREERTOS.configUSE_NEWLIB_REENTRANT=1 18 | File.Version=6 19 | GPIO.groupedBy=Group By Peripherals 20 | KeepUserPlacement=false 21 | Mcu.Family=STM32F4 22 | Mcu.IP0=CAN1 23 | Mcu.IP1=FREERTOS 24 | Mcu.IP2=NVIC 25 | Mcu.IP3=RCC 26 | Mcu.IP4=SPI2 27 | Mcu.IP5=SYS 28 | Mcu.IP6=USART1 29 | Mcu.IP7=USB_DEVICE 30 | Mcu.IP8=USB_OTG_FS 31 | Mcu.IPNb=9 32 | Mcu.Name=STM32F407V(E-G)Tx 33 | Mcu.Package=LQFP100 34 | Mcu.Pin0=PH0-OSC_IN 35 | Mcu.Pin1=PH1-OSC_OUT 36 | Mcu.Pin10=PA9 37 | Mcu.Pin11=PA10 38 | Mcu.Pin12=PA11 39 | Mcu.Pin13=PA12 40 | Mcu.Pin14=PA13 41 | Mcu.Pin15=PA14 42 | Mcu.Pin16=PA15 43 | Mcu.Pin17=PD0 44 | Mcu.Pin18=PD1 45 | Mcu.Pin19=PB3 46 | Mcu.Pin2=PA0-WKUP 47 | Mcu.Pin20=PE0 48 | Mcu.Pin21=VP_FREERTOS_VS_CMSIS_V2 49 | Mcu.Pin22=VP_SYS_VS_tim1 50 | Mcu.Pin23=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS 51 | Mcu.Pin3=PA1 52 | Mcu.Pin4=PC5 53 | Mcu.Pin5=PB1 54 | Mcu.Pin6=PB12 55 | Mcu.Pin7=PB13 56 | Mcu.Pin8=PB14 57 | Mcu.Pin9=PB15 58 | Mcu.PinsNb=24 59 | Mcu.ThirdPartyNb=0 60 | Mcu.UserConstants= 61 | Mcu.UserName=STM32F407VGTx 62 | MxCube.Version=6.4.0 63 | MxDb.Version=DB.6.0.40 64 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 65 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 66 | NVIC.ForceEnableDMAVector=true 67 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 68 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 69 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 70 | NVIC.OTG_FS_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true 71 | NVIC.PendSV_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:false 72 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 73 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false 74 | NVIC.SavedPendsvIrqHandlerGenerated=true 75 | NVIC.SavedSvcallIrqHandlerGenerated=true 76 | NVIC.SavedSystickIrqHandlerGenerated=true 77 | NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:true 78 | NVIC.TIM1_UP_TIM10_IRQn=true\:15\:0\:false\:false\:true\:false\:false\:true 79 | NVIC.TimeBase=TIM1_UP_TIM10_IRQn 80 | NVIC.TimeBaseIP=TIM1 81 | NVIC.USART1_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true 82 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 83 | PA0-WKUP.Mode=SYS_WakeUp0 84 | PA0-WKUP.Signal=SYS_WKUP 85 | PA1.GPIOParameters=GPIO_Label 86 | PA1.GPIO_Label=LED_D2 87 | PA1.Locked=true 88 | PA1.Signal=GPIO_Output 89 | PA10.Mode=Asynchronous 90 | PA10.Signal=USART1_RX 91 | PA11.Mode=Device_Only 92 | PA11.Signal=USB_OTG_FS_DM 93 | PA12.Mode=Device_Only 94 | PA12.Signal=USB_OTG_FS_DP 95 | PA13.Mode=JTAG_4_pins 96 | PA13.Signal=SYS_JTMS-SWDIO 97 | PA14.Mode=JTAG_4_pins 98 | PA14.Signal=SYS_JTCK-SWCLK 99 | PA15.Mode=JTAG_4_pins 100 | PA15.Signal=SYS_JTDI 101 | PA9.Locked=true 102 | PA9.Mode=Asynchronous 103 | PA9.Signal=USART1_TX 104 | PB1.GPIOParameters=GPIO_Label 105 | PB1.GPIO_Label=TFT_RST 106 | PB1.Locked=true 107 | PB1.Signal=GPIO_Output 108 | PB12.GPIOParameters=GPIO_Label 109 | PB12.GPIO_Label=TFT_CS 110 | PB12.Locked=true 111 | PB12.Signal=GPIO_Output 112 | PB13.Locked=true 113 | PB13.Mode=Full_Duplex_Master 114 | PB13.Signal=SPI2_SCK 115 | PB14.Locked=true 116 | PB14.Mode=Full_Duplex_Master 117 | PB14.Signal=SPI2_MISO 118 | PB15.Locked=true 119 | PB15.Mode=Full_Duplex_Master 120 | PB15.Signal=SPI2_MOSI 121 | PB3.Mode=JTAG_4_pins 122 | PB3.Signal=SYS_JTDO-SWO 123 | PC5.GPIOParameters=GPIO_Label 124 | PC5.GPIO_Label=TFT_DC 125 | PC5.Locked=true 126 | PC5.Signal=GPIO_Output 127 | PD0.Locked=true 128 | PD0.Mode=CAN_Activate 129 | PD0.Signal=CAN1_RX 130 | PD1.Locked=true 131 | PD1.Mode=CAN_Activate 132 | PD1.Signal=CAN1_TX 133 | PE0.GPIOParameters=GPIO_PuPd,GPIO_Label 134 | PE0.GPIO_Label=BMS_TYPE_SWITCH 135 | PE0.GPIO_PuPd=GPIO_PULLUP 136 | PE0.Locked=true 137 | PE0.Signal=GPIO_Input 138 | PH0-OSC_IN.Mode=HSE-External-Oscillator 139 | PH0-OSC_IN.Signal=RCC_OSC_IN 140 | PH1-OSC_OUT.Mode=HSE-External-Oscillator 141 | PH1-OSC_OUT.Signal=RCC_OSC_OUT 142 | PinOutPanel.RotationAngle=0 143 | ProjectManager.AskForMigrate=true 144 | ProjectManager.BackupPrevious=false 145 | ProjectManager.CompilerOptimize=6 146 | ProjectManager.ComputerToolchain=false 147 | ProjectManager.CoupleFile=false 148 | ProjectManager.CustomerFirmwarePackage= 149 | ProjectManager.DefaultFWLocation=true 150 | ProjectManager.DeletePrevious=true 151 | ProjectManager.DeviceId=STM32F407VGTx 152 | ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.26.2 153 | ProjectManager.FreePins=false 154 | ProjectManager.HalAssertFull=false 155 | ProjectManager.HeapSize=0x200 156 | ProjectManager.KeepUserCode=true 157 | ProjectManager.LastFirmware=true 158 | ProjectManager.LibraryCopy=1 159 | ProjectManager.MainLocation=Core/Src 160 | ProjectManager.NoMain=false 161 | ProjectManager.PreviousToolchain= 162 | ProjectManager.ProjectBuild=false 163 | ProjectManager.ProjectFileName=jk-bms2pylontech.ioc 164 | ProjectManager.ProjectName=jk-bms2pylontech 165 | ProjectManager.RegisterCallBack= 166 | ProjectManager.StackSize=0x400 167 | ProjectManager.TargetToolchain=STM32CubeIDE 168 | ProjectManager.ToolChainLocation= 169 | ProjectManager.UnderRoot=true 170 | ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_CAN1_Init-CAN1-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,6-MX_SPI2_Init-SPI2-false-HAL-true 171 | RCC.48MHZClocksFreq_Value=48000000 172 | RCC.AHBFreq_Value=72000000 173 | RCC.APB1CLKDivider=RCC_HCLK_DIV2 174 | RCC.APB1Freq_Value=36000000 175 | RCC.APB1TimFreq_Value=72000000 176 | RCC.APB2Freq_Value=72000000 177 | RCC.APB2TimFreq_Value=72000000 178 | RCC.CortexFreq_Value=72000000 179 | RCC.EthernetFreq_Value=72000000 180 | RCC.FCLKCortexFreq_Value=72000000 181 | RCC.FamilyName=M 182 | RCC.HCLKFreq_Value=72000000 183 | RCC.HSE_VALUE=8000000 184 | RCC.HSI_VALUE=16000000 185 | RCC.I2SClocksFreq_Value=192000000 186 | RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSE_VALUE,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLM,PLLN,PLLQ,PLLQCLKFreq_Value,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VcooutputI2S 187 | RCC.LSE_VALUE=32768 188 | RCC.LSI_VALUE=32000 189 | RCC.MCO2PinFreq_Value=72000000 190 | RCC.PLLCLKFreq_Value=72000000 191 | RCC.PLLM=4 192 | RCC.PLLN=72 193 | RCC.PLLQ=3 194 | RCC.PLLQCLKFreq_Value=48000000 195 | RCC.RTCFreq_Value=32000 196 | RCC.RTCHSEDivFreq_Value=4000000 197 | RCC.SYSCLKFreq_VALUE=72000000 198 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 199 | RCC.VCOI2SOutputFreq_Value=384000000 200 | RCC.VCOInputFreq_Value=2000000 201 | RCC.VCOOutputFreq_Value=144000000 202 | RCC.VcooutputI2S=192000000 203 | SPI2.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_2 204 | SPI2.CalculateBaudRate=18.0 MBits/s 205 | SPI2.Direction=SPI_DIRECTION_2LINES 206 | SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler 207 | SPI2.Mode=SPI_MODE_MASTER 208 | SPI2.VirtualType=VM_MASTER 209 | USART1.IPParameters=VirtualMode 210 | USART1.VirtualMode=VM_ASYNC 211 | USB_DEVICE.CLASS_NAME_FS=CDC 212 | USB_DEVICE.IPParameters=VirtualMode-CDC_FS,VirtualModeFS,CLASS_NAME_FS 213 | USB_DEVICE.VirtualMode-CDC_FS=Cdc 214 | USB_DEVICE.VirtualModeFS=Cdc_FS 215 | USB_OTG_FS.IPParameters=VirtualMode 216 | USB_OTG_FS.VirtualMode=Device_Only 217 | VP_FREERTOS_VS_CMSIS_V2.Mode=CMSIS_V2 218 | VP_FREERTOS_VS_CMSIS_V2.Signal=FREERTOS_VS_CMSIS_V2 219 | VP_SYS_VS_tim1.Mode=TIM1 220 | VP_SYS_VS_tim1.Signal=SYS_VS_tim1 221 | VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS 222 | VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_FS 223 | board=custom 224 | isbadioc=false 225 | --------------------------------------------------------------------------------