From 295cc18190c677855782cd0ebe37db46790b9fd8 Mon Sep 17 00:00:00 2001 From: Matthew McGowan Date: Tue, 28 Sep 2021 14:13:04 -0700 Subject: [PATCH] style(swan_r5): pre-commit whitespace style changes --- ports/stm/boards/swan_r5/board.c | 4 +- ports/stm/boards/swan_r5/mpconfigboard.h | 2 +- ports/stm/boards/swan_r5/mpconfigboard.mk | 3 +- .../stm/boards/swan_r5/tests/analog_output.py | 12 ++- .../stm/boards/swan_r5/tests/board_voltage.py | 11 +- ports/stm/boards/swan_r5/tests/button.py | 11 +- ports/stm/boards/swan_r5/tests/i2c_scan.py | 2 +- ports/stm/boards/swan_r5/tests/pwnio.py | 1 - .../swan_r5/tests/spi_bme680_smoke_test.py | 12 ++- ports/stm/boards/swan_r5/tests/uart.py | 6 +- ports/stm/boards/swan_r5/tests/urandom.py | 5 +- ports/stm/common-hal/alarm/SleepMemory.c | 2 +- ports/stm/common-hal/analogio/AnalogIn.c | 102 +++++++++++------- ports/stm/mpconfigport.mk | 4 +- ports/stm/peripherals/stm32l4/clocks.c | 100 ++++++++--------- .../peripherals/stm32l4/stm32l4r5xx/gpio.c | 4 +- .../peripherals/stm32l4/stm32l4r5xx/periph.c | 10 +- .../peripherals/stm32l4/stm32l4r5xx/periph.h | 2 +- ports/stm/supervisor/internal_flash.c | 10 +- ports/stm/supervisor/port.c | 2 +- ports/stm/supervisor/usb.c | 2 +- ports/stm/tools/examples/stm32l4r5zi.csv | 2 +- ports/stm/tools/parse_af_csv.py | 2 +- shared-module/usb_cdc/__init__.c | 71 ++++++------ shared-module/usb_cdc/__init__.h | 2 +- supervisor/shared/usb/usb.c | 8 +- supervisor/shared/usb/usb_desc.c | 4 +- .../shared/usb/usb_vendor_descriptors.h | 8 +- 28 files changed, 217 insertions(+), 187 deletions(-) diff --git a/ports/stm/boards/swan_r5/board.c b/ports/stm/boards/swan_r5/board.c index a1219fe94c..7c0e3c44cd 100644 --- a/ports/stm/boards/swan_r5/board.c +++ b/ports/stm/boards/swan_r5/board.c @@ -33,7 +33,7 @@ void initialize_discharge_pin(void) { /* Initialize the 3V3 discharge to be OFF and the output power to be ON */ __HAL_RCC_GPIOE_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; + GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; @@ -48,7 +48,7 @@ void initialize_discharge_pin(void) { void board_init(void) { // 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 // Without this, USB does not function. diff --git a/ports/stm/boards/swan_r5/mpconfigboard.h b/ports/stm/boards/swan_r5/mpconfigboard.h index bc02cc5c4f..da07d6530b 100644 --- a/ports/stm/boards/swan_r5/mpconfigboard.h +++ b/ports/stm/boards/swan_r5/mpconfigboard.h @@ -34,7 +34,7 @@ #define STM32L4R5XX -#define BOARD_SWAN_R5 +#define BOARD_SWAN_R5 // The flash size is defined in the STM32L4xx HAL (but not for the F4) diff --git a/ports/stm/boards/swan_r5/mpconfigboard.mk b/ports/stm/boards/swan_r5/mpconfigboard.mk index 688e9f34b5..24b73e332d 100644 --- a/ports/stm/boards/swan_r5/mpconfigboard.mk +++ b/ports/stm/boards/swan_r5/mpconfigboard.mk @@ -39,7 +39,7 @@ CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_PULSEIO = 1 CIRCUITPY_PWMIO = 1 CIRCUITPY_AUDIOPWMIO = 1 -CIRCUITPY_CANIO = 0 +CIRCUITPY_CANIO = 0 CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_I2CPERIPHERAL = 0 # Requires SPI, PulseIO (stub ok): @@ -71,4 +71,3 @@ CIRCUITPY_BLEIO = 0 CIRCUITPY_BUSDEVICE = 0 CIRCUITPY_KEYPAD = 1 CIRCUITPY_RGBMATRIX = 0 - diff --git a/ports/stm/boards/swan_r5/tests/analog_output.py b/ports/stm/boards/swan_r5/tests/analog_output.py index 877e5a57c9..6af931e65d 100644 --- a/ports/stm/boards/swan_r5/tests/analog_output.py +++ b/ports/stm/boards/swan_r5/tests/analog_output.py @@ -15,6 +15,7 @@ def test_dac_analog(p_in, p_out): pin_in.deinit() pin_out.deinit() + 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") pin_in = digitalio.DigitalInOut(p_in) @@ -27,6 +28,7 @@ def test_dac_digital(p_in, p_out): pin_in.deinit() pin_out.deinit() + def test_dual(pair1, pair2): # verifies that the DACs can be set independently print(f"Running pair test\n") @@ -36,7 +38,7 @@ def test_dual(pair1, pair2): pin2_out = analogio.AnalogOut(pair2[1]) for v in range(0, 65536, 4096): - v2 = 65535-v + v2 = 65535 - v pin1_out.value = v pin2_out.value = v2 print(f"Pair1: Value {v} read as {pin1_in.value}") @@ -47,6 +49,7 @@ def test_dual(pair1, pair2): pin2_in.deinit() pin2_out.deinit() + 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") pin_in = analogio.AnalogIn(p_in) @@ -60,12 +63,14 @@ def test_analog_hilo(p_in, p_out): pin_in.deinit() pin_out.deinit() + def test_pair(pair): # FIXME: test_analog_hilo works fine alone, but fails when the other dac functions are executed test_analog_hilo(*pair) test_dac_analog(*pair) test_dac_digital(*pair) - + + def main(): pair1 = (board.A3, board.DAC1) pair2 = (board.A2, board.DAC2) @@ -75,7 +80,6 @@ def main(): test_pair(pair2) print("running dual DAC tests") test_dual(pair1, pair2) - + main() - diff --git a/ports/stm/boards/swan_r5/tests/board_voltage.py b/ports/stm/boards/swan_r5/tests/board_voltage.py index e1248e722b..6191067fde 100644 --- a/ports/stm/boards/swan_r5/tests/board_voltage.py +++ b/ports/stm/boards/swan_r5/tests/board_voltage.py @@ -78,21 +78,23 @@ def _toggle_wait(pin_gpios): if time.monotonic() > timestamp + LED_OFF_DELAY_TIME: led_state = True timestamp = time.monotonic() - + gpio.value = led_state if supervisor.runtime.serial_bytes_available: answer = input() if bool(answer == "y"): done = True - elif (bool(answer == "n")): + elif bool(answer == "n"): failed += pin done = True return failed + def buildPin(pin): gpio = digitalio.DigitalInOut(pin) return gpio + def run_test(pins): """ @@ -103,7 +105,7 @@ def run_test(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 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") return NA, [] -run_test([p for p in dir(board)]) \ No newline at end of file + +run_test([p for p in dir(board)]) diff --git a/ports/stm/boards/swan_r5/tests/button.py b/ports/stm/boards/swan_r5/tests/button.py index 58825452da..4f00254ddb 100644 --- a/ports/stm/boards/swan_r5/tests/button.py +++ b/ports/stm/boards/swan_r5/tests/button.py @@ -2,20 +2,21 @@ import board import digitalio import time + def monitor_button(pin, callback): with digitalio.DigitalInOut(pin) as button: - newstate = not button.value # state is inverted - state = not newstate # ensure change reported to start with - while callback(newstate, newstate!=state): + newstate = not button.value # state is inverted + state = not newstate # ensure change reported to start with + while callback(newstate, newstate != state): state = newstate newstate = button.value time.sleep(0.01) + def print_changes(state, changed): if changed: print(f"button pressed {state}") return True + monitor_button(board.BUTTON_USR, print_changes) - - diff --git a/ports/stm/boards/swan_r5/tests/i2c_scan.py b/ports/stm/boards/swan_r5/tests/i2c_scan.py index 100efea8df..8e3ef557d1 100644 --- a/ports/stm/boards/swan_r5/tests/i2c_scan.py +++ b/ports/stm/boards/swan_r5/tests/i2c_scan.py @@ -17,4 +17,4 @@ for x in i2c.scan(): print("%d device(s) found on I2C bus" % count) # Release the I2C bus -i2c.unlock() \ No newline at end of file +i2c.unlock() diff --git a/ports/stm/boards/swan_r5/tests/pwnio.py b/ports/stm/boards/swan_r5/tests/pwnio.py index d1e67e7631..71888d867b 100644 --- a/ports/stm/boards/swan_r5/tests/pwnio.py +++ b/ports/stm/boards/swan_r5/tests/pwnio.py @@ -15,4 +15,3 @@ def fade(pin): else: led.duty_cycle = 65535 - int((i - 50) * 2 * 65535 / 100) # Down time.sleep(0.01) - diff --git a/ports/stm/boards/swan_r5/tests/spi_bme680_smoke_test.py b/ports/stm/boards/swan_r5/tests/spi_bme680_smoke_test.py index 100b48d391..01e98bfd31 100644 --- a/ports/stm/boards/swan_r5/tests/spi_bme680_smoke_test.py +++ b/ports/stm/boards/swan_r5/tests/spi_bme680_smoke_test.py @@ -1,4 +1,3 @@ - import board import busio import digitalio @@ -14,13 +13,14 @@ SPI_HERZ = 0x500000 spi = busio.SPI(board.SCK, MISO=board.MISO, MOSI=board.MOSI) + def readByte(addr): value = -1 while not spi.try_lock(): pass try: spi.configure(baudrate=500000, phase=0, polarity=0) - + cs.value = False result = bytearray(1) result[0] = addr | 0x80 @@ -32,12 +32,13 @@ def readByte(addr): spi.unlock() cs.value = True + def writeByte(addr, value): while not spi.try_lock(): pass try: spi.configure(baudrate=500000, phase=0, polarity=0) - + cs.value = False result = bytearray(2) result[0] = addr & ~0x80 @@ -46,11 +47,12 @@ def writeByte(addr, value): finally: spi.unlock() + # put the device in the correct mode to read the ID reg = readByte(BME680_SPI_REGISTER) -if (reg & 16)!=0: +if (reg & 16) != 0: writeByte(BME680_SPI_REGISTER, reg & ~16) - + id = readByte(BME680_CHIPID_REGISTER) print(f"id is {id}, expected {BME680_CHIPID}") diff --git a/ports/stm/boards/swan_r5/tests/uart.py b/ports/stm/boards/swan_r5/tests/uart.py index eedcb524b9..a8dbc272a8 100644 --- a/ports/stm/boards/swan_r5/tests/uart.py +++ b/ports/stm/boards/swan_r5/tests/uart.py @@ -25,13 +25,13 @@ while True: led.value = True # 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="") led.value = False if usb_cdc.console.in_waiting: data = usb_cdc.console.read() - data_string = '*'.join([chr(b) for b in data]) - print("writing "+data_string) + data_string = "*".join([chr(b) for b in data]) + print("writing " + data_string) uart.write(data) diff --git a/ports/stm/boards/swan_r5/tests/urandom.py b/ports/stm/boards/swan_r5/tests/urandom.py index 847db1899a..25ff655596 100644 --- a/ports/stm/boards/swan_r5/tests/urandom.py +++ b/ports/stm/boards/swan_r5/tests/urandom.py @@ -1,9 +1,10 @@ import os + def main(): print("Random number test") r = os.urandom(32) - print(f"urandom TRNG string is {r}") + print(f"urandom TRNG string is {r}") + main() - diff --git a/ports/stm/common-hal/alarm/SleepMemory.c b/ports/stm/common-hal/alarm/SleepMemory.c index 6280bc1204..d8fa88785e 100644 --- a/ports/stm/common-hal/alarm/SleepMemory.c +++ b/ports/stm/common-hal/alarm/SleepMemory.c @@ -36,7 +36,7 @@ #define STM_BKPSRAM_SIZE 0 #define STM_BKPSRAM_START 0 #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 #define STM_BKPSRAM_SIZE 0x1000 #define STM_BKPSRAM_START BKPSRAM_BASE diff --git a/ports/stm/common-hal/analogio/AnalogIn.c b/ports/stm/common-hal/analogio/AnalogIn.c index 483c9922a1..ed2575493e 100644 --- a/ports/stm/common-hal/analogio/AnalogIn.c +++ b/ports/stm/common-hal/analogio/AnalogIn.c @@ -84,32 +84,52 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) { } uint32_t adc_channel(uint32_t channel) { -#if CPY_STM32L4 + #if CPY_STM32L4 switch (channel) { - case 0: return ADC_CHANNEL_0; - case 1: return ADC_CHANNEL_1; - case 2: return ADC_CHANNEL_2; - case 3: return ADC_CHANNEL_3; - case 4: return ADC_CHANNEL_4; - case 5: return ADC_CHANNEL_5; - case 6: return ADC_CHANNEL_6; - case 7: return ADC_CHANNEL_7; - case 8: return ADC_CHANNEL_8; - case 9: 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; + case 0: + return ADC_CHANNEL_0; + case 1: + return ADC_CHANNEL_1; + case 2: + return ADC_CHANNEL_2; + case 3: + return ADC_CHANNEL_3; + case 4: + return ADC_CHANNEL_4; + case 5: + return ADC_CHANNEL_5; + case 6: + return ADC_CHANNEL_6; + case 7: + return ADC_CHANNEL_7; + case 8: + return ADC_CHANNEL_8; + case 9: + 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; -#endif + #endif } 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.DMAContinuousRequests = DISABLE; AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; -#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 */ -#endif + #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 */ + #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.Rank = 1; 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 (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; } #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; } HAL_ADC_PollForConversion(&AdcHandle,1); diff --git a/ports/stm/mpconfigport.mk b/ports/stm/mpconfigport.mk index 13a1435c0b..6729a747b5 100644 --- a/ports/stm/mpconfigport.mk +++ b/ports/stm/mpconfigport.mk @@ -76,8 +76,8 @@ ifeq ($(MCU_SERIES),L4) CIRCUITPY_RTC ?= 0 # 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 - # 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 endif -CIRCUITPY_PARALLELDISPLAY := 0 \ No newline at end of file +CIRCUITPY_PARALLELDISPLAY := 0 diff --git a/ports/stm/peripherals/stm32l4/clocks.c b/ports/stm/peripherals/stm32l4/clocks.c index b0730d07bc..4419f751d4 100644 --- a/ports/stm/peripherals/stm32l4/clocks.c +++ b/ports/stm/peripherals/stm32l4/clocks.c @@ -31,7 +31,7 @@ // L4 Series #ifdef STM32L4R5xx #include "stm32l4/stm32l4r5xx/clocks.h" -#else +#else #error Please add other MCUs here so that they are not silently ignored due to #define typos #endif @@ -42,69 +42,69 @@ #endif 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) { - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; - - // Configure LSE Drive - HAL_PWR_EnableBkUpAccess(); - __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW); - __HAL_RCC_PWR_CLK_ENABLE(); + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; + + // Configure LSE Drive + HAL_PWR_EnableBkUpAccess(); + __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW); + __HAL_RCC_PWR_CLK_ENABLE(); /** Configure the main internal regulator output voltage */ - if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST) != HAL_OK) { - Error_Handler(); - } + if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST) != HAL_OK) { + Error_Handler(); + } - /* Activate PLL with MSI , stabilizied via PLL by LSE */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_MSI; - RCC_OscInitStruct.MSIState = RCC_MSI_ON; - RCC_OscInitStruct.LSEState = RCC_LSE_ON; - RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_11; - RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI; - RCC_OscInitStruct.PLL.PLLM = 6; - RCC_OscInitStruct.PLL.PLLN = 30; - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV5; - RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; - RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; - HAL_CHECK(HAL_RCC_OscConfig(&RCC_OscInitStruct)); + /* Activate PLL with MSI , stabilizied via PLL by LSE */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_MSI; + RCC_OscInitStruct.MSIState = RCC_MSI_ON; + RCC_OscInitStruct.LSEState = RCC_LSE_ON; + RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_11; + RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI; + RCC_OscInitStruct.PLL.PLLM = 6; + RCC_OscInitStruct.PLL.PLLN = 30; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV5; + RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; + RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; + HAL_CHECK(HAL_RCC_OscConfig(&RCC_OscInitStruct)); - /* Enable MSI Auto-calibration through LSE */ - 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)); + /* Enable MSI Auto-calibration through LSE */ + HAL_RCCEx_EnableMSIPLLMode(); - /* AHB prescaler divider at 1 as second step */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - HAL_CHECK(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5)); + /* 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)); - /* 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)); + /* AHB prescaler divider at 1 as second step */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + HAL_CHECK(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5)); + + /* 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)); } diff --git a/ports/stm/peripherals/stm32l4/stm32l4r5xx/gpio.c b/ports/stm/peripherals/stm32l4/stm32l4r5xx/gpio.c index 2afb7caf04..e8b805dcec 100644 --- a/ports/stm/peripherals/stm32l4/stm32l4r5xx/gpio.c +++ b/ports/stm/peripherals/stm32l4/stm32l4r5xx/gpio.c @@ -38,8 +38,8 @@ void stm32_peripherals_gpio_init(void) { __HAL_RCC_GPIOG_CLK_ENABLE(); // 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_GPIOI_CLK_ENABLE(); + // __HAL_RCC_GPIOH_CLK_ENABLE(); + // __HAL_RCC_GPIOI_CLK_ENABLE(); // Never reset pins never_reset_pin_number(2,14); // PC14 OSC32_IN diff --git a/ports/stm/peripherals/stm32l4/stm32l4r5xx/periph.c b/ports/stm/peripherals/stm32l4/stm32l4r5xx/periph.c index 2d8012e20a..32da56f222 100644 --- a/ports/stm/peripherals/stm32l4/stm32l4r5xx/periph.c +++ b/ports/stm/peripherals/stm32l4/stm32l4r5xx/periph.c @@ -167,7 +167,7 @@ const mcu_periph_obj_t mcu_uart_rx_list[UART_RX_ARRAY_LEN] = { // Timers // 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] = { 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(16, 15, 1, &pin_PA06), 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, 2, &pin_PA09), 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(16, 15, 1, &pin_PB08), 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, 4, &pin_PB11), 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, 4, &pin_PD15), 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, 2, &pin_PE04), 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_PD00), PERIPH(1, 10, &pin_PI09), -}; \ No newline at end of file +}; diff --git a/ports/stm/peripherals/stm32l4/stm32l4r5xx/periph.h b/ports/stm/peripherals/stm32l4/stm32l4r5xx/periph.h index 300a6918a2..d28b6c8ea3 100644 --- a/ports/stm/peripherals/stm32l4/stm32l4r5xx/periph.h +++ b/ports/stm/peripherals/stm32l4/stm32l4r5xx/periph.h @@ -57,7 +57,7 @@ extern const mcu_periph_obj_t mcu_uart_rx_list[UART_RX_ARRAY_LEN]; // Timers #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 const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; diff --git a/ports/stm/supervisor/internal_flash.c b/ports/stm/supervisor/internal_flash.c index 48c4970e3b..8d8ca2e0e1 100644 --- a/ports/stm/supervisor/internal_flash.c +++ b/ports/stm/supervisor/internal_flash.c @@ -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) { if (addr >= flash_layout[0].base_address) { uint32_t sector_index = 0; - if (MP_ARRAY_SIZE(flash_layout)==1) { - sector_index = (addr-flash_layout[0].base_address)/flash_layout[0].sector_size; - if (sector_index>=flash_layout[0].sector_count) { + if (MP_ARRAY_SIZE(flash_layout) == 1) { + sector_index = (addr - flash_layout[0].base_address) / flash_layout[0].sector_size; + if (sector_index >= flash_layout[0].sector_count) { return 0; } 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); #else #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 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); #endif @@ -256,7 +256,7 @@ void port_internal_flash_flush(void) { // program the flash word by word for (uint32_t i = 0; i < sector_size / 8; i++) { 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 HAL_FLASH_Lock(); // lock the flash reset_into_safe_mode(FLASH_WRITE_FAIL); diff --git a/ports/stm/supervisor/port.c b/ports/stm/supervisor/port.c index b47e1b0f0d..3b487d38ab 100644 --- a/ports/stm/supervisor/port.c +++ b/ports/stm/supervisor/port.c @@ -176,7 +176,7 @@ static volatile uint32_t systick_ms; safe_mode_t port_init(void) { HAL_Init(); // Turns on SysTick __HAL_RCC_SYSCFG_CLK_ENABLE(); - + #if CPY_STM32F4 || CPY_STM32L4 __HAL_RCC_PWR_CLK_ENABLE(); HAL_PWR_EnableBkUpAccess(); diff --git a/ports/stm/supervisor/usb.c b/ports/stm/supervisor/usb.c index 05702af39d..0e08dc06df 100644 --- a/ports/stm/supervisor/usb.c +++ b/ports/stm/supervisor/usb.c @@ -125,7 +125,7 @@ void init_usb_hardware(void) { never_reset_pin_number(0, 10); claim_pin(0, 10); #endif - + #ifdef STM32F412Zx /* Configure POWER_SWITCH IO pin (F412 ONLY)*/ GPIO_InitStruct.Pin = GPIO_PIN_8; diff --git a/ports/stm/tools/examples/stm32l4r5zi.csv b/ports/stm/tools/examples/stm32l4r5zi.csv index 3ca4f00011..37683c751f 100644 --- a/ports/stm/tools/examples/stm32l4r5zi.csv +++ b/ports/stm/tools/examples/stm32l4r5zi.csv @@ -138,4 +138,4 @@ PI7,-,-,-,TIM8_CH3,-,-,-,-,,-,-,DCMI_D7,-,-,-,-,EVENTOUT PI8,-,-,-,-,-,OCTOSPIM_P2_NCS,-,-,,-,-,DCMI_D12,-,-,-,-,EVENTOUT PI9,-,-,-,-,-,OCTOSPIM_P2_IO2,-,-,,-,CAN1_RX,-,-,-,-,-,EVENTOUT PI10,-,-,-,-,-,OCTOSPIM_P2_IO1,-,-,,-,-,-,-,-,-,-,EVENTOUT -PI11,-,-,-,-,-,OCTOSPIM_P2_IO0,-,-,,-,-,-,-,-,-,-,EVENTOUT \ No newline at end of file +PI11,-,-,-,-,-,OCTOSPIM_P2_IO0,-,-,,-,-,-,-,-,-,-,EVENTOUT diff --git a/ports/stm/tools/parse_af_csv.py b/ports/stm/tools/parse_af_csv.py index f0667ba2a2..3e48d4145d 100644 --- a/ports/stm/tools/parse_af_csv.py +++ b/ports/stm/tools/parse_af_csv.py @@ -88,7 +88,7 @@ with open(sys.argv[1]) as csv_file: for row in csv_reader: altfn = 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:] for col in row: array_index = 0 diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index d8ebb636b5..9961d6d53f 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -36,7 +36,7 @@ #include "tusb.h" #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" #endif @@ -275,19 +275,18 @@ bool common_hal_usb_cdc_enable(bool console, bool data) { // BOS Descriptor is required for webUSB uint8_t const desc_bos[] = { - // total length, number of device caps - TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 2), + // total length, number of device caps + TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 2), - // Vendor Code, iLandingPage - TUD_BOS_WEBUSB_DESCRIPTOR(VENDOR_REQUEST_WEBUSB, 1), + // Vendor Code, iLandingPage + TUD_BOS_WEBUSB_DESCRIPTOR(VENDOR_REQUEST_WEBUSB, 1), - // Microsoft OS 2.0 descriptor - TUD_BOS_MS_OS_20_DESCRIPTOR(MS_OS_20_DESC_LEN, VENDOR_REQUEST_MICROSOFT) + // Microsoft OS 2.0 descriptor + TUD_BOS_MS_OS_20_DESCRIPTOR(MS_OS_20_DESC_LEN, VENDOR_REQUEST_MICROSOFT) }; -uint8_t const * tud_descriptor_bos_cb(void) -{ - return desc_bos; +uint8_t const *tud_descriptor_bos_cb(void) { + return desc_bos; } #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[] = { - // 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), + // 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), - // 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), + // 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), - // 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), + // 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), - // 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, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible + // 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, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible - // 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(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, - '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 - //bPropertyData: “{975F44D9-0D08-43FD-8B3E-127CA8AFFF9D}”. - '{', 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, - '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 + // 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(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, + '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 + // bPropertyData: “{975F44D9-0D08-43FD-8B3E-127CA8AFFF9D}”. + '{', 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, + '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 }; 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] #define VENDOR_OUT_ENDPOINT_INDEX 11 0x02, // 12 bmAttributes (Bulk) -#if USB_HIGHSPEED + #if USB_HIGHSPEED 0x00, 0x02, // 13,14 wMaxPacketSize 512 -#else + #else 0x40, 0x00, // 13,14 wMaxPacketSize 64 -#endif + #endif 0x0, // 15 bInterval 0 // Vendor IN Endpoint Descriptor @@ -376,15 +375,15 @@ static supervisor_allocation *ms_os_20_descriptor_allocation; size_t vendor_ms_os_20_descriptor_length() { 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; } 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) { - ms_os_20_descriptor_allocation = + if (ms_os_20_descriptor_template[MS_OS_20_ITF_NUM_OFFSET] == MS_OS_20_ITF_NUM_MAGIC) { + ms_os_20_descriptor_allocation = allocate_memory(align32_size(sizeof(ms_os_20_descriptor_template)), /*high_address*/ false, /*movable*/ false); uint8_t *ms_os_20_descriptor_buf = (uint8_t *)ms_os_20_descriptor_allocation->ptr; diff --git a/shared-module/usb_cdc/__init__.h b/shared-module/usb_cdc/__init__.h index cb2064ed1d..87dabf05db 100644 --- a/shared-module/usb_cdc/__init__.h +++ b/shared-module/usb_cdc/__init__.h @@ -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 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 /* SHARED_MODULE_USB_CDC___INIT___H */ diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index c15f6d0c79..9a8b6cd1b6 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -65,10 +65,10 @@ static bool web_serial_connected = false; const tusb_desc_webusb_url_t desc_webusb_url = { - .bLength = 3 + sizeof(URL) - 1, - .bDescriptorType = 3, // WEBUSB URL type - .bScheme = 1, // 0: http, 1: https - .url = URL + .bLength = 3 + sizeof(URL) - 1, + .bDescriptorType = 3, // WEBUSB URL type + .bScheme = 1, // 0: http, 1: https + .url = URL }; #endif diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index 9873c8a547..6a0b7ab851 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -140,7 +140,7 @@ static void usb_build_device_descriptor(uint16_t vid, uint16_t pid) { static void usb_build_configuration_descriptor(void) { size_t total_descriptor_length = sizeof(configuration_descriptor_template); - + // 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. #if CIRCUITPY_USB_CDC @@ -172,7 +172,7 @@ static void usb_build_configuration_descriptor(void) { #if CIRCUITPY_USB_VENDOR if (usb_vendor_enabled()) { - total_descriptor_length += usb_vendor_descriptor_length(); + total_descriptor_length += usb_vendor_descriptor_length(); } #endif diff --git a/supervisor/shared/usb/usb_vendor_descriptors.h b/supervisor/shared/usb/usb_vendor_descriptors.h index b3b88b9092..0b41c09d34 100644 --- a/supervisor/shared/usb/usb_vendor_descriptors.h +++ b/supervisor/shared/usb/usb_vendor_descriptors.h @@ -1,4 +1,4 @@ -/* +/* * The MIT License (MIT) * * Copyright (c) 2019 Ha Thach (tinyusb.org) @@ -29,11 +29,11 @@ enum { - VENDOR_REQUEST_WEBUSB = 1, - VENDOR_REQUEST_MICROSOFT = 2 + VENDOR_REQUEST_WEBUSB = 1, + VENDOR_REQUEST_MICROSOFT = 2 }; 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_ */