女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

瑞薩e2studio----串口獲取數據通過SPI存儲于W25Q128外部flash

RA生態工作室 ? 2021-12-02 17:54 ? 次閱讀
pYYBAGGA3i6Af0z4AABdWrtWoBM374.png

1.概述

本篇文章主要介紹如何使用e2studio對瑞薩進行spi配置,同時移植stm32上的W25Q128到瑞薩上,同時通過對該FLASH進行讀寫操作,驗證是否正確。

2.硬件準備

首先需要準備一個開發板,這里我準備的是芯片型號 R7FA2L1AB2DFL 的開發板。

pYYBAGGLLTuAKokoAAL5D_IbQXA990.png

3.新建工程

1b66d376-51d1-11ec-a27f-dac502259ad0.png

4.工程模板

1bdd20ee-51d1-11ec-a27f-dac502259ad0.png

5.保存工程路徑

1c5da570-51d1-11ec-a27f-dac502259ad0.png

6.芯片配置

本文中使用R7FA2L1AB2DFL來進行演示。

1cde6494-51d1-11ec-a27f-dac502259ad0.png

7

7.工程模板選擇

1d8e86bc-51d1-11ec-a27f-dac502259ad0.png

8.SPI配置

點擊Stacks->New Stack->Driver->Connectivity->SPI Driver on r_spi。

1e004450-51d1-11ec-a27f-dac502259ad0.png

9.SPI屬性配置

1e8fc8fa-51d1-11ec-a27f-dac502259ad0.png

10.片選CS管腳設置

設置P103管腳為輸出管腳,作為CS片選。

1f47176c-51d1-11ec-a27f-dac502259ad0.png

11.設置E2STUDIO堆棧

1fd12614-51d1-11ec-a27f-dac502259ad0.png

12.e2studio的重定向printf設置

2048c692-51d1-11ec-a27f-dac502259ad0.png

C++ 構建->設置->GNU ARM Cross C Linker->Miscellaneous去掉Other linker flags中的 “--specs=rdimon.specs”

20f8c4f2-51d1-11ec-a27f-dac502259ad0.png

13.printf輸出重定向到串口

打印最常用的方法是printf,所以要解決的問題是將printf的輸出重定向到串口,然后通過串口將數據發送出去。

注意一定要加上頭文件#include

 
#ifdef __GNUC__                                 //串口重定向
    #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
    #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif

PUTCHAR_PROTOTYPE
{
        err = R_SCI_UART_Write(&g_uart0_ctrl, (uint8_t *)&ch, 1);
        if(FSP_SUCCESS != err) __BKPT();
        while(uart_send_complete_flag == false){}
        uart_send_complete_flag = false;
        return ch;
}

int _write(int fd,char *pBuffer,int size)
{
    for(int i=0;i;i++)>

14.stm32移植瑞薩說明

在STM32的W25Qx.h中,有個片選定義,代碼如下。


#define W25Qx_Enable()  HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_RESET)
#define W25Qx_Disable()     HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_SET)

修改后如下所示。

#define W25Qx_Enable()          R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_03, BSP_IO_LEVEL_LOW);
#define W25Qx_Disable()         R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_03, BSP_IO_LEVEL_HIGH);

在STM32的W25Qx.c中,有對數據進行發送和接受,代碼如下。

    /* Send the read status command */
    HAL_SPI_Transmit(&hspi1, cmd, 1, W25Qx_TIMEOUT_VALUE);  
    /* Reception of the data */
    HAL_SPI_Receive(&hspi1,&status, 1, W25Qx_TIMEOUT_VALUE);

修改后如下所示。

    /* Send the read status command */
    g_transfer_complete = false;
    err = R_SPI_Write(&g_spi0_ctrl, cmd, 1, SPI_BIT_WIDTH_8_BITS);
    assert(FSP_SUCCESS == err);
    /* Wait for SPI_EVENT_TRANSFER_COMPLETE callback event. */
    while (  g_transfer_complete==false)
    {
        ;
    }
    /* Reception of the data */
    g_transfer_complete = false;
    err = R_SPI_Read(&g_spi0_ctrl, &status, 1, SPI_BIT_WIDTH_8_BITS);
    assert(FSP_SUCCESS == err);
    /* Wait for SPI_EVENT_TRANSFER_COMPLETE callback event. */
    while (  g_transfer_complete==false)
    {
        ;
    }

15.W25Q128說明

W25Q128將16M的容量分為256個塊(Block),每個塊大小為64K字節,每個塊又分為16個扇區(Sector),每個扇區4K個字節。W25Q128的最小擦除單位為一個扇區,也就是每次必須擦除4K個字節。芯片ID如下所示。

  • 0XEF13,表示芯片型號為W25Q80
  • 0XEF14,表示芯片型號為W25Q16
  • 0XEF15,表示芯片型號為W25Q32
  • 0XEF16,表示芯片型號為W25Q64
  • 0XEF17,表示芯片型號為W25Q128

16.演示效果

開機會打印W25Q128的ID,ID為0XEF17,實際如下所示。

并且之前保存的數據也正確讀取出來了。

2187051e-51d1-11ec-a27f-dac502259ad0.png

定義數組DataBuff,其中DataBuff[0]表示寫入扇區, DataBuff[1]表示寫入位置,剩下的為寫入數據,同時以0xff結尾。

分別輸入數據 01 02 01 02 03 04 ff與02 20 aa bb cc dd ff

2259bd38-51d1-11ec-a27f-dac502259ad0.png2356134e-51d1-11ec-a27f-dac502259ad0.png

17.主程序代碼

#include "hal_data.h"
#include 
#include "W25Qx.h"
FSP_CPP_HEADER
void R_BSP_WarmStart(bsp_warm_start_event_t event);
FSP_CPP_FOOTER

void uart1_data(void);

#define BUFFERSIZE 255           //可以接收的最大字符個數
uint8_t ReceiveBuff[BUFFERSIZE]; //接收緩沖區
uint8_t recv_end_flag = 0,Rx_len=0;//接收完成中斷標志,接收到字符長度

uint8_t wData1[0x200];
uint8_t wData2[0x200];
uint8_t wData3[0x200];

uint8_t rData1[0x200];
uint8_t rData2[0x200];
uint8_t rData3[0x200];
uint8_t ID[4];
uint32_t i;

uint8_t flag[1] ;
int i_flag = 0;


fsp_err_t err = FSP_SUCCESS;
volatile bool uart_send_complete_flag = false;
uint8_t RxBuff[1];      //進入中斷接收數據的數組
uint8_t DataBuff[5000]; //保存接收到的數據的數組
int RxLine=0;           //接收到的數據長度
int Rx_flag=0;                  //接受到數據標志
int Rx_flag_finish=0;                  //接受完成或者時間溢出
void user_uart_callback (uart_callback_args_t * p_args)
{
    if(p_args->event == UART_EVENT_TX_COMPLETE)
    {
        uart_send_complete_flag = true;
    }

    if(p_args->event ==     UART_EVENT_RX_CHAR)
    {
        RxBuff[0] = p_args->data;
        RxLine++;                      //每接收到一個數據,進入回調數據長度加1
        DataBuff[RxLine-1]=RxBuff[0];  //把每次接收到的數據保存到緩存數組
        Rx_flag=1;
        Rx_len++;
        if(RxBuff[0]==0xff)            //接收結束標志位,這個數據可以自定義,根據實際需求,這里只做示例使用,不一定是0xff
        {
            Rx_flag_finish=1;
            Rx_len--;
        }
        RxBuff[0]=0;
    }
}

#ifdef __GNUC__                                 //串口重定向
    #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
    #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif

PUTCHAR_PROTOTYPE
{
        err = R_SCI_UART_Write(&g_uart1_ctrl, (uint8_t *)&ch, 1);
        if(FSP_SUCCESS != err) __BKPT();
        while(uart_send_complete_flag == false){}
        uart_send_complete_flag = false;
        return ch;
}

int _write(int fd,char *pBuffer,int size)
{
    for(int i=0;ievent)
    {
        g_transfer_complete = true;
    }
}
/*******************************************************************************************************************//**
 * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used.  This function
 * is called by main() when no RTOS is used.
 **********************************************************************************************************************/
void hal_entry(void)
{
    /* TODO: add your own code here */

    err = R_SCI_UART_Open(&g_uart1_ctrl, &g_uart1_cfg);
    assert(FSP_SUCCESS == err);
    err = R_SPI_Open(&g_spi0_ctrl, &g_spi0_cfg);
    assert(FSP_SUCCESS == err);
    printf("\r\n SPI-W25Q128 open\n");
    /*##-1- Read the device ID  ########################*/
    BSP_W25Qx_Init();//初始化W25Q128
    BSP_W25Qx_Read_ID(ID);//讀取ID
    if((ID[0] != 0xEF) | (ID[1] != 0x17))
    {
        printf("SPI-W25Q128 error");
    }
    else//ID正確,打印ID
    {
        printf("W25Q128 ID : ");
        for(i=0;i<2;i++)
        {
            printf("0x%02X ",ID[i]);
        }
        printf("\r\n\r\n");
    }

    /**************************讀取第1扇區數據**************************************************************/
     /*##-3- Read the flash     ########################*/
    /*讀取數據,rData讀取數據的指針,起始地址0x00,讀取數據長度0x200*/
    if(BSP_W25Qx_Read(rData1,0x0,0x200)== W25Qx_OK)
        printf("The first sector success\n");
    else
        printf("The first sector error\n");
    /*打印數據*/
    printf("The first sector data: \r\n");
    for(i =0;i<0x200;i++)
    {
        if(i%20==0)
            printf("\nThe first sector data[%d]--data[%d]: \r\n",i,i+19);
        printf("0x%02X  ",rData1[i]);
    }
        printf("\n");
    /**************************讀取第2扇區數據**************************************************************/
    /*##-3- Read the flash     ########################*/
    /*讀取數據,rData讀取數據的指針,起始地址0x1000,讀取數據長度0x200*/
     if(BSP_W25Qx_Read(rData2,0x1000,0x200)== W25Qx_OK)
         printf("The second sector success\n");
     else
         printf("The second sector error\n");
     /*打印數據*/
    printf("The second sector data: \r\n");

    for(i =0;i<0x200;i++)
    {
        if(i%20==0)
            printf("\nThe second sector data[%d]--data[%d]: \r\n",i,i+19);
        printf("0x%02X  ",rData2[i]);
        }
    printf("\n");
    /**************************讀取第3扇區數據**************************************************************/
    /*##-3- Read the flash     ########################*/
    /*讀取數據,rData讀取數據的指針,起始地址0x2000,讀取數據長度0x200*/
    if(BSP_W25Qx_Read(rData3,0x2000,0x200)== W25Qx_OK)
        printf("The third  sector success\n");
    else
        printf("The third  sector error\n");
    /*打印數據*/
     printf("The third  sector data: \r\n");
     for(i =0;i<0x200;i++)
    {
         if(i%20==0)
             printf("\nThe third  sector data[%d]--data[%d]: \r\n",i,i+19);
         printf("0x%02X  ",rData3[i]);
    }
    printf("\n");
    /**************************清除第1扇區數據為0**************************************************************/
    /*##-1- Erase Block ##################################*/
    if(BSP_W25Qx_Erase_Block(0) == W25Qx_OK)
        printf(" QSPI Erase Block ok\r\n");
    else
        printf("error\r\n");
    /*##-1- Written to the flash ########################*/
     /* fill buffer */
     printf(" Clear the first sector data[0]--data[0x200]\r\n");
     for(i =0;i<0x200;i ++)
     {
         wData1[i] = 0;
         rData1[i] = 0;
     }
     /*寫入數據,wData寫入數據的指針,起始地址0x00,寫入數據長度0x200*/
     if(BSP_W25Qx_Write(wData1,0x00,0x200)== W25Qx_OK)
         printf("Clear success\r\n");
     else
         printf("Clear error\r\n");

     /*##-1- Read the flash     ########################*/
     /*讀取數據,rData讀取數據的指針,起始地址0x00,讀取數據長度0x200*/
     if(BSP_W25Qx_Read(rData1,0x00,0x200)== W25Qx_OK)
         printf("Read the first sector data[0]--data[0x200]\r\n\r\n");
     else
         printf("Read error\r\n\r\n");
     /*打印數據*/
     printf("the first sector data[0]--data[0x200]: \r\n");
     for(i =0;i<0x200;i++)
     {
         if(i%20==0)
             printf("\ndata[%d]--data[%d]:\r\n",i,i+19);
         printf("0x%02X  ",rData1[i]);
     }
     printf("\n");
    /**************************清除第2扇區數據為0**************************************************************/
    /*##-2- Erase Block ##################################*/
    if(BSP_W25Qx_Erase_Block(0x1000) == W25Qx_OK)
        printf(" QSPI Erase Block ok\r\n");
    else
        printf("error\r\n");
    /*##-2- Written to the flash ########################*/
    /* fill buffer */
    printf(" Clear the second sector data[0]--data[0x200]\r\n");
    for(i =0;i<0x200;i ++)
    {
        wData2[i] = 0;
        rData2[i] = 0;
    }
    /*寫入數據,wData寫入數據的指針,起始地址0x1000,寫入數據長度0x200*/
    if(BSP_W25Qx_Write(wData2,0x1000,0x200)== W25Qx_OK)
        printf("Clear success\r\n");
    else
        printf("Clear error\r\n");
    /*##-2- Read the flash     ########################*/
    /*讀取數據,rData讀取數據的指針,起始地址0x00,讀取數據長度0x200*/
    if(BSP_W25Qx_Read(rData2,0x1000,0x200)== W25Qx_OK)
        printf("Read the second sector data[0]--data[0x200]\r\n\r\n");
    else
        printf("Read error\r\n\r\n");
    /*打印數據*/
    printf("the first sector data[0]--data[0x200]: \r\n");
    for(i =0;i<0x200;i++)
    {
        if(i%20==0)
            printf("\ndata[%d]--data[%d]:\r\n",i,i+19);
        printf("0x%02X  ",rData2[i]);
        }
    printf("\n");
    /**************************清除第3扇區數據為0**************************************************************/
    /*##-3- Erase Block ##################################*/
    if(BSP_W25Qx_Erase_Block(0x2000) == W25Qx_OK)
        printf(" QSPI Erase Block ok\r\n");
    else
        printf("error\r\n");
    /*##-3- Written to the flash ########################*/
    /* fill buffer */
    printf(" Clear the third sector data[0]--data[0x200]\r\n");
    for(i =0;i<0x200;i ++)
    {
        wData3[i] = 0;
        rData3[i] = 0;
    }
    /*寫入數據,wData寫入數據的指針,起始地址0x2000,寫入數據長度0x200*/
    if(BSP_W25Qx_Write(wData3,0x2000,0x200)== W25Qx_OK)
        printf("Clear success\r\n");
    else
        printf("Clear error\r\n");
    /*##-3- Read the flash     ########################*/
    /*讀取數據,rData讀取數據的指針,起始地址0x00,讀取數據長度0x200*/
    if(BSP_W25Qx_Read(rData3,0x2000,0x200)== W25Qx_OK)
        printf("Read the third sector data[0]--data[0x200]\r\n\r\n");
    else
        printf("Read error\r\n\r\n");
    /*打印數據*/
    printf("the first third data[0]--data[0x200]: \r\n");
    for(i =0;i<0x200;i++)
    {
        if(i%20==0)
            printf("\ndata[%d]--data[%d]:\r\n",i,i+19);
        printf("0x%02X  ",rData3[i]);
    }
                printf("\n");
    while(1)
    {
        uart1_data();
        R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS); // NOLINT100->160
    }
#if BSP_TZ_SECURE_BUILD
    /* Enter non-secure code */
    R_BSP_NonSecureEnter();
#endif
}



void uart1_data(void)
{
    if(Rx_flag_finish ==1)//接收完成標志
    {
        if(DataBuff[0]==0x01)
        {
            printf("LENGTH:%d\n",Rx_len-2);
            for(int i =0;i;i++)>;i++)>


聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • mcu
    mcu
    +關注

    關注

    146

    文章

    17831

    瀏覽量

    360307
  • ARM
    ARM
    +關注

    關注

    134

    文章

    9305

    瀏覽量

    374964
  • 嵌入式
    +關注

    關注

    5141

    文章

    19526

    瀏覽量

    314861
  • 開發板
    +關注

    關注

    25

    文章

    5503

    瀏覽量

    102202
收藏 人收藏

    評論

    相關推薦
    熱點推薦

    RA單片機在e2 studio環境下printf編譯出錯的問題解析

    最近看到有一些網友在討論關于:RA單片機在e2 studio環境下printf編譯出錯的問題。
    的頭像 發表于 05-24 15:51 ?512次閱讀
    <b class='flag-5'>瑞</b><b class='flag-5'>薩</b>RA單片機在<b class='flag-5'>e2</b> <b class='flag-5'>studio</b>環境下printf編譯出錯的問題解析

    【RA-Eco-RA4M2開發板評測】初學-使用flash programmer燒錄程序

    本人剛入坑不久,對單片機的熱情很高,于是也加入了的板子申請隊伍,很榮幸也成為了試用者之一,此前對于的板子從未接觸過,包括對于使用e2stud
    發表于 04-29 17:28

    【RA-Eco-RA4M2開發板評測】試用flash programmer燒錄

    本人剛入坑不久,對單片機的熱情很高,于是也加入了的板子申請隊伍,很榮幸也成為了試用者之一,此前對于的板子從未接觸過,包括對于使用e2stud
    發表于 04-28 19:12

    RA2L1入門學習】+e2_studio軟件安裝及使用

    一、e2_studio軟件安裝及使用 注冊e2 studio | Renesas 電子 下載軟件 安裝 4.創建工程 更改工程位置 新
    發表于 03-27 13:25

    e2studio和Keil簡介及如何安裝e2studio開發環境

    (簡稱為e2e2s)是電子的一款包含代碼開發、構建和調試的開發工具。e2studio基于開
    的頭像 發表于 03-13 17:27 ?1009次閱讀
    <b class='flag-5'>e</b>2<b class='flag-5'>studio</b>和Keil簡介及如何安裝<b class='flag-5'>e</b>2<b class='flag-5'>studio</b>開發環境

    **RA2L1入門學習】+**UART測試實驗

    RA2L1入門學習】+UART測試實驗 本篇文章主要介紹如何使用e2studio單片
    發表于 03-09 15:45

    RA2L1入門學習】00. 開箱 + 點燈

    常用到的。 【點燈】 開發MCU是要用到E2 Studio的(簡稱e2s)來開發以及編譯程序。通過
    發表于 03-07 11:07

    e2studio(1)----芯片之搭建FSP環境

    視頻教學 樣品申請 請勿添加外鏈 e2studio軟件 e2studio的集成開發環境,FSP 提供了眾多可提高效率的工具,用于開發針對
    發表于 09-30 15:28

    STM32CUBEMX(13)--SPIW25Q128外部Flash移植

    上節省空間,提供方便,正是出于這種簡單易用的特性,越來越多的芯片集成了這種通信協議,比如 EEPROM,FLASH,實時時鐘,AD轉換器。 W25Q128 是一款SPI接口的Flash
    發表于 09-30 14:41

    物聯網行業中Nor Flash的軟件設計分享_W25Q128的軟件設計方案

    一 概述 W25Q128是一種NOR Flash芯片,掉電后數據不丟失的特點。 W25Q128FV陣列被組織成65,536個可編程頁面,每個頁面256字節。每次最多可編程256字節。可
    的頭像 發表于 09-26 11:20 ?1146次閱讀
    物聯網行業中Nor <b class='flag-5'>Flash</b>的軟件設計分享_<b class='flag-5'>W25Q128</b>的軟件設計方案

    W25Q128FV中文手冊

    W25Q128FV(128Mbit)型串行 Flash 存儲器面向受限于空間、引腳和功耗的系統,提供了一種存儲解決方案。
    發表于 09-18 11:33 ?17次下載

    e2studio----SPI速率解析

    在嵌入式系統的設計中,串行外設接口(SPI)的通信速率是一個關鍵參數,它直接影響到系統的性能和穩定性。電子的RA4M2微控制器為開發者提供了靈活而強大的
    的頭像 發表于 08-08 17:00 ?2207次閱讀
    <b class='flag-5'>瑞</b><b class='flag-5'>薩</b><b class='flag-5'>e2studio----SPI</b>速率解析

    如何使用e2studio單片機進行GPIO輸出

    本篇文章主要介紹如何使用e2studio單片機進行GPIO輸出,并以LED顯示。
    的頭像 發表于 07-30 16:12 ?1053次閱讀
    如何使用<b class='flag-5'>e2studio</b>對<b class='flag-5'>瑞</b><b class='flag-5'>薩</b>單片機進行GPIO輸出

    ESP32外部flashspi外設沖突怎么解決?

    硬件: ESP32 ,W25Q128 SPI顯示器 庫:IDF4.0.1 使用hspi掛載了外部16MB的W25Q128,并同時掛載了SPI
    發表于 06-25 06:19

    【GD32H757Z海棠派開發板使用手冊】第十一講 SPI-SPI NOR FLASH讀寫實驗

    通過本實驗主要學習以下內容: ?SPI簡介 ?GD32H7 SPI簡介 ?SPI NOR FLASH——GD
    的頭像 發表于 06-04 11:42 ?1728次閱讀
    【GD32H757Z海棠派開發板使用手冊】第十一講 <b class='flag-5'>SPI-SPI</b> NOR <b class='flag-5'>FLASH</b>讀寫實驗