Skip to content

Commit a3ada5c

Browse files
raiden00plsimbit18
authored andcommitted
boards/nucleo-c0xxx: fix leds handling
Fix LED handling for nucleo-c092rc and nucleo-c071rb. These boards have two LEDs but one is activated with HIGH the other is activated with LOW. Also fix userled registration. Signed-off-by: raiden00pl <[email protected]>
1 parent 31e562b commit a3ada5c

File tree

8 files changed

+54
-18
lines changed

8 files changed

+54
-18
lines changed

boards/arm/stm32f0l0g0/nucleo-c071rb/src/nucleo-c071rb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*/
4646

4747
#define GPIO_LD1 (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_MEDIUM | \
48-
GPIO_OUTPUT_SET | GPIO_PORTA | GPIO_PIN5)
48+
GPIO_OUTPUT_CLEAR | GPIO_PORTA | GPIO_PIN5)
4949
#define GPIO_LD2 (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_MEDIUM | \
5050
GPIO_OUTPUT_SET | GPIO_PORTC | GPIO_PIN9)
5151

boards/arm/stm32f0l0g0/nucleo-c071rb/src/stm32_autoleds.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050

5151
void board_autoled_initialize(void)
5252
{
53-
/* Configure LD2 GPIO for output */
53+
/* Configure LD1 and LD2 GPIO for output */
5454

55+
stm32_configgpio(GPIO_LD1);
5556
stm32_configgpio(GPIO_LD2);
5657
}
5758

@@ -61,7 +62,12 @@ void board_autoled_initialize(void)
6162

6263
void board_autoled_on(int led)
6364
{
64-
if (led == 1)
65+
if (led == BOARD_LED1)
66+
{
67+
stm32_gpiowrite(GPIO_LD1, true);
68+
}
69+
70+
if (led == BOARD_LED2)
6571
{
6672
stm32_gpiowrite(GPIO_LD2, false);
6773
}
@@ -73,7 +79,12 @@ void board_autoled_on(int led)
7379

7480
void board_autoled_off(int led)
7581
{
76-
if (led == 1)
82+
if (led == BOARD_LED1)
83+
{
84+
stm32_gpiowrite(GPIO_LD1, false);
85+
}
86+
87+
if (led == BOARD_LED2)
7788
{
7889
stm32_gpiowrite(GPIO_LD2, true);
7990
}

boards/arm/stm32f0l0g0/nucleo-c071rb/src/stm32_bringup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int stm32_bringup(void)
7878
stm32_iwdginitialize("/dev/watchdog0", STM32_LSI_FREQUENCY);
7979
#endif
8080

81-
#ifdef HAVE_LEDS
81+
#if !defined(CONFIG_ARCH_LEDS) && defined(CONFIG_USERLED_LOWER)
8282
/* Register the LED driver */
8383

8484
ret = userled_lower_initialize(LED_DRIVER_PATH);

boards/arm/stm32f0l0g0/nucleo-c071rb/src/stm32_userleds.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ static int led_pm_prepare(struct pm_callback_s *cb, int domain,
120120

121121
uint32_t board_userled_initialize(void)
122122
{
123-
/* Configure LD2 GPIO for output */
123+
/* Configure LD1 and LD2 GPIO for output */
124124

125+
stm32_configgpio(GPIO_LD1);
125126
stm32_configgpio(GPIO_LD2);
126127
return BOARD_NLEDS;
127128
}
@@ -132,9 +133,14 @@ uint32_t board_userled_initialize(void)
132133

133134
void board_userled(int led, bool ledon)
134135
{
135-
if (led == BOARD_LD2)
136+
if (led == BOARD_LED1)
136137
{
137-
stm32_gpiowrite(GPIO_LD2, ledon);
138+
stm32_gpiowrite(GPIO_LD1, ledon);
139+
}
140+
141+
if (led == BOARD_LED2)
142+
{
143+
stm32_gpiowrite(GPIO_LD2, !ledon);
138144
}
139145
}
140146

@@ -144,7 +150,8 @@ void board_userled(int led, bool ledon)
144150

145151
void board_userled_all(uint32_t ledset)
146152
{
147-
stm32_gpiowrite(GPIO_LD2, (ledset & BOARD_LD2_BIT) != 0);
153+
stm32_gpiowrite(GPIO_LD1, (ledset & BOARD_LED1_BIT) != 0);
154+
stm32_gpiowrite(GPIO_LD2, (ledset & BOARD_LED2_BIT) == 0);
148155
}
149156

150157
/****************************************************************************

boards/arm/stm32f0l0g0/nucleo-c092rc/src/nucleo-c092rc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*/
4646

4747
#define GPIO_LD1 (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_MEDIUM | \
48-
GPIO_OUTPUT_SET | GPIO_PORTA | GPIO_PIN5)
48+
GPIO_OUTPUT_CLEAR | GPIO_PORTA | GPIO_PIN5)
4949
#define GPIO_LD2 (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_MEDIUM | \
5050
GPIO_OUTPUT_SET | GPIO_PORTC | GPIO_PIN9)
5151

