RT1050 DTCM 配置问题

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

RT1050 DTCM 配置问题

6,877 Views
haifeng_jin
Contributor III

hi  我在使用过程中把DTCM配置成了448K,配置成了如下模式

pastedImage_1.png

但是我定义了一个程序如下:

unsigned char gtx[1024*128];

typedef struct _tagtest
{
unsigned short pk_head;
unsigned char testtr[10];

}test_typedef,*p_test_def;

test_typedef testdata;

memset(gtx,0x00,sizeof(gtx));

memcpy(testdata.testtr,"0123456789",strlen("0123456789"));

系统使用ram我用gtx这个数组控制,只要配置超出128K,在执行这个memcpy的时候,就会进入错误中断,如果把总的内存控制在128K以内,就没有问题,非常奇怪的问题。

也许你们会说是字节对齐问题,但是,你们可以看下你们lwip移植的,都是字节对齐,这样你们复杂点的历程都没法用,我们写程序都要控制,非常受限制,还请你们看下,希望以后出的历程能够完善,不会有这么多的问题。

当然你们还会问我的ram配置大小有没有问题,我的配置如下,是没有问题的


ldr r0, = REG_IOMUXC_GPR16;
ldr r1,[r0];
bic r1,#BIT_GPR16_ITCM_EN
bic r1,#BIT_GPR16_DTCM_EN;
str r1,[r0];
dsb
ldr r1, = 0xAAAAAAA5;0x5AAFFAA5;
ldr r0, = REG_IOMUXC_GPR17;
str r1,[r0];
dsb
isb
ldr r0, = REG_IOMUXC_GPR16;
ldr r1,[r0];
orr r1,#BIT_GPR16_FLEX_RAM_BANK_CFG_SEL
str r1,[r0];
dsb
isb

ldr r0, = REG_IOMUXC_GPR14;
ldr r1, [r0]
bic r1,#MASK_GPR14_ITCM_SZ

bic r1,#MASK_GPR14_DTCM_SZ
orr r1,#(0xa << 20);
orr r1,#(0x0 << 16);
str r1,[r0];
dsb
ldr r0, = REG_IOMUXC_GPR16;
ldr r1,[r0];
orr r1,#BIT_GPR16_DTCM_EN;
str r1,[r0];
dsb
isb
;ldr r0, = REG_IOMUXC_GPR16;
;ldr r1,[r0];
;orr r1,#BIT_GPR16_ITCM_EN;
;str r1,[r0];
;dsb
;isb

0 Kudos
14 Replies

5,453 Views
1099789860
Contributor II

我也遇到,现象如下:

1.发现当使用超过128K地址(0x20000000~0x20020000)之后的RAM,memcpy必须四字节对齐,直接按short类型访问则必须2字节对齐,直接按int类型访问必须4字节对齐,否则引起非对齐访问错误HardFault;

2.在128K地址(0x20000000~0x20020000)内的空间,分别进行上述3种操作,不对齐时仍正常。

3.看评论NXP提供的两个代码,我使用后发现并没有解决这个问题。请问该如何解决?

4.我的代码如下:

unsigned char testtr[10] __attribute__((at(0x20020001)));
void HardFault_Handler() {
    PRINTF("Hard_FaulT\r\n");
    if(SCB->CFSR & (1<<24)) PRINTF("    非对齐访问错误(UNALIGNED)!\r\n");
    while(1);
}

main函数内的测试代码:

   memcpy(testtr,"0123456789",10); /* 超过128k后 必须四字节对齐,否则引起非对齐访问错误 */
    testtr[0] = 0x3;
    PRINTF("单字节访问成功\r\n");
   
    *((uint16_t *)testtr) = 0xff;/* 超过128k后,双字节访问时必须2字节对齐,否则引起非对齐访问错误 */
    PRINTF("双字节访问成功\r\n");
   
    *((uint32_t *)testtr) = 0xff;/* 超过128k后,四字节访问时必须4字节对齐,否则引起非对齐访问错误 */
    PRINTF("四字节访问成功\r\n");

0 Kudos

5,453 Views
wayne_wang
NXP Employee
NXP Employee

the root cause for you mentioned issue is, it don't change MPU setting after you adjust the FlexRAM configuration, because ARM specify only normal memory support non-aligned access, and default SDK only configure the default memory as normal memory, so it generate  hard fault when access the address out of 128KB.

please find the function "BOARD_ConfigMPU" and change memory size with new configuration.

/* Region 5 setting: Memory with Normal type, not shareable, outer/inner write back */
MPU->RBAR = ARM_MPU_RBAR(5, 0x20000000U);
MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 0, 0, 1, 1, 0, ARM_MPU_REGION_SIZE_128KB);

5,453 Views
1099789860
Contributor II

Thank you for your answer, your test method has been successfully solved the problem.

0 Kudos

5,453 Views
eladhhh
Contributor I

您好!

         是这样的,与MPU有关,在board.c文件中

                      谢谢!

0 Kudos

5,453 Views
haifeng_jin
Contributor III

无法解决吗,这个问题,这个问题我认为是比较奇怪的,会影响很多东西

0 Kudos

5,453 Views
haifeng_jin
Contributor III

我们已经采用OCRAM去屏蔽这个问题,但是OCRAM用到了Dcache,因为QSPI需要数据备份,一旦用了OCRAM,数据备份就不行,还请贵司查看下这个DTCM的问题

0 Kudos

5,453 Views
jimmychan
NXP TechSupport
NXP TechSupport

I will ask the expert for helping this. I will let you know when I get the reply.

0 Kudos

5,453 Views
wayne_wang
NXP Employee
NXP Employee

it don't need to configure GPR14 registers, this is not related to FlexRAM configuration.

please customer try the below code.

        LDR     R0, =0x400ac044

        LDR     R1, =0xaaaaaaaa              //FlexRAM configuration, all is for DTCM

        STR     R1,[R0]

        LDR     R0,=0x400ac040

        LDR     R1,=0x04

        LDR     R3,[R0]

        ORR     R2,R1,R3

        STR     R2,[R0]

but please note to change FlexRAM configuration before using it, so we recommend to place above code to reset handler, also we have one app notes on how to use FlexRAM.

https://www.nxp.com/docs/en/application-note/AN12077.pdf 

0 Kudos

5,453 Views
haifeng_jin
Contributor III

这个手册看过,和我写的差不多的,没什么大的出路

0 Kudos

5,453 Views
jimmychan
NXP TechSupport
NXP TechSupport

Our expert have validated the DTCM configuration. It can work well. Please refer to attached test example.

also please note that not to set GPR14 register.

0 Kudos

5,453 Views
haifeng_jin
Contributor III

按照你们官方的地方改只是部分功能可以,只算个半成品,是不可以用的

0 Kudos

5,453 Views
eladhhh
Contributor I

你好!

         已经下载你提供的代码,例程中,ram问题出在哪里?  请告知! 这边将DTCM扩大为256KB,memcpy也出了问题。

   谢谢!

0 Kudos

5,453 Views
haifeng_jin
Contributor III

hi  你们的方法都是有问题的,这个ram问题就在我给你们的历程上,改一个 地方需要,这个地方非常深入,建议你们自己找下,把你们官方发布的手册也更新下,只按照那个手册改是不可以的,还需要改其他的地方,你们可以自己看下,我觉得你们对自己的芯片太不了解了

0 Kudos

5,453 Views
haifeng_jin
Contributor III

hi  wayne

        不行的,全部配置成DTCM也会有问题(数据手册上说ocram必须留64K,因为DMA靠近ocram,如果用DMA,这个需要配置空间的吧,这个可以先不讨论),我的那个代码配置能用,但是我不知道是什么问题会有DTCM超出128K,memcpy在字节不对齐的情况下面就有问题,或则用百度网盘的代码,我是在QSPI上跑的,就是在官方demo板上,如果你下载正常,就可以正常闪烁的。百度网盘:448KRAM_CODE-x.rar_免费高速下载|百度网盘-分享无限制 

448KRAM_CODE-x\boards\evkbimxrt1050\driver_examples\gpio\led_output  这个历程

0 Kudos