|
|
|
@ -51,6 +51,7 @@ void SystemClock_Config(void);
|
|
|
|
static void MX_GPIO_Init(void);
|
|
|
|
static void MX_GPIO_Init(void);
|
|
|
|
static void MX_ICACHE_Init(void);
|
|
|
|
static void MX_ICACHE_Init(void);
|
|
|
|
static void MX_TIM5_Init(void);
|
|
|
|
static void MX_TIM5_Init(void);
|
|
|
|
|
|
|
|
static void MX_TIM2_Init(void);
|
|
|
|
/* USER CODE BEGIN PFP */
|
|
|
|
/* USER CODE BEGIN PFP */
|
|
|
|
|
|
|
|
|
|
|
|
/* USER CODE END PFP */
|
|
|
|
/* USER CODE END PFP */
|
|
|
|
@ -61,6 +62,22 @@ static inline void LD2_On() { LL_GPIO_SetOutputPin( LD2_GPIO_Port, LD2_Pin);
|
|
|
|
static inline void LD2_Off() { LL_GPIO_ResetOutputPin( LD2_GPIO_Port, LD2_Pin); }
|
|
|
|
static inline void LD2_Off() { LL_GPIO_ResetOutputPin( LD2_GPIO_Port, LD2_Pin); }
|
|
|
|
static inline void LD2_Toggle() { LL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin); }
|
|
|
|
static inline void LD2_Toggle() { LL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************//**
|
|
|
|
|
|
|
|
* @brief Check if specified time interval has elapsed
|
|
|
|
|
|
|
|
* @param tref Pointer to time reference variable [ms]
|
|
|
|
|
|
|
|
* @param tcycle Time interval in milliseconds
|
|
|
|
|
|
|
|
*//****************************************************************************/
|
|
|
|
|
|
|
|
static inline uint32_t TickChk(uint32_t *tref, int_fast16_t tcycle) {
|
|
|
|
|
|
|
|
uint32_t t = LL_TIM_GetCounter(TIM2) / 2; // 2kHz/2=1kHz
|
|
|
|
|
|
|
|
int32_t tdif = t - *tref;
|
|
|
|
|
|
|
|
if (tdif >= tcycle) {
|
|
|
|
|
|
|
|
*tref += tcycle;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* USER CODE END 0 */
|
|
|
|
/* USER CODE END 0 */
|
|
|
|
|
|
|
|
|
|
|
|
@ -100,7 +117,10 @@ int main(void)
|
|
|
|
MX_GPIO_Init();
|
|
|
|
MX_GPIO_Init();
|
|
|
|
MX_ICACHE_Init();
|
|
|
|
MX_ICACHE_Init();
|
|
|
|
MX_TIM5_Init();
|
|
|
|
MX_TIM5_Init();
|
|
|
|
|
|
|
|
MX_TIM2_Init();
|
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
|
|
|
|
LL_TIM_GenerateEvent_UPDATE(TIM2);
|
|
|
|
|
|
|
|
LL_TIM_EnableCounter(TIM2);
|
|
|
|
LL_TIM_GenerateEvent_UPDATE(TIM5);
|
|
|
|
LL_TIM_GenerateEvent_UPDATE(TIM5);
|
|
|
|
LL_TIM_EnableCounter(TIM5);
|
|
|
|
LL_TIM_EnableCounter(TIM5);
|
|
|
|
|
|
|
|
|
|
|
|
@ -118,15 +138,27 @@ int main(void)
|
|
|
|
/* USER CODE BEGIN WHILE */
|
|
|
|
/* USER CODE BEGIN WHILE */
|
|
|
|
while (1)
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
static uint32_t Tick10msRef = 0;
|
|
|
|
|
|
|
|
if (TickChk(&Tick10msRef, 10)) { // execute every 10ms
|
|
|
|
|
|
|
|
ShiftReg_Update();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t Tick1secRef = 0;
|
|
|
|
|
|
|
|
if (TickChk(&Tick1secRef, 1000)) { // execute every 1s
|
|
|
|
LD2_Toggle();
|
|
|
|
LD2_Toggle();
|
|
|
|
Delay_us(1000000); // 1s delay
|
|
|
|
|
|
|
|
static uint8_t cnt = 0;
|
|
|
|
static uint8_t cnt = 0;
|
|
|
|
DispPutDigit(0, '0'+cnt, 0);
|
|
|
|
DispPutDigit(0, '0'+cnt, 0);
|
|
|
|
DispPutDigit(1, 'a'+cnt, 1);
|
|
|
|
DispPutDigit(1, 'a'+cnt, 1);
|
|
|
|
DispPutDigit(2, 'A'+cnt, 0);
|
|
|
|
DispPutDigit(2, 'A'+cnt, 0);
|
|
|
|
DispPutDigit(3, 'Z'-cnt, 1);
|
|
|
|
cnt = (cnt + 1) % 16;
|
|
|
|
if (++cnt > 9) cnt = 0;
|
|
|
|
}
|
|
|
|
ShiftReg_Update();
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t Tick100msRef = 0;
|
|
|
|
|
|
|
|
if (TickChk(&Tick100msRef, 100)) { // execute every 100ms
|
|
|
|
|
|
|
|
static uint8_t dot = 0;
|
|
|
|
|
|
|
|
dot ^= 1; // toggle dot
|
|
|
|
|
|
|
|
DispPutDigit(3, ' ', dot);
|
|
|
|
|
|
|
|
}
|
|
|
|
/* USER CODE END WHILE */
|
|
|
|
/* USER CODE END WHILE */
|
|
|
|
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
|
|
@ -214,6 +246,41 @@ static void MX_ICACHE_Init(void)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @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 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LL_TIM_InitTypeDef TIM_InitStruct = {0};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Peripheral clock enable */
|
|
|
|
|
|
|
|
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* USER CODE BEGIN TIM2_Init 1 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* USER CODE END TIM2_Init 1 */
|
|
|
|
|
|
|
|
TIM_InitStruct.Prescaler = 39999;
|
|
|
|
|
|
|
|
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
|
|
|
|
|
|
|
|
TIM_InitStruct.Autoreload = 4294967295;
|
|
|
|
|
|
|
|
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
|
|
|
|
|
|
|
|
LL_TIM_Init(TIM2, &TIM_InitStruct);
|
|
|
|
|
|
|
|
LL_TIM_DisableARRPreload(TIM2);
|
|
|
|
|
|
|
|
LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL);
|
|
|
|
|
|
|
|
LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET);
|
|
|
|
|
|
|
|
LL_TIM_DisableMasterSlaveMode(TIM2);
|
|
|
|
|
|
|
|
/* USER CODE BEGIN TIM2_Init 2 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* USER CODE END TIM2_Init 2 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief TIM5 Initialization Function
|
|
|
|
* @brief TIM5 Initialization Function
|
|
|
|
* @param None
|
|
|
|
* @param None
|
|
|
|
|