Monday, August 23, 2021

Memo of ARM Programming on Cortex M4でのプログラミングメモ


1. 開発環境

 参考リンク[15]と[16]はいいスタートです。

2. Compilation error: arm-none-eabi-gcc exit.c:(.text.exit+0x*): undefined reference to `_exit'

According to exit.c:(.text+0x18): undefined reference to `_exit' when using arm-none-eabi-gcc

This happens when compiling a file with arm-none-eabi-gcc in one machine/architecture to load it in an ARM target machine. Most probably you are not making use of semihosting, you want to retarget.

When not using Semihosting, can use below command

$ arm-none-eabi-gcc --specs=nosys.specs $(OTHER_LINK_OPTIONS)

3. GPIO

 According [1], "The STM microcontroller used by the evaluation board provides eight GPIO ports, named A-I. Port pins PG6,7,8; PH2,3,6,7; PI10 are connected to LEDs. "

4. Cコードにアセンブラを組み込む

  [10]によると、aとbが宣言されている変数であるならば、以下のようにCコードにアセンブラを組み込めます。

     __asm("add a, b");

 Cから見えるアセンブラ関数は以下のように書けます

__asm int add3_embasm(int i)
{
  add r0, #3
  bx lr
}

5. 周辺デバイスへのアクセス

 [17]によると、以下のマクロで周辺アドレスレジスター(peripheral register)にアクセスできます。

#define _VAL2FLD(field, value)
Mask and shift a bit field value for assigning the result to a peripheral register. More...

#define _FLD2VAL(field, value)
Extract from a peripheral register value the a bit field value. More...

6. Instruction width selection

Cortex CM4のGuideによると、強制的に32ビットのインストラクションをにしたい場合、「.W」をつかい、16ビットの場合、「.N」を使う。
There are many instructions that can generate either a 16-bit encoding or a 32-bit encoding depending on the operands and destination register specified. For some of these instructions, you can force a specific instruction size by using an instruction width suffix. The .W suffix forces
a 32-bit instruction encoding. The .N suffix forces a 16-bit instruction encoding.
If you specify an instruction width suffix and the assembler cannot generate an instruction encoding of the requested width, it generates an error.
以下は一例である。
BCS.W label ; creates a 32-bit instruction even for a short branch

7. ブートローダーとアプリのHEXファイルを一つにまとめる
 SRecord[20]ツールを使って、ブートローダーとアプリのHEXファイルを一つにまとめることができます。
$ srec_cat bootloader.hex -Intel app.hex -Intel -o combined.hex -Intel


Reference Links

1. Understanding the simple use of GPIO (ARM Cortex M4 CookBook) 

2. General Purpose I/O Pin (PDL_GPIO) and Fast GPIO Pin (PDL_FGPIO)

3. 32-Bit Microcontroller FM4 Family Peripheral Manual

4. Programming of ARM Cortex-M microcontrollers - Part 0 - Tools and basics

5. Tips and Tricks – Jumping from the Bootloader to the Application Code Cleanly

6. Catalogue of parametrised CRC algorithms

7. Calculating a simple CRC

8. C > CRC-8-CCITTを計算 > I2C通信用のCRC

アセンブラコードをCから呼び出す

10.  ぐだぐだ低レベルプログラミング(5)Arm組み込みアセンブラとインラインアセンブラ

11. ARM: How to Write a Bootloader

12. How to obtain reliable Cortex M4 short delays

13. ARM® Compiler armcc User Guide

14. Cortex-M3をアセンブリで動かす

15. Programming of ARM Cortex-M microcontrollers - Part 0 - Tools and basics

16. Bare Metal Embedded Systems Build Process using GNU Toolchain

17. Peripheral Access - CMSIS-Core (Cortex-M)  Version 5.5.0

18. リンカスクリプトを理解しよう - GNU Cを使いこなそう

19. INTERRUPT HANDLING IN ARM CORTEX M

20. SRecord 1.64

Saturday, August 14, 2021

All about Global Warming

July Was The Hottest Month In Recorded Human History
によると、「July was the hottest month ever recorded in human history, according to new data from the National Oceanic and Atmospheric Administration.
"In this case, first place is the worst place to be," NOAA Administrator Rick Spinrad said in a statement. "July is typically the world's warmest month of the year, but July 2021 outdid itself as the hottest July and month ever recorded."」

これは数十年前から注目されて、世界レベルで研究・議論されてきた課題です。同時に、各国の政治道具にもなっています。

2018年のニュースである「Trump on climate change report: 'I don't believe it'」では、当時のアメリカ大統領が「Right now we're at the cleanest we've ever been and that's very important to me.」と断言しました。

外務省の「二酸化炭素(CO2)排出量の多い国
順位 国名」によると、排出量(100万トン)(2018年)の一位は確かに中国で、9,570.8でした。しかし、アメリカはその約半分の4,921.1で、堂々の2でした。さらに、一人当たりの排出量で言うと、むしろ中国の2倍以上です。

日本は1,080.7で、アメリカの約5分の1でした。つまり一人当たりの排出量はアメリカよりも若干多い計算です。

でも、2021年現在でも、中国やインド(3位の2,307.8)はまだ世界の製造工場です。つまり、他の国々はその製造工場の排出量の恩恵を受けていることです。