Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
4e29dce3
Commit
4e29dce3
authored
8 years ago
by
Hauke Petersen
Browse files
Options
Downloads
Patches
Plain Diff
cpu/samd0: added flashpage driver implemenation
parent
25d90972
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cpu/sam0_common/include/cpu_conf.h
+10
-0
10 additions, 0 deletions
cpu/sam0_common/include/cpu_conf.h
cpu/sam0_common/periph/flashpage.c
+62
-0
62 additions, 0 deletions
cpu/sam0_common/periph/flashpage.c
with
72 additions
and
0 deletions
cpu/sam0_common/include/cpu_conf.h
+
10
−
0
View file @
4e29dce3
...
@@ -36,6 +36,16 @@ extern "C" {
...
@@ -36,6 +36,16 @@ extern "C" {
#define CPU_FLASH_BASE FLASH_ADDR
#define CPU_FLASH_BASE FLASH_ADDR
/** @} */
/** @} */
/**
* @brief Flash page configuration
* @{
*/
/* a flashpage in RIOT is mapped to a flash row on the SAM0s */
#define FLASHPAGE_SIZE (256U)
/* one SAM0 row contains 4 SAM0 pages -> 4x the amount of RIOT flashpages */
#define FLASHPAGE_NUMOF (FLASH_NB_OF_PAGES / 4)
/** @} */
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
This diff is collapsed.
Click to expand it.
cpu/sam0_common/periph/flashpage.c
0 → 100644
+
62
−
0
View file @
4e29dce3
/*
* Copyright (C) 2016 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup cpu_sam0_common
* @{
*
* @file
* @brief Low-level flash page driver implementation
*
* The sam0 has its flash memory organized in pages and rows, where each row
* consists of 4 pages. While pages are writable one at a time, it is only
* possible to delete a complete row. This implementation abstracts this
* behavior by only writing complete rows at a time, so the FLASH_PAGE_SIZE we
* use in RIOT is actually the row size as specified in the datasheet.
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include
"cpu.h"
#include
"assert.h"
#include
"periph/flashpage.h"
#define NVMCTRL_PAC_BIT (0x00000002)
void
flashpage_write
(
int
page
,
void
*
data
)
{
assert
(
page
<
FLASHPAGE_NUMOF
);
uint32_t
*
page_addr
=
(
uint32_t
*
)
flashpage_addr
(
page
);
/* remove peripheral access lock for the NVMCTRL peripheral */
#ifdef CPU_FAM_SAML21
PAC
->
WRCTRL
.
reg
=
(
PAC_WRCTRL_KEY_CLR
|
ID_NVMCTRL
);
#else
if
(
PAC1
->
WPSET
.
reg
&
NVMCTRL_PAC_BIT
)
{
PAC1
->
WPCLR
.
reg
=
NVMCTRL_PAC_BIT
;
}
#endif
/* erase given page (the ADDR register uses 16-bit addresses) */
NVMCTRL
->
ADDR
.
reg
=
(((
uint32_t
)
page_addr
)
>>
1
);
NVMCTRL
->
CTRLA
.
reg
=
(
NVMCTRL_CTRLA_CMDEX_KEY
|
NVMCTRL_CTRLA_CMD_ER
);
while
(
!
(
NVMCTRL
->
INTFLAG
.
reg
&
NVMCTRL_INTFLAG_READY
))
{}
/* write data to page */
if
(
data
!=
NULL
)
{
uint32_t
*
data_addr
=
(
uint32_t
*
)
data
;
NVMCTRL
->
CTRLA
.
reg
=
(
NVMCTRL_CTRLA_CMDEX_KEY
|
NVMCTRL_CTRLA_CMD_PBC
);
for
(
unsigned
i
=
0
;
i
<
(
FLASHPAGE_SIZE
/
4
);
i
++
)
{
*
page_addr
++
=
data_addr
[
i
];
}
NVMCTRL
->
CTRLA
.
reg
=
(
NVMCTRL_CTRLA_CMDEX_KEY
|
NVMCTRL_CTRLA_CMD_WP
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment