|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2025 Andrew Leech |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | + * of this software and associated documentation files (the "Software"), to deal |
| 10 | + * in the Software without restriction, including without limitation the rights |
| 11 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | + * copies of the Software, and to permit persons to whom the Software is |
| 13 | + * furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be included in |
| 16 | + * all copies or substantial portions of the Software. |
| 17 | + * |
| 18 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | + * THE SOFTWARE. |
| 25 | + */ |
| 26 | + |
| 27 | +#include <string.h> |
| 28 | +#include "py/mphal.h" |
| 29 | +#include "storage.h" |
| 30 | +#include "sdram.h" |
| 31 | + |
| 32 | +void DISCO_board_early_init(void) { |
| 33 | + HAL_InitTick(0); |
| 34 | +} |
| 35 | + |
| 36 | +void DISCO_board_low_power(int mode) { |
| 37 | + switch (mode) { |
| 38 | + case 0: // Leave stop mode. |
| 39 | + sdram_leave_low_power(); |
| 40 | + break; |
| 41 | + case 1: // Enter stop mode. |
| 42 | + sdram_enter_low_power(); |
| 43 | + break; |
| 44 | + case 2: // Enter standby mode. |
| 45 | + sdram_enter_power_down(); |
| 46 | + break; |
| 47 | + } |
| 48 | + |
| 49 | + #if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE == 0 |
| 50 | + // Enable QSPI deepsleep for modes 1 and 2 |
| 51 | + mp_spiflash_deepsleep(&spi_bdev.spiflash, (mode != 0)); |
| 52 | + #endif |
| 53 | + |
| 54 | + #if defined(M4_APP_ADDR) |
| 55 | + // Signal Cortex-M4 to go to Standby mode. |
| 56 | + if (mode == 2) { |
| 57 | + __HAL_RCC_HSEM_CLK_ENABLE(); |
| 58 | + HAL_HSEM_FastTake(0); |
| 59 | + HAL_HSEM_Release(0, 0); |
| 60 | + __HAL_RCC_HSEM_CLK_DISABLE(); |
| 61 | + HAL_Delay(100); |
| 62 | + } |
| 63 | + #endif |
| 64 | +} |
0 commit comments