Skip to content

Commit b9bed98

Browse files
committed
Merge stm32-meowbit
2 parents ab9483b + 8a9c309 commit b9bed98

File tree

8 files changed

+33
-37
lines changed

8 files changed

+33
-37
lines changed

ports/stm32f4/boards/meowbit_v121/board.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ uint8_t display_init_sequence[] = {
7474
void board_init(void) {
7575
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
7676
bus->base.type = &displayio_fourwire_type;
77-
busio_spi_obj_t *internal_spi = &spi;
77+
busio_spi_obj_t *internal_spi = &supervisor_flash_spi_bus;
7878
common_hal_displayio_fourwire_construct(bus,
7979
internal_spi,
8080
&pin_PA08, // Command or data

ports/stm32f4/boards/meowbit_v121/mpconfigboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
#define BOARD_OSC_DIV 12
3939
#define BOARD_NO_VBUS_SENSE
40-
// #define BOARD_VTOR_DEFER //Leave VTOR relocation to bootloader
40+
#define BOARD_VTOR_DEFER //Leave VTOR relocation to bootloader
4141
#define BOARD_USE_INTERNAL_SPI
4242

4343
// On-board flash

ports/stm32f4/boards/meowbit_v121/mpconfigboard.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ EXTERNAL_FLASH_DEVICE_COUNT = 1
99
EXTERNAL_FLASH_DEVICES = W25Q16JV_IQ
1010
LONGINT_IMPL = MPZ
1111

12-
# BOOTLOADER_OFFSET = 0x8010000
12+
BOOTLOADER_OFFSET = 0x8010000
1313

1414
# INTERNAL_FLASH_FILESYSTEM = 1
1515
# LONGINT_IMPL = NONE
@@ -19,5 +19,5 @@ MCU_VARIANT = stm32f4
1919
MCU_SUB_VARIANT = stm32f401xe
2020
MCU_PACKAGE = 64
2121
CMSIS_MCU = STM32F401xE
22-
# LD_FILE = boards/STM32F401_boot.ld
23-
LD_FILE = boards/STM32F401_fs.ld #use for internal flash
22+
LD_FILE = boards/STM32F401_boot.ld
23+
# LD_FILE = boards/STM32F401_fs.ld #use for internal flash

ports/stm32f4/boards/meowbit_v121/pins.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
1313
{ MP_ROM_QSTR(MP_QSTR_DISP_CS), MP_ROM_PTR(&pin_PB12) },
1414
{ MP_ROM_QSTR(MP_QSTR_DISP_DC), MP_ROM_PTR(&pin_PA08) },
1515
{ MP_ROM_QSTR(MP_QSTR_DISP_RST), MP_ROM_PTR(&pin_PB10) },
16-
{ MP_ROM_QSTR(MP_QSTR_DISP_BL), MP_ROM_PTR(&pin_PB03) }, //what is this, backlight?
16+
{ MP_ROM_QSTR(MP_QSTR_DISP_BL), MP_ROM_PTR(&pin_PB03) },
1717

1818
{ MP_ROM_QSTR(MP_QSTR_BUZZ), MP_ROM_PTR(&pin_PB08) },
1919
{ MP_ROM_QSTR(MP_QSTR_BTNA), MP_ROM_PTR(&pin_PB09) },
@@ -62,8 +62,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
6262
{ MP_ROM_QSTR(MP_QSTR_P0), MP_ROM_PTR(&pin_PA00) },
6363
{ MP_ROM_QSTR(MP_QSTR_P3), MP_ROM_PTR(&pin_PB00) },
6464

65-
{ MP_ROM_QSTR(MP_QSTR_INTERNAL_SPI), MP_ROM_PTR(&spi) },
66-
6765
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)},
66+
{ MP_ROM_QSTR(MP_QSTR_INTERNAL_SPI), MP_ROM_PTR(&supervisor_flash_spi_bus) },
6867
};
6968
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

ports/stm32f4/common-hal/pulseio/PWMOut.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ STATIC uint32_t timer_get_source_freq(uint32_t tim_id) {
6868
}
6969

