Start12.c and FLASH erase/write

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

Start12.c and FLASH erase/write

785 Views
sebasira
Senior Contributor I

Hi everybody!

 

I've got two people working on the same hardware but different application. They both work with MC9S12A256 and CW4.6.

 

The problem arrise when one could not perform FLASH erase, while the other can. They where using exactly the same FLASH routines. But one of them was not working.

 

So I made a simple test. Starting from each other project, I remove everything except flash routines. And indeed one worked, and the other one didn't.

 

I look at their settings. And only found a difference at "Assembler for HC12", and start12.c was also different.

I try changing the setting of the non-working with the one that worked and strange things happended. Sometimes it runs, others it hangs... But when run, the flash was written. I guess this might be related to the start12.c

 

Could you take a look at both "test" projects and give a hand here?

 

I think it's important to remark that we've never deal with the code of the start12.c.. We've always use the one generated with the wizard, so we don't know why they are different. (Maybe one was from and oldeir CW version. We use to use CW3.1)

 

Thanks in advance

Labels (1)
0 Kudos
6 Replies

438 Views
kef
Specialist I

Both versions are wrong. At least FLASH clock initialization is broken. Also a lot of wrong flag clear sequences like FSTAT_PVIOL = 1.

0 Kudos

438 Views
sebasira
Senior Contributor I

Thanks for your reply kef!

 

About wrong flag clear sequence, that's because I didn't know about read-write, read-modify-write and write-only instructions (you explain it to me few days ago). And I'm trying to correct that in my all projects, I must have missed flash routines.

 

What you mean with: "At least FLASH clock initialization is broken"?

 

Thanks again!

 

0 Kudos

438 Views
kef
Specialist I

Try stepping over initialization routine. Clearly it fails to initialize clock divider properly.

 

1)

fclk_val = 48000000 / 8 / 200 -1 = 29999

 

that's more than 12000, so you write ... 29999 | 8  into ... 8 bits wide flash clock divider register...

 

2) Flash module source clock is oscilator clock, not the bus clock or VCO clock. 48000000 is probably your PLL VCO clock, isn't it?

 

 

0 Kudos

438 Views
sebasira
Senior Contributor I

Kef, you're totally right!!

 

Flash clock is derived from OSCCLK (in my case 16Mhz), not from BUS CLOCK.

 

I'll attach both projects again with FLASH_ini modified (now called FLASH_ini16Mhz). Init values taken from MC9S12DP256 datasheet, page 179.

 

Thanks to you kef, I'm getting closer to my goal. Right now, flash erase/write is working on the nonWorking version, but it doesn't work the first time I run the application after loading the code. All the next times I reset, then run, flash update works perfectly.

 

The first time seems that flash is not erased, because error is "FLASH_ERR_NOT_ERASED"

 

Maybe you can figure out why is that happening. 

 

As always, thanks in advance!

0 Kudos

438 Views
sebasira
Senior Contributor I

Well I'm really amaze here!!!!

 

I can't beleive this!!!

 

After trial and error, several hours and lot of new dummy projects; I found out that if I change the .ini file of the project, the flash erase/write works like a charm!!

 

Why's that? First I thought it was a problem of the debugger that can't display the memory correctly, but then I realized that if the error-code returned from function is that "the flash is not erased"... then the flash is not erased indeed, despite any viewing problem...

 

So (don't know why) I think of changing the ini file. I put the one from the working version inside the nonWorking one, and then it works, and viceversa.

 

Why?????? Why???

0 Kudos

438 Views
J2MEJediMaster
Specialist I

Have you used a text editor with a compare feature to check out the differences between the two files? I took a look at the P&E_Multilink_CyclonePro.ini files and the value used to set BDMClockSpeed is different between the two.

 

---Tom

0 Kudos