Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in ETH_DMARxDescListInit - reported in the forum #7

Closed
pavel-a opened this issue Nov 20, 2019 · 18 comments
Closed

Bug in ETH_DMARxDescListInit - reported in the forum #7

pavel-a opened this issue Nov 20, 2019 · 18 comments
Assignees
Labels
bug Something isn't working hal HAL-LL driver-related issue or pull-request. internal bug tracker Issue confirmed and logged into the internal bug tracking system st community Also reported by users on the community.st.com
Milestone

Comments

@pavel-a
Copy link

pavel-a commented Nov 20, 2019

Please see description and fix here:
https://community.st.com/s/question/0D50X0000Bea7dNSQQ/hellomay-be-it-is-wrong-ethernet-dma-tail-calculation

In STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_eth.c, line 2704

pavel-a pushed a commit to pavel-a/STM32CubeH7 that referenced this issue Nov 20, 2019
 - Reported in official repo: STMicroelectronics#7
@ALABSTM
Copy link
Contributor

ALABSTM commented Nov 21, 2019

Hi Pavel,

Thank you for having reported this point. It will be transmitted to our development teams. We will be back to you as soon as they provide us with a feedback. Thank you once more.

With regards,

@pavel-a
Copy link
Author

pavel-a commented Nov 21, 2019

Thank you Ali. Kudos for finding this issue go to ashchepkov581 (on the forum).

@ALABSTM
Copy link
Contributor

ALABSTM commented Nov 28, 2019

Hi Pavel,

Our development teams confirmed this issue. A fix will be implemented and published in the frame of a future release. Thank you again for your contribution.

With regards,

@ALABSTM ALABSTM added bug Something isn't working st community Also reported by users on the community.st.com labels Nov 28, 2019
@ALABSTM ALABSTM added the internal bug tracker Issue confirmed and logged into the internal bug tracking system label Nov 29, 2019
@ALABSTM
Copy link
Contributor

ALABSTM commented Nov 29, 2019

ST Internal Reference: 76913

@pavel-a
Copy link
Author

pavel-a commented Feb 6, 2020

Still not fixed in v. 1.6.0

WRITE_REG(heth->Instance->DMACRDTPR, ((uint32_t)(heth->Init.RxDesc + (((uint32_t)(ETH_RX_DESC_CNT - 1))*sizeof(ETH_DMADescTypeDef)))));

pavel-a pushed a commit to pavel-a/STM32CubeH7 that referenced this issue Feb 6, 2020
 - Reported in official repo: STMicroelectronics#7

