diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 4949d91..ff72e7a 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -48,7 +48,7 @@ extern "C" { /* Exported macro ------------------------------------------------------------*/ /* USER CODE BEGIN EM */ -#define VERSION_STR "V1.0.0" +#define VERSION_STR "V1.1.0" #ifdef BOOTLOADER #define SW_VER "BL for " VERSION_STR #else diff --git a/Core/Src/main.c b/Core/Src/main.c index 453ee68..fbc1b6a 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -151,9 +151,9 @@ int main(void) { /* USER CODE BEGIN 1 */ -// #ifndef BOOTLOADER -// SCB->VTOR = 0x30000000; -// #endif +#ifndef BOOTLOADER + SCB->VTOR = 0x30000000; +#endif /* USER CODE END 1 */ /* MPU Configuration--------------------------------------------------------*/ @@ -542,7 +542,7 @@ static void MX_SPI1_Init(void) hspi1.Init.TIMode = SPI_TIMODE_DISABLE; hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; hspi1.Init.CRCPolynomial = 0x0; - hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE; + hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE; hspi1.Init.NSSPolarity = SPI_NSS_POLARITY_LOW; hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA; hspi1.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN; diff --git a/Drivers/User/CPY_PROT/cpy_prot.c b/Drivers/User/CPY_PROT/cpy_prot.c index cfc89db..9309ad6 100644 --- a/Drivers/User/CPY_PROT/cpy_prot.c +++ b/Drivers/User/CPY_PROT/cpy_prot.c @@ -4,6 +4,7 @@ #include "Param/param.h" #include "Filament/filament.h" #include "IAP/iap.h" +#include "OSU/osu.h" char gacVersionBuf[32]; @@ -40,7 +41,7 @@ static uint16_t crc16(const uint8_t *data, uint16_t len) { static int check_packet(cpy_prot_packet_t *packet) { if (packet->header != CPY_PROT_HEADER) { - printf("header error, 0x%04X\r\n", packet->header); + // printf("header error, 0x%04X\r\n", packet->header); return 0; } @@ -70,9 +71,9 @@ void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) void HAL_UARTEx_RxEventCallback_UART4(UART_HandleTypeDef *huart, uint16_t Size) { - if ((huart->Instance == huart4.Instance) && (huart->RxEventType == HAL_UART_RXEVENT_IDLE)) { + if ((huart->Instance == huart4.Instance && huart->RxEventType == HAL_UART_RXEVENT_IDLE)) { //SCB_InvalidateDCache_by_Addr((volatile void *)rx_packet_buf, Size); - printf("rx packet %d\r\n", Size); + // printf("rx packet %d\r\n", Size); // for (int i = 0; i < Size; i++) { // printf("%02X ", ((uint8_t *)rx_packet_buf)[i]); // } @@ -99,9 +100,7 @@ static int start_send(const char *data, size_t len) { } static int start_recv(char *data, size_t len) { - if (huart4.gState != HAL_UART_STATE_READY) { - HAL_UART_AbortReceive(&huart4); - } + HAL_UART_AbortReceive(&huart4); return HAL_UARTEx_ReceiveToIdle_DMA(&huart4, (uint8_t *)data, len); } @@ -141,13 +140,15 @@ int cpyProtPacketHandle(uint8_t cmd, const uint8_t *data, uint16_t len) { case CPY_PROT_CMD_HEARTBEAT: { extern uint16_t gusTempVal; - uint8_t aucRspData[13]; + uint8_t aucRspData[16]; *((uint32_t *)&aucRspData[0]) = osKernelGetTickCount(); *((uint16_t *)&aucRspData[4]) = gusTempVal; *((uint16_t *)&aucRspData[6]) = gusFilamentCurrent; *((uint16_t *)&aucRspData[8]) = gusFilamentVoltage; *((uint16_t *)&aucRspData[10]) = gusXrayCurrent; - aucRspData[12] = gucWorkState; + *((uint16_t *)&aucRspData[12]) = gusOsuTemp; + aucRspData[14] = gusOsuLevel; + aucRspData[15] = gucWorkState; cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, aucRspData, sizeof(aucRspData)); } break; diff --git a/Drivers/User/Filament/filament.c b/Drivers/User/Filament/filament.c index 09c019f..2e5debd 100644 --- a/Drivers/User/Filament/filament.c +++ b/Drivers/User/Filament/filament.c @@ -102,8 +102,6 @@ static void filamentThread(void *arg) HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t *)gausAdcBuf, ADC_CHNL_NUM); - debug("ADC_CHNL_NUM = %d\n", ADC_CHNL_NUM); - __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); @@ -125,8 +123,8 @@ static void filamentThread(void *arg) iWorkCmd = 3; if (gucWorkState == 1) { gucWorkState = 2; - if (gusNormalDuty == 0) { - gusNormalDuty = gusPreheatDuty * 2; + if (gusNormalDuty < gusPreheatDuty * 1.5 ) { + gusNormalDuty = gusPreheatDuty * 1.5; } gusDuty = gusNormalDuty; __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty); @@ -157,9 +155,11 @@ static void filamentThread(void *arg) continue; } iCnt = 0; - + + printf("\n"); + printf("\n"); printf("ADC: %d,%d,%d\n", gausAdcBuf[0], gausAdcBuf[1], gausAdcBuf[2]); - printf("duty:%d%%,I:%.3fA,V:%.2fV\n", gusDuty, gusFilamentCurrent/1000.0, gusFilamentVoltage/1000.0); + printf("workState:%d,duty:%d%%,I:%.3fA,V:%.2fV\n", gucWorkState, gusDuty * 100 / 2400, gusFilamentCurrent/1000.0, gusFilamentVoltage/1000.0); } } diff --git a/Drivers/User/OSU/osu.c b/Drivers/User/OSU/osu.c index 3d7019c..e68e304 100644 --- a/Drivers/User/OSU/osu.c +++ b/Drivers/User/OSU/osu.c @@ -2,6 +2,9 @@ #include "cmsis_os.h" #include "osu.h" +uint16_t gusOsuLevel = 0; +uint16_t gusOsuTemp = 0; + extern UART_HandleTypeDef huart3; static uint8_t gausRcvBuf[100]; static int rx_packet_ready = 0; @@ -39,6 +42,8 @@ static void osuDataProcess(void) { int level = gausRcvBuf[4]; int temp = gausRcvBuf[5] * 256 + gausRcvBuf[6]; printf("osu packet level, %d, temp, %.1f\r\n", level, temp / 10.0); + gusOsuLevel = level; + gusOsuTemp = temp; } void HAL_UARTEx_RxEventCallback_UART3(UART_HandleTypeDef *huart, uint16_t Size) diff --git a/Drivers/User/OSU/osu.h b/Drivers/User/OSU/osu.h index 9f99a0c..fea8c9c 100644 --- a/Drivers/User/OSU/osu.h +++ b/Drivers/User/OSU/osu.h @@ -6,6 +6,9 @@ #include "main.h" /* Exported types ------------------------------------------------------------*/ +extern uint16_t gusOsuLevel; +extern uint16_t gusOsuTemp; + void osuInit(void); diff --git a/Drivers/User/W25QXX/w25qxx.c b/Drivers/User/W25QXX/w25qxx.c index c16e136..389a403 100644 --- a/Drivers/User/W25QXX/w25qxx.c +++ b/Drivers/User/W25QXX/w25qxx.c @@ -22,7 +22,8 @@ static HAL_StatusTypeDef SPI_Transmit(uint8_t* send_buf, uint16_t size) */ static HAL_StatusTypeDef SPI_Receive(uint8_t* recv_buf, uint16_t size) { - return HAL_SPI_Receive(&hspi1, recv_buf, size, 100); + memset(recv_buf, 0xFF, size); + return HAL_SPI_TransmitReceive(&hspi1, recv_buf, recv_buf, size, 100); } @@ -135,10 +136,13 @@ AGAIN: { HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_SET); return 0; + } else { + debug("spi read data %d bytes failed:%d", nbytes, ret); } + } else { + debug("spi read cmd failed:%d", ret); } - debug("spi read failed:%d", ret); if (iCnt < 3) { iCnt++; goto AGAIN; diff --git a/MDK-ARM/bootloader.uvoptx b/MDK-ARM/bootloader.uvoptx index c670c20..f3d9652 100644 --- a/MDK-ARM/bootloader.uvoptx +++ b/MDK-ARM/bootloader.uvoptx @@ -248,7 +248,7 @@ 2 2 1 - 1 + 0 0 0 ../Core/Src/main.c @@ -588,6 +588,30 @@ 0 0 + + 3 + 30 + 1 + 0 + 0 + 0 + ..\Drivers\STM32H7xx_HAL_Driver\Src\stm32h7xx_hal_adc.c + stm32h7xx_hal_adc.c + 0 + 0 + + + 3 + 31 + 1 + 0 + 0 + 0 + ..\Drivers\STM32H7xx_HAL_Driver\Src\stm32h7xx_hal_adc_ex.c + stm32h7xx_hal_adc_ex.c + 0 + 0 + @@ -598,7 +622,7 @@ 0 4 - 30 + 32 1 0 0 @@ -618,7 +642,7 @@ 0 5 - 31 + 33 1 0 0 @@ -630,7 +654,7 @@ 5 - 32 + 34 1 0 0 @@ -642,7 +666,7 @@ 5 - 33 + 35 1 0 0 @@ -654,7 +678,7 @@ 5 - 34 + 36 1 0 0 @@ -666,7 +690,7 @@ 5 - 35 + 37 1 0 0 @@ -678,7 +702,7 @@ 5 - 36 + 38 1 0 0 @@ -690,7 +714,7 @@ 5 - 37 + 39 1 0 0 @@ -702,7 +726,7 @@ 5 - 38 + 40 1 0 0 @@ -714,7 +738,7 @@ 5 - 39 + 41 1 0 0 @@ -726,7 +750,7 @@ 5 - 40 + 42 1 0 0 @@ -746,7 +770,7 @@ 0 6 - 41 + 43 1 0 0 @@ -758,7 +782,7 @@ 6 - 42 + 44 1 0 0 @@ -770,7 +794,7 @@ 6 - 43 + 45 1 0 0 @@ -782,19 +806,7 @@ 6 - 44 - 1 - 0 - 0 - 0 - ..\Drivers\User\ADS8321\ads8321.c - ads8321.c - 0 - 0 - - - 6 - 45 + 46 1 0 0 @@ -804,6 +816,30 @@ 0 0 + + 6 + 47 + 1 + 0 + 0 + 0 + ..\Drivers\User\Filament\filament.c + filament.c + 0 + 0 + + + 6 + 48 + 1 + 0 + 0 + 0 + ..\Drivers\User\OSU\osu.c + osu.c + 0 + 0 + diff --git a/MDK-ARM/bootloader.uvprojx b/MDK-ARM/bootloader.uvprojx index 980d802..e249610 100644 --- a/MDK-ARM/bootloader.uvprojx +++ b/MDK-ARM/bootloader.uvprojx @@ -742,6 +742,16 @@ + + stm32h7xx_hal_adc.c + 1 + ..\Drivers\STM32H7xx_HAL_Driver\Src\stm32h7xx_hal_adc.c + + + stm32h7xx_hal_adc_ex.c + 1 + ..\Drivers\STM32H7xx_HAL_Driver\Src\stm32h7xx_hal_adc_ex.c + @@ -827,16 +837,21 @@ 1 ..\Drivers\User\Param\param.c - - ads8321.c - 1 - ..\Drivers\User\ADS8321\ads8321.c - cpy_prot.c 1 ..\Drivers\User\CPY_PROT\cpy_prot.c + + filament.c + 1 + ..\Drivers\User\Filament\filament.c + + + osu.c + 1 + ..\Drivers\User\OSU\osu.c + diff --git a/MDK-ARM/cpy_daq.uvprojx b/MDK-ARM/cpy_daq.uvprojx index 6f06d67..e04bc24 100644 --- a/MDK-ARM/cpy_daq.uvprojx +++ b/MDK-ARM/cpy_daq.uvprojx @@ -206,11 +206,11 @@ 0 0 1 - 1 + 0 0 0 0 - 1 + 0 1 @@ -275,8 +275,8 @@ 1 - 0x8000000 - 0x100000 + 0x30000000 + 0x20000 1 @@ -285,11 +285,11 @@ 0 - 0x30000000 - 0x48000 + 0x0 + 0x0 - 0 + 1 0x38000000 0x10000 diff --git a/cpy_daq.ioc b/cpy_daq.ioc index 5464fda..165f866 100644 --- a/cpy_daq.ioc +++ b/cpy_daq.ioc @@ -489,8 +489,9 @@ SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_16 SPI1.CalculateBaudRate=7.8125 MBits/s SPI1.DataSize=SPI_DATASIZE_8BIT SPI1.Direction=SPI_DIRECTION_2LINES -SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,BaudRatePrescaler +SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,BaudRatePrescaler,NSSPMode SPI1.Mode=SPI_MODE_MASTER +SPI1.NSSPMode=SPI_NSS_PULSE_DISABLE SPI1.VirtualType=VM_MASTER TIM1.BreakPolarity=TIM_BREAKPOLARITY_LOW TIM1.BreakState=TIM_BREAK_DISABLE