Implement EEPROM bytewise read/write
This commit is contained in:
41
Core/Inc/EEPROM.h
Normal file
41
Core/Inc/EEPROM.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef INC_EEPROM_H_
|
||||
#define INC_EEPROM_H_
|
||||
|
||||
#include "stm32f4xx_hal.h"
|
||||
#include "stm32f4xx_hal_def.h"
|
||||
|
||||
#define EEPROM_BASE_ADDR 0b1010000
|
||||
// Device address must be shifted left before being passed to the HAL
|
||||
#define EEPROM_DEV_ADDR (EEPROM_BASE_ADDR << 1)
|
||||
#define EEPROM_TIMEOUT 200 /* ms */
|
||||
#define EEPROM_READ_TRIES 5
|
||||
|
||||
#define EEPROM_ADDR_SLAVE_ID 0x000
|
||||
|
||||
typedef enum { EEPROM_OFF, EEPROM_READY, EEPROM_ERROR } EEPROM_State;
|
||||
extern EEPROM_State eeprom_state;
|
||||
|
||||
void eeprom_init(I2C_HandleTypeDef* handle);
|
||||
|
||||
/**
|
||||
* @brief Write a byte to the EEPROM.
|
||||
*
|
||||
* @param addr 9-bit address (1 bit page select + 8 bit address)
|
||||
* @param data The byte to write
|
||||
*/
|
||||
HAL_StatusTypeDef eeprom_write(uint16_t addr, uint8_t data);
|
||||
/**
|
||||
* @brief Read a byte from the next address in the EEPROM.
|
||||
*
|
||||
* @param data 1-byte buffer into which the read byte is written.
|
||||
*/
|
||||
HAL_StatusTypeDef eeprom_read_curr(uint8_t* data);
|
||||
/**
|
||||
* @brief Read a byte from the EEPROM (random-access).
|
||||
*
|
||||
* @param addr 9-bit address (1 bit page select + 8 bit address)
|
||||
* @param data 1-byte buffer into which the read byte is written.
|
||||
*/
|
||||
HAL_StatusTypeDef eeprom_read_random(uint16_t addr, uint8_t* data);
|
||||
|
||||
#endif // INC_EEPROM_H_
|
||||
@ -57,6 +57,7 @@ void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
void CAN1_RX0_IRQHandler(void);
|
||||
void CAN1_RX1_IRQHandler(void);
|
||||
void I2C1_EV_IRQHandler(void);
|
||||
void USART1_IRQHandler(void);
|
||||
void USART3_IRQHandler(void);
|
||||
void CAN2_RX0_IRQHandler(void);
|
||||
|
||||
Reference in New Issue
Block a user