Skip to content

Commit

Permalink
Merge pull request #960 from miguelfreitas/main
Browse files Browse the repository at this point in the history
STM32Hxx porting fixes and suggestions
  • Loading branch information
tony-josi-aws authored Jul 21, 2023
2 parents efef122 + 245d587 commit f89112c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
45 changes: 26 additions & 19 deletions source/portable/NetworkInterface/STM32Hxx/NetworkInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ static int32_t ETH_PHY_IO_WriteReg( uint32_t DevAddr,
static void vClearOptionBit( volatile uint32_t * pulValue,
uint32_t ulValue );

static size_t uxGetOwnCount( ETH_HandleTypeDef * heth );
#if ( ipconfigHAS_PRINTF != 0 )
static size_t uxGetOwnCount( ETH_HandleTypeDef * heth );
#endif

/* FreeRTOS+TCP/multi :
* Each network device has 3 access functions:
Expand Down Expand Up @@ -494,7 +496,7 @@ static BaseType_t xSTM32H_GetPhyLinkStatus( NetworkInterface_t * pxInterface )
NetworkInterface_t * pxFillInterfaceDescriptor( BaseType_t xEMACIndex,
NetworkInterface_t * pxInterface )
{
pxSTM32Hxx_FillInterfaceDescriptor( xEMACIndex, pxInterface );
return pxSTM32H_FillInterfaceDescriptor( xEMACIndex, pxInterface );
}

#endif
Expand Down Expand Up @@ -999,26 +1001,28 @@ static void vClearOptionBit( volatile uint32_t * pulValue,
}
/*-----------------------------------------------------------*/

static size_t uxGetOwnCount( ETH_HandleTypeDef * heth )
{
BaseType_t xIndex;
BaseType_t xCount = 0;
ETH_RxDescListTypeDef * dmarxdesclist = &heth->RxDescList;

/* Count the number of RX descriptors that are owned by DMA. */
for( xIndex = 0; xIndex < ETH_RX_DESC_CNT; xIndex++ )
#if ( ipconfigHAS_PRINTF != 0 )
static size_t uxGetOwnCount( ETH_HandleTypeDef * heth )
{
__IO const ETH_DMADescTypeDef * dmarxdesc =
( __IO const ETH_DMADescTypeDef * )dmarxdesclist->RxDesc[ xIndex ];
BaseType_t xIndex;
BaseType_t xCount = 0;
ETH_RxDescListTypeDef * dmarxdesclist = &heth->RxDescList;

if( ( dmarxdesc->DESC3 & ETH_DMARXNDESCWBF_OWN ) != 0U )
/* Count the number of RX descriptors that are owned by DMA. */
for( xIndex = 0; xIndex < ETH_RX_DESC_CNT; xIndex++ )
{
xCount++;
__IO const ETH_DMADescTypeDef * dmarxdesc =
( __IO const ETH_DMADescTypeDef * )dmarxdesclist->RxDesc[ xIndex ];

if( ( dmarxdesc->DESC3 & ETH_DMARXNDESCWBF_OWN ) != 0U )
{
xCount++;
}
}
}

return xCount;
}
return xCount;
}
#endif /* if ( ipconfigHAS_PRINTF != 0 ) */
/*-----------------------------------------------------------*/

static void prvEMACHandlerTask( void * pvParameters )
Expand All @@ -1027,8 +1031,11 @@ static void prvEMACHandlerTask( void * pvParameters )
* be occupied. In stat case, the program will wait (block) for the counting
* semaphore. */
const TickType_t ulMaxBlockTime = pdMS_TO_TICKS( 100UL );
size_t uxTXDescriptorsUsed = 0U;
size_t uxRXDescriptorsUsed = ETH_RX_DESC_CNT;

#if ( ipconfigHAS_PRINTF != 0 )
size_t uxTXDescriptorsUsed = 0U;
size_t uxRXDescriptorsUsed = ETH_RX_DESC_CNT;
#endif

( void ) pvParameters;

Expand Down
13 changes: 9 additions & 4 deletions source/portable/NetworkInterface/STM32Hxx/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,22 @@ The following macro's are **not** used by the FreeRTOS driver:

All memory that is shared between the CPU and the DMA ETH peripheral, should be
located in special RAM area called ".ethernet_data". This shall be declared in
the linker file.
the linker file (.ld).

It is possible to use the AXI SRAM for this, but RAM{1,2,3} are also connected
to the Ethernet MAC.

Here is an example of the changes to the linker file:

AXI_RAM (xrw) : ORIGIN = 0x24000000, LENGTH = 512K /* .ethernet_data declared here. */
.ethernet_data :
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K /* should already exist in MEMORY section */

.ethernet_data : /* inside SECTIONS section, before /DISCARD/ */
{
PROVIDE_HIDDEN (__ethernet_data_start = .);
KEEP (*(SORT(.ethernet_data.*)))
KEEP (*(.ethernet_data*))
PROVIDE_HIDDEN (__ethernet_data_end = .);
} >AXI_RAM
} >RAM_D1

Here is a table of 3 types of STH32H7 :

Expand All @@ -69,6 +70,10 @@ Here is a table of 3 types of STH32H7 :
Please make sure that the addresses and lengths are correct for your model of STM32H7xx.
If you use a memory that is not supported, it will result in a DMA errors.

Don't redefine a new memory area (like AXI-SRAM, RAM_D1) if it already exists in the
MEMORY section, just take note of it's name for defining the section .ethernet_data later
in that same file.

In FreeRTOSIPConfig.h :

Define the total number of network buffer descriptors, e.g. 64:
Expand Down

0 comments on commit f89112c

Please sign in to comment.