juribeparada / MMDVM_HS

MMDVM HotSpot: firmware for ZUMspot or MMDVM_HS based boards (D-Star, DMR, YSF, P25, NXDN and POCSAG)
GNU General Public License v2.0
345 stars 141 forks source link

RF7021SE with STM32 BluePill F103C8 #162

Closed klaute closed 4 months ago

klaute commented 4 months ago

Hello,

I'm currently facing an issue about insufficient FLASH space: /Library/Arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/12.2.1-1.2/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/bin/ld: arduino/sketches/F60AD1570D50DD492424A40317C6EFEC/MMDVM_HS.ino.elf section .rodata' will not fit in regionFLASH' Library/Arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/12.2.1-1.2/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/bin/ld: region `FLASH' overflowed by 16356 bytes collect2: error: ld returned 1 exit status

I haven't installed any bootloader because I do use a STLink v2 device. My hardware RF7021SE with STM32 BluePill F103C8 (replaced R10 by a 1k5 Ohm resistor).

My Arduino IDE (2.3.2) Settings: image

My Config.h file settings:

define LIBRE_KIT_ADF7021

define ADF7021_14_7456

define AD7021_GAIN_AUTO

define STM32_USB_HOST

define ENABLE_SCAN_MODE

define LONG_USB_RESET

define ENABLE_DEBUG

I have installed the following software and working on a Mac M1 with latest MacOS: Arduino IDE 2.3.2 STM32 MCU based boards 2.7.1

I followed the instructions from those pages: https://www.instructables.com/Programming-STM32-BluePill-Via-Arduino-for-Beginne/ https://www.f5uii.net/en/hotspot-homebrew-zumspot-mmdvm-pistar-tune/amp/

