cancel
Showing results for 
Search instead for 
Did you mean: 

problem setting STM registers

ivancolla9
Associate III
Posted on January 25, 2016 at 17:14

Hallo everyone,

finally I have received a discovery board (with a

SPC56EL60L3 mounted

) and installed the universal debugger, to try some of my code.

I ran in the first problem trying to set a timer.

I use this code:

STM.CR.B.CPS = PRESCALER;               /* Prescale value.*/

STM.CR.B.FRZ = 1;                    /* Allows Freeze for stop counter in debug. */

STM.CR.B.TEN = 1;                    /* Enable the counter. */

I manage to debug and stop the application, but I am new in this field and problably there is some error that I do not see.

The first thing that I note, is that the code is not executed in the order written. Looking the PC register with the debbuger, it seems that the instructions are ''scrambled'' in the compiling phase.  The second instruction is executed beforre the first (I am debugging step by step).Is it possible?

The second thing is that after the instruction STM.CR.B.CPS = PRESCALER;  the program doesn't continue. I must press ctrl+F5 to stop it and then I see that the program is blocked on an unhandled exception.

Someone can see the problem in the snippet of code. Reading the documentation, I understood that, after using the wizard generator, I can use the memory mapping autogenerated to modify register values. Is this correct? Or I understood wrongly how SPC5 studio works?

Thank you,

Ivan

#stm-registers
7 REPLIES 7
Erwan YVIN
ST Employee
Posted on January 25, 2016 at 18:06 Hello Ivan , it is unhandled exception because the compiler can optimize bitfield settings

STM.CR.B.CPS = PRESCALER;

/* Prescale value.*/

STM.CR.B.FRZ = 1;

/* Allows Freeze for stop counter in debug. */

STM.CR.B.TEN = 1;

/* Enable the counter. */
Did you try to set directly the register with masks ? it is recommended not to use the bitfield.

STM.CR.R = PRESCALER_MASK | FREEZE_ENABLE | TEN_ENABLE;

// example
Best Regards Erwan
ivancolla9
Associate III
Posted on January 26, 2016 at 09:26

Hello Erwan,

I tried your solution and it worked. Thank you very much. As a side note, I tried to set a pin at 1

SIUL.GPDOB.PDO = 1;

and this instruction is executed, but now I fear that, even if I have no exception, I am setting the wrong memory address. In case this is not correct (as it seems from your aswer and from the debugger), when does the bitfield is used? Can I use it to read registers without using masks? Regards, Ivan
Erwan YVIN
ST Employee
Posted on January 26, 2016 at 10:02 Hello Ivan , 1) for writing , Setting only 1 bitfield at a defined address is OK

SIUL.GPDOB.PDO = 1;

Setting 3 successive bitfields at the same address is not recommended. Some compilers can optimize assembler routine and generate an unhandled exception

STM.CR.B.CPS = PRESCALER; 
/* Prescale value.*/
STM.CR.B.FRZ = 1; 
/* Allows Freeze for stop counter in debug. */
STM.CR.B.TEN = 1; 
/* Enable the counter. */

2) for reading , you can use whatever you want. 3) Anyway , you can check in the SFR View Best Regards Erwan

STM.CR.B.CPS = PRESCALER;

/* Prescale value.*/

STM.CR.B.FRZ = 1;

/* Allows Freeze for stop counter in debug. */

STM.CR.B.TEN = 1;

/* Enable the counter. */



STM.CR.B.CPS = PRESCALER;

/* Prescale value.*/

STM.CR.B.FRZ = 1;

/* Allows Freeze for stop counter in debug. */

STM.CR.B.TEN = 1;

/* Enable the counter. */



STM.CR.B.CPS = PRESCALER;

/* Prescale value.*/

STM.CR.B.FRZ = 1;

/* Allows Freeze for stop counter in debug. */

STM.CR.B.TEN = 1;

/* Enable the counter. */



STM.CR.B.CPS = PRESCALER;

/* Prescale value.*/

STM.CR.B.FRZ = 1;

/* Allows Freeze for stop counter in debug. */

STM.CR.B.TEN = 1;

/* Enable the counter. */



SIUL.GPDOB.PDO = 1;

and this instruction is executed, but now I fear that, even if I have no exception, I am setting the wrong memory address.
ivancolla9
Associate III
Posted on January 26, 2016 at 10:25

Ok, now I understand.

Thank you very much for the info,

Ivan

ivancolla9
Associate III
Posted on January 27, 2016 at 09:17

Good morning,

sorry for the double post, but I don't know if the problem of today is related with this discussion. I tried vairous registers to grasp the essentials of the SPC56EL60L3 mounted on my discovery board. I inserted this trial configuration:

CRC.CFG1.R = 0;

in order to access and configure (for now with all bit fields to 0), the CRC module. The micro give me an axception. The strange thing that I note is that, using SFR view, I cannot monitor the CRC register. In the columns of values I see ?????????? instead of a value. Reading the manual I found that CRC bit field are modifyable only in configuration mode. Could be this the problem? In that case, how can I enter configuration mode? I searched the manual, but I didn't found the specific section (probably I misunderstood it). Thank you, Ivan
Erwan YVIN
ST Employee
Posted on February 23, 2016 at 16:57

Hello Ivan ,

Sorry for my late answer Sometimes it is difficult to browse on Non-solved posts on my.st.com. You need to enable the associated PCTL. For CRC, you need to enable PCTL

/* CRC clock gating if present.*/
halSPCSetPeripheralClockMode(58,
SPC5_ME_PCTL_RUN(2) | SPC5_ME_PCTL_LP(2));

you should see the value and not ???? (undefined). Best regards Erwan
ivancolla9
Associate III
Posted on February 29, 2016 at 15:48

Thanks for the answer Erwan.

I managed to activate the CRC module and now I better understand the external peripherals.

Regards,

Ivan