Start implementation of option byte manipulation
This commit is contained in:
parent
4009a2794d
commit
decb484d06
45
stm-firmware/include/stm-periph/option-bytes.h
Normal file
45
stm-firmware/include/stm-periph/option-bytes.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* Reflow Oven Controller
|
||||
*
|
||||
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
||||
*
|
||||
* This file is part of the Reflow Oven Controller Project.
|
||||
*
|
||||
* The reflow oven controller is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* GDSII-Converter 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 the reflow oven controller project.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _OPTION_BYTES_H_
|
||||
#define _OPTION_BYTES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct option_bytes {
|
||||
/* Word 1 */
|
||||
uint32_t read_protection;// : 8;
|
||||
uint32_t nrst_standby;// : 1;
|
||||
uint32_t nrst_stop;// : 1;
|
||||
uint32_t wdg_sw;// : 1;
|
||||
uint32_t brown_out_level;// : 2;
|
||||
/* Word 2 */
|
||||
uint32_t nwrpi;// : 12;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Read out the option bytes to structs
|
||||
* @param opts
|
||||
*/
|
||||
void stm_option_bytes_read(struct option_bytes *opts);
|
||||
|
||||
int stm_option_bytes_program(const struct option_bytes *opts);
|
||||
|
||||
#endif /* _OPTION_BYTES_H_ */
|
48
stm-firmware/stm-periph/option-bytes.c
Normal file
48
stm-firmware/stm-periph/option-bytes.c
Normal file
@ -0,0 +1,48 @@
|
||||
/* Reflow Oven Controller
|
||||
*
|
||||
* Copyright (C) 2021 Mario Hüttel <mario.huettel@gmx.net>
|
||||
*
|
||||
* This file is part of the Reflow Oven Controller Project.
|
||||
*
|
||||
* The reflow oven controller is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* The Reflow Oven Control Firmware 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 the reflow oven controller project.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stm-periph/option-bytes.h>
|
||||
#include <stm32/stm32f4xx.h>
|
||||
|
||||
void stm_option_bytes_read(struct option_bytes *opts)
|
||||
{
|
||||
uint32_t opt_reg;
|
||||
|
||||
if (!opts)
|
||||
return;
|
||||
|
||||
opt_reg = FLASH->OPTCR;
|
||||
opts->brown_out_level = (opt_reg & FLASH_OPTCR_BOR_LEV) >> 2;
|
||||
opts->nrst_standby = (opt_reg & FLASH_OPTCR_nRST_STDBY) >> 7;
|
||||
opts->nrst_stop = (opt_reg & FLASH_OPTCR_nRST_STOP) >> 6;
|
||||
opts->nwrpi = (opt_reg & FLASH_OPTCR_nWRP) >> 16;
|
||||
opts->read_protection = (opt_reg & FLASH_OPTCR_RDP) >> 8;
|
||||
opts->wdg_sw = (opt_reg & FLASH_OPTCR_WDG_SW) >> 5;
|
||||
}
|
||||
|
||||
int stm_option_bytes_program(const struct option_bytes *opts)
|
||||
{
|
||||
FLASH->OPTKEYR = 0x08192A3BUL;
|
||||
FLASH->OPTKEYR = 0x4C5D6E7FUL;
|
||||
|
||||
|
||||
FLASH->OPTCR |= FLASH_OPTCR_OPTLOCK;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user