Fix Network module bug in ch32v208rbt6

Now ch32v208rbt6 can use chnet protocol.

I add a small test in it. As follows:
1. Just connect the board with your computer with net line.
2. config the computer TCP/IPv4:
    a. set IP address as 192.168.1.100
    b. set mask as 255.255.255.0
    c. set gateway as 192.168.1.1
    d. custom setup should be modified in wch_tcp_test.c
3. input the command "test_tcp_client" in your console.

Fix bug as follows:
1. remove delay in method ETH_Init, because it doesn't restore the state of systick,
    causing the failure of systick interupt.
2. add ETH_IRQHandler and TIM2_IRQHandler for chnet protocol.
This commit is contained in:
huoyujia081 2024-05-24 16:57:14 +08:00
parent 0961379b88
commit ab8a00ca93
4 changed files with 55 additions and 10 deletions

View File

@ -11,10 +11,15 @@
*******************************************************************************/
#include "ch32v20x_it.h"
#include "board.h"
#include "ch32v20x_exti.h"
#include "ch32v20x_tim.h"
#include "eth_driver.h"
#include <xs_isr.h>
void NMI_Handler(void) __attribute__((interrupt()));
void HardFault_Handler(void) __attribute__((interrupt()));
void ETH_IRQHandler(void) __attribute__((interrupt()));
void TIM2_IRQHandler(void) __attribute__((interrupt()));
/*********************************************************************
* @fn NMI_Handler
@ -55,4 +60,43 @@ void HardFault_Handler(void)
FREE_INT_SP();
}
/*********************************************************************
* @fn ETH_IRQHandler
*
* @brief This function handles ETH exception.
*
* @return none
*/
void ETH_IRQHandler(void)
{
WCHNET_ETHIsr();
}
/*********************************************************************
* @fn TIM2_IRQHandler
*
* @brief This function handles TIM2 exception.
*
* @return none
*/
void TIM2_IRQHandler(void)
{
// GET_INT_SP();
// /* enter interrupt */
// x_base level;
// level = DisableLocalInterrupt();
// isrManager.done->incCounter();
// EnableLocalInterrupt(level);
// WCHNET_TimeIsr(WCHNETTIMERPERIOD);
// TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
// /* leave interrupt */
// level = DisableLocalInterrupt();
// isrManager.done->decCounter();
// EnableLocalInterrupt(level);
// FREE_INT_SP();
// KPrintf("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__);
WCHNET_TimeIsr(WCHNETTIMERPERIOD);
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
}

View File

@ -44,7 +44,7 @@ extern uint32_t SystemCoreClock;
static uint32_t _SysTick_Config(uint32_t ticks)
{
// SystemCoreClockUpdate();
NVIC_SetPriority(SysTicK_IRQn, 1);
NVIC_SetPriority(SysTicK_IRQn, 0x01);
NVIC_SetPriority(Software_IRQn, 0xf0);
NVIC_EnableIRQ(SysTicK_IRQn);
NVIC_EnableIRQ(Software_IRQn);
@ -60,6 +60,7 @@ static uint32_t _SysTick_Config(uint32_t ticks)
*/
void InitBoardHardware()
{
Delay_Init();
USART_Printf_Init(115200);
/* System Tick Configuration */
_SysTick_Config(SystemCoreClock / TICK_PER_SECOND);
@ -68,19 +69,19 @@ void InitBoardHardware()
InitHwUart();
InstallConsole("uart1", SERIAL_DRV_NAME_1, SERIAL_1_DEVICE_NAME_0);
#ifdef BSP_USING_ETH
// InitHwEth();
InitHwEth();
#endif
KPrintf("consle init completed.\n");
KPrintf("board initialization......\n");
// KPrintf("memory address range: [0x%08x - 0x%08x], size: %d\n", (x_ubase) MEMORY_START_ADDRESS, (x_ubase) MEMORY_END_ADDRESS, gd32vf103_SRAM_SIZE);
KPrintf("memory address range: [0x%08x - 0x%08x] SRAM_SIZE: %d, ssize: %d\n", (x_ubase) MEMORY_START_ADDRESS, (x_ubase) MEMORY_END_ADDRESS, SRAM_SIZE, __stack_size);
/* initialize memory system */
x_ubase dynamic_buddy_start = ALIGN_MEN_UP((x_ubase)MEMORY_START_ADDRESS, MM_PAGE_SIZE);
x_ubase dynamic_buddy_end = ALIGN_MEN_DOWN((x_ubase)MEMORY_END_ADDRESS, MM_PAGE_SIZE);
KPrintf("dynamic buddy address range: [0x%08x - 0x%08x]\n", dynamic_buddy_start, dynamic_buddy_end);
// x_ubase dynamic_buddy_start = ALIGN_MEN_UP((x_ubase)MEMORY_START_ADDRESS, MM_PAGE_SIZE);
// x_ubase dynamic_buddy_end = ALIGN_MEN_DOWN((x_ubase)MEMORY_END_ADDRESS, MM_PAGE_SIZE);
// KPrintf("dynamic buddy address range: [0x%08x - 0x%08x]\n", dynamic_buddy_start, dynamic_buddy_end);
// memory address range: [0x20001440 - 0xcb0843e0]
// dynamic buddy address range: [0x20002000 - 0xcb084000]
ShowMemory();
// ShowMemory();
KPrintf("board init done.\n");
KPrintf("start okernel...\n");
}

View File

@ -240,13 +240,13 @@ uint8_t InitHwEth()
KPrintf("version error.\n");
}
// WCHNET_GetMacAddr(MACAddr); // get the chip MAC address
WCHNET_GetMacAddr(MACAddr); // get the chip MAC address
KPrintf("mac addr:");
for (i = 0; i < 6; i++)
KPrintf("%x ", MACAddr[i]);
KPrintf("\n");
// TIM2_Init();
TIM2_Init();
i = ETH_LibInit(IPAddr, GWIPAddr, IPMask, MACAddr); // Ethernet library initialize
mStopIfError(i);
@ -263,7 +263,7 @@ uint8_t InitHwEth()
}
#endif
// memset(socket, 0xff, WCHNET_MAX_SOCKET_NUM);
memset(socket, 0xff, WCHNET_MAX_SOCKET_NUM);
return i;
}

View File

@ -702,7 +702,7 @@ void WCHNET_ETHIsr( void )
void ETH_Init( uint8_t *macAddr )
{
ETH_LedConfiguration( );
Delay_Ms(100);
// Delay_Ms(100); // there is a bug: the Systick register didn't restore original state, causing systick interrupt failing.
ETH_Configuration( macAddr );
ETH_DMATxDescChainInit(DMATxDscrTab, MACTxBuf, ETH_TXBUFNB);
ETH_DMARxDescChainInit(DMARxDscrTab, MACRxBuf, ETH_RXBUFNB);