Porting NETMF 4.4 to an STM32F4

#define SYSTEM_CLOCK_HZ 84000000 // 84 MHz
#define SYSTEM_CYCLE_CLOCK_HZ 84000000 // 84 MHz
#define SYSTEM_APB1_CLOCK_HZ 42000000 // 42 MHz
#define SYSTEM_APB2_CLOCK_HZ 84000000 // 84 MHz
#define SYSTEM_CRYSTAL_CLOCK_HZ 8000000 // 8 MHz external clock that is used from STLINK Directly
#define CLOCK_COMMON_FACTOR 1000000 // GCD(SYSTEM_CLOCK_HZ, 1M)
#define SLOW_CLOCKS_PER_SECOND 1000000 // 1 MHz
#define SLOW_CLOCKS_TEN_MHZ_GCD 1000000 // GCD(SLOW_CLOCKS_PER_SECOND, 10M)
#define SLOW_CLOCKS_MILLISECOND_GCD 1000 // GCD(SLOW_CLOCKS_PER_SECOND, 1k)
#define SUPPLY_VOLTAGE_MV 3300 // 3.3V supply
// Memory
#define FLASH_MEMORY_Base 0x08000000
#define FLASH_MEMORY_Size 0x00080000 // 512K
#define SRAM1_MEMORY_Base 0x20000000
#define SRAM1_MEMORY_Size 0x00018000 // 96K

so just adjust clock speed i dont now what speed i used on nucleo 72.80 or 84mhz

@valon_hoti_gmail_com The pin definitions in the files are way different than the STM32401, is that because it is the nucleo?

In the data sheet for the 411 it says SPI1 is PB3, PB4, and PB5 but in the definitions above you list it as PA5, PA6, and PA7.

i created solution for nucleo stm32f411 and i belive nucleo stm32f401 should be the same
“but less ram and speed” - but i can not confirm because i have no nucleo 401 to check properly

That was the first discrepancy I saw, there may be more.

more info about pins regards nucleo 401

The minimum files you need to change when making a new NETMF STM32F4xx port are these:

platform_selector.h // Freq, ram and flash sizes, xtal speed and pin mappings - in your case probably just Freq and ram.

STM32F4_BlConfig.cpp // Flash layout - should be ok for 401 vs 411

IO_Init.cpp // Turns on ports and sets default pins - prob ok for 401 vs 411

scatterfile_bootloader_gcc.xml // Flash and ram layouts
scatterfile_tinyclr_gcc.xml

If I look at the datasheets then compare with the pinouts in these header files, the I2C and SPI pins are in different places. ST datasheets for the 401 and 411 match. But neither of those seem to match the header files

@valon_hoti_gmail_com SPI1 and I2C don’t match either the 401 or 411 datasheets. I am confused…

image

you do not need to see on datasheet so you can define by your needs

i prepared to meet my picture as presented here

and

I need the pin outs to match the data sheets because I am substituting this on a board that was made for the G30

and one thing how to calculate pins when you define it for exampe PAn
A=(16 * 0) +n
B=(16 * 1) +n
C=(16 * 2) +n
D=(16 * 3) +n

so based on calculation you get
PA1 = (16 * 0)+1 = 0+1 = 1
PB8 = (16 * 1)+8 = 16+8 = 24

Can I delete the things I do not need like the LED part? Also I am unsure of some parts in bold below (hopefully I did the rest correct):

