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

     1  //go:build nucleol031k6
     2  
     3  package machine
     4  
     5  import (
     6  	"device/stm32"
     7  	"runtime/interrupt"
     8  )
     9  
    10  const (
    11  	// Arduino Pins
    12  	A0 = PA0 // ADC_IN0
    13  	A1 = PA1 // ADC_IN1
    14  	A2 = PA3 // ADC_IN3
    15  	A3 = PA4 // ADC_IN4
    16  	A4 = PA5 // ADC_IN5 || I2C1_SDA
    17  	A5 = PA6 // ADC_IN6 || I2C1_SCL
    18  	A6 = PA7 // ADC_IN7
    19  	A7 = PA2 // ADC_IN2
    20  
    21  	D0  = PA10 // USART1_TX
    22  	D1  = PA9  // USART1_RX
    23  	D2  = PA12
    24  	D3  = PB0 // TIM2_CH3
    25  	D4  = PB7
    26  	D5  = PB6  // TIM16_CH1N
    27  	D6  = PB1  // TIM14_CH1
    28  	D9  = PA8  // TIM1_CH1
    29  	D10 = PA11 // SPI_CS || TIM1_CH4
    30  	D11 = PB5  // SPI1_MOSI || TIM3_CH2
    31  	D12 = PB4  // SPI1_MISO
    32  	D13 = PB3  // SPI1_SCK
    33  )
    34  
    35  const (
    36  	LED         = LED_BUILTIN
    37  	LED_BUILTIN = LED_GREEN
    38  	LED_GREEN   = PB3
    39  )
    40  
    41  const (
    42  	// This board does not have a user button, so
    43  	// use first GPIO pin by default
    44  	BUTTON = PA0
    45  )
    46  
    47  const (
    48  	// UART pins
    49  	// PA2 and PA15 are connected to the ST-Link Virtual Com Port (VCP)
    50  	UART_TX_PIN = PA2
    51  	UART_RX_PIN = PA15
    52  
    53  	// SPI
    54  	SPI1_SCK_PIN = PB3
    55  	SPI1_SDI_PIN = PB5
    56  	SPI1_SDO_PIN = PB4
    57  	SPI0_SCK_PIN = SPI1_SCK_PIN
    58  	SPI0_SDI_PIN = SPI1_SDI_PIN
    59  	SPI0_SDO_PIN = SPI1_SDO_PIN
    60  
    61  	// I2C pins
    62  	// PB6 and PB7 are mapped to CN4 pin 7 and CN4 pin 8 respectively with the
    63  	// default solder bridge settings
    64  	I2C0_SCL_PIN  = PB7
    65  	I2C0_SDA_PIN  = PB6
    66  	I2C0_ALT_FUNC = 1
    67  )
    68  
    69  var (
    70  	// USART2 is the hardware serial port connected to the onboard ST-LINK
    71  	// debugger to be exposed as virtual COM port over USB on Nucleo boards.
    72  	UART1  = &_UART1
    73  	_UART1 = UART{
    74  		Buffer:            NewRingBuffer(),
    75  		Bus:               stm32.USART2,
    76  		TxAltFuncSelector: 4,
    77  		RxAltFuncSelector: 4,
    78  	}
    79  	DefaultUART = UART1
    80  
    81  	// I2C1 is documented, alias to I2C0 as well
    82  	I2C1 = &I2C{
    83  		Bus:             stm32.I2C1,
    84  		AltFuncSelector: 1,
    85  	}
    86  	I2C0 = I2C1
    87  
    88  	// SPI
    89  	SPI0 = SPI{
    90  		Bus:             stm32.SPI1,
    91  		AltFuncSelector: 0,
    92  	}
    93  	SPI1 = &SPI0
    94  )
    95  
    96  func init() {
    97  	UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt)
    98  }