Switch to a new cortex-m4 compiler

This one is newer, so it supports a newer C++ standard. It's also
hermetic.

Also add a variant for building for some Kinetis-K chips with less RAM
that are used on fet12v2.

Change-Id: I9e50b6aae498e0c35acfedb846b3ada619a0e630
diff --git a/motors/core/BUILD b/motors/core/BUILD
index d0385fb..f42a1bc 100644
--- a/motors/core/BUILD
+++ b/motors/core/BUILD
@@ -1,23 +1,26 @@
 load("//tools:environments.bzl", "mcu_cpus")
 
 filegroup(
-  name = 'linkerscript',
-  visibility = ['//tools/cpp:__pkg__'],
-  srcs = [ 'mk64fx512.ld' ],
+    name = "linkerscripts",
+    srcs = [
+        "kinetis_128k.ld",
+        "kinetis_192k.ld",
+    ],
+    visibility = ["//tools/cpp:__pkg__"],
 )
 
 cc_library(
-  name = 'core',
-  visibility = ['//visibility:public'],
-  hdrs = [
-    'kinetis.h',
-    'nonstd.h',
-    'time.h',
-  ],
-  srcs = [
-    'mk20dx128.c',
-    'nonstd.c',
-    'time.cc',
-  ],
-  restricted_to = mcu_cpus,
+    name = "core",
+    srcs = [
+        "mk20dx128.c",
+        "nonstd.c",
+        "time.cc",
+    ],
+    hdrs = [
+        "kinetis.h",
+        "nonstd.h",
+        "time.h",
+    ],
+    restricted_to = mcu_cpus,
+    visibility = ["//visibility:public"],
 )
diff --git a/motors/core/mk64fx512.ld b/motors/core/kinetis_128k.ld
similarity index 94%
copy from motors/core/mk64fx512.ld
copy to motors/core/kinetis_128k.ld
index 05dd9f2..bde65b5 100644
--- a/motors/core/mk64fx512.ld
+++ b/motors/core/kinetis_128k.ld
@@ -28,10 +28,12 @@
  * SOFTWARE.
  */
 
+/* TODO(Brian): De-duplicate with the version for 192K SRAM. */
+/* TODO(Brian): Split out SRAM_L and SRAM_U intelligently. */
 MEMORY
 {
   FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 512K
-  RAM  (rwx) : ORIGIN = 0x1FFF0000, LENGTH = 192K
+  RAM  (rwx) : ORIGIN = 0x1FFF0000, LENGTH = 128K
 }
 
 ENTRY(_VectorsFlash);
diff --git a/motors/core/mk64fx512.ld b/motors/core/kinetis_192k.ld
similarity index 95%
rename from motors/core/mk64fx512.ld
rename to motors/core/kinetis_192k.ld
index 05dd9f2..c266f3d 100644
--- a/motors/core/mk64fx512.ld
+++ b/motors/core/kinetis_192k.ld
@@ -28,6 +28,8 @@
  * SOFTWARE.
  */
 
+/* TODO(Brian): De-duplicate with the version for 128K SRAM. */
+/* TODO(Brian): Split out SRAM_L and SRAM_U intelligently. */
 MEMORY
 {
   FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 512K
diff --git a/motors/fet12/fet12.cc b/motors/fet12/fet12.cc
index 6fedeab..f008379 100644
--- a/motors/fet12/fet12.cc
+++ b/motors/fet12/fet12.cc
@@ -306,6 +306,8 @@
   delay(1000);
 #if 0
   ZeroMotor();
+#else
+  (void)ZeroMotor;
 #endif
 
   printf("Zeroed motor!\n");
diff --git a/motors/pistol_grip/controller.cc b/motors/pistol_grip/controller.cc
index 8b842b7..2bb3e01 100644
--- a/motors/pistol_grip/controller.cc
+++ b/motors/pistol_grip/controller.cc
@@ -359,20 +359,20 @@
               static_cast<int32_t>(static_cast<uint32_t>(data[0]) |
                                    (static_cast<uint32_t>(data[1]) << 8)) -
               32768) /
