Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+1 #1

Open
FrankBau opened this issue Nov 11, 2020 · 4 comments
Open

+1 #1

FrankBau opened this issue Nov 11, 2020 · 4 comments

Comments

@FrankBau
Copy link

It's not an issue: I like your project and hope that you will be continuing it. Could nearly reproduce your results using different versions of OpenOCD and gdb under Ubuntu. The communication OpenOCD/gdb is sometimes not stable and I see packet error messages or resets. Also didn't use gcc10 which is still labelled "preview" on the ARM download site.
Frank

@WerWolv
Copy link
Owner

WerWolv commented Nov 11, 2020

I's not an issue: I like your project and hope that you will be continuing it.

Hi! I struggled with getting I2C to work so I could talk to the PMIC, that's why I stopped for now.

Could nearly reproduce your results using different versions of OpenOCD and gdb under Ubuntu. The communication OpenOCD/gdb is sometimes not stable and I see packet error messages or resets.

I had issues like that when I used a bad USB cable to connect to the board. Maybe try another one?

Also didn't use gcc10 which is still labelled "preview" on the ARM download site.

Also yeah, I'm on Arch and got the latest gcc from the AUR instead of from the ARM download site. I'm using GCC 10 because the project uses C++20 which is partially supported in GCC 8 and 9 but GCC 10 has many more features. So far I didn't experience any issues and I'm using GCC 10.2.0 basically everywhere,

@FrankBau
Copy link
Author

Thanks for your reply. Yes, the I2C code is missing proper clock and GPIO setup etc.. I hooked up an I2C sensor on I2C5 (PA11+PA12 on Arduino connector for easy LA attachment) and can access it in engineering mode with STM32CubeIDE generated code. This demonstrates all needed initializations.

@FrankBau
Copy link
Author

Here is register level code for reading reg 0xD0 of my sensor on I2C5 device 0x76. The read successfully returns the sensor id: 0x60 when used on M4 in engineering mode. The code uses CMSIS macros + some obvious extensions, no C++, sorry.

	RCC->MC_AHB3ENSETR = RCC_MC_AHB3ENSETR_HSEMEN; // __HAL_RCC_HSEM_CLK_ENABLE();

	__HAL_RCC_CKPER_CONFIG(RCC_CKPERCLKSOURCE_HSE);

	RCC->MC_AHB4ENSETR = RCC_MC_AHB4ENSETR_GPIOAEN; // __HAL_RCC_GPIOA_CLK_ENABLE();

	// SCL: PA11 SDA: PA12

	SET_GPIO_MODE( GPIOA, 11, GPIO_MODE_AF_OD );
	SET_GPIO_MODE( GPIOA, 12, GPIO_MODE_AF_OD );

	SET_GPIO_OTYPE( GPIOA, 11, GPIO_MODE_AF_OD );
	SET_GPIO_OTYPE( GPIOA, 12, GPIO_MODE_AF_OD );

	SET_GPIO_OSPEED( GPIOA, 11, GPIO_SPEED_FREQ_MEDIUM );
	SET_GPIO_OSPEED( GPIOA, 12, GPIO_SPEED_FREQ_MEDIUM );

	SET_GPIO_AF( GPIOA, 11, GPIO_AF4_I2C5 );
	SET_GPIO_AF( GPIOA, 12, GPIO_AF4_I2C5 );

	__HAL_RCC_I2C35_CONFIG(RCC_I2C35CLKSOURCE_PCLK1);

	__HAL_RCC_I2C5_CLK_ENABLE();

	// see Figure 555. I2C initialization flowchart
	I2C5->CR1 &= ~I2C_CR1_PE; // SW reset
	I2C5->TIMINGR = 0x40505874;
	I2C5->CR1 |= I2C_CR1_PE; // CR = 0x1; enable
	while(I2C5->ISR & I2C_FLAG_BUSY);

	I2C5->CR2 = I2C_CR2_START | 0x76<<1 | 1<<16 | I2C_CR2_AUTOEND;
	I2C5->TXDR = 0xD0;
	while( !(I2C5->ISR & I2C_FLAG_TXE) );

	I2C5->CR2 = I2C_CR2_START | 0x76<<1 | 1<<16 | I2C_CR2_RD_WRN | I2C_CR2_AUTOEND;
	while( !(I2C5->ISR & I2C_FLAG_RXNE) );
	volatile uint8_t id = I2C5->RXDR;   // 0x60 !!!

@danngreen
Copy link

danngreen commented Jul 11, 2022

Hi, I wanted to add to the +1 on this!

I would like to use your fix_header.py script in a project I've been working on. The project aims to document how to get an STM32MP15x bare-metal environment up and running. You can see the fsbl bootloader here:
stm32mp1-baremetal

I didn't see a license here, so could you tell me if using your script is in this repo is OK (under an MIT license)? Also if you'd like attribution in a way I didn't do already.

Thanks!

On another note, in continuing the discussion above regarding I2C, I did write an I2C driver in modern C++, that has no dependencies besides the the CMSIS device file. Here and here. Nothing fancy, but enough to configure the PMIC to turn on the required DDR voltages. If you ever decide to pick this project back up, you are welcome to use it.

[Edit: updated link]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants