Skip to content

Commit

Permalink
Merge pull request #2 from WIZnet-ioNIC/develop
Browse files Browse the repository at this point in the history
PR #2
  • Loading branch information
wizhannah authored Aug 12, 2024
2 parents 141daf8 + 7f6d66d commit 1e2497c
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 101 deletions.
63 changes: 39 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
# CMake minimum required version
cmake_minimum_required(VERSION 3.12)

# Pull in SDK (must be before project)
if(NOT DEFINED PICO_SDK_PATH)
set(PICO_SDK_PATH ${CMAKE_SOURCE_DIR}/libraries/pico-sdk)
message(STATUS "PICO_SDK_PATH = ${PICO_SDK_PATH}")
endif()

include(pico_sdk_import.cmake)
include(wiznet_pico_lwip_c_sdk_version.cmake)

# Set project name
set(PROJECT_NAME WIZnet-PICO-LWIP-C)

# Set project informations
project(${PROJECT_NAME} C CXX ASM)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Initialize the SDK
pico_sdk_init()

# Set board
#set(BOARD_NAME WIZnet_Ethernet_HAT)
#set(BOARD_NAME W5100S_EVB_PICO)
#set(BOARD_NAME W5500_EVB_PICO)
set(BOARD_NAME W55RP20_EVB_PICO)

set(BOARD_NAME W5500_EVB_PICO)
#set(BOARD_NAME W55RP20_EVB_PICO)
#set(BOARD_NAME W5100S_EVB_PICO2)
#set(BOARD_NAME W5500_EVB_PICO2)

if(${BOARD_NAME} STREQUAL WIZnet_Ethernet_HAT)
#set(PICO_PLATFORM rp2350) #If you are using WIZnet_ethernet_HAT with Pico2, uncomment it.
set(WIZNET_CHIP W5100S)
add_definitions(-D_WIZCHIP_=W5100S)
add_definitions(-DDEVICE_BOARD_NAME=WIZnet_Ethernet_HAT)
Expand All @@ -40,14 +22,47 @@ elseif(${BOARD_NAME} STREQUAL W5500_EVB_PICO)
set(WIZNET_CHIP W5500)
add_definitions(-D_WIZCHIP_=W5500)
add_definitions(-DDEVICE_BOARD_NAME=W5500_EVB_PICO)

elseif(${BOARD_NAME} STREQUAL W55RP20_EVB_PICO)
set(WIZNET_CHIP W5500)
add_definitions(-D_WIZCHIP_=W5500)
add_definitions(-DDEVICE_BOARD_NAME=W55RP20_EVB_PICO)

elseif(${BOARD_NAME} STREQUAL W5100S_EVB_PICO2)
set(PICO_PLATFORM rp2350)
set(WIZNET_CHIP W5100S)
add_definitions(-D_WIZCHIP_=W5100S)
add_definitions(-DDEVICE_BOARD_NAME=W5100S_EVB_PICO2)
elseif(${BOARD_NAME} STREQUAL W5500_EVB_PICO2)
set(PICO_PLATFORM rp2350)
set(WIZNET_CHIP W5500)
add_definitions(-D_WIZCHIP_=W5500)
add_definitions(-DDEVICE_BOARD_NAME=W5500_EVB_PICO2)
else()
message(FATAL_ERROR "BOARD_NAME is wrong = ${BOARD_NAME}")
endif()

# Pull in SDK (must be before project)
if(NOT DEFINED PICO_SDK_PATH)
set(PICO_SDK_PATH ${CMAKE_SOURCE_DIR}/libraries/pico-sdk)
message(STATUS "PICO_SDK_PATH = ${PICO_SDK_PATH}")
endif()

include(pico_sdk_import.cmake)
include(wiznet_pico_lwip_c_sdk_version.cmake)

# Set project name
set(PROJECT_NAME WIZnet-PICO-LWIP-C)

# Set project informations
project(${PROJECT_NAME} C CXX ASM)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Initialize the SDK
pico_sdk_init()

# Set the project root directory if it's not already defined, as may happen if
# the tests folder is included directly by a parent project, without including
# the top level CMakeLists.txt.
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ The LwIP examples were tested by configuring the development environment for **W

The LwIP examples use **Raspberry Pi Pico** and **WIZnet Ethernet HAT** - ethernet I/O module built on WIZnet's [**W5100S**][link-w5100s] ethernet chip, **W5100S-EVB-Pico** - ethernet I/O module built on [**RP2040**][link-rp2040] and WIZnet's [**W5100S**][link-w5100s] ethernet chip or **W5500-EVB-Pico** and **W55RP20-EVB-Pico** - ethernet I/O module built on [**RP2040**][link-rp2040] and WIZnet's [**W5500**][link-w5500] ethernet chip.

- [**Raspberry Pi Pico**][link-raspberry_pi_pico] & - [**WIZnet Ethernet HAT**][link-wiznet_ethernet_hat]
- [**Raspberry Pi Pico**][link-raspberry_pi_pico] or [**Raspberry Pi Pico2**][link-raspberry_pi_pico2]& [**WIZnet Ethernet HAT**][link-wiznet_ethernet_hat]
- [**W5100S-EVB-Pico**][link-w5100s-evb-pico]
- [**W5500-EVB-Pico**][link-w5500-evb-pico]
- [**W55RP20-EVB-Pico**][link-w55rp20-evb-pico]
- [**W5100S-EVB-Pico2**][link-w5100s-evb-pico2]
- [**W5500-EVB-Pico2**][link-w5500-evb-pico2]


<a name="lwip_example_structure"></a>
Expand Down Expand Up @@ -94,6 +96,8 @@ Setup the board in '**CMakeLists.txt**' in '**WIZnet-PICO-LWIP-C/**' directory a
- W5100S-EVB-Pico
- W5500-EVB-Pico
- W55RP20-EVB-Pico
- W5100S-EVB-Pico2
- W5500-EVB-Pico2

For example, when using WIZnet Ethernet HAT or W5100S-EVB-Pico :

