avr_eeprom(3)

πŸ“¦ version 2.2.1, in fedora 43, fedora 44, opensuse-leap 16.0

πŸ’– avr_eeprom(3) β€” avr-libc but make it make sense πŸ’–

hiii bestie 🫢 welcome to avr_eeprom(3), one of the pages from the avr-libc manual, except now it's explained by someone who actually loves you and wants you to pass your embedded class. this is the whole interface for poking at the EEPROM inside AVR microcontrollers. no cap, it's short, it's sweet, and every single detail is still in here. let's go ✨


πŸŽ€ NAME πŸŽ€

avr_eeprom


🌸 SYNOPSIS 🌸

🧚 Macros

#define EEMEM   __attribute__((section('.eeprom')))
#define eeprom_is_ready()
#define eeprom_busy_wait()   do {} while (!eeprom_is_ready())

πŸ¦‹ Functions

uint8_t eeprom_read_byte (const uint8_t *__p) __ATTR_PURE__
uint16_t eeprom_read_word (const uint16_t *__p) __ATTR_PURE__
uint32_t eeprom_read_dword (const uint32_t *__p) __ATTR_PURE__
float eeprom_read_float (const float *__p) __ATTR_PURE__
void eeprom_read_block (void *__dst, const void *__src, size_t __n)
void eeprom_write_byte (uint8_t *__p, uint8_t __value)
void eeprom_write_word (uint16_t *__p, uint16_t __value)
void eeprom_write_dword (uint32_t *__p, uint32_t __value)
void eeprom_write_float (float *__p, float __value)
void eeprom_write_block (const void *__src, void *__dst, size_t __n)
void eeprom_update_byte (uint8_t *__p, uint8_t __value)
void eeprom_update_word (uint16_t *__p, uint16_t __value)
void eeprom_update_dword (uint32_t *__p, uint32_t __value)
void eeprom_update_float (float *__p, float __value)
void eeprom_update_block (const void *__src, void *__dst, size_t __n)

πŸ’œ IAR C compatibility defines

#define _EEPUT(addr,  val)   eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val))
#define __EEPUT(addr,  val)   eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val))
#define _EEGET(var,  addr)   (var) = eeprom_read_byte ((const uint8_t *)(addr))
#define __EEGET(var,  addr)   (var) = eeprom_read_byte ((const uint8_t *)(addr))

✨ Detailed Description ✨

#include <avr/eeprom.h>

so like. this header declares the interface to some simple library routines that handle the data EEPROM inside AVR microcontrollers. the implementation is a simple polled mode interface, periodt. if your app needs interrupt-controlled EEPROM access so that literally no time gets wasted spinning in loops, you're gonna have to deploy your own implementation, bestie. that's on you πŸ’…

Notes, and please actually read these:

  • In addition to the write functions there's a whole set of update ones. these functions read each byte first and skip the burning if the old value is the same as the new one. the scaning direction is from high address to low, to obtain quick return in common cases. iconic behavior honestly πŸŽ€
  • All of the read/write functions first make sure the EEPROM is ready to be accessed. since this may cause long delays if a write operation is still pending, time-critical applications should first poll the EEPROM e.g. using eeprom_is_ready() before attempting any actual I/O. but these functions do not wait until SELFPRGEN in SPMCSR becomes zero. do this manually if your softwate contains the Flash burning. yes that's how it's spelled, i don't make the rules 😭
  • As these functions modify IO registers, they are known to be non-reentrant. if any of these functions are used from both standard and interrupt context, the applications must ensure proper protection (e.g. by disabling interrupts before accessing them). do not skip this, i'm begging 🫢
  • All write functions force erase_and_write programming mode. slay i guess ✨
  • For Xmega the EEPROM start address is 0, like other architectures. the reading functions add the 0x2000 value to use EEPROM mapping into data space. noted πŸ’œ

πŸ“ Macro Definition Documentation πŸ“

#define __EEGET(var, addr) (var) = eeprom_read_byte ((const uint8_t *)(addr))

Read a byte from EEPROM. Compatibility define for IAR C.

#define __EEPUT(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val))

Write a byte to EEPROM. Compatibility define for IAR C.

#define _EEGET(var, addr) (var) = eeprom_read_byte ((const uint8_t *)(addr))

Read a byte from EEPROM. Compatibility define for IAR C.

#define _EEPUT(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val))

Write a byte to EEPROM. Compatibility define for IAR C.

#define EEMEM __attribute__((section('.eeprom')))

An attribute expression that causes a variable to be allocated within the .eeprom section. this is the one that lets you park your variables in EEPROM land instead of RAM, chef's kiss πŸ‘‘

#define eeprom_busy_wait() do {} while (!eeprom_is_ready())

Loops until the eeprom is no longer busy. it just... sits there. patiently. living its truth πŸ¦‹

Returns: Nothing. literally nothing. it returns nothing, bestie πŸ’€

#define eeprom_is_ready()

Returns: 1 if EEPROM is ready for a new read/write operation, 0 if not. vibe check for your EEPROM, fr fr βœ…


🌈 Function Documentation 🌈

void eeprom_read_block (void * __dst, const void * __src, size_t __n)

Read a block of __n bytes from EEPROM address __src to SRAM __dst.

uint8_t eeprom_read_byte (const uint8_t * __p)

Read one byte from EEPROM address __p.

uint32_t eeprom_read_dword (const uint32_t * __p)

Read one 32-bit double word (little endian) from EEPROM address __p.

float eeprom_read_float (const float * __p)

Read one float value (little endian) from EEPROM address __p.

uint16_t eeprom_read_word (const uint16_t * __p)

Read one 16-bit word (little endian) from EEPROM address __p.

void eeprom_update_block (const void * __src, void * __dst, size_t __n)

Update a block of __n bytes to EEPROM address __dst from __src.

Note: the argument order is mismatch with common functions like strcpy(). yes really. read it twice. i said what i said 😭

void eeprom_update_byte (uint8_t * __p, uint8_t __value)

Update a byte __value to EEPROM address __p.

void eeprom_update_dword (uint32_t * __p, uint32_t __value)

Update a 32-bit double word __value to EEPROM address __p.

void eeprom_update_float (float * __p, float __value)

Update a float __value to EEPROM address __p.

void eeprom_update_word (uint16_t * __p, uint16_t __value)

Update a word __value to EEPROM address __p.

void eeprom_write_block (const void * __src, void * __dst, size_t __n)

Write a block of __n bytes to EEPROM address __dst from __src.

Note: the argument order is mismatch with common functions like strcpy(). same warning, same energy, pay attention bestie πŸ’…

void eeprom_write_byte (uint8_t * __p, uint8_t __value)

Write a byte __value to EEPROM address __p.

void eeprom_write_dword (uint32_t * __p, uint32_t __value)

Write a 32-bit double word __value to EEPROM address __p.

void eeprom_write_float (float * __p, float __value)

Write a float __value to EEPROM address __p.

void eeprom_write_word (uint16_t * __p, uint16_t __value)

Write a word __value to EEPROM address __p.


πŸ‘‘ Author πŸ‘‘

Generated automatically by Doxygen for avr-libc from the source code. not a human, not a bestie, just a robot doing its little robot thing πŸ€–βœ¨


okay that's the whole page, you ate that 🫢 go write something to EEPROM and remember to poll first, mwah πŸ’‹

Version 2.1.0 β€” Sat Jan 29 2022 β€” avr_eeprom(3) πŸ’– that's the version and the date, from the footer of the original page, so you know exactly which glow-up era this manual is from. periodt. 🌸

πŸ“¦ where this page comes from