Skip to content

Commit deaa3af

Browse files
committed
fix(rtc): enable the alarm output, open-drain active low on PC13
setAlarmOutput() applied the new output settings by calling HAL_RTC_Init() again, but HAL_RTC_Init() skips all configuration once the calendar is initialized, which setTime()/setDate() always do first, so the alarm output was never enabled. Write the OSEL/POL (CR) and output type/remap (OR) bits directly. PC13 is also the WAKE UP button (to GND, 100k pull-up, JP2 closed as shipped), so drive it open-drain, active low instead of push-pull high: a WAKE UP press during an alarm pulse can then no longer short a driven-high pin to GND. The example's LED now goes from 3V3 to PC13.
1 parent 1ef3e50 commit deaa3af

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

‎examples/Inkplate6Motion/Advanced/RTC/Inkplate_6_Motion_RTC_Alarm_Output/Inkplate_6_Motion_RTC_Alarm_Output.ino‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
*
44
* @file Inkplate_6_Motion_RTC_Alarm_Output.ino
55
* @brief This example will send a pulse on the PC13 pin upon a RTC alarm event
6-
* Connect a 330Ohm resistor and an LED on PC13, upon the alarm, the LED will blink
6+
* PC13 goes low on the alarm (open-drain). Connect a 1kOhm resistor and an LED between 3V3 and
7+
* PC13 (LED cathode towards PC13), upon the alarm, the LED will blink.
8+
* PC13 is also the WAKE UP button pin, so pressing WAKE UP lights the LED too.
79
*
810
* For info on how to quickly get started with Inkplate 6MOTION visit docs.inkplate.com
911
*

‎src/stm32System/STM32H7RTC.cpp‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,10 @@ void STM32H7RTC::setAlarmOutput(bool _outEn, uint32_t _alarm)
526526
__HAL_RCC_GPIOC_CLK_ENABLE();
527527
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
528528
_stm32MotionHrtc.Init.OutPut = _alarm;
529-
// You can change impulse polarity here. By default, on alarm event output will be pulled to high.
530-
_stm32MotionHrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
531-
_stm32MotionHrtc.Init.OutPutType = RTC_OUTPUT_TYPE_PUSHPULL;
529+
// Open-drain, active low: on an alarm event the output pulls PC13 to GND. PC13 is also the WAKE UP
530+
// button (to GND, 100k pull-up to 3V3, JP2 closed), so it must never be driven high.
531+
_stm32MotionHrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_LOW;
532+
_stm32MotionHrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
532533
}
533534
else
534535
{
@@ -537,10 +538,14 @@ void STM32H7RTC::setAlarmOutput(bool _outEn, uint32_t _alarm)
537538
_stm32MotionHrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
538539
_stm32MotionHrtc.Init.OutPutType = RTC_OUTPUT_TYPE_PUSHPULL;
539540
}
540-
if (HAL_RTC_Init(&_stm32MotionHrtc) != HAL_OK)
541-
{
542-
Error_Handler();
543-
}
541+
// HAL_RTC_Init() changes nothing once the calendar is set (and setTime()/setDate() set it),
542+
// so write the output select, polarity, type and remap bits directly.
543+
__HAL_RTC_WRITEPROTECTION_DISABLE(&_stm32MotionHrtc);
544+
_stm32MotionHrtc.Instance->CR = (_stm32MotionHrtc.Instance->CR & ~(RTC_CR_OSEL | RTC_CR_POL)) |
545+
_stm32MotionHrtc.Init.OutPut | _stm32MotionHrtc.Init.OutPutPolarity;
546+
_stm32MotionHrtc.Instance->OR = (_stm32MotionHrtc.Instance->OR & ~(RTC_OR_ALARMOUTTYPE | RTC_OR_OUT_RMP)) |
547+
_stm32MotionHrtc.Init.OutPutType | _stm32MotionHrtc.Init.OutPutRemap;
548+
__HAL_RTC_WRITEPROTECTION_ENABLE(&_stm32MotionHrtc);
544549
}
545550

546551
/**

0 commit comments

Comments
 (0)