summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHierophect <hierophect@gmail.com>2019-08-15 17:45:40 -0400
committerHierophect <hierophect@gmail.com>2019-08-15 17:45:40 -0400
commit1f42ce5f4000d630da5cb744c2a61a69a8d7a0e8 (patch)
tree7ec2cafdd2850d6fe2e38fde4d3f942e26d1d0b1
parentbc7ba33892cae88ffd1b42dfa45868057a4934e8 (diff)
QOL fixes, compatibility fixes, attribution
-rw-r--r--ports/stm32f4/background.c3
-rw-r--r--ports/stm32f4/common-hal/busio/I2C.c3
-rw-r--r--ports/stm32f4/common-hal/busio/I2C.h1
-rw-r--r--ports/stm32f4/common-hal/busio/SPI.c1
-rw-r--r--ports/stm32f4/common-hal/microcontroller/Processor.c1
-rw-r--r--ports/stm32f4/common-hal/microcontroller/__init__.c1
-rw-r--r--ports/stm32f4/peripherals/stm32f4/gpio.h1
-rw-r--r--ports/stm32f4/peripherals/stm32f4/stm32f411xe/gpio.c25
-rw-r--r--ports/stm32f4/peripherals/stm32f4/stm32f412zx/gpio.c30
-rw-r--r--ports/stm32f4/supervisor/internal_flash.c9
-rw-r--r--ports/stm32f4/supervisor/internal_flash.h1
-rw-r--r--ports/stm32f4/supervisor/serial.c6
-rw-r--r--ports/stm32f4/supervisor/usb.c1
-rw-r--r--supervisor/shared/usb/tusb_config.h2
14 files changed, 62 insertions, 23 deletions
diff --git a/ports/stm32f4/background.c b/ports/stm32f4/background.c
index 9c4f3ab27..8e31efdc2 100644
--- a/ports/stm32f4/background.c
+++ b/ports/stm32f4/background.c
@@ -46,7 +46,10 @@ void run_background_tasks(void) {
}
running_background_tasks = true;
filesystem_background();
+
+ #if USB_AVAILABLE
usb_background();
+ #endif
#if CIRCUITPY_DISPLAYIO
displayio_refresh_displays();
diff --git a/ports/stm32f4/common-hal/busio/I2C.c b/ports/stm32f4/common-hal/busio/I2C.c
index 1babe33a1..019465ccc 100644
--- a/ports/stm32f4/common-hal/busio/I2C.c
+++ b/ports/stm32f4/common-hal/busio/I2C.c
@@ -4,6 +4,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2016 Scott Shawcroft
+ * Copyright (c) 2019 Lucian Copeland for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -36,6 +37,8 @@ I2C_HandleTypeDef hi2c2;
void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency, uint32_t timeout) {
+ //TODO: Rework this entire section to use LL, alongside MSP removal
+
hi2c2.Instance = I2C1;
hi2c2.Init.ClockSpeed = 100000;
hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;
diff --git a/ports/stm32f4/common-hal/busio/I2C.h b/ports/stm32f4/common-hal/busio/I2C.h
index 9fe0258a1..5c801ab32 100644
--- a/ports/stm32f4/common-hal/busio/I2C.h
+++ b/ports/stm32f4/common-hal/busio/I2C.h
@@ -4,6 +4,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2016 Scott Shawcroft
+ * Copyright (c) 2019 Lucian Copeland for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
diff --git a/ports/stm32f4/common-hal/busio/SPI.c b/ports/stm32f4/common-hal/busio/SPI.c
index 98faf7b3b..a33581b64 100644
--- a/ports/stm32f4/common-hal/busio/SPI.c
+++ b/ports/stm32f4/common-hal/busio/SPI.c
@@ -40,6 +40,7 @@ void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) {
}
bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) {
+ return 0;
}
void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
diff --git a/ports/stm32f4/common-hal/microcontroller/Processor.c b/ports/stm32f4/common-hal/microcontroller/Processor.c
index 7117945b3..c16bd3125 100644
--- a/ports/stm32f4/common-hal/microcontroller/Processor.c
+++ b/ports/stm32f4/common-hal/microcontroller/Processor.c
@@ -4,6 +4,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2017 Dan Halbert for Adafruit Industries
+ * Copyright (c) 2019 Lucian Copeland for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
diff --git a/ports/stm32f4/common-hal/microcontroller/__init__.c b/ports/stm32f4/common-hal/microcontroller/__init__.c
index 08f8f28f8..4cbd6d66f 100644
--- a/ports/stm32f4/common-hal/microcontroller/__init__.c
+++ b/ports/stm32f4/common-hal/microcontroller/__init__.c
@@ -4,6 +4,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
+ * Copyright (c) 2019 Lucian Copeland for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
diff --git a/ports/stm32f4/peripherals/stm32f4/gpio.h b/ports/stm32f4/peripherals/stm32f4/gpio.h
index 251cdb814..34f89e792 100644
--- a/ports/stm32f4/peripherals/stm32f4/gpio.h
+++ b/ports/stm32f4/peripherals/stm32f4/gpio.h
@@ -25,3 +25,4 @@
*/
void stm32f4_peripherals_gpio_init(void);
+void stm32f4_peripherals_status_led(uint8_t led, uint8_t state);
diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/gpio.c b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/gpio.c
index a9ac97bae..3fd85c632 100644
--- a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/gpio.c
+++ b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/gpio.c
@@ -105,6 +105,7 @@
#define LD6_GPIO_Port GPIOD
#include "stm32f4xx_hal.h"
+#include "stm32f4/gpio.h"
void stm32f4_peripherals_gpio_init(void) {
//Enable all GPIO for now
@@ -128,10 +129,26 @@ void stm32f4_peripherals_gpio_init(void) {
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
//Status LED chain
- HAL_GPIO_WritePin(GPIOD, LD4_Pin, GPIO_PIN_RESET); //LED 1
- HAL_GPIO_WritePin(GPIOD, LD3_Pin, GPIO_PIN_SET); //LED 2
- HAL_GPIO_WritePin(GPIOD, LD5_Pin, GPIO_PIN_SET); //LED 3
- HAL_GPIO_WritePin(GPIOD, LD6_Pin, GPIO_PIN_SET); //LED 4
+ stm32f4_peripherals_status_led(0,1);
+ stm32f4_peripherals_status_led(1,0);
+ stm32f4_peripherals_status_led(2,0);
+ stm32f4_peripherals_status_led(3,0);
+}
+
+//LEDs are inverted on F411 DISCO
+void stm32f4_peripherals_status_led(uint8_t led, uint8_t state) {
+ switch(led)
+ {
+ case 0: HAL_GPIO_WritePin(GPIOD, LD4_Pin, (state ^ 1));
+ break;
+ case 1: HAL_GPIO_WritePin(GPIOD, LD3_Pin, (state ^ 1));
+ break;
+ case 2: HAL_GPIO_WritePin(GPIOD, LD5_Pin, (state ^ 1));
+ break;
+ case 3: HAL_GPIO_WritePin(GPIOD, LD6_Pin, (state ^ 1));
+ break;
+ default: break;
+ }
}
diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f412zx/gpio.c b/ports/stm32f4/peripherals/stm32f4/stm32f412zx/gpio.c
index de783bafe..a22963a9c 100644
--- a/ports/stm32f4/peripherals/stm32f4/stm32f412zx/gpio.c
+++ b/ports/stm32f4/peripherals/stm32f4/stm32f412zx/gpio.c
@@ -178,6 +178,7 @@
*/
#include "stm32f4xx_hal.h"
+#include "stm32f4/gpio.h"
void stm32f4_peripherals_gpio_init(void) {
//Enable all GPIO for now
@@ -202,17 +203,26 @@ void stm32f4_peripherals_gpio_init(void) {
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
//Status LED chain
- HAL_GPIO_WritePin(GPIOE, GPIO_PIN_0, GPIO_PIN_RESET); //LED 1
- HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_SET); //LED 2
- HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_SET); //LED 3
- HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_SET); //LED 4
+ stm32f4_peripherals_status_led(0,1);
+ stm32f4_peripherals_status_led(1,0);
+ stm32f4_peripherals_status_led(2,0);
+ stm32f4_peripherals_status_led(3,0);
+}
- //TBD, USB power
- // GPIO_InitStruct.Pin = USB_OTGFS_PPWR_EN_Pin;
- // GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
- // GPIO_InitStruct.Pull = GPIO_NOPULL;
- // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- // HAL_GPIO_Init(USB_OTGFS_PPWR_EN_GPIO_Port, &GPIO_InitStruct);
+//LEDs are inverted on F411 DISCO
+void stm32f4_peripherals_status_led(uint8_t led, uint8_t state) {
+ switch(led)
+ {
+ case 0: HAL_GPIO_WritePin(GPIOE, GPIO_PIN_0, (state ^ 1));
+ break;
+ case 1: HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, (state ^ 1));
+ break;
+ case 2: HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, (state ^ 1));
+ break;
+ case 3: HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, (state ^ 1));
+ break;
+ default: break;
+ }
}
diff --git a/ports/stm32f4/supervisor/internal_flash.c b/ports/stm32f4/supervisor/internal_flash.c
index 966b167d8..fd3241bd6 100644
--- a/ports/stm32f4/supervisor/internal_flash.c
+++ b/ports/stm32f4/supervisor/internal_flash.c
@@ -4,6 +4,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
+ * Copyright (c) 2019 Lucian Copeland for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -67,8 +68,8 @@ static uint8_t sector_copy[0x4000] __attribute__((aligned(4)));
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;
- for (int i = 0; i < MP_ARRAY_SIZE(flash_layout); ++i) {
- for (int j = 0; j < flash_layout[i].sector_count; ++j) {
+ for (uint8_t i = 0; i < MP_ARRAY_SIZE(flash_layout); ++i) {
+ for (uint8_t j = 0; j < flash_layout[i].sector_count; ++j) {
uint32_t sector_start_next = flash_layout[i].base_address
+ (j + 1) * flash_layout[i].sector_size;
if (addr < sector_start_next) {
@@ -112,7 +113,7 @@ static int32_t convert_block_to_flash_addr(uint32_t block) {
}
mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) {
- uint32_t src = convert_block_to_flash_addr(block);
+ int32_t src = convert_block_to_flash_addr(block);
if (src == -1) {
// bad block number
return false;
@@ -172,7 +173,7 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) {
__HAL_FLASH_DATA_CACHE_ENABLE();
// reprogram the sector
- for (int i = 0; i < sector_size; i++) {
+ for (uint32_t i = 0; i < sector_size; i++) {
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, sector_start_addr, (uint64_t)sector_copy[i]) != HAL_OK) {
// error occurred during flash write
HAL_FLASH_Lock(); // lock the flash
diff --git a/ports/stm32f4/supervisor/internal_flash.h b/ports/stm32f4/supervisor/internal_flash.h
index 83b35e03c..4575cf1d7 100644
--- a/ports/stm32f4/supervisor/internal_flash.h
+++ b/ports/stm32f4/supervisor/internal_flash.h
@@ -4,6 +4,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
+ * Copyright (c) 2019 Lucian Copeland for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
diff --git a/ports/stm32f4/supervisor/serial.c b/ports/stm32f4/supervisor/serial.c
index 1532a8ae8..ce1366000 100644
--- a/ports/stm32f4/supervisor/serial.c
+++ b/ports/stm32f4/supervisor/serial.c
@@ -4,6 +4,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2017, 2018 Scott Shawcroft for Adafruit Industries
+ * Copyright (c) 2019 Lucian Copeland for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -28,6 +29,7 @@
#include <string.h>
#include "supervisor/serial.h"
#include "stm32f4xx_hal.h"
+#include "stm32f4/gpio.h"
UART_HandleTypeDef huart2;
@@ -42,10 +44,8 @@ void serial_init(void) {
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart2) == HAL_OK)
{
- HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET);
+ stm32f4_peripherals_status_led(1,1);
}
- HAL_UART_Transmit(&huart2, (uint8_t*)"Serial On", 9, 2);
- HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_RESET);
}
bool serial_connected(void) {
diff --git a/ports/stm32f4/supervisor/usb.c b/ports/stm32f4/supervisor/usb.c
index 11885b3d9..4fa9045df 100644
--- a/ports/stm32f4/supervisor/usb.c
+++ b/ports/stm32f4/supervisor/usb.c
@@ -4,6 +4,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2018 hathach for Adafruit Industries
+ * Copyright (c) 2019 Lucian Copeland for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
diff --git a/supervisor/shared/usb/tusb_config.h b/supervisor/shared/usb/tusb_config.h
index 2e85bc820..ad5825b6c 100644
--- a/supervisor/shared/usb/tusb_config.h
+++ b/supervisor/shared/usb/tusb_config.h
@@ -107,11 +107,9 @@
// USB RAM PLACEMENT
//--------------------------------------------------------------------+
#define CFG_TUSB_ATTR_USBRAM
-
#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
-
#ifdef __cplusplus
}
#endif