본문 바로가기

Cortex-M/GigaDevice

GD32F130 SSM - W5500을 이용한 웹서버 테스트

GD32F130은 TSSOP20핀 페키지의 작고 저렴한 MCU로 64k 플래시 메모리를 지원하기 때문에 W5500을 연결하면 소형의 웹서버 만들기에 좋을것 같다.

 

GD32F130에서 W5500 테스트 결과 웹서버 관련 라이브러리가 잘되어 있는 EthernetWebServer는 기본 플래시 용량이 64k라서 컴파일 하면 플래시 메모리 용량 부족 에러가 발생한다.

#include <SPI.h>
#include "Ethernet_Generic.h"
#include <EthernetWebServer.h>

 

c:/users/jhpark/appdata/local/arduino15/packages/gd32community/tools/xpack-arm-none-eabi-gcc/9.3.1-1.3/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\jhpark\AppData\Local\Temp\arduino\sketches\5B648DC04C5FB6847830DCDEE748D46F/w5500_web1.ino.elf section `.text' will not fit in region `FLASH'
c:/users/jhpark/appdata/local/arduino15/packages/gd32community/tools/xpack-arm-none-eabi-gcc/9.3.1-1.3/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: region `FLASH' overflowed by 63016 bytes
collect2.exe: error: ld returned 1 exit status

 

 

좀 불편 하지만 Ethernet2 라이브러리로 간단한 웹서버를 작성 해 볼까?

#include <SPI.h>
#include <Ethernet2.h>
int32_t get_temperature() 
{ 
  return 29;
}

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0x00, 0x08, 0xDC, 0x00, 0x00, 0x00
};

IPAddress ip(192, 168, 1, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
EthernetClient client;

void setup() {
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Serial.print("server is at : ");
  
  // start the Ethernet connection and the server:
  pinMode(14, OUTPUT);
  Ethernet.w5500_cspin = 14;
  
  Ethernet.begin(mac, ip);
  server.begin();
  
  Serial.println(Ethernet.localIP());
}

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE html>
<html>
<body>
<h1> STM32G030 Simple Web Server;</h1>
<h2> &#128522 Temperature : </h2>
</body>
</html>
)rawliteral";

void SendHttpRresponse(void)
{
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println("Connection: close");  // the connection will be closed after completion of the response
  client.println("Refresh: 5");  // refresh the page automatically every 5 sec
  client.println();
  client.println("<!DOCTYPE HTML>");
  client.println("<html><center>");
}

void SendHttpPage(const char *pBuf)
{
  client.print(pBuf);
  client.println();
}

void loop() {
  // listen for incoming clients
  client = server.available();
  
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          SendHttpRresponse();
          client.print("<h1>");
          client.print("&#128522 STM32G0 Temperature : ");
          int sensorReading = get_temperature();
          client.print(sensorReading);
          client.println("<br /></center></h1>");

          SendHttpPage(index_html);
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

 

Ethernet2 라이브러리 사용시 20k 정도로 컴파일 된다.

 

Using library SPI at version 1.0 in folder: C:\Users\jhpark\AppData\Local\Arduino15\packages\GD32Community\hardware\gd32\0.0.1\libraries\SPI 
Using library Ethernet2 at version 1.0.4 in folder: C:\Users\jhpark\Documents\Arduino\libraries\Ethernet2 
"C:\\Users\\jhpark\\AppData\\Local\\Arduino15\\packages\\GD32Community\\tools\\xpack-arm-none-eabi-gcc\\9.3.1-1.3/bin/arm-none-eabi-size" -A "C:\\Users\\jhpark\\AppData\\Local\\Temp\\arduino\\sketches\\5B648DC04C5FB6847830DCDEE748D46F/w5500_web1.ino.elf"
Sketch uses 21168 bytes (32%) of program storage space. Maximum is 65536 bytes.
반응형