2019-09-13 04:50 AM
Hello,
I am trying to send data periodically as a client in MCU.I am using program called SocketTest v 3.0.0 from PC.Connection is OK but I can't see other values.These are my codes.
---------------------in main.c------------------------
#include "main.h"
#include "lwip.h"
#include "usart.h"
#include "gpio.h"
void SystemClock_Config(void);
void Soft_Timer0(uint32_t timeMs);
extern struct netif gnetif;
extern struct tcp_pcb *echoclient_pcb;
uint32_t softTimer0=0;
volatile uint8_t a=0;
char str[10] = "123456789";
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_LWIP_Init();
MX_USART1_UART_Init();
User_Notification(&gnetif);
while (1)
{
MX_LWIP_Process();
DHCP_Periodic_Handle(&gnetif);
if(a) Soft_Timer0(2000);
}
}
/*******************************************************************************/
void Soft_Timer0(uint32_t timeMs)
{
static uint8_t cnt=0;
err_t wr_err = ERR_OK;
if(HAL_GetTick() - softTimer0 > timeMs)
{
softTimer0 = HAL_GetTick();
tcp_write(echoclient_pcb, &str[cnt], 1, 0x01);
wr_err = tcp_output(echoclient_pcb);
if(wr_err == ERR_OK)
{
cnt++;
if(cnt == 9) cnt = 0;
}
}
}
/*******************************************************************************/
void EXTI0_IRQHandler(void)
{
err_t err=ERR_CONN;
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
err = tcp_echoclient_connect();
if(err == ERR_OK)
{
tcp_write(echoclient_pcb, "\n", 1, 0x01);
tcp_output(echoclient_pcb);
a = 1;
softTimer0 = HAL_GetTick();
}
}
2019-09-13 05:01 PM
Usually one doesn't want to call things like tcp_write from interrupt handlers.
2019-09-14 12:51 AM
Not only one shouldn't want it but in this case, except for pbuf_free()/mem_free() under special configuration (not recommended), it's not allowed to call any other lwIP function from interrupts at all.
How about reading documentation?
https://www.nongnu.org/lwip/2_1_x/multithreading.html
As such, the list of functions that may be called from other threads or an ISR is very limited!
If SYS_LIGHTWEIGHT_PROT is set to 1 and LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT is set to 1, pbuf_free() may also be called from another thread or an ISR (since only then, mem_free - for PBUF_RAM - may be called from an ISR: otherwise, the HEAP is only protected by semaphores).
2019-09-14 12:53 AM
it doesn't change anything when I don't call it in interrupt.What is the proper method that I want?
2019-09-14 03:29 AM
Ok it works like that
void SystemClock_Config(void);
void Soft_Timer0(uint32_t timeMs);
void Run_One_Time(void);
extern struct netif gnetif;
extern struct tcp_pcb *echoclient_pcb;
uint32_t softTimer0=0;
volatile uint8_t a=0,timer0Start=0;
char str[10] = "123456789";
err_t err=ERR_CONN;
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_LWIP_Init();
MX_USART1_UART_Init();
User_Notification(&gnetif);
while (1)
{
MX_LWIP_Process();
DHCP_Periodic_Handle(&gnetif);
if(timer0Start)
{
Soft_Timer0(1);
}
Run_One_Time();
}
}
/*******************************************************************************/
void Run_One_Time(void)
{
static uint8_t systemOn=1,oneTime=0;
if (a)
{
if (!oneTime)
{
err = tcp_echoclient_connect();
if(err == ERR_OK)
{
softTimer0 = HAL_GetTick();
timer0Start = 1;
oneTime = 1;
}
else
{
oneTime = 0;
HAL_Delay(1000);
}
}
}
else
{
oneTime = 0;
}
}
/*******************************************************************************/
void Soft_Timer0(uint32_t timeMs)
{
static uint8_t cnt=0, var = 1;
if(HAL_GetTick() - softTimer0 > timeMs)
{
softTimer0 = HAL_GetTick();
if(var == 1)
{
err = tcp_write(echoclient_pcb, &str[cnt], 1, 0x01);
if(err == ERR_OK) var = 2;
}
if(var == 2)
{
err = tcp_output(echoclient_pcb);
if(err == ERR_OK) var = 3;
}
if(var == 3)
{
err = tcp_write(echoclient_pcb, "\n", 1, 0x01);
if(err == ERR_OK) var = 4;
}
if(var == 4)
{
err = tcp_output(echoclient_pcb);
if(err == ERR_OK) var = 5;
}
if(var == 5)
{
cnt++;
if(cnt == 9) cnt = 0;
var = 1;
}
}
}
/*******************************************************************************/
void EXTI0_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
a = 1;
}
2019-09-14 06:20 AM
what about reading data from PC.How can I get them.There is no hardware interrupt as much as I understand in lwip.
2019-09-14 07:50 AM