I have the following timer interrupt configuration
static void MX_TIM6_Init(void)
{
/* USER CODE BEGIN TIM6_Init 0 */
/* USER CODE END TIM6_Init 0 */
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM6_Init 1 */
/* USER CODE END TIM6_Init 1 */
htim6.Instance = TIM6;
htim6.Init.Prescaler = 1080;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.Period = 10000;
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/* USER CODE BEGIN TIM6_Init 2 */
/* USER CODE END TIM6_Init 2 */
}
I need to process a web server at the background of the application and a web client in the foreground of the application.
So I created a timer interrupt, but the problem that the calls to the wifi functions gets blocked.
I have tried to set the NVIC to highest priority and the timer to lowest one, but still it stucks there.
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
HAL_NVIC_SetPriority(TIM6_IRQn, 15,15); //Enable the peripheral IRQ
Here is the timer interrupt function:
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
// This callback is automatically called by the HAL on the UEV event
if (htim->Instance == TIM6)
{
processServer = true;
if (WIFI_StartServer(0, WIFI_TCP_PROTOCOL, "TCP_SERVER", 80) != WIFI_STATUS_OK)
return;
HAL_Delay(10);
WIFI_ReceiveData(0, resp, 1200, &respLen, WIFI_READ_TIMEOUT);
if (respLen > 0)
{
char string0[20] = {0};
float kwh = 1.1;
if (strstr((char *)resp, "GET")) /* GET: put web page */
{
// modbus_read_kwh(string0, &kwh);
if (SendWebPage(string0) != WIFI_STATUS_OK)
{
}
}
if (SendWebPage(string0) != WIFI_STATUS_OK)
{
}
}
WIFI_StopServer(0);
processServer = false;
}
}
Here is the main loop after suggestion
while (1)
{
uint8_t ip[4] = {8, 8, 8, 8};
if (processServer)
{
if (WIFI_StartServer(0, WIFI_TCP_PROTOCOL, "TCP_SERVER", 80) != WIFI_STATUS_OK)
return;
WIFI_ReceiveData(0, resp, 1200, &respLen, WIFI_READ_TIMEOUT);
if (respLen > 0)
{
char string0[20] = {0};
float kwh = 1.1;
if (strstr((char *)resp, "GET")) /* GET: put web page */
{
// modbus_read_kwh(string0, &kwh);
if (SendWebPage(string0) != WIFI_STATUS_OK)
{
}
}
if (SendWebPage(string0) != WIFI_STATUS_OK)
{
}
}
WIFI_StopServer(0);
processServer = false;
}
else
{
WIFI_DNS_Lookup("ipdb-eu2.riddleandcode.com", ip);
WIFI_OpenClientConnection(0, WIFI_TCP_PROTOCOL, "TCP_CLIENT", ip, 80, 0);
uint32_t amnt_int = 0;
//int r = get_balance_amount( end_pos + 11, &amnt_int);
int r = get_balance_amount("CJL6QoHLS9vmWfk5zRi7qQc6WrEmp2Jh8UpgWMaxHctK", &amnt_int);
char str[20];
sprintf(str, "amount %d \r\n", amnt_int);
// print our string
SWO_PrintString(str);
WIFI_CloseClientConnection(0);
}
}
volatile
I'm sure. \$\endgroup\$ – brhans May 10 '19 at 14:48