#define PD15_LORA_M1_GPIO_Port GPIOD
#define PC8_LORA_AUX_Pin GPIO_PIN_8
#define PC8_LORA_AUX_GPIO_Port GPIOC
+#define PA11_RS485_DIR1_Pin GPIO_PIN_11
+#define PA11_RS485_DIR1_GPIO_Port GPIOA
+#define PA12_CTL_POWER_Pin GPIO_PIN_12
+#define PA12_CTL_POWER_GPIO_Port GPIOA
#define LORA_RST_Pin GPIO_PIN_4
#define LORA_RST_GPIO_Port GPIOD
#define DM222_PAPWR_EN_Pin GPIO_PIN_7
#define DM222_PAPWR_EN_GPIO_Port GPIOD
#define FAN_EN_Pin GPIO_PIN_5
#define FAN_EN_GPIO_Port GPIOB
+#define PB6_EN_BEIDOU_PWN_Pin GPIO_PIN_6
+#define PB6_EN_BEIDOU_PWN_GPIO_Port GPIOB
+#define PB9_SPI2_NSS_Pin GPIO_PIN_9
+#define PB9_SPI2_NSS_GPIO_Port GPIOB
#define SYS_LED_Pin GPIO_PIN_1
#define SYS_LED_GPIO_Port GPIOE
/* #define HAL_SAI_MODULE_ENABLED */
/* #define HAL_SD_MODULE_ENABLED */
/* #define HAL_MMC_MODULE_ENABLED */
-/* #define HAL_SPI_MODULE_ENABLED */
+#define HAL_SPI_MODULE_ENABLED
#define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED
/* #define HAL_USART_MODULE_ENABLED */
void DebugMon_Handler(void);
void EXTI3_IRQHandler(void);
void TIM1_UP_TIM10_IRQHandler(void);
+void SPI2_IRQHandler(void);
void USART1_IRQHandler(void);
void USART2_IRQHandler(void);
void USART3_IRQHandler(void);
I2C_HandleTypeDef hi2c3;
+SPI_HandleTypeDef hspi2;
+
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim3;
static void MX_USART6_UART_Init(void);
static void MX_TIM2_Init(void);
static void MX_TIM3_Init(void);
+static void MX_SPI2_Init(void);
void main_task(void *argument);
/* USER CODE BEGIN PFP */
MX_USART6_UART_Init();
MX_TIM2_Init();
MX_TIM3_Init();
+ MX_SPI2_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
}
+/**
+ * @brief SPI2 Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_SPI2_Init(void)
+{
+
+ /* USER CODE BEGIN SPI2_Init 0 */
+
+ /* USER CODE END SPI2_Init 0 */
+
+ /* USER CODE BEGIN SPI2_Init 1 */
+
+ /* USER CODE END SPI2_Init 1 */
+ /* SPI2 parameter configuration*/
+ hspi2.Instance = SPI2;
+ hspi2.Init.Mode = SPI_MODE_MASTER;
+ hspi2.Init.Direction = SPI_DIRECTION_2LINES;
+ hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
+ hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
+ hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
+ hspi2.Init.NSS = SPI_NSS_SOFT;
+ hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
+ hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
+ hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
+ hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
+ hspi2.Init.CRCPolynomial = 10;
+ if (HAL_SPI_Init(&hspi2) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN SPI2_Init 2 */
+
+ /* USER CODE END SPI2_Init 2 */
+
+}
+
/**
* @brief TIM2 Initialization Function
* @param None
/* USER CODE END USART1_Init 1 */
huart1.Instance = USART1;
- huart1.Init.BaudRate = 1000000;
+ huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
HAL_GPIO_WritePin(GPIOD, LAKI_RESET_Pin|PD15_LORA_M1_Pin|LORA_RST_Pin, GPIO_PIN_SET);
/*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(FAN_EN_GPIO_Port, FAN_EN_Pin, GPIO_PIN_RESET);
+ HAL_GPIO_WritePin(GPIOA, PA11_RS485_DIR1_Pin|PA12_CTL_POWER_Pin, GPIO_PIN_RESET);
+
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(GPIOB, FAN_EN_Pin|PB6_EN_BEIDOU_PWN_Pin|PB9_SPI2_NSS_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(SYS_LED_GPIO_Port, SYS_LED_Pin, GPIO_PIN_RESET);
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(DQ_IN_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin : PA4_BEIDOU_RST_EN_Pin */
- GPIO_InitStruct.Pin = PA4_BEIDOU_RST_EN_Pin;
+ /*Configure GPIO pins : PA4_BEIDOU_RST_EN_Pin PA11_RS485_DIR1_Pin PA12_CTL_POWER_Pin */
+ GPIO_InitStruct.Pin = PA4_BEIDOU_RST_EN_Pin|PA11_RS485_DIR1_Pin|PA12_CTL_POWER_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(PA4_BEIDOU_RST_EN_GPIO_Port, &GPIO_InitStruct);
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PB14_RMII_INT_Pin */
GPIO_InitStruct.Pin = PB14_RMII_INT_Pin;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(PB14_RMII_INT_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pins : PB15_ETH_RESET_Pin FAN_EN_Pin */
- GPIO_InitStruct.Pin = PB15_ETH_RESET_Pin|FAN_EN_Pin;
+ /*Configure GPIO pins : PB15_ETH_RESET_Pin FAN_EN_Pin PB6_EN_BEIDOU_PWN_Pin PB9_SPI2_NSS_Pin */
+ GPIO_InitStruct.Pin = PB15_ETH_RESET_Pin|FAN_EN_Pin|PB6_EN_BEIDOU_PWN_Pin|PB9_SPI2_NSS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
}
+/**
+* @brief SPI MSP Initialization
+* This function configures the hardware resources used in this example
+* @param hspi: SPI handle pointer
+* @retval None
+*/
+void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
+{
+ GPIO_InitTypeDef GPIO_InitStruct = {0};
+ if(hspi->Instance==SPI2)
+ {
+ /* USER CODE BEGIN SPI2_MspInit 0 */
+
+ /* USER CODE END SPI2_MspInit 0 */
+ /* Peripheral clock enable */
+ __HAL_RCC_SPI2_CLK_ENABLE();
+
+ __HAL_RCC_GPIOC_CLK_ENABLE();
+ __HAL_RCC_GPIOB_CLK_ENABLE();
+ /**SPI2 GPIO Configuration
+ PC2 ------> SPI2_MISO
+ PC3 ------> SPI2_MOSI
+ PB10 ------> SPI2_SCK
+ */
+ GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+
+ GPIO_InitStruct.Pin = GPIO_PIN_10;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+ /* SPI2 interrupt Init */
+ HAL_NVIC_SetPriority(SPI2_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(SPI2_IRQn);
+ /* USER CODE BEGIN SPI2_MspInit 1 */
+
+ /* USER CODE END SPI2_MspInit 1 */
+ }
+
+}
+
+/**
+* @brief SPI MSP De-Initialization
+* This function freeze the hardware resources used in this example
+* @param hspi: SPI handle pointer
+* @retval None
+*/
+void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
+{
+ if(hspi->Instance==SPI2)
+ {
+ /* USER CODE BEGIN SPI2_MspDeInit 0 */
+
+ /* USER CODE END SPI2_MspDeInit 0 */
+ /* Peripheral clock disable */
+ __HAL_RCC_SPI2_CLK_DISABLE();
+
+ /**SPI2 GPIO Configuration
+ PC2 ------> SPI2_MISO
+ PC3 ------> SPI2_MOSI
+ PB10 ------> SPI2_SCK
+ */
+ HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2|GPIO_PIN_3);
+
+ HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10);
+
+ /* SPI2 interrupt DeInit */
+ HAL_NVIC_DisableIRQ(SPI2_IRQn);
+ /* USER CODE BEGIN SPI2_MspDeInit 1 */
+
+ /* USER CODE END SPI2_MspDeInit 1 */
+ }
+
+}
+
/**
* @brief TIM_Base MSP Initialization
* This function configures the hardware resources used in this example
/* External variables --------------------------------------------------------*/
extern ETH_HandleTypeDef heth;
extern DMA_HandleTypeDef hdma_adc1;
+extern SPI_HandleTypeDef hspi2;
extern UART_HandleTypeDef huart4;
extern UART_HandleTypeDef huart5;
extern UART_HandleTypeDef huart1;
/* USER CODE END TIM1_UP_TIM10_IRQn 1 */
}
+/**
+ * @brief This function handles SPI2 global interrupt.
+ */
+void SPI2_IRQHandler(void)
+{
+ /* USER CODE BEGIN SPI2_IRQn 0 */
+
+ /* USER CODE END SPI2_IRQn 0 */
+ HAL_SPI_IRQHandler(&hspi2);
+ /* USER CODE BEGIN SPI2_IRQn 1 */
+
+ /* USER CODE END SPI2_IRQn 1 */
+}
+
/**
* @brief This function handles USART1 global interrupt.
*/
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
-#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
+#define VECT_TAB_OFFSET 0x00020000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */
#endif /* USER_VECT_TAB_ADDRESS */
}
/* USER CODE BEGIN 4 */
-
+extern void user_eth_mac_get( uint8_t *mac );
/* USER CODE END 4 */
/*******************************************************************************
heth.Init.RxBuffLen = 1536;
/* USER CODE BEGIN MACADDRESS */
-
+ user_eth_mac_get(MACAddr);
/* USER CODE END MACADDRESS */
hal_eth_init_status = HAL_ETH_Init(&heth);
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd">
+
+ <SchemaVersion>2.1</SchemaVersion>
+
+ <Header>### uVision Project, (C) Keil Software</Header>
+
+ <Targets>
+ <Target>
+ <TargetName>bootloader</TargetName>
+ <ToolsetNumber>0x4</ToolsetNumber>
+ <ToolsetName>ARM-ADS</ToolsetName>
+ <pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
+ <uAC6>0</uAC6>
+ <TargetOption>
+ <TargetCommonOption>
+ <Device>STM32F407VETx</Device>
+ <Vendor>STMicroelectronics</Vendor>
+ <PackID>Keil.STM32F4xx_DFP.2.16.0</PackID>
+ <PackURL>http://www.keil.com/pack/</PackURL>
+ <Cpu>IRAM(0x20000000-0x2001BFFF) IRAM2(0x2001C000-0x2001FFFF) IROM(0x8000000-0x807FFFF) CLOCK(25000000) FPU2 CPUTYPE("Cortex-M4") TZ</Cpu>
+ <FlashUtilSpec></FlashUtilSpec>
+ <StartupFile></StartupFile>
+ <FlashDriverDll></FlashDriverDll>
+ <DeviceId>0</DeviceId>
+ <RegisterFile></RegisterFile>
+ <MemoryEnv></MemoryEnv>
+ <Cmp></Cmp>
+ <Asm></Asm>
+ <Linker></Linker>
+ <OHString></OHString>
+ <InfinionOptionDll></InfinionOptionDll>
+ <SLE66CMisc></SLE66CMisc>
+ <SLE66AMisc></SLE66AMisc>
+ <SLE66LinkerMisc></SLE66LinkerMisc>
+ <SFDFile>$$Device:STM32F407VETx$CMSIS\SVD\STM32F40x.svd</SFDFile>
+ <bCustSvd>0</bCustSvd>
+ <UseEnv>0</UseEnv>
+ <BinPath></BinPath>
+ <IncludePath></IncludePath>
+ <LibPath></LibPath>
+ <RegisterFilePath></RegisterFilePath>
+ <DBRegisterFilePath></DBRegisterFilePath>
+ <TargetStatus>
+ <Error>0</Error>
+ <ExitCodeStop>0</ExitCodeStop>
+ <ButtonStop>0</ButtonStop>
+ <NotGenerated>0</NotGenerated>
+ <InvalidFlash>1</InvalidFlash>
+ </TargetStatus>
+ <OutputDirectory>bootloader\</OutputDirectory>
+ <OutputName>bootloader</OutputName>
+ <CreateExecutable>1</CreateExecutable>
+ <CreateLib>0</CreateLib>
+ <CreateHexFile>1</CreateHexFile>
+ <DebugInformation>1</DebugInformation>
+ <BrowseInformation>1</BrowseInformation>
+ <ListingPath></ListingPath>
+ <HexFormatSelection>1</HexFormatSelection>
+ <Merge32K>0</Merge32K>
+ <CreateBatchFile>0</CreateBatchFile>
+ <BeforeCompile>
+ <RunUserProg1>0</RunUserProg1>
+ <RunUserProg2>0</RunUserProg2>
+ <UserProg1Name></UserProg1Name>
+ <UserProg2Name></UserProg2Name>
+ <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
+ <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
+ <nStopU1X>0</nStopU1X>
+ <nStopU2X>0</nStopU2X>
+ </BeforeCompile>
+ <BeforeMake>
+ <RunUserProg1>0</RunUserProg1>
+ <RunUserProg2>0</RunUserProg2>
+ <UserProg1Name></UserProg1Name>
+ <UserProg2Name></UserProg2Name>
+ <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
+ <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
+ <nStopB1X>0</nStopB1X>
+ <nStopB2X>0</nStopB2X>
+ </BeforeMake>
+ <AfterMake>
+ <RunUserProg1>1</RunUserProg1>
+ <RunUserProg2>0</RunUserProg2>
+ <UserProg1Name>fromelf --bin --output=$L@L.bin !L</UserProg1Name>
+ <UserProg2Name></UserProg2Name>
+ <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
+ <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
+ <nStopA1X>0</nStopA1X>
+ <nStopA2X>0</nStopA2X>
+ </AfterMake>
+ <SelectedForBatchBuild>1</SelectedForBatchBuild>
+ <SVCSIdString></SVCSIdString>
+ </TargetCommonOption>
+ <CommonProperty>
+ <UseCPPCompiler>0</UseCPPCompiler>
+ <RVCTCodeConst>0</RVCTCodeConst>
+ <RVCTZI>0</RVCTZI>
+ <RVCTOtherData>0</RVCTOtherData>
+ <ModuleSelection>0</ModuleSelection>
+ <IncludeInBuild>1</IncludeInBuild>
+ <AlwaysBuild>0</AlwaysBuild>
+ <GenerateAssemblyFile>0</GenerateAssemblyFile>
+ <AssembleAssemblyFile>0</AssembleAssemblyFile>
+ <PublicsOnly>0</PublicsOnly>
+ <StopOnExitCode>3</StopOnExitCode>
+ <CustomArgument></CustomArgument>
+ <IncludeLibraryModules></IncludeLibraryModules>
+ <ComprImg>0</ComprImg>
+ </CommonProperty>
+ <DllOption>
+ <SimDllName>SARMCM3.DLL</SimDllName>
+ <SimDllArguments>-REMAP -MPU</SimDllArguments>
+ <SimDlgDll>DCM.DLL</SimDlgDll>
+ <SimDlgDllArguments>-pCM4</SimDlgDllArguments>
+ <TargetDllName>SARMCM3.DLL</TargetDllName>
+ <TargetDllArguments>-MPU</TargetDllArguments>
+ <TargetDlgDll>TCM.DLL</TargetDlgDll>
+ <TargetDlgDllArguments>-pCM4</TargetDlgDllArguments>
+ </DllOption>
+ <DebugOption>
+ <OPTHX>
+ <HexSelection>1</HexSelection>
+ <HexRangeLowAddress>0</HexRangeLowAddress>
+ <HexRangeHighAddress>0</HexRangeHighAddress>
+ <HexOffset>0</HexOffset>
+ <Oh166RecLen>16</Oh166RecLen>
+ </OPTHX>
+ </DebugOption>
+ <Utilities>
+ <Flash1>
+ <UseTargetDll>1</UseTargetDll>
+ <UseExternalTool>0</UseExternalTool>
+ <RunIndependent>0</RunIndependent>
+ <UpdateFlashBeforeDebugging>1</UpdateFlashBeforeDebugging>
+ <Capability>1</Capability>
+ <DriverSelection>4101</DriverSelection>
+ </Flash1>
+ <bUseTDR>1</bUseTDR>
+ <Flash2>BIN\UL2CM3.DLL</Flash2>
+ <Flash3></Flash3>
+ <Flash4></Flash4>
+ <pFcarmOut></pFcarmOut>
+ <pFcarmGrp></pFcarmGrp>
+ <pFcArmRoot></pFcArmRoot>
+ <FcArmLst>0</FcArmLst>
+ </Utilities>
+ <TargetArmAds>
+ <ArmAdsMisc>
+ <GenerateListings>0</GenerateListings>
+ <asHll>1</asHll>
+ <asAsm>1</asAsm>
+ <asMacX>1</asMacX>
+ <asSyms>1</asSyms>
+ <asFals>1</asFals>
+ <asDbgD>1</asDbgD>
+ <asForm>1</asForm>
+ <ldLst>0</ldLst>
+ <ldmm>1</ldmm>
+ <ldXref>1</ldXref>
+ <BigEnd>0</BigEnd>
+ <AdsALst>1</AdsALst>
+ <AdsACrf>1</AdsACrf>
+ <AdsANop>0</AdsANop>
+ <AdsANot>0</AdsANot>
+ <AdsLLst>1</AdsLLst>
+ <AdsLmap>1</AdsLmap>
+ <AdsLcgr>1</AdsLcgr>
+ <AdsLsym>1</AdsLsym>
+ <AdsLszi>1</AdsLszi>
+ <AdsLtoi>1</AdsLtoi>
+ <AdsLsun>1</AdsLsun>
+ <AdsLven>1</AdsLven>
+ <AdsLsxf>1</AdsLsxf>
+ <RvctClst>0</RvctClst>
+ <GenPPlst>0</GenPPlst>
+ <AdsCpuType>"Cortex-M4"</AdsCpuType>
+ <RvctDeviceName></RvctDeviceName>
+ <mOS>0</mOS>
+ <uocRom>0</uocRom>
+ <uocRam>0</uocRam>
+ <hadIROM>1</hadIROM>
+ <hadIRAM>1</hadIRAM>
+ <hadXRAM>0</hadXRAM>
+ <uocXRam>0</uocXRam>
+ <RvdsVP>2</RvdsVP>
+ <RvdsMve>0</RvdsMve>
+ <RvdsCdeCp>0</RvdsCdeCp>
+ <hadIRAM2>1</hadIRAM2>
+ <hadIROM2>0</hadIROM2>
+ <StupSel>8</StupSel>
+ <useUlib>1</useUlib>
+ <EndSel>0</EndSel>
+ <uLtcg>0</uLtcg>
+ <nSecure>0</nSecure>
+ <RoSelD>3</RoSelD>
+ <RwSelD>4</RwSelD>
+ <CodeSel>0</CodeSel>
+ <OptFeed>0</OptFeed>
+ <NoZi1>0</NoZi1>
+ <NoZi2>0</NoZi2>
+ <NoZi3>0</NoZi3>
+ <NoZi4>0</NoZi4>
+ <NoZi5>0</NoZi5>
+ <Ro1Chk>0</Ro1Chk>
+ <Ro2Chk>0</Ro2Chk>
+ <Ro3Chk>0</Ro3Chk>
+ <Ir1Chk>1</Ir1Chk>
+ <Ir2Chk>0</Ir2Chk>
+ <Ra1Chk>0</Ra1Chk>
+ <Ra2Chk>0</Ra2Chk>
+ <Ra3Chk>0</Ra3Chk>
+ <Im1Chk>1</Im1Chk>
+ <Im2Chk>0</Im2Chk>
+ <OnChipMemories>
+ <Ocm1>
+ <Type>0</Type>
+ <StartAddress>0x0</StartAddress>
+ <Size>0x0</Size>
+ </Ocm1>
+ <Ocm2>
+ <Type>0</Type>
+ <StartAddress>0x0</StartAddress>
+ <Size>0x0</Size>
+ </Ocm2>
+ <Ocm3>
+ <Type>0</Type>
+ <StartAddress>0x0</StartAddress>
+ <Size>0x0</Size>
+ </Ocm3>
+ <Ocm4>
+ <Type>0</Type>
+ <StartAddress>0x0</StartAddress>
+ <Size>0x0</Size>
+ </Ocm4>
+ <Ocm5>
+ <Type>0</Type>
+ <StartAddress>0x0</StartAddress>
+ <Size>0x0</Size>
+ </Ocm5>
+ <Ocm6>
+ <Type>0</Type>
+ <StartAddress>0x0</StartAddress>
+ <Size>0x0</Size>
+ </Ocm6>
+ <IRAM>
+ <Type>0</Type>
+ <StartAddress>0x20000000</StartAddress>
+ <Size>0x1c000</Size>
+ </IRAM>
+ <IROM>
+ <Type>1</Type>
+ <StartAddress>0x8000000</StartAddress>
+ <Size>0x80000</Size>
+ </IROM>
+ <XRAM>
+ <Type>0</Type>
+ <StartAddress>0x0</StartAddress>
+ <Size>0x0</Size>
+ </XRAM>
+ <OCR_RVCT1>
+ <Type>1</Type>
+ <StartAddress>0x0</StartAddress>
+ <Size>0x0</Size>
+ </OCR_RVCT1>
+ <OCR_RVCT2>
+ <Type>1</Type>
+ <StartAddress>0x0</StartAddress>
+ <Size>0x0</Size>
+ </OCR_RVCT2>
+ <OCR_RVCT3>
+ <Type>1</Type>
+ <StartAddress>0x0</StartAddress>
+ <Size>0x0</Size>
+ </OCR_RVCT3>
+ <OCR_RVCT4>
+ <Type>1</Type>
+ <StartAddress>0x8000000</StartAddress>
+ <Size>0x8000</Size>
+ </OCR_RVCT4>
+ <OCR_RVCT5>
+ <Type>1</Type>
+ <StartAddress>0x0</StartAddress>
+ <Size>0x0</Size>
+ </OCR_RVCT5>
+ <OCR_RVCT6>
+ <Type>0</Type>
+ <StartAddress>0x10000000</StartAddress>
+ <Size>0x10000</Size>
+ </OCR_RVCT6>
+ <OCR_RVCT7>
+ <Type>0</Type>
+ <StartAddress>0x0</StartAddress>
+ <Size>0x0</Size>
+ </OCR_RVCT7>
+ <OCR_RVCT8>
+ <Type>0</Type>
+ <StartAddress>0x0</StartAddress>
+ <Size>0x0</Size>
+ </OCR_RVCT8>
+ <OCR_RVCT9>
+ <Type>0</Type>
+ <StartAddress>0x20000000</StartAddress>
+ <Size>0x1c000</Size>
+ </OCR_RVCT9>
+ <OCR_RVCT10>
+ <Type>0</Type>
+ <StartAddress>0x2001c000</StartAddress>
+ <Size>0x4000</Size>
+ </OCR_RVCT10>
+ </OnChipMemories>
+ <RvctStartVector></RvctStartVector>
+ </ArmAdsMisc>
+ <Cads>
+ <interw>1</interw>
+ <Optim>3</Optim>
+ <oTime>0</oTime>
+ <SplitLS>0</SplitLS>
+ <OneElfS>1</OneElfS>
+ <Strict>0</Strict>
+ <EnumInt>0</EnumInt>
+ <PlainCh>0</PlainCh>
+ <Ropi>0</Ropi>
+ <Rwpi>0</Rwpi>
+ <wLevel>2</wLevel>
+ <uThumb>0</uThumb>
+ <uSurpInc>0</uSurpInc>
+ <uC99>1</uC99>
+ <uGnu>0</uGnu>
+ <useXO>0</useXO>
+ <v6Lang>5</v6Lang>
+ <v6LangP>3</v6LangP>
+ <vShortEn>1</vShortEn>
+ <vShortWch>1</vShortWch>
+ <v6Lto>0</v6Lto>
+ <v6WtE>0</v6WtE>
+ <v6Rtti>0</v6Rtti>
+ <VariousControls>
+ <MiscControls></MiscControls>
+ <Define>USE_HAL_DRIVER,STM32F407xx,ARM_MATH_CM4,BOOTLOADER</Define>
+ <Undefine></Undefine>
+ <IncludePath>../Core/Inc;../LWIP/App;../LWIP/Target;../Middlewares/Third_Party/LwIP/src/include;../Middlewares/Third_Party/LwIP/system;../Drivers/STM32F4xx_HAL_Driver/Inc;../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy;../Middlewares/Third_Party/FreeRTOS/Source/include;../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2;../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F;../Drivers/BSP/Components/lan8742;../Middlewares/Third_Party/LwIP/src/include/netif/ppp;../Drivers/CMSIS/Device/ST/STM32F4xx/Include;../Middlewares/Third_Party/LwIP/src/include/lwip;../Middlewares/Third_Party/LwIP/src/include/lwip/apps;../Middlewares/Third_Party/LwIP/src/include/lwip/priv;../Middlewares/Third_Party/LwIP/src/include/lwip/prot;../Middlewares/Third_Party/LwIP/src/include/netif;../Middlewares/Third_Party/LwIP/src/include/compat/posix;../Middlewares/Third_Party/LwIP/src/include/compat/posix/arpa;../Middlewares/Third_Party/LwIP/src/include/compat/posix/net;../Middlewares/Third_Party/LwIP/src/include/compat/posix/sys;../Middlewares/Third_Party/LwIP/src/include/compat/stdc;../Middlewares/Third_Party/LwIP/system/arch;../Drivers/CMSIS/Include;../USB_DEVICE/App;../USB_DEVICE/Target;../Middlewares/ST/STM32_USB_Device_Library/Core/Inc;../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc;../user;../user_debug</IncludePath>
+ </VariousControls>
+ </Cads>
+ <Aads>
+ <interw>1</interw>
+ <Ropi>0</Ropi>
+ <Rwpi>0</Rwpi>
+ <thumb>0</thumb>
+ <SplitLS>0</SplitLS>
+ <SwStkChk>0</SwStkChk>
+ <NoWarn>0</NoWarn>
+ <uSurpInc>0</uSurpInc>
+ <useXO>0</useXO>
+ <ClangAsOpt>1</ClangAsOpt>
+ <VariousControls>
+ <MiscControls></MiscControls>
+ <Define>BOOTLOADER</Define>
+ <Undefine></Undefine>
+ <IncludePath>../Core/Inc</IncludePath>
+ </VariousControls>
+ </Aads>
+ <LDads>
+ <umfTarg>1</umfTarg>
+ <Ropi>0</Ropi>
+ <Rwpi>0</Rwpi>
+ <noStLib>0</noStLib>
+ <RepFail>1</RepFail>
+ <useFile>0</useFile>
+ <TextAddressRange></TextAddressRange>
+ <DataAddressRange></DataAddressRange>
+ <pXoBase></pXoBase>
+ <ScatterFile></ScatterFile>
+ <IncludeLibs></IncludeLibs>
+ <IncludeLibsPath></IncludeLibsPath>
+ <Misc></Misc>
+ <LinkerInputFile></LinkerInputFile>
+ <DisabledWarnings></DisabledWarnings>
+ </LDads>
+ </TargetArmAds>
+ </TargetOption>
+ <Groups>
+ <Group>
+ <GroupName>Application/MDK-ARM</GroupName>
+ <Files>
+ <File>
+ <FileName>startup_stm32f407xx.s</FileName>
+ <FileType>2</FileType>
+ <FilePath>startup_stm32f407xx.s</FilePath>
+ </File>
+ </Files>
+ </Group>
+ <Group>
+ <GroupName>Application/User/Core</GroupName>
+ <Files>
+ <File>
+ <FileName>freertos.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Core/Src/freertos.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_it.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Core/Src/stm32f4xx_it.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_msp.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Core/Src/stm32f4xx_hal_msp.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_timebase_tim.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Core/Src/stm32f4xx_hal_timebase_tim.c</FilePath>
+ </File>
+ </Files>
+ </Group>
+ <Group>
+ <GroupName>Drivers/STM32F4xx_HAL_Driver</GroupName>
+ <Files>
+ <File>
+ <FileName>stm32f4xx_hal_rcc.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_rcc_ex.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_flash.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_flash_ex.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_flash_ramfunc.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_gpio.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_dma_ex.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_dma.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_pwr.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_pwr_ex.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_cortex.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_exti.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_eth.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_eth.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_adc.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_adc_ex.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_ll_adc.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_adc.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_i2c.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_i2c_ex.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_spi.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c</FilePath>
+ <FileOption>
+ <CommonProperty>
+ <UseCPPCompiler>2</UseCPPCompiler>
+ <RVCTCodeConst>0</RVCTCodeConst>
+ <RVCTZI>0</RVCTZI>
+ <RVCTOtherData>0</RVCTOtherData>
+ <ModuleSelection>0</ModuleSelection>
+ <IncludeInBuild>1</IncludeInBuild>
+ <AlwaysBuild>2</AlwaysBuild>
+ <GenerateAssemblyFile>2</GenerateAssemblyFile>
+ <AssembleAssemblyFile>2</AssembleAssemblyFile>
+ <PublicsOnly>2</PublicsOnly>
+ <StopOnExitCode>11</StopOnExitCode>
+ <CustomArgument></CustomArgument>
+ <IncludeLibraryModules></IncludeLibraryModules>
+ <ComprImg>1</ComprImg>
+ </CommonProperty>
+ <FileArmAds>
+ <Cads>
+ <interw>2</interw>
+ <Optim>0</Optim>
+ <oTime>2</oTime>
+ <SplitLS>2</SplitLS>
+ <OneElfS>2</OneElfS>
+ <Strict>2</Strict>
+ <EnumInt>2</EnumInt>
+ <PlainCh>2</PlainCh>
+ <Ropi>2</Ropi>
+ <Rwpi>2</Rwpi>
+ <wLevel>0</wLevel>
+ <uThumb>2</uThumb>
+ <uSurpInc>2</uSurpInc>
+ <uC99>2</uC99>
+ <uGnu>2</uGnu>
+ <useXO>2</useXO>
+ <v6Lang>0</v6Lang>
+ <v6LangP>0</v6LangP>
+ <vShortEn>2</vShortEn>
+ <vShortWch>2</vShortWch>
+ <v6Lto>2</v6Lto>
+ <v6WtE>2</v6WtE>
+ <v6Rtti>2</v6Rtti>
+ <VariousControls>
+ <MiscControls></MiscControls>
+ <Define></Define>
+ <Undefine></Undefine>
+ <IncludePath></IncludePath>
+ </VariousControls>
+ </Cads>
+ </FileArmAds>
+ </FileOption>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_tim.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_tim_ex.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c</FilePath>
+ </File>
+ <File>
+ <FileName>stm32f4xx_hal_uart.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c</FilePath>
+ </File>
+ </Files>
+ </Group>
+ <Group>
+ <GroupName>Drivers/CMSIS</GroupName>
+ <Files>
+ <File>
+ <FileName>system_stm32f4xx.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Core/Src/system_stm32f4xx.c</FilePath>
+ </File>
+ </Files>
+ </Group>
+ <Group>
+ <GroupName>user</GroupName>
+ <Files>
+ <File>
+ <FileName>mbcrc.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>..\user\mbcrc.c</FilePath>
+ </File>
+ <File>
+ <FileName>user_nv.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>..\user\user_nv.c</FilePath>
+ </File>
+ <File>
+ <FileName>user_sflash.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>..\user\user_sflash.c</FilePath>
+ </File>
+ <File>
+ <FileName>bootloader_main.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>..\user\bootloader_main.c</FilePath>
+ </File>
+ </Files>
+ </Group>
+ <Group>
+ <GroupName>::CMSIS</GroupName>
+ </Group>
+ </Groups>
+ </Target>
+ </Targets>
+
+ <RTE>
+ <apis/>
+ <components>
+ <component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.5.0" condition="ARMv6_7_8-M Device">
+ <package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="5.8.0"/>
+ <targetInfos>
+ <targetInfo name="bootloader"/>
+ </targetInfos>
+ </component>
+ </components>
+ <files/>
+ </RTE>
+
+</Project>
</OCR_RVCT3>
<OCR_RVCT4>
<Type>1</Type>
- <StartAddress>0x8000000</StartAddress>
- <Size>0x80000</Size>
+ <StartAddress>0x8020000</StartAddress>
+ <Size>0x60000</Size>
</OCR_RVCT4>
<OCR_RVCT5>
<Type>1</Type>
<v6Rtti>0</v6Rtti>
<VariousControls>
<MiscControls></MiscControls>
- <Define>USE_HAL_DRIVER,STM32F407xx,ARM_MATH_CM4</Define>
+ <Define>USE_HAL_DRIVER,STM32F407xx,ARM_MATH_CM4,USER_VECT_TAB_ADDRESS</Define>
<Undefine></Undefine>
<IncludePath>../Core/Inc;../LWIP/App;../LWIP/Target;../Middlewares/Third_Party/LwIP/src/include;../Middlewares/Third_Party/LwIP/system;../Drivers/STM32F4xx_HAL_Driver/Inc;../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy;../Middlewares/Third_Party/FreeRTOS/Source/include;../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2;../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F;../Drivers/BSP/Components/lan8742;../Middlewares/Third_Party/LwIP/src/include/netif/ppp;../Drivers/CMSIS/Device/ST/STM32F4xx/Include;../Middlewares/Third_Party/LwIP/src/include/lwip;../Middlewares/Third_Party/LwIP/src/include/lwip/apps;../Middlewares/Third_Party/LwIP/src/include/lwip/priv;../Middlewares/Third_Party/LwIP/src/include/lwip/prot;../Middlewares/Third_Party/LwIP/src/include/netif;../Middlewares/Third_Party/LwIP/src/include/compat/posix;../Middlewares/Third_Party/LwIP/src/include/compat/posix/arpa;../Middlewares/Third_Party/LwIP/src/include/compat/posix/net;../Middlewares/Third_Party/LwIP/src/include/compat/posix/sys;../Middlewares/Third_Party/LwIP/src/include/compat/stdc;../Middlewares/Third_Party/LwIP/system/arch;../Drivers/CMSIS/Include;../USB_DEVICE/App;../USB_DEVICE/Target;../Middlewares/ST/STM32_USB_Device_Library/Core/Inc;../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc;../user;../user_debug</IncludePath>
</VariousControls>
<FileType>1</FileType>
<FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c</FilePath>
</File>
+ <File>
+ <FileName>stm32f4xx_hal_spi.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c</FilePath>
+ <FileOption>
+ <CommonProperty>
+ <UseCPPCompiler>2</UseCPPCompiler>
+ <RVCTCodeConst>0</RVCTCodeConst>
+ <RVCTZI>0</RVCTZI>
+ <RVCTOtherData>0</RVCTOtherData>
+ <ModuleSelection>0</ModuleSelection>
+ <IncludeInBuild>1</IncludeInBuild>
+ <AlwaysBuild>2</AlwaysBuild>
+ <GenerateAssemblyFile>2</GenerateAssemblyFile>
+ <AssembleAssemblyFile>2</AssembleAssemblyFile>
+ <PublicsOnly>2</PublicsOnly>
+ <StopOnExitCode>11</StopOnExitCode>
+ <CustomArgument></CustomArgument>
+ <IncludeLibraryModules></IncludeLibraryModules>
+ <ComprImg>1</ComprImg>
+ </CommonProperty>
+ <FileArmAds>
+ <Cads>
+ <interw>2</interw>
+ <Optim>0</Optim>
+ <oTime>2</oTime>
+ <SplitLS>2</SplitLS>
+ <OneElfS>2</OneElfS>
+ <Strict>2</Strict>
+ <EnumInt>2</EnumInt>
+ <PlainCh>2</PlainCh>
+ <Ropi>2</Ropi>
+ <Rwpi>2</Rwpi>
+ <wLevel>0</wLevel>
+ <uThumb>2</uThumb>
+ <uSurpInc>2</uSurpInc>
+ <uC99>2</uC99>
+ <uGnu>2</uGnu>
+ <useXO>2</useXO>
+ <v6Lang>0</v6Lang>
+ <v6LangP>0</v6LangP>
+ <vShortEn>2</vShortEn>
+ <vShortWch>2</vShortWch>
+ <v6Lto>2</v6Lto>
+ <v6WtE>2</v6WtE>
+ <v6Rtti>2</v6Rtti>
+ <VariousControls>
+ <MiscControls></MiscControls>
+ <Define></Define>
+ <Undefine></Undefine>
+ <IncludePath></IncludePath>
+ </VariousControls>
+ </Cads>
+ </FileArmAds>
+ </FileOption>
+ </File>
<File>
<FileName>stm32f4xx_hal_tim.c</FileName>
<FileType>1</FileType>
<FileType>1</FileType>
<FilePath>..\user\user_wind_sensor.c</FilePath>
</File>
+ <File>
+ <FileName>user_nv.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>..\user\user_nv.c</FilePath>
+ </File>
+ <File>
+ <FileName>user_sflash.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>..\user\user_sflash.c</FilePath>
+ </File>
+ <File>
+ <FileName>user_udp.c</FileName>
+ <FileType>1</FileType>
+ <FilePath>..\user\user_udp.c</FilePath>
+ </File>
</Files>
</Group>
<Group>
__Vectors_Size EQU __Vectors_End - __Vectors
+ IMPORT SW_VER
+ IMPORT |Region$$Table$$Limit|
+ IMPORT |Region$$Table$$Base|
+ ;ALIGN 0x200
+ SPACE 0x200 - __Vectors_Size ;ALIGN 0x200
+ IF :DEF:BOOTLOADER
+ DCD 0x544F4F42 ; 'BOOT'
+ ELSE
+ DCD 0x00505041 ; 'APP\0'
+ ENDIF
+SW_VER_ADDR
+ DCD SW_VER
+ DCD |Region$$Table$$Base|
+ DCD |Region$$Table$$Limit|
+ DCD __Vectors
+ SPACE 44
AREA |.text|, CODE, READONLY
; Reset handler
Mcu.Family=STM32F4
Mcu.IP0=ADC1
Mcu.IP1=DMA
-Mcu.IP10=TIM3
-Mcu.IP11=UART4
-Mcu.IP12=UART5
-Mcu.IP13=USART1
-Mcu.IP14=USART2
-Mcu.IP15=USART3
-Mcu.IP16=USART6
+Mcu.IP10=TIM2
+Mcu.IP11=TIM3
+Mcu.IP12=UART4
+Mcu.IP13=UART5
+Mcu.IP14=USART1
+Mcu.IP15=USART2
+Mcu.IP16=USART3
+Mcu.IP17=USART6
Mcu.IP2=ETH
Mcu.IP3=FREERTOS
Mcu.IP4=I2C3
Mcu.IP5=LWIP
Mcu.IP6=NVIC
Mcu.IP7=RCC
-Mcu.IP8=SYS
-Mcu.IP9=TIM2
-Mcu.IPNb=17
+Mcu.IP8=SPI2
+Mcu.IP9=SYS
+Mcu.IPNb=18
Mcu.Name=STM32F407V(E-G)Tx
Mcu.Package=LQFP100
Mcu.Pin0=PE3
Mcu.Pin1=PC14-OSC32_IN
-Mcu.Pin10=PA6
-Mcu.Pin11=PA7
-Mcu.Pin12=PC4
-Mcu.Pin13=PC5
-Mcu.Pin14=PB11
-Mcu.Pin15=PB12
-Mcu.Pin16=PB13
-Mcu.Pin17=PB14
-Mcu.Pin18=PB15
-Mcu.Pin19=PD8
+Mcu.Pin10=PA4
+Mcu.Pin11=PA5
+Mcu.Pin12=PA6
+Mcu.Pin13=PA7
+Mcu.Pin14=PC4
+Mcu.Pin15=PC5
+Mcu.Pin16=PB10
+Mcu.Pin17=PB11
+Mcu.Pin18=PB12
+Mcu.Pin19=PB13
Mcu.Pin2=PC15-OSC32_OUT
-Mcu.Pin20=PD9
-Mcu.Pin21=PD10
-Mcu.Pin22=PD11
-Mcu.Pin23=PD12
-Mcu.Pin24=PD13
-Mcu.Pin25=PD14
-Mcu.Pin26=PD15
-Mcu.Pin27=PC6
-Mcu.Pin28=PC7
-Mcu.Pin29=PC8
+Mcu.Pin20=PB14
+Mcu.Pin21=PB15
+Mcu.Pin22=PD8
+Mcu.Pin23=PD9
+Mcu.Pin24=PD10
+Mcu.Pin25=PD11
+Mcu.Pin26=PD12
+Mcu.Pin27=PD13
+Mcu.Pin28=PD14
+Mcu.Pin29=PD15
Mcu.Pin3=PH0-OSC_IN
-Mcu.Pin30=PC9
-Mcu.Pin31=PA8
-Mcu.Pin32=PA9
-Mcu.Pin33=PA10
-Mcu.Pin34=PA13
-Mcu.Pin35=PA14
-Mcu.Pin36=PC10
-Mcu.Pin37=PC11
-Mcu.Pin38=PC12
-Mcu.Pin39=PD2
+Mcu.Pin30=PC6
+Mcu.Pin31=PC7
+Mcu.Pin32=PC8
+Mcu.Pin33=PC9
+Mcu.Pin34=PA8
+Mcu.Pin35=PA9
+Mcu.Pin36=PA10
+Mcu.Pin37=PA11
+Mcu.Pin38=PA12
+Mcu.Pin39=PA13
Mcu.Pin4=PH1-OSC_OUT
-Mcu.Pin40=PD4
-Mcu.Pin41=PD5
-Mcu.Pin42=PD6
-Mcu.Pin43=PD7
-Mcu.Pin44=PB5
-Mcu.Pin45=PE1
-Mcu.Pin46=VP_FREERTOS_VS_CMSIS_V2
-Mcu.Pin47=VP_LWIP_VS_Enabled
-Mcu.Pin48=VP_SYS_VS_tim1
-Mcu.Pin49=VP_TIM2_VS_ClockSourceINT
+Mcu.Pin40=PA14
+Mcu.Pin41=PC10
+Mcu.Pin42=PC11
+Mcu.Pin43=PC12
+Mcu.Pin44=PD2
+Mcu.Pin45=PD4
+Mcu.Pin46=PD5
+Mcu.Pin47=PD6
+Mcu.Pin48=PD7
+Mcu.Pin49=PB5
Mcu.Pin5=PC1
-Mcu.Pin50=VP_TIM3_VS_ClockSourceINT
-Mcu.Pin6=PA1
-Mcu.Pin7=PA2
-Mcu.Pin8=PA4
-Mcu.Pin9=PA5
-Mcu.PinsNb=51
+Mcu.Pin50=PB6
+Mcu.Pin51=PB9
+Mcu.Pin52=PE1
+Mcu.Pin53=VP_FREERTOS_VS_CMSIS_V2
+Mcu.Pin54=VP_LWIP_VS_Enabled
+Mcu.Pin55=VP_SYS_VS_tim1
+Mcu.Pin56=VP_TIM2_VS_ClockSourceINT
+Mcu.Pin57=VP_TIM3_VS_ClockSourceINT
+Mcu.Pin6=PC2
+Mcu.Pin7=PC3
+Mcu.Pin8=PA1
+Mcu.Pin9=PA2
+Mcu.PinsNb=58
Mcu.ThirdParty0=STMicroelectronics.X-CUBE-ALGOBUILD.1.3.0
Mcu.ThirdPartyNb=1
Mcu.UserConstants=
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
NVIC.PendSV_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:false\:false
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
+NVIC.SPI2_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false\:false
NVIC.SavedPendsvIrqHandlerGenerated=true
NVIC.SavedSvcallIrqHandlerGenerated=true
PA10.Locked=true
PA10.Mode=Asynchronous
PA10.Signal=USART1_RX
+PA11.GPIOParameters=GPIO_Label
+PA11.GPIO_Label=PA11_RS485_DIR1
+PA11.Locked=true
+PA11.Signal=GPIO_Output
+PA12.GPIOParameters=GPIO_Label
+PA12.GPIO_Label=PA12_CTL_POWER
+PA12.Locked=true
+PA12.Signal=GPIO_Output
PA13.Locked=true
PA13.Mode=Serial_Wire
PA13.Signal=SYS_JTMS-SWDIO
PA9.Locked=true
PA9.Mode=Asynchronous
PA9.Signal=USART1_TX
+PB10.Locked=true
+PB10.Mode=Full_Duplex_Master
+PB10.Signal=SPI2_SCK
PB11.Mode=RMII
PB11.Signal=ETH_TX_EN
PB12.Mode=RMII
PB5.GPIO_Label=FAN_EN
PB5.Locked=true
PB5.Signal=GPIO_Output
+PB6.GPIOParameters=GPIO_Label
+PB6.GPIO_Label=PB6_EN_BEIDOU_PWN
+PB6.Locked=true
+PB6.Signal=GPIO_Output
+PB9.GPIOParameters=GPIO_Label
+PB9.GPIO_Label=PB9_SPI2_NSS
+PB9.Locked=true
+PB9.Signal=GPIO_Output
PC1.Mode=RMII
PC1.Signal=ETH_MDC
PC10.Locked=true
PC15-OSC32_OUT.Locked=true
PC15-OSC32_OUT.Mode=LSE-External-Oscillator
PC15-OSC32_OUT.Signal=RCC_OSC32_OUT
+PC2.Locked=true
+PC2.Mode=Full_Duplex_Master
+PC2.Signal=SPI2_MISO
+PC3.Locked=true
+PC3.Mode=Full_Duplex_Master
+PC3.Signal=SPI2_MOSI
PC4.Mode=RMII
PC4.Signal=ETH_RXD0
PC5.Mode=RMII
ProjectManager.HalAssertFull=false
ProjectManager.HeapSize=0x200
ProjectManager.KeepUserCode=true
-ProjectManager.LastFirmware=true
+ProjectManager.LastFirmware=false
ProjectManager.LibraryCopy=0
ProjectManager.MainLocation=Core/Src
ProjectManager.NoMain=false
SH.GPXTI14.ConfNb=1
SH.GPXTI3.0=GPIO_EXTI3
SH.GPXTI3.ConfNb=1
+SPI2.CLKPhase=SPI_PHASE_1EDGE
+SPI2.CLKPolarity=SPI_POLARITY_LOW
+SPI2.CalculateBaudRate=21.0 MBits/s
+SPI2.Direction=SPI_DIRECTION_2LINES
+SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,CLKPolarity,CLKPhase
+SPI2.Mode=SPI_MODE_MASTER
+SPI2.VirtualType=VM_MASTER
STMicroelectronics.X-CUBE-ALGOBUILD.1.3.0_SwParameter=LibraryCcDSPOoLibraryJjDSPOoLibrary\:true;
TIM2.IPParameters=TIM_MasterOutputTrigger,Prescaler,Period
TIM2.Period=100
--- /dev/null
+/**
+ ******************************************************************************
+ * @file Templates/Src/main.c
+ * @author MCD Application Team
+ * @version V1.0.2
+ * @date 13-November-2015
+ * @brief Main program body
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "main.h"
+#include "cmsis_os.h"
+
+/* Private includes ----------------------------------------------------------*/
+/* USER CODE BEGIN Includes */
+#include "user.h"
+#include "user_sflash.h"
+
+#define BOOT_VERSION "V2.0.0"
+
+#define SFLASH_IMAGE_BASE 0x000000 //addr in spiflash, offset:0M
+#define APP_IMAGE_ADDR 0x08020000
+
+enum{
+ IMG_BOOT = 0x544F4F42, //"BOOT"
+ IMG_APP = 0x00505041, //"APP\0"
+};
+
+typedef struct {
+ uint32_t sign;
+ uint32_t addr;
+ uint32_t sz;
+ uint32_t crc16;
+ uint32_t reserve[12];
+}image_header_t;
+
+const char SW_VER[]= BOOT_VERSION ;
+static image_header_t img_hdr;
+static void go( uint32_t entry, uint32_t sp );
+
+static uint8_t buf[5000];
+
+extern uint32_t flash_write( uint32_t addr, uint8_t *data, uint32_t sz );
+extern uint32_t flash_erase( uint32_t addr, uint32_t sz );
+extern uint32_t sFLASH_crc16( uint32_t addr, uint32_t sz );
+
+//-------------------------------------------------------------------------------------------------------------------
+/* USER CODE BEGIN Header */
+/**
+ ******************************************************************************
+ * @file : main.c
+ * @brief : Main program body
+ ******************************************************************************
+ * @attention
+ *
+ * Copyright (c) 2025 STMicroelectronics.
+ * All rights reserved.
+ *
+ * This software is licensed under terms that can be found in the LICENSE file
+ * in the root directory of this software component.
+ * If no LICENSE file comes with this software, it is provided AS-IS.
+ *
+ ******************************************************************************
+ */
+/* USER CODE END Header */
+/* Includes ------------------------------------------------------------------*/
+#include "main.h"
+#include "cmsis_os.h"
+
+ADC_HandleTypeDef hadc1;
+DMA_HandleTypeDef hdma_adc1;
+
+I2C_HandleTypeDef hi2c3;
+
+SPI_HandleTypeDef hspi2;
+
+TIM_HandleTypeDef htim2;
+TIM_HandleTypeDef htim3;
+
+UART_HandleTypeDef huart4;
+UART_HandleTypeDef huart5;
+UART_HandleTypeDef huart1;
+UART_HandleTypeDef huart2;
+UART_HandleTypeDef huart3;
+UART_HandleTypeDef huart6;
+ETH_HandleTypeDef heth;
+/* Definitions for defaultTask */
+osThreadId_t defaultTaskHandle;
+const osThreadAttr_t defaultTask_attributes = {
+ .name = "defaultTask",
+ .stack_size = 512 * 4,
+ .priority = (osPriority_t) osPriorityNormal,
+};
+/* USER CODE BEGIN PV */
+
+/* USER CODE END PV */
+
+/* Private function prototypes -----------------------------------------------*/
+void SystemClock_Config(void);
+static void MX_GPIO_Init(void);
+static void MX_DMA_Init(void);
+static void MX_ADC1_Init(void);
+static void MX_I2C3_Init(void);
+static void MX_UART4_Init(void);
+static void MX_UART5_Init(void);
+static void MX_USART1_UART_Init(void);
+static void MX_USART2_UART_Init(void);
+static void MX_USART3_UART_Init(void);
+static void MX_USART6_UART_Init(void);
+static void MX_TIM2_Init(void);
+static void MX_TIM3_Init(void);
+static void MX_SPI2_Init(void);
+
+int32_t found_ota_image( void );
+int32_t update_ota_image( void );
+
+/* USER CODE BEGIN PFP */
+
+/* USER CODE END PFP */
+
+/* Private user code ---------------------------------------------------------*/
+/* USER CODE BEGIN 0 */
+
+/* USER CODE END 0 */
+
+/**
+ * @brief The application entry point.
+ * @retval int
+ */
+int main(void)
+{
+ /* USER CODE BEGIN 1 */
+
+ /* USER CODE END 1 */
+
+ /* MCU Configuration--------------------------------------------------------*/
+
+ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
+ HAL_Init();
+
+ /* USER CODE BEGIN Init */
+
+ /* USER CODE END Init */
+
+ /* Configure the system clock */
+ SystemClock_Config();
+
+ /* USER CODE BEGIN SysInit */
+
+ /* USER CODE END SysInit */
+
+ /* Initialize all configured peripherals */
+ MX_GPIO_Init();
+ MX_DMA_Init();
+ MX_ADC1_Init();
+ MX_I2C3_Init();
+ MX_UART4_Init();
+ MX_UART5_Init();
+ MX_USART1_UART_Init();
+ MX_USART2_UART_Init();
+ MX_USART3_UART_Init();
+ MX_USART6_UART_Init();
+ MX_TIM2_Init();
+ MX_TIM3_Init();
+ MX_SPI2_Init();
+
+ uint32_t entry;
+ uint32_t app_sp;
+
+ printf( "bootloader, ver:%s\n", SW_VER );
+ if( sFLASH_Init() == 0 ){
+ //检查升级文件
+ if( found_ota_image() == 0 ){
+ for( int i=0; i<3; i++ ){
+ //执行升级
+ if( update_ota_image()== 0 ){
+ break;
+ }else{
+ printf( "update image fail[%d]!\n", i );
+ }
+ }
+ }
+ }
+
+ entry = 0;
+ if( *(uint32_t*)(APP_IMAGE_ADDR+0x200) == 0x00505041 )
+ entry = *(uint32_t*)(APP_IMAGE_ADDR+4);
+
+ if( entry > APP_IMAGE_ADDR && entry < APP_IMAGE_ADDR + 0x100000 ){
+ app_sp = *(uint32_t*)(APP_IMAGE_ADDR);
+ go( entry, app_sp );
+ }
+ while (1)
+ {
+ /* USER CODE END WHILE */
+
+ /* USER CODE BEGIN 3 */
+ }
+ /* USER CODE END 3 */
+}
+
+/**
+ * @brief System Clock Configuration
+ * @retval None
+ */
+void SystemClock_Config(void)
+{
+ RCC_OscInitTypeDef RCC_OscInitStruct = {0};
+ RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
+
+ /** Configure the main internal regulator output voltage
+ */
+ __HAL_RCC_PWR_CLK_ENABLE();
+ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
+
+ /** Initializes the RCC Oscillators according to the specified parameters
+ * in the RCC_OscInitTypeDef structure.
+ */
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
+ RCC_OscInitStruct.HSEState = RCC_HSE_ON;
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+ RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
+ RCC_OscInitStruct.PLL.PLLM = 8;
+ RCC_OscInitStruct.PLL.PLLN = 336;
+ RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
+ RCC_OscInitStruct.PLL.PLLQ = 7;
+ if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
+ {
+ Error_Handler();
+ }
+
+ /** Initializes the CPU, AHB and APB buses clocks
+ */
+ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
+ |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
+ RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+ RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
+ RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
+
+ if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
+ {
+ Error_Handler();
+ }
+}
+
+/**
+ * @brief ADC1 Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_ADC1_Init(void)
+{
+
+ /* USER CODE BEGIN ADC1_Init 0 */
+
+ /* USER CODE END ADC1_Init 0 */
+
+ ADC_ChannelConfTypeDef sConfig = {0};
+
+ /* USER CODE BEGIN ADC1_Init 1 */
+
+ /* USER CODE END ADC1_Init 1 */
+
+ /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
+ */
+ hadc1.Instance = ADC1;
+ hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
+ hadc1.Init.Resolution = ADC_RESOLUTION_12B;
+ hadc1.Init.ScanConvMode = DISABLE;
+ hadc1.Init.ContinuousConvMode = DISABLE;
+ hadc1.Init.DiscontinuousConvMode = DISABLE;
+ hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
+ hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T2_TRGO;
+ hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
+ hadc1.Init.NbrOfConversion = 1;
+ hadc1.Init.DMAContinuousRequests = DISABLE;
+ hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
+ if (HAL_ADC_Init(&hadc1) != HAL_OK)
+ {
+ Error_Handler();
+ }
+
+ /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
+ */
+ sConfig.Channel = ADC_CHANNEL_6;
+ sConfig.Rank = 1;
+ sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES;
+ if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN ADC1_Init 2 */
+
+ /* USER CODE END ADC1_Init 2 */
+
+}
+
+/**
+ * @brief I2C3 Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_I2C3_Init(void)
+{
+
+ /* USER CODE BEGIN I2C3_Init 0 */
+
+ /* USER CODE END I2C3_Init 0 */
+
+ /* USER CODE BEGIN I2C3_Init 1 */
+
+ /* USER CODE END I2C3_Init 1 */
+ hi2c3.Instance = I2C3;
+ hi2c3.Init.ClockSpeed = 100000;
+ hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;
+ hi2c3.Init.OwnAddress1 = 0;
+ hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
+ hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
+ hi2c3.Init.OwnAddress2 = 0;
+ hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
+ hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
+ if (HAL_I2C_Init(&hi2c3) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN I2C3_Init 2 */
+
+ /* USER CODE END I2C3_Init 2 */
+
+}
+
+/**
+ * @brief SPI2 Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_SPI2_Init(void)
+{
+
+ /* USER CODE BEGIN SPI2_Init 0 */
+
+ /* USER CODE END SPI2_Init 0 */
+
+ /* USER CODE BEGIN SPI2_Init 1 */
+
+ /* USER CODE END SPI2_Init 1 */
+ /* SPI2 parameter configuration*/
+ hspi2.Instance = SPI2;
+ hspi2.Init.Mode = SPI_MODE_MASTER;
+ hspi2.Init.Direction = SPI_DIRECTION_2LINES;
+ hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
+ hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
+ hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
+ hspi2.Init.NSS = SPI_NSS_SOFT;
+ hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
+ hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
+ hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
+ hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
+ hspi2.Init.CRCPolynomial = 10;
+ if (HAL_SPI_Init(&hspi2) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN SPI2_Init 2 */
+
+ /* USER CODE END SPI2_Init 2 */
+
+}
+
+/**
+ * @brief TIM2 Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_TIM2_Init(void)
+{
+
+ /* USER CODE BEGIN TIM2_Init 0 */
+
+ /* USER CODE END TIM2_Init 0 */
+
+ TIM_ClockConfigTypeDef sClockSourceConfig = {0};
+ TIM_MasterConfigTypeDef sMasterConfig = {0};
+
+ /* USER CODE BEGIN TIM2_Init 1 */
+
+ /* USER CODE END TIM2_Init 1 */
+ htim2.Instance = TIM2;
+ htim2.Init.Prescaler = (84-1);
+ htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
+ htim2.Init.Period = 100;
+ htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
+ htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
+ if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
+ if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
+ sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
+ if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN TIM2_Init 2 */
+
+ /* USER CODE END TIM2_Init 2 */
+
+}
+
+/**
+ * @brief TIM3 Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_TIM3_Init(void)
+{
+
+ /* USER CODE BEGIN TIM3_Init 0 */
+
+ /* USER CODE END TIM3_Init 0 */
+
+ TIM_ClockConfigTypeDef sClockSourceConfig = {0};
+ TIM_MasterConfigTypeDef sMasterConfig = {0};
+
+ /* USER CODE BEGIN TIM3_Init 1 */
+
+ /* USER CODE END TIM3_Init 1 */
+ htim3.Instance = TIM3;
+ htim3.Init.Prescaler = 0;
+ htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
+ htim3.Init.Period = 65535;
+ htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
+ htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
+ if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
+ if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
+ sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
+ if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN TIM3_Init 2 */
+
+ /* USER CODE END TIM3_Init 2 */
+
+}
+
+/**
+ * @brief UART4 Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_UART4_Init(void)
+{
+
+ /* USER CODE BEGIN UART4_Init 0 */
+
+ /* USER CODE END UART4_Init 0 */
+
+ /* USER CODE BEGIN UART4_Init 1 */
+
+ /* USER CODE END UART4_Init 1 */
+ huart4.Instance = UART4;
+ huart4.Init.BaudRate = 115200;
+ huart4.Init.WordLength = UART_WORDLENGTH_8B;
+ huart4.Init.StopBits = UART_STOPBITS_1;
+ huart4.Init.Parity = UART_PARITY_NONE;
+ huart4.Init.Mode = UART_MODE_TX_RX;
+ huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+ huart4.Init.OverSampling = UART_OVERSAMPLING_16;
+ if (HAL_UART_Init(&huart4) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN UART4_Init 2 */
+
+ /* USER CODE END UART4_Init 2 */
+
+}
+
+/**
+ * @brief UART5 Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_UART5_Init(void)
+{
+
+ /* USER CODE BEGIN UART5_Init 0 */
+
+ /* USER CODE END UART5_Init 0 */
+
+ /* USER CODE BEGIN UART5_Init 1 */
+
+ /* USER CODE END UART5_Init 1 */
+ huart5.Instance = UART5;
+ huart5.Init.BaudRate = 115200;
+ huart5.Init.WordLength = UART_WORDLENGTH_8B;
+ huart5.Init.StopBits = UART_STOPBITS_1;
+ huart5.Init.Parity = UART_PARITY_NONE;
+ huart5.Init.Mode = UART_MODE_TX_RX;
+ huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+ huart5.Init.OverSampling = UART_OVERSAMPLING_16;
+ if (HAL_UART_Init(&huart5) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN UART5_Init 2 */
+
+ /* USER CODE END UART5_Init 2 */
+
+}
+
+/**
+ * @brief USART1 Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_USART1_UART_Init(void)
+{
+
+ /* USER CODE BEGIN USART1_Init 0 */
+
+ /* USER CODE END USART1_Init 0 */
+
+ /* USER CODE BEGIN USART1_Init 1 */
+
+ /* USER CODE END USART1_Init 1 */
+ huart1.Instance = USART1;
+ huart1.Init.BaudRate = 115200;
+ huart1.Init.WordLength = UART_WORDLENGTH_8B;
+ huart1.Init.StopBits = UART_STOPBITS_1;
+ huart1.Init.Parity = UART_PARITY_NONE;
+ huart1.Init.Mode = UART_MODE_TX_RX;
+ huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+ huart1.Init.OverSampling = UART_OVERSAMPLING_16;
+ if (HAL_UART_Init(&huart1) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN USART1_Init 2 */
+
+ /* USER CODE END USART1_Init 2 */
+
+}
+
+/**
+ * @brief USART2 Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_USART2_UART_Init(void)
+{
+
+ /* USER CODE BEGIN USART2_Init 0 */
+
+ /* USER CODE END USART2_Init 0 */
+
+ /* USER CODE BEGIN USART2_Init 1 */
+
+ /* USER CODE END USART2_Init 1 */
+ huart2.Instance = USART2;
+ huart2.Init.BaudRate = 115200;
+ huart2.Init.WordLength = UART_WORDLENGTH_8B;
+ huart2.Init.StopBits = UART_STOPBITS_1;
+ huart2.Init.Parity = UART_PARITY_NONE;
+ huart2.Init.Mode = UART_MODE_TX_RX;
+ huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+ huart2.Init.OverSampling = UART_OVERSAMPLING_16;
+ if (HAL_UART_Init(&huart2) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN USART2_Init 2 */
+
+ /* USER CODE END USART2_Init 2 */
+
+}
+
+/**
+ * @brief USART3 Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_USART3_UART_Init(void)
+{
+
+ /* USER CODE BEGIN USART3_Init 0 */
+
+ /* USER CODE END USART3_Init 0 */
+
+ /* USER CODE BEGIN USART3_Init 1 */
+
+ /* USER CODE END USART3_Init 1 */
+ huart3.Instance = USART3;
+ huart3.Init.BaudRate = 115200;
+ huart3.Init.WordLength = UART_WORDLENGTH_8B;
+ huart3.Init.StopBits = UART_STOPBITS_1;
+ huart3.Init.Parity = UART_PARITY_NONE;
+ huart3.Init.Mode = UART_MODE_TX_RX;
+ huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+ huart3.Init.OverSampling = UART_OVERSAMPLING_16;
+ if (HAL_UART_Init(&huart3) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN USART3_Init 2 */
+
+ /* USER CODE END USART3_Init 2 */
+
+}
+
+/**
+ * @brief USART6 Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_USART6_UART_Init(void)
+{
+
+ /* USER CODE BEGIN USART6_Init 0 */
+
+ /* USER CODE END USART6_Init 0 */
+
+ /* USER CODE BEGIN USART6_Init 1 */
+
+ /* USER CODE END USART6_Init 1 */
+ huart6.Instance = USART6;
+ huart6.Init.BaudRate = 9600;
+ huart6.Init.WordLength = UART_WORDLENGTH_8B;
+ huart6.Init.StopBits = UART_STOPBITS_1;
+ huart6.Init.Parity = UART_PARITY_NONE;
+ huart6.Init.Mode = UART_MODE_TX_RX;
+ huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+ huart6.Init.OverSampling = UART_OVERSAMPLING_16;
+ if (HAL_UART_Init(&huart6) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN USART6_Init 2 */
+
+ /* USER CODE END USART6_Init 2 */
+
+}
+
+/**
+ * Enable DMA controller clock
+ */
+static void MX_DMA_Init(void)
+{
+
+ /* DMA controller clock enable */
+ __HAL_RCC_DMA2_CLK_ENABLE();
+
+ /* DMA interrupt init */
+ /* DMA2_Stream0_IRQn interrupt configuration */
+ HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);
+
+}
+
+/**
+ * @brief GPIO Initialization Function
+ * @param None
+ * @retval None
+ */
+static void MX_GPIO_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStruct = {0};
+/* USER CODE BEGIN MX_GPIO_Init_1 */
+/* USER CODE END MX_GPIO_Init_1 */
+
+ /* GPIO Ports Clock Enable */
+ __HAL_RCC_GPIOE_CLK_ENABLE();
+ __HAL_RCC_GPIOC_CLK_ENABLE();
+ __HAL_RCC_GPIOH_CLK_ENABLE();
+ __HAL_RCC_GPIOA_CLK_ENABLE();
+ __HAL_RCC_GPIOB_CLK_ENABLE();
+ __HAL_RCC_GPIOD_CLK_ENABLE();
+
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(PA4_BEIDOU_RST_EN_GPIO_Port, PA4_BEIDOU_RST_EN_Pin, GPIO_PIN_SET);
+
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(PB15_ETH_RESET_GPIO_Port, PB15_ETH_RESET_Pin, GPIO_PIN_SET);
+
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(GPIOD, LAKI_WAKE_UP_Pin|PD13_GPS_RST_EN_Pin|PD14_LORA_M0_Pin|DM222_PAPWR_EN_Pin, GPIO_PIN_RESET);
+
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(GPIOD, LAKI_RESET_Pin|PD15_LORA_M1_Pin|LORA_RST_Pin, GPIO_PIN_SET);
+
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(GPIOA, PA11_RS485_DIR1_Pin|PA12_CTL_POWER_Pin, GPIO_PIN_RESET);
+
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(GPIOB, FAN_EN_Pin|PB6_EN_BEIDOU_PWN_Pin|PB9_SPI2_NSS_Pin, GPIO_PIN_RESET);
+
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(SYS_LED_GPIO_Port, SYS_LED_Pin, GPIO_PIN_RESET);
+
+ /*Configure GPIO pin : DQ_IN_Pin */
+ GPIO_InitStruct.Pin = DQ_IN_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(DQ_IN_GPIO_Port, &GPIO_InitStruct);
+
+ /*Configure GPIO pins : PA4_BEIDOU_RST_EN_Pin PA11_RS485_DIR1_Pin PA12_CTL_POWER_Pin */
+ GPIO_InitStruct.Pin = PA4_BEIDOU_RST_EN_Pin|PA11_RS485_DIR1_Pin|PA12_CTL_POWER_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+ /*Configure GPIO pin : PB14_RMII_INT_Pin */
+ GPIO_InitStruct.Pin = PB14_RMII_INT_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(PB14_RMII_INT_GPIO_Port, &GPIO_InitStruct);
+
+ /*Configure GPIO pins : PB15_ETH_RESET_Pin FAN_EN_Pin PB6_EN_BEIDOU_PWN_Pin PB9_SPI2_NSS_Pin */
+ GPIO_InitStruct.Pin = PB15_ETH_RESET_Pin|FAN_EN_Pin|PB6_EN_BEIDOU_PWN_Pin|PB9_SPI2_NSS_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+ /*Configure GPIO pins : LAKI_WAKE_UP_Pin LAKI_RESET_Pin PD13_GPS_RST_EN_Pin PD14_LORA_M0_Pin
+ PD15_LORA_M1_Pin LORA_RST_Pin DM222_PAPWR_EN_Pin */
+ GPIO_InitStruct.Pin = LAKI_WAKE_UP_Pin|LAKI_RESET_Pin|PD13_GPS_RST_EN_Pin|PD14_LORA_M0_Pin
+ |PD15_LORA_M1_Pin|LORA_RST_Pin|DM222_PAPWR_EN_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
+
+ /*Configure GPIO pin : PD12_GPS_1PPS_Pin */
+ GPIO_InitStruct.Pin = PD12_GPS_1PPS_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(PD12_GPS_1PPS_GPIO_Port, &GPIO_InitStruct);
+
+ /*Configure GPIO pin : PC8_LORA_AUX_Pin */
+ GPIO_InitStruct.Pin = PC8_LORA_AUX_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+ GPIO_InitStruct.Pull = GPIO_PULLDOWN;
+ HAL_GPIO_Init(PC8_LORA_AUX_GPIO_Port, &GPIO_InitStruct);
+
+ /*Configure GPIO pin : SYS_LED_Pin */
+ GPIO_InitStruct.Pin = SYS_LED_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ HAL_GPIO_Init(SYS_LED_GPIO_Port, &GPIO_InitStruct);
+
+ /* EXTI interrupt init*/
+ HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(EXTI3_IRQn);
+
+/* USER CODE BEGIN MX_GPIO_Init_2 */
+/* USER CODE END MX_GPIO_Init_2 */
+}
+
+/**
+ * @brief Period elapsed callback in non blocking mode
+ * @note This function is called when TIM1 interrupt took place, inside
+ * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
+ * a global variable "uwTick" used as application time base.
+ * @param htim : TIM handle
+ * @retval None
+ */
+void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
+{
+ /* USER CODE BEGIN Callback 0 */
+
+ /* USER CODE END Callback 0 */
+ if (htim->Instance == TIM1) {
+ HAL_IncTick();
+ }
+ /* USER CODE BEGIN Callback 1 */
+
+ /* USER CODE END Callback 1 */
+}
+
+/**
+ * @brief This function is executed in case of error occurrence.
+ * @retval None
+ */
+void Error_Handler(void)
+{
+ /* USER CODE BEGIN Error_Handler_Debug */
+ /* User can add his own implementation to report the HAL error return state */
+ __disable_irq();
+ while (1)
+ {
+ }
+ /* USER CODE END Error_Handler_Debug */
+}
+
+#ifdef USE_FULL_ASSERT
+/**
+ * @brief Reports the name of the source file and the source line number
+ * where the assert_param error has occurred.
+ * @param file: pointer to the source file name
+ * @param line: assert_param error line source number
+ * @retval None
+ */
+void assert_failed(uint8_t *file, uint32_t line)
+{
+ /* USER CODE BEGIN 6 */
+ /* User can add his own implementation to report the file name and line number,
+ ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
+ /* USER CODE END 6 */
+}
+#endif /* USE_FULL_ASSERT */
+
+
+int32_t update_ota_image( void )
+{
+ uint32_t offset;
+ int32_t ret;
+ uint32_t sflash_img_addr = SFLASH_IMAGE_BASE + sizeof( image_header_t );
+ uint32_t blk_sz = 0;
+
+ ret = flash_erase( APP_IMAGE_ADDR, img_hdr.sz );
+
+ if( ret==0 ){
+ for(offset = 0; offset< img_hdr.sz;offset+=4096 ){
+ blk_sz = img_hdr.sz - offset;
+ if( blk_sz > 4096 )
+ blk_sz = 4096;
+ sFLASH_ReadBuffer(buf, sflash_img_addr+offset, blk_sz );
+ ret = flash_write(APP_IMAGE_ADDR+offset,buf, blk_sz );
+ if( ret ){
+ printf( "wirte flash fail! addr:%08X, size:%d\n", APP_IMAGE_ADDR+offset, blk_sz );
+ break;
+ }else{
+ printf( "wirte flash addr:%08X, size:%d, OK!\n", APP_IMAGE_ADDR+offset, blk_sz );
+ }
+ }
+ }
+
+ if( !ret ){
+ uint32_t read_crc16 = usMBCRC16( (uint8_t*)APP_IMAGE_ADDR, img_hdr.sz );
+ if( read_crc16 == img_hdr.crc16 ){
+ sFLASH_EraseSector( SFLASH_IMAGE_BASE ); //erase ota image header
+ printf( "update img success! erase sflash\n" );
+ }
+ }
+ return ret;
+}
+
+int32_t found_ota_image( void )
+{
+ int32_t ret = -1;
+
+ sFLASH_ReadBuffer( (uint8_t*)&img_hdr, SFLASH_IMAGE_BASE, sizeof( image_header_t ) );
+
+ if( img_hdr.sign == IMG_APP ){
+ if( sFLASH_crc16( SFLASH_IMAGE_BASE+sizeof( image_header_t ), img_hdr.sz ) == img_hdr.crc16 ){
+ printf( "found ota image, size:%08X, crc32:%08X, addr:%08X\n", img_hdr.sz, img_hdr.crc16, img_hdr.addr );
+ ret = 0;
+ }
+ }
+ return ret;
+}
+
+int fputc( int c, FILE* fp )
+{
+// HAL_UART_Transmit( &huart1, (uint8_t*)&c, 1, 10 );
+ return 0;
+}
+
+int32_t xxxmain(void)
+{
+
+
+
+ ///boot_download();
+
+ while(1){
+ //led flash
+ //user_led_on(); HAL_Delay(50); user_led_off(); HAL_Delay(50);
+ //user_led_on(); HAL_Delay(50); user_led_off(); HAL_Delay(50);
+ HAL_Delay( 1000 );
+ }
+}
+
+
+void go( uint32_t entry, uint32_t sp )
+{
+ uint32_t i;
+
+ __disable_irq();
+ HAL_NVIC_DisableIRQ( SysTick_IRQn );
+ for( i=0; i<FPU_IRQn; i++ )
+ HAL_NVIC_DisableIRQ( (IRQn_Type)i);
+
+ //disable interrupt
+ //jump to entry;
+ // __set_PRIMASK( 1 );
+ __set_MSP( sp );
+ __enable_irq();
+ ((void (*)(void) )entry)();
+}
+
+
+#include <stdarg.h>
+void debug_printf(char* str , ...)
+{
+ char buffer[100] = {0};
+ va_list aptr;
+ va_start(aptr, str);
+ if ( vsnprintf(buffer,sizeof(buffer)-1, str, aptr) > 0)
+ {
+// HAL_UART_Transmit( &huart1, (uint8_t*)buffer, strlen( buffer), strlen( buffer)*10 );
+ }
+ va_end(aptr);
+}
+
+int32_t osDelay( uint32_t ms )
+{
+ HAL_Delay(ms);
+ return 0;
+}
+
+//void UART1_RxCpltCallback(UART_HandleTypeDef *huart){}
#include "user_noise_sensor.h"
-#define SW_VER_MAJOR 1
-#define SW_VER_MINOR 0
+#define VERSION "V1.0"
+
#define USER_SHELL_USE_UART1 0
#define WIND_SENSOR_USE_UART1 1
typedef osMutexId_t user_lock_t;
-
+typedef struct udp_pcb udp_pcb_t;
typedef enum{
BD_ST_ERROR = -1,
#include "user.h"
+const char SW_VER[16]= VERSION ;
+
extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart2;
extern uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len);
extern uint32_t adc_finished;
-extern void Tcp_Server_Init(void);
+extern void tcp_server_init(void);
dev_t g_dev;
-uint8_t app_ver[2] = { SW_VER_MAJOR, SW_VER_MINOR };
-
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if( huart->Instance == USART1 ){
memset( &g_dev, 0, sizeof(g_dev ) );
g_dev.lock = user_lock_new();
}
-
+extern uint32_t code_size( void );
+extern uint32_t code_crc16( void );
+uint32_t code_sz,code_crc;
void main_task(void *argument)
{
uint32_t delay_ticks;
MX_LWIP_Init();
- Tcp_Server_Init();
-
+ tcp_server_init();
+ udp_server_init();
+
user_shell_start();
user_noise_task_start();
user_sound_task_start();
user_bd_task_start();
user_wind_task_start();
+code_sz = code_size();
+code_crc = code_crc16();
delay_ticks = xTaskGetTickCount();
for(;;)
{
+
delay_ticks += 500;
osDelayUntil( delay_ticks );
}
/* USER CODE END 5 */
}
+
+
+uint16_t user_crc16( uint8_t *data, uint32_t sz )
+{
+ return usMBCRC16( data, sz );
+}
+
+uint32_t get_b_u32( uint8_t *data )
+{
+ return (data[0]<<24)|(data[1]<<16)|(data[2]<<8)|(data[3]<<0);
+}
+
+void put_b_u32( uint32_t value, uint8_t *data )
+{
+ data[0] = (value>>24)&0xff;
+ data[1] = (value>>16)&0xff;
+ data[2] = (value>>8)&0xff;
+ data[3] = (value>>0)&0xff;
+}
+
+uint32_t get_b_u24( uint8_t *data )
+{
+ return (data[0]<<16)|(data[1]<<8)|(data[2]<<0);
+}
+
+void put_b_u24( uint32_t value, uint8_t *data )
+{
+ data[0] = (value>>16)&0xff;
+ data[1] = (value>>8)&0xff;
+ data[2] = (value>>0)&0xff;
+}
+
+uint32_t get_b_u16( uint8_t *data )
+{
+ return (data[0]<<8)|(data[1]<<0);
+}
+
+void put_b_u16( uint16_t value, uint8_t *data )
+{
+ data[0] = (value>>8)&0xff;
+ data[1] = (value>>0)&0xff;
+}
+
+void user_eth_mac_get( uint8_t *mac )
+{
+ //ÀûÓÃÓÃÉ豸UUIDÉú³É ²»Í¬eth mac ·ÀÖ¹³åÍ»¡£
+ uint32_t uuid[3];
+ uint16_t crc;
+
+ uuid[0] = HAL_GetUIDw0();
+ uuid[1] = HAL_GetUIDw1();
+ uuid[2] = HAL_GetUIDw2();
+ crc = usMBCRC16( (uint8_t*)&uuid[0], 4 );
+ mac[0] = (crc>>8)&0xFC;
+ mac[1] = crc&0xFF;
+ crc = usMBCRC16( (uint8_t*)&uuid[1], 4 );
+ mac[2] = (crc>>8)&0xFF;
+ mac[3] = crc&0xFF;
+ crc = usMBCRC16( (uint8_t*)&uuid[2], 4 );
+ mac[4] = (crc>>8)&0xFF;
+ mac[5] = crc&0xFF;
+}
--- /dev/null
+#include "user.h"
+
+
+//sect 0 - 7 : 16K + 16K + 16K + 16K + 64K + 128K * 3
+/* Base address of the Flash sectors */
+
+#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 11, 128 Kbytes */
+
+//sect 4 0x0801 0000 -- 0x0801 FFFF
+
+#define NV_ADDR ADDR_FLASH_SECTOR_4
+#define NV_DATA_SIZE (2*1024) //2K
+
+void user_nv_init( void )
+{
+
+ return;
+}
+
+static int32_t nv_erase( void )
+{
+
+ /*Variable used for Erase procedure*/
+ FLASH_EraseInitTypeDef EraseInitStruct;
+ uint32_t SectorError = 0;
+
+ /* Unlock the Flash to enable the flash control register access *************/
+ ///HAL_FLASH_Unlock();
+
+ /* Erase the user Flash area
+ (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
+
+
+ /* Fill EraseInit structure*/
+ EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
+ EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
+ EraseInitStruct.Sector = FLASH_SECTOR_4;
+ EraseInitStruct.NbSectors = 1;
+
+ printf( "erase sect %d ...\r\n", EraseInitStruct.Sector );
+
+ if(HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK)
+ {
+ /*
+ Error occurred while sector erase.
+ User can add here some code to deal with this error.
+ SectorError will contain the faulty sector and then to know the code error on this sector,
+ user can call function 'HAL_FLASH_GetError()'
+ */
+ /*
+ FLASH_ErrorTypeDef errorcode = HAL_FLASH_GetError();
+ */
+ ///Error_Handler();
+ printf( "erase fail!, errorcode:%08x\n", HAL_FLASH_GetError() );
+ return -1;
+ }
+ printf( "erase ok!\n" );
+ /* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
+ you have to make sure that these data are rewritten before they are accessed during code
+ execution. If this cannot be done safely, it is recommended to flush the caches by setting the
+ DCRST and ICRST bits in the FLASH_CR register. */
+ __HAL_FLASH_DATA_CACHE_DISABLE();
+ __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
+
+ __HAL_FLASH_DATA_CACHE_RESET();
+ __HAL_FLASH_INSTRUCTION_CACHE_RESET();
+
+ __HAL_FLASH_INSTRUCTION_CACHE_ENABLE();
+ __HAL_FLASH_DATA_CACHE_ENABLE();
+
+ return 0;
+}
+
+typedef struct{
+ uint32_t data[NV_DATA_SIZE/4];
+ uint16_t crc16;
+}nv_data_t;
+
+static nv_data_t s_user_nv;
+
+extern uint16_t usMBCRC16( uint8_t * pucFrame, uint32_t usLen );
+int32_t nv_write( uint16_t off, uint8_t *data, uint16_t wr_size )
+{
+ int32_t i;
+ uint32_t err = 0;
+ uint32_t nv_addr;
+ uint32_t nv_data_size;
+
+ nv_addr = NV_ADDR;
+ nv_data_size = NV_DATA_SIZE;
+
+ if( off+wr_size > nv_data_size )
+ return -1;
+
+ memcpy( &s_user_nv, (void*)nv_addr, sizeof( s_user_nv ) );
+ if( usMBCRC16( (uint8_t*)&s_user_nv.data[0], nv_data_size ) != s_user_nv.crc16 ){
+ memset( &s_user_nv, 0xff, sizeof( s_user_nv ) );
+ }
+
+ if( memcmp( (void*)(off+&s_user_nv.data[0]), data, wr_size ) ){
+
+ memcpy( (void*)(off+&s_user_nv.data[0]), data, wr_size );
+ s_user_nv.crc16 = usMBCRC16( (uint8_t*)&s_user_nv.data[0], nv_data_size );
+
+ HAL_FLASH_Unlock();
+ err = 0;
+ while( nv_erase() < 0 && err < 3){
+ err++ ;
+ //DBG_PRINTF( "nv erase fail! retry:%d\r\n", err );
+ osDelay(100);
+ //todo retry...
+ }
+ if( err >= 3 ){
+
+
+ }else{
+ for( i=0; i<sizeof( s_user_nv.data )/sizeof( s_user_nv.data[0] ); i++ ){
+ if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, nv_addr+i*4, s_user_nv.data[i]) != HAL_OK){
+ err++;
+ break;
+ }
+ }
+ if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, nv_addr+i*4, s_user_nv.crc16 ) != HAL_OK){
+ }
+ }
+
+ //todo :if err < 5 retry ....
+
+ HAL_FLASH_Lock();
+ }
+ return 0;
+}
+
+static const uint32_t sector_size[8]={
+ 16*1024, //S0
+ 16*1024,
+ 16*1024,
+ 16*1024,
+ 64*1024, //S4
+ 128*1024, //S5
+ 128*1024, //S6
+ 128*1024, //S7
+};
+
+int32_t flash_erase( uint32_t addr, uint32_t sz )
+{
+ int i;
+ int32_t ret = -1;
+
+ /*Variable used for Erase procedure*/
+ FLASH_EraseInitTypeDef EraseInitStruct;
+ uint32_t SectorError = 0;
+
+
+ uint32_t sect_addr = 0x08000000;
+ uint32_t erase_start = 0;
+ uint32_t erase_end = 0;
+
+ for( i=0; i<12; i++ ){
+ if( addr >= sect_addr && addr < sect_addr+sector_size[i] ){
+ erase_start = i;
+ }
+ if( addr+sz >= sect_addr && addr+sz < sect_addr+sector_size[i] ){
+ erase_end = i;
+ break;
+ }
+ sect_addr += sector_size[i];
+ }
+
+ if( erase_start<4 || erase_end < erase_start || erase_end > 11 ){
+ return -1;
+ }
+
+ /* Unlock the Flash to enable the flash control register access *************/
+ HAL_FLASH_Unlock();
+
+ /* Fill EraseInit structure*/
+ EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
+ EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
+ EraseInitStruct.Sector = erase_start;
+ EraseInitStruct.NbSectors = erase_end-erase_start+1;
+
+ //printf( "erase sect %d ...\r\n", EraseInitStruct.Sector );
+ for( i=0; i<5; i++ ){
+ if(HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK){
+ printf( "erase fail[%d]!, errorcode:%08x\n", i, HAL_FLASH_GetError() );
+ ret = -1;
+ }else{
+ printf( "erase ok!\n" );
+ ret = 0;
+ break;
+ }
+ }
+ if( ret ){
+ printf( "erase fail!\n" );
+ }
+ /* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
+ you have to make sure that these data are rewritten before they are accessed during code
+ execution. If this cannot be done safely, it is recommended to flush the caches by setting the
+ DCRST and ICRST bits in the FLASH_CR register. */
+ __HAL_FLASH_DATA_CACHE_DISABLE();
+ __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
+
+ __HAL_FLASH_DATA_CACHE_RESET();
+ __HAL_FLASH_INSTRUCTION_CACHE_RESET();
+
+ __HAL_FLASH_INSTRUCTION_CACHE_ENABLE();
+ __HAL_FLASH_DATA_CACHE_ENABLE();
+
+ return ret;
+}
+
+int32_t flash_write( uint32_t addr, uint8_t *data, uint32_t sz )
+{
+ int32_t err=0;
+ int32_t i;
+ uint32_t wr_word;
+
+ err = 0;
+
+ HAL_FLASH_Unlock();
+ for( i=0; i+4<=sz; i+=4 ){
+ memcpy( &wr_word, data+i, 4 );
+ if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, addr+i, wr_word ) != HAL_OK){
+ err++;
+ break;
+ }
+ }
+ if( !err ){
+ for( ; i<sz; i++ ){
+
+ if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, addr+i, data[i] ) != HAL_OK){
+ err++;
+ break;
+ }
+ }
+ }
+
+ //todo :if err < 5 retry ....
+
+ HAL_FLASH_Lock();
+
+ return err?-1:0;
+}
+
+extern uint32_t Region$$Table$$Base;
+extern uint32_t Region$$Table$$Limit;
+extern uint32_t __Vectors;
+extern uint16_t user_crc16( uint8_t *data, uint32_t sz );
+
+uint32_t code_size( void )
+{
+ uint32_t *p;
+ p = (uint32_t*)&Region$$Table$$Base;
+ p += 4;
+ return *p - (uint32_t)&__Vectors;
+}
+
+uint32_t code_crc16( void )
+{
+ return user_crc16( (uint8_t*)&__Vectors, code_size() );
+}
+
+int32_t nv_read( uint16_t off, uint8_t *data, uint16_t rd_size )
+{
+ uint32_t nv_addr;
+ uint32_t nv_data_size;
+
+ nv_addr = NV_ADDR;
+ nv_data_size = NV_DATA_SIZE;
+
+ if( off+rd_size > nv_data_size )
+ return -1;
+
+ memcpy( &s_user_nv, (void*)nv_addr, sizeof( s_user_nv ) );
+ if( usMBCRC16( (uint8_t*)&s_user_nv.data[0], nv_data_size ) != s_user_nv.crc16 ){
+ memset( &s_user_nv, 0, sizeof( s_user_nv ) );
+ }else{
+ memcpy( data, (void*)(nv_addr+off), rd_size );
+ }
+ return 0;
+}
+
+int32_t user_nv_write( uint16_t off, uint8_t *data, uint16_t wr_size )
+{
+ return nv_write( off, data, wr_size );
+}
+
+int32_t user_nv_read( uint16_t off, uint8_t *data, uint16_t rd_size )
+{
+ return nv_read( off, data, rd_size );
+}
+
+uint32_t user_nv_size( void )
+{
+ return NV_DATA_SIZE;
+}
+
--- /dev/null
+#include "user.h"
+#include "user_sflash.h"
+#include "stdio.h"
+#include "string.h"
+#include "stdlib.h"
+
+#define DBG_PRINTF( x... )
+/*
+W25Q64JVSSIQ -- 64J -> 64M bit/8M Byte
+FLASH_CS / PB.9 extern pullup
+SPI2_SCK / PB.10 extern pullup
+SPI2_MISO / PC.2 extern pullup
+SPI2_MOSI / PC.3 extern pullup
+FLASH_WP / vcc
+FLASH_HOLD / vcc
+*/
+
+
+#define SPI_TIMOUT 1000 //1000ms
+#define SPI_OK ((uint8_t)0x00)
+#define SPI_ERROR ((uint8_t)0x01)
+
+extern SPI_HandleTypeDef hspi2;
+
+//spiflash
+static uint8_t buf_1k[1024];
+static uint32_t sFLASH_ready = 0;
+
+/**
+ * @brief Select sFLASH: Chip Select pin low
+ */
+
+void sFLASH_GPIO_Init( void )
+{
+ /*
+ //PB15_SPI2_MOSI --> INPUT
+ //PI3_SPI2_MOSI --> MODSI
+ GPIO_InitTypeDef GPIO_InitStruct = {0};
+ __HAL_RCC_GPIOB_CLK_ENABLE();
+ __HAL_RCC_GPIOI_CLK_ENABLE();
+
+ GPIO_InitStruct.Pin = PB15_SPI2_MOSI_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
+ HAL_GPIO_Init(PB15_SPI2_MOSI_GPIO_Port, &GPIO_InitStruct);
+
+ GPIO_InitStruct.Pin = GPIO_PIN_3;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
+ HAL_GPIO_Init( GPIOI, &GPIO_InitStruct);
+ */
+}
+
+void sFLASH_GPIO_Deinit( void )
+{
+/*
+ //PB15_SPI2_MOSI --> MOSI
+ //PI3_SPI2_MOSI --> INPUT
+ GPIO_InitTypeDef GPIO_InitStruct = {0};
+ __HAL_RCC_GPIOB_CLK_ENABLE();
+ __HAL_RCC_GPIOI_CLK_ENABLE();
+
+ GPIO_InitStruct.Pin = PB15_SPI2_MOSI_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
+ HAL_GPIO_Init(PB15_SPI2_MOSI_GPIO_Port, &GPIO_InitStruct);
+
+ GPIO_InitStruct.Pin = GPIO_PIN_3;
+ GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
+ HAL_GPIO_Init( GPIOI, &GPIO_InitStruct);
+*/
+}
+
+void sFLASH_CS_LOW( void )
+{
+ //spi2 require ... to lock
+ //sFLASH_GPIO_Init();
+ PIN_LOW( PB9_SPI2_NSS );
+}
+
+/**
+ * @brief Deselect sFLASH: Chip Select pin high
+ */
+void sFLASH_CS_HIGH( void )
+{
+ PIN_HIGH( PB9_SPI2_NSS );
+ //sFLASH_GPIO_Deinit();
+ //spi2 release ... to unlock}
+}
+
+void sFLASH_DeInit(void)
+{
+
+}
+
+/**
+ * @brief Initializes the peripherals used by the SPI FLASH driver.
+ * @param None
+ * @retval None
+ */
+
+int32_t sFLASH_Init(void)
+{
+
+ //spi2_init();
+ sFLASH_PowerOn();
+ if( sFLASH_ReadID() == sFLASH_W25Q64JV_ID ){
+ sFLASH_ready = 1;
+ }else{
+ sFLASH_ready = 0;
+ }
+
+ return sFLASH_ready?0:-1;
+}
+
+/**
+ * @brief Erases the specified FLASH sector.
+ * @param SectorAddr: address of the sector to erase.
+ * @retval None
+ */
+void sFLASH_EraseSector(uint32_t SectorAddr)
+{
+ uint32_t ret;
+ uint8_t cmd[8];
+
+ if( !sFLASH_ready )
+ return;
+
+ /*!< Send write enable instruction */
+ sFLASH_WriteEnable();
+
+ cmd[0] = sFLASH_CMD_SE;
+ cmd[1] = (SectorAddr>>16)& 0xFF;
+ cmd[2] = (SectorAddr>>8) & 0xFF;
+ cmd[3] = (SectorAddr) & 0xFF;
+ /*!< Sector Erase */
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ ret = HAL_SPI_Transmit( &hspi2, cmd, 4, SPI_TIMOUT );
+ if( ret == HAL_OK )
+ ;
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+
+ /*!< Wait the end of Flash writing */
+ sFLASH_WaitForWriteEnd();
+}
+
+int32_t sFLASH_EraseBlock(uint32_t SectorAddr, uint32_t sect_sz )
+{
+ int32_t ret;
+ uint8_t cmd[8];
+
+ /*!< Send write enable instruction */
+ sFLASH_WriteEnable();
+
+ if( sect_sz == 64*1024 )
+ cmd[0] = sFLASH_CMD_BE_64K;
+ else if( sect_sz == 32*1024 )
+ cmd[0] = sFLASH_CMD_BE_32K;
+ else
+ cmd[0] = sFLASH_CMD_SE;
+ cmd[1] = (SectorAddr>>16)& 0xFF;
+ cmd[2] = (SectorAddr>>8) & 0xFF;
+ cmd[3] = (SectorAddr) & 0xFF;
+ /*!< Sector Erase */
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ ret = HAL_SPI_Transmit( &hspi2, cmd, 4, SPI_TIMOUT );
+ if( ret == HAL_OK )
+ ;
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+
+ /*!< Wait the end of Flash writing */
+ sFLASH_WaitForWriteEnd();
+
+ return ret==HAL_OK?0:-1;
+}
+
+/**
+ * @brief Erases the entire FLASH.
+ * @param None
+ * @retval None
+ */
+void sFLASH_EraseBulk(void)
+{
+ /*!< Send write enable instruction */
+ sFLASH_WriteEnable();
+
+ /*!< Bulk Erase */
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+ /*!< Send Bulk Erase instruction */
+ sFLASH_SendByte(sFLASH_CMD_BE);
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+
+ /*!< Wait the end of Flash writing */
+ sFLASH_WaitForWriteEnd();
+}
+
+/**
+ * @brief Writes more than one byte to the FLASH with a single WRITE cycle
+ * (Page WRITE sequence).
+ * @note The number of byte can't exceed the FLASH page size.
+ * @param pBuffer: pointer to the buffer containing the data to be written
+ * to the FLASH.
+ * @param WriteAddr: FLASH's internal address to write to.
+ * @param NumByteToWrite: number of bytes to write to the FLASH, must be equal
+ * or less than "sFLASH_PAGESIZE" value.
+ * @retval None
+ */
+void sFLASH_WritePage(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
+{
+ uint32_t ret;
+ uint8_t cmd[8];
+
+ cmd[0] = sFLASH_CMD_WRITE;
+ cmd[1] = (WriteAddr>>16) & 0xFF;
+ cmd[2] = (WriteAddr>> 8) & 0xFF;
+ cmd[3] = (WriteAddr>> 0) & 0xFF;
+ /*!< Enable the write access to the FLASH */
+ sFLASH_WriteEnable();
+
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ ret = HAL_SPI_Transmit( &hspi2, cmd, 4, SPI_TIMOUT );
+ if( ret == HAL_OK )
+ ;
+
+ ret = HAL_SPI_Transmit( &hspi2, pBuffer, NumByteToWrite, SPI_TIMOUT );
+ if( ret == HAL_OK )
+ ;
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+
+ /*!< Wait the end of Flash writing */
+ sFLASH_WaitForWriteEnd();
+}
+
+/**
+ * @brief Writes block of data to the FLASH. In this function, the number of
+ * WRITE cycles are reduced, using Page WRITE sequence.
+ * @param pBuffer: pointer to the buffer containing the data to be written
+ * to the FLASH.
+ * @param WriteAddr: FLASH's internal address to write to.
+ * @param NumByteToWrite: number of bytes to write to the FLASH.
+ * @retval None
+ */
+void sFLASH_WriteBuffer(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
+{
+ uint8_t NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0, temp = 0;
+
+ if( !sFLASH_ready )
+ return;
+
+ Addr = WriteAddr % sFLASH_SPI_PAGESIZE;
+ count = sFLASH_SPI_PAGESIZE - Addr;
+ NumOfPage = NumByteToWrite / sFLASH_SPI_PAGESIZE;
+ NumOfSingle = NumByteToWrite % sFLASH_SPI_PAGESIZE;
+
+ if (Addr == 0) /*!< WriteAddr is sFLASH_PAGESIZE aligned */
+ {
+ if (NumOfPage == 0) /*!< NumByteToWrite < sFLASH_PAGESIZE */
+ {
+ sFLASH_WritePage(pBuffer, WriteAddr, NumByteToWrite);
+ }
+ else /*!< NumByteToWrite > sFLASH_PAGESIZE */
+ {
+ while (NumOfPage--)
+ {
+ sFLASH_WritePage(pBuffer, WriteAddr, sFLASH_SPI_PAGESIZE);
+ WriteAddr += sFLASH_SPI_PAGESIZE;
+ pBuffer += sFLASH_SPI_PAGESIZE;
+ }
+ if (NumOfSingle != 0)
+ sFLASH_WritePage(pBuffer, WriteAddr, NumOfSingle);
+ }
+ }
+ else /*!< WriteAddr is not sFLASH_PAGESIZE aligned */
+ {
+ if (NumOfPage == 0) /*!< NumByteToWrite < sFLASH_PAGESIZE */
+ {
+ if (NumOfSingle > count) /*!< (NumByteToWrite + WriteAddr) > sFLASH_PAGESIZE */
+ {
+ temp = NumOfSingle - count;
+
+ sFLASH_WritePage(pBuffer, WriteAddr, count);
+ WriteAddr += count;
+ pBuffer += count;
+
+ sFLASH_WritePage(pBuffer, WriteAddr, temp);
+ }
+ else
+ {
+ sFLASH_WritePage(pBuffer, WriteAddr, NumByteToWrite);
+ }
+ }
+ else /*!< NumByteToWrite > sFLASH_PAGESIZE */
+ {
+ NumByteToWrite -= count;
+ NumOfPage = NumByteToWrite / sFLASH_SPI_PAGESIZE;
+ NumOfSingle = NumByteToWrite % sFLASH_SPI_PAGESIZE;
+
+ sFLASH_WritePage(pBuffer, WriteAddr, count);
+ WriteAddr += count;
+ pBuffer += count;
+
+ while (NumOfPage--)
+ {
+ sFLASH_WritePage(pBuffer, WriteAddr, sFLASH_SPI_PAGESIZE);
+ WriteAddr += sFLASH_SPI_PAGESIZE;
+ pBuffer += sFLASH_SPI_PAGESIZE;
+ }
+
+ if (NumOfSingle != 0)
+ {
+ sFLASH_WritePage(pBuffer, WriteAddr, NumOfSingle);
+ }
+ }
+ }
+}
+
+/**
+ * @brief Reads a block of data from the FLASH.
+ * @param pBuffer: pointer to the buffer that receives the data read from the FLASH.
+ * @param ReadAddr: FLASH's internal address to read from.
+ * @param NumByteToRead: number of bytes to read from the FLASH.
+ * @retval None
+ */
+void sFLASH_ReadBuffer(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead)
+{
+ uint32_t ret;
+ uint8_t cmd[8];
+
+ cmd[0] = sFLASH_CMD_READ;
+ cmd[1] = (ReadAddr>>16) & 0xFF;
+ cmd[2] = (ReadAddr>> 8) & 0xFF;
+ cmd[3] = (ReadAddr>> 0) & 0xFF;
+
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ ret = HAL_SPI_Transmit( &hspi2, cmd, 4, SPI_TIMOUT );
+ if( ret == HAL_OK )
+ ;
+ ret = HAL_SPI_Receive( &hspi2, pBuffer, NumByteToRead , SPI_TIMOUT );
+ if( ret == HAL_OK )
+ ;
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+}
+
+/**
+ * @brief Reads FLASH identification.
+ * @param None
+ * @retval FLASH identification
+ */
+//HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
+
+uint32_t sFLASH_ReadID(void)
+{
+ uint8_t buf[8];
+ uint32_t ret;
+
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+ /*!< Send "RDID " instruction */
+ sFLASH_SendByte(sFLASH_CMD_RDID);
+
+ ret = HAL_SPI_Receive( &hspi2, buf, 3, SPI_TIMOUT );
+ if( ret == HAL_OK )
+ ;
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+
+ return (buf[0]<<16) | ( buf[1] <<8 ) | buf[2];
+}
+
+/**
+ * @brief Sends a byte through the SPI interface and return the byte received
+ * from the SPI bus.
+ * @param byte: byte to send.
+ * @retval The value of the received byte.
+ */
+uint8_t sFLASH_SendByte(uint8_t byte)
+{
+ uint8_t buf;
+ uint32_t ret;
+
+ buf = byte;
+ ret = HAL_SPI_Transmit( &hspi2, &buf, 1, SPI_TIMOUT );
+ ///HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE, 5000)
+ if( ret == HAL_OK )
+ ;
+ return ret;
+}
+
+/**
+ * @brief Enables the write access to the FLASH.
+ * @param None
+ * @retval None
+ */
+void sFLASH_WriteEnable(void)
+{
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ /*!< Send "Write Enable" instruction */
+ sFLASH_SendByte(sFLASH_CMD_WREN);
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+}
+
+/**
+ * @brief Polls the status of the Write In Progress (WIP) flag in the FLASH's
+ * status register and loop until write opertaion has completed.
+ * @param None
+ * @retval None
+ */
+void sFLASH_WaitForWriteEnd(void)
+{
+ uint8_t flashstatus = 0;
+
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ /*!< Send "Read Status Register" instruction */
+ sFLASH_SendByte(sFLASH_CMD_RDSR);
+
+ /*!< Loop as long as the memory is busy with a write cycle */
+ do
+ {
+ /*!< Send a dummy byte to generate the clock needed by the FLASH
+ and put the value of the status register in FLASH_Status variable */
+ //flashstatus = sFLASH_SendByte(sFLASH_DUMMY_BYTE);
+ if( HAL_SPI_Receive( &hspi2, &flashstatus, 1 , SPI_TIMOUT ) != HAL_OK )
+ {
+ //Error_Handler();
+ }
+
+ }
+ while ((flashstatus & sFLASH_WIP_FLAG) == SET); /* Write in progress */
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+}
+
+void sFLASH_PowerOff(void)
+{
+ volatile uint8_t id;
+
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ /*!< Send "Write Enable" instruction */
+ sFLASH_SendByte(sFLAsh_CMD_POWERDOWN);
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+
+
+}
+
+void sFLASH_PowerOn(void)
+{
+ uint32_t ret;
+ uint8_t cmd[8]={ sFLAsh_CMD_POWERUP, 0xA5, 0xA5, 0xA5, 0xA5, };
+
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ ret = HAL_SPI_Transmit( &hspi2, cmd, 5, SPI_TIMOUT );
+ if( ret == HAL_OK )
+ ;
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+}
+
+void sFlash_PowerTest( void )
+{
+ volatile uint32_t id;
+ uint32_t i;
+
+ id = sFLASH_ReadID();
+ DBG_PRINTF( "Read Flas Id: %08X\n", id );
+ sFLASH_PowerOff();
+ for( i=0; i<0xffff; i++ );
+ id = sFLASH_ReadID();
+ DBG_PRINTF( "Pwr OFF -- Read Flas Id: %08X\n", id );
+ sFLASH_PowerOn();
+ for( i=0; i<0xffff; i++ );
+ id = sFLASH_ReadID();
+ DBG_PRINTF( "Pwr ON -- Read Flas Id: %08X\n", id );
+ for( i=0; i<0xffff; i++ );
+
+}
+
+/**
+ * @brief Reads a block of data from the FLASH.
+ * @param pBuffer: pointer to the buffer that receives the data read from the FLASH.
+ * @param ReadAddr: FLASH's internal address to read from.
+ * @param NumByteToRead: number of bytes to read from the FLASH.
+ * @retval None
+ */
+uint32_t sFLASH_ReadSum( void )
+{
+ uint32_t ret;
+ uint8_t cmd[8];
+
+ uint32_t sum=0;
+ uint32_t count=0;
+// uint8_t data;
+ uint32_t i;
+
+ cmd[0] = sFLASH_CMD_READ;
+ cmd[1] = 0;
+ cmd[2] = 0;
+ cmd[3] = 0;
+
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ ret = HAL_SPI_Transmit( &hspi2, cmd, 4, SPI_TIMOUT );
+ if( ret == HAL_OK )
+ ;
+
+ for( count=0; count<0x800000/1024 - 256; count++ ){
+ /*!< Read a byte from the FLASH */
+ ret = HAL_SPI_Receive( &hspi2, buf_1k, 1024, SPI_TIMOUT );
+ if( ret == HAL_OK )
+ ;
+ for( i=0; i<1024; i++ )
+ sum += buf_1k[i];
+ }
+ sum += 0xff * 256 *1024;
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+
+ return sum;
+}
+
+extern uint16_t mbcrc16_update( uint16_t code, uint8_t *data, uint32_t sz );
+uint32_t sFLASH_crc16( uint32_t addr, uint32_t sz )
+{
+ uint32_t ret;
+ uint8_t cmd[8];
+ uint32_t count=0;
+ uint32_t n;
+ uint8_t page_buf[256];
+ uint16_t crc16;
+
+ cmd[0] = sFLASH_CMD_READ;
+ cmd[1] = (addr>>16) & 0xFF;
+ cmd[2] = (addr>> 8) & 0xFF;
+ cmd[3] = (addr>> 0) & 0xFF;
+
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ ret = HAL_SPI_Transmit( &hspi2, cmd, 4, SPI_TIMOUT );
+ if( ret == HAL_OK )
+ ;
+
+ crc16=0xFFFF;
+ for( count=0; count<sz; count+=sizeof(page_buf) ){
+ /*!< Read a byte from the FLASH */
+ n = sz-count;
+ if( n > sizeof(page_buf) )
+ n = sizeof(page_buf);
+ ret = HAL_SPI_Receive( &hspi2, page_buf, n, SPI_TIMOUT );
+ if( ret != HAL_OK )
+ break;
+ crc16 = mbcrc16_update( crc16, page_buf, n);
+ }
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+ //crc16^=0xFFFFFFFF;
+
+ return crc16;
+}
+
+int32_t user_sflash_erase( uint32_t addr, uint32_t sz )
+{
+ uint32_t erase_sz;
+ int32_t ret = 0;
+
+ if( !sFLASH_ready ){
+ sFLASH_Init();
+ }
+
+ if( addr & 64*1024 ){
+ ret = -1;
+ }else{
+ erase_sz = 0;
+ while( erase_sz < sz ){
+ ret = sFLASH_EraseBlock( addr+erase_sz, 64*1024 );
+ if( ret )
+ break; //err
+ else
+ erase_sz += 64*1024;
+ }
+
+ }
+
+ return ret;
+}
+
+int32_t user_sflash_write( uint32_t addr, uint8_t *data, uint32_t sz )
+{
+ sFLASH_WriteBuffer( data, addr, sz );
+ return 0;
+}
+
+uint32_t user_sflash_crc16( uint32_t addr, uint32_t sz )
+{
+ return sFLASH_crc16( addr, sz );
+}
+
+#if 0
+static uint8_t test_buffer[1024*8];
+void sFLASH_Test( void )
+{
+ uint32_t id, i;
+ char buff[32];
+ uint8_t * ptr;
+
+ //uint32_t s;
+
+// sFlash_PowerTest();
+ sFLASH_Init();
+
+
+ sFLASH_ReadBuffer(test_buffer, 0x700000, sizeof(test_buffer) ); //from 7M addr, read 4k
+
+
+
+ for( i=0; i<sizeof( test_buffer); i++ ){
+ test_buffer[i] += 1;
+ }
+ //erase
+ sFLASH_EraseSector( 0x700000 );
+
+ //write
+ sFLASH_WriteBuffer( test_buffer, 0x700000, sizeof( test_buffer ) );
+
+ //read
+ sFLASH_ReadBuffer(test_buffer, 0x700000, sizeof(test_buffer) ); //from 7M addr, read 4k
+ return ;
+
+ ptr = &test_buffer[0];
+
+ //s = sFLASH_ReadSum();
+
+ ptr = (uint8_t *)malloc( 100*1024);
+ if( ptr )
+ sFLASH_ReadBuffer(ptr, 0, 100*1024 );
+
+ return ;
+
+// LCD_DrawText( 8, 170, buff, 1 );
+// lcd_update_full();
+ for( i=0; i<4096; i++ )
+ ptr[i] = i;
+ sFLASH_WriteBuffer( ptr, 0, 4096 );
+ memset( ptr, 0, 4096 );
+ sFLASH_ReadBuffer( ptr, 6, 4090 );
+ sprintf( buff, "read sflash addr[0]:%x", ptr[0] );
+// LCD_DrawText( 8, 180, buff, 1 );
+// lcd_update_full();
+ memset( ptr, 0, 4096 );
+
+ i=32*1024;
+ while( i ){
+ ptr = (uint8_t*)malloc( i );
+ if( ptr ){
+ sprintf( buff, "malloc [%d]", i );
+// LCD_DrawText( 8, 50, buff, 1 );
+ free( ptr );
+ break;
+ }
+ i--;
+ }
+// if( i==0 )
+// LCD_DrawText( 8, 50, "malloc fail", 1 );
+// lcd_update_full();
+
+}
+#endif
+
+/**
+ * @}
+ */
+
+/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
+
+#if SFLASH_LOG
+
+#include "res_table.h"
+#include "os_rtc.h"
+//#define log_size_max (25*0x1000) //100KB
+//#define log_data_base (2*1024*1024-log_size_max)
+
+//#define TABLE_WORD 0x0000A370
+//#define TABLE_BMP_ZH 0x0018EE28
+
+#define log_start_addr ( (TABLE_WORD+sFLASH_SECT_SZ-1)&~(sFLASH_SECT_SZ-1) )
+#define log_end_addr ( (TABLE_BMP_ZH)&~(sFLASH_SECT_SZ-1) )
+
+#define log_size_max ( log_end_addr - log_start_addr )
+#define log_data_base ( log_start_addr )
+
+static uint32_t log_flash_size = 0;
+static uint32_t log_flash_started = 0;
+
+uint16_t sflash_log_start( void );
+uint16_t sflash_log_write( uint8_t * data, uint16_t sz );
+uint16_t sflash_log_read( uint32_t addr, uint8_t * data, uint16_t sz );
+
+uint32_t sflash_log_start_addr( void );
+uint32_t sflash_log_end_addr( void );
+
+
+extern void pedo_log_timer_start( void );
+
+uint32_t sflash_log_end_addr( void )
+{
+ return log_end_addr;
+}
+
+uint32_t sflash_log_start_addr( void )
+{
+ return log_data_base;
+}
+
+uint32_t sflash_log_size( void )
+{
+ return log_flash_size;
+}
+
+uint16_t sflash_log_st( void )
+{
+ return log_flash_started;
+}
+
+uint16_t sflash_log_stop( void )
+{
+ log_flash_started = 2;
+ return 0;
+}
+
+uint16_t sflash_log_start( void )
+{
+ uint32_t addr;
+ uint32_t sz;
+ struct _os_date_time rtc;
+ int8_t str[32];
+
+ os_rtc_get_time( &rtc );
+
+ if( log_flash_started == 1 )
+ return 0;
+
+ addr = log_data_base;
+ for( sz=0; sz<log_size_max; sz+=sFLASH_SECT_SZ, addr+=sFLASH_SECT_SZ ){
+ sFLASH_EraseSector( addr );
+ }
+ log_flash_size = 0;
+ log_flash_started = 1;
+
+ sprintf((char*)str, "[%02d.%02d %02d:%02d:%02d]",rtc.mMon, rtc.mDay, rtc.mHour, rtc.mMin, rtc.mSec );
+ sFLASH_WriteBuffer( (uint8_t*)str, log_data_base, strlen((char*)str)+1 );
+ log_flash_size+=48;
+ return 0;
+}
+
+uint16_t sflash_log_write( uint8_t * data, uint16_t sz )
+{
+// uint32_t offset;
+ uint16_t count =0;
+
+ if( log_flash_started != 1 )
+ return 0;
+
+
+ if( log_flash_size< log_size_max){
+ if( log_flash_size+sz <= log_size_max ){
+ count = sz;
+ }else{
+ count = log_size_max - log_flash_size;
+ }
+ sFLASH_WriteBuffer( data, log_data_base+log_flash_size, count );
+ log_flash_size+=count;
+ }else{
+ log_flash_started = 3;
+ }
+
+ return count;
+}
+
+uint16_t sflash_log_read( uint32_t addr, uint8_t * data, uint16_t sz )
+{
+
+ return 0;
+}
+#endif //SFLASH_LOG
--- /dev/null
+/**
+ ******************************************************************************
+ * @file stm32_eval_spi_flash.h
+ * @author MCD Application Team
+ * @version V4.6.1
+ * @date 18-April-2011
+ * @brief This file contains all the functions prototypes for the stm32_eval_spi_flash
+ * firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+ * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
+ * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
+ * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
+ * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
+ * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+ *
+ * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USER_SFLASH_H
+#define __USER_SFLASH_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include <stdint.h>
+
+/**
+ * @brief M25P SPI Flash supported commands
+ */
+#define sFLASH_CMD_WRITE 0x02 /*!< Write to Memory instruction */
+#define sFLASH_CMD_WRSR 0x01 /*!< Write Status Register instruction */
+#define sFLASH_CMD_WREN 0x06 /*!< Write enable instruction */
+#define sFLASH_CMD_READ 0x03 /*!< Read from Memory instruction */
+#define sFLASH_CMD_RDSR 0x05 /*!< Read Status Register instruction */
+#define sFLASH_CMD_RDID 0x9F /*!< Read identification */
+#define sFLASH_CMD_SE_4K 0x20 /*0x20:4K < Sector Erase instruction */
+#define sFLASH_CMD_BE_32K 0x52 /*0x52:32K !< Block Erase instruction */
+#define sFLASH_CMD_BE_64K 0xD8 /*0xD8:64K !< Block Erase instruction */
+#define sFLASH_CMD_SE sFLASH_CMD_SE_4K /*0x20:4K, 0x52:32K, 0xD8:64K !< Sector Erase instruction */
+#define sFLASH_SECT_SZ 0x1000 //4k
+
+#define sFLASH_CMD_BE 0xC7 /*!< Bulk Erase instruction */
+#define sFLAsh_CMD_POWERDOWN 0xB9
+#define sFLAsh_CMD_POWERUP 0xAB
+
+#define sFLASH_WIP_FLAG 0x01 /*!< Write In Progress (WIP) flag */
+
+#define sFLASH_DUMMY_BYTE 0xA5
+#define sFLASH_SPI_PAGESIZE 0x100
+
+#define sFLASH_M25P128_ID 0x202018
+#define sFLASH_M25P64_ID 0x202017
+#define sFLASH_W25Q64JV_ID 0xEF4017
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32_EVAL_SPI_FLASH_Exported_Functions
+ * @{
+ */
+/**
+ * @brief High layer functions
+ */
+void sFLASH_DeInit(void);
+int32_t sFLASH_Init(void);
+void sFLASH_EraseSector(uint32_t SectorAddr);
+void sFLASH_EraseBulk(void);
+int32_t sFLASH_EraseBlock(uint32_t SectorAddr, uint32_t sect_sz );
+void sFLASH_WritePage(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
+void sFLASH_WriteBuffer(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
+void sFLASH_ReadBuffer(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
+uint32_t sFLASH_ReadID(void);
+void sFLASH_StartReadSequence(uint32_t ReadAddr);
+
+/**
+ * @brief Low layer functions
+ */
+uint8_t sFLASH_ReadByte(void);
+uint8_t sFLASH_SendByte(uint8_t byte);
+uint16_t sFLASH_SendHalfWord(uint16_t HalfWord);
+void sFLASH_WriteEnable(void);
+void sFLASH_WaitForWriteEnd(void);
+
+
+uint32_t sFLASH_ReadSum( void );
+
+void sFLASH_PowerOff(void);
+void sFLASH_PowerOn(void);
+
+int32_t user_sflash_erase( uint32_t addr, uint32_t sz );
+int32_t user_sflash_write( uint32_t addr, uint8_t *data, uint32_t sz );
+uint32_t user_sflash_crc16( uint32_t addr, uint32_t sz );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __USER_SFLASH_H */
#include "user.h"
#include "user_tcp.h"
+#include "user_sflash.h"
/*
static uint16_t tx_pkt_sn = 0;
static uint16_t rx_pkt_sn;
-void Tcp_Server_Init(void)
+void tcp_server_init(void)
{
/* Ϊtcp·þÎñÆ÷·ÖÅäÒ»¸ötcp_pcb½á¹¹Ìå */
FLAG SN CMD LEN DATA CRC
55AA 0002 0001 0008 XX... XXXX
CMD:
- 0001: query LEN 0 query period:5s
- 0002: resp LEN 32 , DATA: noise + alarm + pos + wind
- 1001: Lora Tx
- 1002: Lora Rx
- 2001: BD Tx
- 2002: BD Rx
- 3001: Laki Tx
- 3002: Laki Rx
-
- FFFF: Debug get adc raw data
-
+ 0001: query LEN 0 query period:5s
+ 0002: resp LEN 32 , DATA: noise + alarm + pos + wind
+ 1001: Lora Tx
+ 1002: Lora Rx
+ 2001: BD Tx
+ 2002: BD Rx
+ 3001: Laki Tx
+ 3002: Laki Rx
+
+ FFFF: Debug get adc raw data
+*/
+/*
+ //TODO:
+ F001: fw_ver/16B fw_size/4 fw_crc16/4
+ F002: sfash_erase
+ F003: sflash_write
+ F004: sflash_read
+ F005: sflash_read_crc
*/
int32_t wrap_pkt( uint8_t *buf, uint16_t sn, uint16_t cmd, uint8_t *data, uint32_t data_sz )
int g_adc_debug = 0;
extern int32_t g_alarm;
+extern const char SW_VER[16];
+extern void put_b_u32( uint32_t value, uint8_t *data );
+extern uint32_t get_b_u32( uint8_t *data );
+extern uint32_t code_size( void );
+extern uint32_t code_crc16( void );
+extern uint16_t user_crc16( uint8_t *data, uint32_t sz );
int32_t tcp_recv_cb(struct tcp_pcb *pcb, uint8_t *data, uint32_t len )
{
uint16_t recv_pkt_sn;
uint16_t cmd;
uint16_t pkt_data_sz;
- //uint8_t *pkt_data;
+ uint8_t *pkt_data;
uint16_t pkt_crc;
uint8_t resp[64];
uint16_t resp_sz = 0;
recv_pkt_sn = (p[2]<<8)|p[3];
cmd = (p[4]<<8)|p[5];
pkt_data_sz = (p[6]<<8)|p[7];
- //pkt_data = p+8;
+ pkt_data = p+8;
pkt_crc = (p[8+pkt_data_sz]<<8)|p[8+pkt_data_sz+1];
if( (recv_pkt_sn != rx_pkt_sn) && pkt_crc == usMBCRC16(p, 8+pkt_data_sz) ){
g_adc_debug = p[8];
}
break;
+ /*-------------------
+ //TODO:
+ F001: fw_ver/16B fw_size/4 fw_crc16/4
+ F002: sfash_erase
+ F003: sflash_write
+ F004: sflash_read
+ F005: sflash_read_crc
+ F006: system restart
+ -------------------*/
+ case 0xF001:
+ memset( resp_data, 0, sizeof(resp_data ) );
+ strncpy( (char*)resp_data, &SW_VER[0], 16 );
+ put_b_u32( code_size(), &resp_data[16] );
+ put_b_u32( code_crc16(), &resp_data[20] );
+ resp_sz = wrap_pkt( resp, rx_pkt_sn, 0xF001, resp_data, 24 );
+ break;
+ case 0xF002:
+ {
+ uint32_t erase_addr = get_b_u32( &pkt_data[0] );
+ uint32_t erase_sz = get_b_u32( &pkt_data[4] );
+ resp_data[0] = user_sflash_erase( erase_addr, erase_sz )==0?1:0;
+ resp_sz = wrap_pkt( resp, rx_pkt_sn, 0xF002, resp_data, 1 );
+ }
+ break;
+ case 0xF003:
+ {
+ uint32_t wr_addr = get_b_u32( &pkt_data[0] );
+ uint32_t wr_sz = pkt_data_sz - 4;
+ uint32_t wr_crc;
+ uint32_t rd_crc;
+
+ user_sflash_write( wr_addr, &pkt_data[4], wr_sz );
+ wr_crc = user_crc16( &pkt_data[4], wr_sz );
+ rd_crc = user_sflash_crc16( wr_addr, wr_sz );
+ resp_data[0] = wr_crc == rd_crc ? 1:0;
+ resp_sz = wrap_pkt( resp, rx_pkt_sn, 0xF003, resp_data, 1 );
+ //debug
+ if( wr_crc != rd_crc ){
+ //DBG_PRINTF( "[%X-%X] write crc:%04X, read rcr:%04X\n",wr_addr, wr_sz, wr_crc, rd_crc );
+ }else{
+ //DBG_PRINTF( "[%X-%X] write/read crc:%04X\n",wr_addr, wr_sz, wr_crc );
+ }
+ break;
+ }
+ case 0xF004:
+ break;
+ case 0xF005:
+ {
+ uint32_t addr = get_b_u32( &pkt_data[0] );
+ uint32_t sz = get_b_u32( &pkt_data[4] );
+ uint32_t crc = get_b_u32( &pkt_data[8] );
+ uint32_t crc_read = user_sflash_crc16( addr, sz );
+ if( crc == crc_read ){
+ resp_data[0] = 1;
+ //debug_printf( "sflash %d--%d, crc32:%08X\n", addr, sz, crc );
+ }else{
+ resp_data[0] = 0;
+ //debug_printf( "sflash %d--%d, crc32:[%08X | %08X]\n", addr, sz, crc, crc_read );
+ }
+ resp_sz = wrap_pkt( resp, rx_pkt_sn, 0xF005, resp_data, 1 );
+ break;
+ }
+ case 0xF006:
+ //systewm restart
+ resp_data[0] = 1;
+ resp_sz = wrap_pkt( resp, rx_pkt_sn, 0xF006, resp_data, 1 );
+ tcp_write( pcb, resp, resp_sz, TCP_WRITE_FLAG_COPY );
+ osDelay(1000);
+ HAL_NVIC_SystemReset();
+ return 0;
}
if( resp_sz ){
tcp_write( pcb, resp, resp_sz, TCP_WRITE_FLAG_COPY );
*********************************************************************************************************
*/
-void Tcp_Server_Init(void);
+void tcp_server_init(void);
/*
********************************************************************************************************
--- /dev/null
+#include "lwip/debug.h"
+#include "lwip/stats.h"
+#include "lwip/udp.h"
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "user.h"
+#include "user_udp.h"
+#include "user_sflash.h"
+
+
+/*
+*********************************************************************************************************
+* LOCAL TABLES
+*********************************************************************************************************
+*/
+
+#define PKT_HEADER_LEN 10 //flag + sn + cmd + dlen + crc = 10
+
+typedef struct{
+ uint16_t flag; //FF00-²éѯ/FF01-Ó¦´ð'
+ uint16_t sn; //°üÐòÁкÅ
+ uint16_t cmd; //ÃüÁîÂë
+ uint16_t dlen; //Êý¾Ý¶Î³¤¶È ºóÃæÊý¾Ý¶Î³¤¶È£¬¿ÉÒÔΪ0£»
+ uint8_t* pdata; //Ö¸ÏòÊý¾Ý×Ö¶Î, Êý¾Ý³¤¶È0µ½ffff;
+ uint16_t crc; //×ܸöÊý¾Ý°üµÄУÑéÖµ£¬crc-16/modbus
+}udp_pkt_t;
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+#define UDP_SERVER_PORT 10000 /* define the UDP local connection port */
+#define UDP_CLIENT_PORT 10000 /* define the UDP remote connection port */
+
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+extern int32_t udp_recv_cb( udp_pcb_t *upcb, ip_addr_t * tx_ip, uint16_t tx_port, uint8_t *rx_data, uint32_t rx_sz );
+
+typedef struct {
+ struct udp_pcb *upcb;
+ ip_addr_t remote_addr;
+ uint16_t remote_port;
+}udp_senssion_t;
+
+static udp_senssion_t g_udp={NULL, NULL, 0 };
+
+
+/* Private function prototypes -----------------------------------------------*/
+void udp_server_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port);
+int32_t udp_tx( udp_pcb_t *upcb, ip_addr_t * tx_ip, uint16_t tx_port, uint8_t *tx_data, uint32_t tx_sz );
+
+extern uint16_t usMBCRC16( uint8_t * pucFrame, uint32_t usLen );
+
+extern const char SW_VER[16];
+extern void put_b_u32( uint32_t value, uint8_t *data );
+extern uint32_t get_b_u32( uint8_t *data );
+extern uint32_t code_size( void );
+extern uint32_t code_crc16( void );
+extern uint16_t user_crc16( uint8_t *data, uint32_t sz );
+
+/**
+ * @brief This function is called when an UDP datagrm has been received on the port UDP_PORT.
+ * @param arg user supplied argument (udp_pcb.recv_arg)
+ * @param pcb the udp_pcb which received data
+ * @param p the packet buffer that was received
+ * @param addr the remote IP address from which the packet was received
+ * @param port the remote port from which the packet was received
+ * @retval None
+ */
+int32_t udp_tx( udp_pcb_t *upcb, ip_addr_t * tx_ip, uint16_t tx_port, uint8_t *tx_data, uint32_t tx_sz )
+{
+ struct pbuf *p;
+
+ //tick = osKernelGetTickCount()/portTICK_PERIOD_MS;
+ //DBG_PRINTF( "[%d.%03d]UDP TX: [", tick/1000, tick%1000 );
+
+ for( int i=0; i<tx_sz; i++ ){
+ //DBG_PRINTF( "%02X ", tx_data[i] );
+ if( i > 40 ){
+ //DBG_PRINTF( " ... " );
+ break;
+ }
+ }
+ //DBG_PRINTF( "]\r\n" );
+
+ p = pbuf_alloc(PBUF_TRANSPORT, tx_sz, PBUF_RAM);
+ if( p ){
+ pbuf_take( p, tx_data, tx_sz );
+ udp_sendto( upcb, p, tx_ip, tx_port );
+ pbuf_free( p );
+ }
+ return 0;
+}
+
+#define debug_printf printf
+#define DBG_PRINTF printf
+
+void print_rx_pkt( char * str, udp_pkt_t *pkt )
+{
+ uint32_t tick;
+ if( !pkt )
+ return;
+ debug_printf( "----------------------------------------------------\n" );
+ tick = osKernelGetTickCount()/portTICK_PERIOD_MS;
+ debug_printf( "[%d.%03d]", tick/1000, tick%1000 );
+ debug_printf( "%s -- get rx pkt, cmd:%02X, datalen:%d \n", str?str:"", pkt->cmd, pkt->dlen );
+ if( pkt->dlen ){
+ int i = 0;
+ debug_printf( "data:[" );
+ for( i=0; i<pkt->dlen; i++ ){
+ debug_printf( "%02X ", pkt->pdata[i] );
+ if( i>40 ){
+ DBG_PRINTF( " ... " );
+ break;
+ }
+ }
+ debug_printf( " ]\n" );
+ }
+ debug_printf( "----------------------------------------------------\n" );
+}
+
+int32_t get_rx_pkt( uint8_t * data, uint32_t data_size, udp_pkt_t *out_pkt )
+{
+ uint16_t data_len;
+ uint16_t crc16, crc16_recv;
+
+ if( data_size < PKT_HEADER_LEN ){
+ //timeout++;
+ return 0;
+ }
+
+ data_len = (data[6]<<8)|data[7];
+ if( data_size < data_len+PKT_HEADER_LEN ){
+ //timeout
+ return 0;
+ }
+
+ crc16 = user_crc16( data, data_len+PKT_HEADER_LEN - 2 );
+ crc16_recv = (data[data_len+PKT_HEADER_LEN-2]<<8)|data[data_len+PKT_HEADER_LEN-1];
+ if( crc16 != crc16_recv ){
+ return -1;
+ }
+ out_pkt->flag = (data[0]<<8)|data[1];
+ out_pkt->sn = (data[2]<<8)|data[3];
+ out_pkt->cmd = (data[4]<<8)|data[5];
+ out_pkt->dlen = data_len;
+ out_pkt->pdata = &data[8];
+ return 1;
+}
+
+uint16_t wrap_tx_pkt( uint16_t cmd, uint8_t *pkt_buf, uint16_t sn, uint8_t *data, uint16_t data_len )
+{
+ uint16_t crc=0;
+ uint16_t n = 0;
+
+ debug_printf( "wrap_tx_pkt, cmd:%02X, sn:%d, dlen:%d\n", cmd, sn, data_len );
+
+ pkt_buf[n++] = 0xFF; //flag:ff00
+ pkt_buf[n++] = 0x00;
+ pkt_buf[n++] = (sn>>8)&0xff; //sn
+ pkt_buf[n++] = (sn>>0)&0xff;
+ pkt_buf[n++] = (cmd>>8)&0xff; //cmd
+ pkt_buf[n++] = (cmd>>0)&0xff;
+ pkt_buf[n++] = (data_len>>8)&0xff; //dlen
+ pkt_buf[n++] = (data_len>>0)&0xff;
+ memcpy( &pkt_buf[n], data, data_len );
+ n += data_len;
+ crc = user_crc16( pkt_buf, n);
+ pkt_buf[n++] = (crc>>8)&0xff;
+ pkt_buf[n++] = (crc)&0xff;
+ return n;
+}
+static uint8_t txbuf[512];
+int32_t handle_rx_pkt( udp_pcb_t *upcb, udp_pkt_t *pkt, ip_addr_t* ip, uint16_t port )
+{
+ static udp_pkt_t last_pkt_header;
+ uint32_t pkt_retransmitted = 0;
+
+ uint8_t buf[250];
+ uint16_t n = 0;
+// uint16_t tx_n = 0;
+ uint32_t off;
+ uint32_t i;
+ uint8_t can_bus;
+ uint8_t ch;
+
+ if( pkt->flag != 0xff00 ){
+ return -1;
+ }
+
+ if( last_pkt_header.cmd == pkt->cmd && last_pkt_header.sn == pkt->sn ){
+ pkt_retransmitted = 1;
+ //DBG_PRINTF( "RX retransmitted pkt!\n" );
+ }else{
+ pkt_retransmitted = 0;
+ memcpy( &last_pkt_header, pkt, sizeof( last_pkt_header ) );
+ }
+
+ switch( pkt->cmd ){
+ case 0xFF82:
+ //read fw version
+ memset( buf, 0, 24 );
+ strncpy( (char*)buf, VERSION, 16 );
+ //version 16B + SZ 4B + crc32 4B
+ put_b_u32( code_size(), &buf[16] );
+ put_b_u32( code_crc16(), &buf[20] );
+ n = wrap_tx_pkt( pkt->cmd, txbuf, pkt->sn, buf, 24 );
+ udp_tx( upcb, ip, port, txbuf, n );
+ break;
+ case 0xFF83:
+ //systewm restart
+ buf[0] = 1;
+ n = wrap_tx_pkt( pkt->cmd, txbuf, pkt->sn, buf, 1 );
+ udp_tx( upcb, ip, port, txbuf, n );
+ osDelay(1000);
+ HAL_NVIC_SystemReset();
+ break;
+ case 0xFFA0:
+ //sflash erase addr, size
+ {
+ uint32_t erase_addr = get_b_u32( &pkt->pdata[0] );
+ uint32_t erase_sz = get_b_u32( &pkt->pdata[4] );
+ buf[0] = user_sflash_erase( erase_addr, erase_sz )==0?1:0;
+ n = wrap_tx_pkt( pkt->cmd, txbuf, pkt->sn, buf, 1 );
+ udp_tx( upcb, ip, port, txbuf, n );
+ }
+ break;
+ case 0xFFA1:
+ //sflash write addr
+ {
+ uint32_t wr_addr = get_b_u32( &pkt->pdata[0] );
+ uint32_t wr_sz = pkt->dlen - 4;
+ uint32_t wr_crc;
+ uint32_t rd_crc;
+
+ user_sflash_write( wr_addr, &pkt->pdata[4], wr_sz );
+ wr_crc = user_crc16( &pkt->pdata[4], wr_sz );
+ rd_crc = user_sflash_crc16( wr_addr, wr_sz );
+ buf[0] = wr_crc == rd_crc ? 1:0;
+ n = wrap_tx_pkt( pkt->cmd, txbuf, pkt->sn, buf, 1 );
+ udp_tx( upcb, ip, port, txbuf, n );
+ //debug
+ if( wr_crc != rd_crc ){
+ DBG_PRINTF( "[%X-%X] write crc:%04X, read rcr:%04X\n",wr_addr, wr_sz, wr_crc, rd_crc );
+ }else{
+ DBG_PRINTF( "[%X-%X] write/read crc:%04X\n",wr_addr, wr_sz, wr_crc );
+ }
+ }
+ break;
+ case 0xFFA2:
+ //sflash read addr
+ {
+ //uint32_t wr_addr = get_b_u32( &pkt->pdata[0] );
+ //uint32_t wr_sz = pkt->dlen - 4;
+ //buf[0] = user_sflash_write( wr_addr, &pkt->pdata[4], wr_sz )==0?1:0;
+ //n = wrap_tx_pkt( pkt->cmd, txbuf, pkt->sn, buf, 1 );
+ //udp_tx( upcb, ip, port, txbuf, n );
+ }
+ break;
+ case 0xFFA3:
+ //sflash read crc
+ {
+ uint32_t addr = get_b_u32( &pkt->pdata[0] );
+ uint32_t sz = get_b_u32( &pkt->pdata[4] );
+ uint32_t crc = get_b_u32( &pkt->pdata[8] );
+ uint32_t crc_read = user_sflash_crc16( addr, sz );
+ if( crc == crc_read ){
+ buf[0] = 1;
+ debug_printf( "sflash %d--%d, crc16:%08X\n", addr, sz, crc );
+ }else{
+ buf[0] = 0;
+ debug_printf( "sflash %d--%d, crc16:[%08X | %08X]\n", addr, sz, crc, crc_read );
+ }
+ n = wrap_tx_pkt( pkt->cmd, txbuf, pkt->sn, buf, 1 );
+ udp_tx( upcb, ip, port, txbuf, n );
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+int32_t handle_rx_udp_data( udp_pcb_t *upcb, ip_addr_t * tx_ip, uint16_t tx_port, uint8_t *rx_data, uint32_t rx_sz )
+{
+ udp_pkt_t pkt;
+ int32_t ret = 0;
+
+ ret = get_rx_pkt( rx_data, rx_sz, &pkt );
+ if( ret == 1 ){
+ print_rx_pkt( "rx:", &pkt );
+ handle_rx_pkt( upcb, &pkt, tx_ip, tx_port );
+ }else if( ret < 0 ){
+ //udp_rx_count = 0;
+ }else{
+ }
+ return 0;
+}
+
+int32_t udp_recv_cb( udp_pcb_t *upcb, ip_addr_t * tx_ip, uint16_t tx_port, uint8_t *rx_data, uint32_t rx_sz )
+{
+ handle_rx_udp_data( upcb, tx_ip, tx_port, rx_data, rx_sz );
+ return 0;
+}
+
+void udp_server_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *remote_addr, u16_t remote_port)
+{
+ g_udp.upcb = upcb;
+ memcpy( &g_udp.remote_addr, remote_addr, sizeof( ip_addr_t ) );
+ g_udp.remote_port = remote_port;
+
+ /* Connect to the remote client */
+ udp_connect(upcb, remote_addr, remote_port);
+
+ /* Tell the client that we have accepted it */
+
+ #if 1
+ //todo handle rx_data
+ uint8_t *rx_data = pvPortMalloc( p->tot_len );
+ if( rx_data ){
+ if( pbuf_copy_partial( p, rx_data, p->tot_len, 0 ) == p->tot_len ){
+ udp_recv_cb(upcb, (ip_addr_t*)remote_addr, remote_port, rx_data, p->tot_len );
+ }
+ vPortFree( rx_data );
+ }
+ #else
+ //echo client test
+ udp_send(upcb, p);
+ #endif
+
+ /* free the UDP connection, so we can accept new clients */
+ udp_disconnect(upcb);
+
+ /* Free the p buffer */
+ pbuf_free(p);
+
+}
+
+void udp_server_start(void)
+{
+ struct udp_pcb *upcb;
+ err_t err;
+ uint16_t udp_port;
+
+
+ /* Create a new UDP control block */
+ upcb = udp_new();
+
+ if (upcb)
+ {
+ udp_port = 8888;
+ /* Bind the upcb to the UDP_PORT port */
+ /* Using IP_ADDR_ANY allow the upcb to be used by any local interface */
+ err = udp_bind(upcb, IP_ADDR_ANY, udp_port);
+
+ if(err == ERR_OK)
+ {
+ /* Set a receive callback for the upcb */
+ udp_recv(upcb, udp_server_receive_callback, NULL);
+ //DBG_PRINTF( "start udp server, port:%d\r\n", udp_port );
+ }
+ else
+ {
+ udp_remove(upcb);
+ }
+ }
+}
+
+void udp_server_init(void)
+{
+ udp_server_start();
+}
+
--- /dev/null
+#ifndef __UDP_SERVER_H__
+#define __UDP_SERVER_H__
+
+
+void udp_server_init(void);
+
+
+#endif /* TCP_SERVER_H */
rs485_rx_flag = 1;
}
+void rs485_tx_enable( int enabled )
+{
+ HAL_GPIO_WritePin( PA11_RS485_DIR1_GPIO_Port, PA11_RS485_DIR1_Pin, enabled?GPIO_PIN_SET:GPIO_PIN_RESET );
+}
+
int32_t rs485_tx( uint8_t *data, uint16_t sz )
{
uint8_t dummy;
while( HAL_UART_Receive( &huart1, &dummy, 1, 0 ) == HAL_OK){
};
-
+ rs485_tx_enable(1);
HAL_UART_Transmit( &huart1, data, sz, 100 );
-
+ osDelay(1);
+ rs485_tx_enable(0);
return 0;
}
#include "shell.h"
extern UART_HandleTypeDef huart1;
+extern const char SW_VER[16];
#define huart_shell huart1
void version( void )
{
- printf( "Version: V%d.%d\n", SW_VER_MAJOR, SW_VER_MINOR );
+ printf( "Version: %s\n", SW_VER );
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), version, version, version );
shellInit(&shell, shellBuffer, sizeof( shellBuffer));
- printf( "Version:%d.%d\n", SW_VER_MAJOR, SW_VER_MINOR );
+ printf( "Version:%s\n", SW_VER );
shell_uart_rx_start();
for(;;){