-          32768.0f * M_PI / 8.0;
+          static_cast<float>(32768.0 * M_PI / 8.0);
       trigger_goal_velocity =
           static_cast<float>(
               static_cast<int32_t>(static_cast<uint32_t>(data[2]) |
                                    (static_cast<uint32_t>(data[3]) << 8)) -
               32768) /
-          32768.0f * 4.0f;
+          static_cast<float>(32768.0 * 4.0);
 
       trigger_haptic_current =
           static_cast<float>(
               static_cast<int32_t>(static_cast<uint32_t>(data[4]) |
                                    (static_cast<uint32_t>(data[5]) << 8)) -
               32768) /
-          32768.0f * 2.0f;
+          static_cast<float>(32768.0 * 2.0);
       if (trigger_haptic_current > kHapticTriggerCurrentLimit) {
         trigger_haptic_current = kHapticTriggerCurrentLimit;
       } else if (trigger_haptic_current < -kHapticTriggerCurrentLimit) {
@@ -400,20 +400,20 @@
               static_cast<int32_t>(static_cast<uint32_t>(data[0]) |
                                    (static_cast<uint32_t>(data[1]) << 8)) -
               32768) /
-          32768.0f * M_PI;
+          static_cast<float>(32768.0 * M_PI);
       wheel_goal_velocity =
           static_cast<float>(
               static_cast<int32_t>(static_cast<uint32_t>(data[2]) |
                                    (static_cast<uint32_t>(data[3]) << 8)) -
               32768) /
-          32768.0f * 10.0f;
+          static_cast<float>(32768.0 * 10.0);
 
       wheel_haptic_current =
           static_cast<float>(
               static_cast<int32_t>(static_cast<uint32_t>(data[4]) |
                                    (static_cast<uint32_t>(data[5]) << 8)) -
               32768) /
-          32768.0f * 2.0f;
+          static_cast<float>(32768.0 * 2.0);
       if (wheel_haptic_current > kHapticWheelCurrentLimit) {
         wheel_haptic_current = kHapticWheelCurrentLimit;
       } else if (wheel_haptic_current < -kHapticWheelCurrentLimit) {
diff --git a/motors/pistol_grip/drivers_station.cc b/motors/pistol_grip/drivers_station.cc
index d78cfd4..e87d5e3 100644
--- a/motors/pistol_grip/drivers_station.cc
+++ b/motors/pistol_grip/drivers_station.cc
@@ -19,7 +19,8 @@
 
 ::std::atomic<teensy::AcmTty *> global_stdout{nullptr};
 
-void EchoChunks(teensy::AcmTty *tty1) {
+// TODO(Brian): Move this and the other two test functions somewhere else.
+__attribute__((unused)) void EchoChunks(teensy::AcmTty *tty1) {
   while (true) {
     char buffer[512];
     size_t buffered = 0;
@@ -42,7 +43,7 @@
   }
 }
 
-void EchoImmediately(teensy::AcmTty *tty1) {
+__attribute__((unused)) void EchoImmediately(teensy::AcmTty *tty1) {
   while (true) {
     if (false) {
       // Delay for a while.
@@ -60,7 +61,7 @@
   }
 }
 
-void WriteData(teensy::AcmTty *tty1) {
+__attribute__((unused)) void WriteData(teensy::AcmTty *tty1) {
   GPIOC_PTOR = 1 << 5;
   for (int i = 0; i < 100000000; ++i) {
     GPIOC_PSOR = 0;
diff --git a/motors/simple_receiver.cc b/motors/simple_receiver.cc
index f8b38f0..3b174b0 100644
--- a/motors/simple_receiver.cc
+++ b/motors/simple_receiver.cc
@@ -188,7 +188,8 @@
   can_send(id, data, sizeof(data), 2 + vesc_id);
 }
 
-void DoVescTest() {
+// TODO(Brian): Move these two test functions somewhere else.
+__attribute__((unused)) void DoVescTest() {
   uint32_t time = micros();
   while (true) {
     for (int i = 0; i < 6; ++i) {
@@ -212,7 +213,7 @@
   }
 }
 
-void DoReceiverTest2() {
+__attribute__((unused)) void DoReceiverTest2() {
   static constexpr float kMaxRpm = 10000.0f;
   while (true) {
     const bool flip = convert_input_width(2) > 0;