terry 2 anni fa
parent
commit
d0cfc370ea

+ 3 - 0
.mxproject

@@ -6,6 +6,9 @@ SourceFiles=..\Core\Src\main.c;..\Core\Src\gpio.c;..\Core\Src\freertos.c;..\Core
 HeaderPath=..\Drivers\STM32F1xx_HAL_Driver\Inc;..\Drivers\STM32F1xx_HAL_Driver\Inc\Legacy;..\Middlewares\Third_Party\FreeRTOS\Source\include;..\Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS;..\Middlewares\Third_Party\FreeRTOS\Source\portable\RVDS\ARM_CM3;..\Drivers\CMSIS\Device\ST\STM32F1xx\Include;..\Drivers\CMSIS\Include;..\Core\Inc;
 CDefines=USE_HAL_DRIVER;STM32F103xE;USE_HAL_DRIVER;USE_HAL_DRIVER;
 
+[]
+SourceFiles=;;
+
 [PreviousGenFiles]
 AdvancedFolderStructure=true
 HeaderFileListSize=9

+ 4 - 3
Core/Inc/iap.h

@@ -8,7 +8,7 @@
 
 
 
-#define Startup_Normal 					((uint32_t)0xFFFFFFFF)	
+#define Startup_Normal 					((uint32_t)0xBBBBBBBB)	
 #define Startup_Update 					((uint32_t)0xAAAAAAAA)	
 #define Startup_APP2  					((uint32_t)0x5555BBBB)	
 #define Jump_app	  					((uint32_t)0x6666CCCC)	
@@ -18,8 +18,8 @@
 #define StartBytes_IAP  	 			((uint32_t)0xA55A55AA) 
 #define EndBytes_IAP    	 			((uint32_t)0x5AA5AA55)
 
-#define ADD_UPDATE_PROG                	((uint32_t)0x08040000U)                          
-#define Application_Buffer_Addr        	((uint32_t)0x08060000U)        
+#define ADD_UPDATE_PROG                	((uint32_t)0x8020000)                          
+#define Application_Buffer_Addr        	((uint32_t)0x8040000)        
 
 #define StartMode_Addr                	((uint32_t)0x807F07A) 
 
@@ -51,6 +51,7 @@ extern uint16_t iapbinMd5[8] ;
 void Process_CMD_IAP_Update(void);
 void Start_BootLoader(void);
 extern uint16_t FileBuffArray[512];
+void iap_load_app(uint32_t appxaddr);
 extern uint16_t FileBuffArray1[512];
 #endif
 

+ 5 - 3
Core/Inc/main.h

@@ -39,12 +39,14 @@ extern "C" {
 /* Exported types ------------------------------------------------------------*/
 /* USER CODE BEGIN ET */
 
+extern void __set_FAULTMASK(uint32_t faultMask);
+
 #define iap_ 1
 
 #if 1
-#define IR_ROM1   0x08000000
+#define IR_ROM1   0x8000000
 #else
-#define IR_ROM1   0x08020000
+#define IR_ROM1   0x8020000
 #endif
 
 
@@ -56,7 +58,7 @@ extern "C" {
 /* USER CODE END EC */
 
 /* Exported macro ------------------------------------------------------------*/
-/* USER CODE BEGIN EM */	
+/* USER CODE BEGIN EM */
 extern uint16_t initial_address;
 extern int nameLength;
 extern int sizeLength ;

+ 19 - 15
Core/Src/dataHandling.c

@@ -143,8 +143,9 @@ void Set_App2_Flag(void)
 	update_flag1[0] = (uint16_t)(update_flag >> 16);
 	Flash_WriteBytes(update_flag1, StartMode_Addr, 2);
 	
-	NVIC_SystemReset();
-	
+//	__set_FAULTMASK(0);			   //ÏȹرÕÈ«¾ÖÖжÏ
+////	
+//	HAL_NVIC_SystemReset();
 	
 }
 
@@ -250,14 +251,14 @@ void Set_Update_Down(void)
 	memcpy(&update_flag1, &update_flag, sizeof(uint16_t) * 2);
 	Flash_WriteBytes(update_flag1, StartMode_Addr, sizeof(update_flag1));
 	
-	int txLen = sprintf((char *)USART_IAP_RX, "reboot\r\n");
-	HAL_UART_Transmit_IT(&huart1,USART_IAP_RX,txLen);		
-	while (huart1.gState == HAL_UART_STATE_BUSY_TX)
-	{
-		HAL_Delay(1);
-	}
+//	int txLen = sprintf((char *)USART_IAP_RX, "reboot\r\n");
+//	HAL_UART_Transmit_IT(&huart1,USART_IAP_RX,txLen);		
+//	while (huart1.gState == HAL_UART_STATE_BUSY_TX)
+//	{
+//		HAL_Delay(1);
+//	}
 	
-	__NOP();__NOP();
+//	__NOP();__NOP();
 //	__disable_irq();
 	NVIC_SystemReset();
 }