boards/arm/stm32f0l0g0/nucleo-c092rc/src/stm32_autoleds.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050

5151
void board_autoled_initialize(void)
5252
{
53-
/* Configure LD2 GPIO for output */
53+
/* Configure LD1 and LD2 GPIO for output */
5454

55+
stm32_configgpio(GPIO_LD1);
5556
stm32_configgpio(GPIO_LD2);
5657
}
5758

@@ -61,7 +62,12 @@ void board_autoled_initialize(void)
6162

6263
void board_autoled_on(int led)
6364
{
64-
if (led == 1)
65+
if (led == BOARD_LED1)
66+
{
67+
stm32_gpiowrite(GPIO_LD1, true);
68+
}
69+
70+
if (led == BOARD_LED2)
6571
{
6672
stm32_gpiowrite(GPIO_LD2, false);
6773
}
@@ -73,7 +79,12 @@ void board_autoled_on(int led)
7379

7480
void board_autoled_off(int led)
7581
{
76-
if (led == 1)
82+
if (led == BOARD_LED1)
83+
{
84+
stm32_gpiowrite(GPIO_LD1, false);
85+
}
86+
87+
if (led == BOARD_LED2)
7788
{
7889
stm32_gpiowrite(GPIO_LD2, true);
7990
}

boards/arm/stm32f0l0g0/nucleo-c092rc/src/stm32_bringup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int stm32_bringup(void)
7878
stm32_iwdginitialize("/dev/watchdog0", STM32_LSI_FREQUENCY);
7979
#endif
8080

81-
#ifdef HAVE_LEDS
81+
#if !defined(CONFIG_ARCH_LEDS) && defined(CONFIG_USERLED_LOWER)
8282
/* Register the LED driver */
8383

8484
ret = userled_lower_initialize(LED_DRIVER_PATH);

boards/arm/stm32f0l0g0/nucleo-c092rc/src/stm32_userleds.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ static int led_pm_prepare(struct pm_callback_s *cb, int domain,
120120

121121
uint32_t board_userled_initialize(void)
122122
{
123-
/* Configure LD2 GPIO for output */
123+
/* Configure LD1 and LD2 GPIO for output */
124124

125+
stm32_configgpio(GPIO_LD1);
125126
stm32_configgpio(GPIO_LD2);
126127
return BOARD_NLEDS;
127128
}
@@ -132,9 +133,14 @@ uint32_t board_userled_initialize(void)
132133

133134
void board_userled(int led, bool ledon)
134135
{
135-
if (led == BOARD_LD2)
136+
if (led == BOARD_LED1)
136137
{
137-
stm32_gpiowrite(GPIO_LD2, ledon);
138+
stm32_gpiowrite(GPIO_LD1, ledon);
139+
}
140+
141+
if (led == BOARD_LED2)
142+
{
143+
stm32_gpiowrite(GPIO_LD2, !ledon);
138144
}
139145
}
140146

@@ -144,7 +150,8 @@ void board_userled(int led, bool ledon)
144150

145151
void board_userled_all(uint32_t ledset)
146152
{
147-
stm32_gpiowrite(GPIO_LD2, (ledset & BOARD_LD2_BIT) != 0);
153+
stm32_gpiowrite(GPIO_LD1, (ledset & BOARD_LED1_BIT) != 0);
154+
stm32_gpiowrite(GPIO_LD2, (ledset & BOARD_LED2_BIT) == 0);
148155
}
149156

150157
/****************************************************************************

0 commit comments

Comments
 (0)