2019-11-20 05:26 AM
In ethernet HAL driver stm32h7xx_hal_eth.c function void ETH_DMARxDescListInit include row: " WRITE_REG(heth->Instance->DMACRDTPR, ((uint32_t)(heth->Init.RxDesc + (((uint32_t)(ETH_RX_DESC_CNT - 1))*sizeof(ETH_DMADescTypeDef)))));"
This code adding value to heth->Init.RxDesc. But, RxDesc is pointer to 32bit and added shift is multiplicated for 4.
Correct row must be:
" WRITE_REG(heth->Instance->DMACRDTPR, ((uint32_t)(heth->Init.RxDesc) + ((uint32_t)(ETH_RX_DESC_CNT - 1))*sizeof(ETH_DMADescTypeDef)));"
Solved! Go to Solution.
2019-11-20 10:08 AM
Created an issue on github:
https://github.com/STMicroelectronics/STM32CubeH7/issues/7
Yep, this is why "better" languages like Go don't have pointer arithmetic. Too confusing. Causes more trouble than utility.
-- pa
2019-11-20 07:59 AM
RxDesc is pointer to ETH_DMADescTypeDef. 6*4 bytes,
-- pa
2019-11-20 09:44 AM
Pavel is right - RxDesc is a pointer to a structure. Therefore neither ST's, nor your version is correct because of C pointer arithmetic, but the correct version is even simpler:
WRITE_REG(heth->Instance->DMACRDTPR, ((uint32_t)(heth->Init.RxDesc + (uint32_t)(ETH_RX_DESC_CNT - 1))));
ST, this is a bug report and we're talking about this line:
P.S. ST's driver developers, who don't know C pointer arithmetic? Fabulous! Do they know arithmetic at all?
2019-11-20 09:49 AM
@Piranha ,
@AAshc 's version is correct, too, as he casts the pointer to integer before applying the + operator, and then uses sizeof() of the target type.
I personally am not fan of pointer arithmetics, as it's bit easily perceivable when fast reading code; and I recommend to explicitly comment all instances where it's used, or, maybe better, use it in the &a[b] form, which is more easily recognizable when reading the code.
(Strictly speaking, pointer cast to integer is not entirely correct, but then all three versions do some form of that).
JW
2019-11-20 10:03 AM
Indeed, I stand corrected! I overlooked the braces in OP's version. Therefore only ST's version is flawed.
2019-11-20 10:08 AM
Created an issue on github:
https://github.com/STMicroelectronics/STM32CubeH7/issues/7
Yep, this is why "better" languages like Go don't have pointer arithmetic. Too confusing. Causes more trouble than utility.
-- pa
2019-11-20 03:53 PM
I don't really care as I don't Cube, but is this limited to H7?
JW
2019-11-21 10:44 AM
Yes, H7 only. Other STM32 series doesn't even have that or similar register. H7 has a different ETH peripheral than all other STM32 MCUs.
2019-11-21 01:03 PM
Oh, I see. Thanks for the explanation.
JW
2019-11-28 02:54 AM
A good practice @Pavel A. ! Thanks for taking the initiative to report the issue there.
So the status of the progress can be followed on Github now.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.