STM32G0 RTC init failure Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Thargon
Posts: 135
Joined: Wed Feb 04, 2015 5:03 pm
Location: CITEC, Bielefeld University, germany
Has thanked: 15 times
Been thanked: 24 times
Contact:

STM32G0 RTC init failure  Topic is solved

Postby Thargon » Wed Sep 16, 2020 4:40 pm

When I enable RTC on my NUCLEO-G071RB board, ChibiOS won't start due to a failed assertion during HAL initialization. This issue can easily be reproduced for the RT-STM32G07RB-NUCLEO64 demo.

DETAILS

To enable RTC, I enabled the flag in halconf.h and set STM32_RTCSEL to STM32_RTCSEL_LSI in mcuconf.h. Furthermore, I enabled all debug checks and assertions in chconf.h (CH_DBG_ENABLE_CHECKS and CH_DBG_ENABLE_ASSERTS).

When halInit() is called at the beginning of the main() function, it executes rtcInit(), which again calls rtc_lld_init() of the RTCv3 driver. This function eventually calls the STM32_RTC_ENABLE_ALL_EXTI() macro, which again executes extiEnableGroup1() of the EXTIv1 driver. At the very beginning of that function, there is an assertion, which fails:

Code: Select all

  /* Masked out lines must not be touched by this driver.*/
  osalDbgAssert((mask & STM32_EXTI_IMR1_MASK) == 0U, "fixed lines");

'mask' is the first argument of the call

Code: Select all

extiEnableGroup1(EXTI_MASK1(STM32_RTC_EVENT_RTC_EXTI) | EXTI_MASK1(STM32_RTC_EVENT_TAMP_EXTI),
                 EXTI_MODE_RISING_EDGE | EXTI_MODE_ACTION_INTERRUPT);

After briefly comparing the values of those defines in the code with the definitions in the reference manual (https://www.st.com/resource/en/referenc ... ronics.pdf), those seem to be correct.

BUG & FIX

The assertion itself, however, seems to be flawed in two ways:
  1. According to the comment it should check if any reserved bits are set in 'mask'. Unfortunately, it seems to checks all valid bits instead. This can be fixed easily by negating STM32_EXTI_IMR1_MASK.
  2. STM32_EXTI_IMR1_MASK is defined as 0xFFF8000U, which is the default value of the IMR1 register. The actual mask of valid bits would be 0xFEAFFFFFU. The same issue applies to STM32_EXTI_IMR2_MASK which is defined as 0xFFFFFFFFU (again the default value) instead of 0x00000003U.

When I apply those fixes, Everything seem to be fine, though I'd rather have someone double check to be sure.

Regards
Thomas

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: STM32G0 RTC init failure

Postby Giovanni » Sat Sep 19, 2020 2:31 pm

Hi,

Bits at 1 in STM32_EXTI_IMR1_MASK are those lines that cannot be configured (raising, falling), so I believe definitions are right aand the assertions is doing what it is meant to.

The problem is that in G0 the RTC lines are not among those configurable so using extiEnableGroup1() is inherently wrong. The EXTI driver needs another function for just enabling interrupts on fixed lines (without configuration of edges).

Giovanni

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: STM32G0 RTC init failure

Postby Giovanni » Sun Sep 20, 2020 8:54 am

Hi,

Fixed as bug #1123.

Could you confirm that this fixes your issue?

Giovanni

Thargon
Posts: 135
Joined: Wed Feb 04, 2015 5:03 pm
Location: CITEC, Bielefeld University, germany
Has thanked: 15 times
Been thanked: 24 times
Contact:

Re: STM32G0 RTC init failure

Postby Thargon » Mon Sep 21, 2020 8:06 am

Giovanni wrote:Could you confirm that this fixes your issue?

Confirmed =)

I have two notes to make, though:
  • In extiEnableGroup2() you also use STM32_EXTI_IMR1_MASK for masking the argument (should be STM32_EXTI_IMR2_MASK).
  • The commit message says the fix has been backported to branch 20.3 and 19.1, but it has only been applied to master/trunk so far ;)

Thank you for the quick fix!
Thomas

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: STM32G0 RTC init failure

Postby Giovanni » Wed Sep 23, 2020 9:44 am

Hi,

Fixed that as well and back-ported, thanks.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 15 guests