Thanks to visit codestin.com
Credit goes to github.com

Skip to content

L4 integration: Added new lines for building for l4 series. #1904

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

Closed
wants to merge 1 commit into from

Conversation

tobbad
Copy link
Contributor

@tobbad tobbad commented Mar 15, 2016

This is the 4th PR in a series of PR to support the STM32L4 series in micropython. (see http://forum.micropython.org/viewtopic.php?f=12&t=1332&sid=64e2f63af49643c3edee159171f4a365)

I add the modifications to the Makefile to support the build of the new platform. I had to add the inclusion of the libgcc as on line 965 of the stm32l4xx_hal_uart.h there is a division with 64bit parameter (Macro UART_DIV_LPUART). The PCLK can be the system clock which is on L4 up to 80MHz. Multiply 80MHz by 256 is larger than 2**32. Is there a better way to solve this problem?

Including libgcc still gives link error:
arm-none-eabi-ld: warning: /usr/lib/gcc/arm-none-eabi/4.9.3/armv7e-m/fpu/libgcc.a(bpabi.o) uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail
arm-none-eabi-ld: warning: /usr/lib/gcc/arm-none-eabi/4.9.3/armv7e-m/fpu/libgcc.a(_divdi3.o) uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail
arm-none-eabi-ld: warning: /usr/lib/gcc/arm-none-eabi/4.9.3/armv7e-m/fpu/libgcc.a(_udivdi3.o) uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail

How can this be solved?

@dpgeorge
Copy link
Member

The PCLK can be the system clock which is on L4 up to 80MHz. Multiply 80MHz by 256 is larger than 2**32. Is there a better way to solve this problem?

If this is the only location where 64-bit integer arith is used, then it would be good to find an alternative. For example, pre-dividing the clock by 8 and post-multiplying the answer by 8 should work.

@tobbad tobbad force-pushed the l4_integration_makefile branch from 34af761 to a838aae Compare March 16, 2016 16:00
@tobbad
Copy link
Contributor Author

tobbad commented Mar 16, 2016

I modified stm32l4xx_hal_uart.h in the way you proposed and therefore removed the inclusion of libgcc in the stm32l4 build. With a little python program I calculated the devision of the calculations:
Old:
(((__PCLK__)*256)/((__BAUD__)))
New:
((((__PCLK__)<<5)/((__BAUD__)))<<3)
With the old code the maximal deviation (expected Baud)/(real Baud) is about 0.06%. For the new code we will raise up to 0.523%. So do not transmit more than 11 Bytes in one go.

This modification is put in a separate commit to see the changes done to the vanilla HAL (as proposed by dhylands).

@dpgeorge
Copy link
Member

If the maximum for PCLK is 80MHz, would it be better to do (PCLK<<7 / BAUD) <<1? Less error and no overflow?

@tobbad
Copy link
Contributor Author

tobbad commented Mar 16, 2016

2**32/80E6=53.6870912. So the maximal shift up is floor(log(2**32/80E6 )/log(2)) = 5 or factor 32.

@dpgeorge
Copy link
Member

This is not a good solution, we don't want to lose precision like this. The BRR register is actually only 20-bits wide, and one can write a custom division routine, something like:

uint32_t div = pclk / 0x1000000 + 1;
pclk /= div;
baud /= div;
brr = 256 * pclk / baud; // won't overflow

This code removes a common factor between pclk and baud before doing the large division. For pclk=80MHz it'll divide the two variables through by 5, which is enough to make sure 256 * pclk doesn't overflow an unsigned 32-bit int.

@tobbad
Copy link
Contributor Author

tobbad commented Mar 21, 2016

Solution which works for any frequency from 32768...4294967295 (2**32-1) is checked in to #1890.

@dpgeorge
Copy link
Member

Merged in 69f26c6.

@dpgeorge dpgeorge closed this Apr 16, 2016
@tobbad tobbad deleted the l4_integration_makefile branch April 18, 2016 14:33
tannewt added a commit to tannewt/circuitpython that referenced this pull request May 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants