STM8S存储器的块写和字节写没区别呀!请看代码。

2019-07-19 21:58发布


/**
  * @brief  Programs a memory block
  * @note   This function should be called and executed from RAM.
  * @param  FLASH_MemType : The type of memory to program
  * @param  BlockNum : The block number
  * @param  FLASH_ProgMode : The programming mode.
  * @param  Buffer : Pointer to buffer containing source data.
  * @retval None.
  */
IN_RAM(void FLASH_ProgramBlock(uint16_t BlockNum, FLASH_MemType_TypeDef FLASH_MemType,
                        FLASH_ProgramMode_TypeDef FLASH_ProgMode, uint8_t *Buffer))
{
    uint16_t Count = 0;
    uint32_t startaddress = 0;     /* Check parameters */
    assert_param(IS_MEMORY_TYPE_OK(FLASH_MemType));
    assert_param(IS_FLASH_PROGRAM_MODE_OK(FLASH_ProgMode));
    if (FLASH_MemType == FLASH_MEMTYPE_PROG)
    {
        assert_param(IS_FLASH_PROG_BLOCK_NUMBER_OK(BlockNum));
        startaddress = FLASH_PROG_START_PHYSICAL_ADDRESS;
    }
    else
    {
        assert_param(IS_FLASH_DATA_BLOCK_NUMBER_OK(BlockNum));
        startaddress = FLASH_DATA_START_PHYSICAL_ADDRESS;
    }     /* Point to the first block address */
    startaddress = startaddress + ((uint32_t)BlockNum * FLASH_BLOCK_SIZE);     /* Selection of Standard or Fast programming mode */
    if (FLASH_ProgMode == FLASH_PROGRAMMODE_STANDARD)
    {
        /* Standard programming mode */ /*No need in standard mode */
        FLASH->CR2 |= FLASH_CR2_PRG;
        FLASH->NCR2 &= (uint8_t)(~FLASH_NCR2_NPRG);
    }
    else
    {
        /* Fast programming mode */
        FLASH->CR2 |= FLASH_CR2_FPRG;
        FLASH->NCR2 &= (uint8_t)(~FLASH_NCR2_NFPRG);
    }     /* Copy data bytes from RAM to FLASH memory */
    for (Count = 0; Count < FLASH_BLOCK_SIZE; Count++)
    {   
        *((PointerAttr uint8_t*) (uint16_t)startaddress + Count) = ((uint8_t)(Buffer[Count]));     
    }
}
这不还是字节写吗!?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
1条回答
yzk
2019-07-19 22:29
没仔细看
 /* Selection of Standard or Fast programming mode */
    if (FLASH_ProgMode == FLASH_PROGRAMMODE_STANDARD)
    {
        /* Standard programming mode */ /*No need in standard mode */
        FLASH->CR2 |= FLASH_CR2_PRG;
        FLASH->NCR2 &= (uint8_t)(~FLASH_NCR2_NPRG);
    }
    else
    {
        /* Fast programming mode */
        FLASH->CR2 |= FLASH_CR2_FPRG;
        FLASH->NCR2 &= (uint8_t)(~FLASH_NCR2_NFPRG);
    }
这里是块相关

一周热门 更多>