Disabling the ENABLE_DEBUG makro changes the amount of overflowed bytes slightly: Library/Arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/12.2.1-1.2/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/bin/ld: arduino/sketches/F60AD1570D50DD492424A40317C6EFEC/MMDVM_HS.ino.elf section .rodata' will not fit in regionFLASH' Library/Arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/12.2.1-1.2/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/bin/ld: region `FLASH' overflowed by 11972 bytes

Do you have any suggestions?

Thank you!

klaute commented 4 months ago

Arduino is able to flash the software if i set USB support to "None" like shown in the screenshot and also DEBUG_ENABLED is commented out: image

But the device is not recognized by a PC/Mac on MacOS/Linux.

klaute commented 4 months ago

I couldn't solve the issue with the Arduino IDE yet. But I switched to the bash on my linux machine, and tried to get on by using make. I'm using a ST Link v2 device to flash the STM32F103 controller.

My Config.h:

#define  CONFIG_H
#define LIBRE_KIT_ADF7021
#define ENABLE_ADF7021
#define ADF7021_14_7456
#define AD7021_GAIN_AUTO
#define STM32_USB_HOST
#define I2C_ADDR 0x22
#define ENABLE_SCAN_MODE
#define LONG_USB_RESET
#define ENABLE_DEBUG

After I have installed the tools running make bl was successful.

After I run sudo make stlink-bl i faced the following errors (BOOT0 set to 1 and BOOT1 set to 0): Output:

/usr/bin/st-flash --flash=128k write ./STM32F10X_Lib/utils/bootloader/generic_boot20_pc13_long_rst.bin 0x8000000                                                                                                                                                                                                             
st-flash 1.7.0                                                                                                                                                                                                                                                                                                               
2024-03-20T10:01:52 INFO common.c: F1xx Medium-density: 20 KiB SRAM, 1040 KiB flash in at least 1 KiB pages.                                                                                                                                                                                                                 
Forcing flash size: --flash=0x00020000                                                                                                                                                                                                                                                                                       
file ./STM32F10X_Lib/utils/bootloader/generic_boot20_pc13_long_rst.bin md5 checksum: 4b2f1eeb1a8aaa192d6255e94a341c, stlink checksum: 0x000900fc                                                                                                                                                                             
2024-03-20T10:01:52 INFO common.c: Attempting to write 7180 (0x1c0c) bytes to stm32 address: 134217728 (0x8000000)                                                                                                                                                                                                           
2024-03-20T10:01:52 INFO common.c: Flash page at addr: 0x08000000 erased  
...                                                                                                                                                                                                                                                   
2024-03-20T10:01:53 INFO common.c: Flash page at addr: 0x08001c00 erased                                                                                                                                                                                                                                                     
2024-03-20T10:01:53 INFO common.c: Finished erasing 8 pages of 1024 (0x400) bytes                                                                                                                                                                                                                                            
2024-03-20T10:01:53 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL                                                                                                                                                                                                                                                   
2024-03-20T10:01:53 INFO flash_loader.c: Successfully loaded flash loader in sram                                                                                                                                                                                                                                            
2024-03-20T10:01:53 INFO flash_loader.c: Clear DFSR                                                                                                                                                                                                                                                                          
2024-03-20T10:01:53 INFO flash_loader.c: Clear CFSR                                                                                                                                                                                                                                                                          
2024-03-20T10:01:53 INFO flash_loader.c: Clear HFSR                                                                                                                                                                                                                                                                          
  8/  8 pages written                                                                                                                                                                                                                                                                                                        
2024-03-20T10:01:53 INFO common.c: Starting verification of write complete                                                                                                                                                                                                                                                   
2024-03-20T10:01:53 INFO common.c: Flash written and verified! jolly good!                                                                                                                                                                                                                                                   
sleep 3                                                                                                                                                                                                                                                                                                                      
/usr/bin/st-flash --flash=128k write bin/mmdvm_f1bl.bin 0x8002000                                                                                                                                                                                                                                                            
st-flash 1.7.0                                                                                                                                                                                                                                                                                                               
2024-03-20T10:01:56 INFO common.c: F1xx Medium-density: 20 KiB SRAM, 64 KiB flash in at least 1 KiB pages.                                                                                                                                                                                                                   
Forcing flash size: --flash=0x00020000                                                                                                                                                                                                                                                                                       
file bin/mmdvm_f1bl.bin md5 checksum: 9f9c1f9b35a9514f5ec6de987f8df1aa, stlink checksum: 0x004ca893                                                                                                                                                                                                                          
2024-03-20T10:01:56 INFO common.c: Attempting to write 59316 (0xe7b4) bytes to stm32 address: 134225920 (0x8002000)                                                                                                                                                                                                          
2024-03-20T10:01:56 INFO common.c: Flash page at addr: 0x08002000 erased
...                                                                                                                                                                                                                                                 
2024-03-20T10:02:01 INFO common.c: Flash page at addr: 0x08010400 erased                                                                                                                                                                                                                                                     
2024-03-20T10:02:01 INFO common.c: Finished erasing 58 pages of 1024 (0x400) bytes                                                                                                                                                                                                                                           
2024-03-20T10:02:01 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL                                                                                                                                                                                                                                                   
2024-03-20T10:02:01 INFO flash_loader.c: Successfully loaded flash loader in sram                                                                                                                                                                                                                                            
2024-03-20T10:02:01 INFO flash_loader.c: Clear DFSR                                                                                                                                                                                                                                                                          
2024-03-20T10:02:01 INFO flash_loader.c: Clear CFSR                                                                                                                                                                                                                                                                          
 58/ 58 pages written^[[A                                                                                                                                                                                                                                                                                                    
2024-03-20T10:02:03 INFO common.c: Starting verification of write complete                                                                                                                                                                                                                                                   
2024-03-20T10:02:04 ERROR common.c: Verification of flash failed at offset: 57344                                                                                                                                                                                                                                            
stlink_fwrite_flash() == -1                                                                                                                                                                                                                                                                                                  
make: *** [Makefile:432: stlink-bl] Fehler 255                                         

But after that the device is recognized as Mapel DFU.

[ 5527.638601] usb 1-1.3: new full-speed USB device number 38 using ehci-pci                                                                                  
[ 5527.748364] usb 1-1.3: New USB device found, idVendor=1eaf, idProduct=0003, bcdDevice= 2.01                                                                
[ 5527.748374] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3                                                                            
[ 5527.748377] usb 1-1.3: Product: Maple 003                                                                                                                  
[ 5527.748380] usb 1-1.3: Manufacturer: LeafLabs                                                                                                              
[ 5527.748382] usb 1-1.3: SerialNumber: LLM 003                                                                                                               
[ 5533.630623] usb 1-1.3: reset full-speed USB device number 38 using ehci-pci 

I noticed that the flash size is set to 128k, as I know my device only has 64k. So I run:

/usr/bin/st-flash --flash=64k write ./STM32F10X_Lib/utils/bootloader/generic_boot20_pc13_long_rst.bin 0x8000000           
st-flash 1.7.0                                                                                                                                                
2024-03-20T10:28:50 INFO common.c: F1xx Medium-density: 20 KiB SRAM, 64 KiB flash in at least 1 KiB pages.                                                    
file ./STM32F10X_Lib/utils/bootloader/generic_boot20_pc13_long_rst.bin md5 checksum: 4b2f1eeb1a8aaa192d6255e94a341c, stlink checksum: 0x000900fc                                                                                                                                                                             
2024-03-20T10:28:50 INFO common.c: Attempting to write 7180 (0x1c0c) bytes to stm32 address: 134217728 (0x8000000)
2024-03-20T10:28:50 INFO common.c: Flash page at addr: 0x08000000 erased                                                                                      
2024-03-20T10:28:50 INFO common.c: Flash page at addr: 0x08000400 erased                                                                                      
2024-03-20T10:28:51 INFO common.c: Flash page at addr: 0x08000800 erased                                                                                      
2024-03-20T10:28:51 INFO common.c: Flash page at addr: 0x08000c00 erased                                                                                      
2024-03-20T10:28:51 INFO common.c: Flash page at addr: 0x08001000 erased       
2024-03-20T10:28:51 INFO common.c: Flash page at addr: 0x08001400 erased                                                                                      
2024-03-20T10:28:51 INFO common.c: Flash page at addr: 0x08001800 erased                                                                                      
2024-03-20T10:28:51 INFO common.c: Flash page at addr: 0x08001c00 erased                                                                                      
2024-03-20T10:28:51 INFO common.c: Finished erasing 8 pages of 1024 (0x400) bytes                                                                             
2024-03-20T10:28:51 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL                                                                                    
2024-03-20T10:28:51 INFO flash_loader.c: Successfully loaded flash loader in sram                                                                             
2024-03-20T10:28:51 INFO flash_loader.c: Clear DFSR                                                                                                           
  8/  8 pages written                                                                                                                                         
2024-03-20T10:28:51 INFO common.c: Starting verification of write complete                                                                                    
2024-03-20T10:28:51 INFO common.c: Flash written and verified! jolly good!

Dmesg informed me again that the device is correctly recognized.

Next step:

BOOT0 is set back to 0 and the STM32 is now connected by USB. ST Link is disconnected. How to get sudo make dfu to work was not that easy to figure out, because I had to press the reset button of the STM32 and then start the make call several times, until it was able to connect to the DFU device.

././STM32F10X_Lib/utils/linux64/dfu-util -D bin/mmdvm_f1bl.bin -d 1eaf:0003 -a 2 -R -R                                                                                                                                                                                                                               [3/1831]
dfu-util 0.7                                                                                                                                                  

Copyright 2005-2008 Weston Schmidt, Harald Welte and OpenMoko Inc.                                                                                            
Copyright 2010-2012 Tormod Volden and Stefan Schmidt                                                                                                          
This program is Free Software and has ABSOLUTELY NO WARRANTY                                                                                                  
Please report bugs to dfu-util@lists.gnumonks.org                              

Filter on vendor = 0x1eaf product = 0x0003                                     
Opening DFU capable USB device... ID 1eaf:0003                                 
Run-time device DFU version 0110                                               
Found DFU: [1eaf:0003] devnum=0, cfg=1, intf=0, alt=2, name="STM32duino bootloader v1.0  Upload to Flash 0x8002000"                                                                                                                                                                                                          
Claiming USB DFU Interface...                                                  
Setting Alternate Setting #2 ...                                               
Determining device status: state = dfuIDLE, status = 0                                                                                                        
dfuIDLE, continuing                                                            
DFU mode device DFU version 0110                                               
Device returned transfer size 1024                                             
No valid DFU suffix signature                                                  
Warning: File has no DFU suffix                                                
bytes_per_hash=1174                                                            
Copying data from PC to DFU device                                             
Starting download: [##################################################] finished!                                                                             
state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present                                                                                
Done!                                                                          
Resetting USB to switch back to runtime mode  

But after that the device is not recognized:

[ 6620.236557] usb 1-1.3: reset full-speed USB device number 56 using ehci-pci                                                                                
[ 6620.316558] usb 1-1.3: device descriptor read/64, error -32                                                                                                
[ 6620.504552] usb 1-1.3: device descriptor read/64, error -32                                                                                                
[ 6620.692552] usb 1-1.3: reset full-speed USB device number 56 using ehci-pci                                                                                
[ 6620.772551] usb 1-1.3: device descriptor read/64, error -32                                                                                                
[ 6620.960546] usb 1-1.3: device descriptor read/64, error -32                                                                                                
[ 6621.148572] usb 1-1.3: reset full-speed USB device number 56 using ehci-pci                                                                                
[ 6621.564545] usb 1-1.3: device not accepting address 56, error -32                                                                                          
[ 6621.644541] usb 1-1.3: reset full-speed USB device number 56 using ehci-pci                                                                                
[ 6622.060532] usb 1-1.3: device not accepting address 56, error -32   

After a reconnect of the device it is again recognized as the Mapel bootloader DFU device but it is kind of stuck in it:

[ 6640.036169] usb 1-1.3: USB disconnect, device number 62
[ 6641.744327] usb 1-1.3: new full-speed USB device number 63 using ehci-pci
[ 6641.854184] usb 1-1.3: New USB device found, idVendor=1eaf, idProduct=0003, bcdDevice= 2.01
[ 6641.854195] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 6641.854198] usb 1-1.3: Product: Maple 003
[ 6641.854200] usb 1-1.3: Manufacturer: LeafLabs
[ 6641.854202] usb 1-1.3: SerialNumber: LLM 003

A /dev/ttyACM0 device is not available, which seems to be ok because i only enabled the makro STM32_USB_HOST.

I also tried it with enabled STM32_USB_HOST but still no success.

Do you have any suggestions?

My next step would be to try out the nobl make options.

klaute commented 4 months ago

No success with nobl, the USB device is not recognized by the OS.

Timewise I also enabled the following options:

define SERIAL_REPEATER

define SERIAL_REPEATER_BAUD 9600

define SERIAL_REPEATER_USART1

It does not make a difference.

klaute commented 4 months ago

No chance.

I tested all possible board types from ZUMSPOT_ADF7021 to LONESTAR_USB with the following settings:

define LIBRE_KIT_ADF7021

define ENABLE_ADF7021

define ADF7021_14_7456

define AD7021_GAIN_AUTO

define STM32_USART1_HOST

define ENABLE_SCAN_MODE

define ENABLE_DEBUG

But after flashing of the software with make dfu, the STM32 is stuck and does not reset properly. After I hit the reset button, the Maple DFU device is visible again. No TTY device is recogniced.

I attached an USART tu USB connector to PA9 & PA10 to see if I could connect to the STM32. Also no success, that for I'm use the latest MMDVMHost software (master branch). MMDVMHost is configured to use 115200 baud.

M: 2024-03-22 19:18:12.322 Opening the MMDVM
E: 2024-03-22 19:18:25.149 Unable to read the firmware version after six attempts
I: 2024-03-22 19:18:25.206 MMDVMHost-20240223 exited on receipt of an unknown signal

If I disable STM32_USART1_HOST and enable STM32_USB_HOST I'm facing the following errors during compilation (latest master branch):


/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: obj_f1/SerialSTM.o: in function `CSerialPort::beginInt(unsigned char, int)':
SerialSTM.cpp:(.text._ZN11CSerialPort8beginIntEhi+0xc): undefined reference to `usbserial'
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: SerialSTM.cpp:(.text._ZN11CSerialPort8beginIntEhi+0x6): undefined reference to `USBSerial::begin()'
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: obj_f1/SerialSTM.o: in function `CSerialPort::availableInt(unsigned char)':
SerialSTM.cpp:(.text._ZN11CSerialPort12availableIntEh+0x10): undefined reference to `usbserial'
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: SerialSTM.cpp:(.text._ZN11CSerialPort12availableIntEh+0x6): undefined reference to `USBSerial::available()'
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: obj_f1/SerialSTM.o: in function `CSerialPort::readInt(unsigned char)':
SerialSTM.cpp:(.text._ZN11CSerialPort7readIntEh+0x8): undefined reference to `USBSerial::read()'
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: SerialSTM.cpp:(.text._ZN11CSerialPort7readIntEh+0x14): undefined reference to `usbserial'
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: obj_f1/SerialSTM.o: in function `CSerialPort::writeInt(unsigned char, unsigned char const*, unsigned short, bool)':
SerialSTM.cpp:(.text._ZN11CSerialPort8writeIntEhPKhtb+0x12): undefined reference to `USBSerial::write(unsigned char const*, unsigned long)'
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: SerialSTM.cpp:(.text._ZN11CSerialPort8writeIntEhPKhtb+0x24): undefined reference to `usbserial'
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: SerialSTM.cpp:(.text._ZN11CSerialPort8writeIntEhPKhtb+0x1e): undefined reference to `USBSerial::flush()'
collect2: error: ld returned 1 exit status
make: *** [Makefile:333: bin/mmdvm_f1.elf] Fehler 1

I'm currently working on a ubuntu linux system.

I also have connected the RF7021SE module to see if the firmware comes up if it is attached, but it doesn't look like that this changed anything.

I also read all of the documentation in this repository and for me it sounds simple, also external documentation is very similar.

For me it looks like that my STM32 hardware is kind of "wrong" or "broken", but the example programs I run arw working fine.

klaute commented 4 months ago

I tested several bin release files without success. So my interpretation is that my setup is wrong. Therefore I closed the issue. Tested with release MMDVM_HS v1.5.2