Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions make/smoketest.mk
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ ifneq ($(STM32), 0)
@$(MD5SUM) $(SMOKE_OUT).hex
$(TINYGO) build -size short -o $(SMOKE_OUT).hex -target=nucleo-f103rb examples/blinky1
@$(MD5SUM) $(SMOKE_OUT).hex
$(TINYGO) build -size short -o $(SMOKE_OUT).hex -target=nucleo-f401re examples/blinky1
@$(MD5SUM) $(SMOKE_OUT).hex
$(TINYGO) build -size short -o $(SMOKE_OUT).hex -target=nucleo-f722ze examples/blinky1
@$(MD5SUM) $(SMOKE_OUT).hex
$(TINYGO) build -size short -o $(SMOKE_OUT).hex -target=nucleo-h753zi examples/blinky1
Expand All @@ -384,6 +386,8 @@ ifneq ($(STM32), 0)
@$(MD5SUM) $(SMOKE_OUT).hex
$(TINYGO) build -size short -o $(SMOKE_OUT).hex -target=stm32f4disco-1 examples/pwm
@$(MD5SUM) $(SMOKE_OUT).hex
$(TINYGO) build -size short -o $(SMOKE_OUT).hex -target=nucleo-f401re examples/pwm
@$(MD5SUM) $(SMOKE_OUT).hex
$(TINYGO) build -size short -o $(SMOKE_OUT).hex -target=stm32f469disco examples/blinky1
@$(MD5SUM) $(SMOKE_OUT).hex
$(TINYGO) build -size short -o $(SMOKE_OUT).hex -target=lorae5 examples/blinky1
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/rand/rand_baremetal.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build nrf || (stm32 && !(stm32f103 || stm32l0x1 || stm32u0)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || esp32s3 || tkey || (tinygo.riscv32 && virt)
//go:build nrf || (stm32 && !(stm32f103 || stm32l0x1 || stm32u0 || stm32f401)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || esp32s3 || tkey || (tinygo.riscv32 && virt)

// If you update the above build constraint, you'll probably also need to update
// src/runtime/rand_hwrng.go.
Expand Down
13 changes: 13 additions & 0 deletions src/examples/pwm/nucleo-f401re.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build nucleof401re

package main

import "machine"

// TIM3 is reserved by the runtime tick timer on STM32F401.
// Use TIM2 instead: PB10=D6 (TIM2_CH3/AF1), PB3=D3 (TIM2_CH2/AF1).
var (
pwm = &machine.TIM2
pinA = machine.D6
pinB = machine.D3
)
140 changes: 140 additions & 0 deletions src/machine/board_nucleof401re.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
//go:build nucleof401re

// Schematic: https://www.st.com/resource/en/user_manual/um1724-stm32-nucleo64-boards-mb1136-stmicroelectronics.pdf
// Datasheet: https://www.st.com/resource/en/datasheet/stm32f401re.pdf

package machine

import (
"device/stm32"
"runtime/interrupt"
)

const xtalHz = 8_000_000

const (
// Arduino Pins
A0 = PA0
A1 = PA1
A2 = PA4
A3 = PB0
A4 = PC1
A5 = PC0

D0 = PA3
D1 = PA2
D2 = PA10
D3 = PB3
D4 = PB5
D5 = PB4
D6 = PB10
D7 = PA8
D8 = PA9
D9 = PC7
D10 = PB6
D11 = PA7
D12 = PA6
D13 = PA5
D14 = PB9
D15 = PB8
)

// Analog pins (ADC1 channels).
// examples/adc uses ADC2 (PA2). That pin is ST-Link VCP TX, so use A0 instead.
const (
ADC0 = PA0
ADC1 = PA1
ADC2 = PA2
ADC3 = PA3
ADC4 = PA4
ADC5 = PA5
ADC6 = PA6
ADC7 = PA7
ADC8 = PB0
ADC9 = PB1
ADC10 = PC0
ADC11 = PC1
ADC12 = PC2
ADC13 = PC3
ADC14 = PC4
ADC15 = PC5
)

// User LD2: the green LED is a user LED connected to Arduino signal D13
// corresponding to STM32 I/O PA5.
const (
LED = LED_BUILTIN
LED_BUILTIN = LED_GREEN
LED_GREEN = PA5
)

// BUTTON is the user button B1 connected to PC13 (active low).
const BUTTON = PC13

const (
// UART pins
// PA2 and PA3 are connected to the ST-Link Virtual Com Port (VCP).
UART_TX_PIN = PA2
UART_RX_PIN = PA3
UART1_TX_PIN = UART_TX_PIN
UART1_RX_PIN = UART_RX_PIN

// USART1 on Arduino D8 (PA9 = TX) / D2 (PA10 = RX).
// Use for external UART communication (e.g. with another board).
UART2_TX_PIN = PA9
UART2_RX_PIN = PA10

// I2C pins
// PB8 / Arduino D15 is SCL, PB9 / Arduino D14 is SDA.
I2C0_SCL_PIN = PB8
I2C0_SDA_PIN = PB9

// SPI pins
SPI1_SCK_PIN = PA5
SPI1_SDI_PIN = PA6
SPI1_SDO_PIN = PA7
SPI0_SCK_PIN = SPI1_SCK_PIN
SPI0_SDI_PIN = SPI1_SDI_PIN
SPI0_SDO_PIN = SPI1_SDO_PIN
)

var (
// USART2 is the hardware serial port connected to the onboard ST-LINK
// debugger, exposed as a virtual COM port over USB.
UART1 = &_UART1
_UART1 = UART{
Buffer: NewRingBuffer(),
Bus: stm32.USART2,
TxAltFuncSelector: AF7_USART1_2_3,
RxAltFuncSelector: AF7_USART1_2_3,
}
DefaultUART = UART1

// USART1 on PA9 (TX=D8) / PA10 (RX=D2). Use for external communication.
UART2 = &_UART2
_UART2 = UART{
Buffer: NewRingBuffer(),
Bus: stm32.USART1,
TxAltFuncSelector: AF7_USART1_2_3,
RxAltFuncSelector: AF7_USART1_2_3,
}

// I2C1 is documented; I2C0 is an alias.
I2C1 = &I2C{
Bus: stm32.I2C1,
AltFuncSelector: AF4_I2C1_2_3,
}
I2C0 = I2C1

// SPI1 is documented; SPI0 is an alias.
SPI1 = &SPI{
Bus: stm32.SPI1,
AltFuncSelector: AF5_SPI1_SPI2,
}
SPI0 = SPI1
)

func init() {
UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt)
UART2.Interrupt = interrupt.New(stm32.IRQ_USART1, _UART2.handleInterrupt)
}
9 changes: 6 additions & 3 deletions src/machine/machine_stm32_adc_f4.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ func InitADC() {
func (a ADC) Configure(ADCConfig) {
a.Pin.ConfigureAltFunc(PinConfig{Mode: PinInputAnalog}, 0)

// set sample time
// set sample time (84 ADC cycles). Each SMPx field is 3 bits wide; the
// encoding for 84 cycles is 4. Named Cycles84 constants are not present
// in every F4 SVD, so use the literal values.
const cycles84 = 4
ch := a.getChannel()
if ch > 9 {
stm32.ADC1.SMPR1.SetBits(stm32.ADC_SMPR1_SMP11_Cycles84 << (ch - 10) * stm32.ADC_SMPR1_SMP11_Pos)
stm32.ADC1.SMPR1.SetBits(cycles84 << ((ch - 10) * 3))
} else {
stm32.ADC1.SMPR2.SetBits(stm32.ADC_SMPR2_SMP1_Cycles84 << (ch * stm32.ADC_SMPR2_SMP1_Pos))
stm32.ADC1.SMPR2.SetBits(cycles84 << (ch * 3))
}

return
Expand Down
4 changes: 3 additions & 1 deletion src/machine/machine_stm32_otgfs_usb.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//go:build stm32f4 || stm32f7
// NUCLEO-F401RE has no USB OTG connector. This chip-wide exclude
// also blocks later F401 boards that have USB (for example Blackpill F401CC).
//go:build (stm32f4 && !stm32f401) || stm32f7

package machine

Expand Down
2 changes: 1 addition & 1 deletion src/machine/machine_stm32_rng.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build stm32 && !(stm32f103 || stm32l0x1 || stm32g0 || stm32u0)
//go:build stm32 && !(stm32f103 || stm32l0x1 || stm32g0 || stm32u0 || stm32f401)

package machine

Expand Down
Loading
Loading