Skip to content

Commit

Permalink
__ALIGN(4) をたしたら、releaseビルドでも動いた。やったぜ!
Browse files Browse the repository at this point in the history
__ALIGN(4) をたしたら、releaseビルドでも動いた。やったぜ!
  • Loading branch information
takurx committed Aug 2, 2019
1 parent 84fe2bb commit 4ad1fbb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
6 changes: 6 additions & 0 deletions components/libraries/fstorage/nrf_fstorage.c
Expand Up @@ -48,10 +48,15 @@
#include "sdk_macros.h"
#include "nrf_section.h"



#define NRF_LOG_MODULE_NAME nrf_fstorage
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();

//#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

/* Create the section "fs_data". */
NRF_SECTION_DEF(fs_data, nrf_fstorage_t);
Expand Down Expand Up @@ -143,6 +148,7 @@ ret_code_t nrf_fstorage_write(nrf_fstorage_t const * p_fs,

/* Source and destination addresses must be word-aligned. */
NRF_FSTORAGE_PARAM_CHECK(addr_is_aligned32(dest), NRF_ERROR_INVALID_ADDR);
NRF_LOG_INFO("addr, (uint32_t)p_src: %d", (uint32_t)p_src);
NRF_FSTORAGE_PARAM_CHECK(addr_is_aligned32((uint32_t)p_src), NRF_ERROR_INVALID_ADDR);
NRF_FSTORAGE_PARAM_CHECK(addr_is_within_bounds(p_fs, dest, len), NRF_ERROR_INVALID_ADDR);

Expand Down
37 changes: 20 additions & 17 deletions examples/ble_peripheral/ble_app_uart/main.c
Expand Up @@ -992,9 +992,11 @@ static volatile unsigned int Count_index_data_hr_hr = 0;
*/
typedef struct
{
ble_date_time_t start_time;
float body_temperature_array[6];
uint16_t heart_rate;
ble_date_time_t start_time; // 7byte = 56 = 16 + 8 + 8 + 8 + 8 + 8
//uint8_t reserved_0; // 1byte = 8
float body_temperature_array[6]; // 4byte = 32
uint16_t heart_rate; // 2byte = 16
uint16_t reserved_1; // 2byte = 16
} ble_data_ht_hr_t;
static volatile ble_data_ht_hr_t data_hr_hr[Num_of_data_hr_hr] = {};
static volatile ble_data_ht_hr_t temp_data_hr_hr = {};
Expand Down Expand Up @@ -2627,11 +2629,11 @@ const uint8_t write_count = 4;
const uint32_t Flash_start_address = 0x60000;
uint32_t write_index = Flash_start_address;
//static uint8_t flash_ff_padding[4096] = {0xFF};
uint8_t flash_ff_padding[0x1000];
__ALIGN(4) uint8_t flash_ff_padding[0x1000];

static volatile int size_write_data = sizeof(data_hr_hr[0]);
const int size_write_data = sizeof(data_hr_hr[0]);
const int size_write_buffer = sizeof(data_hr_hr[0]) * 8;
static uint8_t write_buffer[sizeof(data_hr_hr[0]) * 8];
__ALIGN(4) uint8_t write_buffer[sizeof(data_hr_hr[0]) * 8];
const int Flash_write_count_for_sleep = Num_of_data_hr_hr / 8;

static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
Expand Down Expand Up @@ -2821,7 +2823,7 @@ static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
if (Enter_sleep_count == 24)
{
//3s long push and sleep mode enter
NRF_LOG_INFO("sleep mode enter");
NRF_LOG_INFO("sleep mode enter, user operation");

rc = app_timer_stop(m_data_record_timer_id);
APP_ERROR_CHECK(rc);
Expand Down Expand Up @@ -2876,6 +2878,7 @@ static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
//while (nrf_fstorage_is_busy(p_fstorage))
if (nrf_fstorage_is_busy(&fstorage) == false)
{
NRF_LOG_INFO("write data to sleep: %d, %d", Wait_sleep_count, size_write_data);
memcpy(&write_buffer[size_write_data * 0], (const void *)(&data_hr_hr[Wait_sleep_count * 8 + 0]), size_write_data);
memcpy(&write_buffer[size_write_data * 1], (const void *)(&data_hr_hr[Wait_sleep_count * 8 + 1]), size_write_data);
memcpy(&write_buffer[size_write_data * 2], (const void *)(&data_hr_hr[Wait_sleep_count * 8 + 2]), size_write_data);
Expand All @@ -2884,7 +2887,7 @@ static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
memcpy(&write_buffer[size_write_data * 5], (const void *)(&data_hr_hr[Wait_sleep_count * 8 + 5]), size_write_data);
memcpy(&write_buffer[size_write_data * 6], (const void *)(&data_hr_hr[Wait_sleep_count * 8 + 6]), size_write_data);
memcpy(&write_buffer[size_write_data * 7], (const void *)(&data_hr_hr[Wait_sleep_count * 8 + 7]), size_write_data);
rc = nrf_fstorage_write(&fstorage, write_index, &write_buffer, sizeof(write_buffer), NULL);
rc = nrf_fstorage_write(&fstorage, write_index, write_buffer, sizeof(write_buffer), NULL);
APP_ERROR_CHECK(rc);
write_index = write_index + sizeof(write_buffer);

Expand All @@ -2898,9 +2901,9 @@ static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
if (nrf_fstorage_is_busy(&fstorage) == false)
{
//Current time, time_stamp
static uint8_t write_time_stamp[sizeof(time_stamp)];
__ALIGN(4) static uint8_t write_time_stamp[sizeof(time_stamp)];
*(ble_date_time_t *) write_time_stamp = time_stamp;
rc = nrf_fstorage_write(&fstorage, write_index, &write_time_stamp, sizeof(write_time_stamp), NULL);
rc = nrf_fstorage_write(&fstorage, write_index, write_time_stamp, sizeof(write_time_stamp), NULL);
APP_ERROR_CHECK(rc);
write_index = write_index + sizeof(write_time_stamp);

Expand All @@ -2914,9 +2917,9 @@ static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
if (nrf_fstorage_is_busy(&fstorage) == false)
{
//Write index, Write_index_data_hr_hr
static uint8_t write_write_index[sizeof(Write_index_data_hr_hr)];
__ALIGN(4) static uint8_t write_write_index[sizeof(Write_index_data_hr_hr)];
*(unsigned int *) write_write_index = Write_index_data_hr_hr;
rc = nrf_fstorage_write(&fstorage, write_index, &write_write_index, sizeof(write_write_index), NULL);
rc = nrf_fstorage_write(&fstorage, write_index, write_write_index, sizeof(write_write_index), NULL);
APP_ERROR_CHECK(rc);
write_index = write_index + sizeof(write_write_index);

Expand All @@ -2930,9 +2933,9 @@ static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
if (nrf_fstorage_is_busy(&fstorage) == false)
{
//Read index, Read_index_data_hr_hr
static uint8_t write_read_index[sizeof(Read_index_data_hr_hr)];
__ALIGN(4) static uint8_t write_read_index[sizeof(Read_index_data_hr_hr)];
*(unsigned int *) write_read_index = Read_index_data_hr_hr;
rc = nrf_fstorage_write(&fstorage, write_index, &write_read_index, sizeof(write_read_index), NULL);
rc = nrf_fstorage_write(&fstorage, write_index, write_read_index, sizeof(write_read_index), NULL);
APP_ERROR_CHECK(rc);
write_index = write_index + sizeof(write_read_index);

Expand All @@ -2946,9 +2949,9 @@ static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
if (nrf_fstorage_is_busy(&fstorage) == false)
{
//Count index, Count_index_data_hr_hr
static uint8_t write_count_index[sizeof(Count_index_data_hr_hr)];
__ALIGN(4) static uint8_t write_count_index[sizeof(Count_index_data_hr_hr)];
*(unsigned int *) write_count_index = Count_index_data_hr_hr;
rc = nrf_fstorage_write(&fstorage, write_index, &write_count_index, sizeof(write_count_index), NULL);
rc = nrf_fstorage_write(&fstorage, write_index, write_count_index, sizeof(write_count_index), NULL);
APP_ERROR_CHECK(rc);
write_index = write_index + sizeof(write_count_index);

Expand Down Expand Up @@ -3212,7 +3215,7 @@ int main(void)
/*
uint32_t test_write_address = 0x60000;
NRF_LOG_INFO("Writing \"%x\" to flash.", m_data);
rc = nrf_fstorage_write(&fstorage, test_write_address, &m_data, sizeof(m_data), NULL);
rc = nrf_fstorage_write(&fstorage, test_write_address, m_data, sizeof(m_data), NULL);
APP_ERROR_CHECK(rc);
wait_for_flash_ready(&fstorage);
Expand Down
Expand Up @@ -27,7 +27,7 @@
linker_printf_fmt_level="long"
linker_printf_width_precision_supported="Yes"
linker_section_placement_file="flash_placement.xml"
linker_section_placement_macros="FLASH_PH_START=0x0;FLASH_PH_SIZE=0x80000;RAM_PH_START=0x20000000;RAM_PH_SIZE=0x10000;FLASH_START=0x26000;FLASH_SIZE=0x5a000;RAM_START=0x20002b98;RAM_SIZE=0xd468"
linker_section_placement_macros="FLASH_PH_START=0x0;FLASH_PH_SIZE=0x80000;RAM_PH_START=0x20000000;RAM_PH_SIZE=0x10000;FLASH_START=0x26000;FLASH_SIZE=0x5a000;RAM_START=0x20002C00;RAM_SIZE=0xd400"
linker_section_placements_segments="FLASH RX 0x0 0x80000;RAM RWX 0x20000000 0x10000"
macros="CMSIS_CONFIG_TOOL=../../../../../../external_tools/cmsisconfig/CMSIS_Configuration_Wizard.jar"
project_directory=""
Expand Down
Expand Up @@ -64,10 +64,13 @@
<Watches active="0" update="Never"/>
</Watch4>
<Files>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="3454" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../main.c" selected="1" top="2815" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="2005" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/softdevice/s132/headers/ble_gap.h" selected="0" top="1980" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="31" useTextEdit="1" useBinaryEdit="0" left="0" path="ble_app_uart_pca10040_s132.emProject" selected="0" top="0" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="99" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/libraries/util/app_error_weak.c" selected="0" top="68" codecName=""/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="56" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/libraries/fstorage/nrf_fstorage.c" selected="0" top="47" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="99" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/libraries/util/app_error_weak.c" selected="0" top="77" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="73" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/ble/common/ble_date_time.h" selected="0" top="49" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="989" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/libraries/fds/fds.c" selected="0" top="941" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="29" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../BH1792GLC_HeartRate/pwCalc.c" selected="0" top="0" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="3148" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../main.c" selected="1" top="3126" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="29" useTextEdit="1" useBinaryEdit="0" left="0" path="ble_app_uart_pca10040_s132.emProject" selected="0" top="7" codecName="Default"/>
</Files>
<ARMCrossStudioWindow activeProject="ble_app_uart_pca10040_s132" fileDialogDefaultFilter="*.c" autoConnectTarget="J-Link" buildConfiguration="Release" sessionSettings="" debugSearchFileMap="" fileDialogInitialDirectory="" debugSearchPath="" autoConnectCapabilities="3711"/>
</session>

0 comments on commit 4ad1fbb

Please sign in to comment.