cancel
Showing results for 
Search instead for 
Did you mean: 

I can't get the ouputs to do anything.

Dan in WY
Associate III

I'm using STM32CubeMX and Atollic's TrueStudio to make a simple program that writes to the serial port and turns on and of ports B3 and B4.

I've tried every possible combination in the GPIO section of Pinout & Confiuration of CubeMX and can't read any volts output to those pins. The serial port works fine. I'm using freeRTOS as middleware and have the gpio, uart and freertos in separate source files. Here's the freertos.c file.

#include "task.h"
#include "main.h"
#include "cmsis_os.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */     
 
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
#define mainQUEUE_SEND_FREQUENCY_MS			( 2000 / portTICK_PERIOD_MS )
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
 
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
 
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */
extern UART_HandleTypeDef huart1;
/* USER CODE END Variables */
osThreadId defaultTaskHandle;
osThreadId Task02Handle;
osThreadId Task03Handle;
osMessageQId Queue01Handle;
 
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
   
/* USER CODE END FunctionPrototypes */
 
void StartDefaultTask(void const * argument);
void StartTask02(void const * argument);
void StartTask03(void const * argument);
 
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
 
/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */
       
  /* USER CODE END Init */
 
  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */
 
  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */
 
  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */
 
  /* Create the thread(s) */
  /* definition and creation of defaultTask */
  osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
 
  /* definition and creation of Task02 */
  osThreadDef(Task02, StartTask02, osPriorityIdle, 0, 128);
  Task02Handle = osThreadCreate(osThread(Task02), NULL);
 
  /* definition and creation of Task03 */
  osThreadDef(Task03, StartTask03, osPriorityIdle, 0, 128);
  Task03Handle = osThreadCreate(osThread(Task03), NULL);
 
  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  /* USER CODE END RTOS_THREADS */
 
  /* Create the queue(s) */
  /* definition and creation of Queue01 */
  osMessageQDef(Queue01, 16, uint16_t);
  Queue01Handle = osMessageCreate(osMessageQ(Queue01), NULL);
 
  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */
}
 
/* USER CODE BEGIN Header_StartDefaultTask */
/**
  * @brief  Function implementing the defaultTask thread.
  * @param  argument: Not used 
  * @retval None
  */
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void const * argument)
{
 
  /* USER CODE BEGIN StartDefaultTask */
	UCHAR xchar = 0x22;
	UCHAR buff[100];
	int i;
	for(i = 0;i < 100;i++)
	{
		buff[i] = xchar;
 		if(++xchar > 0x7e)
			xchar = 0x21;
 	}
	i = 0x21;
	/* Infinite loop */
	for(;;)
	{
		HAL_UART_Transmit(&huart1,buff,93,100);
		vTaskDelay(500);
 	}
  /* USER CODE END StartDefaultTask */
}
 
/* USER CODE BEGIN Header_StartTask02 */
/**
* @brief Function implementing the Task02 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartTask02 */
void StartTask02(void const * argument)
{
  /* USER CODE BEGIN StartTask02 */
	unsigned long ulReceivedValue;
  /* Infinite loop */
 
 	static int onoff = 0;
	for(;;)
	{
		xQueueReceive( Queue01Handle, &ulReceivedValue, portMAX_DELAY );
		HAL_GPIO_TogglePin(test5_GPIO_Port, test5_Pin);
		HAL_GPIO_TogglePin(test4_GPIO_Port, test4_Pin);
		
		if(onoff == 0)
		{
			HAL_GPIO_WritePin(LED_PORT_GPIO_Port, LED_PORT_Pin, GPIO_PIN_RESET);
			onoff = 1;
		}else
		{
 			HAL_GPIO_WritePin(LED_PORT_GPIO_Port, LED_PORT_Pin, GPIO_PIN_SET);
		}
	}
 
 
  /* USER CODE END StartTask02 */
}
 
/* USER CODE BEGIN Header_StartTask03 */
/**
* @brief Function implementing the Task03 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartTask03 */
void StartTask03(void const * argument)
{
  /* USER CODE BEGIN StartTask03 */
	const unsigned long ulValueToSend = 500UL;
	TickType_t xNextWakeTime;
  /* Infinite loop */
	for(;;)
	{
		vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
		xQueueSend( Queue01Handle, &ulValueToSend, 0 );
 
	}
  /* USER CODE END StartTask03 */
}
 
/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
 
 
/* USER CODE END Application */
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

14 REPLIES 14
S.Ma
Principal

Check and make sure that the GPIOB registers in debug mode are properly initialized.

If both are outputs (driving voltage), make then push-pull output MODER = 01

If both are inputs (reading voltage), make then input with pull-up (so when they are not connected, they report 1=Vdd)

If the GPIOB registers are all zeros, it means the clock enable for this GPIOB was missing and registers can;t be written.

MikeDB
Lead

Is this for an STM32F103 or similar ? If so PB3 and PB4 are assigned as a debug port on boot and you need to use disableDebugPorts() or similar to change them to normal ports.

Dan in WY
Associate III

I don't *have* to use PB3 & 4. I can't find anything called disableDebugPorts() in the generated code. I am calling __HAL_AFIO_REMAP_SWJ_DISABLE() tho. I'll let you know what I find out...

MikeDB
Lead

The actual code I use is

       RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;

       AFIO->MAPR = AFIO_MAPR_SWJ_CFG_1;

Dan in WY
Associate III

OK I got GPIOA to work and that's good enough for me now...

hello.

from above code LED toggles only once (did you forget onoff = 0; at line 150?)

If xQueueReceive never returns , then test5_Pin and test4_Pin have always its initial value (usually LO)

If xQueueReceive returns immediately then test5_Pin and test4_Pin have indefinite state (hi freq ) and in case GPIOs configured at low speed, no freq out

So.. check xQueueSend and xQueueReceive functionality first by put a breakpoint in line 141 , walking step by step the rest code and watching GPIO registers. This will gives you the answers about the issue.

Dan in WY
Associate III

I removed line 150 by accident when I was trimming the commented out code just to post it here. I was using HAL_GPIO_WritePin instead of TogglePin inside the if(onoff... but setting pin4/5 right after one another and the speed was conf as low that maybe that was it.

Dan in WY
Associate III

I just tested every pin on this chip and the only ones I can get to work are:

A0, A1, A2, A3, A9, A10 and PB12.

I've disabled every other peripheral except the LED which is PC13.

Dan in WY
Associate III

Would it make any difference if you powered the board via the USB or with an external power supply?