W5500 driver for mbed OS 5
Dependents: http-webserver-example mbed-os-example-sockets
Fork of W5500Interface by
Diff: WIZnet/W5500.cpp
- Revision:
- 18:afec30f0922a
- Parent:
- 17:60f75e78f35d
--- a/WIZnet/W5500.cpp Tue Aug 14 01:20:36 2018 +0000 +++ b/WIZnet/W5500.cpp Thu Aug 16 07:33:40 2018 +0000 @@ -34,12 +34,23 @@ WIZnet_Chip::WIZnet_Chip(PinName mosi, PinName miso, PinName sclk, PinName _cs, PinName _reset): cs(_cs), reset_pin(_reset) { + connected_reset_pin = false; spi = new SPI(mosi, miso, sclk); DBG("SPI interface init...\n"); - spi->format(32, 0); + spi->format(8, 0); spi->frequency(MBED_CONF_W5500_SPI_SPEED); - cs = 1; - reset_pin = 1; + + if (_cs != NC) { + cs = 1; + } else { + DBG("CS pin is necessary. So You have to set CS pin name\n"); + } + + if (_reset != NC) { + reset_pin = 1; + connected_reset_pin = true; + } + inst = this; } @@ -134,22 +145,24 @@ void WIZnet_Chip::reset() { // reset_pin = 1; - reset_pin = 0; - wait_us(500); // 500us (w5500) - reset_pin = 1; - wait_ms(400); // 400ms (w5500) + if(connected_reset_pin) { + reset_pin = 0; + wait_us(500); // 500us (w5500) + reset_pin = 1; + wait_ms(400); // 400ms (w5500) + } #if defined(USE_WIZ550IO_MAC) //reg_rd_mac(SHAR, mac); // read the MAC address inside the module #endif //reg_wr_mac(SHAR, mac); - + // set RX and TX buffer size for (int socket = 0; socket < MAX_SOCK_NUM; socket++) { sreg<uint8_t>(socket, Sn_RXBUF_SIZE, 2); sreg<uint8_t>(socket, Sn_TXBUF_SIZE, 2); } - + reg_rd_mac(SHAR, mac); // read the MAC address inside the module } @@ -184,7 +197,7 @@ if (socket < 0) { return -1; } - + Timer t; t.reset(); t.start(); @@ -196,15 +209,15 @@ while (1) { size1 = sreg<uint16_t>(socket, Sn_RX_RSR); size2 = sreg<uint16_t>(socket, Sn_RX_RSR); - + if (size1 == size2) { break; } - + if (wait_time_ms != (-1) && t.read_ms() > wait_time_ms) { - return NSAPI_ERROR_WOULD_BLOCK; + return NSAPI_ERROR_WOULD_BLOCK; } - + if (!is_connected(socket)) { return -1; } @@ -229,7 +242,7 @@ t.reset(); t.start(); t.start(); - + while(1) { //int size = sreg<uint16_t>(socket, Sn_TX_FSR); int size1, size2; @@ -239,11 +252,11 @@ size1 = sreg<uint16_t>(socket, Sn_TX_FSR); size2 = sreg<uint16_t>(socket, Sn_TX_FSR); DBG("The time taken was %d %d %f seconds\n", wait_time_ms, t.read_ms(), t.read()); - + if (wait_time_ms != (-1) && t.read_ms() > wait_time_ms) { - + return NSAPI_ERROR_WOULD_BLOCK; - } + } } while (size1 != size2); if (size1 > req_size) { return size1;