2016-04-20 10:23:48 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 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 tests
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Manual test application for UART peripheral drivers
|
|
|
|
*
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "shell.h"
|
|
|
|
#include "periph/flashpage.h"
|
|
|
|
|
|
|
|
#define LINE_LEN (16)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Allocate space for 1 flash page in RAM
|
|
|
|
*/
|
|
|
|
static uint8_t page_mem[FLASHPAGE_SIZE];
|
|
|
|
|
2017-11-09 01:59:02 +01:00
|
|
|
#ifdef MODULE_PERIPH_FLASHPAGE_RAW
|
|
|
|
/*
|
|
|
|
* @brief Allocate an aligned buffer for raw writings
|
|
|
|
*/
|
|
|
|
static char raw_buf[64] __attribute__ ((aligned (FLASHPAGE_RAW_ALIGNMENT)));
|
|
|
|
|
|
|
|
static uint32_t getaddr(const char *str)
|
|
|
|
{
|
|
|
|
uint32_t addr = strtol(str, NULL, 16);
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-04-20 10:23:48 +02:00
|
|
|
static int getpage(const char *str)
|
|
|
|
{
|
|
|
|
int page = atoi(str);
|
make: fix sign-compare errors
cpu, nrf5x_common: fix sign-compare in periph/flashpage
drivers, periph_common: fix sign-compare in flashpage
cpu, sam0_common: fix sign-compare error in periph/gpio
cpu, cc2538: fix sign-compare in periph/timer
cpu, sam3: fix sign-compare in periph/gpio
cpu, stm32_common: fix sign-compare in periph/pwm
cpu, stm32_common: fix sign-compare in periph/timer
cpu, stm32_common: fix sign-compare in periph/flashpage
cpu, nrf5x_common: fix sign-compare in radio/nrfmin
cpu, samd21: fix sign-compare in periph/pwm
cpu, ezr32wg: fix sign-compare in periph/gpio
cpu, ezr32wg: fix sign-compare in periph/timer
drivers, ethos: fix sign-compare
sys, net: fix sign-compare
cpu, atmega_common: fix sign-compare error
cpu, msp430fxyz: fix sign-compare in periph/gpio
boards, msb-430-common: fix sign-compare in board_init
driver, cc2420: fix sign-compared
sys/net: fix sign-compare in gnrc_tftp
driver, pcd8544: fix sign-compare
driver, pn532: fix sign-compare
driver, sdcard_spi: fix sign-compare
tests: fix sign_compare
sys/net, lwmac: fix sign_compare
pkg, lwip: fix sign-compare
boards, waspmote: make CORECLOCK unsigned long to fix sign_compare error
tests, sock_ip: fix sign compare
tests, msg_avail: fix sign compare
tests, sock_udp: fix sign compare
boards: fix sign-compare for calliope and microbit matrix
2017-10-31 11:57:40 +01:00
|
|
|
if ((page >= (int)FLASHPAGE_NUMOF) || (page < 0)) {
|
2016-04-20 10:23:48 +02:00
|
|
|
printf("error: page %i is invalid\n", page);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dumpchar(uint8_t mem)
|
|
|
|
{
|
|
|
|
if (mem >= ' ' && mem <= '~') {
|
|
|
|
printf(" %c ", mem);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf(" ?? ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void memdump(void *addr, size_t len)
|
|
|
|
{
|
|
|
|
unsigned pos = 0;
|
|
|
|
uint8_t *mem = (uint8_t *)addr;
|
|
|
|
|
|
|
|
while (pos < (unsigned)len) {
|
|
|
|
for (unsigned i = 0; i < LINE_LEN; i++) {
|
|
|
|
printf("0x%02x ", mem[pos + i]);
|
|
|
|
}
|
|
|
|
puts("");
|
|
|
|
for (unsigned i = 0; i < LINE_LEN; i++) {
|
|
|
|
dumpchar(mem[pos++]);
|
|
|
|
}
|
|
|
|
puts("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_local(void)
|
|
|
|
{
|
|
|
|
puts("Local page buffer:");
|
|
|
|
memdump(page_mem, FLASHPAGE_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_info(int argc, char **argv)
|
|
|
|
{
|
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
|
|
|
|
printf("Flash start addr:\t0x%08x\n", (int)CPU_FLASH_BASE);
|
|
|
|
printf("Page size:\t\t%i\n", (int)FLASHPAGE_SIZE);
|
|
|
|
printf("Number of pages:\t%i\n", (int)FLASHPAGE_NUMOF);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_dump(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int page;
|
|
|
|
void *addr;
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
printf("usage: %s <page>\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
page = getpage(argv[1]);
|
|
|
|
if (page < 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
addr = flashpage_addr(page);
|
|
|
|
|
|
|
|
printf("Flash page %i at address %p\n", page, addr);
|
|
|
|
memdump(addr, FLASHPAGE_SIZE);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_dump_local(int argc, char **argv)
|
|
|
|
{
|
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
|
|
|
|
dump_local();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_read(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int page;
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
printf("usage: %s <page>\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
page = getpage(argv[1]);
|
|
|
|
if (page < 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
flashpage_read(page, page_mem);
|
|
|
|
printf("Read flash page %i into local page buffer\n", page);
|
|
|
|
dump_local();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_write(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int page;
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
printf("usage: %s <page>\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
page = getpage(argv[1]);
|
|
|
|
if (page < 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flashpage_write_and_verify(page, page_mem) != FLASHPAGE_OK) {
|
|
|
|
printf("error: verification for page %i failed\n", page);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-03-11 20:35:48 +01:00
|
|
|
printf("wrote local page buffer to flash page %i at addr %p\n",
|
2016-04-20 10:23:48 +02:00
|
|
|
page, flashpage_addr(page));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-09 01:59:02 +01:00
|
|
|
#ifdef MODULE_PERIPH_FLASHPAGE_RAW
|
|
|
|
static int cmd_write_raw(int argc, char **argv)
|
|
|
|
{
|
|
|
|
uint32_t addr;
|
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
printf("usage: %s <addr> <data>\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = getaddr(argv[1]);
|
|
|
|
|
|
|
|
/* try to align */
|
|
|
|
memcpy(raw_buf, argv[2], strlen(argv[2]));
|
|
|
|
|
|
|
|
flashpage_write_raw((void*)addr, raw_buf, strlen(raw_buf));
|
|
|
|
|
|
|
|
printf("wrote local data to flash address %#lx of len %u\n",
|
|
|
|
addr, strlen(raw_buf));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-04-20 10:23:48 +02:00
|
|
|
static int cmd_erase(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int page;
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
printf("usage: %s <page>\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
page = getpage(argv[1]);
|
|
|
|
if (page < 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
flashpage_write(page, NULL);
|
|
|
|
|
|
|
|
printf("successfully erased page %i (addr %p)\n",
|
|
|
|
page, flashpage_addr(page));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_edit(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
size_t data_len;
|
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
printf("usage: %s <offset> <data>\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = atoi(argv[1]);
|
make: fix sign-compare errors
cpu, nrf5x_common: fix sign-compare in periph/flashpage
drivers, periph_common: fix sign-compare in flashpage
cpu, sam0_common: fix sign-compare error in periph/gpio
cpu, cc2538: fix sign-compare in periph/timer
cpu, sam3: fix sign-compare in periph/gpio
cpu, stm32_common: fix sign-compare in periph/pwm
cpu, stm32_common: fix sign-compare in periph/timer
cpu, stm32_common: fix sign-compare in periph/flashpage
cpu, nrf5x_common: fix sign-compare in radio/nrfmin
cpu, samd21: fix sign-compare in periph/pwm
cpu, ezr32wg: fix sign-compare in periph/gpio
cpu, ezr32wg: fix sign-compare in periph/timer
drivers, ethos: fix sign-compare
sys, net: fix sign-compare
cpu, atmega_common: fix sign-compare error
cpu, msp430fxyz: fix sign-compare in periph/gpio
boards, msb-430-common: fix sign-compare in board_init
driver, cc2420: fix sign-compared
sys/net: fix sign-compare in gnrc_tftp
driver, pcd8544: fix sign-compare
driver, pn532: fix sign-compare
driver, sdcard_spi: fix sign-compare
tests: fix sign_compare
sys/net, lwmac: fix sign_compare
pkg, lwip: fix sign-compare
boards, waspmote: make CORECLOCK unsigned long to fix sign_compare error
tests, sock_ip: fix sign compare
tests, msg_avail: fix sign compare
tests, sock_udp: fix sign compare
boards: fix sign-compare for calliope and microbit matrix
2017-10-31 11:57:40 +01:00
|
|
|
if (offset >= (int)FLASHPAGE_SIZE) {
|
2016-04-20 10:23:48 +02:00
|
|
|
printf("error: given offset is out of bounce\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
data_len = strlen(argv[2]);
|
|
|
|
if ((data_len + offset) > FLASHPAGE_SIZE) {
|
|
|
|
data_len = FLASHPAGE_SIZE - offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&page_mem[offset], argv[2], data_len);
|
|
|
|
dump_local();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_test(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int page;
|
|
|
|
char fill = 'a';
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
printf("usage: %s <page>\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
page = getpage(argv[1]);
|
|
|
|
if (page < 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
make: fix sign-compare errors
cpu, nrf5x_common: fix sign-compare in periph/flashpage
drivers, periph_common: fix sign-compare in flashpage
cpu, sam0_common: fix sign-compare error in periph/gpio
cpu, cc2538: fix sign-compare in periph/timer
cpu, sam3: fix sign-compare in periph/gpio
cpu, stm32_common: fix sign-compare in periph/pwm
cpu, stm32_common: fix sign-compare in periph/timer
cpu, stm32_common: fix sign-compare in periph/flashpage
cpu, nrf5x_common: fix sign-compare in radio/nrfmin
cpu, samd21: fix sign-compare in periph/pwm
cpu, ezr32wg: fix sign-compare in periph/gpio
cpu, ezr32wg: fix sign-compare in periph/timer
drivers, ethos: fix sign-compare
sys, net: fix sign-compare
cpu, atmega_common: fix sign-compare error
cpu, msp430fxyz: fix sign-compare in periph/gpio
boards, msb-430-common: fix sign-compare in board_init
driver, cc2420: fix sign-compared
sys/net: fix sign-compare in gnrc_tftp
driver, pcd8544: fix sign-compare
driver, pn532: fix sign-compare
driver, sdcard_spi: fix sign-compare
tests: fix sign_compare
sys/net, lwmac: fix sign_compare
pkg, lwip: fix sign-compare
boards, waspmote: make CORECLOCK unsigned long to fix sign_compare error
tests, sock_ip: fix sign compare
tests, msg_avail: fix sign compare
tests, sock_udp: fix sign compare
boards: fix sign-compare for calliope and microbit matrix
2017-10-31 11:57:40 +01:00
|
|
|
for (unsigned i = 0; i < sizeof(page_mem); i++) {
|
2016-04-20 10:23:48 +02:00
|
|
|
page_mem[i] = (uint8_t)fill++;
|
|
|
|
if (fill > 'z') {
|
|
|
|
fill = 'a';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flashpage_write_and_verify(page, page_mem) != FLASHPAGE_OK) {
|
2018-03-11 20:35:48 +01:00
|
|
|
printf("error verifying the content of page %i\n", page);
|
2016-04-20 10:23:48 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-03-11 20:35:48 +01:00
|
|
|
printf("wrote local page buffer to flash page %i at addr %p\n",
|
2016-04-20 10:23:48 +02:00
|
|
|
page, flashpage_addr(page));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const shell_command_t shell_commands[] = {
|
|
|
|
{ "info", "Show information about pages", cmd_info },
|
|
|
|
{ "dump", "Dump the selected page to STDOUT", cmd_dump },
|
|
|
|
{ "dump_local", "Dump the local page buffer to STDOUT", cmd_dump_local },
|
2018-03-11 20:35:48 +01:00
|
|
|
{ "read", "Copy the given page to the local page buffer and dump to STDOUT", cmd_read },
|
|
|
|
{ "write", "Write the local page buffer to the given page", cmd_write },
|
2017-11-09 01:59:02 +01:00
|
|
|
#ifdef MODULE_PERIPH_FLASHPAGE_RAW
|
|
|
|
{ "write_raw", "Write (ASCII, max 64B) data to the given address", cmd_write_raw },
|
|
|
|
#endif
|
2018-03-11 20:35:48 +01:00
|
|
|
{ "erase", "Erase the given page buffer", cmd_erase },
|
|
|
|
{ "edit", "Write bytes to the local page buffer", cmd_edit },
|
2016-04-20 10:23:48 +02:00
|
|
|
{ "test", "Write and verify test pattern", cmd_test },
|
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
puts("ROM flash read write test\n");
|
|
|
|
puts("Please refer to the README.md for further information\n");
|
|
|
|
|
|
|
|
cmd_info(0, NULL);
|
|
|
|
|
|
|
|
/* run the shell */
|
|
|
|
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
|
|
|
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
|
|
|
|
return 0;
|
|
|
|
}
|