7 years, 1 month ago.

Why can't I access FTM2->MODE on the FRDM-K64f?

I need to access the FTM2_MODE register. I tried using FRM2->MODE but it won't compile.

I looked through the file "MK64F12.h" to see the declarations to ensure I was using them correctly. Here they are:

MK64F12.h

typedef struct {
  __IO uint32_t SC;                                /**< Status And Control, offset: 0x0 */
  __IO uint32_t CNT;                               /**< Counter, offset: 0x4 */
  __IO uint32_t MOD;                               /**< Modulo, offset: 0x8 */
  struct {                                         /* offset: 0xC, array step: 0x8 */
    __IO uint32_t CnSC;                              /**< Channel (n) Status And Control, array offset: 0xC, array step: 0x8 */
    __IO uint32_t CnV;                               /**< Channel (n) Value, array offset: 0x10, array step: 0x8 */
  } CONTROLS[8];
  __IO uint32_t CNTIN;                             /**< Counter Initial Value, offset: 0x4C */
  __IO uint32_t STATUS;                            /**< Capture And Compare Status, offset: 0x50 */
  __IO uint32_t MODE;                              /**< Features Mode Selection, offset: 0x54 */
  __IO uint32_t SYNC;                              /**< Synchronization, offset: 0x58 */
  __IO uint32_t OUTINIT;                           /**< Initial State For Channels Output, offset: 0x5C */
  __IO uint32_t OUTMASK;                           /**< Output Mask, offset: 0x60 */
  __IO uint32_t COMBINE;                           /**< Function For Linked Channels, offset: 0x64 */
  __IO uint32_t DEADTIME;                          /**< Deadtime Insertion Control, offset: 0x68 */
  __IO uint32_t EXTTRIG;                           /**< FTM External Trigger, offset: 0x6C */
  __IO uint32_t POL;                               /**< Channels Polarity, offset: 0x70 */
  __IO uint32_t FMS;                               /**< Fault Mode Status, offset: 0x74 */
  __IO uint32_t FILTER;                            /**< Input Capture Filter Control, offset: 0x78 */
  __IO uint32_t FLTCTRL;                           /**< Fault Control, offset: 0x7C */
  __IO uint32_t QDCTRL;                            /**< Quadrature Decoder Control And Status, offset: 0x80 */
  __IO uint32_t CONF;                              /**< Configuration, offset: 0x84 */
  __IO uint32_t FLTPOL;                            /**< FTM Fault Input Polarity, offset: 0x88 */
  __IO uint32_t SYNCONF;                           /**< Synchronization Configuration, offset: 0x8C */
  __IO uint32_t INVCTRL;                           /**< FTM Inverting Control, offset: 0x90 */
  __IO uint32_t SWOCTRL;                           /**< FTM Software Output Control, offset: 0x94 */
  __IO uint32_t PWMLOAD;                           /**< FTM PWM Load, offset: 0x98 */
} FTM_Type;

#define FTM2_BASE   (0x4003A000u)
#define FTM2        ((FTM_Type *)FTM2_BASE)

If I'm understanding the code correctly, I should be able to call "FTM2->MODE" but I can't for some reason. I tried FTM2->SC, FTM2->CNT, FTM2->CONTROLS[0].CnSV, and all the others options defined in FTM_Type. They all work except FTM2->MODE, which is really odd.

I must be missing something obvious. Could someone point it out or suggest another way to access the FTM2_MODE register?

1 Answer

7 years, 1 month ago.

Compiles fine here. Do you maybe have a very old mbed library? (Right mouse button, update in the online compiler). And you are using the correct target, not another (ex) Freescale MCU?

It's up-to-date. The error is "Expected a member name "ODE;" which is the end of the command "FTM2->MODE;". The platform is the FRDM-K64F. The code was originally for an older mbed library, but I was updating the code to work with the current mbed library. FTM2_MODE no longer works with the new (current) mbed library so I changed all "FTM2_" to "FTM2->" and they all worked except "FTM2->MODE".

posted by Joseph McElderry 16 Mar 2017

This program:

#include "mbed.h"

DigitalOut myled(LED1);

int main() {
    FTM2->MODE = 0;
    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }
}

Compiles fine for me. (It probably won't actually work since I think the FTM is unclocked at that point, but it does compile). With revision 138 of the mbed lib. Could it be that you got some weird special (hidden) character somewhere? Or for example a macro defined which breaks it?

posted by Erik - 16 Mar 2017