카테고리 보관물: SAM8

IAR 에서 SmartOption 설정하기.

일단 이것은 정식 방법인지는 모른다.
꽁수일 수도 있고, 뭐… 일단 잘 되니 OK ! !

보통 SmartOption 은 MDS 장비와 타겟 보드를 이용하여 개발할 때에는 사용하지 않는다.
타겟에 딥 스위치나 점퍼로 SmartOption 을 설정하게 되어있거나, 설정이 필요없는 MCU 도 있기 때문에 SmartOption 을 롬의 지정된 영역에 넣을 필요가 없다.

하지만 양산시에는 예기가 달라진다.
양산시에는 SmartOption 을 조정하는 스위치 같은 것들은 넣을 수 없다. ( 딥 스위치나 점퍼를 이용한 세팅은 개발 편의를 위해 타겟만의 특수 기능이라고 보면 된다.)

양산시 사용할 인텔 표준 헥사 규격(Intel-Standard HEX Format) 으로 헥사 파일을 생성해 대량 롬 라이터(갱 라이터를 말한다)를 이용해 MCU 의 롬을 구울경우, 즉 대량생산시에는 헥사파일로 컴파일 결과물을 만들어야 하기 때문에 사용한다.

The “Intel-Standard” HEX file is one of the most popular and commonly used formats in the 8052 world. The standard is used to burn the 8052 program into an EPROM, PROM, etc. For example, an 8052 assembler will usually generate an Intel Standard HEX file which can then be loaded into an EPROM programmer and burned into the chip.An Intel Standard HEX file is an ASCII file with one “record” per line. Each line has the following format:

Position Description
1 Record Marker: The first character of the line is always a colon (ASCII 0x3A) to identify the line as an Intel HEX file
2 – 3 Record Length: This field contains the number of data bytes in the register represented as a 2-digit hexidecimal number. This is the total number of data bytes, not including the checksum byte nor the first 9 characters of the line.
4 – 7 Address: This field contains the address where the data should be loaded into the chip. This is a value from 0 to 65,535 represented as a 4-digit hexidecimal value.
8 – 9 Record Type: This field indicates the type of record for this line. The possible values are: 00=Register contains normal data. 01=End of File. 02=Extended address.
10 – ? Data Bytes: The following bytes are the actual data that will be burned into the EPROM. The data is represented as 2-digit hexidecimal values.
Last 2 characters Checksum: The last two characters of the line are a checksum for the line. The checksum value is calculated by taking the two’s complement of the sum of all the preceeding data bytes, excluding the checksum byte itself and the colon at the beginning of the line.

Calculating the Checksum

As mentioned in the format table above, the last two characters represent a checksum of the data in the line. Since the checksum is a two-digit hexidecimal value, it may represent a value of 0 to 255, inclusive.The checksum is calculated by summing the value of the data on the line, excluding the leading colon and checksum byte itself, and taking its two’s complement. For example, the line::0300300002337A1E Breaking this line into it’s components we have:Record Length: 03 (3 bytes of data)Address: 0030 (the 3 bytes will be stored at 0030, 0031, and 0032)Record Type: 00 (normal data)Data: 02, 33, 7AChecksum: 1ETaking all the data bytes above, we have to calculate the checksum based on the following hexidecimal values:03 + 00 + 30 + 00 + 02 + 33 + 7A = E2 The two’s complement of E2 is 1E which is, as you can, the checksum value.For those unfamiliar with calculating a two’s complement, it’s quite simple: The two’s complement of a number if the value which must be added to the number to reach the value 256 (decimal). That is to say, E2 + 1E = 100.You may also calculate the two’s complement by subtracting the value from 100h. In other words, 100h – E2h = 1Eh — which is the checksum.If the value in question is greater than FFh, simply take the part which is less than 100h. For example, if you want the two’s complement of the value 494h, simply drop the leading “4” which leaves you with 94h. The two’s complement of 94h is 6Ch.

먼저 사용할 삼성 MCU 에 데이터 쉬트를 보자!
데이터 쉬트는 삼성 반도체나 AllDataSheet 를 이용하면 된다.

S3F9488 의 경우 2-3 페이지에 스마트 옵션과 관련된 내용이 있다.

이제 상세 설명으로….
스마트 옵션 코드는 롬 코드에 존재해야되는데, 데이터 쉬트상에 보면 롬의 0x003C 번지부터 순서대로 4 개의 영역(4 Byte)에 이 코드를 넣으라고, 한다.
설정에 대한 내용은 데이터 쉬트를 참고하도록 하고…

이제 IAR 에서 간단하게 3 줄만 넣자.

[CODE type=c]
/*코드 상단에*/
__code const unsigned char SmartOption[4] @ 0x003C = { 0x00, 0x00, 0xD8, 0x04 }
unsigned char SOTemp;



/*리셋 함수내에 위치*/
SOTemp = SmartOption[0];
[/HTML][/CODE]

__code 는 컴파일러 지시자로서 컴파일러에게 해당 변수 내용을 롬 코드로 만들라는 명령이다.
후반부에 @ 0x003C 는 주소를 표현하며 이 부분이 없을 경우 컴파일러 마음대로 위치시키게 된다.
이 함수는 램에 존재하지 않고 직접 롬에서 데이터를 읽기 때문에 램을 절약할 수 있다.
특히 __code 는 절대 변해선 안되는 코드일 경우에 좋다.

하단에 변수 선언과 선언한 변수에 데이터를 넣는 작업은 컴파일러 때문에 하는 작업이다.

컴파일러마다 특성이 다르기 때문에 약간씩은 다르지만 기본적으로 사용되지 않는 함수, 변수, 상수 등은 컴파일시 자동으로 제외된다. (물론 제외 안하는 것들도 있을 수 있으며, IAR 의 경우 사용 안하는 것들은 컴파일 하지 않는다.)
그렇기 때문에 강제로 딱 한번, MCU 가 리셋되었을 때(전원인가시, 리셋이 걸렸을 때) 리셋 부분에서 대충 데이터를 넣도록 하는것일 뿐, 큰 의미가 없다.

일단 이 방법의 강점은 걍 코딩하면서 쓴다는 것과, 급하게 스마트 옵션 변경시 HEX 파일에서 해당 부분을 수정하면 된다는 것이다. (물론 위에 걸어놓은 인텔 표준 헥사 규격을 알고 있어야 된다.)