Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qitas committed Nov 1, 2021
1 parent 35b9e65 commit ac3b3c5
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 130 deletions.
23 changes: 18 additions & 5 deletions project/IAP/Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,24 @@ void Error_Handler(void);
/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define KEY1_Pin LL_GPIO_PIN_13
#define KEY1_GPIO_Port GPIOC
#define KEY1_EXTI_IRQn EXTI4_15_IRQn
#define LED1_Pin LL_GPIO_PIN_4
#define LED1_GPIO_Port GPIOB
#define LED3_Pin LL_GPIO_PIN_3
#define LED3_GPIO_Port GPIOA
#define LED2_Pin LL_GPIO_PIN_4
#define LED2_GPIO_Port GPIOA
#define LED1_Pin LL_GPIO_PIN_5
#define LED1_GPIO_Port GPIOA
#define AUTO_Pin LL_GPIO_PIN_6
#define AUTO_GPIO_Port GPIOA
#define HALL1_Pin LL_GPIO_PIN_7
#define HALL1_GPIO_Port GPIOA
#define HALL2_Pin LL_GPIO_PIN_0
#define HALL2_GPIO_Port GPIOB
#define HALL3_Pin LL_GPIO_PIN_1
#define HALL3_GPIO_Port GPIOB
#define SD_Pin LL_GPIO_PIN_15
#define SD_GPIO_Port GPIOB
#define RS485_EN_Pin LL_GPIO_PIN_8
#define RS485_EN_GPIO_Port GPIOA
/* USER CODE BEGIN Private defines */
// extern IWDG_HandleTypeDef hiwdg;
#define feed_dog() LL_IWDG_ReloadCounter(IWDG) //LL_mDelay(0) //HAL_IWDG_Refresh(&hiwdg) //
Expand Down
1 change: 0 additions & 1 deletion project/IAP/Core/Inc/stm32g0xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ void HardFault_Handler(void);
void SysTick_Handler(void);
void FLASH_IRQHandler(void);
void RCC_IRQHandler(void);
void EXTI4_15_IRQHandler(void);
void USART1_IRQHandler(void);
/* USER CODE BEGIN EFP */

Expand Down
170 changes: 101 additions & 69 deletions project/IAP/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ osThreadId defaultTaskHandle;
osThreadId SystemTaskHandle;
/* USER CODE BEGIN PV */
#endif

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
Expand All @@ -62,16 +63,57 @@ static void MX_USART1_UART_Init(void);
static void MX_RTC_Init(void);
static void MX_IWDG_Init(void);
void StartDefaultTask(void const * argument);
void StartSystemTask(void const * argument);
extern void StartSystemTask(void const * argument);

/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */


#ifndef BLT
void StartSystemTask(void const * argument)
{
/* USER CODE BEGIN StartSystemTask */
char buf[50];
static uint32_t rcnt = 0;
/* Infinite loop */
for(;;)
{
rcnt++;
#ifdef APP1
osDelay(1000);
uart_tx_str("App1 Mark\r\n",15);
if(rcnt>5)
{
sprintf(buf, "\r\nAPP1:%x,%x,%x,%x,%x\r\n\r\n",Mark_Get(bkp_app1_addr),Mark_Get(bkp_app2_addr),Mark_Get(bkp_app1_mark),Mark_Get(bkp_app2_mark),Mark_Get(bkp_boot_mark));
uart_tx_str((uint8_t *)buf,strlen((char *)buf));
Mark_Set(bkp_app1_addr,0);
Mark_Set(bkp_app1_mark,0);
Mark_Set(bkp_app2_mark,0);
Mark_Set(bkp_app2_addr,USER_APP2_ADDRESS);
osDelay(10);
sysReset();
}
#endif
#ifdef APP2
osDelay(1000);
uart_tx_str("app2 test\r\n",15);
if(rcnt>5)
{
sprintf((char *)buf, "APP2:%x,%x,%x,%x,%x\r\n",Mark_Get(bkp_app1_addr),Mark_Get(bkp_app2_addr),Mark_Get(bkp_app1_mark),Mark_Get(bkp_app2_mark),Mark_Get(bkp_boot_mark));
uart_tx_str((uint8_t *)buf,strlen((char *)buf));
Mark_Set(bkp_app1_addr,USER_APP1_ADDRESS);
Mark_Set(bkp_app2_addr,0);
Mark_Set(bkp_app2_mark,0);
Mark_Set(bkp_app1_mark,0);
osDelay(10);
sysReset();
}
#endif
}
}
#endif
/* USER CODE END 0 */

