Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
BD_DISCO_F746NG.cpp
00001 #include "BD_DISCO_F746NG.h" 00002 00003 00004 BD_DISCO_F746NG::BD_DISCO_F746NG(bd_size_t block) 00005 : _read_size(block), _program_size(block), _erase_size(block) 00006 , _blocks(0) 00007 { 00008 //MBED_ASSERT(_count * _erase_size == size); 00009 } 00010 00011 BD_DISCO_F746NG::BD_DISCO_F746NG(bd_size_t read, bd_size_t program, bd_size_t erase) 00012 : _read_size(read), _program_size(program), _erase_size(erase) 00013 , _blocks(0) 00014 { 00015 //MBED_ASSERT(_count * _erase_size == size); 00016 Timeout = 100; 00017 } 00018 00019 BD_DISCO_F746NG::~BD_DISCO_F746NG() 00020 { 00021 BSP_SD_DeInit(); 00022 /* 00023 if (_blocks) { 00024 for (size_t i = 0; i < _count; i++) { 00025 free(_blocks[i]); 00026 } 00027 00028 delete[] _blocks; 00029 _blocks = 0; 00030 } 00031 */ 00032 } 00033 00034 int BD_DISCO_F746NG::init() 00035 { 00036 Timeout = 100; 00037 bool result; 00038 00039 _SD_state = BSP_SD_Init(); 00040 00041 if(_SD_state != MSD_OK){ 00042 if(_SD_state == MSD_ERROR_SD_NOT_PRESENT){ 00043 return BD_ERROR_DEVICE_ERROR; 00044 } else { 00045 return BD_ERROR_DEVICE_ERROR; 00046 } 00047 } else { 00048 BSP_SD_GetCardInfo(&_currentCardInfo); 00049 //_blocksize = _currentCardInfo.BlockSize; 00050 _blocksize = 512; 00051 return BD_ERROR_OK; 00052 } 00053 /* 00054 if (!_blocks) { 00055 _blocks = new uint8_t*[_count]; 00056 for (size_t i = 0; i < _count; i++) { 00057 _blocks[i] = 0; 00058 } 00059 } 00060 */ 00061 // return BD_ERROR_OK; 00062 } 00063 00064 int BD_DISCO_F746NG::deinit() 00065 { 00066 return BSP_SD_DeInit(); 00067 /* 00068 MBED_ASSERT(_blocks != NULL); 00069 // Memory is lazily cleaned up in destructor to allow 00070 // data to live across de/reinitialization 00071 */ 00072 // return BD_ERROR_OK; 00073 } 00074 00075 bd_size_t BD_DISCO_F746NG::get_read_size() const 00076 { 00077 //MBED_ASSERT(_blocks != NULL); 00078 return _read_size; 00079 } 00080 00081 bd_size_t BD_DISCO_F746NG::get_program_size() const 00082 { 00083 //MBED_ASSERT(_blocks != NULL); 00084 return _program_size; 00085 } 00086 00087 bd_size_t BD_DISCO_F746NG::get_erase_size() const 00088 { 00089 //MBED_ASSERT(_blocks != NULL); 00090 return _erase_size; 00091 } 00092 00093 bd_size_t BD_DISCO_F746NG::size() const 00094 { 00095 //MBED_ASSERT(_blocks != NULL); 00096 //return (_currentCardInfo.BlockNbr*2) * _blocksize; 00097 return 128 * _blocksize; 00098 } 00099 00100 int BD_DISCO_F746NG::read(void *b, bd_addr_t addr, bd_size_t size) 00101 { 00102 int result; 00103 uint32_t nblocks = (uint32_t)size / _blocksize; 00104 result = BSP_SD_ReadBlocks((uint32_t *)b, (uint32_t)addr, nblocks, Timeout); 00105 return result; 00106 } 00107 00108 int BD_DISCO_F746NG::program(const void *b, bd_addr_t addr, bd_size_t size) 00109 { 00110 int result; 00111 uint32_t nblocks = (uint32_t)size / _blocksize; 00112 result = BSP_SD_WriteBlocks((uint32_t *)b, (uint32_t)addr, nblocks, Timeout); 00113 return result; 00114 } 00115 00116 int BD_DISCO_F746NG::erase(bd_addr_t addr, bd_size_t size) 00117 { 00118 int result; 00119 uint32_t StartAddr = addr; 00120 uint32_t EndAddr = StartAddr + size; 00121 result = BSP_SD_Erase(StartAddr, EndAddr); 00122 00123 return result; 00124 }
Generated on Sat Jul 16 2022 21:27:47 by