@@ -358,22 +359,25 @@ void iap_write_appbin(uint32_t appxaddr, uint32_t appbuf, uint32_t appsize)
 	
 	for( z =1; z<=pagesize ;z++)
 	{
+		
 		HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
-		HAL_Delay(1);  
+		HAL_Delay(5);  
 		HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
+		
 		Flash_ReadBytes(&iapbuf[0], fwaddr, 2048);//2048
 		Flash_WriteBytes(&iapbuf[0],addrtowrite,1024);
 		delay_sys_us(80);
-		
-		
-		
-		memset(iapbuf, 0, sizeof(iapbuf));	
+			
+//		memset(iapbuf, 0, sizeof(iapbuf));	
 		int txLen;
 		txLen = sprintf((char *)USART_IAP_RX, "%s%d\r\n", ACK_Arr,z);
 		HAL_UART_Transmit_IT(&huart1,USART_IAP_RX,txLen);	
 
 		fwaddr = fwaddr + 0x800;
-		addrtowrite = addrtowrite + 0x800;		
+		addrtowrite = addrtowrite + 0x800;	
+		HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
+		HAL_Delay(5);  
+		HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);	
 
 	}
 	

+ 70 - 40
Core/Src/iap.c

@@ -6,25 +6,37 @@
 #include "dataHandling.h"
 #include "md5c.h"
 
-extern void __set_FAULTMASK(uint32_t faultMask);
-/* 采用汇编设置栈的值 */
-__asm void MSR_MSP(unsigned int ulAddr)
+typedef  void (*iapfun)(void);	
+iapfun jump2app;
+
+__asm void MSR_MSP(uint32_t addr) 
+{
+    MSR MSP, r0 			//set Main Stack value
+    BX r14
+}
+
+void iap_load_app(uint32_t appxaddr)
 {
-    MSR MSP, r0 // 设置主堆栈指针的值为r0寄存器的值
-    BX r14 			// 返回到调用子程序并使用r14寄存器中的地址
+	if (((*(uint32_t *)appxaddr) & 0x2FFE0000) == 0x20000000) //检查栈顶地址是否合法.
+	{
+		jump2app = (iapfun) * (uint32_t *)(appxaddr + 4); //用户代码区第二个字为程序开始地址(复位地址)
+		MSR_MSP(*(uint32_t *)appxaddr);					  //初始化APP堆栈指针(用户代码区的第一个字用于存放栈顶地址)
+		jump2app();										  //跳转到APP.
+	}
 }
 
-typedef void (*Jump_Fun)(void);
-void IAP_ExecuteApp(unsigned int App_Addr)
+typedef void (*pFunction)(void);
+void jump_to_app(uint32_t app_addr)
 {
-    Jump_Fun JumpToApp;
-
-    if (((*(__IO unsigned int *)App_Addr) & 0x2FFE0000) == 0x20000000) //检查栈顶地址是否合法.
-    {
-        JumpToApp = (Jump_Fun) * (__IO unsigned int *)(App_Addr + 4); //用户代码区第二个字为程序开始地址(复位地址)
-        MSR_MSP(*(__IO unsigned int *)App_Addr); //初始化APP堆栈指针(用户代码区的第一个字用于存放栈顶地址)
-        JumpToApp(); //跳转到APP.
-    }
+    // Step 1: 关闭中断
+    __disable_irq();
+    
+    // Step 2: 将设备的运行代码地址设置为主堆栈指针(MSP)
+    __set_MSP(*(volatile uint32_t*)app_addr);
+    
+    // Step 3: 跳转到设备的运行代码
+    pFunction app_entry = (pFunction)(*(volatile uint32_t*)(app_addr + 4));
+    app_entry();
 }
 
 uint8_t YmodemID;
