mirror of
https://github.com/micropython/micropython.git
synced 2025-09-07 02:10:52 +02:00
The PYBD boards use an F7xx which has an errata 2.4.3: Memory-mapped read operations may fail when timeout counter is enabled This is unfortunate because it means that once QSPI memory-mapped flash is accessed the QSPI peripheral will leave the CS pin active (low) forever, which increases power consumption of the SPI flash chip (because it's active and waiting for commands). The exact amount of power increase depends on the flash, but the PYBD_SFx increase by about 2.5mA. Previously this increase in power only happened when QSPI flash was needed, eg on PYBD_SF2 when mbedtls or nimble libraries were used. On PYBD_SF6 it's actually never used. But with the introduction of ROMFS which lives in the QSPI flash, the memory is always access on start up to see if the ROMFS contains a valid image (it must read the memory to find out). That means these boards always consume about 2.5mA more after starting up (compared to when ROMFS is disabled). The fix in this commit is to explicitly restart the QSPI memory mapped mode during the start up process. More precisely, the restart is done after querying the ROMFS and just before trying to execute `boot.py`. That's the right location to keep power consumption permanently down if the QSPI is never used (eg ROMFS image doesn't exist). Signed-off-by: Damien George <damien@micropython.org>
100 lines
3.3 KiB
C
100 lines
3.3 KiB
C
/*
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
*
|
|
* The MIT License (MIT)
|
|
*
|
|
* Copyright (c) 2018-2019 Damien P. George
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include "py/mphal.h"
|
|
#include "storage.h"
|
|
|
|
#if defined(STM32F722xx) || defined(STM32F723xx) || defined(STM32F732xx) || defined(STM32F733xx)
|
|
#define OTP_ADDR (0x1ff079e0)
|
|
#else
|
|
#define OTP_ADDR (0x1ff0f3c0)
|
|
#endif
|
|
#define OTP ((pyb_otp_t *)OTP_ADDR)
|
|
|
|
typedef struct _pyb_otp_t {
|
|
uint16_t series;
|
|
uint16_t rev;
|
|
uint8_t mac[6];
|
|
} pyb_otp_t;
|
|
|
|
void mboot_board_early_init(void) {
|
|
// Enable 500mA on WBUS-DIP28
|
|
mp_hal_pin_config(pyb_pin_W23, MP_HAL_PIN_MODE_INPUT, MP_HAL_PIN_PULL_UP, 0);
|
|
|
|
#if defined(MBOOT_SDCARD_ADDR)
|
|
// Configure EN_3V3 as an output pin so that SD card can be used
|
|
mp_hal_pin_config(pyb_pin_EN_3V3, MP_HAL_PIN_MODE_OUTPUT, MP_HAL_PIN_PULL_NONE, 0);
|
|
#endif
|
|
}
|
|
|
|
void board_early_init(void) {
|
|
// Configure EN_3V3 as an output pin, but keep it turned off
|
|
mp_hal_pin_config(pyb_pin_EN_3V3, MP_HAL_PIN_MODE_OUTPUT, MP_HAL_PIN_PULL_NONE, 0);
|
|
|
|
// Explicitly init SPI2 because it's not enabled as a block device
|
|
spi_bdev_ioctl(&spi_bdev2, BDEV_IOCTL_INIT, (uint32_t)&spiflash2_config);
|
|
}
|
|
|
|
#if !BUILDING_MBOOT
|
|
|
|
#include "boardctrl.h"
|
|
#include "qspi.h"
|
|
|
|
int board_run_boot_py(boardctrl_state_t *state) {
|
|
// Due to errata 2.4.3, restart memory-mapped mode to deactivate the CS line and save power.
|
|
qspi_memory_map_restart();
|
|
|
|
return boardctrl_run_boot_py(state);
|
|
}
|
|
|
|
void board_sleep(int value) {
|
|
mp_spiflash_deepsleep(&spi_bdev.spiflash, value);
|
|
mp_spiflash_deepsleep(&spi_bdev2.spiflash, value);
|
|
}
|
|
|
|
void mp_hal_get_mac(int idx, uint8_t buf[6]) {
|
|
// Check if OTP region has a valid MAC address, and use it if it does
|
|
if (OTP->series == 0x00d1 && OTP->mac[0] == 'H' && OTP->mac[1] == 'J' && OTP->mac[2] == '0') {
|
|
#if __GNUC__ >= 11
|
|
#pragma GCC diagnostic push
|
|
#pragma GCC diagnostic ignored "-Warray-bounds"
|
|
#pragma GCC diagnostic ignored "-Wstringop-overread"
|
|
#endif
|
|
memcpy(buf, OTP->mac, 6);
|
|
#if __GNUC__ >= 11
|
|
#pragma GCC diagnostic pop
|
|
#endif
|
|
buf[5] += idx;
|
|
return;
|
|
}
|
|
|
|
// Generate a random locally administered MAC address (LAA)
|
|
mp_hal_generate_laa_mac(idx, buf);
|
|
}
|
|
|
|
#endif
|