PN7462AUHN SPIM问题

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PN7462AUHN SPIM问题

10,366 Views
onlineit
Contributor II

操作SPIM外部的FLASH时,会出现死机现象,没有任何反应,程序在运行到phhalSPIM_Transmit时死机,代码如下:

#define PH_HW_SPIM_TIMEOUT 0xFFFFFFFFUL
#define PH_HW_SPIM_SLAVE 0
#define PH_HW_SPIM_INIT_CRC 0 /* Flag to initialize internal CRC */
#define PH_HW_SPIM_APPEND_CRC 0 /* Flag to say appending of CRC is to be done for Tx bytes
or not, if 1 then CRC is to be appended else not. */
#define PH_HW_SPIM_CRC_INIT 0 /* Transmit CRC initial value. */
#define PH_HW_SPIM_CRC_OFFSET 0 /* Number of bytes to be skipped for CRC computation. */
#define PH_HW_SPIM_MSB_FIRST 1 /* MSB or LSB selection flag. if true MSB transmitted first. */
#define PH_HW_SPIM_NSSPULSE 1 /* NSS pulse control. If false no pulse is generated between the bytes. */
#define PH_HW_SPIM_NSSPOL 0 /* NSS polarity control. If false the polarity is low. */
#define PH_HW_SPIM_MODE 0x00 /**< Mode = 0 CPOL = 0 CPHA = 0 */
#define PH_HW_SPIM_BAUDRATE 0x06 /** b110 5.42MHz */

phStatus_t eStatus = PH_ERR_SUCCESS;
uint8_t cBuffer[32]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,\
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F};
uint16_t wLength;

/** Init and Configure SPIM as Egress communication channel */
PH_USER_ASSERT(phhalSPIM_Init(PH_HW_SPIM_TIMEOUT) == PH_ERR_SUCCESS);

PH_USER_ASSERT(
phhalSPIM_Configure(PH_HW_SPIM_SLAVE, PH_HW_SPIM_MSB_FIRST, \
PH_HW_SPIM_MODE, PH_HW_SPIM_BAUDRATE, \
PH_HW_SPIM_NSSPULSE, PH_HW_SPIM_NSSPOL) == PH_ERR_SUCCESS);

cBuffer[0] = 0x4B;
wLength = 1;
eStatus = phhalSPIM_Transmit(PH_HW_SPIM_SLAVE,\
PH_HW_SPIM_INIT_CRC, \
PH_HW_SPIM_APPEND_CRC,\
PH_HW_SPIM_CRC_INIT, \
wLength, cBuffer, \
PH_HW_SPIM_CRC_OFFSET);

wLength = 5;
eStatus = phhalSPIM_Receive(PH_HW_SPIM_SLAVE, \
PH_HW_SPIM_INIT_CRC, \
PH_HW_SPIM_CRC_INIT, \
wLength,cBuffer, \
PH_HW_SPIM_CRC_OFFSET);

我看了一个PN7462BM开发板的连接,是用GPIO_1去连接到FLASH的NSS片选信号,我用的是PN7462的SPIM_SSN去连接SPI Flash,型号为W25Q32FVSSIG,读Flash ID的命令都无法发出,请问是什么问题?

以前用过LPC的SPI,发现SPI的NSS片选信号不是太好用,难道NXP官方也发现了这个问题,在其PN7462BM开发板上未连接SPIM_SSN,而是用GPIO1作为SPI FLASH的片选信号(SSN)?

能否给出一个详细的例程?

Tags (1)
0 Kudos
16 Replies

9,871 Views
onlineit
Contributor II

PN7462AUHN_SPIM_S25FL216K.png

0 Kudos

9,871 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Xia,

Thanks for the information! Referring to the spec, you can not directly use phhalSPIM_Transmit() and phhalSPIM_Receive() to implement above timing as there is NSS pulse between them, please use NSS_VAL and NSS_CTRL to perform the right timing.

Please refer to the following for more details.

pastedImage_1.png

pastedImage_2.png

Hope that helps,


Have a great day,
Kan

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

9,871 Views
onlineit
Contributor II

Hi Kan_Li &#21592;&#24037; ,

        在SPI初始化时设置NSS_CTRL=1,NSS_VAL=0,后,读写时只是SPIM_NSS信号的片选信号的低电平拖尾时间长了250uS,在PNEV7462BM开发板上还是读不出Flash的任何东西。而且只要设置了NSS_CTRL=1,在PH_HW_SPIM_NSSPOL 为0的情况下,NSS_VAL的值不受影响,设为0和设为1结果一样,不信你可以测一下,用示波器量一下NSS波形。

       个人认为PN7462AUHN SPIM的硬件设计是有缺陷的,NSS不能通过GPIO的方式去控制,因为一旦切换为GPIO方式,SPIM的其它信号也是GPIO方式了。NSS自动控制的方式在NXP的其它CPU也是不行的,最终都是通过GPIO的方式才能解决问题。

