Skip to content

Commit 5ac38c9

Browse files
committed
Various requested fixes
1 parent 92a0621 commit 5ac38c9

File tree

11 files changed

+40
-81
lines changed

11 files changed

+40
-81
lines changed

ports/stm/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
255255
ifeq ($(INTERNAL_LIBM),1)
256256
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
257257
endif
258-
#OBJ += $(addprefix $(BUILD)/, $(SRC_O))
259258
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
260259
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
261260

ports/stm/boards/nucleo_f767zi/mpconfigboard.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
USB_VID = 0x239A #REPLACE
2-
USB_PID = 0x808A #REPLACE
1+
USB_VID = 0x239A
2+
USB_PID = 0x809A
33
USB_PRODUCT = "Nucleo F767ZI - CPy"
44
USB_MANUFACTURER = "STMicroelectronics"
55
USB_DEVICES = "CDC,MSC"

ports/stm/boards/nucleo_h743zi_2/mpconfigboard.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
USB_VID = 0x239A #REPLACE
2-
USB_PID = 0x808A #REPLACE
1+
USB_VID = 0x239A
2+
USB_PID = 0x8098
33
USB_PRODUCT = "Nucleo H743ZI - CPy"
44
USB_MANUFACTURER = "STMicroelectronics"
55
USB_DEVICES = "CDC,MSC"

ports/stm/boards/thunderpack/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ MCU_SERIES = F4
1313
MCU_VARIANT = STM32F411xE
1414
MCU_PACKAGE = UFQFPN48
1515

16-
LD_FILE = boards/common_nvm.ld
16+
LD_COMMON = boards/common_nvm.ld
1717
LD_FILE = boards/STM32F411_nvm.ld

ports/stm/common-hal/busio/I2C.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
6464
uint8_t sda_len = MP_ARRAY_SIZE(mcu_i2c_sda_list);
6565
uint8_t scl_len = MP_ARRAY_SIZE(mcu_i2c_scl_list);
6666
bool i2c_taken = false;
67-
bool search_done = false;
6867

6968
for (uint i = 0; i < sda_len; i++) {
7069
if (mcu_i2c_sda_list[i].pin == sda) {
@@ -78,12 +77,11 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
7877
}
7978
self->scl = &mcu_i2c_scl_list[j];
8079
self->sda = &mcu_i2c_sda_list[i];
81-
// Multi-level break here, or it'll pick the highest numbered peripheral (inefficient)
82-
search_done = true;
8380
break;
8481
}
8582
}
86-
if (search_done) {
83+
if (self->scl != NULL) {
84+
// Multi-level break to pick lowest peripheral
8785
break;
8886
}
8987
}

ports/stm/common-hal/busio/SPI.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
118118
uint8_t mosi_len = MP_ARRAY_SIZE(mcu_spi_mosi_list);
119119
uint8_t miso_len = MP_ARRAY_SIZE(mcu_spi_miso_list);
120120
bool spi_taken = false;
121-
bool search_done = false;
122121

123122
//SCK is not optional. MOSI and MISO are
124123
for (uint i = 0; i < sck_len; i++) {
@@ -142,64 +141,51 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
142141
self->sck = &mcu_spi_sck_list[i];
143142
self->mosi = &mcu_spi_mosi_list[j];
144143
self->miso = &mcu_spi_miso_list[k];
145-
146-
// Multi-level break to pick lowest peripheral
147-
search_done = true;
148144
break;
149145
}
150146
}
151-
if (search_done) {
152-
break;
147+
if (self->sck != NULL) {
148+
break; // Multi-level break to pick lowest peripheral
153149
}
154150
}
155151
}
156-
if (search_done) {
152+
if (self->sck != NULL) {
157153
break;
158154
}
159155
// if just MISO, reduce search
160156
} else if (miso != NULL) {
161157
for (uint j = 0; j < miso_len; j++) {
162158
if ((mcu_spi_miso_list[j].pin == miso) //only SCK and MISO need the same index
163159
&& (mcu_spi_sck_list[i].periph_index == mcu_spi_miso_list[j].periph_index)) {
164-
//keep looking if the SPI is taken, edge case
165160
if (reserved_spi[mcu_spi_sck_list[i].periph_index - 1]) {
166161
spi_taken = true;
167162
continue;
168163
}
169-
//store pins if not
170164
self->sck = &mcu_spi_sck_list[i];
171165
self->mosi = NULL;
172166
self->miso = &mcu_spi_miso_list[j];
173-
174-
// Multi-level break to pick lowest peripheral
175-
search_done = true;
176167
break;
177168
}
178169
}
179-
if (search_done) {
170+
if (self->sck != NULL) {
180171
break;
181172
}
182173
// if just MOSI, reduce search
183174
} else if (mosi != NULL) {
184175
for (uint j = 0; j < mosi_len; j++) {
185176
if ((mcu_spi_mosi_list[j].pin == mosi) //only SCK and MOSI need the same index
186177
&& (mcu_spi_sck_list[i].periph_index == mcu_spi_mosi_list[j].periph_index)) {
187-
//keep looking if the SPI is taken, edge case
188178
if (reserved_spi[mcu_spi_sck_list[i].periph_index - 1]) {
189179
spi_taken = true;
190180
continue;
191181
}
192-
//store pins if not
193182
self->sck = &mcu_spi_sck_list[i];
194183
self->mosi = &mcu_spi_mosi_list[j];
195184
self->miso = NULL;
196-
197-
// Multi-level break to pick lowest peripheral
198-
search_done = true;
199185
break;
200186
}
201187
}
202-
if (search_done) {
188+
if (self->sck != NULL) {
203189
break;
204190
}
205191
} else {

ports/stm/common-hal/busio/UART.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
8484
uint8_t rx_len = MP_ARRAY_SIZE(mcu_uart_rx_list);
8585
bool uart_taken = false;
8686
uint8_t periph_index = 0; //origin 0 corrected
87-
bool search_done = false;
8887

8988
if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert == true)) {
9089
mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device"));
@@ -107,13 +106,10 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
107106
//store pins if not
108107
self->tx = &mcu_uart_tx_list[i];
109108
self->rx = &mcu_uart_rx_list[j];
110-
111-
// Multi-level break to pick lowest peripheral
112-
search_done = true;
113109
break;
114110
}
115111
}
116-
if (search_done) {
112+
if (self->tx != NULL) {
117113
break;
118114
}
119115
}
@@ -132,9 +128,6 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
132128
}
133129
//store pins if not
134130
self->rx = &mcu_uart_rx_list[i];
135-
136-
// Multi-level break to pick lowest peripheral
137-
search_done = true;
138131
break;
139132
}
140133
}
@@ -152,9 +145,6 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
152145
}
153146
//store pins if not
154147
self->tx = &mcu_uart_tx_list[i];
155-
156-
// Multi-level break to pick lowest peripheral
157-
search_done = true;
158148
break;
159149
}
160150
}

