[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] lwip with fatfs on a STM32 speed problem
From: |
Dave Sandl |
Subject: |
[lwip-users] lwip with fatfs on a STM32 speed problem |
Date: |
Mon, 27 Jan 2014 20:10:09 -0700 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
Hi,
I am having problems getting good speed results on sending files using a
stm32 with fatfs files system.
I can only get max of around 2.5kBs on a image download.
My server and file system seem to work fine, here are the specs
STM32F4discovery with the ethernet/sdcard baseboard from element14
I used the ST supplied drivers for both lwip and fatfs to create a raw
api basic server.
Here is the relevant code sections, any help would be appreciated.
If I increase the sd_read_buff to 1024 or higher is does not send the
file correctly (not sure what to do here or if it should be bigger?)
#define sd_read_buff 512
struct http_state
{
FIL fileFS;
char *file;
u32_t left;
uint8_t buff[sd_read_buff];
};
static void send_data(struct tcp_pcb *pcb, struct http_state *hs)
{
err_t err;
FRESULT ret;
u16_t len;
uint br;
uint temp1 = tcp_sndbuf(pcb);
if(tcp_sndbuf(pcb) < sd_read_buff)
len = tcp_sndbuf(pcb);
else
{
if(hs->left < sd_read_buff)
len = hs->left;
else
len = sd_read_buff;
}
ret = f_read(&hs->fileFS, hs->buff, len, &br);
if(ret == FR_OK){
err = tcp_write(pcb, hs->buff, br, 0);
if (err == ERR_OK)
{
if(br < len)
hs->left = 0;
else
hs->left -= br;
}
}
}
static err_t http_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
{
struct http_state *hs;
hs = arg;
if (hs->left > 0)
{
send_data(pcb, hs);
}
else
{
f_close(&hs->fileFS);
close_conn(pcb, hs);
}
return ERR_OK;
}
static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
err_t err)
{
int32_t len=0;
char *data;
struct http_state *hs;
hs = arg;
if (err == ERR_OK && p != NULL)
{
/* Inform TCP that we have taken the data */
tcp_recved(pcb, p->tot_len);
if (hs->file == NULL)
{
data = p->payload;
len = p->tot_len;
/* process HTTP GET requests*/
if (strncmp(data, "GET /index.htm", 10) == 0)
{
FIL file;
FRESULT ret;
hs->fileFS = file;
ret = f_open(&hs->fileFS, "index.htm", FA_READ);
if(ret == FR_OK)
{
pbuf_free(p); // Free the receive data
hs->left = f_size(&hs->fileFS);
send_data(pcb, hs);
tcp_sent(pcb, http_sent);
}
else
{
tcp_write(pcb, file_error, sizeof(file_error), 0);
pbuf_free(p);
close_conn(pcb, hs);
}
}
else if (strncmp(data, "GET /pic.jpg", 12) == 0)
{
FIL file;
FRESULT ret;
hs->fileFS = file;
ret = f_open(&hs->fileFS, "pic.jpg", FA_READ);
if(ret == FR_OK)
{
pbuf_free(p); // Free the receive data
hs->left = f_size(&hs->fileFS);
send_data(pcb, hs);
tcp_sent(pcb, http_sent);
}
else
{
tcp_write(pcb, file_error, sizeof(file_error), 0);
pbuf_free(p);
close_conn(pcb, hs);
}
}
else
{
tcp_write(pcb, http_index_html, sizeof(http_index_html), 0);
pbuf_free(p);
close_conn(pcb, hs);
}
}
else
{
pbuf_free(p);
close_conn(pcb,hs);
}
}
if (err == ERR_OK && p == NULL)
{
close_conn(pcb, hs);
}
return ERR_OK;
}
void IAP_httpd_init(void)
{
struct tcp_pcb *pcb;
/*create new pcb*/
pcb = tcp_new();
if (!pcb)
{
return ;
}
/* bind HTTP traffic to pcb */
tcp_bind(pcb, IP_ADDR_ANY, 80);
/* start listening on port 80 */
pcb = tcp_listen(pcb);
/* define callback function for TCP connection setup */
tcp_accept(pcb, http_accept);
}
- [lwip-users] lwip with fatfs on a STM32 speed problem,
Dave Sandl <=
- Re: [lwip-users] lwip with fatfs on a STM32 speed problem, Noam weissman, 2014/01/28
- Re: [lwip-users] lwip with fatfs on a STM32 speed problem, Krzysztof WesoĊowski, 2014/01/28
- Re: [lwip-users] lwip with fatfs on a STM32 speed problem, Dave Sandl, 2014/01/28
- Re: [lwip-users] lwip with fatfs on a STM32 speed problem, Pomeroy, Marty, 2014/01/29
- Re: [lwip-users] lwip with fatfs on a STM32 speed problem, Dave Sandl, 2014/01/29
- Re: [lwip-users] lwip with fatfs on a STM32 speed problem, Jonathan dumaresq, 2014/01/29
- Re: [lwip-users] lwip with fatfs on a STM32 speed problem, Dave Sandl, 2014/01/29
- Re: [lwip-users] lwip with fatfs on a STM32 speed problem, Jonathan dumaresq, 2014/01/30
- Re: [lwip-users] lwip with fatfs on a STM32 speed problem, east3, 2014/01/31