// constants
//
// System clock
#define SYSTEM_CLOCK_HZ 84000000 // 84 MHz
#define SYSTEM_CYCLE_CLOCK_HZ 84000000 // 84 MHz
#define SYSTEM_APB1_CLOCK_HZ 42000000 // 42 MHz
#define SYSTEM_APB2_CLOCK_HZ 84000000 // 84 MHz
#define SYSTEM_CRYSTAL_CLOCK_HZ 12000000 // 12 MHz external clock
#define CLOCK_COMMON_FACTOR 1000000 // GCD(SYSTEM_CLOCK_HZ, 1M)
#define SLOW_CLOCKS_PER_SECOND 1000000 // 1 MHz
#define SLOW_CLOCKS_TEN_MHZ_GCD 1000000 // GCD(SLOW_CLOCKS_PER_SECOND, 10M)
#define SLOW_CLOCKS_MILLISECOND_GCD 1000 // GCD(SLOW_CLOCKS_PER_SECOND, 1k)
#define SUPPLY_VOLTAGE_MV 3300 // 3.3V supply
// Memory
#define FLASH_MEMORY_Base 0x08000000
#define FLASH_MEMORY_Size 0x00080000 // 512K
#define SRAM1_MEMORY_Base 0x20000000
#define SRAM1_MEMORY_Size 0x00018000 // 96K
//total GPIO PORTS A,B,C,D
#define TOTAL_GPIO_PORT 3
#define TOTAL_GPIO_PINS (TOTAL_GPIO_PORT*16)
//total UART TLL ports
#define TOTAL_USART_PORT 3
#define USART_DEFAULT_PORT COM1
#define USART_DEFAULT_BAUDRATE 115200
//used generic but SWO is PB3 it should defined otherway … on nucleo stm32f411ret6
#define TOTAL_GENERIC_PORTS 1 // 1 generic port extensions (ITM channel 0 )
#define ITM_GENERIC_PORTNUM 0 // ITM0 is index 0 in generic port interface table
//debug to be used …
#define DEBUG_TEXT_PORT ITM0
#define STDIO ITM0
#define DEBUGGER_PORT USB1
#define MESSAGING_PORT USB1
//total controllers
#define TOTAL_USB_CONTROLLER 1 // FS only
#define USB_MAX_QUEUES 4 // 3 endpoints (EP0 + 2)
//scok port
#define TOTAL_SOCK_PORT 0
// System Timer Configuration
#define STM32F4_32B_TIMER 5
#define STM32F4_16B_TIMER 1
// Pin Configuration
#define STM32F4_ADC 1
#define STM32F4_AD_CHANNELS {8,9,10,11,14,15,16,17,20,21,22,23,24,25,26,27} // PC0, PC1, PC2, PC3, PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PC4, PC5, PB0, PB1
//pwm
#define STM32F4_PWM_TIMER {2,2,2,3,1,1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 2, 3, 3, 3, 3}
#define STM32F4_PWM_CHNL {1,2,1,1,1,2, 3, 4, 1, 2, 1, 2, 1, 2, 3, 4, 3, 1, 2, 3, 4}
#define STM32F4_PWM_PINS {0,1,5,6,8,9,10,11,15,19,20,21,22,23,24,25,26,38,39,40,41}
//spi
#define STM32F4_SPI_SCLK_PINS {55, 34} // PB3, PB13
#define STM32F4_SPI_MISO_PINS {56, 35} // PB4, PB14
#define STM32F4_SPI_MOSI_PINS {57, 36} // PB5, PB15
//i2c
#define STM32F4_I2C_PORT 1
#define STM32F4_I2C_SCL_PIN 58 // PB6
#define STM32F4_I2C_SDA_PIN 59 // PB7
//uart
#define STM32F4_UART_RXD_PINS {43, 17} // PA10, PA3
#define STM32F4_UART_TXD_PINS { 42, 16} // PA9, PA2
#define STM32F4_UART_CTS_PINS {GPIO_PIN_NONE, 14 } // PA0
#define STM32F4_UART_RTS_PINS {GPIO_PIN_NONE, 15 } // PA1
// User LEDs
#define LED2 5 // Green
// TinyBooter entry using GPIO
#define TINYBOOTER_ENTRY_GPIO_PIN 45 // User button
#define TINYBOOTER_ENTRY_GPIO_STATE FALSE // Active low
#define TINYBOOTER_ENTRY_GPIO_RESISTOR RESISTOR_DISABLED
//
// constants

#define STM32F4_I2C_PORT 1
#define STM32F4_I2C_SCL_PIN 58 // PB6
#define STM32F4_I2C_SDA_PIN 59 // PB7

Did you mean scl pin is PD10 and SDA is PD11

Little bit lost changing the Ram and Flash Layouts, especially in the two scatter files. All I know is to change the Ram Size line from 0x00020000 to 0x00018000…the Flash size is 512kb for both devices so that part doesn’t need to change. I am not sure about all the base address stuff and what else needs to be changed in these files besides that line.

Also I don’t really understand how 0x00080000 = 512 kb, doesn’t it equal 524288?

524288/1024=512

On the STM32F401 the SCL is pin 58 / PB6 and SDA is pin 59 / PB7. There is no PD10 or PD11

What is the 1024 from? Sorry I get mixed up by conversions

524288 Bytes vs 512 KBytes

Oh ya thank you, kilo makes me think 1000.

You made wrong values
I give to you formula how to declare pins

A=0
B=16
C=32
D=48 so

PA0 mean 0+0=0
PA5 mean 0+5=5 (those values are not hex values)

PB7 mean 16+7=23 when you declare pins

And you seted value 58 is which mean 48+10 = D10

I don’t understand what you mean. I am going straight from the ST datasheet:

Pin 58 = PB6 = SCL
Pin 59 = PB7 = SDA

It is the same in the GHI G30 datasheet as well:
image

My PCB is routed so that pins 58 and 59 are the I2C lines…I have to replicate that