X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fstm32f1%2Fao_eeprom.c;fp=src%2Fstm32f1%2Fao_eeprom.c;h=ec6654d50418877a5166685b99941b98dba36545;hb=1311eba0bbe32bc1759a3b11b00c78774843383c;hp=0000000000000000000000000000000000000000;hpb=7b2588ee723827b9be2a2d5f287afb1b5d351b23;p=fw%2Faltos diff --git a/src/stm32f1/ao_eeprom.c b/src/stm32f1/ao_eeprom.c new file mode 100644 index 00000000..ec6654d5 --- /dev/null +++ b/src/stm32f1/ao_eeprom.c @@ -0,0 +1,50 @@ +/* + * Copyright © 2024 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include +#include + +extern uint8_t __eeprom_base[2048]; + +uint8_t +ao_eeprom_read(ao_pos_t pos, void *v, uint16_t len) +{ + memcpy(v, &__eeprom_base[pos], len); + return 1; +} + +uint8_t +ao_eeprom_write(ao_pos_t pos, void *v, uint16_t len) +{ + bool hsi_on = (stm_rcc.cr & (1UL << STM_RCC_CR_HSIRDY)) != 0; + + if (!hsi_on) { + stm_rcc.cr |= (1UL << STM_RCC_CR_HSION); + while (!(stm_rcc.cr & (1 << STM_RCC_CR_HSIRDY))) + ao_arch_nop(); + + } + ao_flash_bytes(&__eeprom_base[pos], v, len); + + if (!hsi_on) { + stm_rcc.cr &= ~(1UL << STM_RCC_CR_HSION); + } + + return 1; +} +