ChibiOS vs maple jtag

Posted at 2015-12-28.

Yesterday I was trying to get some simple GPIO pins working on a Maple mini clone with ChibiOS HAL. Turns out, I'd picked maybe the only five(!) pins that don't work out of the box. I tried a further one, D17 (PB5), and it worked. (D17 is not marked as 5V tolerant.) So, it looks like these pins may be special and board.h does indeed give JTAG sounding names to them. Could JTAG be enabled at boot? Could I disable it?

Experiment

After lots of grep and google, I suspected that a line:

AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE;

Should enable these:

Looks like the first three do work, but that still leaves two.

Looking further, there's a disable for SWD as well:

AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_DISABLE;

This seems to give me 5 (6) working adjacent IO pins. Neat!

Towards step patterns

I pulled up an ULN2003 board that has LEDs on the outputs for an easy way to look at a set of pins. If it looks like a sequence, I can just plug in a stepper, too. I'll have to find a power supply for an actual motor as the LED board is now powered by the Maple and it won't be able to supply very much.

Looks like I've misplaced my old stepper driver codes, but why not write something fresh. I think I can use palWritePad and conditions as a straightforward way to pass bits from a pattern to pins.

/*
 * Stepper driving sequence
 * 0001 = 0x01
 * 0011 = 0x03
 * 0010 = 0x02 
 * 0110 = 0x06
 * 0100 = 0x04
 * 1100 = 0x0c
 * 1000 = 0x08
 * 1001 = 0x09
 */
static THD_FUNCTION(stepperThread, arg) {
  (void) arg; 
  static const uint8_t steps[] = {
      0x01, 0x03, 0x02, 0x06, 0x04, 0x0c, 0x08, 0x09
  };
  static uint8_t stepn = 0;

  palSetPadMode(GPIOB, 4, PAL_MODE_OUTPUT_PUSHPULL);
  palSetPadMode(GPIOB, 3, PAL_MODE_OUTPUT_PUSHPULL);
  palSetPadMode(GPIOA, 15, PAL_MODE_OUTPUT_PUSHPULL);
  palSetPadMode(GPIOA, 14, PAL_MODE_OUTPUT_PUSHPULL);

  while (true) {
    // Set pins to match bits from step
    palWritePad(GPIOB,  4, ( steps[stepn] & 0x01 ) > 0 );
    palWritePad(GPIOB,  3, ( steps[stepn] & 0x02 ) > 0 );
    palWritePad(GPIOA, 15, ( steps[stepn] & 0x04 ) > 0 );
    palWritePad(GPIOA, 14, ( steps[stepn] & 0x08 ) > 0 );

    // Increment step, wrap around
    stepn = ( stepn + 1 ) % 8;

    // Sleep, very long at start for visual feedback
    chThdSleepMilliseconds(500);
  }
}

A bit of encoding and masking there. Hopefully not very cryptic if not fantastically elegant either. That's enough to put a familiar shifting pattern going on the LEDs.

Commit, push.

Results

Some more blinking lights and text. No longer annoyed and stuck with unresponsive IO pins. I've also got a driver putting out a four-bit pattern that might drive a motor. I'll need to test that with a suitable power supply and then see if I can use that with the L9110 driver and a bipolar motor.

I've also decided that I need to check the license (probably GPL3, so mine will fall under that as well) and the repo structure. I will probably make a new application and dir outside of the ChibiOS tree and use an upstream pull from there instead of pretending to be one of the demos (the Maple one, even). This will mean new repos and commits, perhaps a step at a time, and retconning the blog to reflect new links.

Edit: Changes done. All posts should refer to existing repo only.

Links