pub fn read_flash_size<P>(device: &mut Device<P>) -> io::Result<u32>
where
    P: serial::SerialPort,
{
    let addr = match device.family() {
        Family::CC2538 => CC2538_FLASH_CTRL_O_DIECFG0,
        Family::CC26X0 | Family::CC26X2 => CC26XX_FLASH_O_FLASH_SIZE,
    };

    let mut reg = [0u8; REG32_SIZE];
    device.memory_read_32(addr, &mut reg)?;

    match device.family() {
        Family::CC2538 => {
            let flash_ctrl = u32::from_le_bytes(reg);
            let flash_size = (flash_ctrl >> 4) & 0x07;
            match flash_size {
                1 => Ok(0x20000), // 128 KB
                2 => Ok(0x40000), // 256 KB
                3 => Ok(0x60000), // 384 KB
                4 => Ok(0x80000), // 512 KB
                0 => Ok(0x10000), //  64 KB
                _ => Ok(0x10000), // All invalid values are interpreted as 64 KB
            }
        }
        Family::CC26X0 | Family::CC26X2 => {
            let mut flash_size = u32::from_le_bytes(reg);
            flash_size &= 0xFF;

            Ok(flash_size * device.family().sector_size())
        }
    }
}
/// Reads the flash size from the memory.
Reads the flash size from the memory.
Reads the flash size from the memory .
pub fn read_flash_size<P>(device: &mut Device<P>) -> io::Result<u32>
where
    P: serial::SerialPort,
{
    let addr = match device.family() {
        Family::CC2538 => CC2538_FLASH_CTRL_O_DIECFG0,
        Family::CC26X0 | Family::CC26X2 => CC26XX_FLASH_O_FLASH_SIZE,
    };
    let mut reg = [0u8; REG32_SIZE];
    device.memory_read_32(addr, &mut reg)?;
    match device.family() {
        Family::CC2538 => {
            let flash_ctrl = u32::from_le_bytes(reg);
            let flash_size = (flash_ctrl >> 4) & 0x07;
            match flash_size {
                1 => Ok(0x20000), // 128 KB
                2 => Ok(0x40000), // 256 KB
                3 => Ok(0x60000), // 384 KB
                4 => Ok(0x80000), // 512 KB
                0 => Ok(0x10000), //  64 KB
                _ => Ok(0x10000), // All invalid values are interpreted as 64 KB
            }
        }
        Family::CC26X0 | Family::CC26X2 => {
            let mut flash_size = u32::from_le_bytes(reg);
            flash_size &= 0xFF;
            Ok(flash_size * device.family().sector_size())
        }
    }
}
pub fn read_flash_size < P > ( device : & mut Device < P > ) -> io :: Result < u32 > where P : serial :: SerialPort , { let addr = match device . family ( ) { Family :: CC2538 => CC2538_FLASH_CTRL_O_DIECFG0 , Family :: CC26X0 | Family :: CC26X2 => CC26XX_FLASH_O_FLASH_SIZE , } ; let mut reg = [ 0u8 ; REG32_SIZE ] ; device . memory_read_32 ( addr , & mut reg ) ? ; match device . family ( ) { Family :: CC2538 => { let flash_ctrl = u32 :: from_le_bytes ( reg ) ; let flash_size = ( flash_ctrl >> 4 ) & 0x07 ; match flash_size { 1 => Ok ( 0x20000 ) , // 128 KB 2 => Ok ( 0x40000 ) , // 256 KB 3 => Ok ( 0x60000 ) , // 384 KB 4 => Ok ( 0x80000 ) , // 512 KB 0 => Ok ( 0x10000 ) , //  64 KB _ => Ok ( 0x10000 ) , // All invalid values are interpreted as 64 KB } } Family :: CC26X0 | Family :: CC26X2 => { let mut flash_size = u32 :: from_le_bytes ( reg ) ; flash_size &= 0xFF ; Ok ( flash_size * device . family ( ) . sector_size ( ) ) } } }
Reads the flash size from the memory.
Reads the flash size from the memory .
device
&mut Device<P>
device
&mut Device<P>