7070
STATIC uint32_t timer_get_internal_duty(uint16_t duty, uint32_t period) {
71-
//duty cycle is (0xFFFF - duty)/0xFFFF fraction x (number of pulses per period)
72-
//Note that pulses are inverted, so duty cycle is inverted
73-
return ((0xFFFF - duty)*period) / ((1 << 16) - 1);
71+
//duty cycle is duty/0xFFFF fraction x (number of pulses per period)
72+
return (duty*period) / ((1 << 16) - 1);
7473
}
7574

7675
STATIC void timer_get_optimal_divisors(uint32_t*period, uint32_t*prescaler,
@@ -114,11 +113,12 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
114113
bool first_time_setup = true;
115114

116115
for (uint i = 0; i < tim_num; i++) {
117-
uint8_t l_tim_index = mcu_tim_pin_list[i].tim_index - 1;
118-
uint8_t l_tim_channel = mcu_tim_pin_list[i].channel_index - 1;
116+
const mcu_tim_pin_obj_t * l_tim = &mcu_tim_pin_list[i];
117+
uint8_t l_tim_index = l_tim->tim_index - 1;
118+
uint8_t l_tim_channel = l_tim->channel_index - 1;
119119

120120
//if pin is same
121-
if (mcu_tim_pin_list[i].pin == pin) {
121+
if (l_tim->pin == pin) {
122122
//check if the timer has a channel active
123123
if (reserved_tim[l_tim_index] != 0) {
124124
//is it the same channel? (or all channels reserved by a var-freq)
@@ -139,7 +139,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
139139
first_time_setup = false; //skip setting up the timer
140140
}
141141
//No problems taken, so set it up
142-
self->tim = &mcu_tim_pin_list[i];
142+
self->tim = l_tim;
143143
break;
144144
}
145145
}
@@ -203,11 +203,8 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
203203
//Channel/PWM init
204204
self->chan_handle.OCMode = TIM_OCMODE_PWM1;
205205
self->chan_handle.Pulse = timer_get_internal_duty(duty, period);
206-
self->chan_handle.OCPolarity = TIM_OCPOLARITY_LOW;
206+
self->chan_handle.OCPolarity = TIM_OCPOLARITY_HIGH;
207207
self->chan_handle.OCFastMode = TIM_OCFAST_DISABLE;
208-
self->chan_handle.OCNPolarity = TIM_OCNPOLARITY_LOW; // needed for TIM1 and TIM8
209-
self->chan_handle.OCIdleState = TIM_OCIDLESTATE_SET; // needed for TIM1 and TIM8
210-
self->chan_handle.OCNIdleState = TIM_OCNIDLESTATE_SET; // needed for TIM1 and TIM8
211208
if (HAL_TIM_PWM_ConfigChannel(&self->handle, &self->chan_handle, self->channel) != HAL_OK) {
212209
mp_raise_ValueError(translate("Could not initialize channel"));
213210
}

shared-module/displayio/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void reset_displays(void) {
104104
}
105105
#endif
106106
#ifdef BOARD_USE_INTERNAL_SPI
107-
if (original_spi == (mp_obj_t)(&spi)) {
107+
if (original_spi == (mp_obj_t)(&supervisor_flash_spi_bus)) {
108108
continue;
109109
}
110110
#endif

supervisor/shared/external_flash/spi_flash.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,33 @@
3636
#include "py/mpconfig.h"
3737

3838
digitalio_digitalinout_obj_t cs_pin;
39-
busio_spi_obj_t spi;
39+
busio_spi_obj_t supervisor_flash_spi_bus;
4040

4141
const external_flash_device* flash_device;
4242
uint32_t spi_flash_baudrate;
4343

4444
// Enable the flash over SPI.
4545
static void flash_enable(void) {
46-
while (!common_hal_busio_spi_try_lock(&spi)) {}
46+
while (!common_hal_busio_spi_try_lock(&supervisor_flash_spi_bus)) {}
4747
common_hal_digitalio_digitalinout_set_value(&cs_pin, false);
4848
}
4949

5050
// Disable the flash over SPI.
5151
static void flash_disable(void) {
5252
common_hal_digitalio_digitalinout_set_value(&cs_pin, true);
53-
common_hal_busio_spi_unlock(&spi);
53+
common_hal_busio_spi_unlock(&supervisor_flash_spi_bus);
5454
}
5555

5656
static bool transfer(uint8_t* command, uint32_t command_length, uint8_t* data_in, uint8_t* data_out, uint32_t data_length) {
5757
flash_enable();
58-
bool status = common_hal_busio_spi_write(&spi, command, command_length);
58+
bool status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, command, command_length);
5959
if (status) {
6060
if (data_in != NULL && data_out != NULL) {
61-
status = common_hal_busio_spi_transfer(&spi, data_out, data_in, data_length);
61+
status = common_hal_busio_spi_transfer(&supervisor_flash_spi_bus, data_out, data_in, data_length);
6262
} else if (data_out != NULL) {
63-
status = common_hal_busio_spi_read(&spi, data_out, data_length, 0xff);
63+
status = common_hal_busio_spi_read(&supervisor_flash_spi_bus, data_out, data_length, 0xff);
6464
} else if (data_in != NULL) {
65-
status = common_hal_busio_spi_write(&spi, data_in, data_length);
65+
status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, data_in, data_length);
6666
}
6767
}
6868
flash_disable();
@@ -103,10 +103,10 @@ bool spi_flash_write_data(uint32_t address, uint8_t* data, uint32_t data_length)
103103
// Write the SPI flash write address into the bytes following the command byte.
104104
address_to_bytes(address, request + 1);
105105
flash_enable();
106-
common_hal_busio_spi_configure(&spi, spi_flash_baudrate, 0, 0, 8);
107-
bool status = common_hal_busio_spi_write(&spi, request, 4);
106+
common_hal_busio_spi_configure(&supervisor_flash_spi_bus, spi_flash_baudrate, 0, 0, 8);
107+
bool status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, request, 4);
108108
if (status) {
109-
status = common_hal_busio_spi_write(&spi, data, data_length);
109+
status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, data, data_length);
110110
}
111111
flash_disable();
112112
return status;
@@ -122,10 +122,10 @@ bool spi_flash_read_data(uint32_t address, uint8_t* data, uint32_t data_length)
122122
// Write the SPI flash write address into the bytes following the command byte.
123123
address_to_bytes(address, request + 1);
124124
flash_enable();
125-
common_hal_busio_spi_configure(&spi, spi_flash_baudrate, 0, 0, 8);
126-
bool status = common_hal_busio_spi_write(&spi, request, command_length);
125+
common_hal_busio_spi_configure(&supervisor_flash_spi_bus, spi_flash_baudrate, 0, 0, 8);
126+
bool status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, request, command_length);
127127
if (status) {
128-
status = common_hal_busio_spi_read(&spi, data, data_length, 0xff);
128+
status = common_hal_busio_spi_read(&supervisor_flash_spi_bus, data, data_length, 0xff);
129129
}
130130
flash_disable();
131131
return status;
@@ -140,9 +140,9 @@ void spi_flash_init(void) {
140140
common_hal_digitalio_digitalinout_switch_to_output(&cs_pin, true, DRIVE_MODE_PUSH_PULL);
141141
common_hal_digitalio_digitalinout_never_reset(&cs_pin);
142142

143-
spi.base.type = &busio_spi_type;
144-
common_hal_busio_spi_construct(&spi, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN);
145-
common_hal_busio_spi_never_reset(&spi);
143+
supervisor_flash_spi_bus.base.type = &busio_spi_type;
144+
common_hal_busio_spi_construct(&supervisor_flash_spi_bus, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN);
145+
common_hal_busio_spi_never_reset(&supervisor_flash_spi_bus);
146146
}
147147

148148
void spi_flash_init_device(const external_flash_device* device) {

supervisor/spi_flash_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#include "shared-bindings/busio/SPI.h"
3535

36-
extern busio_spi_obj_t spi; //Used to share SPI bus on some boards
36+
extern busio_spi_obj_t supervisor_flash_spi_bus; //Used to share SPI bus on some boards
3737

3838
// This API is implemented for both normal SPI peripherals and QSPI peripherals.
3939

0 commit comments

Comments
 (0)