cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5A5: PC13 with two LEDs - FOUR states (instead of three)?

tjaekel
Lead

Three states on a single GPIO pin with two LEDs is possible.
For users who want to drive 2 LEDs with three states with one signal GPIO - please, see the details below.

But I want to ask one question:
On a STM32U5A5 - how does the PC13 behave? - I see "FOUR states" possible (even I can force later just to use three states).

  • MCU was never flashed with a FW: both LEDs are on (dimmed, like getting pulses)
  • both LEDs off: configure PC13 as input (or GPIO_DeInit() to set as analog pin)
  • LED1 on / LED2 off: configured as output and drive low
  • LED1 off / LED2 on: configure as output and drive high

I cannot force again to see both LEDs on.
But I am sure: after I have soldered my boards, power it up the first time in order to flush the 1st time my FW - both LEDs are on (but dimmed). I assume: there is a frequency (a toggling signal). But why and which one?

BTW: how to configure PC13 for RTC_OUT1? I have not found an ALT setting to do so?

One GPIO pin for three states

LED_oneGPIO.png

  • Use a Dual-LED with two LEDs, "anti-parallel"
  • One LED is on, if GPIO is set low (acting as a sink)
  • The other LED is on, if GPIO is set high (providing a source)
  • Both LEDs are off, if GPIO is configured as an input (no current)

Remark:
if you run VDD as 1V8 (as I do) - you can only use red LEDs! The forward voltage of a green LED (or a blue one) is above 1V8 - it would never go on.  With 3V3 you can use any combination of colors (maybe not white).

The "fourth state"

The fourth state is just there if MCU was never flashed with a FW. Why do I see both LEDs?

I tried to force the "fourth state" but with simple means not possible, like erasing entire MCU flash, not progressing in Reset_Handler.

I can still make use the "fourth state" in order to realize if the MCU has a flashed FW running.

If you want to create a fourth state with one GPIO and two LEDs:

  • generate a frequency (toggling the GPIO fast enough, e.g. with 20 Hz or faster) - both LEDs are on

But this PC13 does not have an option for a PWM output. And not clear how to enable RTC_OUT1/RTC_TS, TAMP_OUT2. Is it maybe a TAMP_OUT2 signal when MCU FW was never flashed?

PC13 not intended to drive LEDs

Yes, I know: datasheet says: PC13,,,PC15 can just source 3mA in total (as sum). And it should not be used to drive LEDs (directly), even I do.
But I made sure the current is below 1mA (1V8 with 300R).

I decided to use PC13 as LED because it does not have any other useful ALT function (e.g. SPI, I2C, ...).

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

BTW: I have implemented the "fourth state" for my LEDs:

  • set a global variable to enable "both LEDs"
  • use this variable and when set: toggle via SysTick or TIM6 INT the LEDs (they toggle between both due to fact that GPIO for both is sink vs. source)

This results in having both LEDs on (toggling so fast that it looks like both are on, greater 20Hz for human eyes). It does not need a PWM.

Example code (in TIM6 INT for AZURE RTOS):

void TIM6_IRQHandler(void)
{
  HAL_TIM_IRQHandler(&htim6);
  if (GBothLEDs)
      LED_Toggle(0);
}

Remark:

AUZURE RTOS does not have an "idle thread" (otherwise you could add there, e.g. when using FreeRTOS). So, I have added the LED "both on" (actually toggle both very fast) in the SysTick, RTOS timer tick INT (used by AZURE RTOS).

The global variable GBothLEDs enables the "fourth state" as "both LEDs on".

It works fine to have four states for two LEDs connected to one single GPIO. Cool.

View solution in original post

4 REPLIES 4
tjaekel
Lead

Here the functions for PC13.

LED_oneGPIO_2.png

How to configure/enable the "additional functions"? (only EVENTOUT is possible for me)

Is one of the "additional functions" enabled when a FW was never flushed?

TDK
Guru

> how to configure PC13 for RTC_OUT1? I have not found an ALT setting to do so?

See Table 628. RTC pin PC13 configuration(1) in the reference manual for how PC13 is configured for RTC options. It is in "Additional functions" because it is not defined as an "alternate function" through the normal means (GPIO_AFRx registers). It is controlled with the RTC registers.

By default, it should be a GPIO pin as far as I can see. Analog mode, high impedance. 

Can definitely light up an LED with less than 1.8 V, though I'd be surprised if it was visible at 0.9 V.

Should be able to connect to a virgin chip and examine register values to determine the configuration when it's in the unknown state.

If you feel a post has answered your question, please click "Accept as Solution".

Thank you, makes sense (to have PC13 as RTC pins, when configuring RTC).

I run board with 1V8 (not 0.9V, too low anyway).

I try to debug a virgin chip, no FW loaded: just to see how to do... (with ST-Link debugger, esp. how to see registers when MCU FW should not be flashed, starting debugger from IDE flashes FW first - very delicate).

BTW: I have implemented the "fourth state" for my LEDs:

  • set a global variable to enable "both LEDs"
  • use this variable and when set: toggle via SysTick or TIM6 INT the LEDs (they toggle between both due to fact that GPIO for both is sink vs. source)

This results in having both LEDs on (toggling so fast that it looks like both are on, greater 20Hz for human eyes). It does not need a PWM.

Example code (in TIM6 INT for AZURE RTOS):

void TIM6_IRQHandler(void)
{
  HAL_TIM_IRQHandler(&htim6);
  if (GBothLEDs)
      LED_Toggle(0);
}

Remark:

AUZURE RTOS does not have an "idle thread" (otherwise you could add there, e.g. when using FreeRTOS). So, I have added the LED "both on" (actually toggle both very fast) in the SysTick, RTOS timer tick INT (used by AZURE RTOS).

The global variable GBothLEDs enables the "fourth state" as "both LEDs on".

It works fine to have four states for two LEDs connected to one single GPIO. Cool.