Custom board with STM32L433CCU6

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:

  1. Make new project with MBED OS 6->mbed-os-example-blinky
  2. Copy all this files: GitHub - ARMmbed/stm32customtargets at GENERIC_TARGET
    to my project: /mbed-os/targets/TARGET_STM/
  3. 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:
Zrzut ekranu 2023-11-29 120846

I got error durning compilation:
argument -m/–mcu: GENERIC_STM32L433CC is not a supported MCU. Supported MCUs are: [long list of default MBED devices]

  1. 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:
Zrzut ekranu 2023-11-29 122455
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?

Hello,

whem you inherit from L433xC you take its memory and clock settings.
So, did you check the differences between both MCUs? Like RAM and ROM size. And also when you made your own board, what clock source do you use? HSI/HSE? It is same like is defined in Mbed?

mbed-os/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L433xC at master · ARMmbed/mbed-os (github.com)

BR, Jan

Hi. Thank you for your reply.

Following your advice, I tooked startup and *.ld file from working project from STM32CubeIDE and copy it to my target folder. Now my target folder look like this:
Zrzut ekranu 2023-12-03 122346
Inside of cmakelist.txt I have:

# Copyright (c) 2022 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

add_library(mbed-generic-stm32l433cc INTERFACE)

target_sources(mbed-generic-stm32l433cc
    INTERFACE
        PeripheralPins.c
        system_clock.c
)


set(STARTUP_FILE TOOLCHAIN_GCC_ARM/startup_stm32l433ccux.s)
set(LINKER_FILE TOOLCHAIN_GCC_ARM/stm32l433CCUX_FLASH.ld)


target_include_directories(mbed-generic-stm32l433cc
    INTERFACE
        .
)

target_link_libraries(mbed-generic-stm32l433cc INTERFACE mbed-stm32l433xc)

file system_clock is empty, so I want it to run on default, MSI 4MHz clock.

This changed nothing:
-In STM32CubeProgrammer I can see that GPIO registers are not set
-When I type anything, I can not get any hints in my code.

Is there any tutorial where step by step can I see how can I generate empty project for board like mine?

Starting address, size of RAM and ROM is here, you have to check if this is ok. Based on this is set the memory in .ld file here so it is not necessary to copy new one from CUBE and also the CUBE one have to be modified little bit before usage, I think.

I do not know what is default but I am no sure is good practice let the clock settings empty. There are another dependencies on this.

Some handy info could be - Port process overview - Porting | Mbed OS 6 Documentation

BR, Jan

The CubeMX linkerfile will not work. Mbed copies the interrupt vector table to the begin of the RAM section and places the data section thereafter. The program may start, but crashes at the first interrupts.

1 Like