Skip to content

Commit 562c73b

Browse files
authored
Merge pull request #6458 from blues/swan_r5_3v3_enable
fix(swan_r5): 3v3 was enabled but then immediately reset.
2 parents d0953e8 + 019a160 commit 562c73b

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

ports/stm/boards/swan_r5/board.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,27 @@
3030
#include "stm32l4xx.h"
3131
#include "stm32l4r5xx.h"
3232

33+
#include "shared-bindings/microcontroller/Pin.h"
34+
#include "shared-bindings/digitalio/DigitalInOut.h"
35+
#include "shared-bindings/digitalio/Direction.h"
36+
#include "shared-bindings/digitalio/DriveMode.h"
37+
#include "board.h"
38+
39+
digitalio_digitalinout_obj_t power_pin = { .base.type = &digitalio_digitalinout_type };
40+
digitalio_digitalinout_obj_t discharge_pin = { .base.type = &digitalio_digitalinout_type };
41+
3342
void initialize_discharge_pin(void) {
43+
3444
/* Initialize the 3V3 discharge to be OFF and the output power to be ON */
3545
__HAL_RCC_GPIOE_CLK_ENABLE();
3646
__HAL_RCC_GPIOC_CLK_ENABLE();
3747

48+
49+
common_hal_digitalio_digitalinout_construct(&power_pin, &pin_PE04);
50+
common_hal_digitalio_digitalinout_construct(&discharge_pin, &pin_PE06);
51+
common_hal_digitalio_digitalinout_never_reset(&power_pin);
52+
common_hal_digitalio_digitalinout_never_reset(&discharge_pin);
53+
3854
GPIO_InitTypeDef GPIO_InitStruct;
3955
/* Set the DISCHARGE pin and the USB_DETECT pin to FLOAT */
4056
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
@@ -49,6 +65,7 @@ void initialize_discharge_pin(void) {
4965
GPIO_InitStruct.Pin = GPIO_PIN_4;
5066
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
5167
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_SET);
68+
5269
}
5370

5471
void board_init(void) {
@@ -59,8 +76,6 @@ void board_init(void) {
5976
// Without this, USB does not function.
6077
HAL_InitTick((1UL << __NVIC_PRIO_BITS) - 1UL);
6178

62-
initialize_discharge_pin();
63-
6479
__HAL_RCC_GPIOE_CLK_ENABLE();
6580
GPIO_InitTypeDef GPIO_InitStruct;
6681
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
@@ -78,6 +93,7 @@ bool board_requests_safe_mode(void) {
7893
}
7994

8095
void reset_board(void) {
96+
initialize_discharge_pin();
8197
}
8298

8399
void board_deinit(void) {

ports/stm/boards/swan_r5/board.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef _BOARDS_SWAN_R5_BOARD_H_
2+
#define _BOARDS_SWAN_R5_BOARD_H_
3+
4+
#include "common-hal/digitalio/DigitalInOut.h"
5+
6+
extern digitalio_digitalinout_obj_t power_pin;
7+
extern digitalio_digitalinout_obj_t discharge_pin;
8+
9+
10+
#endif // _BOARDS_SWAN_R5_BOARD_H_

ports/stm/boards/swan_r5/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,6 @@
6464

6565
#define DEFAULT_UART_BUS_RX (&pin_PA10)
6666
#define DEFAULT_UART_BUS_TX (&pin_PA09)
67+
68+
#define SWAN_R5_DISCHARGE_3V3 (&pin_PE06)
69+
#define SWAN_R5_ENABLE_3V3 (&pin_PE04)

ports/stm/boards/swan_r5/pins.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "py/objtuple.h"
22
#include "shared-bindings/board/__init__.h"
3+
#include "board.h"
34

45
// extended pins
56
STATIC const mp_rom_map_elem_t board_module_carrier_table[] = {
@@ -86,10 +87,8 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
8687

8788
{ MP_ROM_QSTR(MP_QSTR_ext), MP_ROM_PTR(&carrier_type) },
8889

89-
{ MP_ROM_QSTR(MP_QSTR_ENABLE_3V3), MP_ROM_PTR(&pin_PE04) },
90-
{ MP_ROM_QSTR(MP_QSTR_DISCHARGE_3V3), MP_ROM_PTR(&pin_PE06) },
91-
{ MP_ROM_QSTR(MP_QSTR_DISABLE_DISCHARGING), MP_ROM_TRUE },
92-
{ MP_ROM_QSTR(MP_QSTR_ENABLE_DISCHARGING), MP_ROM_FALSE },
90+
{ MP_ROM_QSTR(MP_QSTR_ENABLE_3V3), &power_pin },
91+
{ MP_ROM_QSTR(MP_QSTR_DISCHARGE_3V3), &discharge_pin },
9392

9493
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA03) }, // PWM, ADC
9594
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA01) }, // PWM, ADC

0 commit comments

Comments
 (0)