forked from xialei/BenTengFDC2
170 lines
5.2 KiB
C
170 lines
5.2 KiB
C
|
#include "led.h"
|
|||
|
#include "stm32f10x_iwdg.h"
|
|||
|
#include "sd.h"
|
|||
|
|
|||
|
#define WWDG_REFRESH (0x7F)
|
|||
|
uint8_t wwdg_int_cnt = 0;
|
|||
|
|
|||
|
//LED IO<49><4F>ʼ<EFBFBD><CABC>
|
|||
|
void LED_Init(void)
|
|||
|
{
|
|||
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|||
|
|
|||
|
|
|||
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE); //ʹ<><CAB9>PB,PE,PD<50>˿<EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //LED0-->PB.5 <20>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO<49><4F><EFBFBD>ٶ<EFBFBD>Ϊ50MHz
|
|||
|
GPIO_Init(GPIOA, &GPIO_InitStructure); //<2F><><EFBFBD><EFBFBD><EFBFBD>趨<EFBFBD><E8B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>GPIOB.5
|
|||
|
GPIO_SetBits(GPIOA,GPIO_Pin_9); //PB.5 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //LED0-->PB.5 <20>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO<49><4F><EFBFBD>ٶ<EFBFBD>Ϊ50MHz
|
|||
|
GPIO_Init(GPIOA, &GPIO_InitStructure); //<2F><><EFBFBD><EFBFBD><EFBFBD>趨<EFBFBD><E8B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>GPIOB.5
|
|||
|
GPIO_SetBits(GPIOA,GPIO_Pin_0); //PB.5 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_10; //LED0-->PB.5 <20>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO<49><4F><EFBFBD>ٶ<EFBFBD>Ϊ50MHz
|
|||
|
GPIO_Init(GPIOA, &GPIO_InitStructure); //<2F><><EFBFBD><EFBFBD><EFBFBD>趨<EFBFBD><E8B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>GPIOB.5
|
|||
|
GPIO_SetBits(GPIOA,GPIO_Pin_1); //PB.5 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
GPIO_ResetBits(GPIOA,GPIO_Pin_10); // pwr5v open
|
|||
|
|
|||
|
//KC 1 2 3 4 5
|
|||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7; //
|
|||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO<49><4F><EFBFBD>ٶ<EFBFBD>Ϊ50MHz
|
|||
|
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|||
|
GPIO_ResetBits(GPIOC,GPIO_Pin_5); //PB.5 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
GPIO_SetBits(GPIOC,GPIO_Pin_7); // 1043 ENable
|
|||
|
// GPIO_ResetBits(GPIOC,GPIO_Pin_7); // 1043 DISENable
|
|||
|
|
|||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2 |GPIO_Pin_14|GPIO_Pin_9|GPIO_Pin_5; //
|
|||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO<49><4F><EFBFBD>ٶ<EFBFBD>Ϊ50MHz
|
|||
|
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|||
|
|
|||
|
GPIO_SetBits(GPIOB,GPIO_Pin_9); // pwr3.3v close
|
|||
|
GPIO_ResetBits(GPIOB,GPIO_Pin_0);
|
|||
|
GPIO_ResetBits(GPIOB,GPIO_Pin_1);
|
|||
|
GPIO_ResetBits(GPIOB,GPIO_Pin_2);
|
|||
|
GPIO_ResetBits(GPIOB,GPIO_Pin_14);
|
|||
|
////GPIO_SetBits(GPIOB,GPIO_Pin_9); // pwr3.3v close
|
|||
|
// GPIO_ResetBits(GPIOB,GPIO_Pin_9); // pwr3.3v open
|
|||
|
GPIO_ResetBits(GPIOB,GPIO_Pin_5); // can_en open
|
|||
|
|
|||
|
// //SD<53><44><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// GPIO_InitStructure.GPIO_Pin = SD_INSERT_PIN;
|
|||
|
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //PC4
|
|||
|
// GPIO_Init(SD_INSERT_PORT, &GPIO_InitStructure);//<2F><>ʼ<EFBFBD><CABC>GPIOC
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; // A+ detect
|
|||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //
|
|||
|
GPIO_Init(GPIOA, &GPIO_InitStructure);//<2F><>ʼ<EFBFBD><CABC>GPIOC
|
|||
|
|
|||
|
|
|||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; // Acc detect
|
|||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //
|
|||
|
GPIO_Init(GPIOC, &GPIO_InitStructure);//<2F><>ʼ<EFBFBD><CABC>GPIOC
|
|||
|
|
|||
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
|
|||
|
GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE); // <20>ͷ<EFBFBD>PB4
|
|||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ; //
|
|||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
|||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
|||
|
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|||
|
|
|||
|
GPIO_SetBits(GPIOB,GPIO_Pin_4); // 1043 work
|
|||
|
|
|||
|
BKP_TamperPinCmd(DISABLE); /* <20>ر<EFBFBD><D8B1><EFBFBD><EFBFBD>ּ<EFBFBD><D6BC><EFBFBD><E2B9A6>,PC13<31><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨIO*/
|
|||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; // 1043 Can_int
|
|||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //
|
|||
|
GPIO_Init(GPIOC, &GPIO_InitStructure);//<2F><>ʼ<EFBFBD><CABC>GPIOC
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> IWDG <EFBFBD>ij<EFBFBD>ʱʱ<EFBFBD><EFBFBD>
|
|||
|
* Tout = prv/40 * rlv (s)
|
|||
|
* prv<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[4,8,16,32,64,128,256]
|
|||
|
* prv:Ԥ<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ȡֵ<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* @arg IWDG_Prescaler_4: IWDG prescaler set to 4
|
|||
|
* @arg IWDG_Prescaler_8: IWDG prescaler set to 8
|
|||
|
* @arg IWDG_Prescaler_16: IWDG prescaler set to 16
|
|||
|
* @arg IWDG_Prescaler_32: IWDG prescaler set to 32
|
|||
|
* @arg IWDG_Prescaler_64: IWDG prescaler set to 64
|
|||
|
* @arg IWDG_Prescaler_128: IWDG prescaler set to 128
|
|||
|
* @arg IWDG_Prescaler_256: IWDG prescaler set to 256
|
|||
|
*
|
|||
|
* rlv:Ԥ<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ȡֵ<EFBFBD><EFBFBD>ΧΪ<EFBFBD><EFBFBD>0-0XFFF
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>þ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* IWDG_Config(IWDG_Prescaler_64 ,625); // IWDG 1s <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
|
|||
|
void IWDG_Config(uint8_t prv ,uint16_t rlv)
|
|||
|
{
|
|||
|
// ʹ<><CAB9> Ԥ<><D4A4>Ƶ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>PR<50><52><EFBFBD><EFBFBD>װ<EFBFBD>ؼĴ<D8BC><C4B4><EFBFBD>RLR<4C><52>д
|
|||
|
IWDG_WriteAccessCmd( IWDG_WriteAccess_Enable );
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4>Ƶ<EFBFBD><C6B5>ֵ
|
|||
|
IWDG_SetPrescaler( prv );
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD>ؼĴ<D8BC><C4B4><EFBFBD>ֵ
|
|||
|
IWDG_SetReload( rlv );
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>װ<EFBFBD>ؼĴ<D8BC><C4B4><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
IWDG_ReloadCounter();
|
|||
|
|
|||
|
// ʹ<><CAB9> IWDG
|
|||
|
IWDG_Enable();
|
|||
|
}
|
|||
|
|
|||
|
// ι<><CEB9>
|
|||
|
void IWDG_Feed(void)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD>װ<EFBFBD>ؼĴ<D8BC><C4B4><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>ι<EFBFBD><CEB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹIWDG<44><47>λ
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>0<EFBFBD><30>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3>λ
|
|||
|
//IWDG_ReloadCounter();
|
|||
|
WWDG->CR = WWDG_REFRESH;
|
|||
|
wwdg_int_cnt = 0;
|
|||
|
}
|
|||
|
void IWDG_Init(void) // use window dog
|
|||
|
{
|
|||
|
// IWDG 1s <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
//IWDG_Config(IWDG_Prescaler_64 ,625);
|
|||
|
|
|||
|
RCC->APB1ENR |= RCC_APB1ENR_WWDGEN;
|
|||
|
WWDG->CFR = WWDG_CFR_EWI | WWDG_CFR_WDGTB | 0x7f; //ʹ<><CAB9>EWI<57>жϣ<D0B6>8<EFBFBD><38>Ƶ//
|
|||
|
WWDG->CR = WWDG_REFRESH;
|
|||
|
WWDG->CR |= WWDG_CR_WDGA;
|
|||
|
NVIC_SetPriority(WWDG_IRQn, 0);
|
|||
|
NVIC_EnableIRQ(WWDG_IRQn);
|
|||
|
////DebugOut("WWDG init ok\r\n",0, PCPRINTF);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void WWDG_IRQHandler(void)////
|
|||
|
{
|
|||
|
WWDG->SR = 0;
|
|||
|
//#if (WDG_TYPE == WDG_WWDG)
|
|||
|
wwdg_int_cnt++;
|
|||
|
if (wwdg_int_cnt <= 30) // 15
|
|||
|
{
|
|||
|
WWDG->CR = WWDG_REFRESH;
|
|||
|
}
|
|||
|
//#endif
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|