FSPを使用して、イーサネットテストプログラムを作成しました。
リンク検出は動作するのですが、送信してもTX_ENピンなどが動作しません。
FAQ 2001354
ja-support.renesas.com/.../20542987
を見つけて、レジスタを調べると記述と同じ問題が起きていました。
ldファイル・cファイルについてはFSP側で対策されているらしく、自動生成されています。
サポート記述に 【ユーザの外部デバッグプローブハードウェアがRA Serial Bootインターフェース接続をサポートしていない場合は、別途シリアル変換ケーブルなどを用意し、RFP(Renesas Flash Programmer)を使用してプログラムすることもできます(図4)。】と書いてあるのですが、
[RA Serial Bootインターフェース接続をサポートしていない]デバッグプローブとはどれのことかわかりますでしょうか?
現状、E2Liteを使用しております。
書き込み方法による 動作不良
上記スレッドと関連する可能性があると思います。
TrustZone対応マイコンは、フラッシュオプションでSRAMのセキュア/非セキュア領域の設定があります。EDMACで使用するメモリ(送受信バッファやディスクリプタ)は「非セキュア」な領域に配置されなれければなりません。
(メモリの配置アドレスと非セキュア領域のBoundary設定が妥当でなければ、Etherが動きません。)
フラッシュオプションの(Boundary領域)変更は、ブートモードで接続して設定する必要があります。E2Liteは、ブートモード接続に対応しています。RFP(RenesasFlashProgrammer)での接続時、「2-wire UART」を選んで接続してください。(SWD接続の場合は、ブートモード接続にならないので、フラッシュオプションの変更が出来ません。)
([RA Serial Bootインターフェース接続をサポートしていない]デバッグプローブが具体的にどの様なデバッガを指してるのかは判りません。E2, E2Lite, J-Linkなどは、ブートモード接続をサポートしています。USB-Serial変換ケーブルなども、ブートモード接続に使えます。)
ありがとうございます。まさしくこれだと思います。
-------------生成されていたrpd--------------
RAM_S_SIZE=0x3e000RAM_C_SIZE=0x0FLASH_S_SIZE=0x100000FLASH_C_SIZE=0x0DATA_FLASH_S_SIZE=0x2000OPTION_SETTING_S_SIZE=0x80OPTION_SETTING_S_S_SIZE=0xd0ID_CODE_S_SIZE=0x0SDRAM_S_SIZE=0x0QSPI_FLASH_S_SIZE=0x0OSPI_DEVICE_0_S_SIZE=0x0OSPI_DEVICE_1_S_SIZE=0x0
--------------読みだしたTrustZone設定--------------
Current TrustZone device status
DLM state : Secure Software Development (SSD)
Debug level : 2
Secure/NSC memory partition size :
- Code Flash Secure (kB) : 16383
- Code Flash NSC (kB) : 0
- Data Flash Secure (kB) : 63
- SRAM Secure (kB) : 2047
- SRAM NSC (kB) : 0
試しにRAM_S_SIZEとRAM_C_SIZEを入れ替えてみましたが、読みだしたTrustZone設定は変わっていませんでした。
現状、rpdファイルをどう設定するのが適切なのかよくわかっていない状態です。
何か参考になる資料をご存知でしょうか
(Ethernet動作させたいだけなのでTrustZone自体を無効化できるとよいのですが)
設定書き込めました。
Boundaryの設定オプションを"設定する"だけで行けると思ってました。
操作設定のフラッシュオプション書込みもチェックが必要というのに気づいていませんでした。
MAPファイルを見て設定したけどまだ動作していません。(ADEが出る)
(1)rpdファイルをRFPに与える
(2)rpdファイルの内容を値に反映させる
RAM_S_SIZE=0x1800 →6kBRAM_C_SIZE=0x800 →2kBFLASH_S_SIZE=0x4400 →17kBFLASH_C_SIZE=0x3c00 →15kBDATA_FLASH_S_SIZE=0x0 →0kB
(1)(2)どちらかの設定の後で
上記「フラッシュオプションの書き込み」チェックを入れて「スタート」です。
(書き込みはうまく行ったとの事ですが、将来同じ様な問題ではまった人向けの情報です、参考まで)
(期待した動作にならないとの事ですが、挙動が変わったのなら、SRAMの非セキュアの問題はクリアされたのかも?とも思います。)
ether_do_link内の
/* Enable EDMAC receive */
p_reg_edmac->EDRRR = 0x1;
上記を実行した際にEtherC-EDMAのEESR(ステータス)にADE(アドレスエラー)が出ている状態です。
TrustZoneエラーフィルタを確認するとエラーになっているので正しく設定できていないのかもしれません。
現状、Secure:248kb Non-Secure:8kbに設定しています。
------------------------------------以下 mapファイル------------------------------------
0x00002000 RAM_NS_BUFFER_BLOCK_LENGTH = DEFINED (RAM_NS_BUFFER_LENGTH)?ALIGN (RAM_NS_BUFFER_LENGTH, 0x2000):0x0
0x00000c40 RAM_NS_BUFFER_LENGTH = DEFINED (RAM_NS_BUFFER_LENGTH)?RAM_NS_BUFFER_LENGTH:0x0
0x2003f3c0 RAM_NS_BUFFER_START = ((RAM_START + RAM_LENGTH) - RAM_NS_BUFFER_LENGTH)
0x2003e000 RAM_NS_BUFFER_BLOCK_START = ((RAM_START + RAM_LENGTH) - RAM_NS_BUFFER_BLOCK_LENGTH)
ちょっと試してみましたが、私の環境でも
FSPでEtherのスタックを追加した単純なプロジェクトを作成してビルドすると、
SRAM_Secure 248kB
SRAM_NSC 0kB
SRAM_Non-Secure 8kB
になりました。その値をマイコンチップに反映させました。
mapファイルでEDMACがアクセスするバッファの配置アドアレスを確認しましたが、
.ns_buffer.eth 0x2003f3e0 0xc20 ./ra_gen/hal_data.o 0x2003f3e0 g_ether0_tx_descriptors 0x2003f3f0 g_ether0_rx_descriptors 0x2003f400 g_ether0_ether_buffer0 0x2003fa00 g_ether0_ether_buffer1
SRAM_Non-Secure 8kB内に配置されていましたので、Boundaryの問題はありません。
Fullscreen hal_entry.c.txt Download #include "hal_data.h" #define ETHER_EXAMPLE_MAXIMUM_ETHERNET_FRAME_SIZE (1514) #define ETHER_EXAMPLE_TRANSMIT_ETHERNET_FRAME_SIZE (60) #define ETHER_EXAMPLE_SOURCE_MAC_ADDRESS 0x74, 0x90, 0x50, 0x00, 0x79, 0x01 #define ETHER_EXAMPLE_DESTINATION_MAC_ADDRESS 0x74, 0x90, 0x50, 0x00, 0x79, 0x02 #define ETHER_EXAMPLE_FRAME_TYPE 0x00, 0x2E #define ETHER_EXAMPLE_PAYLOAD 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ /* Receive data buffer */ static uint8_t gp_read_buffer[ETHER_EXAMPLE_MAXIMUM_ETHERNET_FRAME_SIZE] = {0}; /* Transmit data buffer */ static uint8_t gp_send_data[ETHER_EXAMPLE_TRANSMIT_ETHERNET_FRAME_SIZE] = { ETHER_EXAMPLE_DESTINATION_MAC_ADDRESS, /* Destination MAC address */ ETHER_EXAMPLE_SOURCE_MAC_ADDRESS, /* Source MAC address */ ETHER_EXAMPLE_FRAME_TYPE, /* Type field */ ETHER_EXAMPLE_PAYLOAD /* Payload value (46byte) */ }; FSP_CPP_HEADER void R_BSP_WarmStart(bsp_warm_start_event_t event); FSP_CPP_FOOTER /*******************************************************************************************************************//** * 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 */ fsp_err_t err = FSP_SUCCESS; //PHY chip RESET R_PORT4->PODR_b.PODR5 = 0; R_PORT4->PDR_b.PDR5 = 1; R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS); R_PORT4->PODR_b.PODR5 = 1; R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS); /* Source MAC Address */ static uint8_t mac_address_source[6] = {ETHER_EXAMPLE_SOURCE_MAC_ADDRESS}; uint32_t read_data_size = 0; //g_ether0_cfg.p_mac_address = mac_address_source; /* Open the ether instance with initial configuration. */ err = R_ETHER_Open(&g_ether0_ctrl, &g_ether0_cfg); /* Handle any errors. This function should be defined by the user. */ assert(FSP_SUCCESS == err); do { /* When the Ethernet link status read from the PHY-LSI Basic Status register is link-up, * Initializes the module and make auto negotiation. */ err = R_ETHER_LinkProcess(&g_ether0_ctrl); } while (FSP_SUCCESS != err); /* Transmission is non-blocking. */ /* User data copy to internal buffer and is transferred by DMA in the background. */ err = R_ETHER_Write(&g_ether0_ctrl, (void *) gp_send_data, sizeof(gp_send_data)); assert(FSP_SUCCESS == err); /* received data copy to user buffer from internal buffer. */ err = R_ETHER_Read(&g_ether0_ctrl, (void *) gp_read_buffer, &read_data_size); assert(FSP_SUCCESS == err); /* Disable transmission and receive function and close the ether instance. */ R_ETHER_Close(&g_ether0_ctrl); while(1) { __NOP(); } #if BSP_TZ_SECURE_BUILD /* Enter non-secure code */ R_BSP_NonSecureEnter(); #endif } /*******************************************************************************************************************//** * This function is called at various points during the startup process. This implementation uses the event that is * called right before main() to set up the pins. * * @param[in] event Where at in the start up process the code is currently at **********************************************************************************************************************/ void R_BSP_WarmStart(bsp_warm_start_event_t event) { if (BSP_WARM_START_RESET == event) { #if BSP_FEATURE_FLASH_LP_VERSION != 0 /* Enable reading from data flash. */ R_FACI_LP->DFLCTL = 1U; /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */ #endif } if (BSP_WARM_START_POST_C == event) { /* C runtime environment and system clocks are setup. */ /* Configure pins. */ R_IOPORT_Open (&IOPORT_CFG_CTRL, &IOPORT_CFG_NAME); #if BSP_CFG_SDRAM_ENABLED /* Setup SDRAM and initialize it. Must configure pins first. */ R_BSP_SdramInit(true); #endif } } #if BSP_TZ_SECURE_BUILD FSP_CPP_HEADER BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable (); /* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */ BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable () { } FSP_CPP_FOOTER #endif void ether_callback(ether_callback_args_t * p) { __NOP(); }
#include "hal_data.h" #define ETHER_EXAMPLE_MAXIMUM_ETHERNET_FRAME_SIZE (1514) #define ETHER_EXAMPLE_TRANSMIT_ETHERNET_FRAME_SIZE (60) #define ETHER_EXAMPLE_SOURCE_MAC_ADDRESS 0x74, 0x90, 0x50, 0x00, 0x79, 0x01 #define ETHER_EXAMPLE_DESTINATION_MAC_ADDRESS 0x74, 0x90, 0x50, 0x00, 0x79, 0x02 #define ETHER_EXAMPLE_FRAME_TYPE 0x00, 0x2E #define ETHER_EXAMPLE_PAYLOAD 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ /* Receive data buffer */ static uint8_t gp_read_buffer[ETHER_EXAMPLE_MAXIMUM_ETHERNET_FRAME_SIZE] = {0}; /* Transmit data buffer */ static uint8_t gp_send_data[ETHER_EXAMPLE_TRANSMIT_ETHERNET_FRAME_SIZE] = { ETHER_EXAMPLE_DESTINATION_MAC_ADDRESS, /* Destination MAC address */ ETHER_EXAMPLE_SOURCE_MAC_ADDRESS, /* Source MAC address */ ETHER_EXAMPLE_FRAME_TYPE, /* Type field */ ETHER_EXAMPLE_PAYLOAD /* Payload value (46byte) */ }; FSP_CPP_HEADER void R_BSP_WarmStart(bsp_warm_start_event_t event); FSP_CPP_FOOTER /*******************************************************************************************************************//** * 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 */ fsp_err_t err = FSP_SUCCESS; //PHY chip RESET R_PORT4->PODR_b.PODR5 = 0; R_PORT4->PDR_b.PDR5 = 1; R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS); R_PORT4->PODR_b.PODR5 = 1; R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS); /* Source MAC Address */ static uint8_t mac_address_source[6] = {ETHER_EXAMPLE_SOURCE_MAC_ADDRESS}; uint32_t read_data_size = 0; //g_ether0_cfg.p_mac_address = mac_address_source; /* Open the ether instance with initial configuration. */ err = R_ETHER_Open(&g_ether0_ctrl, &g_ether0_cfg); /* Handle any errors. This function should be defined by the user. */ assert(FSP_SUCCESS == err); do { /* When the Ethernet link status read from the PHY-LSI Basic Status register is link-up, * Initializes the module and make auto negotiation. */ err = R_ETHER_LinkProcess(&g_ether0_ctrl); } while (FSP_SUCCESS != err); /* Transmission is non-blocking. */ /* User data copy to internal buffer and is transferred by DMA in the background. */ err = R_ETHER_Write(&g_ether0_ctrl, (void *) gp_send_data, sizeof(gp_send_data)); assert(FSP_SUCCESS == err); /* received data copy to user buffer from internal buffer. */ err = R_ETHER_Read(&g_ether0_ctrl, (void *) gp_read_buffer, &read_data_size); assert(FSP_SUCCESS == err); /* Disable transmission and receive function and close the ether instance. */ R_ETHER_Close(&g_ether0_ctrl); while(1) { __NOP(); } #if BSP_TZ_SECURE_BUILD /* Enter non-secure code */ R_BSP_NonSecureEnter(); #endif } /*******************************************************************************************************************//** * This function is called at various points during the startup process. This implementation uses the event that is * called right before main() to set up the pins. * * @param[in] event Where at in the start up process the code is currently at **********************************************************************************************************************/ void R_BSP_WarmStart(bsp_warm_start_event_t event) { if (BSP_WARM_START_RESET == event) { #if BSP_FEATURE_FLASH_LP_VERSION != 0 /* Enable reading from data flash. */ R_FACI_LP->DFLCTL = 1U; /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */ #endif } if (BSP_WARM_START_POST_C == event) { /* C runtime environment and system clocks are setup. */ /* Configure pins. */ R_IOPORT_Open (&IOPORT_CFG_CTRL, &IOPORT_CFG_NAME); #if BSP_CFG_SDRAM_ENABLED /* Setup SDRAM and initialize it. Must configure pins first. */ R_BSP_SdramInit(true); #endif } } #if BSP_TZ_SECURE_BUILD FSP_CPP_HEADER BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable (); /* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */ BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable () { } FSP_CPP_FOOTER #endif void ether_callback(ether_callback_args_t * p) { __NOP(); }
FSPのオンラインマニュアルのBasic Exampleをコピペして実行しましたが、
EDRRR = 0x1;
の箇所では、アドレスエラーにはなりませんでした。
err = R_ETHER_Write(&g_ether0_ctrl, (void *) gp_send_data, sizeof(gp_send_data));
Etherのパケットを観測すると上記箇所で、
#define ETHER_EXAMPLE_SOURCE_MAC_ADDRESS 0x74, 0x90, 0x50, 0x00, 0x79, 0x01#define ETHER_EXAMPLE_DESTINATION_MAC_ADDRESS 0x74, 0x90, 0x50, 0x00, 0x79, 0x02
で定義したMACアドレスの通信が行われており、問題無く動作していると思われます。
ありがとうございます。
を見て勘違いに気づきました。
Renesas Flash Programmerにて
SRAM Secure Size : 248kb
SRAM Non-secure calable Size : 8kb
にしていました。8kb -> 0kbにしたところ動作しました。
ちゃんと読んどけばもっと早く気が付けたはず。
確認ありがとうございました。