0 Kudos

9,871 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hello,

I just wrote a doc on that topic, please kindly refer to Guide For Creating PN7462 SPIM demo based on NFC reader library for details.

Hope that helps,


Have a great day,
Kan

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

9,871 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Xia,

Did you make sure you use the SPIM module properly before complaining the device hardware design? actually we have customers use PN7462 to interface with some similar flash device, and they implement the timing with the help of NSS_CTRL and NSS_VAL, and there is no issue with the application, but they implement the read/write API by their own code, maybe that is the difference from you. Did you still use phhalSPIM_Transmit() and phhalSPIM_Receive() to implement the timing? Please note they are Rom based API, and they will clear NSS_CTRL for proper operation as it should be.

I will test it as well based on PNEV7462BM, but this board was sent to other member for a test. I will get it back next week, and hope I make the demo ready next week as well.

Thanks for your patience!

BTW, can we continue the discussion in English? You know, there are users from other countries in our community, and they might also have met/solved similar issue, and your experience is also helpful for others. That is the main purpose of our community.

Thanks for your understanding!


Have a great day,
Kan

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

9,871 Views
onlineit
Contributor II

Hi Kan_Li &#21592;&#24037;,

       函数phStatus_t phhalSPIM_SetWaterLevel(uint16_t wWaterLevel, pphhalSPIM_CallbackFun_t pCallBackFunc);没有使用的例子,NXP官方有关于SPI应用的完整例程吗?

      我使用的FLASH为华帮的W25Q32 SPI Flash,见附图。

      https://community.nxp.com/servlet/JiveServlet/download/498865-1-443811/PN7462AUHN_SPIFLASH.png 

0 Kudos

9,874 Views
Kan_Li
NXP TechSupport
NXP TechSupport

No, there is no ready demo contains phStatus_t phhalSPIM_SetWaterLevel(uint16_t wWaterLevel, pphhalSPIM_CallbackFun_t pCallBackFunc), but you may refer to the api guide before using this function, and it is a recommended process for any api in the NFC reader library. Please refer to the following for details.

pastedImage_1.png

I also checked the flash device you use, and found there is some issue in your implementation.

pastedImage_2.png

you just sent 1 byte of 4B by calling phhalSPIM_Transmit(), missing 4 bytes of dummy byte, that might be the root cause, and further more, to receive the whole UID, you must set 8 bytes to phhalSPIM_Receive(), not 5 bytes as above.

Hope that helps,


Have a great day,
Kan

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

9,874 Views
onlineit
Contributor II

Hi Kan_Li &#21592;&#24037; ,

      用下面的代码读写PNEV7462B开发板,有输出和片选信号及SI信号,但SO信号没有,根本读不到S25FL216K的JEDEC ID。

代码如下:

#define PH_HW_SPIM_TIMEOUT 0xFFFFFFFFUL
#define PH_HW_SPIM_SLAVE 1        /*0:SPIM_SSN,1:GPIO1*/
#define PH_HW_SPIM_INIT_CRC 0 /* Flag to initialize internal CRC */
#define PH_HW_SPIM_APPEND_CRC 0 /* Flag to say appending of CRC is to be done for Tx bytes
or not, if 1 then CRC is to be appended else not. */
#define PH_HW_SPIM_CRC_INIT 0 /* Transmit CRC initial value. */
#define PH_HW_SPIM_CRC_OFFSET 0 /* Number of bytes to be skipped for CRC computation. */
#define PH_HW_SPIM_MSB_FIRST 1 /* MSB or LSB selection flag. if true MSB transmitted first. */
#define PH_HW_SPIM_NSSPULSE 0 /* NSS pulse control. If false no pulse is generated between the bytes. */
#define PH_HW_SPIM_NSSPOL 0 /* NSS polarity control. If false the polarity is low. */
#define PH_HW_SPIM_MODE 0x00 /**< Mode = 0 CPOL = 0 CPHA = 0 */
#define PH_HW_SPIM_BAUDRATE 0x06 /** b110 5.42MHz */

    phStatus_t eStatus = PH_ERR_SUCCESS;
    uint8_t cBuffer[64];
    uint16_t wLength;
    uint32_t wRegValue;

    PH_USER_ASSERT(phhalSPIM_Init(PH_HW_SPIM_TIMEOUT) == PH_ERR_SUCCESS);
    PH_USER_ASSERT(
                    phhalSPIM_Configure(PH_HW_SPIM_SLAVE, PH_HW_SPIM_MSB_FIRST,                 \
                                    (phhalSPIM_Modes_t) gpkphCfg_EE_HW_SPIM->bModes, gpkphCfg_EE_HW_SPIM->bDataRate,  \
                                    PH_HW_SPIM_NSSPULSE, PH_HW_SPIM_NSSPOL) == PH_ERR_SUCCESS);        


    cBuffer[0] = 0x9F;
    wLength = 1;
    phUser_Wait(100);
    eStatus = phhalSPIM_Transmit(PH_HW_SPIM_SLAVE,\
    PH_HW_SPIM_INIT_CRC, \
    PH_HW_SPIM_APPEND_CRC,\
    PH_HW_SPIM_CRC_INIT, \
    wLength, cBuffer, \
    PH_HW_SPIM_CRC_OFFSET);

    phUser_Wait(50000);
    wLength = 3;
    eStatus = phhalSPIM_Receive(PH_HW_SPIM_SLAVE, \
    PH_HW_SPIM_INIT_CRC, \
    PH_HW_SPIM_CRC_INIT, \
    wLength,cBuffer, \
    PH_HW_SPIM_CRC_OFFSET);
    phUser_Wait(5000);        