/**
Expand Down Expand Up @@ -117,7 +159,6 @@ int main(void)
// uint16_t *uuid = (uint16_t *) UID_BASE;
sprintf((char *)buf, "BLT:%x-%x,%x-%x,%d\r\n",Mark_Get(bkp_app1_addr),Mark_Get(bkp_app2_addr),Mark_Get(bkp_app1_mark),Mark_Get(bkp_app2_mark),flash_size);
uart_tx_str((uint8_t *)buf,strlen((char *)buf));
//
#else
// SCB->VTOR = USER_APP2_ADDRESS;
// appjump(USER_APP2_ADDRESS);
Expand Down Expand Up @@ -148,7 +189,7 @@ int main(void)

/* Create the thread(s) */
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 64);
osThreadDef(defaultTask, StartDefaultTask, osPriorityLow, 0, 64);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

/* definition and creation of SystemTask */
Expand Down Expand Up @@ -395,32 +436,39 @@ static void MX_USART1_UART_Init(void)
*/
static void MX_GPIO_Init(void)
{
LL_EXTI_InitTypeDef EXTI_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};

/* GPIO Ports Clock Enable */
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOC);
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);

/**/
LL_GPIO_ResetOutputPin(LED1_GPIO_Port, LED1_Pin);
LL_GPIO_ResetOutputPin(LED3_GPIO_Port, LED3_Pin);

/**/
LL_EXTI_SetEXTISource(LL_EXTI_CONFIG_PORTC, LL_EXTI_CONFIG_LINE13);
LL_GPIO_ResetOutputPin(LED2_GPIO_Port, LED2_Pin);

/**/
EXTI_InitStruct.Line_0_31 = LL_EXTI_LINE_13;
EXTI_InitStruct.LineCommand = ENABLE;
EXTI_InitStruct.Mode = LL_EXTI_MODE_IT;
EXTI_InitStruct.Trigger = LL_EXTI_TRIGGER_RISING_FALLING;
LL_EXTI_Init(&EXTI_InitStruct);
LL_GPIO_ResetOutputPin(LED1_GPIO_Port, LED1_Pin);

/**/
LL_GPIO_SetPinPull(KEY1_GPIO_Port, KEY1_Pin, LL_GPIO_PULL_NO);
LL_GPIO_ResetOutputPin(RS485_EN_GPIO_Port, RS485_EN_Pin);

/**/
LL_GPIO_SetPinMode(KEY1_GPIO_Port, KEY1_Pin, LL_GPIO_MODE_INPUT);
GPIO_InitStruct.Pin = LED3_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(LED3_GPIO_Port, &GPIO_InitStruct);

/**/
GPIO_InitStruct.Pin = LED2_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(LED2_GPIO_Port, &GPIO_InitStruct);

/**/
GPIO_InitStruct.Pin = LED1_Pin;
Expand All @@ -430,9 +478,43 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(LED1_GPIO_Port, &GPIO_InitStruct);

/* EXTI interrupt init*/
NVIC_SetPriority(EXTI4_15_IRQn, 3);
NVIC_EnableIRQ(EXTI4_15_IRQn);
/**/
GPIO_InitStruct.Pin = AUTO_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(AUTO_GPIO_Port, &GPIO_InitStruct);

/**/
GPIO_InitStruct.Pin = HALL1_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(HALL1_GPIO_Port, &GPIO_InitStruct);

/**/
GPIO_InitStruct.Pin = HALL2_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(HALL2_GPIO_Port, &GPIO_InitStruct);

/**/
GPIO_InitStruct.Pin = HALL3_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(HALL3_GPIO_Port, &GPIO_InitStruct);