@@ -261,6 +273,7 @@ void Process_CMD_IAP_Update(void)
 					{
 						
 						Set_Update_Down(); //设定标志位  下次启动时进行程序拷贝
+						
 					}else{
 						int	txLen = sprintf((char *)USART_IAP_RX,"check=error\r\n");
 						delay_sys_us(80);
@@ -303,29 +316,32 @@ void Start_BootLoader(void)
 	int tag;
 	int txLen;
 	memset(USART_IAP_RX, 0, sizeof(USART_IAP_RX));	
-	uint16_t pagenum =  (all_len+2048)/2048;
+	
+	
+    update_iaplength(LENGTH_ADDR);
+//	uint16_t pagenum =  (all_len+2048)/2048;
 	
 	switch (ModeStart)
 	{
 		case Startup_Normal: // 正常启动  在APP2中可以设定此标志位   使得下次重启之后进入APP1
 		{
-			txLen = sprintf((char *)USART_IAP_RX, "normalStart");
-			
-			HAL_UART_Transmit_IT(&huart1,USART_IAP_RX,txLen);		
+//			txLen = sprintf((char *)USART_IAP_RX, "normalStart");
+//			HAL_UART_Transmit_IT(&huart1,USART_IAP_RX,txLen);		
 			break;
 		}
 		
+		
 		case Startup_Update: /*启动最新的程序 */
-			{
-				FLASH_EraseInitTypeDef erase_init;
-				erase_init.TypeErase = FLASH_TYPEERASE_PAGES;  // 擦除类型为页擦除
-				erase_init.PageAddress = ADD_UPDATE_PROG;  
-				erase_init.NbPages = pagenum;  // 擦除的页数
-				uint32_t page_error = 0;
-				HAL_FLASH_Unlock();  // 解锁Flash
-				HAL_StatusTypeDef status = HAL_FLASHEx_Erase(&erase_init, &page_error);  // 执行擦除操作
-				HAL_FLASH_Lock();  // 上锁Flash
-			}
+//			{
+//				FLASH_EraseInitTypeDef erase_init;
+//				erase_init.TypeErase = FLASH_TYPEERASE_PAGES;  // 擦除类型为页擦除
+//				erase_init.PageAddress = ADD_UPDATE_PROG;  
+//				erase_init.NbPages = pagenum;  // 擦除的页数
+//				uint32_t page_error = 0;
+//				HAL_FLASH_Unlock();  // 解锁Flash
+//				HAL_StatusTypeDef status = HAL_FLASHEx_Erase(&erase_init, &page_error);  // 执行擦除操作
+//				HAL_FLASH_Lock();  // 上锁Flash
+//			}
 			all_len = FileLength_IAP;
 			
 			tag = App2_MD5_Check(Application_Buffer_Addr,all_len);
@@ -333,7 +349,8 @@ void Start_BootLoader(void)
 			{
 				iap_write_appbin(ADD_UPDATE_PROG,Application_Buffer_Addr,all_len);
 
-				txLen = sprintf((char *)USART_IAP_RX, "update\r\n");
+				HAL_Delay(80);
+				txLen = sprintf((char *)USART_IAP_RX, "updating");
 				HAL_UART_Transmit_IT(&huart1,USART_IAP_RX,txLen);		
 				while (huart1.gState == HAL_UART_STATE_BUSY_TX)
 				{
@@ -354,36 +371,49 @@ void Start_BootLoader(void)
 				return ;
 			}	
 			
-			
 			if (App2_MD5_Check(ADD_UPDATE_PROG,all_len))
 			{		
-				txLen = sprintf((char *)USART_IAP_RX, "updateok\r\n");
+				txLen = sprintf((char *)USART_IAP_RX, "checkok");
 				HAL_UART_Transmit_IT(&huart1,USART_IAP_RX,txLen);			
 				while (huart1.gState == HAL_UART_STATE_BUSY_TX)
 				{
 					HAL_Delay(1);
 				}
+				
 				Set_App2_Flag();
+//				iap_load_app(ADD_UPDATE_PROG);
 			}
-			break;
+//			break;
+
 		case Startup_APP2: /*启动最新的程序 */
 
-			txLen = sprintf((char *)USART_IAP_RX, "jump");
-			HAL_UART_Transmit_IT(&huart1,USART_IAP_RX,txLen);		
-			while (huart1.gState == HAL_UART_STATE_BUSY_TX)
+//			txLen = sprintf((char *)USART_IAP_RX, "jump");
+//			HAL_UART_Transmit_IT(&huart1,USART_IAP_RX,txLen);		
+			if ((all_len<0x20000) && App2_MD5_Check(ADD_UPDATE_PROG,all_len))
 			{
-				HAL_Delay(1);
+				__set_FAULTMASK(0);			   //先关闭全局中断
+//				iap_load_app(ADD_UPDATE_PROG); //执行FLASH APP2代码
+				jump_to_app(ADD_UPDATE_PROG);
 			}
 			
 			
-			__set_FAULTMASK(0);		
+//			__set_FAULTMASK(0);		
 //			Set_normal_Flag();
 			
-			IAP_ExecuteApp(ADD_UPDATE_PROG); //执行FLASH APP2代码
+//			HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
+//			HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
+//			Set_App2_Flag();
+//			
+//			__set_FAULTMASK(0);			   //先关闭全局中断
+//			iap_load_app(ADD_UPDATE_PROG);
+			
+			
 
 //			Set_jump_Flag();
-//	
+////	
 //		case Jump_app:
+			
+//			__set_FAULTMASK(0);			   //先关闭全局中断
 ////			Set_normal_Flag();
 //			IAP_ExecuteApp(0x8020000); //执行FLASH APP2代码
 //			

+ 22 - 11
Core/Src/main.c

@@ -54,7 +54,7 @@ uint16_t initial_address = 0x00C1;
 uint16_t BaudrateValue 	 = 0x0000;
 uint32_t System_version  = 0x23080700;
 uint8_t  bufMain[128] 	= {0};
-
+uint32_t scb;
 
 
 /* USER CODE END PV */
@@ -107,23 +107,32 @@ int main(void)
   MX_USART3_UART_Init();
   /* USER CODE BEGIN 2 */
   HAL_TIM_Base_Start_IT(&htim2);
-//更新标定数据  
-  AdcCalibration_init();
-  updateiapMd5(StartMode_Addr);
   update_iaplength(LENGTH_ADDR);
-  read_new_address(addr_FLASH_ADDR); 
-  update_sysVersion(StartMode_Addr+14);
-  updatePbStatus(read_flash_16(pbstatus_FLASH_ADDR));
-  update_baudrate(read_flash_16(baudrate_FLASH_ADDR));
-//更新结束  
 #if	IR_ROM1 == 0x08000000	
    	Start_BootLoader();
 #else	
 	SCB->VTOR = 0x08020000;
 	__set_PRIMASK(0);
 #endif	
-  
 
+//更新标定数据  
+  AdcCalibration_init();
+  updateiapMd5(StartMode_Addr);
+  update_sysVersion(StartMode_Addr+14);
+  read_new_address(addr_FLASH_ADDR); 
+  updatePbStatus(read_flash_16(pbstatus_FLASH_ADDR));
+  update_baudrate(read_flash_16(baudrate_FLASH_ADDR));
+//更新结束  
+
+
+
+//  scb = SCB->VTOR;
+//  if(scb==0x08020000)
+//  {
+//	
+//  }
+	int txLen = sprintf((char *)USART_IAP_RX, "app1");
+	HAL_UART_Transmit_IT(&huart1,USART_IAP_RX,txLen);	
 //  rebootTip = sprintf((char*)bufMain, "reboot ok");
 //  HAL_UART_Transmit(&huart1, bufMain, rebootTip, 300);
   HAL_UART_Receive_DMA(&huart1,USART_PUB_RX,RX_BUF_SIZE); 
@@ -142,7 +151,6 @@ int main(void)
   { 
 
 
-	
     /* USER CODE END WHILE */
 
     /* USER CODE BEGIN 3 */
@@ -512,6 +520,9 @@ void ModBus(void) {
 			&& USART_MODBUS_RX[3] == 0x00 && USART_MODBUS_RX[4] == 0x00 && USART_MODBUS_RX[5] == 0x02){
 
 			receive_modbus_9(initial_address, 0x03, 0x04,  ((System_version >> 16) & 0xFFFF), (System_version & 0xFFFF), 9);
+				
+//			__set_FAULTMASK(0);			   //先关闭全局中断
+//			iap_load_app(0x08020000);
 		}
 
 		else if(USART_MODBUS_RX[0] == (uint8_t)initial_address && USART_MODBUS_RX[1] == 0x06 && USART_MODBUS_RX[2] == 0x00 \

+ 406 - 0
Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c

@@ -0,0 +1,406 @@
+/**
+  ******************************************************************************
+  * @file    system_stm32f1xx.c
+  * @author  MCD Application Team
+  * @brief   CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
+  * 
+  * 1.  This file provides two functions and one global variable to be called from 
+  *     user application:
+  *      - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
+  *                      factors, AHB/APBx prescalers and Flash settings). 
+  *                      This function is called at startup just after reset and 
+  *                      before branch to main program. This call is made inside
+  *                      the "startup_stm32f1xx_xx.s" file.
+  *
+  *      - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
+  *                                  by the user application to setup the SysTick 
+  *                                  timer or configure other parameters.
+  *                                     
+  *      - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
+  *                                 be called whenever the core clock is changed
+  *                                 during program execution.
+  *
+  * 2. After each device reset the HSI (8 MHz) is used as system clock source.
+  *    Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to
+  *    configure the system clock before to branch to main program.
+  *
+  * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on
+  *    the product used), refer to "HSE_VALUE". 
+  *    When HSE is used as system clock source, directly or through PLL, and you
+  *    are using different crystal you have to adapt the HSE value to your own
+  *    configuration.
+  *        
+  ******************************************************************************
+  * @attention
+  *
+  * Copyright (c) 2017-2021 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.
+  *
+  ******************************************************************************
+  */
+
+/** @addtogroup CMSIS
+  * @{
+  */
+
+/** @addtogroup stm32f1xx_system
+  * @{
+  */  
+  
+/** @addtogroup STM32F1xx_System_Private_Includes
+  * @{
+  */
+
+#include "stm32f1xx.h"
+
+/**
+  * @}
+  */
+
+/** @addtogroup STM32F1xx_System_Private_TypesDefinitions
+  * @{
+  */
+
+/**
+  * @}
+  */
+
+/** @addtogroup STM32F1xx_System_Private_Defines
+  * @{
+  */
+
+#if !defined  (HSE_VALUE) 
+  #define HSE_VALUE               8000000U /*!< Default value of the External oscillator in Hz.
+                                                This value can be provided and adapted by the user application. */
+#endif /* HSE_VALUE */
+
+#if !defined  (HSI_VALUE)
+  #define HSI_VALUE               8000000U /*!< Default value of the Internal oscillator in Hz.
+                                                This value can be provided and adapted by the user application. */
+#endif /* HSI_VALUE */
+
+/*!< Uncomment the following line if you need to use external SRAM  */ 
+#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
+/* #define DATA_IN_ExtSRAM */
+#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
+
+/* Note: Following vector table addresses must be defined in line with linker
+         configuration. */
+/*!< Uncomment the following line if you need to relocate the vector table
+     anywhere in Flash or Sram, else the vector table is kept at the automatic
+     remap of boot address selected */
+/* #define USER_VECT_TAB_ADDRESS */
+
+#if defined(USER_VECT_TAB_ADDRESS)
+/*!< Uncomment the following line if you need to relocate your vector Table
+     in Sram else user remap will be done in Flash. */
+/* #define VECT_TAB_SRAM */
+#if defined(VECT_TAB_SRAM)
+#define VECT_TAB_BASE_ADDRESS   SRAM_BASE       /*!< Vector Table base address field.
+                                                     This value must be a multiple of 0x200. */
+#define VECT_TAB_OFFSET         0x00000000U     /*!< Vector Table base offset field.
+                                                     This value must be a multiple of 0x200. */
+#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.
+                                                     This value must be a multiple of 0x200. */
+#endif /* VECT_TAB_SRAM */
+#endif /* USER_VECT_TAB_ADDRESS */
+
+/******************************************************************************/
+
+/**
+  * @}
+  */
+
+/** @addtogroup STM32F1xx_System_Private_Macros
+  * @{
+  */
+
+/**
+  * @}
+  */
+
+/** @addtogroup STM32F1xx_System_Private_Variables
+  * @{
+  */
+
+  /* This variable is updated in three ways:
+      1) by calling CMSIS function SystemCoreClockUpdate()
+      2) by calling HAL API function HAL_RCC_GetHCLKFreq()
+      3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 
+         Note: If you use this function to configure the system clock; then there
+               is no need to call the 2 first functions listed above, since SystemCoreClock
+               variable is updated automatically.
+  */
+uint32_t SystemCoreClock = 16000000;
+const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
+const uint8_t APBPrescTable[8U] =  {0, 0, 0, 0, 1, 2, 3, 4};
+
+/**
+  * @}
+  */
+
+/** @addtogroup STM32F1xx_System_Private_FunctionPrototypes
+  * @{
+  */
+
+#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
+#ifdef DATA_IN_ExtSRAM
+  static void SystemInit_ExtMemCtl(void); 
+#endif /* DATA_IN_ExtSRAM */
+#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
+
+/**
+  * @}
+  */
+
+/** @addtogroup STM32F1xx_System_Private_Functions
+  * @{
+  */
+
+/**
+  * @brief  Setup the microcontroller system
+  *         Initialize the Embedded Flash Interface, the PLL and update the 
+  *         SystemCoreClock variable.
+  * @note   This function should be used only after reset.
+  * @param  None
+  * @retval None
+  */
+void SystemInit (void)
+{
+#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
+  #ifdef DATA_IN_ExtSRAM
+    SystemInit_ExtMemCtl(); 
+  #endif /* DATA_IN_ExtSRAM */
+#endif 
+
+  /* Configure the Vector Table location -------------------------------------*/
+#if defined(USER_VECT_TAB_ADDRESS)
+  SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
+#endif /* USER_VECT_TAB_ADDRESS */
+}
+
+/**
+  * @brief  Update SystemCoreClock variable according to Clock Register Values.
+  *         The SystemCoreClock variable contains the core clock (HCLK), it can
+  *         be used by the user application to setup the SysTick timer or configure
+  *         other parameters.
+  *           
+  * @note   Each time the core clock (HCLK) changes, this function must be called
+  *         to update SystemCoreClock variable value. Otherwise, any configuration
+  *         based on this variable will be incorrect.         
+  *     
+  * @note   - The system frequency computed by this function is not the real 
+  *           frequency in the chip. It is calculated based on the predefined 
+  *           constant and the selected clock source:
+  *             
+  *           - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
+  *                                              
+  *           - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
+  *                          
+  *           - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) 
+  *             or HSI_VALUE(*) multiplied by the PLL factors.
+  *         
+  *         (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value
+  *             8 MHz) but the real value may vary depending on the variations
+  *             in voltage and temperature.   
+  *    
+  *         (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value
+  *              8 MHz or 25 MHz, depending on the product used), user has to ensure
+  *              that HSE_VALUE is same as the real frequency of the crystal used.
+  *              Otherwise, this function may have wrong result.
+  *                
+  *         - The result of this function could be not correct when using fractional
+  *           value for HSE crystal.
+  * @param  None
+  * @retval None
+  */
+void SystemCoreClockUpdate (void)
+{
+  uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U;
+
+#if defined(STM32F105xC) || defined(STM32F107xC)
+  uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U;
+#endif /* STM32F105xC */
+
+#if defined(STM32F100xB) || defined(STM32F100xE)
+  uint32_t prediv1factor = 0U;
+#endif /* STM32F100xB or STM32F100xE */
+    
+  /* Get SYSCLK source -------------------------------------------------------*/
+  tmp = RCC->CFGR & RCC_CFGR_SWS;
+  
+  switch (tmp)
+  {
+    case 0x00U:  /* HSI used as system clock */
+      SystemCoreClock = HSI_VALUE;
+      break;
+    case 0x04U:  /* HSE used as system clock */
+      SystemCoreClock = HSE_VALUE;
+      break;
+    case 0x08U:  /* PLL used as system clock */
+
+      /* Get PLL clock source and multiplication factor ----------------------*/
+      pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
+      pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
+      
+#if !defined(STM32F105xC) && !defined(STM32F107xC)      
+      pllmull = ( pllmull >> 18U) + 2U;
+      
+      if (pllsource == 0x00U)
+      {
+        /* HSI oscillator clock divided by 2 selected as PLL clock entry */
+        SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
+      }
+      else
+      {
+ #if defined(STM32F100xB) || defined(STM32F100xE)
+       prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
+       /* HSE oscillator clock selected as PREDIV1 clock entry */
+       SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; 
+ #else
+        /* HSE selected as PLL clock entry */
+        if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET)
+        {/* HSE oscillator clock divided by 2 */
+          SystemCoreClock = (HSE_VALUE >> 1U) * pllmull;
+        }
+        else
+        {
+          SystemCoreClock = HSE_VALUE * pllmull;
+        }
+ #endif
+      }
+#else
+      pllmull = pllmull >> 18U;
+      
+      if (pllmull != 0x0DU)
+      {
+         pllmull += 2U;
+      }
+      else
+      { /* PLL multiplication factor = PLL input clock * 6.5 */
+        pllmull = 13U / 2U; 
+      }
+            
+      if (pllsource == 0x00U)
+      {
+        /* HSI oscillator clock divided by 2 selected as PLL clock entry */
+        SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
+      }
+      else
+      {/* PREDIV1 selected as PLL clock entry */
+        
+        /* Get PREDIV1 clock source and division factor */
+        prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
+        prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
+        
+        if (prediv1source == 0U)
+        { 
+          /* HSE oscillator clock selected as PREDIV1 clock entry */
+          SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;          
+        }
+        else
+        {/* PLL2 clock selected as PREDIV1 clock entry */
+          
+          /* Get PREDIV2 division factor and PLL2 multiplication factor */
+          prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U;
+          pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; 
+          SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;                         
+        }
+      }
+#endif /* STM32F105xC */ 
+      break;
+
+    default:
+      SystemCoreClock = HSI_VALUE;
+      break;
+  }
+  
+  /* Compute HCLK clock frequency ----------------*/
+  /* Get HCLK prescaler */
+  tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
+  /* HCLK clock frequency */
+  SystemCoreClock >>= tmp;  
+}
+
+#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
+/**
+  * @brief  Setup the external memory controller. Called in startup_stm32f1xx.s 
+  *          before jump to __main
+  * @param  None
+  * @retval None
+  */ 
+#ifdef DATA_IN_ExtSRAM
+/**
+  * @brief  Setup the external memory controller. 
+  *         Called in startup_stm32f1xx_xx.s/.c before jump to main.
+  *         This function configures the external SRAM mounted on STM3210E-EVAL
+  *         board (STM32 High density devices). This SRAM will be used as program
+  *         data memory (including heap and stack).
+  * @param  None
+  * @retval None
+  */ 
+void SystemInit_ExtMemCtl(void) 
+{
+  __IO uint32_t tmpreg;
+  /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is 
+    required, then adjust the Register Addresses */
+
+  /* Enable FSMC clock */
+  RCC->AHBENR = 0x00000114U;
+
+  /* Delay after an RCC peripheral clock enabling */
+  tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN);
+  
+  /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
+  RCC->APB2ENR = 0x000001E0U;
+  
+  /* Delay after an RCC peripheral clock enabling */
+  tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);
+
+  (void)(tmpreg);
+  
+/* ---------------  SRAM Data lines, NOE and NWE configuration ---------------*/
+/*----------------  SRAM Address lines configuration -------------------------*/
+/*----------------  NOE and NWE configuration --------------------------------*/  
+/*----------------  NE3 configuration ----------------------------------------*/
+/*----------------  NBL0, NBL1 configuration ---------------------------------*/
+  
+  GPIOD->CRL = 0x44BB44BBU;  
+  GPIOD->CRH = 0xBBBBBBBBU;
+
+  GPIOE->CRL = 0xB44444BBU;  
+  GPIOE->CRH = 0xBBBBBBBBU;
+
+  GPIOF->CRL = 0x44BBBBBBU;  
+  GPIOF->CRH = 0xBBBB4444U;
+
+  GPIOG->CRL = 0x44BBBBBBU;  
+  GPIOG->CRH = 0x444B4B44U;
+   
+/*----------------  FSMC Configuration ---------------------------------------*/  
+/*----------------  Enable FSMC Bank1_SRAM Bank ------------------------------*/
+  
+  FSMC_Bank1->BTCR[4U] = 0x00001091U;
+  FSMC_Bank1->BTCR[5U] = 0x00110212U;
+}
+#endif /* DATA_IN_ExtSRAM */
+#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+  
+/**
+  * @}
+  */

+ 4 - 4
MDK-ARM/iocollect.uvoptx

@@ -140,7 +140,7 @@
         <SetRegEntry>
           <Number>0</Number>
           <Key>JL2CM3</Key>
-          <Name>-U69618568 -O76 -S4 -ZTIFSpeedSel2000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8001 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO31 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_512.FLM -FS08000000 -FL080000 -FP0($$Device:STM32F103RE$Flash\STM32F10x_512.FLM)</Name>
+          <Name>-U69618568 -O76 -S4 -ZTIFSpeedSel2000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8001 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO31 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_512.FLM -FS08000000 -FL010000 -FP0($$Device:STM32F103RE$Flash\STM32F10x_512.FLM)</Name>
         </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
@@ -203,7 +203,7 @@
         <Ww>
           <count>9</count>
           <WinNumber>1</WinNumber>
-          <ItemText>z</ItemText>
+          <ItemText>scb</ItemText>
         </Ww>
       </WatchWindow1>
       <WatchWindow2>
@@ -251,7 +251,7 @@
       <DebugFlag>
         <trace>0</trace>
         <periodic>1</periodic>
-        <aLwin>0</aLwin>
+        <aLwin>1</aLwin>
         <aCover>0</aCover>
         <aSer1>0</aSer1>
         <aSer2>0</aSer2>
@@ -351,7 +351,7 @@
       <GroupNumber>2</GroupNumber>
       <FileNumber>4</FileNumber>
       <FileType>1</FileType>
-      <tvExp>1</tvExp>
+      <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
       <PathWithFileName>../Core/Src/main.c</PathWithFileName>

+ 1 - 1
MDK-ARM/iocollect.uvprojx

@@ -277,7 +277,7 @@
               <OCR_RVCT4>
                 <Type>1</Type>
                 <StartAddress>0x8000000</StartAddress>
-                <Size>0x80000</Size>
+                <Size>0x10000</Size>
               </OCR_RVCT4>
               <OCR_RVCT5>
                 <Type>1</Type>

BIN
Output/iocollect_23080700.bin


File diff suppressed because it is too large
+ 2117 - 2125
Output/iocollect_23080700.hex


+ 1 - 1
iocollect.ioc

@@ -238,7 +238,7 @@ SH.ADCx_IN12.ConfNb=1
 TIM2.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
 TIM2.IPParameters=Prescaler,Period,AutoReloadPreload
 TIM2.Period=8000-1
-TIM2.Prescaler=4800-1
+TIM2.Prescaler=800-1
 USART1.BaudRate=9600
 USART1.IPParameters=VirtualMode,BaudRate
 USART1.VirtualMode=VM_ASYNC