PNEV7462B开发板Flash连接图如下:

  

0 Kudos

9,870 Views
Kan_Li
NXP TechSupport
NXP TechSupport

What are the values set for "(phhalSPIM_Modes_t) gpkphCfg_EE_HW_SPIM->bModes" and  "gpkphCfg_EE_HW_SPIM->bDataRate" ?  Please kindly clarify.


Have a great day,
Kan

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

9,870 Views
onlineit
Contributor II

Hi Kan_Li &#21592;&#24037; ,

        能否在PNEV7462BM开发板的基础上,写一段代码,随便读一个ID号或什么的,把代码贴出来参考一下?

0 Kudos

9,870 Views
onlineit
Contributor II

Hi Kan_Li &#21592;&#24037; ,

   

          最早用如下的代码配置SPIM也不行,才弄成上面的代码,把人都搞晕了。

          刚测试了不行,读出来的结果还是0x00,没有变化。代码如下:

#define PH_HW_SPIM_MODE 0x00 /**< Mode = 0 CPOL = 0 CPHA = 0 */
#define PH_HW_SPIM_BAUDRATE 0x06 /** b110 5.42MHz */

            PH_USER_ASSERT(
                            phhalSPIM_Configure(PH_HW_SPIM_SLAVE, PH_HW_SPIM_MSB_FIRST,                 \
                                            PH_HW_SPIM_MODE, PH_HW_SPIM_BAUDRATE,  \
                                            PH_HW_SPIM_NSSPULSE, PH_HW_SPIM_NSSPOL) == PH_ERR_SUCCESS);   

0 Kudos

9,872 Views
onlineit
Contributor II

放在phExCcid_SystemTask代码最前面就不会死机了,主要是操作系统还没启动。

PNEV7462B开发板的SPIM_NSS是连接到GPIO1的,在预定义中:

#define PH_HW_SPIM_SLAVE 1        /*0:SPIM_SSN,1:GPIO1*/

要定义为slave1才OK,访问Flash我看到NSS、SCK、MOSI都有波形,就MISO没有输出,输出一直为低电平,读FLASH ID没有任何反应。官方没有操作SPI外部设备的demo,能否提供一下demo?

0 Kudos

9,868 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hello Xia,

I am sorry, but there is no SPIM demo available so far, while the APIs are used in the demo of "PN7462AU_ex_phExHif", in the file of "phExHif_Hw.c", and alternatively you may refer to the api guide along with the NFC reader lib, please refer to the following for details.

pastedImage_9.png

BTW, would you specify the flash you use on your board? I may help to check if there is any implementation issue in your code.


Have a great day,
Kan

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

9,867 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hello Xia,

How to reproduce this issue? Would you please provide more details on that? Thanks for your patience!


Have a great day,
Kan

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

9,872 Views
onlineit
Contributor II

死机是因为代码放的位置不对,程序在wStatus = phhalSPIM_EventWait();位置出现异常。

0 Kudos

9,872 Views
Kan_Li
NXP TechSupport
NXP TechSupport

There are phhalSPIM_EventWait() calls in both phhalSPIM_Transmit() and phhalSPIM_Receive(), which one are you referring to?

BTW, on our demo board, NSS of SPIM is connected with some display module. Please refer to the following for details.

pastedImage_1.png


Have a great day,
Kan

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos