From 46c875c2089d04f19d692c104828f197cec75676 Mon Sep 17 00:00:00 2001 From: Floris Romeijn Date: Tue, 31 Oct 2023 20:12:43 +0100 Subject: [PATCH 1/4] able to build with gcc --- .gitignore | 1 + LCM/Code/App/task.c | 114 ++++---- .../Source/GCC/startup_hk32f030mf4p6.s | 245 ++++++++++++++++++ LCM/Library/LDScripts/hk32f030mf4p6.ld | 163 ++++++++++++ LCM/Makefile | 75 ++++++ LCM/Readme/Readme.txt | 6 - LCM/rules.mk | 124 +++++++++ README.md | 71 +++++ 8 files changed, 736 insertions(+), 63 deletions(-) create mode 100644 LCM/Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/CMSIS/HK32F030M/Source/GCC/startup_hk32f030mf4p6.s create mode 100644 LCM/Library/LDScripts/hk32f030mf4p6.ld create mode 100644 LCM/Makefile delete mode 100644 LCM/Readme/Readme.txt create mode 100644 LCM/rules.mk create mode 100644 README.md diff --git a/.gitignore b/.gitignore index b20d9939..39fea4c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ LCM/Project/MDK5/Objects/ LCM/Project/MDK5/LCM_Light_Control_IO_WS2812_New.uvguix.* LCM/Project/MDK5/Listings/ +LCM/Build/ diff --git a/LCM/Code/App/task.c b/LCM/Code/App/task.c index 1e7dd75f..8acf2db9 100644 --- a/LCM/Code/App/task.c +++ b/LCM/Code/App/task.c @@ -3,9 +3,9 @@ /************************************************** * @brie :LED_Task() - * @note :LED任务 - * @param :无 - * @retval :无 + * @note :LED锟斤拷锟斤拷 + * @param :锟斤拷 + * @retval :锟斤拷 **************************************************/ void LED_Task(void) { @@ -18,13 +18,13 @@ void LED_Task(void) /************************************************** * @brie :KEY1_Task() - * @note :KEY1任务 - * @param :无 - * @retval :无 + * @note :KEY1锟斤拷锟斤拷 + * @param :锟斤拷 + * @retval :锟斤拷 **************************************************/ void KEY1_Task(void) { - if(KEY1_State == 0 || Power_Flag == 3) //充电器供电按键不起作用 + if(KEY1_State == 0 || Power_Flag == 3) //锟斤拷锟斤拷锟斤拷锟斤拷绨达拷锟斤拷锟斤拷锟斤拷锟斤拷锟 { return; } @@ -177,7 +177,7 @@ void WS2812_VESC(void) void WS2812_Boot(void) { uint8_t i; - uint8_t num = floor(Power_Time / 100) + 1; + uint8_t num = floorf(Power_Time / 100) + 1; uint8_t rgbMap[10][3] = {{255,0,0}, {255,127,0}, {255,255,0}, {127,255,0}, {0,255,0}, {0,255,127}, {0,255,255}, {0,127,255}, {0,0,255}, {127,0,255}}; while (num > 10) { @@ -249,9 +249,9 @@ void WS2812_Charge(void) /************************************************** * @brie :WS2812_Task() - * @note :WS2812任务 - * @param :无 - * @retval :无 + * @note :WS2812锟斤拷锟斤拷 + * @param :锟斤拷 + * @retval :锟斤拷 **************************************************/ void WS2812_Task(void) { @@ -306,15 +306,15 @@ void WS2812_Task(void) } else switch(Gear_Position) { - case 1: //1挡 + case 1: //1锟斤拷 WS2812_Measure = WS2812_1_BRIGHTNESS; break; - case 2: //2挡 + case 2: //2锟斤拷 WS2812_Measure = WS2812_2_BRIGHTNESS; break; - case 3: //3挡 + case 3: //3锟斤拷 WS2812_Measure = WS2812_3_BRIGHTNESS; break; @@ -344,13 +344,13 @@ void WS2812_Task(void) /************************************************** * @brie :Power_Task() - * @note :电源任务 - * @param :无 - * @retval :无 + * @note :锟斤拷源锟斤拷锟斤拷 + * @param :锟斤拷 + * @retval :锟斤拷 **************************************************/ void Power_Task(void) { - static uint8_t power_flag_last = 0; //上一次的状态 + static uint8_t power_flag_last = 0; //锟斤拷一锟轿碉拷状态 static uint8_t power_step = 0; if(power_flag_last == Power_Flag && Power_Flag != 1) @@ -361,7 +361,7 @@ void Power_Task(void) switch(Power_Flag) { - case 1://VESC开机 + case 1://VESC锟斤拷锟斤拷 PWR_ON; switch(power_step) { @@ -373,9 +373,9 @@ void Power_Task(void) case 1: if(Power_Time > VESC_BOOT_TIME) { - Power_Flag = 2; //开机完成 - Gear_Position = 1; //开机后默认是1挡 - Buzzer_Flag = 2; //开机默认蜂鸣器响 + Power_Flag = 2; //锟斤拷锟斤拷锟斤拷锟 + Gear_Position = 1; //锟斤拷锟斤拷锟斤拷默锟斤拷锟斤拷1锟斤拷 + Buzzer_Flag = 2; //锟斤拷锟斤拷默锟较凤拷锟斤拷锟斤拷锟斤拷 power_step = 0; } break; @@ -383,10 +383,10 @@ void Power_Task(void) break; - case 3://VESC关机,充电器给板子供电 + case 3://VESC锟截伙拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷庸锟斤拷锟 PWR_OFF; //LED1_Filp_Time(1000); - //Charge_Flag = 1; //准备充电 + //Charge_Flag = 1; //准锟斤拷锟斤拷锟 break; default: @@ -397,9 +397,9 @@ void Power_Task(void) /************************************************** * @brie :Charge_Task() - * @note :充电任务 - * @param :无 - * @retval :无 + * @note :锟斤拷锟斤拷锟斤拷锟 + * @param :锟斤拷 + * @retval :锟斤拷 **************************************************/ void Charge_Task(void) { @@ -418,14 +418,14 @@ void Charge_Task(void) break; case 1: - if(Charge_Time > 1000) //延时1S + if(Charge_Time > 1000) //锟斤拷时1S { charge_step = 2; } break; case 2: - CHARGE_ON; //打开充电器 + CHARGE_ON; //锟津开筹拷锟斤拷锟 Charge_Flag = 2; charge_step = 3; break; @@ -440,7 +440,7 @@ void Charge_Task(void) { V_I = 1; Charge_Time = 0; - LED1_ON; //采集充电电压 + LED1_ON; //锟缴硷拷锟斤拷锟斤拷压 charge_step = 5; } break; @@ -450,7 +450,7 @@ void Charge_Task(void) { V_I = 0; Charge_Time = 0; - LED1_OFF; //采集充电流 + LED1_OFF; //锟缴硷拷锟斤拷锟斤拷锟 charge_step = 4; } break; @@ -522,25 +522,25 @@ void Headlights_Task(void) /************************************************** * @brie :Buzzer_Task() - * @note :蜂鸣器任务 - * @param :无 - * @retval :无 + * @note :锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 + * @param :锟斤拷 + * @retval :锟斤拷 **************************************************/ void Buzzer_Task(void) { static uint8_t buzzer_step = 0; - static uint8_t gear_position_last = 0; //上一次的档位 + static uint8_t gear_position_last = 0; //锟斤拷一锟轿的碉拷位 static uint8_t ring_frequency = 0; static uint16_t sound_frequency = 0; - if(Power_Flag != 2 || Buzzer_Flag == 1) //VESC断电或蜂鸣器关闭 + if(Power_Flag != 2 || Buzzer_Flag == 1) //VESC锟较碉拷锟斤拷锟斤拷锟斤拷锟截憋拷 { BUZZER_OFF; buzzer_step = 0; return; } - if(Buzzer_Frequency == 0 && gear_position_last == Gear_Position) //蜂鸣器响的频率为0或上一次的档位等于这次的档位 + if(Buzzer_Frequency == 0 && gear_position_last == Gear_Position) //锟斤拷锟斤拷锟斤拷锟斤拷锟狡碉拷锟轿0锟斤拷锟斤拷一锟轿的碉拷位锟斤拷锟斤拷锟斤拷蔚牡锟轿 { BUZZER_OFF; buzzer_step = 0; @@ -611,9 +611,9 @@ void Buzzer_Task(void) /************************************************** * @brie :Usart_Task() - * @note :串口任务 - * @param :无 - * @retval :无 + * @note :锟斤拷锟斤拷锟斤拷锟斤拷 + * @param :锟斤拷 + * @retval :锟斤拷 **************************************************/ void Usart_Task(void) { @@ -662,16 +662,16 @@ void Usart_Task(void) VESC_RX_Flag = 0; result = Protocol_Parse(VESC_RX_Buff); - if(result == 0) //解析成功 + if(result == 0) //锟斤拷锟斤拷锟缴癸拷 { //LED1_Filp_Time(500); Usart_Flag = 1; -// Battery_Voltage = data.inpVoltage; //电池电压 -// VESC_Rpm = data.rpm; //转速 -// AvgInputCurrent = data.avgInputCurrent; //母线电流 -// DutyCycleNow = data.dutyCycleNow; //占空比 +// Battery_Voltage = data.inpVoltage; //锟斤拷氐锟窖 +// VESC_Rpm = data.rpm; //转锟斤拷 +// AvgInputCurrent = data.avgInputCurrent; //母锟竭碉拷锟斤拷 +// DutyCycleNow = data.dutyCycleNow; //占锟秸憋拷 } - else //解析失败 + else //锟斤拷锟斤拷失锟斤拷 { //LED1_Filp_Time(100); Usart_Flag = 2; @@ -714,9 +714,9 @@ void Usart_Task(void) //float k = 0.15; /************************************************** * @brie :ADC_Task() - * @note :ADC任务 - * @param :无 - * @retval :无 + * @note :ADC锟斤拷锟斤拷 + * @param :锟斤拷 + * @retval :锟斤拷 **************************************************/ void ADC_Task(void) { @@ -763,7 +763,7 @@ void ADC_Task(void) // V_I = 0; // Charge_Time = 0; // Sampling_Completion = 0; -// LED1_OFF; //采集充电流 +// LED1_OFF; //锟缴硷拷锟斤拷锟斤拷锟 // Charge_Voltage = (float)(adc_charge_sum_ave*0.0257080078125); // // } @@ -776,7 +776,7 @@ void ADC_Task(void) // // if(i == 10) // { -// LED1_ON; //采集充电压 +// LED1_ON; //锟缴硷拷锟斤拷锟窖 // Charge_Time = 0; // Sampling_Completion = 1; // V_I = 1; @@ -886,9 +886,9 @@ void CheckPowerLevel(float battery_voltage) /************************************************** * @brie :Conditional_Judgment() - * @note :条件判断 - * @param :无 - * @retval :无 + * @note :锟斤拷锟斤拷锟叫讹拷 + * @param :锟斤拷 + * @retval :锟斤拷 **************************************************/ void Conditional_Judgment(void) { @@ -998,8 +998,8 @@ void Conditional_Judgment(void) Charger_Detection_1ms = 0; } /* - 脚踏板踩下或转速大于1000定时清零 - 即不踩脚踏板转速低于1000开始计时,超过关机时间关机 + 锟斤拷踏锟斤拷锟斤拷禄锟阶拷俅锟斤拷锟1000锟斤拷时锟斤拷锟斤拷 + 锟斤拷锟斤拷锟饺斤拷踏锟斤拷转锟劫碉拷锟斤拷1000锟斤拷始锟斤拷时锟斤拷锟斤拷锟斤拷锟截伙拷时锟斤拷鼗锟 */ if(ADC1_Val > 2.9 || ADC2_Val > 2.9 || data.rpm > 1000) { @@ -1031,7 +1031,7 @@ void Conditional_Judgment(void) { // Charge_Flag = 3; Shutdown_Cnt = 0; - CHARGE_OFF; //关闭充电器 + CHARGE_OFF; //锟截闭筹拷锟斤拷锟 } } else diff --git a/LCM/Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/CMSIS/HK32F030M/Source/GCC/startup_hk32f030mf4p6.s b/LCM/Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/CMSIS/HK32F030M/Source/GCC/startup_hk32f030mf4p6.s new file mode 100644 index 00000000..822b0749 --- /dev/null +++ b/LCM/Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/CMSIS/HK32F030M/Source/GCC/startup_hk32f030mf4p6.s @@ -0,0 +1,245 @@ +/** + ****************************************************************************** + * @file startup_hk32f030mf4p6.s + * @brief HK32F030MF4P6 devices vector table for GCC toolchain. + * This module performs: + * - Set the initial SP + * - Set the initial PC == Reset_Handler, + * - Set the vector table entries with the exceptions ISR address + * - Branches to main in the C library (which eventually calls main()). + * After Reset the Cortex-M0 processor is in Thread mode, + * priority is Privileged, and the Stack is set to Main. + ****************************************************************************** + */ + + .syntax unified + .cpu cortex-m0 + .fpu softvfp + .thumb + +.global g_pfnVectors +.global Default_Handler + +/* start address for the initialization values of the .data section. +defined in linker script */ +.word _sidata +/* start address for the .data section. defined in linker script */ +.word _sdata +/* end address for the .data section. defined in linker script */ +.word _edata +/* start address for the .bss section. defined in linker script */ +.word _sbss +/* end address for the .bss section. defined in linker script */ +.word _ebss + + .section .text.Reset_Handler + .weak Reset_Handler + .type Reset_Handler, %function +Reset_Handler: + ldr r0, =_estack + mov sp, r0 /* set stack pointer */ + +/* Copy the data segment initializers from flash to SRAM */ + ldr r0, =_sdata + ldr r1, =_edata + ldr r2, =_sidata + movs r3, #0 + b LoopCopyDataInit + +CopyDataInit: + ldr r4, [r2, r3] + str r4, [r0, r3] + adds r3, r3, #4 + +LoopCopyDataInit: + adds r4, r0, r3 + cmp r4, r1 + bcc CopyDataInit + +/* Zero fill the bss segment. */ + ldr r2, =_sbss + ldr r4, =_ebss + movs r3, #0 + b LoopFillZerobss + +FillZerobss: + str r3, [r2] + adds r2, r2, #4 + +LoopFillZerobss: + cmp r2, r4 + bcc FillZerobss + +/* Call the clock system intitialization function.*/ + bl SystemInit +/* Call static constructors. Remove this line if compile with `-nostartfiles` reports error */ + bl __libc_init_array +/* Call the application's entry point.*/ + bl main + +LoopForever: + b LoopForever + + +.size Reset_Handler, .-Reset_Handler + +/** + * @brief This is the code that gets called when the processor receives an + * unexpected interrupt. This simply enters an infinite loop, preserving + * the system state for examination by a debugger. + * + * @param None + * @retval : None +*/ + .section .text.Default_Handler,"ax",%progbits +Default_Handler: +Infinite_Loop: + b Infinite_Loop + .size Default_Handler, .-Default_Handler +/****************************************************************************** +* +* The minimal vector table for a Cortex M0. Note that the proper constructs +* must be placed on this to ensure that it ends up at physical address +* 0x0000.0000. +* +******************************************************************************/ + .section .isr_vector,"a",%progbits + .type g_pfnVectors, %object + .size g_pfnVectors, .-g_pfnVectors + + +g_pfnVectors: + .word _estack + .word Reset_Handler + .word NMI_Handler + .word HardFault_Handler + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word SVC_Handler + .word 0 + .word 0 + .word PendSV_Handler + .word SysTick_Handler + .word WWDG_IRQHandler /* Window WatchDog */ + .word 0 /* Reserved */ + .word EXTI11_IRQHandler /* EXTI Line 11 interrupt(AWU_WKP) */ + .word FLASH_IRQHandler /* FLASH */ + .word RCC_IRQHandler /* RCC */ + .word EXTI0_IRQHandler /* EXTI Line 0 */ + .word EXTI1_IRQHandler /* EXTI Line 1 */ + .word EXTI2_IRQHandler /* EXTI Line 2 */ + .word EXTI3_IRQHandler /* EXTI Line 3 */ + .word EXTI4_IRQHandler /* EXTI Line 4 */ + .word EXTI5_IRQHandler /* EXTI Line 5 */ + .word TIM1_BRK_IRQHandler /* TIM1 break interrupt */ + .word ADC1_IRQHandler /* ADC1 interrupt, combined with EXTI line 8 */ + .word TIM1_UP_TRG_COM_IRQHandler /* TIM1 Update, Trigger and Commutation */ + .word TIM1_CC_IRQHandler /* TIM1 Capture Compare */ + .word TIM2_IRQHandler /* TIM2 */ + .word 0 /* Reserved */ + .word TIM6_IRQHandler /* TIM6 */ + .word 0 /* Reserved */ + .word 0 /* Reserved */ + .word 0 /* Reserved */ + .word EXTI6_IRQHandler /* EXTI Line 6 */ + .word EXTI7_IRQHandler /* EXTI Line 7 */ + .word I2C1_IRQHandler /* I2C1 global interrupt, combined with EXTI Line 10 */ + .word 0 /* Reserved */ + .word SPI1_IRQHandler /* SPI1 */ + .word 0 /* Reserved */ + .word USART1_IRQHandler /* USART1 global interrupt, combined with EXTI Line 9 */ + .word 0 /* Reserved */ + .word 0 /* Reserved */ + .word 0 /* Reserved */ + .word 0 /* Reserved */ + +/******************************************************************************* +* +* Provide weak aliases for each Exception handler to the Default_Handler. +* As they are weak aliases, any function with the same name will override +* this definition. +* +*******************************************************************************/ + + .weak NMI_Handler + .thumb_set NMI_Handler,Default_Handler + + .weak HardFault_Handler + .thumb_set HardFault_Handler,Default_Handler + + .weak SVC_Handler + .thumb_set SVC_Handler,Default_Handler + + .weak PendSV_Handler + .thumb_set PendSV_Handler,Default_Handler + + .weak SysTick_Handler + .thumb_set SysTick_Handler,Default_Handler + + .weak WWDG_IRQHandler + .thumb_set WWDG_IRQHandler,Default_Handler + + .weak EXTI11_IRQHandler + .thumb_set EXTI11_IRQHandler,Default_Handler + + .weak FLASH_IRQHandler + .thumb_set FLASH_IRQHandler,Default_Handler + + .weak RCC_IRQHandler + .thumb_set RCC_IRQHandler,Default_Handler + + .weak EXTI0_IRQHandler + .thumb_set EXTI0_IRQHandler,Default_Handler + + .weak EXTI1_IRQHandler + .thumb_set EXTI1_IRQHandler,Default_Handler + + .weak EXTI2_IRQHandler + .thumb_set EXTI2_IRQHandler,Default_Handler + + .weak EXTI3_IRQHandler + .thumb_set EXTI3_IRQHandler,Default_Handler + + .weak EXTI4_IRQHandler + .thumb_set EXTI4_IRQHandler,Default_Handler + + .weak EXTI5_IRQHandler + .thumb_set EXTI5_IRQHandler,Default_Handler + + .weak TIM1_BRK_IRQHandler + .thumb_set TIM1_BRK_IRQHandler,Default_Handler + + .weak ADC1_IRQHandler + .thumb_set ADC1_IRQHandler,Default_Handler + + .weak TIM1_UP_TRG_COM_IRQHandler + .thumb_set TIM1_UP_TRG_COM_IRQHandler,Default_Handler + + .weak TIM1_CC_IRQHandler + .thumb_set TIM1_CC_IRQHandler,Default_Handler + + .weak TIM2_IRQHandler + .thumb_set TIM2_IRQHandler,Default_Handler + + .weak TIM6_IRQHandler + .thumb_set TIM6_IRQHandler,Default_Handler + + .weak EXTI6_IRQHandler + .thumb_set EXTI6_IRQHandler,Default_Handler + + .weak EXTI7_IRQHandler + .thumb_set EXTI7_IRQHandler,Default_Handler + + .weak I2C1_IRQHandler + .thumb_set I2C1_IRQHandler,Default_Handler + + .weak SPI1_IRQHandler + .thumb_set SPI1_IRQHandler,Default_Handler + + .weak USART1_IRQHandler + .thumb_set USART1_IRQHandler,Default_Handler diff --git a/LCM/Library/LDScripts/hk32f030mf4p6.ld b/LCM/Library/LDScripts/hk32f030mf4p6.ld new file mode 100644 index 00000000..f619651d --- /dev/null +++ b/LCM/Library/LDScripts/hk32f030mf4p6.ld @@ -0,0 +1,163 @@ +/* +****************************************************************************** +** +** File : LinkerScript.ld +** +** Abstract : Linker script for HK32F030Mx series +** Set heap size, stack size and stack location according +** to application requirements. +** Set memory bank area and size if external memory is used. +** +** Distribution: The file is distributed 鈥渁s is,鈥 without any warranty +** of any kind. +** +***************************************************************************** +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of RAM */ +/* + Generate a link error if heap and stack don't fit into RAM. + These numbers affect the USED size of RAM +*/ +_Min_Heap_Size = 0x200; /* required amount of heap: 512 bytes */ +_Min_Stack_Size = 0x400; /* required amount of stack: 1024 bytes */ + +/* Specify the memory areas */ +MEMORY +{ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 4K + FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 16K + EEPROM (rx) : ORIGIN = 0x0C000000, LENGTH = 448 +} + +/* Define output sections */ +SECTIONS +{ + .eeprom : + { + . = ALIGN(4); + KEEP(*(.eeprom)) /* .eeprom section */ + . = ALIGN(4); + } >EEPROM + + /* The startup code goes first into FLASH */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data goes into FLASH */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data goes into FLASH */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH + .ARM : { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } >FLASH + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >FLASH + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } >FLASH + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >FLASH + + /* used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections goes into RAM, load LMA copy after code */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + } >RAM AT> FLASH + + + /* Uninitialized data section */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss secion */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough RAM left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + /* Remove information from the standard libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} + + diff --git a/LCM/Makefile b/LCM/Makefile new file mode 100644 index 00000000..6e1b33e1 --- /dev/null +++ b/LCM/Makefile @@ -0,0 +1,75 @@ +# Based on https://github.com/IOsetting/hk32f030m-template/blob/master/Makefile +##### Project ##### + +PROJECT ?= app +# The path for generated files +BUILD_DIR = Build + + +##### Options ##### + +# Enable printf float %f support, y:yes, n:no +ENABLE_PRINTF_FLOAT ?= n +# Build with FreeRTOS, y:yes, n:no +USE_FREERTOS ?= n +# Programmer, jlink or pyocd +FLASH_PROGRM ?= jlink + + +##### Toolchains ####### + +# path to gcc arm +# ARM_TOOCHAIN ?= /opt/gcc-arm/arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi/bin +# path to JLinkExe +JLINKEXE ?= /opt/SEGGER/JLink/JLinkExe +# JLink device type: HK32F030MD4P6, HK32F030MF4U6, HK32F030MF4P6 or HK32F030MJ4M6 +JLINK_DEVICE ?= HK32F030MF4P6 +# path to PyOCD +PYOCD_EXE ?= pyocd +# PyOCD device type: hk32f030md4p6, hk32f030mf4p6, hk32f030mf4u6, hk32f030mj4m6 +PYOCD_DEVICE ?= hk32f030mf4p6 + + +##### Paths ############ + +# Link descript file +LDSCRIPT = Library/LDScripts/hk32f030mf4p6.ld +# Library build flags +LIB_FLAGS = HK32F030MF4P6 + +# C source folders +CDIRS := Code/App \ + Code/Drive \ + Code/User \ + Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/CMSIS/HK32F030M/Source/GCC \ + Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/CMSIS/HK32F030M/Source \ + Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/HK32F030M_Lib/src/ + +# C source files (if there are any single ones) +CFILES := + +# ASM source folders +ADIRS := Code/User +# ASM single files +AFILES := Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/CMSIS/HK32F030M/Source/GCC/startup_hk32f030mf4p6.s + +# Include paths +INCLUDES := Code/App \ + Code/Drive \ + Code/User \ + Libraries/CMSIS/HK32F030M/Source/ \ + Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/CMSIS/HK32F030M/Include \ + Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/CMSIS/CM0/Core/ \ + Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/HK32F030M_Lib/inc + +ifeq ($(USE_FREERTOS),y) +CDIRS += Libraries/FreeRTOS \ + Libraries/FreeRTOS/portable/GCC/ARM_CM0 + +CFILES += Libraries/FreeRTOS/portable/MemMang/heap_4.c + +INCLUDES += Libraries/FreeRTOS/include \ + Libraries/FreeRTOS/portable/GCC/ARM_CM0 +endif + +include ./rules.mk diff --git a/LCM/Readme/Readme.txt b/LCM/Readme/Readme.txt deleted file mode 100644 index e4a77164..00000000 --- a/LCM/Readme/Readme.txt +++ /dev/null @@ -1,6 +0,0 @@ -This code is a continuation of the stock Floatwheel LCM (Light Control Module). This version offers added features. On the side off the LCM an expended messaging structure was added (to work in combination with the Comm bridge that was created in a custom Float Package). -EEPROM writes and reads, store settings on the LCM without having to flash again. This brings some features such as changing the preset lighting profiles, remembering which profile was last used, changing boot animation and cell type and more. - -TODO: -Include Float package buzzer support (let the vesc controll the buzzer). - diff --git a/LCM/rules.mk b/LCM/rules.mk new file mode 100644 index 00000000..047b80dd --- /dev/null +++ b/LCM/rules.mk @@ -0,0 +1,124 @@ +# 'make V=1' will show all compiler calls. +V ?= 0 +ifeq ($(V),0) +Q := @ +NULL := 2>/dev/null +endif + +ifdef ARM_TOOCHAIN +PREFIX ?= $(ARM_TOOCHAIN)/arm-none-eabi- +else +PREFIX = arm-none-eabi- +endif +CC = $(PREFIX)gcc +AS = $(PREFIX)as +LD = $(PREFIX)ld +OBJCOPY = $(PREFIX)objcopy +# `$(shell pwd)` or `.`, both works +TOP = . +BDIR = $(TOP)/$(BUILD_DIR) + +# For each direcotry, add it to csources +CSOURCES := $(foreach dir, $(CDIRS), $(shell find $(TOP)/$(dir) -maxdepth 1 -name '*.c')) +# Add single c source files to csources +CSOURCES += $(addprefix $(TOP)/, $(CFILES)) +# Then assembly source folders and files +ASOURCES := $(foreach dir, $(ADIRS), $(shell find $(TOP)/$(dir) -maxdepth 1 -name '*.s')) +ASOURCES += $(addprefix $(TOP)/, $(AFILES)) + +# Fill object files with c and asm files (keep source directory structure) +OBJS = $(CSOURCES:$(TOP)/%.c=$(BDIR)/%.o) +OBJS += $(ASOURCES:$(TOP)/%.s=$(BDIR)/%.o) +# d files for detecting h file changes +DEPS=$(CSOURCES:$(TOP)/%.c=$(BDIR)/%.d) + +# Arch and target specified flags +ARCH_FLAGS := -mthumb -mcpu=cortex-m0 -fno-common +# Debug options, -gdwarf-2 for debug, -g0 for release +# https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Debugging-Options.html +# -g: system鈥檚 native format, -g0:off, -g/g1,-g2,-g3 -> more verbosely +# -ggdb: for gdb, -ggdb0:off, -ggdb/ggdb1,-ggdb2,-ggdb3 -> more verbosely +# -gdwarf: in DWARF format, -gdwarf-2,-gdwarf-3,-gdwarf-4,-gdwarf-5 +DEBUG_FLAGS ?= -gdwarf-3 + +# c flags +OPT ?= -Os +CSTD ?= -std=c99 +TGT_CFLAGS += $(ARCH_FLAGS) $(DEBUG_FLAGS) $(OPT) $(CSTD) $(addprefix -D, $(LIB_FLAGS)) \ + -Wall -ffunction-sections -fdata-sections -ffreestanding -flto \ + -fsingle-precision-constant + +# asm flags +TGT_ASFLAGS += $(ARCH_FLAGS) $(DEBUG_FLAGS) $(OPT) -Wa,--warn + +# ld flags +TGT_LDFLAGS += $(ARCH_FLAGS) -specs=nano.specs -specs=nosys.specs -static -lc -lm \ + -Wl,-Map=$(BDIR)/$(PROJECT).map \ + -Wl,--gc-sections \ + -Wl,--print-memory-usage \ + -Wl,--cref +# Exclude standard initialization actions, when __libc_init_array exists, this should be omit, \ + otherwise it will generate "undefined reference to `_init'" error. \ + **Remove** `bl __libc_init_array` from startup.s if you want to enable this. +# TGT_LDFLAGS += -nostartfiles + +ifeq ($(ENABLE_PRINTF_FLOAT),y) +TGT_LDFLAGS += -u _printf_float +endif + +### included paths ### +TGT_INCFLAGS := $(addprefix -I $(TOP)/, $(INCLUDES)) + + +.PHONY: all clean flash echo + +all: $(BDIR)/$(PROJECT).elf $(BDIR)/$(PROJECT).bin $(BDIR)/$(PROJECT).hex + +# for debug +echo: + $(info 1. $(AFILES)) + $(info 2. $(ASOURCES)) + $(info 3. $(CSOURCES)) + $(info 4. $(OBJS)) + $(info 5. $(TGT_INCFLAGS)) + +# include d files without non-exist warning +-include $(DEPS) + +# Compile c to obj -- should be `$(BDIR)/%.o: $(TOP)/%.c`, but since $(TOP) is base folder so non-path also works +$(BDIR)/%.o: %.c + @printf " CC\t$<\n" + @mkdir -p $(dir $@) + $(Q)$(CC) $(TGT_CFLAGS) $(TGT_INCFLAGS) -o $@ -c $< -MD -MF $(BDIR)/$*.d -MP + +# Compile asm to obj +$(BDIR)/%.o: %.s + @printf " AS\t$<\n" + @mkdir -p $(dir $@) + $(Q)$(CC) $(TGT_ASFLAGS) -o $@ -c $< + +# Link object files to elf +$(BDIR)/$(PROJECT).elf: $(OBJS) $(TOP)/$(LDSCRIPT) + @printf " LD\t$@\n" + $(Q)$(CC) $(TGT_LDFLAGS) -T$(TOP)/$(LDSCRIPT) $(OBJS) -o $@ + +# Convert elf to bin +%.bin: %.elf + @printf " OBJCP BIN\t$@\n" + $(Q)$(OBJCOPY) -I elf32-littlearm -O binary $< $@ + +# Convert elf to hex +%.hex: %.elf + @printf " OBJCP HEX\t$@\n" + $(Q)$(OBJCOPY) -I elf32-littlearm -O ihex $< $@ + +clean: + rm -rf $(BDIR)/* + +flash: +ifeq ($(FLASH_PROGRM),jlink) + $(JLINKEXE) -device $(JLINK_DEVICE) -if swd -speed 4000 -JLinkScriptFile $(TOP)/Misc/jlink-script -CommanderScript $(TOP)/Misc/jlink-command +else ifeq ($(FLASH_PROGRM),pyocd) + $(PYOCD_EXE) erase -c -t $(PYOCD_DEVICE) --config $(TOP)/Misc/pyocd.yaml + $(PYOCD_EXE) load $(BDIR)/$(PROJECT).hex -t $(PYOCD_DEVICE) --config $(TOP)/Misc/pyocd.yaml +endif diff --git a/README.md b/README.md new file mode 100644 index 00000000..4f2d2d85 --- /dev/null +++ b/README.md @@ -0,0 +1,71 @@ +# Floatwheel Light Control Module + +This code is a continuation of the stock Floatwheel LCM (Light Control Module). This version offers added features. On the side off the LCM an expended messaging structure was added (to work in combination with the Comm bridge that was created in a custom Float Package). +EEPROM writes and reads, store settings on the LCM without having to flash again. This brings some features such as changing the preset lighting profiles, remembering which profile was last used, changing boot animation and cell type and more. + +TODO: +Include Float package buzzer support (let the vesc control the buzzer). + +## Building with GCC / Makefile (Linux) + +### Requirements + +* Programmer + * PyOCD: DAPLink, J-Link or ST-LINK +* PyOCD [https://pyocd.io/](https://pyocd.io/) +* GNU Arm Embedded Toolchain + +### Building + +#### 1. Install GNU Arm Embedded Toolchain + +On debian based systems simply use + +```bash +sudo apt install gcc-arm-none-eabi +``` + +or + +Download the toolchain from [Arm GNU Toolchain Downloads](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads) according to your pc architecture, extract the files + +```bash +cd ~/Downloads +curl https://developer.arm.com/-/media/Files/downloads/gnu/12.2.mpacbti-rel1/binrel/arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi.tar.xz -L -o arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi.tar.xz +tar xvf arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi.tar.xz +sudo mkdir -p /opt/gcc-arm +cd /opt/gcc-arm/ +sudo mv ~/Downloads/arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi/ . +sudo chown -R root:root arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi/ +``` + +add /opt/gcc-arm/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/bin to you `PATH` or define `ARM_TOOCHAIN` in `Makefile` + +#### 2. Install PyOCD + +Install from pip instead of apt repository because the version is 0.13.1+dfsg-1, which is too low to recognize J-Link probe + +```bash +pip install pyocd +``` + +#### 3. Clone This Repository + +Clone this repository to local workspace + +#### 4. Compiling And Flashing + +```bash +# clean source code +make clean +# build +make +# or make with verbose output +V=1 make +# flash +make flash +``` + +#### 5. Troubleshooting + +* Image is too big, make sure you are not using double functions From 98fac8edd1b26c6a2c9151fa48ff407b8bb15112 Mon Sep 17 00:00:00 2001 From: Floris Romeijn Date: Tue, 31 Oct 2023 21:16:17 +0100 Subject: [PATCH 2/4] fix build warnings --- LCM/Code/App/task.c | 1 - .../HK32F030M/HK32F030M_Lib/inc/hk32f030m_tim.h | 8 ++++---- .../HK32F030M/HK32F030M_Lib/src/hk32f030m_tim.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/LCM/Code/App/task.c b/LCM/Code/App/task.c index 8acf2db9..66f76ca1 100644 --- a/LCM/Code/App/task.c +++ b/LCM/Code/App/task.c @@ -100,7 +100,6 @@ void Power_Display(uint8_t brightness) **************************************************/ void WS2812_VESC(void) { - uint8_t i; uint8_t pos, red; uint8_t green = 0; uint8_t blue = WS2812_Measure; diff --git a/LCM/Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/HK32F030M_Lib/inc/hk32f030m_tim.h b/LCM/Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/HK32F030M_Lib/inc/hk32f030m_tim.h index 7f9bdaea..b03e4d17 100644 --- a/LCM/Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/HK32F030M_Lib/inc/hk32f030m_tim.h +++ b/LCM/Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/HK32F030M_Lib/inc/hk32f030m_tim.h @@ -951,13 +951,13 @@ void TIM_EncoderInterfaceConfig(TIM_TypeDef* TIMx, uint16_t TIM_EncoderMode, uint16_t TIM_IC1Polarity, uint16_t TIM_IC2Polarity); void TIM_SelectHallSensor(TIM_TypeDef* TIMx, FunctionalState NewState); -static void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, +void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, uint16_t TIM_ICFilter); -static void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, +void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, uint16_t TIM_ICFilter); -static void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, +void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, uint16_t TIM_ICFilter); -static void TI4_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, +void TI4_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, uint16_t TIM_ICFilter); diff --git a/LCM/Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/HK32F030M_Lib/src/hk32f030m_tim.c b/LCM/Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/HK32F030M_Lib/src/hk32f030m_tim.c index 987999eb..a003eaea 100644 --- a/LCM/Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/HK32F030M_Lib/src/hk32f030m_tim.c +++ b/LCM/Library/HK32F030Mxx_Library_V1.1.6/HK32F030M/HK32F030M_Lib/src/hk32f030m_tim.c @@ -30,13 +30,13 @@ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ -static void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, +void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, uint16_t TIM_ICFilter); -static void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, +void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, uint16_t TIM_ICFilter); -static void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, +void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, uint16_t TIM_ICFilter); -static void TI4_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, +void TI4_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, uint16_t TIM_ICFilter); /* Private functions ---------------------------------------------------------*/ @@ -2808,7 +2808,7 @@ void TIM_SelectHallSensor(TIM_TypeDef* TIMx, FunctionalState NewState) * This parameter must be a value between 0x00 and 0x0F. * @retval None */ -static void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, +void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, uint16_t TIM_ICFilter) { uint16_t tmpccmr1 = 0, tmpccer = 0; @@ -2844,7 +2844,7 @@ static void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ * This parameter must be a value between 0x00 and 0x0F. * @retval None */ -static void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, +void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, uint16_t TIM_ICFilter) { uint16_t tmpccmr1 = 0, tmpccer = 0, tmp = 0; @@ -2881,7 +2881,7 @@ static void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ * This parameter must be a value between 0x00 and 0x0F. * @retval None */ -static void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, +void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, uint16_t TIM_ICFilter) { uint16_t tmpccmr2 = 0, tmpccer = 0, tmp = 0; @@ -2917,7 +2917,7 @@ static void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ * This parameter must be a value between 0x00 and 0x0F. * @retval None */ -static void TI4_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, +void TI4_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, uint16_t TIM_ICFilter) { uint16_t tmpccmr2 = 0, tmpccer = 0, tmp = 0; From 48a464d6d1ab6a0b5c3a39da2d20503e5b354fa4 Mon Sep 17 00:00:00 2001 From: Floris Romeijn Date: Tue, 31 Oct 2023 21:50:59 +0100 Subject: [PATCH 3/4] make flash --- LCM/Makefile | 2 +- LCM/rules.mk | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LCM/Makefile b/LCM/Makefile index 6e1b33e1..9c1bae89 100644 --- a/LCM/Makefile +++ b/LCM/Makefile @@ -13,7 +13,7 @@ ENABLE_PRINTF_FLOAT ?= n # Build with FreeRTOS, y:yes, n:no USE_FREERTOS ?= n # Programmer, jlink or pyocd -FLASH_PROGRM ?= jlink +FLASH_PROGRM ?= pyocd ##### Toolchains ####### diff --git a/LCM/rules.mk b/LCM/rules.mk index 047b80dd..802a9dbc 100644 --- a/LCM/rules.mk +++ b/LCM/rules.mk @@ -119,6 +119,6 @@ flash: ifeq ($(FLASH_PROGRM),jlink) $(JLINKEXE) -device $(JLINK_DEVICE) -if swd -speed 4000 -JLinkScriptFile $(TOP)/Misc/jlink-script -CommanderScript $(TOP)/Misc/jlink-command else ifeq ($(FLASH_PROGRM),pyocd) - $(PYOCD_EXE) erase -c -t $(PYOCD_DEVICE) --config $(TOP)/Misc/pyocd.yaml - $(PYOCD_EXE) load $(BDIR)/$(PROJECT).hex -t $(PYOCD_DEVICE) --config $(TOP)/Misc/pyocd.yaml + $(PYOCD_EXE) erase -c -t $(PYOCD_DEVICE) --config $(TOP)/pyocd.yaml + $(PYOCD_EXE) load $(BDIR)/$(PROJECT).hex -t $(PYOCD_DEVICE) --config $(TOP)/pyocd.yaml endif From 0531b9f01d7c8823c409b36db06dde10654aff31 Mon Sep 17 00:00:00 2001 From: Floris Romeijn Date: Tue, 31 Oct 2023 22:01:20 +0100 Subject: [PATCH 4/4] fix encoding problem --- LCM/Code/App/task.c | 112 ++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/LCM/Code/App/task.c b/LCM/Code/App/task.c index 66f76ca1..e4866a9d 100644 --- a/LCM/Code/App/task.c +++ b/LCM/Code/App/task.c @@ -3,9 +3,9 @@ /************************************************** * @brie :LED_Task() - * @note :LED锟斤拷锟斤拷 - * @param :锟斤拷 - * @retval :锟斤拷 + * @note :LED任务 + * @param :无 + * @retval :无 **************************************************/ void LED_Task(void) { @@ -18,13 +18,13 @@ void LED_Task(void) /************************************************** * @brie :KEY1_Task() - * @note :KEY1锟斤拷锟斤拷 - * @param :锟斤拷 - * @retval :锟斤拷 + * @note :KEY1任务 + * @param :无 + * @retval :无 **************************************************/ void KEY1_Task(void) { - if(KEY1_State == 0 || Power_Flag == 3) //锟斤拷锟斤拷锟斤拷锟斤拷绨达拷锟斤拷锟斤拷锟斤拷锟斤拷锟 + if(KEY1_State == 0 || Power_Flag == 3) //充电器供电按键不起作用 { return; } @@ -248,9 +248,9 @@ void WS2812_Charge(void) /************************************************** * @brie :WS2812_Task() - * @note :WS2812锟斤拷锟斤拷 - * @param :锟斤拷 - * @retval :锟斤拷 + * @note :WS2812任务 + * @param :无 + * @retval :无 **************************************************/ void WS2812_Task(void) { @@ -305,15 +305,15 @@ void WS2812_Task(void) } else switch(Gear_Position) { - case 1: //1锟斤拷 + case 1: //1挡 WS2812_Measure = WS2812_1_BRIGHTNESS; break; - case 2: //2锟斤拷 + case 2: //2挡 WS2812_Measure = WS2812_2_BRIGHTNESS; break; - case 3: //3锟斤拷 + case 3: //3挡 WS2812_Measure = WS2812_3_BRIGHTNESS; break; @@ -343,13 +343,13 @@ void WS2812_Task(void) /************************************************** * @brie :Power_Task() - * @note :锟斤拷源锟斤拷锟斤拷 - * @param :锟斤拷 - * @retval :锟斤拷 + * @note :电源任务 + * @param :无 + * @retval :无 **************************************************/ void Power_Task(void) { - static uint8_t power_flag_last = 0; //锟斤拷一锟轿碉拷状态 + static uint8_t power_flag_last = 0; //上一次的状态 static uint8_t power_step = 0; if(power_flag_last == Power_Flag && Power_Flag != 1) @@ -360,7 +360,7 @@ void Power_Task(void) switch(Power_Flag) { - case 1://VESC锟斤拷锟斤拷 + case 1://VESC开机 PWR_ON; switch(power_step) { @@ -372,9 +372,9 @@ void Power_Task(void) case 1: if(Power_Time > VESC_BOOT_TIME) { - Power_Flag = 2; //锟斤拷锟斤拷锟斤拷锟 - Gear_Position = 1; //锟斤拷锟斤拷锟斤拷默锟斤拷锟斤拷1锟斤拷 - Buzzer_Flag = 2; //锟斤拷锟斤拷默锟较凤拷锟斤拷锟斤拷锟斤拷 + Power_Flag = 2; //开机完成 + Gear_Position = 1; //开机后默认是1挡 + Buzzer_Flag = 2; //开机默认蜂鸣器响 power_step = 0; } break; @@ -382,10 +382,10 @@ void Power_Task(void) break; - case 3://VESC锟截伙拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷庸锟斤拷锟 + case 3://VESC关机,充电器给板子供电 PWR_OFF; //LED1_Filp_Time(1000); - //Charge_Flag = 1; //准锟斤拷锟斤拷锟 + //Charge_Flag = 1; //准备充电 break; default: @@ -396,9 +396,9 @@ void Power_Task(void) /************************************************** * @brie :Charge_Task() - * @note :锟斤拷锟斤拷锟斤拷锟 - * @param :锟斤拷 - * @retval :锟斤拷 + * @note :充电任务 + * @param :无 + * @retval :无 **************************************************/ void Charge_Task(void) { @@ -417,14 +417,14 @@ void Charge_Task(void) break; case 1: - if(Charge_Time > 1000) //锟斤拷时1S + if(Charge_Time > 1000) //延时1S { charge_step = 2; } break; case 2: - CHARGE_ON; //锟津开筹拷锟斤拷锟 + CHARGE_ON; //打开充电器 Charge_Flag = 2; charge_step = 3; break; @@ -439,7 +439,7 @@ void Charge_Task(void) { V_I = 1; Charge_Time = 0; - LED1_ON; //锟缴硷拷锟斤拷锟斤拷压 + LED1_ON; //采集充电电压 charge_step = 5; } break; @@ -449,7 +449,7 @@ void Charge_Task(void) { V_I = 0; Charge_Time = 0; - LED1_OFF; //锟缴硷拷锟斤拷锟斤拷锟 + LED1_OFF; //采集充电流 charge_step = 4; } break; @@ -521,25 +521,25 @@ void Headlights_Task(void) /************************************************** * @brie :Buzzer_Task() - * @note :锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 - * @param :锟斤拷 - * @retval :锟斤拷 + * @note :蜂鸣器任务 + * @param :无 + * @retval :无 **************************************************/ void Buzzer_Task(void) { static uint8_t buzzer_step = 0; - static uint8_t gear_position_last = 0; //锟斤拷一锟轿的碉拷位 + static uint8_t gear_position_last = 0; //上一次的档位 static uint8_t ring_frequency = 0; static uint16_t sound_frequency = 0; - if(Power_Flag != 2 || Buzzer_Flag == 1) //VESC锟较碉拷锟斤拷锟斤拷锟斤拷锟截憋拷 + if(Power_Flag != 2 || Buzzer_Flag == 1) //VESC断电或蜂鸣器关闭 { BUZZER_OFF; buzzer_step = 0; return; } - if(Buzzer_Frequency == 0 && gear_position_last == Gear_Position) //锟斤拷锟斤拷锟斤拷锟斤拷锟狡碉拷锟轿0锟斤拷锟斤拷一锟轿的碉拷位锟斤拷锟斤拷锟斤拷蔚牡锟轿 + if(Buzzer_Frequency == 0 && gear_position_last == Gear_Position) //蜂鸣器响的频率为0或上一次的档位等于这次的档位 { BUZZER_OFF; buzzer_step = 0; @@ -610,9 +610,9 @@ void Buzzer_Task(void) /************************************************** * @brie :Usart_Task() - * @note :锟斤拷锟斤拷锟斤拷锟斤拷 - * @param :锟斤拷 - * @retval :锟斤拷 + * @note :串口任务 + * @param :无 + * @retval :无 **************************************************/ void Usart_Task(void) { @@ -661,16 +661,16 @@ void Usart_Task(void) VESC_RX_Flag = 0; result = Protocol_Parse(VESC_RX_Buff); - if(result == 0) //锟斤拷锟斤拷锟缴癸拷 + if(result == 0) //解析成功 { //LED1_Filp_Time(500); Usart_Flag = 1; -// Battery_Voltage = data.inpVoltage; //锟斤拷氐锟窖 -// VESC_Rpm = data.rpm; //转锟斤拷 -// AvgInputCurrent = data.avgInputCurrent; //母锟竭碉拷锟斤拷 -// DutyCycleNow = data.dutyCycleNow; //占锟秸憋拷 +// Battery_Voltage = data.inpVoltage; //电池电压 +// VESC_Rpm = data.rpm; //转速 +// AvgInputCurrent = data.avgInputCurrent; //母线电流 +// DutyCycleNow = data.dutyCycleNow; //占空比 } - else //锟斤拷锟斤拷失锟斤拷 + else //解析失败 { //LED1_Filp_Time(100); Usart_Flag = 2; @@ -713,9 +713,9 @@ void Usart_Task(void) //float k = 0.15; /************************************************** * @brie :ADC_Task() - * @note :ADC锟斤拷锟斤拷 - * @param :锟斤拷 - * @retval :锟斤拷 + * @note :ADC任务 + * @param :无 + * @retval :无 **************************************************/ void ADC_Task(void) { @@ -762,7 +762,7 @@ void ADC_Task(void) // V_I = 0; // Charge_Time = 0; // Sampling_Completion = 0; -// LED1_OFF; //锟缴硷拷锟斤拷锟斤拷锟 +// LED1_OFF; //采集充电流 // Charge_Voltage = (float)(adc_charge_sum_ave*0.0257080078125); // // } @@ -775,7 +775,7 @@ void ADC_Task(void) // // if(i == 10) // { -// LED1_ON; //锟缴硷拷锟斤拷锟窖 +// LED1_ON; //采集充电压 // Charge_Time = 0; // Sampling_Completion = 1; // V_I = 1; @@ -885,9 +885,9 @@ void CheckPowerLevel(float battery_voltage) /************************************************** * @brie :Conditional_Judgment() - * @note :锟斤拷锟斤拷锟叫讹拷 - * @param :锟斤拷 - * @retval :锟斤拷 + * @note :条件判断 + * @param :无 + * @retval :无 **************************************************/ void Conditional_Judgment(void) { @@ -997,8 +997,8 @@ void Conditional_Judgment(void) Charger_Detection_1ms = 0; } /* - 锟斤拷踏锟斤拷锟斤拷禄锟阶拷俅锟斤拷锟1000锟斤拷时锟斤拷锟斤拷 - 锟斤拷锟斤拷锟饺斤拷踏锟斤拷转锟劫碉拷锟斤拷1000锟斤拷始锟斤拷时锟斤拷锟斤拷锟斤拷锟截伙拷时锟斤拷鼗锟 + 脚踏板踩下或转速大于1000定时清零 + 即不踩脚踏板转速低于1000开始计时,超过关机时间关机 */ if(ADC1_Val > 2.9 || ADC2_Val > 2.9 || data.rpm > 1000) { @@ -1030,7 +1030,7 @@ void Conditional_Judgment(void) { // Charge_Flag = 3; Shutdown_Cnt = 0; - CHARGE_OFF; //锟截闭筹拷锟斤拷锟 + CHARGE_OFF; //关闭充电器 } } else