From 4ad1fbb4d11beb241c9113651fb07c861f293fa3 Mon Sep 17 00:00:00 2001 From: Yoshihiro Nakagawa Date: Fri, 2 Aug 2019 12:57:29 +0900 Subject: [PATCH] =?UTF-8?q?=5F=5FALIGN(4)=20=E3=82=92=E3=81=9F=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=82=89=E3=80=81release=E3=83=93=E3=83=AB=E3=83=89?= =?UTF-8?q?=E3=81=A7=E3=82=82=E5=8B=95=E3=81=84=E3=81=9F=E3=80=82=E3=82=84?= =?UTF-8?q?=E3=81=A3=E3=81=9F=E3=81=9C=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit __ALIGN(4) をたしたら、releaseビルドでも動いた。やったぜ! --- components/libraries/fstorage/nrf_fstorage.c | 6 +++ examples/ble_peripheral/ble_app_uart/main.c | 37 ++++++++++--------- .../ses/ble_app_uart_pca10040_s132.emProject | 2 +- .../ses/ble_app_uart_pca10040_s132.emSession | 11 ++++-- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/components/libraries/fstorage/nrf_fstorage.c b/components/libraries/fstorage/nrf_fstorage.c index a1300ac..f58308d 100644 --- a/components/libraries/fstorage/nrf_fstorage.c +++ b/components/libraries/fstorage/nrf_fstorage.c @@ -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); @@ -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); diff --git a/examples/ble_peripheral/ble_app_uart/main.c b/examples/ble_peripheral/ble_app_uart/main.c index d3ff34e..e1b791d 100644 --- a/examples/ble_peripheral/ble_app_uart/main.c +++ b/examples/ble_peripheral/ble_app_uart/main.c @@ -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 = {}; @@ -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) @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/examples/ble_peripheral/ble_app_uart/pca10040/s132/ses/ble_app_uart_pca10040_s132.emProject b/examples/ble_peripheral/ble_app_uart/pca10040/s132/ses/ble_app_uart_pca10040_s132.emProject index 0b4125e..5bed2af 100644 --- a/examples/ble_peripheral/ble_app_uart/pca10040/s132/ses/ble_app_uart_pca10040_s132.emProject +++ b/examples/ble_peripheral/ble_app_uart/pca10040/s132/ses/ble_app_uart_pca10040_s132.emProject @@ -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="" diff --git a/examples/ble_peripheral/ble_app_uart/pca10040/s132/ses/ble_app_uart_pca10040_s132.emSession b/examples/ble_peripheral/ble_app_uart/pca10040/s132/ses/ble_app_uart_pca10040_s132.emSession index 5bbd5af..9406055 100644 --- a/examples/ble_peripheral/ble_app_uart/pca10040/s132/ses/ble_app_uart_pca10040_s132.emSession +++ b/examples/ble_peripheral/ble_app_uart/pca10040/s132/ses/ble_app_uart_pca10040_s132.emSession @@ -64,10 +64,13 @@ - - - - + + + + + + +