Modify the file main.cpp for M487

Dependencies:   BufferedSerial

Committer:
shliu1
Date:
Fri Sep 29 05:45:43 2017 +0000
Revision:
0:c89ccc69a48b
main.cpp adds the setting of TARGET_NUMAKER_PFM_M487 for M487

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shliu1 0:c89ccc69a48b 1 /* mbed Microcontroller Library
shliu1 0:c89ccc69a48b 2 * Copyright (c) 2015-2016 Nuvoton
shliu1 0:c89ccc69a48b 3 *
shliu1 0:c89ccc69a48b 4 * Licensed under the Apache License, Version 2.0 (the "License");
shliu1 0:c89ccc69a48b 5 * you may not use this file except in compliance with the License.
shliu1 0:c89ccc69a48b 6 * You may obtain a copy of the License at
shliu1 0:c89ccc69a48b 7 *
shliu1 0:c89ccc69a48b 8 * http://www.apache.org/licenses/LICENSE-2.0
shliu1 0:c89ccc69a48b 9 *
shliu1 0:c89ccc69a48b 10 * Unless required by applicable law or agreed to in writing, software
shliu1 0:c89ccc69a48b 11 * distributed under the License is distributed on an "AS IS" BASIS,
shliu1 0:c89ccc69a48b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
shliu1 0:c89ccc69a48b 13 * See the License for the specific language governing permissions and
shliu1 0:c89ccc69a48b 14 * limitations under the License.
shliu1 0:c89ccc69a48b 15 */
shliu1 0:c89ccc69a48b 16 #ifndef __NU_SD_BLOCK_DEVICE_H__
shliu1 0:c89ccc69a48b 17 #define __NU_SD_BLOCK_DEVICE_H__
shliu1 0:c89ccc69a48b 18
shliu1 0:c89ccc69a48b 19 #include "BlockDevice.h"
shliu1 0:c89ccc69a48b 20 #include "mbed.h"
shliu1 0:c89ccc69a48b 21
shliu1 0:c89ccc69a48b 22 struct nu_modinit_s;
shliu1 0:c89ccc69a48b 23
shliu1 0:c89ccc69a48b 24 class NuSDBlockDevice : public BlockDevice {
shliu1 0:c89ccc69a48b 25 public:
shliu1 0:c89ccc69a48b 26 /** Lifetime of an SD card
shliu1 0:c89ccc69a48b 27 */
shliu1 0:c89ccc69a48b 28 NuSDBlockDevice();
shliu1 0:c89ccc69a48b 29 NuSDBlockDevice(PinName sd_dat0, PinName sd_dat1, PinName sd_dat2, PinName sd_dat3,
shliu1 0:c89ccc69a48b 30 PinName sd_cmd, PinName sd_clk, PinName sd_cdn);
shliu1 0:c89ccc69a48b 31 virtual ~NuSDBlockDevice();
shliu1 0:c89ccc69a48b 32
shliu1 0:c89ccc69a48b 33 /** Initialize a block device
shliu1 0:c89ccc69a48b 34 *
shliu1 0:c89ccc69a48b 35 * @return 0 on success or a negative error code on failure
shliu1 0:c89ccc69a48b 36 */
shliu1 0:c89ccc69a48b 37 virtual int init();
shliu1 0:c89ccc69a48b 38
shliu1 0:c89ccc69a48b 39 /** Deinitialize a block device
shliu1 0:c89ccc69a48b 40 *
shliu1 0:c89ccc69a48b 41 * @return 0 on success or a negative error code on failure
shliu1 0:c89ccc69a48b 42 */
shliu1 0:c89ccc69a48b 43 virtual int deinit();
shliu1 0:c89ccc69a48b 44
shliu1 0:c89ccc69a48b 45 /** Read blocks from a block device
shliu1 0:c89ccc69a48b 46 *
shliu1 0:c89ccc69a48b 47 * @param buffer Buffer to write blocks to
shliu1 0:c89ccc69a48b 48 * @param addr Address of block to begin reading from
shliu1 0:c89ccc69a48b 49 * @param size Size to read in bytes, must be a multiple of read block size
shliu1 0:c89ccc69a48b 50 * @return 0 on success, negative error code on failure
shliu1 0:c89ccc69a48b 51 */
shliu1 0:c89ccc69a48b 52 virtual int read(void *buffer, bd_addr_t addr, bd_size_t size);
shliu1 0:c89ccc69a48b 53
shliu1 0:c89ccc69a48b 54 /** Program blocks to a block device
shliu1 0:c89ccc69a48b 55 *
shliu1 0:c89ccc69a48b 56 * The blocks must have been erased prior to being programmed
shliu1 0:c89ccc69a48b 57 *
shliu1 0:c89ccc69a48b 58 * @param buffer Buffer of data to write to blocks
shliu1 0:c89ccc69a48b 59 * @param addr Address of block to begin writing to
shliu1 0:c89ccc69a48b 60 * @param size Size to write in bytes, must be a multiple of program block size
shliu1 0:c89ccc69a48b 61 * @return 0 on success, negative error code on failure
shliu1 0:c89ccc69a48b 62 */
shliu1 0:c89ccc69a48b 63 virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size);
shliu1 0:c89ccc69a48b 64
shliu1 0:c89ccc69a48b 65 /** Erase blocks on a block device
shliu1 0:c89ccc69a48b 66 *
shliu1 0:c89ccc69a48b 67 * The state of an erased block is undefined until it has been programmed
shliu1 0:c89ccc69a48b 68 *
shliu1 0:c89ccc69a48b 69 * @param addr Address of block to begin erasing
shliu1 0:c89ccc69a48b 70 * @param size Size to erase in bytes, must be a multiple of erase block size
shliu1 0:c89ccc69a48b 71 * @return 0 on success, negative error code on failure
shliu1 0:c89ccc69a48b 72 */
shliu1 0:c89ccc69a48b 73 virtual int erase(bd_addr_t addr, bd_size_t size);
shliu1 0:c89ccc69a48b 74
shliu1 0:c89ccc69a48b 75 /** Get the size of a readable block
shliu1 0:c89ccc69a48b 76 *
shliu1 0:c89ccc69a48b 77 * @return Size of a readable block in bytes
shliu1 0:c89ccc69a48b 78 */
shliu1 0:c89ccc69a48b 79 virtual bd_size_t get_read_size() const;
shliu1 0:c89ccc69a48b 80
shliu1 0:c89ccc69a48b 81 /** Get the size of a programable block
shliu1 0:c89ccc69a48b 82 *
shliu1 0:c89ccc69a48b 83 * @return Size of a programable block in bytes
shliu1 0:c89ccc69a48b 84 * @note Must be a multiple of the read size
shliu1 0:c89ccc69a48b 85 */
shliu1 0:c89ccc69a48b 86 virtual bd_size_t get_program_size() const;
shliu1 0:c89ccc69a48b 87
shliu1 0:c89ccc69a48b 88 /** Get the size of a eraseable block
shliu1 0:c89ccc69a48b 89 *
shliu1 0:c89ccc69a48b 90 * @return Size of a eraseable block in bytes
shliu1 0:c89ccc69a48b 91 * @note Must be a multiple of the program size
shliu1 0:c89ccc69a48b 92 */
shliu1 0:c89ccc69a48b 93 virtual bd_size_t get_erase_size() const;
shliu1 0:c89ccc69a48b 94
shliu1 0:c89ccc69a48b 95 /** Get the total size of the underlying device
shliu1 0:c89ccc69a48b 96 *
shliu1 0:c89ccc69a48b 97 * @return Size of the underlying device in bytes
shliu1 0:c89ccc69a48b 98 */
shliu1 0:c89ccc69a48b 99 virtual bd_size_t size() const;
shliu1 0:c89ccc69a48b 100
shliu1 0:c89ccc69a48b 101 /** Enable or disable debugging
shliu1 0:c89ccc69a48b 102 *
shliu1 0:c89ccc69a48b 103 * @param State of debugging
shliu1 0:c89ccc69a48b 104 */
shliu1 0:c89ccc69a48b 105 virtual void debug(bool dbg);
shliu1 0:c89ccc69a48b 106
shliu1 0:c89ccc69a48b 107 private:
shliu1 0:c89ccc69a48b 108 int _init_sdh();
shliu1 0:c89ccc69a48b 109 uint32_t _sd_sectors();
shliu1 0:c89ccc69a48b 110 void _sdh_irq();
shliu1 0:c89ccc69a48b 111
shliu1 0:c89ccc69a48b 112 uint32_t _sectors;
shliu1 0:c89ccc69a48b 113 bool _is_initialized;
shliu1 0:c89ccc69a48b 114 bool _dbg;
shliu1 0:c89ccc69a48b 115 Mutex _lock;
shliu1 0:c89ccc69a48b 116
shliu1 0:c89ccc69a48b 117 const struct nu_modinit_s * _sdh_modinit;
shliu1 0:c89ccc69a48b 118 SDName _sdh;
shliu1 0:c89ccc69a48b 119 SDH_T * _sdh_base;
shliu1 0:c89ccc69a48b 120 #if defined(TARGET_NUMAKER_PFM_NUC472)
shliu1 0:c89ccc69a48b 121 uint32_t _sdh_port;
shliu1 0:c89ccc69a48b 122 #endif
shliu1 0:c89ccc69a48b 123
shliu1 0:c89ccc69a48b 124 CThunk<NuSDBlockDevice> _sdh_irq_thunk;
shliu1 0:c89ccc69a48b 125
shliu1 0:c89ccc69a48b 126 PinName _sd_dat0;
shliu1 0:c89ccc69a48b 127 PinName _sd_dat1;
shliu1 0:c89ccc69a48b 128 PinName _sd_dat2;
shliu1 0:c89ccc69a48b 129 PinName _sd_dat3;
shliu1 0:c89ccc69a48b 130 PinName _sd_cmd;
shliu1 0:c89ccc69a48b 131 PinName _sd_clk;
shliu1 0:c89ccc69a48b 132 PinName _sd_cdn;
shliu1 0:c89ccc69a48b 133 };
shliu1 0:c89ccc69a48b 134
shliu1 0:c89ccc69a48b 135 #endif /* __NU_SD_BLOCK_DEVICE_H__ */