ports/stm/supervisor/internal_flash.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ void supervisor_flash_flush(void) {
181181
EraseInitStruct.Sector = flash_get_sector_info(_cache_flash_addr, &sector_start_addr, &sector_size);
182182
EraseInitStruct.NbSectors = 1;
183183
if (sector_size > sizeof(_flash_cache)) {
184-
__ASM volatile ("bkpt");
185-
mp_printf(&mp_plat_print, "FLASH ERR: invalid sector\n");
186184
reset_into_safe_mode(FLASH_WRITE_FAIL);
187185
}
188186

@@ -196,8 +194,6 @@ void supervisor_flash_flush(void) {
196194
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
197195
// error occurred during sector erase
198196
HAL_FLASH_Lock(); // lock the flash
199-
__ASM volatile ("bkpt");
200-
mp_printf(&mp_plat_print, "FLASH ERR: erase failure\n");
201197
reset_into_safe_mode(FLASH_WRITE_FAIL);
202198
}
203199

@@ -211,7 +207,6 @@ void supervisor_flash_flush(void) {
211207
(uint32_t)cache_addr) != HAL_OK) {
212208
// error occurred during flash write
213209
HAL_FLASH_Lock(); // lock the flash
214-
__ASM volatile ("bkpt");
215210
reset_into_safe_mode(FLASH_WRITE_FAIL);
216211
}
217212
// RAM memory is by word (4 byte), but flash memory is by byte
@@ -226,7 +221,6 @@ void supervisor_flash_flush(void) {
226221
(uint64_t)*cache_addr) != HAL_OK) {
227222
// error occurred during flash write
228223
HAL_FLASH_Lock(); // lock the flash
229-
__ASM volatile ("bkpt");
230224
reset_into_safe_mode(FLASH_WRITE_FAIL);
231225
}
232226
// RAM memory is by word (4 byte), but flash memory is by byte
@@ -267,8 +261,6 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num,
267261
int32_t dest = convert_block_to_flash_addr(block_num);
268262
if (dest == -1) {
269263
// bad block number
270-
__ASM volatile ("bkpt");
271-
mp_printf(&mp_plat_print, "BAD FLASH BLOCK ERROR");
272264
return false;
273265
}
274266

@@ -281,8 +273,6 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num,
281273

282274
// Fail for any sector outside the 16k ones for now
283275
if (sector_size > sizeof(_flash_cache)) {
284-
__ASM volatile ("bkpt");
285-
mp_printf(&mp_plat_print, "FLASH ERR: invalid sector\n");
286276
reset_into_safe_mode(FLASH_WRITE_FAIL);
287277
}
288278

ports/stm/supervisor/port.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@
3131
#include "tick.h"
3232

3333
#include "common-hal/microcontroller/Pin.h"
34+
35+
#if CIRCUITPY_BUSIO
3436
#include "common-hal/busio/I2C.h"
3537
#include "common-hal/busio/SPI.h"
3638
#include "common-hal/busio/UART.h"
37-
38-
#if defined(STM32F4)
39-
#include "common-hal/pulseio/PWMOut.h"
40-
#include "common-hal/pulseio/PulseOut.h"
41-
#include "common-hal/pulseio/PulseIn.h"
39+
#endif
40+
#if CIRCUITPY_PULSEIO
41+
#include "common-hal/pulseio/PWMOut.h"
42+
#include "common-hal/pulseio/PulseOut.h"
43+
#include "common-hal/pulseio/PulseIn.h"
4244
#endif
4345

