style(swan_r5): pre-commit whitespace style changes
This commit is contained in:
parent
8a3fb7bd13
commit
295cc18190
@ -33,7 +33,7 @@
|
|||||||
void initialize_discharge_pin(void) {
|
void initialize_discharge_pin(void) {
|
||||||
/* Initialize the 3V3 discharge to be OFF and the output power to be ON */
|
/* Initialize the 3V3 discharge to be OFF and the output power to be ON */
|
||||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
|
||||||
@ -48,7 +48,7 @@ void initialize_discharge_pin(void) {
|
|||||||
|
|
||||||
void board_init(void) {
|
void board_init(void) {
|
||||||
// enable the debugger while sleeping. Todo move somewhere more central (kind of generally useful in a debug build)
|
// enable the debugger while sleeping. Todo move somewhere more central (kind of generally useful in a debug build)
|
||||||
SET_BIT (DBGMCU-> CR, DBGMCU_CR_DBG_SLEEP);
|
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
|
||||||
|
|
||||||
// Set tick interrupt priority, default HAL value is intentionally invalid
|
// Set tick interrupt priority, default HAL value is intentionally invalid
|
||||||
// Without this, USB does not function.
|
// Without this, USB does not function.
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#define STM32L4R5XX
|
#define STM32L4R5XX
|
||||||
#define BOARD_SWAN_R5
|
#define BOARD_SWAN_R5
|
||||||
|
|
||||||
|
|
||||||
// The flash size is defined in the STM32L4xx HAL (but not for the F4)
|
// The flash size is defined in the STM32L4xx HAL (but not for the F4)
|
||||||
|
@ -39,7 +39,7 @@ CIRCUITPY_NEOPIXEL_WRITE = 0
|
|||||||
CIRCUITPY_PULSEIO = 1
|
CIRCUITPY_PULSEIO = 1
|
||||||
CIRCUITPY_PWMIO = 1
|
CIRCUITPY_PWMIO = 1
|
||||||
CIRCUITPY_AUDIOPWMIO = 1
|
CIRCUITPY_AUDIOPWMIO = 1
|
||||||
CIRCUITPY_CANIO = 0
|
CIRCUITPY_CANIO = 0
|
||||||
CIRCUITPY_AUDIOBUSIO = 0
|
CIRCUITPY_AUDIOBUSIO = 0
|
||||||
CIRCUITPY_I2CPERIPHERAL = 0
|
CIRCUITPY_I2CPERIPHERAL = 0
|
||||||
# Requires SPI, PulseIO (stub ok):
|
# Requires SPI, PulseIO (stub ok):
|
||||||
@ -71,4 +71,3 @@ CIRCUITPY_BLEIO = 0
|
|||||||
CIRCUITPY_BUSDEVICE = 0
|
CIRCUITPY_BUSDEVICE = 0
|
||||||
CIRCUITPY_KEYPAD = 1
|
CIRCUITPY_KEYPAD = 1
|
||||||
CIRCUITPY_RGBMATRIX = 0
|
CIRCUITPY_RGBMATRIX = 0
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ def test_dac_analog(p_in, p_out):
|
|||||||
pin_in.deinit()
|
pin_in.deinit()
|
||||||
pin_out.deinit()
|
pin_out.deinit()
|
||||||
|
|
||||||
|
|
||||||
def test_dac_digital(p_in, p_out):
|
def test_dac_digital(p_in, p_out):
|
||||||
print(f"Running dac digital test with pin {p_in} as input and {p_out} as output")
|
print(f"Running dac digital test with pin {p_in} as input and {p_out} as output")
|
||||||
pin_in = digitalio.DigitalInOut(p_in)
|
pin_in = digitalio.DigitalInOut(p_in)
|
||||||
@ -27,6 +28,7 @@ def test_dac_digital(p_in, p_out):
|
|||||||
pin_in.deinit()
|
pin_in.deinit()
|
||||||
pin_out.deinit()
|
pin_out.deinit()
|
||||||
|
|
||||||
|
|
||||||
def test_dual(pair1, pair2):
|
def test_dual(pair1, pair2):
|
||||||
# verifies that the DACs can be set independently
|
# verifies that the DACs can be set independently
|
||||||
print(f"Running pair test\n")
|
print(f"Running pair test\n")
|
||||||
@ -36,7 +38,7 @@ def test_dual(pair1, pair2):
|
|||||||
pin2_out = analogio.AnalogOut(pair2[1])
|
pin2_out = analogio.AnalogOut(pair2[1])
|
||||||
|
|
||||||
for v in range(0, 65536, 4096):
|
for v in range(0, 65536, 4096):
|
||||||
v2 = 65535-v
|
v2 = 65535 - v
|
||||||
pin1_out.value = v
|
pin1_out.value = v
|
||||||
pin2_out.value = v2
|
pin2_out.value = v2
|
||||||
print(f"Pair1: Value {v} read as {pin1_in.value}")
|
print(f"Pair1: Value {v} read as {pin1_in.value}")
|
||||||
@ -47,6 +49,7 @@ def test_dual(pair1, pair2):
|
|||||||
pin2_in.deinit()
|
pin2_in.deinit()
|
||||||
pin2_out.deinit()
|
pin2_out.deinit()
|
||||||
|
|
||||||
|
|
||||||
def test_analog_hilo(p_in, p_out):
|
def test_analog_hilo(p_in, p_out):
|
||||||
print(f"Running analog hilo test with pin {p_in} as input and {p_out} as output")
|
print(f"Running analog hilo test with pin {p_in} as input and {p_out} as output")
|
||||||
pin_in = analogio.AnalogIn(p_in)
|
pin_in = analogio.AnalogIn(p_in)
|
||||||
@ -60,12 +63,14 @@ def test_analog_hilo(p_in, p_out):
|
|||||||
pin_in.deinit()
|
pin_in.deinit()
|
||||||
pin_out.deinit()
|
pin_out.deinit()
|
||||||
|
|
||||||
|
|
||||||
def test_pair(pair):
|
def test_pair(pair):
|
||||||
# FIXME: test_analog_hilo works fine alone, but fails when the other dac functions are executed
|
# FIXME: test_analog_hilo works fine alone, but fails when the other dac functions are executed
|
||||||
test_analog_hilo(*pair)
|
test_analog_hilo(*pair)
|
||||||
test_dac_analog(*pair)
|
test_dac_analog(*pair)
|
||||||
test_dac_digital(*pair)
|
test_dac_digital(*pair)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
pair1 = (board.A3, board.DAC1)
|
pair1 = (board.A3, board.DAC1)
|
||||||
pair2 = (board.A2, board.DAC2)
|
pair2 = (board.A2, board.DAC2)
|
||||||
@ -75,7 +80,6 @@ def main():
|
|||||||
test_pair(pair2)
|
test_pair(pair2)
|
||||||
print("running dual DAC tests")
|
print("running dual DAC tests")
|
||||||
test_dual(pair1, pair2)
|
test_dual(pair1, pair2)
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
@ -78,21 +78,23 @@ def _toggle_wait(pin_gpios):
|
|||||||
if time.monotonic() > timestamp + LED_OFF_DELAY_TIME:
|
if time.monotonic() > timestamp + LED_OFF_DELAY_TIME:
|
||||||
led_state = True
|
led_state = True
|
||||||
timestamp = time.monotonic()
|
timestamp = time.monotonic()
|
||||||
|
|
||||||
gpio.value = led_state
|
gpio.value = led_state
|
||||||
if supervisor.runtime.serial_bytes_available:
|
if supervisor.runtime.serial_bytes_available:
|
||||||
answer = input()
|
answer = input()
|
||||||
if bool(answer == "y"):
|
if bool(answer == "y"):
|
||||||
done = True
|
done = True
|
||||||
elif (bool(answer == "n")):
|
elif bool(answer == "n"):
|
||||||
failed += pin
|
failed += pin
|
||||||
done = True
|
done = True
|
||||||
return failed
|
return failed
|
||||||
|
|
||||||
|
|
||||||
def buildPin(pin):
|
def buildPin(pin):
|
||||||
gpio = digitalio.DigitalInOut(pin)
|
gpio = digitalio.DigitalInOut(pin)
|
||||||
return gpio
|
return gpio
|
||||||
|
|
||||||
|
|
||||||
def run_test(pins):
|
def run_test(pins):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -103,7 +105,7 @@ def run_test(pins):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Create a list of analog GPIO pins
|
# Create a list of analog GPIO pins
|
||||||
analog_pins = [p for p in pins if p[0] == "A" and _is_number(p[1])]
|
analog_pins = [p for p in pins if p[0] == "A" and _is_number(p[1])]
|
||||||
|
|
||||||
# Create a list of digital GPIO
|
# Create a list of digital GPIO
|
||||||
digital_pins = [p for p in pins if p[0] == "D" and _is_number(p[1])]
|
digital_pins = [p for p in pins if p[0] == "D" and _is_number(p[1])]
|
||||||
@ -142,4 +144,5 @@ def run_test(pins):
|
|||||||
print("No GPIO pins found")
|
print("No GPIO pins found")
|
||||||
return NA, []
|
return NA, []
|
||||||
|
|
||||||
run_test([p for p in dir(board)])
|
|
||||||
|
run_test([p for p in dir(board)])
|
||||||
|
@ -2,20 +2,21 @@ import board
|
|||||||
import digitalio
|
import digitalio
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
def monitor_button(pin, callback):
|
def monitor_button(pin, callback):
|
||||||
with digitalio.DigitalInOut(pin) as button:
|
with digitalio.DigitalInOut(pin) as button:
|
||||||
newstate = not button.value # state is inverted
|
newstate = not button.value # state is inverted
|
||||||
state = not newstate # ensure change reported to start with
|
state = not newstate # ensure change reported to start with
|
||||||
while callback(newstate, newstate!=state):
|
while callback(newstate, newstate != state):
|
||||||
state = newstate
|
state = newstate
|
||||||
newstate = button.value
|
newstate = button.value
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
|
||||||
def print_changes(state, changed):
|
def print_changes(state, changed):
|
||||||
if changed:
|
if changed:
|
||||||
print(f"button pressed {state}")
|
print(f"button pressed {state}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
monitor_button(board.BUTTON_USR, print_changes)
|
monitor_button(board.BUTTON_USR, print_changes)
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,4 +17,4 @@ for x in i2c.scan():
|
|||||||
print("%d device(s) found on I2C bus" % count)
|
print("%d device(s) found on I2C bus" % count)
|
||||||
|
|
||||||
# Release the I2C bus
|
# Release the I2C bus
|
||||||
i2c.unlock()
|
i2c.unlock()
|
||||||
|
@ -15,4 +15,3 @@ def fade(pin):
|
|||||||
else:
|
else:
|
||||||
led.duty_cycle = 65535 - int((i - 50) * 2 * 65535 / 100) # Down
|
led.duty_cycle = 65535 - int((i - 50) * 2 * 65535 / 100) # Down
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import board
|
import board
|
||||||
import busio
|
import busio
|
||||||
import digitalio
|
import digitalio
|
||||||
@ -14,13 +13,14 @@ SPI_HERZ = 0x500000
|
|||||||
|
|
||||||
spi = busio.SPI(board.SCK, MISO=board.MISO, MOSI=board.MOSI)
|
spi = busio.SPI(board.SCK, MISO=board.MISO, MOSI=board.MOSI)
|
||||||
|
|
||||||
|
|
||||||
def readByte(addr):
|
def readByte(addr):
|
||||||
value = -1
|
value = -1
|
||||||
while not spi.try_lock():
|
while not spi.try_lock():
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
spi.configure(baudrate=500000, phase=0, polarity=0)
|
spi.configure(baudrate=500000, phase=0, polarity=0)
|
||||||
|
|
||||||
cs.value = False
|
cs.value = False
|
||||||
result = bytearray(1)
|
result = bytearray(1)
|
||||||
result[0] = addr | 0x80
|
result[0] = addr | 0x80
|
||||||
@ -32,12 +32,13 @@ def readByte(addr):
|
|||||||
spi.unlock()
|
spi.unlock()
|
||||||
cs.value = True
|
cs.value = True
|
||||||
|
|
||||||
|
|
||||||
def writeByte(addr, value):
|
def writeByte(addr, value):
|
||||||
while not spi.try_lock():
|
while not spi.try_lock():
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
spi.configure(baudrate=500000, phase=0, polarity=0)
|
spi.configure(baudrate=500000, phase=0, polarity=0)
|
||||||
|
|
||||||
cs.value = False
|
cs.value = False
|
||||||
result = bytearray(2)
|
result = bytearray(2)
|
||||||
result[0] = addr & ~0x80
|
result[0] = addr & ~0x80
|
||||||
@ -46,11 +47,12 @@ def writeByte(addr, value):
|
|||||||
finally:
|
finally:
|
||||||
spi.unlock()
|
spi.unlock()
|
||||||
|
|
||||||
|
|
||||||
# put the device in the correct mode to read the ID
|
# put the device in the correct mode to read the ID
|
||||||
reg = readByte(BME680_SPI_REGISTER)
|
reg = readByte(BME680_SPI_REGISTER)
|
||||||
if (reg & 16)!=0:
|
if (reg & 16) != 0:
|
||||||
writeByte(BME680_SPI_REGISTER, reg & ~16)
|
writeByte(BME680_SPI_REGISTER, reg & ~16)
|
||||||
|
|
||||||
id = readByte(BME680_CHIPID_REGISTER)
|
id = readByte(BME680_CHIPID_REGISTER)
|
||||||
|
|
||||||
print(f"id is {id}, expected {BME680_CHIPID}")
|
print(f"id is {id}, expected {BME680_CHIPID}")
|
||||||
|
@ -25,13 +25,13 @@ while True:
|
|||||||
led.value = True
|
led.value = True
|
||||||
|
|
||||||
# convert bytearray to string
|
# convert bytearray to string
|
||||||
data_string = '*'.join([chr(b) for b in data])
|
data_string = "*".join([chr(b) for b in data])
|
||||||
print(data_string, end="")
|
print(data_string, end="")
|
||||||
|
|
||||||
led.value = False
|
led.value = False
|
||||||
|
|
||||||
if usb_cdc.console.in_waiting:
|
if usb_cdc.console.in_waiting:
|
||||||
data = usb_cdc.console.read()
|
data = usb_cdc.console.read()
|
||||||
data_string = '*'.join([chr(b) for b in data])
|
data_string = "*".join([chr(b) for b in data])
|
||||||
print("writing "+data_string)
|
print("writing " + data_string)
|
||||||
uart.write(data)
|
uart.write(data)
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("Random number test")
|
print("Random number test")
|
||||||
r = os.urandom(32)
|
r = os.urandom(32)
|
||||||
print(f"urandom TRNG string is {r}")
|
print(f"urandom TRNG string is {r}")
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#define STM_BKPSRAM_SIZE 0
|
#define STM_BKPSRAM_SIZE 0
|
||||||
#define STM_BKPSRAM_START 0
|
#define STM_BKPSRAM_START 0
|
||||||
#define HAL_PWREx_EnableBkUpReg()
|
#define HAL_PWREx_EnableBkUpReg()
|
||||||
// backup RAM disabled for now. Will have the backup region at the top of SRAM3 which is retained.
|
// backup RAM disabled for now. Will have the backup region at the top of SRAM3 which is retained.
|
||||||
#else
|
#else
|
||||||
#define STM_BKPSRAM_SIZE 0x1000
|
#define STM_BKPSRAM_SIZE 0x1000
|
||||||
#define STM_BKPSRAM_START BKPSRAM_BASE
|
#define STM_BKPSRAM_START BKPSRAM_BASE
|
||||||
|
@ -84,32 +84,52 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t adc_channel(uint32_t channel) {
|
uint32_t adc_channel(uint32_t channel) {
|
||||||
#if CPY_STM32L4
|
#if CPY_STM32L4
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
case 0: return ADC_CHANNEL_0;
|
case 0:
|
||||||
case 1: return ADC_CHANNEL_1;
|
return ADC_CHANNEL_0;
|
||||||
case 2: return ADC_CHANNEL_2;
|
case 1:
|
||||||
case 3: return ADC_CHANNEL_3;
|
return ADC_CHANNEL_1;
|
||||||
case 4: return ADC_CHANNEL_4;
|
case 2:
|
||||||
case 5: return ADC_CHANNEL_5;
|
return ADC_CHANNEL_2;
|
||||||
case 6: return ADC_CHANNEL_6;
|
case 3:
|
||||||
case 7: return ADC_CHANNEL_7;
|
return ADC_CHANNEL_3;
|
||||||
case 8: return ADC_CHANNEL_8;
|
case 4:
|
||||||
case 9: return ADC_CHANNEL_9;
|
return ADC_CHANNEL_4;
|
||||||
case 10: return ADC_CHANNEL_10;
|
case 5:
|
||||||
case 11: return ADC_CHANNEL_11;
|
return ADC_CHANNEL_5;
|
||||||
case 12: return ADC_CHANNEL_12;
|
case 6:
|
||||||
case 13: return ADC_CHANNEL_13;
|
return ADC_CHANNEL_6;
|
||||||
case 14: return ADC_CHANNEL_14;
|
case 7:
|
||||||
case 15: return ADC_CHANNEL_15;
|
return ADC_CHANNEL_7;
|
||||||
case 16: return ADC_CHANNEL_16;
|
case 8:
|
||||||
case 17: return ADC_CHANNEL_17;
|
return ADC_CHANNEL_8;
|
||||||
case 18: return ADC_CHANNEL_18;
|
case 9:
|
||||||
default: return 0;
|
return ADC_CHANNEL_9;
|
||||||
|
case 10:
|
||||||
|
return ADC_CHANNEL_10;
|
||||||
|
case 11:
|
||||||
|
return ADC_CHANNEL_11;
|
||||||
|
case 12:
|
||||||
|
return ADC_CHANNEL_12;
|
||||||
|
case 13:
|
||||||
|
return ADC_CHANNEL_13;
|
||||||
|
case 14:
|
||||||
|
return ADC_CHANNEL_14;
|
||||||
|
case 15:
|
||||||
|
return ADC_CHANNEL_15;
|
||||||
|
case 16:
|
||||||
|
return ADC_CHANNEL_16;
|
||||||
|
case 17:
|
||||||
|
return ADC_CHANNEL_17;
|
||||||
|
case 18:
|
||||||
|
return ADC_CHANNEL_18;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return channel;
|
return channel;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
|
uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
|
||||||
@ -151,31 +171,33 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
|
|||||||
AdcHandle.Init.NbrOfConversion = 1;
|
AdcHandle.Init.NbrOfConversion = 1;
|
||||||
AdcHandle.Init.DMAContinuousRequests = DISABLE;
|
AdcHandle.Init.DMAContinuousRequests = DISABLE;
|
||||||
AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
||||||
#ifdef ADC_OVR_DATA_OVERWRITTEN
|
#ifdef ADC_OVR_DATA_OVERWRITTEN
|
||||||
AdcHandle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; /* DR register is overwritten with the last conversion result in case of overrun */
|
AdcHandle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; /* DR register is overwritten with the last conversion result in case of overrun */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (HAL_ADC_Init(&AdcHandle) != HAL_OK) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (HAL_ADC_Init(&AdcHandle)!=HAL_OK) return 0;
|
|
||||||
|
|
||||||
sConfig.Channel = adc_channel(self->pin->adc_channel); // ADC_CHANNEL_0 <-normal iteration, not mask
|
sConfig.Channel = adc_channel(self->pin->adc_channel); // ADC_CHANNEL_0 <-normal iteration, not mask
|
||||||
sConfig.Rank = 1;
|
sConfig.Rank = 1;
|
||||||
sConfig.SamplingTime = ADC_SAMPLETIME;
|
sConfig.SamplingTime = ADC_SAMPLETIME;
|
||||||
#if CPY_STM32L4
|
|
||||||
sConfig.SingleDiff = ADC_SINGLE_ENDED; /* Single-ended input channel */
|
|
||||||
sConfig.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */
|
|
||||||
if (!IS_ADC_CHANNEL(&AdcHandle, sConfig.Channel)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig)!=HAL_OK) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#if CPY_STM32L4
|
#if CPY_STM32L4
|
||||||
if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED) != HAL_OK) {
|
sConfig.SingleDiff = ADC_SINGLE_ENDED; /* Single-ended input channel */
|
||||||
|
sConfig.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */
|
||||||
|
if (!IS_ADC_CHANNEL(&AdcHandle, sConfig.Channel)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (HAL_ADC_Start(&AdcHandle)!=HAL_OK) {
|
if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#if CPY_STM32L4
|
||||||
|
if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED) != HAL_OK) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (HAL_ADC_Start(&AdcHandle) != HAL_OK) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
HAL_ADC_PollForConversion(&AdcHandle,1);
|
HAL_ADC_PollForConversion(&AdcHandle,1);
|
||||||
|
@ -76,8 +76,8 @@ ifeq ($(MCU_SERIES),L4)
|
|||||||
CIRCUITPY_RTC ?= 0
|
CIRCUITPY_RTC ?= 0
|
||||||
# todo - this varies between devices in the series
|
# todo - this varies between devices in the series
|
||||||
# This slide deck https://www.st.com/content/ccc/resource/training/technical/product_training/98/89/c8/6c/3e/e9/49/79/STM32L4_Peripheral_USB.pdf/files/STM32L4_Peripheral_USB.pdf/jcr:content/translations/en.STM32L4_Peripheral_USB.pdf
|
# This slide deck https://www.st.com/content/ccc/resource/training/technical/product_training/98/89/c8/6c/3e/e9/49/79/STM32L4_Peripheral_USB.pdf/files/STM32L4_Peripheral_USB.pdf/jcr:content/translations/en.STM32L4_Peripheral_USB.pdf
|
||||||
# cites 16 endpoints, 8 endpoint pairs, while section 3.39 of the L4R5 datasheet states 6 endpoint pairs.
|
# cites 16 endpoints, 8 endpoint pairs, while section 3.39 of the L4R5 datasheet states 6 endpoint pairs.
|
||||||
USB_NUM_ENDPOINT_PAIRS = 6
|
USB_NUM_ENDPOINT_PAIRS = 6
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CIRCUITPY_PARALLELDISPLAY := 0
|
CIRCUITPY_PARALLELDISPLAY := 0
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
// L4 Series
|
// L4 Series
|
||||||
#ifdef STM32L4R5xx
|
#ifdef STM32L4R5xx
|
||||||
#include "stm32l4/stm32l4r5xx/clocks.h"
|
#include "stm32l4/stm32l4r5xx/clocks.h"
|
||||||
#else
|
#else
|
||||||
#error Please add other MCUs here so that they are not silently ignored due to #define typos
|
#error Please add other MCUs here so that they are not silently ignored due to #define typos
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -42,69 +42,69 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Error_Handler(void) {
|
void Error_Handler(void) {
|
||||||
for(;;) {
|
for (;;) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define HAL_CHECK(x) if (x!=HAL_OK) Error_Handler()
|
#define HAL_CHECK(x) if (x != HAL_OK) Error_Handler()
|
||||||
|
|
||||||
void stm32_peripherals_clocks_init(void) {
|
void stm32_peripherals_clocks_init(void) {
|
||||||
|
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
||||||
|
|
||||||
// Configure LSE Drive
|
// Configure LSE Drive
|
||||||
HAL_PWR_EnableBkUpAccess();
|
HAL_PWR_EnableBkUpAccess();
|
||||||
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
|
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
|
||||||
__HAL_RCC_PWR_CLK_ENABLE();
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
|
|
||||||
/** Configure the main internal regulator output voltage
|
/** Configure the main internal regulator output voltage
|
||||||
*/
|
*/
|
||||||
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST) != HAL_OK) {
|
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST) != HAL_OK) {
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Activate PLL with MSI , stabilizied via PLL by LSE */
|
/* Activate PLL with MSI , stabilizied via PLL by LSE */
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_MSI;
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_MSI;
|
||||||
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
|
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
|
||||||
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||||||
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_11;
|
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_11;
|
||||||
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
|
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
|
||||||
RCC_OscInitStruct.PLL.PLLM = 6;
|
RCC_OscInitStruct.PLL.PLLM = 6;
|
||||||
RCC_OscInitStruct.PLL.PLLN = 30;
|
RCC_OscInitStruct.PLL.PLLN = 30;
|
||||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV5;
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV5;
|
||||||
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
|
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
|
||||||
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
|
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
|
||||||
HAL_CHECK(HAL_RCC_OscConfig(&RCC_OscInitStruct));
|
HAL_CHECK(HAL_RCC_OscConfig(&RCC_OscInitStruct));
|
||||||
|
|
||||||
/* Enable MSI Auto-calibration through LSE */
|
/* Enable MSI Auto-calibration through LSE */
|
||||||
HAL_RCCEx_EnableMSIPLLMode();
|
HAL_RCCEx_EnableMSIPLLMode();
|
||||||
|
|
||||||
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
|
|
||||||
clocks dividers */
|
|
||||||
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
|
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
||||||
// Avoid overshoot and start with HCLK 60 MHz
|
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
||||||
HAL_CHECK(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3));
|
|
||||||
|
|
||||||
/* AHB prescaler divider at 1 as second step */
|
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK;
|
clocks dividers */
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
|
||||||
HAL_CHECK(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5));
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
|
// Avoid overshoot and start with HCLK 60 MHz
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||||
|
HAL_CHECK(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3));
|
||||||
|
|
||||||
/* Select MSI output as USB clock source */
|
/* AHB prescaler divider at 1 as second step */
|
||||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB | RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_ADC;
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK;
|
||||||
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_MSI;
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
|
HAL_CHECK(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5));
|
||||||
PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
|
|
||||||
HAL_CHECK(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct));
|
/* Select MSI output as USB clock source */
|
||||||
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB | RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_ADC;
|
||||||
|
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_MSI;
|
||||||
|
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
|
||||||
|
PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
|
||||||
|
HAL_CHECK(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,8 @@ void stm32_peripherals_gpio_init(void) {
|
|||||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||||
|
|
||||||
// These ports are not used on the Swan R5 but may need to be enabeld on other boards
|
// These ports are not used on the Swan R5 but may need to be enabeld on other boards
|
||||||
//__HAL_RCC_GPIOH_CLK_ENABLE();
|
// __HAL_RCC_GPIOH_CLK_ENABLE();
|
||||||
//__HAL_RCC_GPIOI_CLK_ENABLE();
|
// __HAL_RCC_GPIOI_CLK_ENABLE();
|
||||||
|
|
||||||
// Never reset pins
|
// Never reset pins
|
||||||
never_reset_pin_number(2,14); // PC14 OSC32_IN
|
never_reset_pin_number(2,14); // PC14 OSC32_IN
|
||||||
|
@ -167,7 +167,7 @@ const mcu_periph_obj_t mcu_uart_rx_list[UART_RX_ARRAY_LEN] = {
|
|||||||
|
|
||||||
// Timers
|
// Timers
|
||||||
// TIM6 and TIM7 are basic timers that are only used by DAC, and don't have pins
|
// TIM6 and TIM7 are basic timers that are only used by DAC, and don't have pins
|
||||||
TIM_TypeDef *mcu_tim_banks[TIM_BANK_ARRAY_LEN] = {TIM1, TIM2, TIM3, TIM4, TIM5, NULL, NULL, TIM8, /*TIM9*/NULL, NULL, NULL, NULL, NULL, NULL, TIM15, TIM16, TIM17};
|
TIM_TypeDef *mcu_tim_banks[TIM_BANK_ARRAY_LEN] = {TIM1, TIM2, TIM3, TIM4, TIM5, NULL, NULL, TIM8, /*TIM9*/ NULL, NULL, NULL, NULL, NULL, NULL, TIM15, TIM16, TIM17};
|
||||||
|
|
||||||
const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN] = {
|
const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN] = {
|
||||||
TIM(2, 1, 1, &pin_PA00),
|
TIM(2, 1, 1, &pin_PA00),
|
||||||
@ -184,7 +184,7 @@ const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN] = {
|
|||||||
TIM(3, 2, 1, &pin_PA06),
|
TIM(3, 2, 1, &pin_PA06),
|
||||||
TIM(16, 15, 1, &pin_PA06),
|
TIM(16, 15, 1, &pin_PA06),
|
||||||
TIM(3, 2, 2, &pin_PA07),
|
TIM(3, 2, 2, &pin_PA07),
|
||||||
//TIM(17, 15, 1, &pin_PA07), // peripheral indices are 1 based, stored 0-based with 4 bits available.
|
// TIM(17, 15, 1, &pin_PA07), // peripheral indices are 1 based, stored 0-based with 4 bits available.
|
||||||
TIM(1, 1, 1, &pin_PA08),
|
TIM(1, 1, 1, &pin_PA08),
|
||||||
TIM(1, 1, 2, &pin_PA09),
|
TIM(1, 1, 2, &pin_PA09),
|
||||||
TIM(1, 1, 3, &pin_PA10),
|
TIM(1, 1, 3, &pin_PA10),
|
||||||
@ -200,7 +200,7 @@ const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN] = {
|
|||||||
TIM(4, 2, 3, &pin_PB08),
|
TIM(4, 2, 3, &pin_PB08),
|
||||||
TIM(16, 15, 1, &pin_PB08),
|
TIM(16, 15, 1, &pin_PB08),
|
||||||
TIM(4, 2, 4, &pin_PB09),
|
TIM(4, 2, 4, &pin_PB09),
|
||||||
//TIM(17, 15, 1, &pin_PB09), // peripheral indices are 1 based, stored 0-based with 4 bits available.
|
// TIM(17, 15, 1, &pin_PB09), // peripheral indices are 1 based, stored 0-based with 4 bits available.
|
||||||
TIM(2, 1, 3, &pin_PB10),
|
TIM(2, 1, 3, &pin_PB10),
|
||||||
TIM(2, 1, 4, &pin_PB11),
|
TIM(2, 1, 4, &pin_PB11),
|
||||||
TIM(15, 15, 1, &pin_PB14),
|
TIM(15, 15, 1, &pin_PB14),
|
||||||
@ -218,7 +218,7 @@ const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN] = {
|
|||||||
TIM(4, 2, 3, &pin_PD14),
|
TIM(4, 2, 3, &pin_PD14),
|
||||||
TIM(4, 2, 4, &pin_PD15),
|
TIM(4, 2, 4, &pin_PD15),
|
||||||
TIM(16, 15, 1, &pin_PE00),
|
TIM(16, 15, 1, &pin_PE00),
|
||||||
//TIM(17, 15, 1, &pin_PE01), // peripheral indices are 1 based, stored 0-based with 4 bits available.
|
// TIM(17, 15, 1, &pin_PE01), // peripheral indices are 1 based, stored 0-based with 4 bits available.
|
||||||
TIM(3, 2, 1, &pin_PE03),
|
TIM(3, 2, 1, &pin_PE03),
|
||||||
TIM(3, 2, 2, &pin_PE04),
|
TIM(3, 2, 2, &pin_PE04),
|
||||||
TIM(3, 2, 3, &pin_PE05),
|
TIM(3, 2, 3, &pin_PE05),
|
||||||
@ -280,4 +280,4 @@ const mcu_periph_obj_t mcu_can_rx_list[4] = {
|
|||||||
PERIPH(1, 10, &pin_PB08),
|
PERIPH(1, 10, &pin_PB08),
|
||||||
PERIPH(1, 10, &pin_PD00),
|
PERIPH(1, 10, &pin_PD00),
|
||||||
PERIPH(1, 10, &pin_PI09),
|
PERIPH(1, 10, &pin_PI09),
|
||||||
};
|
};
|
||||||
|
@ -57,7 +57,7 @@ extern const mcu_periph_obj_t mcu_uart_rx_list[UART_RX_ARRAY_LEN];
|
|||||||
|
|
||||||
// Timers
|
// Timers
|
||||||
#define TIM_BANK_ARRAY_LEN 17
|
#define TIM_BANK_ARRAY_LEN 17
|
||||||
#define TIM_PIN_ARRAY_LEN (73-3)
|
#define TIM_PIN_ARRAY_LEN (73 - 3)
|
||||||
extern TIM_TypeDef *mcu_tim_banks[TIM_BANK_ARRAY_LEN];
|
extern TIM_TypeDef *mcu_tim_banks[TIM_BANK_ARRAY_LEN];
|
||||||
extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
|
extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
|
||||||
|
|
||||||
|
@ -138,9 +138,9 @@ STATIC uint32_t get_bank(uint32_t addr) {
|
|||||||
uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) {
|
uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) {
|
||||||
if (addr >= flash_layout[0].base_address) {
|
if (addr >= flash_layout[0].base_address) {
|
||||||
uint32_t sector_index = 0;
|
uint32_t sector_index = 0;
|
||||||
if (MP_ARRAY_SIZE(flash_layout)==1) {
|
if (MP_ARRAY_SIZE(flash_layout) == 1) {
|
||||||
sector_index = (addr-flash_layout[0].base_address)/flash_layout[0].sector_size;
|
sector_index = (addr - flash_layout[0].base_address) / flash_layout[0].sector_size;
|
||||||
if (sector_index>=flash_layout[0].sector_count) {
|
if (sector_index >= flash_layout[0].sector_count) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (start_addr) {
|
if (start_addr) {
|
||||||
@ -193,7 +193,7 @@ void port_internal_flash_flush(void) {
|
|||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS_BANK1 | FLASH_FLAG_ALL_ERRORS_BANK2);
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS_BANK1 | FLASH_FLAG_ALL_ERRORS_BANK2);
|
||||||
#else
|
#else
|
||||||
#ifndef FLASH_FLAG_ALL_ERRORS
|
#ifndef FLASH_FLAG_ALL_ERRORS
|
||||||
#define FLASH_FLAG_ALL_ERRORS FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGPERR |FLASH_FLAG_PGSERR
|
#define FLASH_FLAG_ALL_ERRORS FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR
|
||||||
#endif
|
#endif
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
|
||||||
#endif
|
#endif
|
||||||
@ -256,7 +256,7 @@ void port_internal_flash_flush(void) {
|
|||||||
// program the flash word by word
|
// program the flash word by word
|
||||||
for (uint32_t i = 0; i < sector_size / 8; i++) {
|
for (uint32_t i = 0; i < sector_size / 8; i++) {
|
||||||
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, sector_start_addr,
|
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, sector_start_addr,
|
||||||
*(uint64_t*)cache_addr) != HAL_OK) {
|
*(uint64_t *)cache_addr) != HAL_OK) {
|
||||||
// error occurred during flash write
|
// error occurred during flash write
|
||||||
HAL_FLASH_Lock(); // lock the flash
|
HAL_FLASH_Lock(); // lock the flash
|
||||||
reset_into_safe_mode(FLASH_WRITE_FAIL);
|
reset_into_safe_mode(FLASH_WRITE_FAIL);
|
||||||
|
@ -176,7 +176,7 @@ static volatile uint32_t systick_ms;
|
|||||||
safe_mode_t port_init(void) {
|
safe_mode_t port_init(void) {
|
||||||
HAL_Init(); // Turns on SysTick
|
HAL_Init(); // Turns on SysTick
|
||||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||||
|
|
||||||
#if CPY_STM32F4 || CPY_STM32L4
|
#if CPY_STM32F4 || CPY_STM32L4
|
||||||
__HAL_RCC_PWR_CLK_ENABLE();
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
HAL_PWR_EnableBkUpAccess();
|
HAL_PWR_EnableBkUpAccess();
|
||||||
|
@ -125,7 +125,7 @@ void init_usb_hardware(void) {
|
|||||||
never_reset_pin_number(0, 10);
|
never_reset_pin_number(0, 10);
|
||||||
claim_pin(0, 10);
|
claim_pin(0, 10);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef STM32F412Zx
|
#ifdef STM32F412Zx
|
||||||
/* Configure POWER_SWITCH IO pin (F412 ONLY)*/
|
/* Configure POWER_SWITCH IO pin (F412 ONLY)*/
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_8;
|
GPIO_InitStruct.Pin = GPIO_PIN_8;
|
||||||
|
@ -138,4 +138,4 @@ PI7,-,-,-,TIM8_CH3,-,-,-,-,,-,-,DCMI_D7,-,-,-,-,EVENTOUT
|
|||||||
PI8,-,-,-,-,-,OCTOSPIM_P2_NCS,-,-,,-,-,DCMI_D12,-,-,-,-,EVENTOUT
|
PI8,-,-,-,-,-,OCTOSPIM_P2_NCS,-,-,,-,-,DCMI_D12,-,-,-,-,EVENTOUT
|
||||||
PI9,-,-,-,-,-,OCTOSPIM_P2_IO2,-,-,,-,CAN1_RX,-,-,-,-,-,EVENTOUT
|
PI9,-,-,-,-,-,OCTOSPIM_P2_IO2,-,-,,-,CAN1_RX,-,-,-,-,-,EVENTOUT
|
||||||
PI10,-,-,-,-,-,OCTOSPIM_P2_IO1,-,-,,-,-,-,-,-,-,-,EVENTOUT
|
PI10,-,-,-,-,-,OCTOSPIM_P2_IO1,-,-,,-,-,-,-,-,-,-,EVENTOUT
|
||||||
PI11,-,-,-,-,-,OCTOSPIM_P2_IO0,-,-,,-,-,-,-,-,-,-,EVENTOUT
|
PI11,-,-,-,-,-,OCTOSPIM_P2_IO0,-,-,,-,-,-,-,-,-,-,EVENTOUT
|
||||||
|
|
@ -88,7 +88,7 @@ with open(sys.argv[1]) as csv_file:
|
|||||||
for row in csv_reader:
|
for row in csv_reader:
|
||||||
altfn = 0
|
altfn = 0
|
||||||
pin = row[0]
|
pin = row[0]
|
||||||
if len(pin) < 4: # add additional leading 0 to pin number after port
|
if len(pin) < 4: # add additional leading 0 to pin number after port
|
||||||
pin = pin[:2] + "0" + pin[2:]
|
pin = pin[:2] + "0" + pin[2:]
|
||||||
for col in row:
|
for col in row:
|
||||||
array_index = 0
|
array_index = 0
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#include "tusb.h"
|
#include "tusb.h"
|
||||||
|
|
||||||
#if CIRCUITPY_USB_VENDOR
|
#if CIRCUITPY_USB_VENDOR
|
||||||
// todo - this doesn't feel like it should be here.
|
// todo - this doesn't feel like it should be here.
|
||||||
#include "supervisor/memory.h"
|
#include "supervisor/memory.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -275,19 +275,18 @@ bool common_hal_usb_cdc_enable(bool console, bool data) {
|
|||||||
// BOS Descriptor is required for webUSB
|
// BOS Descriptor is required for webUSB
|
||||||
uint8_t const desc_bos[] =
|
uint8_t const desc_bos[] =
|
||||||
{
|
{
|
||||||
// total length, number of device caps
|
// total length, number of device caps
|
||||||
TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 2),
|
TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 2),
|
||||||
|
|
||||||
// Vendor Code, iLandingPage
|
// Vendor Code, iLandingPage
|
||||||
TUD_BOS_WEBUSB_DESCRIPTOR(VENDOR_REQUEST_WEBUSB, 1),
|
TUD_BOS_WEBUSB_DESCRIPTOR(VENDOR_REQUEST_WEBUSB, 1),
|
||||||
|
|
||||||
// Microsoft OS 2.0 descriptor
|
// Microsoft OS 2.0 descriptor
|
||||||
TUD_BOS_MS_OS_20_DESCRIPTOR(MS_OS_20_DESC_LEN, VENDOR_REQUEST_MICROSOFT)
|
TUD_BOS_MS_OS_20_DESCRIPTOR(MS_OS_20_DESC_LEN, VENDOR_REQUEST_MICROSOFT)
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t const * tud_descriptor_bos_cb(void)
|
uint8_t const *tud_descriptor_bos_cb(void) {
|
||||||
{
|
return desc_bos;
|
||||||
return desc_bos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MS_OS_20_ITF_NUM_MAGIC 0x5b
|
#define MS_OS_20_ITF_NUM_MAGIC 0x5b
|
||||||
@ -295,30 +294,30 @@ uint8_t const * tud_descriptor_bos_cb(void)
|
|||||||
|
|
||||||
const uint8_t ms_os_20_descriptor_template[] =
|
const uint8_t ms_os_20_descriptor_template[] =
|
||||||
{
|
{
|
||||||
// 10 Set header: length, type, windows version, total length
|
// 10 Set header: length, type, windows version, total length
|
||||||
U16_TO_U8S_LE(0x000A), U16_TO_U8S_LE(MS_OS_20_SET_HEADER_DESCRIPTOR), U32_TO_U8S_LE(0x06030000), U16_TO_U8S_LE(MS_OS_20_DESC_LEN),
|
U16_TO_U8S_LE(0x000A), U16_TO_U8S_LE(MS_OS_20_SET_HEADER_DESCRIPTOR), U32_TO_U8S_LE(0x06030000), U16_TO_U8S_LE(MS_OS_20_DESC_LEN),
|
||||||
|
|
||||||
// 8 Configuration subset header: length, type, configuration index, reserved, configuration total length
|
// 8 Configuration subset header: length, type, configuration index, reserved, configuration total length
|
||||||
U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_CONFIGURATION), 0, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A),
|
U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_CONFIGURATION), 0, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A),
|
||||||
|
|
||||||
// 8 Function Subset header: length, type, first interface, reserved, subset length
|
// 8 Function Subset header: length, type, first interface, reserved, subset length
|
||||||
U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), /* 22 */MS_OS_20_ITF_NUM_MAGIC, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08),
|
U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), /* 22 */ MS_OS_20_ITF_NUM_MAGIC, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A - 0x08),
|
||||||
|
|
||||||
// 20 MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID
|
// 20 MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID
|
||||||
U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00,
|
U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible
|
||||||
|
|
||||||
// MS OS 2.0 Registry property descriptor: length, type
|
// MS OS 2.0 Registry property descriptor: length, type
|
||||||
U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08-0x08-0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY),
|
U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A - 0x08 - 0x08 - 0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY),
|
||||||
U16_TO_U8S_LE(0x0007), U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16
|
U16_TO_U8S_LE(0x0007), U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16
|
||||||
'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00,
|
'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00,
|
||||||
'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00,
|
'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00,
|
||||||
U16_TO_U8S_LE(0x0050), // wPropertyDataLength
|
U16_TO_U8S_LE(0x0050), // wPropertyDataLength
|
||||||
//bPropertyData: “{975F44D9-0D08-43FD-8B3E-127CA8AFFF9D}”.
|
// bPropertyData: “{975F44D9-0D08-43FD-8B3E-127CA8AFFF9D}”.
|
||||||
'{', 0x00, '9', 0x00, '7', 0x00, '5', 0x00, 'F', 0x00, '4', 0x00, '4', 0x00, 'D', 0x00, '9', 0x00, '-', 0x00,
|
'{', 0x00, '9', 0x00, '7', 0x00, '5', 0x00, 'F', 0x00, '4', 0x00, '4', 0x00, 'D', 0x00, '9', 0x00, '-', 0x00,
|
||||||
'0', 0x00, 'D', 0x00, '0', 0x00, '8', 0x00, '-', 0x00, '4', 0x00, '3', 0x00, 'F', 0x00, 'D', 0x00, '-', 0x00,
|
'0', 0x00, 'D', 0x00, '0', 0x00, '8', 0x00, '-', 0x00, '4', 0x00, '3', 0x00, 'F', 0x00, 'D', 0x00, '-', 0x00,
|
||||||
'8', 0x00, 'B', 0x00, '3', 0x00, 'E', 0x00, '-', 0x00, '1', 0x00, '2', 0x00, '7', 0x00, 'C', 0x00, 'A', 0x00,
|
'8', 0x00, 'B', 0x00, '3', 0x00, 'E', 0x00, '-', 0x00, '1', 0x00, '2', 0x00, '7', 0x00, 'C', 0x00, 'A', 0x00,
|
||||||
'8', 0x00, 'A', 0x00, 'F', 0x00, 'F', 0x00, 'F', 0x00, '9', 0x00, 'D', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00
|
'8', 0x00, 'A', 0x00, 'F', 0x00, 'F', 0x00, 'F', 0x00, '9', 0x00, 'D', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
TU_VERIFY_STATIC(sizeof(ms_os_20_descriptor_template) == MS_OS_20_DESC_LEN, "Incorrect size");
|
TU_VERIFY_STATIC(sizeof(ms_os_20_descriptor_template) == MS_OS_20_DESC_LEN, "Incorrect size");
|
||||||
@ -343,11 +342,11 @@ static const uint8_t usb_vendor_descriptor_template[] = {
|
|||||||
0xFF, // 11 bEndpointAddress (IN/D2H) [SET AT RUNTIME: number]
|
0xFF, // 11 bEndpointAddress (IN/D2H) [SET AT RUNTIME: number]
|
||||||
#define VENDOR_OUT_ENDPOINT_INDEX 11
|
#define VENDOR_OUT_ENDPOINT_INDEX 11
|
||||||
0x02, // 12 bmAttributes (Bulk)
|
0x02, // 12 bmAttributes (Bulk)
|
||||||
#if USB_HIGHSPEED
|
#if USB_HIGHSPEED
|
||||||
0x00, 0x02, // 13,14 wMaxPacketSize 512
|
0x00, 0x02, // 13,14 wMaxPacketSize 512
|
||||||
#else
|
#else
|
||||||
0x40, 0x00, // 13,14 wMaxPacketSize 64
|
0x40, 0x00, // 13,14 wMaxPacketSize 64
|
||||||
#endif
|
#endif
|
||||||
0x0, // 15 bInterval 0
|
0x0, // 15 bInterval 0
|
||||||
|
|
||||||
// Vendor IN Endpoint Descriptor
|
// Vendor IN Endpoint Descriptor
|
||||||
@ -376,15 +375,15 @@ static supervisor_allocation *ms_os_20_descriptor_allocation;
|
|||||||
size_t vendor_ms_os_20_descriptor_length() {
|
size_t vendor_ms_os_20_descriptor_length() {
|
||||||
return sizeof(ms_os_20_descriptor_template);
|
return sizeof(ms_os_20_descriptor_template);
|
||||||
}
|
}
|
||||||
uint8_t const* vendor_ms_os_20_descriptor() {
|
uint8_t const *vendor_ms_os_20_descriptor() {
|
||||||
return (uint8_t *)ms_os_20_descriptor_allocation->ptr;
|
return (uint8_t *)ms_os_20_descriptor_allocation->ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t usb_vendor_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *descriptor_counts, uint8_t *current_interface_string) {
|
size_t usb_vendor_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *descriptor_counts, uint8_t *current_interface_string) {
|
||||||
|
|
||||||
if (ms_os_20_descriptor_template[MS_OS_20_ITF_NUM_OFFSET]==MS_OS_20_ITF_NUM_MAGIC) {
|
if (ms_os_20_descriptor_template[MS_OS_20_ITF_NUM_OFFSET] == MS_OS_20_ITF_NUM_MAGIC) {
|
||||||
ms_os_20_descriptor_allocation =
|
ms_os_20_descriptor_allocation =
|
||||||
allocate_memory(align32_size(sizeof(ms_os_20_descriptor_template)),
|
allocate_memory(align32_size(sizeof(ms_os_20_descriptor_template)),
|
||||||
/*high_address*/ false, /*movable*/ false);
|
/*high_address*/ false, /*movable*/ false);
|
||||||
uint8_t *ms_os_20_descriptor_buf = (uint8_t *)ms_os_20_descriptor_allocation->ptr;
|
uint8_t *ms_os_20_descriptor_buf = (uint8_t *)ms_os_20_descriptor_allocation->ptr;
|
||||||
|
@ -45,7 +45,7 @@ size_t usb_vendor_descriptor_length(void);
|
|||||||
size_t usb_vendor_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *descriptor_counts, uint8_t *current_interface_string);
|
size_t usb_vendor_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *descriptor_counts, uint8_t *current_interface_string);
|
||||||
|
|
||||||
size_t vendor_ms_os_20_descriptor_length(void);
|
size_t vendor_ms_os_20_descriptor_length(void);
|
||||||
uint8_t const* vendor_ms_os_20_descriptor(void);
|
uint8_t const *vendor_ms_os_20_descriptor(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* SHARED_MODULE_USB_CDC___INIT___H */
|
#endif /* SHARED_MODULE_USB_CDC___INIT___H */
|
||||||
|
@ -65,10 +65,10 @@ static bool web_serial_connected = false;
|
|||||||
|
|
||||||
const tusb_desc_webusb_url_t desc_webusb_url =
|
const tusb_desc_webusb_url_t desc_webusb_url =
|
||||||
{
|
{
|
||||||
.bLength = 3 + sizeof(URL) - 1,
|
.bLength = 3 + sizeof(URL) - 1,
|
||||||
.bDescriptorType = 3, // WEBUSB URL type
|
.bDescriptorType = 3, // WEBUSB URL type
|
||||||
.bScheme = 1, // 0: http, 1: https
|
.bScheme = 1, // 0: http, 1: https
|
||||||
.url = URL
|
.url = URL
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -140,7 +140,7 @@ static void usb_build_device_descriptor(uint16_t vid, uint16_t pid) {
|
|||||||
|
|
||||||
static void usb_build_configuration_descriptor(void) {
|
static void usb_build_configuration_descriptor(void) {
|
||||||
size_t total_descriptor_length = sizeof(configuration_descriptor_template);
|
size_t total_descriptor_length = sizeof(configuration_descriptor_template);
|
||||||
|
|
||||||
// CDC should be first, for compatibility with Adafruit Windows 7 drivers.
|
// CDC should be first, for compatibility with Adafruit Windows 7 drivers.
|
||||||
// In the past, the order has been CDC, MSC, MIDI, HID, so preserve that order.
|
// In the past, the order has been CDC, MSC, MIDI, HID, so preserve that order.
|
||||||
#if CIRCUITPY_USB_CDC
|
#if CIRCUITPY_USB_CDC
|
||||||
@ -172,7 +172,7 @@ static void usb_build_configuration_descriptor(void) {
|
|||||||
|
|
||||||
#if CIRCUITPY_USB_VENDOR
|
#if CIRCUITPY_USB_VENDOR
|
||||||
if (usb_vendor_enabled()) {
|
if (usb_vendor_enabled()) {
|
||||||
total_descriptor_length += usb_vendor_descriptor_length();
|
total_descriptor_length += usb_vendor_descriptor_length();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||||
@ -29,11 +29,11 @@
|
|||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
VENDOR_REQUEST_WEBUSB = 1,
|
VENDOR_REQUEST_WEBUSB = 1,
|
||||||
VENDOR_REQUEST_MICROSOFT = 2
|
VENDOR_REQUEST_MICROSOFT = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t vendor_ms_os_20_descriptor_length(void);
|
size_t vendor_ms_os_20_descriptor_length(void);
|
||||||
uint8_t const* vendor_ms_os_20_descriptor(void);
|
uint8_t const *vendor_ms_os_20_descriptor(void);
|
||||||
|
|
||||||
#endif /* USB_DESCRIPTORS_H_ */
|
#endif /* USB_DESCRIPTORS_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user