github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/machine/board_nucleowl55jc.go (about)

     1  //go:build nucleowl55jc
     2  
     3  package machine
     4  
     5  import (
     6  	"device/stm32"
     7  	"runtime/interrupt"
     8  )
     9  
    10  const (
    11  	LED_BLUE  = PB15
    12  	LED_GREEN = PB9
    13  	LED_RED   = PB11
    14  	LED       = LED_RED
    15  
    16  	BTN1   = PA0
    17  	BTN2   = PA1
    18  	BTN3   = PC6
    19  	BUTTON = BTN1
    20  
    21  	// SubGhz (SPI3)
    22  	SPI0_NSS_PIN = PA4
    23  	SPI0_SCK_PIN = PA5
    24  	SPI0_SDO_PIN = PA6
    25  	SPI0_SDI_PIN = PA7
    26  
    27  	//MCU USART1
    28  	UART1_TX_PIN = PB6
    29  	UART1_RX_PIN = PB7
    30  
    31  	//MCU USART2
    32  	UART2_RX_PIN = PA3
    33  	UART2_TX_PIN = PA2
    34  
    35  	// DEFAULT USART
    36  	UART_RX_PIN = UART2_RX_PIN
    37  	UART_TX_PIN = UART2_TX_PIN
    38  
    39  	// I2C1 pins
    40  	I2C1_SCL_PIN  = PA9
    41  	I2C1_SDA_PIN  = PA10
    42  	I2C1_ALT_FUNC = 4
    43  
    44  	// I2C2 pins
    45  	I2C2_SCL_PIN  = PA12
    46  	I2C2_SDA_PIN  = PA11
    47  	I2C2_ALT_FUNC = 4
    48  
    49  	// I2C0 alias for I2C1
    50  	I2C0_SDA_PIN = I2C1_SDA_PIN
    51  	I2C0_SCL_PIN = I2C1_SCL_PIN
    52  )
    53  
    54  var (
    55  	// STM32 UART2 is connected to the embedded STLINKV3 Virtual Com Port
    56  	UART0  = &_UART0
    57  	_UART0 = UART{
    58  		Buffer:            NewRingBuffer(),
    59  		Bus:               stm32.USART2,
    60  		TxAltFuncSelector: 7,
    61  		RxAltFuncSelector: 7,
    62  	}
    63  
    64  	// UART1 is free
    65  	UART1  = &_UART1
    66  	_UART1 = UART{
    67  		Buffer:            NewRingBuffer(),
    68  		Bus:               stm32.USART1,
    69  		TxAltFuncSelector: 7,
    70  		RxAltFuncSelector: 7,
    71  	}
    72  
    73  	DefaultUART = UART0
    74  
    75  	// I2C Busses
    76  	I2C1 = &I2C{
    77  		Bus:             stm32.I2C1,
    78  		AltFuncSelector: I2C1_ALT_FUNC,
    79  	}
    80  	I2C2 = &I2C{
    81  		Bus:             stm32.I2C2,
    82  		AltFuncSelector: I2C2_ALT_FUNC,
    83  	}
    84  	I2C0 = I2C1
    85  
    86  	// SPI
    87  	SPI3 = SPI{
    88  		Bus: stm32.SPI3,
    89  	}
    90  )
    91  
    92  func init() {
    93  	// Enable UARTs Interrupts
    94  	UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART0.handleInterrupt)
    95  	UART1.Interrupt = interrupt.New(stm32.IRQ_USART1, _UART1.handleInterrupt)
    96  }