4446
#include "clocks.h"
@@ -114,7 +116,6 @@ __attribute__((used, naked)) void Reset_Handler(void) {
114116

115117
// The first number in RBAR is the region number. When searching for a policy, the region with
116118
// the highest number wins. If none match, then the default policy set at enable applies.
117-
// TODO: what is the default policy? Where is that set?
118119

119120
// TODO: do I need to subdivide this up?
120121
// Mark all the flash the same until instructed otherwise.
@@ -124,7 +125,7 @@ __attribute__((used, naked)) void Reset_Handler(void) {
124125
// This the ITCM. Set it to read-only because we've loaded everything already and it's easy to
125126
// accidentally write the wrong value to 0x00000000 (aka NULL).
126127
MPU->RBAR = ARM_MPU_RBAR(12, 0x00000000U);
127-
MPU->RASR = ARM_MPU_RASR(EXECUTION, ARM_MPU_AP_RO, NORMAL, NOT_SHAREABLE, CACHEABLE, BUFFERABLE, NO_SUBREGIONS, ARM_MPU_REGION_SIZE_128KB);
128+
MPU->RASR = ARM_MPU_RASR(EXECUTION, ARM_MPU_AP_RO, NORMAL, NOT_SHAREABLE, CACHEABLE, BUFFERABLE, NO_SUBREGIONS, ARM_MPU_REGION_SIZE_64KB);
128129

129130
// This the DTCM.
130131
MPU->RBAR = ARM_MPU_RBAR(14, 0x20000000U);
@@ -187,17 +188,16 @@ safe_mode_t port_init(void) {
187188

188189
void reset_port(void) {
189190
reset_all_pins();
191+
#if CIRCUITPY_BUSIO
190192
i2c_reset();
191193
spi_reset();
192194
uart_reset();
193-
194-
// TODO: it'd be nice if this was more automatic
195-
#if defined(STM32F4)
196-
197-
pwmout_reset();
198-
pulseout_reset();
199-
pulsein_reset();
200-
#endif
195+
#endif
196+
#if CIRCUITPY_PULSEIO
197+
pwmout_reset();
198+
pulseout_reset();
199+
pulsein_reset();
200+
#endif
201201
}
202202

203203
void reset_to_bootloader(void) {

ports/stm/supervisor/usb.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,58 +78,54 @@ void init_usb_hardware(void) {
7878
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
7979
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
8080
GPIO_InitStruct.Pull = GPIO_NOPULL;
81-
#if defined(STM32H7)
81+
#if CPY_STM32H7
8282
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_FS;
83-
#elif defined(STM32F4) || defined(STM32F7)
83+
#elif CPY_STM32F4 || CPY_STM32F7
8484
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
85-
#else
86-
#error Unsupported processor
8785
#endif
8886
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
8987
never_reset_pin_number(0, 11);
9088
never_reset_pin_number(0, 12);
9189

9290
/* Configure VBUS Pin */
93-
#if !(BOARD_NO_VBUS_SENSE)
91+
#if !(BOARD_NO_VBUS_SENSE)
9492
GPIO_InitStruct.Pin = GPIO_PIN_9;
9593
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
9694
GPIO_InitStruct.Pull = GPIO_NOPULL;
9795
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
9896
never_reset_pin_number(0, 9);
99-
#endif
97+
#endif
10098

10199
/* This for ID line debug */
102100
GPIO_InitStruct.Pin = GPIO_PIN_10;
103101
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
104102
GPIO_InitStruct.Pull = GPIO_PULLUP;
105103
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
106-
#if defined(STM32H7)
104+
#if CPY_STM32H7
107105
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_FS;
108-
#elif defined(STM32F4) || defined(STM32F7)
106+
#elif CPY_STM32F4 || CPY_STM32F7
109107
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
110-
#else
111-
#error Unsupported processor
112108
#endif
113109
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
114110
never_reset_pin_number(0, 10);
115111

116-
#ifdef STM32F412Zx
112+
#ifdef STM32F412Zx
117113
/* Configure POWER_SWITCH IO pin (F412 ONLY)*/
118114
GPIO_InitStruct.Pin = GPIO_PIN_8;
119115
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
120116
GPIO_InitStruct.Pull = GPIO_NOPULL;
121117
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
122118
never_reset_pin_number(0, 8);
123-
#endif
119+
#endif
124120

125121

126-
#if defined(STM32H7)
122+
#if CPY_STM32H7
127123
HAL_PWREx_EnableUSBVoltageDetector();
128124
__HAL_RCC_USB2_OTG_FS_CLK_ENABLE();
129-
#else
125+
#else
130126
/* Peripheral clock enable */
131127
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
132-
#endif
128+
#endif
133129

134130
init_usb_vbus_sense();
135131
}

0 commit comments

Comments
 (0)