/**/
GPIO_InitStruct.Pin = SD_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(SD_GPIO_Port, &GPIO_InitStruct);

/**/
GPIO_InitStruct.Pin = RS485_EN_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(RS485_EN_GPIO_Port, &GPIO_InitStruct);

}

Expand Down Expand Up @@ -461,56 +543,6 @@ void StartDefaultTask(void const * argument)
/* USER CODE END 5 */
}

/* USER CODE BEGIN Header_StartSystemTask */
/**
* @brief Function implementing the SystemTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartSystemTask */
void StartSystemTask(void const * argument)
{
/* USER CODE BEGIN StartSystemTask */
char buf[50];
static uint32_t rcnt = 0;
/* Infinite loop */
for(;;)
{
rcnt++;
#ifdef APP1
osDelay(1000);
uart_tx_str("App1 Mark\r\n",15);
if(rcnt>5)
{
sprintf(buf, "\r\nAPP1:%x,%x,%x,%x,%x\r\n\r\n",Mark_Get(bkp_app1_addr),Mark_Get(bkp_app2_addr),Mark_Get(bkp_app1_mark),Mark_Get(bkp_app2_mark),Mark_Get(bkp_boot_mark));
uart_tx_str((uint8_t *)buf,strlen((char *)buf));
Mark_Set(bkp_app1_addr,0);
Mark_Set(bkp_app1_mark,0);
Mark_Set(bkp_app2_mark,0);
Mark_Set(bkp_app2_addr,USER_APP2_ADDRESS);
osDelay(10);
sysReset();
}
#endif
#ifdef APP2
osDelay(1000);
uart_tx_str("app2 test\r\n",15);
if(rcnt>5)
{
sprintf((char *)buf, "APP2:%x,%x,%x,%x,%x\r\n",Mark_Get(bkp_app1_addr),Mark_Get(bkp_app2_addr),Mark_Get(bkp_app1_mark),Mark_Get(bkp_app2_mark),Mark_Get(bkp_boot_mark));
uart_tx_str((uint8_t *)buf,strlen((char *)buf));
Mark_Set(bkp_app1_addr,USER_APP1_ADDRESS);
Mark_Set(bkp_app2_addr,0);
Mark_Set(bkp_app2_mark,0);
Mark_Set(bkp_app1_mark,0);
osDelay(10);
sysReset();
}
#endif
}
/* USER CODE END StartSystemTask */
}

/**
* @brief This function is executed in case of error occurrence.
* @retval None
Expand Down
27 changes: 0 additions & 27 deletions project/IAP/Core/Src/stm32g0xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,33 +159,6 @@ void RCC_IRQHandler(void)
/* USER CODE END RCC_IRQn 1 */
}

/**
* @brief This function handles EXTI line 4 to 15 interrupts.
*/
void EXTI4_15_IRQHandler(void)
{
/* USER CODE BEGIN EXTI4_15_IRQn 0 */

/* USER CODE END EXTI4_15_IRQn 0 */
if (LL_EXTI_IsActiveFallingFlag_0_31(LL_EXTI_LINE_13) != RESET)
{
LL_EXTI_ClearFallingFlag_0_31(LL_EXTI_LINE_13);
/* USER CODE BEGIN LL_EXTI_LINE_13_FALLING */

/* USER CODE END LL_EXTI_LINE_13_FALLING */
}
if (LL_EXTI_IsActiveRisingFlag_0_31(LL_EXTI_LINE_13) != RESET)
{
LL_EXTI_ClearRisingFlag_0_31(LL_EXTI_LINE_13);
/* USER CODE BEGIN LL_EXTI_LINE_13_RISING */

/* USER CODE END LL_EXTI_LINE_13_RISING */
}
/* USER CODE BEGIN EXTI4_15_IRQn 1 */

/* USER CODE END EXTI4_15_IRQn 1 */
}

/**
* @brief This function handles USART1 global interrupt / USART1 wake-up interrupt through EXTI line 25.
*/
Expand Down
Loading

0 comments on commit ac3b3c5

Please sign in to comment.