/** * @brief Main program. * @param None * @retval None */ int main(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Flash unlock */ FLASH_Unlock(); /* Judge STM3210b-LK1 Key2 - PD3 */ /* Enable GPIOD clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); /* Configure PD.00 pin as input floating */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOD, &GPIO_InitStructure); /* Test if Key push-button on STM3210X-EVAL Board is pressed */ if (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3) == 0x00) { /* If Key is pressed */ /* Execute the IAP driver in order to re-program the Flash */ IAP_Init(); SerialPutString("\r\n======================================================================"); SerialPutString("\r\n= (C) COPYRIGHT 2010 STMicroelectronics ="); SerialPutString("\r\n= ="); SerialPutString("\r\n= In-Application Programming Application (Version 3.3.0) ="); SerialPutString("\r\n= ="); SerialPutString("\r\n= By MCD Application Team ="); SerialPutString("\r\n======================================================================"); SerialPutString("\r\n\r\n"); Main_Menu (); } /* Keep the user application running */ else { /* Test if user code is programmed starting from address "ApplicationAddress" */ if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000) { /* Jump to user application */ JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4); Jump_To_Application = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ __set_MSP(*(__IO uint32_t*) ApplicationAddress); Jump_To_Application(); } } while (1) {} }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* STM32F103xG HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Set NVIC Group Priority to 4 - Low Level Initialization */ HAL_Init(); /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize Key Button mounted on STM3210E-EVAL RevD board */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); /* Test if Key push-button on STM3210E-EVAL RevD Board is pressed */ if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { /* Initialise Flash */ FLASH_If_Init(); /* Execute the IAP driver in order to reprogram the Flash */ IAP_Init(); /* Display main menu */ Main_Menu (); } /* Keep the user application running */ else { /* Test if user code is programmed starting from address "APPLICATION_ADDRESS" */ if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000) { /* Jump to user application */ JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4); JumpToApplication = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS); JumpToApplication(); } } while (1) {} }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* Flash unlock */ FLASH_Unlock(); /* Initialize Key Button mounted on STM3210X-EVAL board */ STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* Test if Key push-button on STM3210X-EVAL Board is pressed */ if (STM_EVAL_PBGetState(BUTTON_KEY) == 0x00) { /* If Key is pressed */ /* Execute the IAP driver in order to re-program the Flash */ IAP_Init(); SerialPutString("\r\n======================================================================"); SerialPutString("\r\n= (C) COPYRIGHT 2010 STMicroelectronics ="); SerialPutString("\r\n= ="); SerialPutString("\r\n= In-Application Programming Application (Version 3.3.0) ="); SerialPutString("\r\n= ="); SerialPutString("\r\n= By MCD Application Team ="); SerialPutString("\r\n======================================================================"); SerialPutString("\r\n\r\n"); Main_Menu (); } /* Keep the user application running */ else { /* Test if user code is programmed starting from address "ApplicationAddress" */ if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000) { /* Jump to user application */ JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4); Jump_To_Application = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ __set_MSP(*(__IO uint32_t*) ApplicationAddress); Jump_To_Application(); } } while (1) {} }
/*=====================================================================================================*/ int main( void ) { SystemInit(); GPIO_Config(); if(KEY_BO == 1) { IAP_Init(); IAP_Download(); Delay_10ms(10); IAP_JumpToApp(); } else { if(((*(vu32*)(IAP_APP_ADDR)) & 0x2FFE0000 ) == 0x20000000) IAP_JumpToApp(); } while(1) { } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* Reset of all peripherals, Initializes the Systick. */ HAL_Init(); /* Configure the system clock to have a system clock = 168 Mhz */ SystemClock_Config(); /* Initialize Key Button mounted on STM324xG-EVAL board */ BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); /* Test if Key push-button is pressed */ if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { /* Execute the IAP driver in order to reprogram the Flash */ IAP_Init(); /* Display main menu */ Main_Menu (); } /* Keep the user application running */ else { /* Test if user code is programmed starting from address "APPLICATION_ADDRESS" */ if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000) { /* Jump to user application */ JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4); JumpToApplication = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS); JumpToApplication(); } } while (1) {} }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*Clock initialization. */ clock_init(); /* Flash unlock */ FLASH_Unlock(); /*GPIO Initialization. */ /*GPIOA, GPIOB on APB2 bus clock enable. */ RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_AFIOEN; /*PA0, PA1, PA2, PA3 in output mode general purpose push-pull. */ GPIOA->CRL =(0x03 << (3 * 4)) | (0x03 << (2 * 4)) | (0x03 << (1 * 4)) | (0x03 << (0 * 4)); /*PB0, PB1 in floating input mode. */ GPIOB->CRL = (0x08 << (1 * 4)) | (0x08 << (0 * 4)); /*why do we do this?. */ GPIOB->ODR |= GPIO_ODR_ODR0 | GPIO_ODR_ODR1; /*Light up all leds by resetting the output bits. */ GPIOA->BSRR |= GPIO_BSRR_BR0 | GPIO_BSRR_BR1 | GPIO_BSRR_BR2 | GPIO_BSRR_BR3; /* Initialize Key Button mounted on STM3210X-EVAL board */ //STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); /* Test if button on the board is pressed during reset. */ if ((GPIOB->IDR & GPIO_IDR_IDR1) == 0x00) { /* If Key is pressed */ /* Execute the IAP driver in order to re-program the Flash */ IAP_Init(); SerialPutString("\r\n======================================================================"); SerialPutString("\r\n= (C) COPYRIGHT 2010 STMicroelectronics ="); SerialPutString("\r\n= ="); SerialPutString("\r\n= In-Application Programming Application (Version 3.3.0) ="); SerialPutString("\r\n= ="); SerialPutString("\r\n= By MCD Application Team ="); SerialPutString("\r\n======================================================================"); SerialPutString("\r\n\r\n"); Main_Menu (); } /* Keep the user application running */ else { /* Test if user code is programmed starting from address "ApplicationAddress" */ uint32_t pippo1, pippo2; pippo1 = (*(__IO uint32_t*)ApplicationAddress); // 0x08000000 what is this value pippo2 = pippo1 & 0x2FFE0000; if (pippo2 == 0x20000000) { /* Jump to user application */ /* JumpAddress is not a pointer type. */ /* ApplicationAddress+4 casted to a pointer to uin32_t. Jump address is the content * of the cell pointed by ApplicationAddress * Though wouldn't this be correct: JumpAddress = ApplicationAddress+4; * or! why does it dereferences it? */ JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4); /*Jump_To_Application now points to the same address = JumpAddress through casting. */ Jump_To_Application = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ /* __set_MSP implemented in CMSIS (as all the functions __* like). */ __set_MSP(*(__IO uint32_t*) ApplicationAddress); Jump_To_Application(); } } while (1) {} }
/******************************************************************************* * @函数名称 main * @函数说明 主函数 * @输入参数 无 * @输出参数 无 * @返回参数 无 *******************************************************************************/ int main(void) { uint8_t fuf=0; uint8_t fu_e=1; //固件更新使能 uint8_t i=0; uint8_t hui[32]= {0x04,0x04,0xF4,0x54,0x54,0x54,0x54,0xFF,0x54,0x54,0x54,0x54,0xF4,0x04,0x04,0x00, 0x40,0x30,0x01,0x01,0x39,0x41,0x41,0x45,0x59,0x41,0x41,0x71,0x01,0x08,0x30,0x00};/*"恵",0*/ SystemTick_Init(); NVIC_Configuration(); oled_control_Init(); OLED_ON; OLED_Init(); SPI_FLASH_Init(); //SPI接口初始化 FLASH_Unlock(); //STM32内部Flash 解锁 //LED_Configuration(); //配置按键 KEY_Configuration();//按钮对应的PB5脚初始化 IAP_Init(); //即串口1初始化,但是没有串口中断程序 buzzer_control_Init(); coil_control_Init(); // OLED_Clear(); // OLED_ShowUnite(24,2,"if updata"); // OLED_ShowUnite(28,4,"press OK"); // delay_ms(500); // while(i<5) // { // OLED_Clear(); // OLED_DrawBMP(32,2,48,4,hui); // OLED_ShowUnite(48,2," 科 "); // OLED_ShowUnite(32,4," 合 技"); // delay_ms(500); // // OLED_Clear(); // OLED_ShowUnite(32,2," 合 技"); // OLED_DrawBMP(32,4,48,6,hui); // OLED_ShowUnite(48,4," 科 "); // delay_ms(500); // // i++; // } // OLED_Clear(); // OLED_DrawBMP(32,2,48,4,hui); // OLED_ShowUnite(48,2,"合科技"); // delay_ms(800); //测试发送 // while(1) // { // Send_Byte(ACK); //收到上位机发送的第0帧之后发送ACK命令 // Send_Byte(CRC16); //接着再发送C,表示等待上位机发送数据帧 // } //按键是否按下 //if (GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5) == 0x00) /* 出厂时,下载程序的步骤: 1.下载字库 2.下载IAP 3.下载应用程序 */ //在下载字库时,先将FIRMWARE_UPGRADE_FLAG标志置为1,所以再下载IAP程序时会直接进入固件更新 SPI_FLASH_Read(&fuf,FIRMWARE_UPGRADE_FLAG,1); if(fuf==1) { OLED_Clear(); //OLED_ShowUnite(16,2,"固件更新中..."); OLED_ShowUnite(32,2,"to updata"); delay_ms(500); //假如按键按下 //执行IAP驱动程序更新Flash程序 SerialPutString("\r\n======================================================================"); SerialPutString("\r\n= (C) COPYRIGHT 2011 Lierda ="); SerialPutString("\r\n= ="); SerialPutString("\r\n= In-Application Programming Application (Version 1.0.0) ="); SerialPutString("\r\n= ="); SerialPutString("\r\n= By wuguoyan ="); SerialPutString("\r\n======================================================================"); SerialPutString("\r\n\r\n"); Main_Menu(); } //否则执行用户程序 else { /* 在程序里#define ApplicationAddress 0x8003000 ,*(__IO uint32_t*)ApplicationAddress) 即取0x8003000开始到0x8003003 的4个字节的值, 因为我们的应用程序APP中设置把 中断向 量表 放置在0x08003000 开始的位置;而中断向量表里第一个放的就是栈顶地址的值 也就是说,这句话即通过判断栈顶地址值是否正确(是否在0x2000 0000 - 0x 2000 2000之间) 来判断是否应用程序已经下载了,因为应用程序的启动文件刚开始就去初始化化栈空间, 如果栈顶值对了,说应用程已经下载了启动文件的初始化也执行了; */ //判断用户是否已经下载程序,因为正常情况下此地址是栈地址。 //若没有这一句的话,即使没有下载程序也会进入而导致跑飞。 //*(__IO uint32_t*)ApplicationAddress 与 __vector_table[0]是一样的 //__vector_table[0]是应用程序栈的顶 //X=*(__IO uint32_t*)ApplicationAddress //if (( X & 0x2FFE0000 ) == 0x20000000) //X只有在0x20000000与0x2001FFFF之间时,才可能有(X&0x2FFE0000) == 0x20000000成立 //即栈顶是不是在以0x20000000开始的128K的范围内,这里便是STM32的RAM区域 if (( ( *(__IO uint32_t*)ApplicationAddress ) & 0x2FFE0000 ) == 0x20000000) { // OLED_Clear(); // OLED_ShowUnite(4,2,"Execute Program"); // delay_ms(500); //SerialPutString("Execute Program\r\n\n"); //跳转至用户代码 JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4); Jump_To_Application = (pFunction) JumpAddress; //初始化用户程序的堆栈指针 __set_MSP(*(__IO uint32_t*) ApplicationAddress); Jump_To_Application(); //执行复位中断函数 } else { OLED_Clear(); OLED_ShowUnite(4,2,"no user Program"); delay_ms(500); SerialPutString("no user Program\r\n\n"); } } // OLED_Clear(); // OLED_ShowUnite(16,2,"please reboot"); // delay_ms(500); // // SerialPutString("please reboot\r\n\n"); // while (1) // { // } }