R7FA4M2AD Issue with DTC and SCI9 – Master TrustZone Filter Error

Hello All,

I'm new to Renesas and currently working on configuring SCI9 as a UART to transmit and receive data.

Transmission and reception work fine, but I'm encountering issues when I try to use the DTC.

Specifically, I'm getting a Master TrustZone Filter Error, even though I am not intentionally using TrustZone.
When I check SAU.SFAR, I see the address 0x40118903, which points to &PBP_SCI->TDR.

Do I need to disable something if I'm not using TrustZone in my application?

My code: 

typedef struct

{

uint8_t MRA;

uint8_t MRB;

uint8_t RESERVED[2];

uint32_t SAR;

uint32_t DAR;

uint16_t CRA;

uint16_t CRB;

} dtc_transfer_information;

#define PBP_SCI R_SCI9

#define PBP_TIM R_GPT320

#define PBP_TIM_IRQn IEL0_IRQn

#define PBP_TIM_IRQHandler GPT0_COMPARE_C_IRQHandler

#define PBP_DMA_TX R_DTC

#define PBP_DMA_TX_IRQn IEL2_IRQn

#define PBP_USART_IRQn IEL1_IRQn

#define PBP_USART_IRQHandler SCI9_RXI_IRQHandler

#define PBP_TIMEOUT_μs 10000-1

static LPBP_Frame_t PBP_Frame; //!< Strukuta odbieranej ramki

static uint8_t PBP_Out_Buffer[1536]; //!< Bufor danych wyjściowych

dtc_transfer_information DTC_VECTOR[DTC_VECTOR_SIZE] __attribute__((aligned(1024)));

void PBP_Init(void)

{

DTC_VECTOR[PBP_DMA_TX_IRQn].MRA = 0

| DTC_MRA_SM_INC

| DTC_MRA_SZ_8bit

| DTC_MRA_MD_NORMAL;

DTC_VECTOR[PBP_DMA_TX_IRQn].MRB = 0

| DTC_MRB_DM_FIXED;

DTC_VECTOR[PBP_DMA_TX_IRQn].SAR = (uint32_t)&PBP_Out_Buffer[1];

DTC_VECTOR[PBP_DMA_TX_IRQn].DAR = (uint32_t)&PBP_SCI->TDR;

R_DTC->DTCVBR = (uint32_t) DTC_VECTOR;

PBP_TIM->GTCR = GPT_GTCR_MD_MODE_PWM | GPT_GTCR_TPCS_PCLKD_DIV32;

PBP_TIM->GTPR = 0xFFFFFFFF;

PBP_TIM->GTCCRC = PBP_TIMEOUT_μs;

PBP_TIM->GTCNT = 0x00000000;

PBP_TIM->GTST = 0;

NVIC_ClearPendingIRQ(PBP_TIM_IRQn);

NVIC_EnableIRQ(PBP_TIM_IRQn);

PBP_SCI->SMR = SCI_SMR_CKS_PCLK_DIV4; //CLK = 8Mhz

PBP_SCI->SPTR = 0

| SCI0_SPTR_SPB2DT_Msk

| SCI0_SPTR_SPB2IO_Msk;

// PBP_SCI->BRR = (uint8_t)((CLK_PCLKA / (32 * 9600U)) - 1);

PBP_SCI->BRR = 1;

PBP_SCI->SEMR = SCI0_SEMR_BRME_Msk; //Enable MDDR

PBP_SCI->MDDR = 236;

PBP_SCI->SCR = 0

| SCI0_SCR_RE_Msk

| SCI0_SCR_TE_Msk

| SCI0_SCR_TIE_Msk

| SCI0_SCR_RIE_Msk;

NVIC_ClearPendingIRQ(PBP_DMA_TX_IRQn);

NVIC_EnableIRQ(PBP_DMA_TX_IRQn);

R_ICU->IELSR2 = ICU_IELSRn_DTCE_EN | ICU_IELSRn_IELS(0x1B7); //ELC_EVENT_SCI9_TXI

NVIC_ClearPendingIRQ(PBP_USART_IRQn);

NVIC_EnableIRQ(PBP_USART_IRQn);

}

void send_USART_DMA(uint16_t size)

{

// for(uint16_t idx=0; idx<size; idx++)

// {

// PBP_SCI->TDR = PBP_Out_Buffer[idx];

// while((PBP_SCI->SSR & SCI0_SSR_TDRE_Msk) == 0);

// }

R_DTC->DTCST = 0;

DTC_VECTOR[PBP_DMA_TX_IRQn].CRA = size-1;

R_DTC->DTCST = DTC_DTCST_DTCST_Msk;

PBP_SCI->TDR = PBP_Out_Buffer[0];

while(DTC_VECTOR[PBP_DMA_TX_IRQn].CRA);

R_DTC->DTCST = 0;

while((PBP_SCI->SSR & SCI0_SSR_TDRE_Msk) == 0);

}

Any help would be appreciated.

Best regards,
Baterflu

  • Hello,

    From chapter 17.4.11 of the hardware manual:

    DTC has the Master TrustZone Filter. The Master TrustZone Filter in DTC can detect the security areas of Flash area(code Flash and data Flash) and SRAM area(ECC / Parity RAM) defined by IDAU. When no-secure accesses those addresses, it detects the security violation. Access of violation address is not performed. Detected the error is handled as the Master TrustZone Filter error.

    It could be because the Trustzone boundaries have not been programmed correctly.

    Are you working on a custom board or evaluation kit ? If the P201/MD pin is not wired with P300/SWCLK then e2studio cannot put the device into boot mode in order to program the Trustzone boundaries on the device.

  • Hello,

    Thank you for your explanation — it was very helpful.

    I’m working on a custom board, not an evaluation kit.
    The SWCLK (P300) pin is connected to a JTAG connector, and the MD/BOOT (P201) pin can only be pulled to GND or 3.3V, so we cannot toggle it dynamically during debug or programming.

    Could you please clarify if anything needs to be configured manually in order to set or disable TrustZone?
    For example, are there registers or settings that must be initialized to allow proper DTC operation without triggering a Master TrustZone Filter error?

    Best regards,
    Baterflu

  • Additionally, I noticed that when starting a debug session in e² studio, it's important to go to the Debugger settings and uncheck the option:

    Set TrustZone secure/non-secure boundaries

    When this option is enabled, the debugger fails to connect and shows a "connection error" suggesting to check the wiring — even though the physical connection is fine. Disabling this option allowed me to proceed without issues.

  • The SWCLK (P300) and SWDIO pins are connected to a debug connector, along with RESET — it's not a full JTAG, just the standard SWD interface (SWDIO/SWCLK/RESET).

  • I am using a SEGGER J-Link Ultra+ as the debugger/programmer.

  • The Trustzone boundary settings can be programmed while the device is in SCI or USB boot mode via the serial programming interface. To do this you need to have implemented connections via SCI9 pins or USBFS port.

    If you do not have such a connection, the debugger will not be able to program the Trustzone boundaries.

    A J-Link debugger can do this via the SCI9 pins (P109/TXD9 and P110/RXD9) . As far as I understand these pins are not currently connected to the connector, please refer below for a connection which allows both the debugging and serial programming interface.

    If you cannot change the connection of MD pin to be connected with the SWCLK pin, you can keep it low and use Renesas Flash Programmer to program the Trustzone boundaries, then switch MD pin to high and disable the 'Set TrustZone secure/non-secure boundaries' option since your connection will allow this operation. 

    Let me know if you have further questions.