WIZnet Developer Forum

STM32F4 Can't init

Hello I try to using wizchip_setnetinfo but only dns is set correctly. Think i wrong implement wizchip_write and wizchip_read.
Instead setted info via wizchip_getnetinfo i get:

MAC: 04:81:FF:81:FF:81
SIP: 255.129.255.129
GAR: 255.129.255.129
SUB: 255.129.255.129
DNS: 1.168.4.99
void network_init() {
    uint8_t bufSize[] = {2, 2, 2, 2};

    reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
    reg_wizchip_spi_cbfunc(wizchip_read, wizchip_write);

    wizchip_init(bufSize, bufSize);
    wiz_NetInfo netInfo = { .mac = {0x00, 0x08, 0xdc,0x00, 0xab, 0xcd},
                            .ip  = {192, 168, 1, 123},
                            .sn  = {255, 255, 255, 0},
                            .gw  = {192, 168, 1, 1},
                            .dns = {1,168,4,99};

    wizchip_setnetinfo(&netInfo);
    wizchip_getnetinfo(&netInfo);

    delay_ms(2000);
    uint8_t *mac = netInfo.mac;

    uprintf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
    uprintf("SIP: %d.%d.%d.%d\r\n", netInfo.ip[0],netInfo.ip[1],netInfo.ip[2],netInfo.ip[3]);
    uprintf("GAR: %d.%d.%d.%d\r\n", netInfo.gw[0],netInfo.gw[1],netInfo.gw[2],netInfo.gw[3]);
    uprintf("SUB: %d.%d.%d.%d\r\n", netInfo.sn[0],netInfo.sn[1],netInfo.sn[2],netInfo.sn[3]);
    uprintf("DNS: %d.%d.%d.%d\r\n", netInfo.dns[0],netInfo.dns[1],netInfo.dns[2],netInfo.dns[3]);
}

void init_spi() {
    SPI_I2S_DeInit(SPI1);

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_SPI1);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_SPI1);

    GPIO_InitTypeDef GPIO_InitStructure;

    // SPI
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    // CS
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_4;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    //

    SPI_InitTypeDef SPI_InitTypeDefStruct;
    SPI_InitTypeDefStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
    SPI_InitTypeDefStruct.SPI_Mode = SPI_Mode_Master;
    SPI_InitTypeDefStruct.SPI_DataSize = SPI_DataSize_8b;
    SPI_InitTypeDefStruct.SPI_CPOL = SPI_CPOL_Low;
    SPI_InitTypeDefStruct.SPI_CPHA = SPI_CPHA_1Edge;
    SPI_InitTypeDefStruct.SPI_NSS = SPI_NSS_Soft;
    SPI_InitTypeDefStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
    SPI_InitTypeDefStruct.SPI_FirstBit = SPI_FirstBit_MSB;

    SPI_Init(SPI1, &SPI_InitTypeDefStruct);
    SPI_Cmd(SPI1, ENABLE);
    SPI_NSSInternalSoftwareConfig(SPI1, SPI_NSSInternalSoft_Set);
}

void wizchip_select  () { GPIO_ResetBits (GPIOA, GPIO_Pin_4); }
void wizchip_deselect() { GPIO_SetBits   (GPIOA, GPIO_Pin_4); }

void wizchip_write(uint8_t wb) {
    while (SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE) == RESET);
    SPI_I2S_SendData(SPI1, wb);
}

uint8_t wizchip_read() {
    while (SPI_GetFlagStatus(SPI1, SPI_FLAG_RXNE) == RESET);
    return SPI_I2S_ReceiveData(SPI1);
}

void hw_init() {
    RCC_APB2PeriphClockCmd (RCC_APB2Periph_SYSCFG, ENABLE);
    RCC_APB2PeriphClockCmd (RCC_APB2Periph_SPI1  , ENABLE);
    RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA , ENABLE);
    RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOD , ENABLE); // The LEDs are on GPIOD

    init_spi();

    GPIO_InitTypeDef  GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin   = LED_GREEN_PIN|LED_ORANGE_PIN|LED_RED_PIN|LED_BLUE_PIN;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOD, &GPIO_InitStructure);

    /* Connect PXx to USARTx_Tx* + Rx*/
    GPIO_PinAFConfig(DISCOVERY_COM_TX_GPIO_PORT, DISCOVERY_COM_TX_SOURCE, DISCOVERY_COM_TX_AF);
    GPIO_PinAFConfig(DISCOVERY_COM_RX_GPIO_PORT, DISCOVERY_COM_RX_SOURCE, DISCOVERY_COM_RX_AF);

    USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb);
}

int main() {
    if (SysTick_Config(SystemCoreClock / 1000))
        while (1) ;    // Capture error

    hw_init();
    network_init();

    while (1) ;
    return 0;
}

Thank in advance.

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.