提交油温油位传感器的代码

This commit is contained in:
2025-04-12 09:51:25 +08:00
parent c464673b2f
commit 0a00aeda46
984 changed files with 421936 additions and 90 deletions
+55 -5
View File
@@ -1,4 +1,4 @@
/* USER CODE BEGIN Header */
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
@@ -21,7 +21,8 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "string.h"
#include "stdio.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@@ -32,11 +33,16 @@
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define DEV_ADDR 0x01
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
#define DUMP_HEX(__buf, __len) do {\
for (int __i = 0; __i < __len; ++__i) {printf("%02X ", (__buf)[__i]);} \
} while (0)
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
@@ -49,6 +55,8 @@ static uint16_t _gusUart1RxIndex = 0;
static uint8_t _gaucUart2RxBuf[100];
static uint16_t _gusUart2RxIndex = 0;
static uint32_t _gulUartRxTime = 0;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
@@ -63,18 +71,29 @@ static void MX_USART2_UART_Init(void);
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
int fputc(int ch, FILE *f)
{
uint8_t ucTmp;
// while (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_TXE) == 0);
ucTmp = (uint8_t)ch;
HAL_UART_Transmit(&huart1, &ucTmp, 1, 10);
return ch;
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == USART1) {
USART1->TDR = _gaucUart1RxBuf[0];
// USART1->TDR = _gaucUart1RxBuf[0];
HAL_UART_Receive_IT(huart, _gaucUart1RxBuf, 1);
} else if (huart->Instance == USART2) {
USART1->TDR = _gaucUart2RxBuf[_gusUart2RxIndex];
// USART1->TDR = _gaucUart2RxBuf[_gusUart2RxIndex];
++_gusUart2RxIndex;
if (_gusUart2RxIndex >= 100) {
_gusUart2RxIndex = 0;
}
HAL_UART_Receive_IT(huart, &_gaucUart2RxBuf[_gusUart2RxIndex], 1);
_gulUartRxTime = HAL_GetTick();
}
}
@@ -89,6 +108,23 @@ void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
}
}
void uart2DataHandler(uint8_t *pucBuf, int iLen)
{
// HAL_UART_Transmit_IT(&huart1, pucBuf, iLen);
printf("uart2 rx %d:\n", iLen);
DUMP_HEX(pucBuf, iLen);
printf("\n");
if (pucBuf[0] != DEV_ADDR) {
return;
}
if (pucBuf[1] == 0x7F) { // 消息递传功能码
HAL_UART_Transmit(&huart2, &pucBuf[2], iLen - 2, 100);
printf("retransmit msg done\n");
}
}
/* USER CODE END 0 */
/**
@@ -98,6 +134,8 @@ void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
int main(void)
{
/* USER CODE BEGIN 1 */
static uint8_t aucBuf[100];
int iTmp;
/* USER CODE END 1 */
@@ -123,7 +161,7 @@ int main(void)
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT(&huart1, _gaucUart1RxBuf, 1);
// HAL_UART_Receive_IT(&huart1, _gaucUart1RxBuf, 1);
HAL_UART_Receive_IT(&huart2, _gaucUart2RxBuf, 1);
/* USER CODE END 2 */
@@ -134,6 +172,17 @@ int main(void)
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if (_gusUart2RxIndex > 0) {
if (HAL_GetTick() > _gulUartRxTime + 2) {
memcpy(aucBuf, _gaucUart2RxBuf, _gusUart2RxIndex);
iTmp = _gusUart2RxIndex;
_gusUart2RxIndex = 0;
HAL_UART_AbortReceive_IT(&huart2);
HAL_UART_Receive_IT(&huart2, _gaucUart2RxBuf, 1);
uart2DataHandler(aucBuf, iTmp);
}
}
}
/* USER CODE END 3 */
}
@@ -321,3 +370,4 @@ void assert_failed(uint8_t *file, uint32_t line)
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
+1 -18
View File
@@ -148,24 +148,7 @@
<Name>-U32FF70063046593229502251 -O2254 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP") -D00(0BC11477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32G0xx_32.FLM -FS08000000 -FL08000 -FP0($$Device:STM32G030F6Px$CMSIS\Flash\STM32G0xx_32.FLM)</Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>68</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134222858</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>../Core/Src/main.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\CPY_PMU\../Core/Src/main.c\68</Expression>
</Bp>
</Breakpoint>
<Breakpoint/>
<Tracepoint>
<THDelay>0</THDelay>
</Tracepoint>
+1 -1
View File
@@ -189,7 +189,7 @@
<hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2>
<StupSel>8</StupSel>
<useUlib>0</useUlib>
<useUlib>1</useUlib>
<EndSel>0</EndSel>
<uLtcg>0</uLtcg>
<nSecure>0</nSecure>
+30 -60
View File
@@ -183,9 +183,9 @@ er
WEAK]
119 00000000 IMPORT __main
120 00000000 IMPORT SystemInit
121 00000000 4807 LDR R0, =SystemInit
121 00000000 4804 LDR R0, =SystemInit
122 00000002 4780 BLX R0
123 00000004 4807 LDR R0, =__main
123 00000004 4804 LDR R0, =__main
124 00000006 4700 BX R0
125 00000008 ENDP
126 00000008
@@ -322,42 +322,31 @@ ARM Macro Assembler Page 5
210 00000014 ;*******************************************************
************************
211 00000014 IF :DEF:__MICROLIB
218 00000014
212 00000014
ARM Macro Assembler Page 6
219 00000014 IMPORT __use_two_region_memory
220 00000014 EXPORT __user_initial_stackheap
221 00000014
222 00000014 __user_initial_stackheap
223 00000014
224 00000014 4804 LDR R0, = Heap_Mem
225 00000016 4905 LDR R1, =(Stack_Mem + Stack_Size)
226 00000018 4A05 LDR R2, = (Heap_Mem + Heap_Size)
227 0000001A 4B06 LDR R3, = Stack_Mem
228 0000001C 4770 BX LR
229 0000001E
230 0000001E 00 00 ALIGN
231 00000020
232 00000020 ENDIF
233 00000020
234 00000020 END
213 00000014 EXPORT __initial_sp
214 00000014 EXPORT __heap_base
215 00000014 EXPORT __heap_limit
216 00000014
217 00000014 ELSE
232 ENDIF
233 00000014
234 00000014 END
00000000
00000000
00000000
00000400
00000200
00000000
Command Line: --debug --xref --diag_suppress=9931 --cpu=Cortex-M0+ --apcs=inter
work --depend=cpy_pmu\startup_stm32g030xx.d -ocpy_pmu\startup_stm32g030xx.o -I.
\RTE\_CPY_PMU -IC:\Users\leon\AppData\Local\Arm\Packs\ARM\CMSIS\5.8.0\CMSIS\Cor
e\Include -IC:\Users\leon\AppData\Local\Arm\Packs\Keil\STM32G0xx_DFP\1.4.0\Driv
ers\CMSIS\Device\ST\STM32G0xx\Include --predefine="__UVISION_VERSION SETA 536"
--predefine="_RTE_ SETA 1" --predefine="STM32G030xx SETA 1" --predefine="_RTE_
SETA 1" --list=startup_stm32g030xx.lst startup_stm32g030xx.s
ers\CMSIS\Device\ST\STM32G0xx\Include --predefine="__MICROLIB SETA 1" --predefi
ne="__UVISION_VERSION SETA 536" --predefine="_RTE_ SETA 1" --predefine="STM32G0
30xx SETA 1" --predefine="_RTE_ SETA 1" --list=startup_stm32g030xx.lst startup_
stm32g030xx.s
@@ -378,9 +367,8 @@ Symbol: Stack_Mem
Definitions
At line 34 in file startup_stm32g030xx.s
Uses
At line 225 in file startup_stm32g030xx.s
At line 227 in file startup_stm32g030xx.s
None
Comment: Stack_Mem unused
__initial_sp 00000400
Symbol: __initial_sp
@@ -388,7 +376,8 @@ Symbol: __initial_sp
At line 35 in file startup_stm32g030xx.s
Uses
At line 59 in file startup_stm32g030xx.s
Comment: __initial_sp used once
At line 213 in file startup_stm32g030xx.s
3 symbols
@@ -410,25 +399,24 @@ Symbol: Heap_Mem
Definitions
At line 46 in file startup_stm32g030xx.s
Uses
At line 224 in file startup_stm32g030xx.s
At line 226 in file startup_stm32g030xx.s
None
Comment: Heap_Mem unused
__heap_base 00000000
Symbol: __heap_base
Definitions
At line 45 in file startup_stm32g030xx.s
Uses
None
Comment: __heap_base unused
At line 214 in file startup_stm32g030xx.s
Comment: __heap_base used once
__heap_limit 00000200
Symbol: __heap_limit
Definitions
At line 47 in file startup_stm32g030xx.s
Uses
None
Comment: __heap_limit unused
At line 215 in file startup_stm32g030xx.s
Comment: __heap_limit used once
4 symbols
@@ -770,15 +758,7 @@ Symbol: WWDG_IRQHandler
At line 77 in file startup_stm32g030xx.s
At line 153 in file startup_stm32g030xx.s
__user_initial_stackheap 00000014
Symbol: __user_initial_stackheap
Definitions
At line 222 in file startup_stm32g030xx.s
Uses
At line 220 in file startup_stm32g030xx.s
Comment: __user_initial_stackheap used once
32 symbols
31 symbols
@@ -792,8 +772,7 @@ Symbol: Heap_Size
At line 42 in file startup_stm32g030xx.s
Uses
At line 46 in file startup_stm32g030xx.s
At line 226 in file startup_stm32g030xx.s
Comment: Heap_Size used once
Stack_Size 00000400
Symbol: Stack_Size
@@ -801,8 +780,7 @@ Symbol: Stack_Size
At line 31 in file startup_stm32g030xx.s
Uses
At line 34 in file startup_stm32g030xx.s
At line 225 in file startup_stm32g030xx.s
Comment: Stack_Size used once
__Vectors_Size 000000C0
Symbol: __Vectors_Size
@@ -834,13 +812,5 @@ Symbol: __main
Uses
At line 123 in file startup_stm32g030xx.s
Comment: __main used once
__use_two_region_memory 00000000
Symbol: __use_two_region_memory
Definitions
At line 219 in file startup_stm32g030xx.s
Uses
None
Comment: __use_two_region_memory unused
3 symbols
385 symbols in table
2 symbols
382 symbols in table