move custom start up to linker folder
This commit is contained in:
1 parent
49baa7eae4
commit
4950de9ea3
5 files changed
+61
-327
No files matched your search
+14
-1
@@ -25,6 +25,8 @@ NOTICE: This file has been modified by Nordic Semiconductor ASA.
|
||||
.syntax unified
|
||||
.arch armv7e-m
|
||||
|
||||
/* Adafruit define stack & heap inside linker script */
|
||||
/*
|
||||
#ifdef __STARTUP_CONFIG
|
||||
#include "startup_config.h"
|
||||
#ifndef __STARTUP_CONFIG_STACK_ALIGNEMENT
|
||||
@@ -69,7 +71,7 @@ __HeapBase:
|
||||
.size __HeapBase, . - __HeapBase
|
||||
__HeapLimit:
|
||||
.size __HeapLimit, . - __HeapLimit
|
||||
|
||||
*/
|
||||
.section .isr_vector
|
||||
.align 2
|
||||
.globl __isr_vector
|
||||
@@ -243,6 +245,17 @@ Reset_Handler:
|
||||
|
||||
.L_loop1_done:
|
||||
|
||||
|
||||
/* Adafruit fill stack region with pattern 0xADADADAD */
|
||||
ldr r0, =__StackLimit
|
||||
ldr r1, =__StackSize
|
||||
ldr r2, =0xADADADAD
|
||||
.L_fill:
|
||||
str r2, [r0]
|
||||
adds r0, 4
|
||||
subs r1, 4
|
||||
bne .L_fill
|
||||
|
||||
/* This part of work usually is done in C library startup code. Otherwise,
|
||||
* define __STARTUP_CLEAR_BSS to enable it in this startup. This section
|
||||
* clears the RAM where BSS data is located.
|
||||
+13
-2
@@ -24,7 +24,8 @@ NOTICE: This file has been modified by Nordic Semiconductor ASA.
|
||||
|
||||
.syntax unified
|
||||
.arch armv7e-m
|
||||
|
||||
/* Adafruit define stack & heap inside linker script */
|
||||
/*
|
||||
#ifdef __STARTUP_CONFIG
|
||||
#include "startup_config.h"
|
||||
#ifndef __STARTUP_CONFIG_STACK_ALIGNEMENT
|
||||
@@ -69,7 +70,7 @@ __HeapBase:
|
||||
.size __HeapBase, . - __HeapBase
|
||||
__HeapLimit:
|
||||
.size __HeapLimit, . - __HeapLimit
|
||||
|
||||
*/
|
||||
.section .isr_vector
|
||||
.align 2
|
||||
.globl __isr_vector
|
||||
@@ -243,6 +244,16 @@ Reset_Handler:
|
||||
|
||||
.L_loop1_done:
|
||||
|
||||
/* Adafruit fill stack region with pattern 0xADADADAD */
|
||||
ldr r0, =__StackLimit
|
||||
ldr r1, =__StackSize
|
||||
ldr r2, =0xADADADAD
|
||||
.L_fill:
|
||||
str r2, [r0]
|
||||
adds r0, 4
|
||||
subs r1, 4
|
||||
bne .L_fill
|
||||
|
||||
/* This part of work usually is done in C library startup code. Otherwise,
|
||||
* define __STARTUP_CLEAR_BSS to enable it in this startup. This section
|
||||
* clears the RAM where BSS data is located.
|
||||
@@ -60,8 +60,8 @@ PROVIDE(__stack = __StackTop);
|
||||
/* Flash region */
|
||||
__flash_arduino_start = ORIGIN(FLASH);
|
||||
__flash_arduino_end = ORIGIN(FLASH) + LENGTH(FLASH);
|
||||
__flash_bond_start = ORIGIN(FLASH_BOND);
|
||||
|
||||
/* __flash_bond_start = ORIGIN(FLASH_BOND); */
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
@@ -148,26 +148,26 @@ SECTIONS
|
||||
. = ALIGN(4);
|
||||
__bss_end__ = .;
|
||||
} > RAM
|
||||
|
||||
/*.heap (COPY):*/
|
||||
|
||||
.heap :
|
||||
{
|
||||
__HeapBase = .;
|
||||
__end__ = .;
|
||||
PROVIDE(end = .);
|
||||
__HeapBase = .;
|
||||
*(.heap*)
|
||||
KEEP(*(.heap*))
|
||||
. = ALIGN(__StackLimit);
|
||||
__HeapLimit = .;
|
||||
} > RAM
|
||||
|
||||
|
||||
/* .stack section doesn't contains any symbols. It is only
|
||||
* used for linker to calculate size of stack sections */
|
||||
.stack :
|
||||
/* .stack_dummy section doesn't contains any symbols. It is only
|
||||
* used for linker to calculate size of stack sections, and assign
|
||||
* values to stack symbols later */
|
||||
/*
|
||||
.stack_dummy (COPY):
|
||||
{
|
||||
. = ALIGN(__StackLimit);
|
||||
. = ALIGN(__StackTop);
|
||||
KEEP(*(.stack*))
|
||||
} > RAM
|
||||
*/
|
||||
|
||||
/* Check if data + heap + stack exceeds RAM limit */
|
||||
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file nrf52_flash.h
|
||||
@file nffs_port.c
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
@@ -33,28 +33,29 @@
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
#ifndef NRF52_FLASH_H_
|
||||
#define NRF52_FLASH_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <hal/hal_flash_int.h>
|
||||
#include "kernel.h"
|
||||
#include "nffs/nffs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
nffs_os_mempool_t nffs_file_pool = sizeof(struct nffs_file);
|
||||
nffs_os_mempool_t nffs_dir_pool = sizeof(struct nffs_dir);
|
||||
nffs_os_mempool_t nffs_inode_entry_pool = sizeof(struct nffs_inode_entry);
|
||||
nffs_os_mempool_t nffs_block_entry_pool = sizeof(struct nffs_hash_entry);
|
||||
nffs_os_mempool_t nffs_cache_inode_pool = sizeof(struct nffs_cache_inode);
|
||||
nffs_os_mempool_t nffs_cache_block_pool = sizeof(struct nffs_cache_block);
|
||||
|
||||
#define NRF52K_FLASH_SECTOR_SZ 4096
|
||||
int nffs_os_mempool_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// const struct hal_flash* dev is required for nffs flash interface but not used
|
||||
// by nrf52_flash, just simply pass NULL when invoked
|
||||
void* nffs_os_mempool_get(nffs_os_mempool_t *pool)
|
||||
{
|
||||
return pvPortMalloc(*pool);
|
||||
}
|
||||
|
||||
int nrf52_flash_init(const struct hal_flash *dev);
|
||||
int nrf52_flash_erase_sector(const struct hal_flash *dev, uint32_t sector_address);
|
||||
int nrf52_flash_write(const struct hal_flash *dev, uint32_t address, const void *src, uint32_t num_bytes);
|
||||
int nrf52k_flash_read(const struct hal_flash *dev, uint32_t address, void *dst, uint32_t num_bytes);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF52_FLASH_H_ */
|
||||
int nffs_os_mempool_free(nffs_os_mempool_t *pool, void *block)
|
||||
{
|
||||
vPortFree(block);
|
||||
return 0;
|
||||
}
|
||||
-291
@@ -1,291 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file nrf52_flash.c
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2018, Adafruit Industries (adafruit.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include "Arduino.h"
|
||||
#include "nrf52_flash.h"
|
||||
|
||||
#if CFG_DEBUG
|
||||
#define CFG_DEBUG_NFFS 0
|
||||
|
||||
#if CFG_DEBUG_NFFS
|
||||
static void print_buf(const uint8_t* address, uint32_t count)
|
||||
{
|
||||
for(uint32_t i=0; i<count; i++) cprintf("%02X ", address[i] );
|
||||
}
|
||||
|
||||
static void print_write_before(uint32_t address, const void* data, uint32_t count)
|
||||
{
|
||||
cprintf("Flash Write at 0x%06lX from 0x%06lX, %d bytes\n", address, (uint32_t) data, count);
|
||||
|
||||
cprintf(" Before: ");
|
||||
print_buf((const uint8_t*)address, count);
|
||||
cprintf("\n");
|
||||
|
||||
cprintf(" Data : ");
|
||||
print_buf((const uint8_t*)data, count);
|
||||
cprintf("\n");
|
||||
}
|
||||
|
||||
static void print_write_after(uint32_t address, uint32_t count)
|
||||
{
|
||||
cprintf(" After : ");
|
||||
print_buf((const uint8_t*)address, count);
|
||||
cprintf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
static int nrf52_flash_sector_info(void *dev, int idx, uint32_t *address, uint32_t *sz);
|
||||
|
||||
static const struct hal_flash_funcs nrf52k_flash_funcs = {
|
||||
.hff_read = nrf52k_flash_read,
|
||||
.hff_write = nrf52_flash_write,
|
||||
.hff_erase_sector = nrf52_flash_erase_sector,
|
||||
.hff_sector_info = nrf52_flash_sector_info,
|
||||
.hff_init = nrf52_flash_init
|
||||
};
|
||||
|
||||
const struct hal_flash nrf52k_flash_dev = {
|
||||
.hf_itf = &nrf52k_flash_funcs,
|
||||
.hf_base_addr = 0x00000000,
|
||||
.hf_size = 512 * 1024, /* XXX read from factory info? */
|
||||
.hf_sector_cnt = 128, /* XXX read from factory info? */
|
||||
.hf_align = 1
|
||||
};
|
||||
|
||||
static SemaphoreHandle_t _evt_sem = NULL;
|
||||
static volatile uint32_t _op_result;
|
||||
|
||||
void hal_flash_event_cb(uint32_t event)
|
||||
{
|
||||
_op_result = event;
|
||||
xSemaphoreGive(_evt_sem);
|
||||
}
|
||||
|
||||
int nrf52_flash_init(const struct hal_flash *dev)
|
||||
{
|
||||
(void) dev;
|
||||
_evt_sem = xSemaphoreCreateCounting(10, 0);
|
||||
return (_evt_sem != NULL) ? 0 : 1;
|
||||
}
|
||||
|
||||
int nrf52_flash_erase_sector(const struct hal_flash *dev, uint32_t sector_address)
|
||||
{
|
||||
(void) dev;
|
||||
uint32_t err;
|
||||
|
||||
#if CFG_DEBUG_NFFS
|
||||
cprintf("Flash Erase at 0x%06lX \n", sector_address);
|
||||
#endif
|
||||
|
||||
// delay and try again if busy
|
||||
while ( NRF_ERROR_BUSY == (err = sd_flash_page_erase(sector_address/NRF52K_FLASH_SECTOR_SZ)) )
|
||||
{
|
||||
delay(1);
|
||||
}
|
||||
VERIFY_STATUS(err);
|
||||
|
||||
xSemaphoreTake(_evt_sem, portMAX_DELAY);
|
||||
return (_op_result == NRF_EVT_FLASH_OPERATION_SUCCESS ) ? 0 : (-1);
|
||||
}
|
||||
|
||||
static int write_and_wait(uint32_t addr, uint32_t const * const data, uint32_t size)
|
||||
{
|
||||
if ( size == 0 ) return 0;
|
||||
|
||||
uint32_t err;
|
||||
|
||||
#if CFG_DEBUG_NFFS
|
||||
cprintf(" %02d bytes at 0x%06lX: ", 4*size, addr);
|
||||
print_buf((const uint8_t*) data, 4*size);
|
||||
cprintf("\n");
|
||||
#endif
|
||||
|
||||
// delay and try again if busy
|
||||
while ( NRF_ERROR_BUSY == (err = sd_flash_write( (uint32_t*) addr, data, size)) )
|
||||
{
|
||||
delay(1);
|
||||
}
|
||||
VERIFY_STATUS(err);
|
||||
|
||||
xSemaphoreTake(_evt_sem, portMAX_DELAY);
|
||||
return (_op_result == NRF_EVT_FLASH_OPERATION_SUCCESS ) ? 0 : (-1);
|
||||
}
|
||||
|
||||
int nrf52_flash_write(const struct hal_flash *dev, uint32_t address, const void *src, uint32_t num_bytes)
|
||||
{
|
||||
(void) dev;
|
||||
|
||||
#if CFG_DEBUG_NFFS
|
||||
const uint32_t _num = num_bytes;
|
||||
const uint32_t _addr = address;
|
||||
print_write_before(_addr, src, _num);
|
||||
#endif
|
||||
|
||||
/* SD Flash requires
|
||||
* 1. src data must be word aligned
|
||||
* 2. address must be word aligned
|
||||
* 2. each write is 4 bytes
|
||||
*
|
||||
* This cause issue with string literal. Solution is break up to 3 sequence write
|
||||
* 1. First is required if address not started at word aligned
|
||||
* 2. Malloc aligned data for src if needed
|
||||
* 3. Trailing bytes
|
||||
*/
|
||||
|
||||
/*------------- non-aligned Address -------------*/
|
||||
// Address is not aligned
|
||||
uint32_t miss = address & 0x03;
|
||||
|
||||
if ( miss )
|
||||
{
|
||||
/* Address is not aligned. Combine odd bytes data + existed data
|
||||
* then update and write back
|
||||
*/
|
||||
|
||||
uint32_t cnt = 4 - miss;
|
||||
uint32_t val;
|
||||
|
||||
memcpy( &val, (uint8_t*) align4(address), 4);
|
||||
memcpy( ((uint8_t*)&val)+miss, src, cnt);
|
||||
|
||||
#if CFG_DEBUG_NFFS
|
||||
cprintf(" P1");
|
||||
#endif
|
||||
|
||||
VERIFY_STATUS( write_and_wait( align4(address), &val, 1) );
|
||||
|
||||
address += cnt;
|
||||
src += cnt;
|
||||
num_bytes -= cnt;
|
||||
}
|
||||
|
||||
/*------------- Main write -------------*/
|
||||
uint32_t const n4 = align4(num_bytes);
|
||||
uint32_t const leftover = (num_bytes & 0x03UL);
|
||||
|
||||
if ( ((uint32_t)src) & 0x03 )
|
||||
{
|
||||
// src is not word aligned
|
||||
// Malloc and copy multiple of 4 bytes from src to write to flash
|
||||
uint8_t* tempbuf = (uint8_t*) rtos_malloc( n4 + 4 );
|
||||
VERIFY( tempbuf, NRF_ERROR_NO_MEM);
|
||||
|
||||
memcpy(tempbuf, src, num_bytes);
|
||||
|
||||
// There is trailing bytes, read overflow from address
|
||||
if ( leftover )
|
||||
{
|
||||
memcpy(tempbuf+num_bytes, (uint8_t*) (address+num_bytes), 4-leftover);
|
||||
}
|
||||
|
||||
#if CFG_DEBUG_NFFS
|
||||
cprintf(" P2");
|
||||
#endif
|
||||
|
||||
int err = write_and_wait(address, (uint32_t*)tempbuf, (n4 / 4) + (leftover ? 1 : 0) );
|
||||
|
||||
rtos_free(tempbuf);
|
||||
|
||||
VERIFY_STATUS(err);
|
||||
}else
|
||||
{
|
||||
if ( n4 )
|
||||
{
|
||||
#if CFG_DEBUG_NFFS
|
||||
cprintf(" P3");
|
||||
#endif
|
||||
VERIFY_STATUS( write_and_wait(address, src, n4 / 4) );
|
||||
|
||||
address += n4;
|
||||
src += n4;
|
||||
num_bytes -= n4;
|
||||
}
|
||||
|
||||
/*------------- Trailing Bytes -------------*/
|
||||
if ( leftover )
|
||||
{
|
||||
uint32_t val;
|
||||
|
||||
memcpy(&val, (uint8_t*) address, 4);
|
||||
memcpy(&val, src, leftover);
|
||||
|
||||
#if CFG_DEBUG_NFFS
|
||||
cprintf(" P4");
|
||||
#endif
|
||||
|
||||
VERIFY_STATUS( write_and_wait(address, &val, 1) );
|
||||
}
|
||||
}
|
||||
|
||||
#if CFG_DEBUG_NFFS
|
||||
print_write_after(_addr, _num);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nrf52k_flash_read(const struct hal_flash *dev, uint32_t address, void *dst, uint32_t num_bytes)
|
||||
{
|
||||
(void) dev;
|
||||
memcpy(dst, (void *)address, num_bytes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int nrf52_flash_sector_info(void *dev, int idx, uint32_t *address, uint32_t *sz)
|
||||
{
|
||||
(void) dev;
|
||||
assert(idx < nrf52k_flash_dev.hf_sector_cnt);
|
||||
*address = idx * NRF52K_FLASH_SECTOR_SZ;
|
||||
*sz = NRF52K_FLASH_SECTOR_SZ;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const struct hal_flash *
|
||||
hal_bsp_flash_dev(uint8_t id)
|
||||
{
|
||||
/*
|
||||
* Internal flash mapped to id 0.
|
||||
*/
|
||||
if (id != 0) {
|
||||
return NULL;
|
||||
}
|
||||
return &nrf52k_flash_dev;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user