This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Use usbd_msc eample & libuarte to create .xls file, the file was damaged sometimes when open it on PC

Hi, Dear Nordic & All:

    I use usbd_msc example to generate .xls file, and write content in it, sometimes I write successfully, and can open it right on PC with WPS,

    but sometimes I generate the same .xls file  (my application in nrf52840 DK(sdk 17.0.2) is exactly the same for creating the .xls files ),  but after write content and close it,  I can not open it on PC with WPS, and PC  prompt the file may be damaged so I can not open, just like this:

  All APIs I used in this demo is: f_open(my_file, my_filename, FA_OPEN_ALWAYS | FA_WRITE | FA_OPEN_APPEND);

                                                      f_write(&file, m_rx.rx_buff, (UINT)strlen(m_rx.rx_buff), &written);

                                                      f_close(my_file);

I'v thought the damaged file may caused by the frequency I open/close(because this demo need operate .xls file  frequently ), but I decrease the frequency of open/close, the problem  still exist, this really confuse me.

The following is my whole code, It's function is: writing  serial data (va libuarte) into .xls file, I will open file once the data come, and will close it when received "END",

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

and, the following is my .xls file which is damaged and can not  open, can you see anything wrong about this file?

4162.TEST1.XLS

 Can anybody know what happened on this? 

Thanks for your kind help!