-
Notifications
You must be signed in to change notification settings - Fork 143
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
[board] Nucleo-L496ZG-P #614
Conversation
ab2fd1a
to
2efdb8a
Compare
The LPUART driver is enabled now, but does not work yet on my Nucleo-L496... |
Maybe the LPUART requires additional power bit enabled in the RCC? I remember some LP bits in there which are not used by the API yet. |
I only see the |
Issue: Uart is on Then I found this little nasty detail: Now I set this bit: But reading back |
Did you enable the PWREN bit in the RCC APB1ENR1 register? Otherwise the PWR peripheral is not clocked. EDIT: looked at you branch, does not seem to be enabled. |
2efdb8a
to
b4be026
Compare
constexpr auto result = Prescaler::from_range(SystemClock::{{ uart_name ~ id }}, baudrate, 1, max); | ||
%% elif uart_name == "Lpuart" | ||
constexpr uint32_t max = (1ul << 19) - 1ul; | ||
constexpr auto result = Prescaler::from_range(SystemClock::{{ uart_name ~ id }} * 256, baudrate / 6, 1, max); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no explanation fot this magic /6
factor right now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was suspicious from the beginning, since the 19-bit - 16-bit = 3-bit, but the scalar is 256 = 8bit, so where do the other 5-bits go? But if this works, meh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the /6
is not the correct solution, it is just a coincidence. The optimal prescaler for 115200 baud is 0x2b672 (177778), ST's table in the manual says 0x2b671 (177777) for 80 MHz clock. The code in this PR with /6
gives 171881. This looks pretty suspicious, still somehow close but not optimal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an int overflow problem, we are calculating prescalers in 32 bit arithmetic.
>>> (80e6*256)/(2**31 - 1)
9.536743168503392
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh crap, we should replace the modm::frequency_t
and uint32_t
with uint64_t
in the modm::Prescaler
class:
https://github.com/modm-io/modm/blob/develop/src/modm/math/algorithm/prescaler.hpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to be careful, int overflow is evil. This compiles:
static constexpr uint32_t clock = 80'000'000;
static constexpr uint64_t clock2 = 80'000'000;
static_assert((clock * 256) != (clock2 * 256));
The system clock structs need an update as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about my solution in adbe4da?
-class
-Prescaler
+template<typename T>
+class
+GenericPrescaler
{
// ...
// sed s/modm::frequency_t/T/
// ...
};
+using Prescaler = GenericPrescaler<modm::frequency_t>;
(except for the typo in the commit message)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good, it leaves the option open to use it at runtime with 32-bit, however I would just make it GenericPrescaler<uint64_t>;
by default, since we only use it at compile time.
Actually 20 bits 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yesssssss (for everything but the prescaler issues)
b4be026
to
a224093
Compare
a224093
to
347acdd
Compare
Now also shared interrupts of any u(s)art should be supported. |
Review, then squash and merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. Shared IRQs are kinda evil though… looks sternly at ST
7f4cc65
to
897579e
Compare
ST decided to use a different pinout for the Zio/Arduino connectors on this Nucleo-L144 board, see schematic.
The ST-Link serial lines are only connected to LpUart1 which is not yet supported by modm; thus the logger is disabled 😒.
I will have a look at the LpUart in the next days...