main.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /****************************************Copyright (c)****************************************************
  2. **
  3. ** http://www.powermcu.com
  4. **
  5. **--------------File Info---------------------------------------------------------------------------------
  6. ** File name: main.c
  7. ** Descriptions: The UCOSII application function
  8. **
  9. **--------------------------------------------------------------------------------------------------------
  10. ** Created by: AVRman
  11. ** Created date: 2010-11-9
  12. ** Version: v1.0
  13. ** Descriptions: The original version
  14. **
  15. **--------------------------------------------------------------------------------------------------------
  16. ** Modified by:
  17. ** Modified date:
  18. ** Version:
  19. ** Descriptions:
  20. **
  21. *********************************************************************************************************/
  22. /* Includes ------------------------------------------------------------------*/
  23. #include "includes.h"
  24. /**********************************************************************************************************
  25. * main()
  26. *
  27. * Description : This is the standard entry point for C code. It is assumed that your code will call
  28. * main() once you have performed all necessary initialization.
  29. *
  30. * Argument(s) : none.
  31. *
  32. * Return(s) : none.
  33. **********************************************************************************************************/
  34. void PwrLock(void)
  35. {
  36. GPIO_InitTypeDef GPIO_InitStructure;
  37. RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
  38. GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
  39. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
  40. GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  41. GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  42. GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;
  43. GPIO_Init(GPIOB, &GPIO_InitStructure);
  44. //USB SWITCH
  45. GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13;
  46. GPIO_Init(GPIOC, &GPIO_InitStructure);
  47. GPIOC->BSRR=GPIO_Pin_13;
  48. //key power
  49. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  50. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  51. GPIO_InitStructure.GPIO_Pin=KEY_POWER_PIN;//3
  52. GPIO_Init(KEY_POWER_PORT, &GPIO_InitStructure);
  53. }
  54. #define FLASH_BASE ((uint32_t)0x08000000)
  55. #define MAIN_CONFIG_ADDR (FLASH_BASE+126*1024)
  56. int sutProductParaPSN=0;
  57. void ShowMcuFreq(void)
  58. {
  59. char buf[40];
  60. RCC_ClocksTypeDef clk;
  61. RCC_GetClocksFreq(&clk);
  62. //SysTick_Config(clk.SYSCLK_Frequency / 100);
  63. printf("SYSCLK=%d,PCLK1=%d,PCLK2=%d,HCLK=%d\r\n",clk.SYSCLK_Frequency,clk.PCLK1_Frequency,clk.PCLK2_Frequency,clk.HCLK_Frequency);
  64. }
  65. int main (void)
  66. {
  67. Uart1Init();
  68. if (SysTick_Config(SystemCoreClock / 100)){ //100
  69. while (1);
  70. }
  71. PwrLock();
  72. W25Q64_Init();
  73. FileSysInit();
  74. //IapTrace(IAP_VERSION_NAME);
  75. g_ucRand=GetRandBySTM32ID();
  76. memset(&sutMsg,0,sizeof(SUT_MSG));
  77. NewTask(TASK_WAIT);
  78. ShowMcuFreq();
  79. CheckPwrKeyOn();
  80. //NewTask(TASK_DL_APP);
  81. //CopyFileInit();
  82. while(1)
  83. {
  84. if(sutMsg.Uart1Recv){ //Use for PC
  85. Uart1Msg();
  86. g_usRx1Len=0;
  87. sutMsg.Uart1Recv=0;
  88. g_usRx1In=0;
  89. memset(IapRxBuf,0,sizeof(IapRxBuf));
  90. }
  91. if(sutMsg.TaskStart){
  92. sutMsg.TaskStart=0;
  93. StartMsg();
  94. }
  95. if(sutMsg.Tick10ms){
  96. sutMsg.Tick10ms=0;
  97. TickMsg();
  98. }
  99. if(sutMsg.Tick500ms){
  100. sutMsg.Tick500ms=0;
  101. Tick500Msg();
  102. }
  103. }
  104. return (0);
  105. }
  106. //void assert_failed(uint8_t* file, uint32_t line)
  107. //{
  108. // printf("[AF]f:%s,l:%d\r\n",file,line);
  109. // while (1)
  110. // {}
  111. //}
  112. /*********************************************************************************************************
  113. END FILE
  114. *********************************************************************************************************/