2019-10-04 01:20 AM
Hi,
I am trying to develop a simple example program to control the 3 User LED's in the nucleo-144 board.
Part number - STM32L4R5ZI
I have configured the following clock settings and BSP for the LED's.
Clock Settings:
/* Enable MSI oscillator and configure the PLL to reach the max system frequency (120 MHz)
when using MSI oscillator as PLL clock source. */
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
HAL_PWR_EnableBkUpAccess();
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_LSI| RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6; /* 4MHz */
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
RCC_OscInitStruct.PLL.PLLM = 1;
RCC_OscInitStruct.PLL.PLLN = 60;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK)
{
/* Enable MSI in PLL mode */
HAL_RCCEx_EnableMSIPLLMode();
}
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
/* To avoid undershoot due to maximum frequency, select PLL as system clock source */
/* with AHB prescaler divider 2 as first step */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
{
return FAILURE:
}
I hope the clock settings are fine.
Out of the 3 user LED's Red(PortB ; GPIO_PIN_14)and Green(PORT C ; GPIO_PIN_7) are working as expected, but BLUE LED(PortB ; GPIO_PIN_7) is not working.
Any clue would be of great help.
Thanks & Regards,
Shanmathi
2019-10-04 02:53 AM
Please check MB1312 schematic and STM32L4R5 datasheet, and if necessary the BOM for Nucleo 144 STM32L4R5 , to check on what pin the blue LED is.
2019-10-04 03:03 AM
Hi Mike,
I have checked with the schematic.
It is PB7 for Blue LED. Also mentioned in Board_Drawing_en.DM00368330.pdf
SB171 is open and SB172 is closed in the development kit.
2019-10-04 03:07 AM
Maybe If you have SMPS version of the board, aka NUCLEO-L4R5ZI-P.
It may be connected to PB6 instead.
2019-10-04 03:15 AM
Checked with the board. It is NUCLEO-L4R5ZI not NUCLEO-L4R5ZI-P.
But I tried now PB6 instead of PB7, still blue LED is not blinking.
2019-10-04 04:09 AM
Show the code configuring and blinking the LED, it will be a lot more enlightening than the clock code.
2019-10-04 04:22 AM
#define PINB_LED_R GPIO_PIN_14
#define PINB_LED_B GPIO_PIN_6
#define PINC_LED_G GPIO_PIN_7
BSP_LED_Connect(void)
{
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_Init.Pin = (PINB_LED_R | PINB_LED_B);
GPIO_Init.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_Init.Pull = GPIO_NOPULL;
GPIO_Init.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_Init);
GPIO_Init.Pin = PINC_LED_G;
HAL_GPIO_Init(GPIOC, &GPIO_Init);
}
BSP_LED_Enable(void)
{
HAL_GPIO_WritePin(GPIOB, (PINB_LED_R | PINB_LED_B), GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOC, PINC_LED_G, GPIO_PIN_RESET);
}
BSP_LED_Disable(void)
{
LED_Off(NUCLEOL4_LED_ALL);
}
BSP_LED_Disconnect(void)
{
HAL_GPIO_DeInit(GPIOB, (PINB_LED_R | PINB_LED_B));
HAL_GPIO_DeInit(GPIOC, PINC_LED_G);
}
BSP_LED_Switch(uint32_t id, uint32_t command)
{
switch (command)
{
case NUCLEOL4_LED_COMMAND_OFF:
retcode = LED_Off(id);
break;
case NUCLEOL4_LED_COMMAND_ON:
retcode = LED_On(id);
break;
case NUCLEOL4_LED_COMMAND_TOGGLE:
retcode = LED_Toggle(id);
break;
default:
break;
}
}
/*---------------------- LOCAL FUNCTIONS IMPLEMENTATION ----------------------*/
LED_Off(uint32_t id)
{
switch (id)
{
case NUCLEOL4_LED_ALL:
HAL_GPIO_WritePin(GPIOB, (PINB_LED_R | PINB_LED_B), GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOC, PINC_LED_G, GPIO_PIN_RESET);
break;
case NUCLEOL4_LED_RED_ID:
HAL_GPIO_WritePin(GPIOB, PINB_LED_R, GPIO_PIN_RESET);
break;
case NUCLEOL4_LED_GREEN_ID:
HAL_GPIO_WritePin(GPIOC, PINC_LED_G, GPIO_PIN_RESET);
break;
case NUCLEOL4_LED_BLUE_ID:
HAL_GPIO_WritePin(GPIOB, PINB_LED_B, GPIO_PIN_RESET);
break;
default:
break;
}
}
LED_On(uint32_t id)
{
switch (id)
{
case NUCLEOL4_LED_ALL:
HAL_GPIO_WritePin(GPIOB, (PINB_LED_R | PINB_LED_B), GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOC, PINC_LED_G, GPIO_PIN_SET);
break;
case NUCLEOL4_LED_RED_ID:
HAL_GPIO_WritePin(GPIOB, PINB_LED_R, GPIO_PIN_SET);
break;
case NUCLEOL4_LED_GREEN_ID:
HAL_GPIO_WritePin(GPIOC, PINC_LED_G, GPIO_PIN_SET);
break;
case NUCLEOL4_LED_BLUE_ID:
HAL_GPIO_WritePin(GPIOB, PINB_LED_B, GPIO_PIN_SET);
break;
default:
break;
}
}
LED_Toggle(uint32_t id)
{
Retcode_T retcode = RETCODE_OK;
switch (id)
{
case NUCLEOL4_LED_ALL:
HAL_GPIO_TogglePin(GPIOB, (PINB_LED_R | PINB_LED_B));
HAL_GPIO_TogglePin(GPIOC, PINC_LED_G);
break;
case NUCLEOL4_LED_RED_ID:
HAL_GPIO_TogglePin(GPIOB, PINB_LED_R);
break;
case NUCLEOL4_LED_GREEN_ID:
HAL_GPIO_TogglePin(GPIOC, PINC_LED_G);
break;
case NUCLEOL4_LED_BLUE_ID:
HAL_GPIO_TogglePin(GPIOB, PINB_LED_B);
break;
default:
break;
}
}
Hi Clive,
Please find the code snippet for BSP settings of user LED's
2019-10-04 04:24 AM
#define PINB_LED_B GPIO_PIN_6
2019-10-04 04:28 AM
Note:
Tried with both GPIO_PIN_6 and GPIO_PIN_7 for #define PINB_LED_B.
Still the same issue resides.
I completely do not have any clue why only this BLUE LED is not working, while the other two are fine.
2019-10-04 04:42 AM
Might be good idea to check the voltage across the LED, and check that the LED is actually working.