Topic

FAQ
Login Register
TLSR8251 system clock - single connection SDK
Feb 27, 2022 08:23

/

A

/A

I spent hours trying to figure it out, but I can't.

I have a board with TSR8251 and 32MHz crystal.


I have in app_config.h: #define CLOCK_SYS_CLOCK_HZ 32000000

In function main() - clock_init(SYS_CLK_32M_Crystal);

Uart intit - uart_init(17, 13, PARITY_NONE, STOP_BIT_ONE);

In function main_loop() I flash led with 500ms ON and 500ms OFF

if ((clock_time() - led_flash) > 500 * CLOCK_SYS_CLOCK_1MS) {

   gpio_toggle(GPIO_LED); //_RED

   led_flash = clock_time();

}


When I flash the chip and run it doesn't work correctly:

- Frequency measured on Crystal pins - 32MHz, which is correct

- Bluetooth not working

- led flash timing measured - 666.7ms (should be 500ms)

- uart not working correctly - shows correct data if baud rate set on the scope from around 162000, measured 1 bit timing approx 5.9us


I suspected that the system clock is not set to 32MHz but stays at 24MHz!

After doing simple calculation 32MHz/24MHz = 1.333

If the chip is running with the 24MHz clock (but 32MHz crystal connected) then the led would be flashing at:

500ms * 1.333 = 666.7ms - that's what I measured!


This proves that the system clock is not set in the code to 32MHz.


Note, I am using old SDK (I think the version is 1.3, which still can be downloaded from Telink website), because when I tried to convert my old project to the latest version of the SDK, I get too many errors, so I gave up.


So where is the problem?

Where is the value of the CLOCK_SYS_CLOCK_HZ 32MHz overwritten with 24Mhz?

Why doesn't it work?


4 replies
wes58 [Author] Feb 27, 2022 17:16
0
/A

I did some more testing, converted my project to the latest SDK, read datasheet and now I am confused even more.

When I look in the .lst file for clock_init(SYS_CLK_TYPE), I can see: the following assembly code:

for selection of 32MHz clock - SYS_CLK_32M_Crystal

642: a042 tmovs r0, #96 ; 0x60

644: 9000 98de tjl 804

for selection of 24MHz clock - SYS_CLK_24M_Crystal


642: a042 tmovs r0, #66 ; 0x42

644: 9000 98de tjl 804

So, values 0x60 (for 32MHz) and 0x42 (for 24MHz), are the values written to Register Address 0x66 - which makes sense looking at the bits that are set and in accordance to the datasheet page 54 and Figure 4.1 on page 52, .

But, does it mean that you can only use (connect) 24MHz crystal to the chip?

But then it doesn t make sense because, doing the test:

Firmware configured for SYS_CLK_32M_Crystal and 24Mhz crystal connected to the chip:

#define CLOCK_SYS_CLOCK_HZ 32000000

- Bluetooth works

- Led Flashing 1000ms instead of 500ms - 2 times than what should be.

- Uart not working correctly - configured as uart_init(17, 13, PARITY_NONE, STOP_BIT_ONE);, which is according to the uart.c for 32Mhz sys_clk?

UART works when on the scope the baud rate is set to 116500 (or a bit higher, should be 115200)


Second test: Firmware configured for SYS_CLK_32M_Crystal and 32Mhz crystal connected to the chip:

#define CLOCK_SYS_CLOCK_HZ 32000000

- Bluetooth not working

- Led Flashing 750ms instead of 500ms - 1.5 times than what should be

- Uart not working correctly 


So, what does SYS_CLK_32M_Crystal mean?

What crystal is connected to the chip?

How do you configure UART when you select SYS_CLK_32M_Crystal?

From the datasheet I understand that SYS_CLK_32M_Crystal means 24MHz system clock with 24MHz crystal connected to the chip.

Why doesn't led flash timing is not right?


I would appreciated some help because I spent too much time on this so far.


wes58 [Author] Feb 28, 2022 06:16
0
/A

My last findings:

- I think it is definitely that you use only 24MHz crystal connected to the chip and change the system clock with SYS_CLK_24M_Crystal, SYS_CLK_32M_Crystal, SYS_CLK_48M_Crystal.

So I think, SYS_CLK_32M_Crystal shouldn t be named like this. That s what confused me. It should be named SYS_CLK_32M, which would mean 32MHz system clock, and the crystal used doesn t change - it is still 24MHz


- To fix UART instead of using: uart_init(17, 13, PARITY_NONE, STOP_BIT_ONE);, I use uart_init_baudrate(115200, CLOCK_SYS_CLOCK_HZ, PARITY_NONE, STOP_BIT_ONE);.


- Last issue was led flashing or clock timing in general.

Since function clock_time() is the system timer, I changed the following code:

if ((clock_time() - led_flash) > 500 * CLOCK_SYS_CLOCK_1MS) {
gpio_toggle(GPIO_LED); //_RED
led_flash = clock_time();
}

to:

if ((clock_time() - led_flash) > 500 * CLOCK_16M_SYS_TIMER_CLK_1MS) {
gpio_toggle(GPIO_LED); //_RED
led_flash = clock_time();
}


TL_bloom5 Mar 01, 2022 14:34
0
/A

Hi Wes,

The naming could bring some confusion as you mentioned. But as you can see in the only 24M Xtal is supported in the DS.

The crystal suffix pretty means that the system clock's source is from crystal. As you can see there is RC suffix, that means the system clock will rely on internal RC.

wes58 [Author] Mar 02, 2022 04:41
0
/A

Hi TL_blloom5

Thanks for your response.

That's the thing, reading the Datasheet. You don't do it unless you are stuck.

I used an example from multiconnection SDK where I noticed SYS_CLK_32M_Crystal, So I thought that I have to change the crystal on my board to 32MHz. So I ordered it on AliExpress and waited over a month to come to Australia. And then, I found that I got it all wrong, and I don't need it. So it cost me money and time.

I know, you can say that I should read the Datasheet, but I was using an example code, so I thought I don't have to do it - It says 32M_Crystal so I need 32MHz crystal. I was wrong.


It is very confusing! What if you choose internal 24MHz RC source RC24_M and then select SYS_CLK_32M_Crystal? You have RC and Crystal - that would be confusing.

Anyway, now I know.