(cherry picked from my H7_1.5.0
@ALABSTM
Copy link
Contributor

ALABSTM commented Feb 7, 2020

Hi Pavel,

This bug is intended to be fixed in the frame of package v1.7.0 release (or a later one).

With regards,

@ALABSTM
Copy link
Contributor

ALABSTM commented Mar 10, 2020

Hi Pavel,

The fix of this issue will not be part of the v1.7.0 pacakge which will be published soon but part of a later one.

In the meanwhile, here is how the erroneous line will be updated:

-WRITE_REG(heth->Instance->DMACRDTPR, ((uint32_t)(heth->Init.RxDesc + (((uint32_t)(ETH_RX_DESC_CNT - 1))*sizeof(ETH_DMADescTypeDef)))));
+WRITE_REG(heth->Instance->DMACRDTPR, ((uint32_t)(heth->Init.RxDesc) + ((uint32_t)(ETH_RX_DESC_CNT - 1))));

We hope this helps and we thank you once more for your contribution.

With regards,

@pavel-a
Copy link
Author

pavel-a commented Mar 22, 2020

Ali, could they review it again, please? Per the docum (RM0433 page 2889) ETH_DMACRXDTPR indicated location of the last RX descriptor. I understand this as it contains address of the last descriptor, that is (base addr) + sizeof (one descr) * (number of desc. -1)
But in their variant: (base addr) + (number of desc. -1).
-- pa

@ALABSTM
Copy link
Contributor

ALABSTM commented Mar 30, 2020

Hi Pavel,

I had a look to the ETH_DMADescTypeDef structure type and I think I understand better your point. Would you confirm please before I loop back with our development teams? Thanks.

Below is the definition of the ETH_DMADescTypeDef structre type:

typedef struct
{
__IO uint32_t DESC0;
__IO uint32_t DESC1;
__IO uint32_t DESC2;
__IO uint32_t DESC3;
__IO uint32_t BackupAddr0; /* used to store rx buffer 1 address */
__IO uint32_t BackupAddr1; /* used to store rx buffer 2 address */
}ETH_DMADescTypeDef;

Now, sizeof(ETH_DMADescTypeDef) would return 24 (6 members x 4 bytes per member).

And here is the point:

  • On the one hand, removing the sizeof(ETH_DMADescTypeDef) from the expression would not yield the correct result, as you are saying (resulting address less than the targeted one).
  • On the other hand, leaving the sizeof(ETH_DMADescTypeDef) as it is would not yield the correct result neither (resulting address greater than the targeted one).

Rules of pointer arithmetic require rather the following:

  • sizeof(ETH_DMADescTypeDef) / sizeof(uint32_t)

Correct implementation would then be:

-WRITE_REG(heth->Instance->DMACRDTPR, ((uint32_t)(heth->Init.RxDesc + (((uint32_t)(ETH_RX_DESC_CNT - 1))*sizeof(ETH_DMADescTypeDef)))));
+WRITE_REG(heth->Instance->DMACRDTPR, ((uint32_t)(heth->Init.RxDesc) + (((uint32_t)(ETH_RX_DESC_CNT - 1)) * (uint32_t)(sizeof(ETH_DMADescTypeDef) / sizeof(uint32_t)))));

With regards,

@pavel-a
Copy link
Author

pavel-a commented Mar 30, 2020

Ali, sorry for delay. So now there are two "correct" variants. (I assume that red line with - is wrong and green line with + is proposed correction).

I'm confused.... where is pointer arithmetic in (uint32_t)(heth->Init.RxDesc) ? If it were (uint32_t*)(heth->Init.RxDesc) then maybe... Lets' ask help from the ethernet experts on the forum.

Regards,
Pavel

@kele14x
Copy link

kele14x commented Mar 31, 2020

I think @ALABSTM is right. The correct calculation should be (uint32_t)(heth->Init.RxDesc) + offset_bytes

I meet this issue and debug for half of day. I can't believe this bug is not fixed for this long time.

@ALABSTM
Copy link
Contributor

ALABSTM commented Mar 31, 2020

Hi Pavel,

Pointer arithmetic arrives on the scene because structure member RxDesc is actually a pointer to the first DMA Rx descriptor.

ETH_DMADescTypeDef *RxDesc; /*!< Provides the address of the first DMA Rx descriptor in the list */

Hence, as RxDesc points on a ETH_DMADescTypeDef structure, expression (uint32_t)(heth->Init.RxDesc + (uint32_t)1), for instance, will be automatically reevaluated @firstRxDesc + sizeof(ETH_DMADescTypeDef).

To conclude, first fix suggestion is the correct one as confirmed by @kele14x.

-WRITE_REG(heth->Instance->DMACRDTPR, ((uint32_t)(heth->Init.RxDesc + (((uint32_t)(ETH_RX_DESC_CNT - 1))*sizeof(ETH_DMADescTypeDef)))));
+WRITE_REG(heth->Instance->DMACRDTPR, ((uint32_t)(heth->Init.RxDesc) + ((uint32_t)(ETH_RX_DESC_CNT - 1))));

The above expression (in green) will be automatically reevaluated @firstRxDesc + (ETH_RX_DESC_CNT - 1) * sizeof(ETH_DMADescTypeDef).

I hope this makes things clearer. Please do not hesitate if you still have questions about the suggested fix.

With regards,

@pavel-a
Copy link
Author

pavel-a commented Mar 31, 2020

Ali, @kele14x, with all respect it seems there's some misunderstanding.
I put a little example here to explain: rextester.com/LRKA74918
As soon as you cast a pointer to a number (uint32_t)(heth->Init.RxDesc), it becomes a number and pointer stuff no longer applies to it.

However, as @alister commented on the forum, it looks like there are multiple variants of setting this register, depending on the overall design of the driver. If the person who proposed the correction will provide also a thorough fix of the ETH driver, he/she likely knows better. If such fix won't be provided, this issue alone is not important.

Regards,
Pavel A.

@ALABSTM
Copy link
Contributor

ALABSTM commented Mar 31, 2020

Hi Pavel,

I confirm there is a misunderstanding and a typo (from my side) too. In the expression I reported of the suggested fix, parenthesis are not correctly placed. With such an expression, pointer arithmetic applies no more. You are absolutely right about it.

The fix would rather be:

-WRITE_REG(heth->Instance->DMACRDTPR, ((uint32_t)(heth->Init.RxDesc + (((uint32_t)(ETH_RX_DESC_CNT - 1))*sizeof(ETH_DMADescTypeDef)))));
+WRITE_REG(heth->Instance->DMACRDTPR, ((uint32_t)(heth->Init.RxDesc + (uint32_t)(ETH_RX_DESC_CNT - 1))));

I hope you agree on what is written here. I do apologize for the confusion caused.

With regards,

@pavel-a
Copy link
Author

pavel-a commented Apr 1, 2020

Ali, no problem, thanks for checking. The bigger question now is, how about a deeper revision of the eth driver? When this could be expected?

  • P.

@ALABSTM ALABSTM self-assigned this Apr 13, 2020
@tushartp
Copy link

tushartp commented Apr 13, 2020

Hello Guys
I have question if we are changing the RX descriptor tail pointer address.
Do you think the TX descriptors should also be change from

/* Set Transmit Descriptor Tail pointer /
(Line 2663) WRITE_REG(heth->Instance->DMACTDTPR, (uint32_t) heth->Init.TxDesc);
to
/
Set Transmit Descriptor Tail pointer */
(Line 2663) WRITE_REG(heth->Instance->DMACTDTPR, ((uint32_t)(heth->Init.TxDesc + (uint32_t)(ETH_TX_DESC_CNT - 1))));

Please let me know if there is any difference in TX and RX descriptors. I am not expert on this Ethernet HAL handling on stm32h7.

Thanks
Tushar

@pavel-a
Copy link
Author

pavel-a commented Apr 14, 2020

@tushartp You're welcome to ask this in the forum.

@thomask77
Copy link

To make the code's intention clearer, I would suggest

WRITE_REG(heth->Instance->DMACRDTPR, (uint32_t)(&heth->Init.RxDesc[ETH_RX_DESC_CNT - 1]));

Much clearer, and doesn't require knowledge of pointer arithmetic rules.

KwonTae-young added a commit to KwonTae-young/hal_stm32 that referenced this issue May 14, 2020
KwonTae-young added a commit to KwonTae-young/zephyr that referenced this issue May 14, 2020
This driver is being tested to use Ethernet on H7.
F7 and H7 have a slightly different register configuration.

The first goal was the occurrence of the receive interrupt function HAL_ETH_RxCpltCallback().
However, it is not currently working properly.

The register of the PHY chip is read normally.

Because it is a test source, the source is dirty.

There may be a bug when using H7 Ethernet.
1. Bug in ETH_DMARxDescListInit - reported in the forum
:STMicroelectronics/STM32CubeH7#7
2. [bug fixes] STM32H7 Ethernet
:https://community.st.com/s/question/0D50X0000C6eNNSSQ2/bug-fixes-stm32h7-ethernet?t=1581554010199&searchQuery=
3. FAQ: Ethernet not working on STM32H7x3
:https://community.st.com/s/article/FAQ-Ethernet-not-working-on-STM32H7x3
@ALABSTM ALABSTM added this to the v1.8.0 milestone Aug 3, 2020
@ALABSTM ALABSTM closed this as completed Aug 3, 2020
@ALABSTM ALABSTM added the hal HAL-LL driver-related issue or pull-request. label Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hal HAL-LL driver-related issue or pull-request. internal bug tracker Issue confirmed and logged into the internal bug tracking system st community Also reported by users on the community.st.com
Projects
None yet
Development

No branches or pull requests

5 participants