Problems with openOCD

Discussions and support about ChibiStudio, the free development environment for ARM.
demant
Posts: 8
Joined: Tue Nov 01, 2016 2:09 pm
Has thanked: 1 time

Re: Problems with openOCD

Postby demant » Mon Nov 21, 2016 12:09 am

I use STM32F401NUCLEO-64. By ST-LINK tool I read that the firmware version is: V2.J21.M5 STM32 Debug + Mass storage (in this regard when in
"firmware update" I do "connect the device" does not give me problems and it finds the firmware version). The following is the last loaded code but I think I changed from the actually loaded version (which was working) but the pin setting should be the same (I have highlighted in yellow the pin setting):

Code: Select all

  ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

#include "ch.h"
#include "hal.h"

static int selected_led=0;
static bool led_handle=FALSE;
/*
 * Button check thread. Implementa l'antirimbalzo
 */
static THD_WORKING_AREA(waThread1,128);
static THD_FUNCTION(Thread1,arg) {

  (void)arg;
  chRegSetThreadName("select led");
  while (true) {
    if(palReadPad(GPIOB,2))
    {
      chThdSleepMilliseconds(50);
      if(!palReadPad(GPIOB,2))
      {
        if(selected_led<3)
          selected_led++;
        else
          selected_led=0;
      }
    }

    chThdSleepMilliseconds(1);
  }
}

static THD_WORKING_AREA(waThread2, 128);
static THD_FUNCTION(Thread2, arg) {

  (void)arg;
  chRegSetThreadName("led status");
  while (true) {
    if(palReadPad(GPIOA,10))
    {
      chThdSleepMilliseconds(50);
      if(!palReadPad(GPIOA,10))
        led_handle=TRUE;
    }

    chThdSleepMilliseconds(1);
  }
}

/*
 * Application entry point.
 */
int main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  [highlight=yellow]palSetPadMode(GPIOA, GPIOA_PIN8, PAL_MODE_OUTPUT_PUSHPULL);
  palSetPadMode(GPIOA, GPIOA_PIN9, PAL_MODE_OUTPUT_PUSHPULL);
  palSetPadMode(GPIOA, GPIOB_PIN2, PAL_MODE_INPUT_PULLUP);
  palSetPadMode(GPIOA, GPIOA_PIN10, PAL_MODE_INPUT_PULLUP);[/highlight]
  /*
   * Creates threads.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL);


  /*
   * Normal main() thread activity, in this demo it does nothing except
   * sleeping in a loop and check the button state.
   */
  while (true) {

    switch (selected_led) {
            case 0:
                   palClearPad(GPIOA,8);
                   palClearPad(GPIOA,9);
                    break;
            case 1:
                    if(led_handle)
                      palTogglePad(GPIOA,8);
                    else
                      palSetPad(GPIOA,8);
                    break;

            case 2:
                    if(led_handle)
                       palTogglePad(GPIOA,9);
                    else
                       palSetPad(GPIOA,9);
                    break;

            }

    chThdSleepMilliseconds(500);
  }
}

User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Location: Munich (Germany)
Has thanked: 83 times
Been thanked: 67 times
Contact:

Re: Problems with openOCD

Postby RoccoMarco » Mon Nov 21, 2016 12:51 am

SWD uses PA13 and PA14. Your code doesn't edit that PIN (unless you have changed board files). You can try to use Automatic Mode (ST Link Utility->drop down menu named "Target") to perform a chip full erase: start full erase than connect USB cable.

Check if the Jumper on the ST-Link are both connected (see the following figure)
st-nucleo-layout.JPG

If you aren't able to connect to the target through the ST Link Utility maybe your hardware is permanently damaged.

A separate note:Please wrap code with related tag next time.
Ciao,
RM


Return to “ChibiStudio”

Who is online

Users browsing this forum: No registered users and 11 guests