Here's my setup:
Host PC: Windows 10 64-bit
CCS: Version: 5.5.0.00077
Simulator: C674x cycle accurate simulator, little endian
I am trying to read a binary file using fread(), see source code below. However, the data appearing in the memory browser is incorrect.
Each element in the binary file is a uint8, and the values of these elements are as follows:
[1 2 3 .. 10 5 5 5 ....]
(i.e. count from 1 to 10 followed by lots of 5).
However, what I actually get is this:
I have attached the input binary file at the end of this post. The source code and build settings are as follows:
Compiler settings: -mv6740 --abi=coffabi -g --include_path="C:/ti/ccsv5/tools/compiler/c6000_7.4.4/include" --define=omapl138 --display_error_number --diag_warning=225 --diag_wrap=off --printf_support=full -k --output_all_syms
Linker Settings: -mv6740 --abi=coffabi -g --define=omapl138 --display_error_number --diag_warning=225 --diag_wrap=off --printf_support=full -k --output_all_syms -z --stack_size=0x8000 -m"06_fileIo_heapStorage.map" --heap_size=0x8000 -i"C:/ti/ccsv5/tools/compiler/c6000_7.4.4/lib" -i"C:/ti/ccsv5/tools/compiler/c6000_7.4.4/include" --reread_libs --define=DSP_CORE=1 --warn_sections --display_error_number --diag_wrap=off --xml_link_info="06_fileIo_heapStorage_linkInfo.xml" --rom_model
Source code:
#include <iostream> #include <fstream> #include <vector> #include <stdio.h> using namespace std; typedef unsigned char uint8_t; typedef unsigned int uint32_t; static const uint32_t MAX_BUFFER_SIZE = 1000U; //function prototype uint8_t* readDataFromFile_CVersion(const char* filename); //main function int main(void) { const char filename[100] = "C:/Work/temp/m-001-1.bin"; uint8_t *pData = readDataFromFile_CVersion(filename); delete[] pData; return 0; } //function for reading binary file uint8_t* readDataFromFile_CVersion(const char* filename) { FILE *fp1; uint32_t fileSizeInBytes; size_t bytesRead; fp1 = fopen(filename, "rb"); if (fp1 == NULL) { printf("failed to open input file"); } //obtain the file size fseek(fp1, 0, SEEK_END); fileSizeInBytes = ftell(fp1); rewind(fp1); std::size_t numBytesToRead = (fileSizeInBytes > MAX_BUFFER_SIZE) ? MAX_BUFFER_SIZE : fileSizeInBytes; uint8_t *dataBuf = new uint8_t(numBytesToRead); bytesRead = fread(dataBuf, 1, numBytesToRead, fp1); if (bytesRead != numBytesToRead) { printf("Reading error"); } //terminate fclose(fp1); return dataBuf; }
(Please visit the site to view this file)