Expand All @@ -116,6 +120,18 @@ When using W55RP20-EVB-Pico :
set(BOARD_NAME W55RP20_EVB_PICO)
```
When using W5100S_EVB_PICO2 :
```cpp
# Set board
set(BOARD_NAME W5100S_EVB_PICO2)
```

When using W5500_EVB_PICO2 :
```cpp
# Set board
set(BOARD_NAME W5500_EVB_PICO2)
```
3. Test
Please refer to 'README.md' in each example directory to find detail guide for testing LwIP examples.
Expand Down Expand Up @@ -380,13 +396,16 @@ Link
[link-w5100s]: https://docs.wiznet.io/Product/iEthernet/W5100S/overview
[link-w5500]: https://docs.wiznet.io/Product/iEthernet/W5500/overview
[link-raspberry_pi_pico]: https://www.raspberrypi.org/products/raspberry-pi-pico/
[link-raspberry_pi_pico2]: https://www.raspberrypi.com/products/raspberry-pi-pico-2/
[link-raspberry_pi_pico_main]: https://github.com/Wiznet/RP2040-HAT-LWIP-C/blob/main/static/images/getting_started/raspberry_pi_pico_main.png
[link-wiznet_ethernet_hat]: https://docs.wiznet.io/Product/Open-Source-Hardware/wiznet_ethernet_hat
[link-wiznet_ethernet_hat_main]: https://github.com/Wiznet/RP2040-HAT-LWIP-C/blob/main/static/images/getting_started/wiznet_ethernet_hat_main.png
[link-w5100s-evb-pico]: https://docs.wiznet.io/Product/iEthernet/W5100S/w5100s-evb-pico
[link-w5100s-evb-pico_main]: https://github.com/Wiznet/RP2040-HAT-LWIP-C/blob/main/static/images/getting_started/w5100s-evb-pico_main.png
[link-w5500-evb-pico]: https://docs.wiznet.io/Product/iEthernet/W5500/w5500-evb-pico
[link-w5500-evb-pico_main]: https://github.com/Wiznet/RP2040-HAT-LWIP-C/blob/main/static/images/getting_started/w5500-evb-pico_main.png
[link-w5100s-evb-pico2]:https://docs.wiznet.io/Product/iEthernet/W5100S/w5100s-evb-pico2
[link-w5500-evb-pico2]:https://docs.wiznet.io/Product/iEthernet/W5500/w5500-evb-pico2
[link-w5500-evb-pico]: https://docs.wiznet.io/Product/iEthernet/W5500/w5500-evb-pico
[link-w55rp20-evb-pico]: https://docs.wiznet.io/Product/ioNIC/W55RP20/w55rp20-evb-pico
[link-dhcp_dns]: https://github.com/Wiznet/RP2040-HAT-LWIP-C/tree/main/examples/dhcp_dns
Expand Down
1 change: 1 addition & 0 deletions port/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ target_include_directories(LWIP_FILES PUBLIC

target_link_libraries(LWIP_FILES PUBLIC
ETHERNET_FILES
pico_stdlib
pico_lwip
pico_lwip_nosys
)
Expand Down
2 changes: 2 additions & 0 deletions port/board_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
#define W5100S_EVB_PICO 1
#define W5500_EVB_PICO 2
#define W55RP20_EVB_PICO 3
#define W5100S_EVB_PICO2 4
#define W5500_EVB_PICO2 5
10 changes: 10 additions & 0 deletions port/ioLibrary_Driver/src/w5x00_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ wiznet_spi_handle_t spi_handle;
* Functions
* ----------------------------------------------------------------------------------------------------
*/
static inline void wizchip_select(void)
{
gpio_put(PIN_CS, 0);
}

static inline void wizchip_deselect(void)
{
gpio_put(PIN_CS, 1);
}

void wizchip_reset()
{
gpio_init(PIN_RST);
Expand Down
75 changes: 1 addition & 74 deletions port/ioLibrary_Driver/src/wiznet_spi_pio.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#include "wiznet_spi_pio.pio.h"



#ifndef PIO_SPI_PREFERRED_PIO
#define PIO_SPI_PREFERRED_PIO 1
#endif
Expand All @@ -33,17 +31,6 @@
#define SPI_OFFSET_WRITE_END __CONCAT(SPI_PROGRAM_NAME, _offset_write_end)
#define SPI_OFFSET_READ_END __CONCAT(SPI_PROGRAM_NAME, _offset_read_end)

//#define ENABLE_SPI_DUMPING 1
#define ENABLE_SPI_DUMPING 0

#if ENABLE_SPI_DUMPING
static uint32_t counter = 0;
#define DUMP_SPI_TRANSACTIONS(A) A
#else
#define DUMP_SPI_TRANSACTIONS(A)
#endif


// All wiznet spi operations must start with writing a 3 byte header
#define SPI_HEADER_LEN 3

Expand Down Expand Up @@ -222,22 +209,6 @@ static void wiznet_spi_pio_frame_end(void) {
#endif
}

#if ENABLE_SPI_DUMPING
static void dump_bytes(const uint8_t *bptr, uint32_t len) {
unsigned int i = 0;

for (i = 0; i < len;) {
if ((i & 0x0f) == 0) {
printf("\n");
} else if ((i & 0x07) == 0) {
printf(" ");
}
printf("%02x ", bptr[i++]);
}
printf("\n");
}
#endif

// send tx then receive rx
// rx can be null if you just want to send, but tx and tx_length must be valid
static bool pio_spi_transfer(spi_pio_state_t *state, const uint8_t *tx, size_t tx_length, uint8_t *rx, size_t rx_length) {
Expand All @@ -248,10 +219,6 @@ static bool pio_spi_transfer(spi_pio_state_t *state, const uint8_t *tx, size_t t

if (rx != NULL && tx != NULL) {
assert(tx && tx_length && rx_length);
DUMP_SPI_TRANSACTIONS(
printf("[%lu] bus TX/RX %u bytes rx %u:", counter++, tx_length, rx_length);
dump_bytes(tx, tx_length);
)

pio_sm_set_enabled(state->pio, state->pio_sm, false); // disable sm
pio_sm_set_wrap(state->pio, state->pio_sm, state->pio_offset + SPI_OFFSET_WRITE_BITS, state->pio_offset + SPI_OFFSET_READ_END - 1);
Expand Down Expand Up @@ -288,10 +255,7 @@ static bool pio_spi_transfer(spi_pio_state_t *state, const uint8_t *tx, size_t t
__compiler_memory_barrier();
} else if (tx != NULL) {
assert(tx_length);
DUMP_SPI_TRANSACTIONS(
printf("[%lu] bus TX only %u bytes:", counter++, tx_length);
dump_bytes(tx, tx_length);
)

pio_sm_set_enabled(state->pio, state->pio_sm, false);
pio_sm_set_wrap(state->pio, state->pio_sm, state->pio_offset + SPI_OFFSET_WRITE_BITS, state->pio_offset + SPI_OFFSET_WRITE_END - 1);
pio_sm_clear_fifos(state->pio, state->pio_sm);
Expand Down Expand Up @@ -323,46 +287,9 @@ static bool pio_spi_transfer(spi_pio_state_t *state, const uint8_t *tx, size_t t
pio_sm_set_consecutive_pindirs(state->pio, state->pio_sm, state->spi_config->data_in_pin, 1, false);
} else if (rx != NULL) {
panic_unsupported(); // shouldn't be used
#if 0
assert(rx_length);
DUMP_SPI_TRANSACTIONS(
printf("[%lu] bus RX only %u bytes:\n", counter++, rx_length);
)
pio_sm_set_enabled(state->pio, state->pio_sm, false); // disable sm
pio_sm_set_wrap(state->pio, state->pio_sm, state->pio_offset + SPI_OFFSET_WRITE_BITS, state->pio_offset + SPI_OFFSET_READ_END - 1); // stall on write at the end of the read
pio_sm_clear_fifos(state->pio, state->pio_sm); // clear fifos from previous run
pio_sm_restart(state->pio, state->pio_sm);
pio_sm_clkdiv_restart(state->pio, state->pio_sm);
pio_sm_put(state->pio, state->pio_sm, rx_length - 1);
pio_sm_exec(state->pio, state->pio_sm, pio_encode_out(pio_y, 32)); // y is bytes to be read
pio_sm_exec(state->pio, state->pio_sm, pio_encode_jmp(state->pio_offset + SPI_OFFSET_READ_BYTE)); // setup pc
dma_channel_abort(state->dma_in);

dma_channel_config in_config = dma_channel_get_default_config(state->dma_in);
channel_config_set_dreq(&in_config, pio_get_dreq(state->pio, state->pio_sm, false));
channel_config_set_write_increment(&in_config, true);
channel_config_set_read_increment(&in_config, false);
channel_config_set_transfer_data_size(&in_config, DMA_SIZE_8);
dma_channel_configure(state->dma_in, &in_config, rx, &state->pio->rxf[state->pio_sm], rx_length, true);

pio_sm_set_enabled(state->pio, state->pio_sm, true);
__compiler_memory_barrier();

dma_channel_wait_for_finish_blocking(state->dma_in);

__compiler_memory_barrier();
#endif
}
pio_sm_exec(state->pio, state->pio_sm, pio_encode_mov(pio_pins, pio_null)); // for next time we turn output on

DUMP_SPI_TRANSACTIONS(
if (rx_length > 0) {
printf("RXed:");
dump_bytes(rx, rx_length);
printf("\n");
}
)

return true;
}

Expand Down
4 changes: 2 additions & 2 deletions wiznet_pico_lwip_c_sdk_version.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# WIZnet-PICO-LWIP-C_BUILD_DEFINE: WIZnet-PICO-LWIP-C_SDK_VERSION_MAJOR, SDK major version number
set(WIZnet-PICO-LWIP-C_SDK_VERSION_MAJOR 1)
set(WIZnet-PICO-LWIP-C_SDK_VERSION_MAJOR 2)
# WIZnet-PICO-LWIP-C_BUILD_DEFINE: WIZnet-PICO-LWIP-C_SDK_VERSION_MINOR, SDK minor version number
set(WIZnet-PICO-LWIP-C_SDK_VERSION_MINOR 1)
set(WIZnet-PICO-LWIP-C_SDK_VERSION_MINOR 0)
# WIZnet-PICO-LWIP-C_BUILD_DEFINE: WIZnet-PICO-LWIP-C_SDK_VERSION_REVISION, SDK version revision
set(WIZnet-PICO-LWIP-C_SDK_VERSION_REVISION 0)
# WIZnet-PICO-LWIP-C_BUILD_DEFINE: WIZnet-PICO-LWIP-C_SDK_VERSION_STRING, SDK version
Expand Down

0 comments on commit 1e2497c

Please sign in to comment.