-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reference/machine: added eeprom reference and machine docs #317
Open
SoleimanyBen
wants to merge
4
commits into
tinygo-org:dev
Choose a base branch
from
SoleimanyBen:eeprom-doc
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
df26e5c
getting-started: remove xtensa-esp32-elf requirement
aykevl 338127f
microcontrollers: remove esp32 toolchain installation instructions
aykevl ab71d28
compiler-internals: remove `-wasm-abi=generic` flag
aykevl 4ec3e72
reference/machine: added eeprom reference and machine docs
SoleimanyBen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
title: "EEPROM" | ||
weight: 3 | ||
description: | | ||
How to use the internal EEPROM. | ||
--- | ||
|
||
For API documentation, see the [machine API](../../../reference/machine#eeprom). | ||
|
||
The EEPROM is a form of non-volatile memory that is uusually integrated along side an MCU. EEPROMs allows you to store a relatively small amount of data by allowing bytes to be erased and reprogrammed. For the most part, EEPROMs are not integrated directly onto a board, but in some cases they are provided as a standard peripheral. | ||
|
||
Although it may seem useful to have some type of data storage for your applications, the EEPROM is often limited in the amount of write cycles that it contains. This means that after a certain amount of writes, the EEPROM will not writeable, but you may still read data from it. | ||
|
||
## Controlling the EEPROM | ||
|
||
Control of the EEPROM has been simplified through the `EEPROM` variable that can be accessed through the `machine` package. | ||
|
||
Unlike most peripherals within TinyGo, you do not need to configure the EEPROM to use it. | ||
|
||
Example usage of the EEPROM can be seen below. | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"machine" | ||
"time" | ||
) | ||
|
||
// Address of the data to be stored. | ||
// Addresses can be either in hex or dec. | ||
const DataAddr = 0x10 | ||
|
||
|
||
func main() { | ||
eeprom := machine.EEPROM0 // the onboard EEPROM | ||
|
||
_, err := eeprom.WriteAt([]byte("Hello, World!"), DataAddr) | ||
if err != nil{ | ||
panic(err) | ||
} | ||
|
||
// Create a buffer to read the data into | ||
// We need to define a buffer with the correct size of the bytes we want to read. | ||
buf := make([]byte, len("Hello, World!")) | ||
_, err := eeprom.ReadAt(buf, DataAddr) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(buf) // Hello, World! | ||
} | ||
``` | ||
|
||
This example will store a value, `Hello, World!`, into the address `0x10`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EEPROMs are almost always included directly on the chip, I think?
Also, here is a suggestion for the text: