Hi.
I hope somebody will be able to help me because I’m stuck for few days already and I can not make it work.
I’ve created board based on STM32L433CCU6 CPU. I program it using STLINK with SWD and software core reset.
I made some hello world code in STM32CubeIDE, and my hardware is fine, LED’s are blinking when I run this code:
/**
******************************************************************************
* @file : main.c
* @author : Auto-generated by STM32CubeIDE
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#include <stdint.h>
#include "stm32l433xx.h"
void delayms(uint32_t n);
void delay();
#if !defined(__SOFT_FP__) && defined(__ARM_FP)
#warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
#endif
uint32_t delayvalue;
int main(void) {
SysTick_Config(4000000 / 1000);
NVIC_EnableIRQ(SysTick_IRQn);
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN;
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOCEN;
RCC->APB1ENR1 |= RCC_APB1ENR1_PWREN;
GPIOA->MODER &= ~GPIO_MODER_MODE4;
GPIOA->MODER |= GPIO_MODER_MODE4_0;
GPIOC->MODER &=
~GPIO_MODER_MODE13 & ~GPIO_MODER_MODE14 & ~GPIO_MODER_MODE15;
GPIOC->MODER |= GPIO_MODER_MODE13_0 | GPIO_MODER_MODE14_0
| GPIO_MODER_MODE15_0;
PWR->CR1 |= PWR_CR1_DBP;
RCC->BDCR = 0; //Turn off LSI to make PC14/15 useable as GPIO
delayms(100);
/* Loop forever */
for (;;) {
while (1) {
writeShiftRegister(0XFF);
delayms(200);
writeShiftRegister(0X00);
delayms(200);
}
}
}
void SysTick_Handler() {
delay();
}
void delayms(uint32_t n) {
delayvalue = n;
while (delayvalue != 0)
;
}
void delay() {
if (delayvalue > 0) {
delayvalue--;
} else {
delayvalue = 0;
}
}
void writeShiftRegister(uint8_t data) {
GPIOC->BSRR |= GPIO_BSRR_BR15; //Latch low
for (int i = 0; i < 8; i++) {
GPIOC->BSRR |= GPIO_BSRR_BR14; //Clock low
if (data & (1 << i)) { //Send data
// Data pin high
GPIOC->BSRR |= GPIO_BSRR_BS13;
} else {
// Data pin low
GPIOC->BSRR |= GPIO_BSRR_BR13;
}
GPIOC->BSRR |= GPIO_BSRR_BS14; //Clock high
}
GPIOC->BSRR |= GPIO_BSRR_BS15; //Latch high
}
In STM32CubeProgrammer I can see that my registers are set correctly.
Now I want to use this board with MBED. Because STM32L433CCU6 is not supported right away this is what I did:
- Make new project with MBED OS 6->mbed-os-example-blinky
- Copy all this files: GitHub - ARMmbed/stm32customtargets at GENERIC_TARGET
to my project: /mbed-os/targets/TARGET_STM/ - I modify: /mbed-os/targets/TARGET_STM/TARGET_STM32L4/TARGET_GENERIC_STM32L433CC/PinNames.h :
ARDUINO_UNO_A0 = Px_x,
All ARDUINO_UNO pins to PB_3 (this pin is not used in my board, if I would left them as Px_x then it will show me error during compilation.
I change Px_x here:
// STDIO for console print
#ifdef MBED_CONF_TARGET_STDIO_UART_TX
CONSOLE_TX = MBED_CONF_TARGET_STDIO_UART_TX,
#else
CONSOLE_TX = PA_2,
#endif
#ifdef MBED_CONF_TARGET_STDIO_UART_RX
CONSOLE_RX = MBED_CONF_TARGET_STDIO_UART_RX,
#else
CONSOLE_RX = PB_3,
#endif
I’m not going to use RX pin so I set it also to PB3. PA_2 is avalaible on my board on header.
3. When I want to configure my STLink on that way:
I got error durning compilation:
argument -m/–mcu: GENERIC_STM32L433CC is not a supported MCU. Supported MCUs are: [long list of default MBED devices]
- I create custom_targets.json in root folder of my project:
{
"GENERIC_STM32L433CC": {
"device_name": "STM32L433CCUx",
"inherits": [
"MCU_STM32L433xC"
]
}
}
Now when I start to type digitalOut, I don’t get any hint:
Also when I compile program with: DigitalOut pin(PC_13);
And upload it to the CPU, then I see that all registers in PORTC are 0x00.
When I try to use CMSIS in my code (I also get no code hint’s)
#include "mbed.h"
// Blinking rate in milliseconds
int main()
{
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN;
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOCEN;
RCC->APB1ENR1 |= RCC_APB1ENR1_PWREN;
GPIOA->MODER &= ~GPIO_MODER_MODE4;
GPIOA->MODER |= GPIO_MODER_MODE4_0;
GPIOC->MODER &=
~GPIO_MODER_MODE13 & ~GPIO_MODER_MODE14 & ~GPIO_MODER_MODE15;
GPIOC->MODER |= GPIO_MODER_MODE13_0 | GPIO_MODER_MODE14_0
| GPIO_MODER_MODE15_0;
while (true) {
ThisThread::sleep_for(500);
}
}
Then program can compile, however CPU is not starting (in STM32CubeProgrammer I can see that registers are not set.
What is the solution for my problem?